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