123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- unit BidLotDM;
- interface
- uses
- SysUtils,
- Classes,
- DB,
- ConstTypeUnit,
- ADODB;
- type
- TBidLotDataModule = class(TDataModule)
- atBidLot: TADOTable;
- atBidLotID: TIntegerField;
- atBidLotProjName: TWideStringField;
- atBidLotAliasName: TWideStringField;
- atBidLotFullName: TWideStringField;
- atBidLotFlag: TIntegerField;
- procedure atBidLotAfterPost(DataSet: TDataSet);
- private
- FProject: TObject;
- function MaxBidLotID: Integer;
- function CheckBidLot(const aProjName, aFullName: string): Boolean;
- procedure BeginRefresh;
- procedure EndRefresh;
- procedure ExecuteSQL(const aSQL: string);
- procedure AddBidLot(const aProjName, aFullName: string);
- procedure DeleteBidLot(const aProjName, aFullName: string);
- procedure ReNameBidLot(const aProjName, aFullName: string);
- function GetBidLotDB: TDataSet;
- procedure SetProject(const Value: TObject);
- public
- procedure Notify(aOperation: TBidLotOperation; const aProjName, aFullName: string);
- procedure RefreshBidLot(aStrings: TStrings);
- procedure SyncProjectView;
- property Project: TObject read FProject write SetProject;
- property BidLotDB: TDataSet read GetBidLotDB;
- end;
- implementation
- uses
- ScProjectManager;
- {$R *.dfm}
- { TBidLotDataModule }
- procedure TBidLotDataModule.AddBidLot(const aProjName, aFullName: string);
- begin
- if not atBidLot.Active then Exit;
- atBidLot.Append;
- atBidLotID.Value := MaxBidLotID;
- atBidLotProjName.Value := aProjName;
- atBidLotAliasName.Value := aProjName;
- atBidLotFullName.Value := aFullName;
- atBidLotFlag.Value := 1;
- atBidLot.Post;
- end;
- procedure TBidLotDataModule.BeginRefresh;
- var
- sSQL: string;
- begin
- sSQL := 'Update BidLot Set Flag = 0';
- ExecuteSQL(sSQL);
- end;
- function TBidLotDataModule.CheckBidLot(const aProjName,
- aFullName: string): Boolean;
- var
- aqQuery: TADOQuery;
- begin
- aqQuery := TADOQuery.Create(nil);
- try
- aqQuery.Connection := TProject(FProject).Connection;
- aqQuery.SQL.Text := Format('Select * From BidLot Where ' +
- '(ProjName = ''%s'') and (FullName = ''%s'')',
- [aProjName, aFullName]);
- aqQuery.Open;
- Result := aqQuery.RecordCount > 0;
- if Result then
- begin
- aqQuery.Edit;
- aqQuery.FieldByName('Flag').AsInteger := 1;
- aqQuery.Post;
- end;
- finally
- aqQuery.Free;
- end;
- end;
- procedure TBidLotDataModule.DeleteBidLot(const aProjName,
- aFullName: string);
- var
- sSQL: string;
- begin
- sSQL := Format('Delete * From BidLot Where ' +
- '(ProjName = ''%s'') and (FullName = ''%s'')',
- [aProjName, aFullName]);
- ExecuteSQL(sSQL);
- // atBidLot.Refresh;
- end;
- procedure TBidLotDataModule.EndRefresh;
- var
- sSQL: string;
- begin
- sSQL := 'Delete * From BidLot Where Flag = 0';
- ExecuteSQL(sSQL);
- end;
- procedure TBidLotDataModule.ExecuteSQL(const aSQL: string);
- var
- aqQuery: TADOQuery;
- begin
- aqQuery := TADOQuery.Create(nil);
- try
- aqQuery.Connection := TProject(FProject).Connection;
- aqQuery.SQL.Text := aSQL;
- aqQuery.ExecSQL;
- finally
- aqQuery.Free;
- end;
- end;
- function TBidLotDataModule.GetBidLotDB: TDataSet;
- begin
- Result := atBidLot;
- end;
- function TBidLotDataModule.MaxBidLotID: Integer;
- var
- aqQuery: TADOQuery;
- begin
- aqQuery := TADOQuery.Create(nil);
- try
- aqQuery.Connection := TProject(FProject).Connection;
- aqQuery.SQL.Text := 'Select Max(ID) As ID From BidLot';
- aqQuery.Open;
- Result := aqQuery.FieldByName('ID').AsInteger + 1;
- finally
- aqQuery.Free;
- end;
- end;
- procedure TBidLotDataModule.Notify(aOperation: TBidLotOperation;
- const aProjName, aFullName: string);
- begin
- if FProject = nil then Exit;
- case aOperation of
- boAdd : AddBidLot(aProjName, aFullName);
- boDelete : DeleteBidLot(aProjName, aFullName);
- boReName : ReNameBidLot(aProjName, aFullName);
- end;
- TProject(FProject).Changed := True;
- end;
- procedure TBidLotDataModule.RefreshBidLot(aStrings: TStrings);
- var
- I: Integer;
- sProjName, sFullName: string;
- begin
- BeginRefresh;
- for I := 0 to aStrings.Count - 1 do
- begin
- sProjName := aStrings[I];
- sFullName := string(aStrings.Objects[I]);
- if not CheckBidLot(sProjName, sFullName) then
- AddBidLot(sProjName, sFullName);
- end;
- EndRefresh;
- atBidLot.Active := False;
- atBidLot.Active := True;
- atBidLot.First;
- end;
- procedure TBidLotDataModule.ReNameBidLot(const aProjName,
- aFullName: string);
- var
- sSQL: string;
- begin
- sSQL := Format('Update BidLot Set ProjName = ''%s'' Where ' +
- 'FullName = ''%s''',
- [aProjName, aFullName]);
- ExecuteSQL(sSQL);
- end;
- procedure TBidLotDataModule.SetProject(const Value: TObject);
- begin
- FProject := Value;
- if Assigned(FProject) then
- begin
- atBidLot.Connection := TProject(FProject).Connection;
- atBidLot.Active := True;
- end;
- end;
- procedure TBidLotDataModule.SyncProjectView;
- var
- sgsBidLot: TStrings;
- begin
- atBidLot.Active := False;
- atBidLot.Active := True;
- sgsBidLot := TStringList.Create;
- try
- atBidLot.First;
- while not atBidLot.Eof do
- begin
- sgsBidLot.Add(atBidLotAliasName.Value);
- atBidLot.Next;
- end;
- TProject(FProject).BidLotList := sgsBidLot;
- finally
- sgsBidLot.Free;
- end;
- end;
- procedure TBidLotDataModule.atBidLotAfterPost(DataSet: TDataSet);
- begin
- TProject(FProject).Changed := True;
- end;
- end.
|