Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to this correctly!!!

1 view
Skip to first unread message

winston castillo

unread,
Oct 2, 2000, 3:00:00 AM10/2/00
to
I have a problem in creating a correct series number when two user input
simultenaiously with the same data in my program.
The process of creating the series number: e.g (TO-1000001)
get the first two character of portof load(field) and locate the
two-character in the table that fall in the present month & year if found
increment the series by 1(one). In the Above example, TO is the first
two-character of the field portofload and 10 (ten) or the next two-digit
after dash corresponds to the present month.And the remaining number is the
number of time(s) that particular portofload appear.

To do this i have this procedure & function to be called.

first I call this
Procedure SetBOLSeries(myplace: string;SeriesDate:TDatetime);
{** This function tries to locate the first two-chararcter of place of
discharge **}
{** If locate increment the series no of that particular series name by one
**}
{** If not then add the characters and initialize the series no to 1**}
var
YY, MM, DD: Word;
YY2, MM2, DD2: Word;
nameflag : boolean;
tempstring : string;
begin
nameflag := False;
With Database do
begin
DecodeDate(SeriesDate, YY, MM, DD);
Table_BOLSeries.Open;
Table_BOLSeries.Filter := 'Series_Name = ''' + myplace + '''';
Table_BOLSeries.Filtered := True;

Table_BOLSeries.First;


While Not(Table_BOLSeries.EOF) Do
begin

DecodeDate(Table_BOLSeries.FieldByName('Series_Date').AsDateTime, YY2, MM2,
DD2);
nameflag := False;
If (YY=YY2) AND (MM=MM2) then
begin
Table_BOLSeries.Edit;
Table_BOLSeries.FieldByName('SERIES_NO').AsInteger :=
Table_BOLSeries.FieldByName('SERIES_NO').AsInteger+1;
Table_BOLSeries.Post;
nameflag := True;
Break;
end;
Table_BOLSeries.Next;
end;

If Not(nameFlag) then
begin
Table_BOLSeries.Append;
Table_BOLSeries.FieldByName('SERIES_NAME').AsString := myplace;
Table_BOLSeries.FieldByName('SERIES_DATE').AsDateTime:=
SeriesDate;
Table_BOLSeries.FieldByName('SERIES_NO').AsInteger := 1;
Table_BOLSeries.Post;
end;

{If Table_BOLSeries.Locate('SERIES_NAME',myplace,[]) then
begin
Table_BOLSeries.Edit;
Table_BOLSeries.FieldByName('SERIES_NO').AsInteger :=
Table_BOLSeries.FieldByName('SERIES_NO').AsInteger+1;
Table_BOLSeries.Post;
end
else
begin
Table_BOLSeries.Append;
Table_BOLSeries.FieldByName('SERIES_NAME').AsString :=
myplace;
Table_BOLSeries.FieldByName('SERIES_NO').AsInteger := 1;
Table_BOLSeries.Post;
end;}
Table_BOLSeries.Filtered := False;
Table_BOLSeries.Close;
end;
end;

----> then this function
Function NewBOLSeries(placeDel: string;Series_Date:TDateTime): String;
{** This function will make a Bill of Lading Series **}
{** format e.g TO-010001 **}
{** where TO is the first two character of Port of Delivery **}
{** and 01 or the first two-digit corresponds to the month **}
{** and 0001 or the last four-digit which pertains to number of times the
port of delivery is used in that month **}
Var tempvalue : string;
SeriesNo : Integer;
YY, MM, DD: Word;
YY2, MM2, DD2: Word;
begin
With Database do
begin
tempvalue := UpperCase(Copy(PlaceDel,1,2));
DecodeDate(Series_Date, YY, MM, DD);
Table_BOLSeries.Open;
Table_BOLSeries.First;
SeriesNo := 1;

Table_BOLSeries.Filter := 'Series_Name = ''' + tempvalue + '''';
Table_BOLSeries.Filtered := True;

While Not(Table_BOLSeries.eof) do
begin

DecodeDate(Table_BOLSeries.FieldByName('Series_Date').AsDateTime, YY2, MM2,
DD2);
If (YY=YY2) AND (MM=MM2) then
begin
If tempvalue =
Table_BOLSeries.FieldByName('Series_Name').AsString then
begin
SeriesNo :=
Table_BOLSeries.FieldByName('SERIES_NO').AsInteger;
Break;
end
else
begin
SeriesNo := 1;
Break;
end;
end;
Table_BOLSeries.Next;
end;{of while}

Table_BOLSeries.Filtered := False;
Table_BOLSeries.Close;
Result := tempvalue+ '-'+ Format('%.2d', [MM])+ Format('%.5d',
[SeriesNo]);
end;
end;
---------------------------
but with this procedure and function and two users simutaneously using it
creates the same series number of
TO-10000003 which is wrong..supposed to be the other user should have a
series number of TO-1000002. My problem is how to obtain that TO-1000002?

To avoid the deadlock i set my TIBTransaction to this setting:

read_committed
rec_version
nowait

I really appreciate if someone can help me with this one.

thank you

Winston Castillo
Newbie Programmer

jcnv...@hotmail.com

unread,
Dec 10, 2004, 1:00:54 AM12/10/04
to
Wins... What's up??
Did u ask nocs already?
0 new messages