unit StaffDm; interface uses SysUtils, Classes, DB, DBClient, Provider, ADODB; type TStaffData = class(TDataModule) atStaff: TADOTable; dspStaff: TDataSetProvider; cdsStaff: TClientDataSet; cdsStaffPhaseID: TIntegerField; cdsStaffStageID: TIntegerField; cdsStaffCompany: TWideStringField; cdsStaffRole: TWideStringField; cdsStaffName: TWideStringField; cdsStaffLocked: TBooleanField; cdsStaffView: TClientDataSet; cdsStaffViewPhaseID: TIntegerField; cdsStaffViewStageID: TIntegerField; cdsStaffViewCompany: TWideStringField; cdsStaffViewRole: TWideStringField; cdsStaffViewName: TWideStringField; cdsStaffViewLocked: TBooleanField; cdsStaffUpdate: TClientDataSet; cdsStaffUpdatePhaseID: TIntegerField; cdsStaffUpdateStageID: TIntegerField; cdsStaffUpdateCompany: TWideStringField; cdsStaffUpdateRole: TWideStringField; cdsStaffUpdateName: TWideStringField; cdsStaffUpdateLocked: TBooleanField; cdsStaffEnable: TBooleanField; cdsStaffViewEnable: TBooleanField; cdsStaffUpdateEnable: TBooleanField; procedure cdsStaffViewStageIDGetText(Sender: TField; var Text: String; DisplayText: Boolean); private FProjectData: TObject; procedure InitStaffData(APhaseIndex: Integer); procedure CopyStaffData(APhaseIndex, AStageIndex: Integer); public constructor Create(AProjectData: TObject); destructor Destroy; override; procedure Open(AConnection: TADOConnection); procedure Close; procedure Save; procedure UpdateDataForNewPhase; procedure UpdateDataForNewAudit; procedure LockedDataForAudit; procedure LockedDataForReply; procedure ResetViewFilter(APhaseIndex: Integer); function FinalStaffCompany: string; end; implementation uses ProjectData; {$R *.dfm} { TStaffData } constructor TStaffData.Create(AProjectData: TObject); begin FProjectData := AProjectData; inherited Create(nil); end; destructor TStaffData.Destroy; begin inherited; end; procedure TStaffData.InitStaffData(APhaseIndex: Integer); var iStage: Integer; begin for iStage := 0 to 9 do begin cdsStaff.Append; cdsStaffPhaseID.AsInteger := APhaseIndex; cdsStaffStageID.AsInteger := iStage; cdsStaffLocked.AsBoolean := False; cdsStaffEnable.AsBoolean := iStage = 0; cdsStaff.Post; end; end; procedure TStaffData.Open(AConnection: TADOConnection); begin atStaff.Connection := AConnection; cdsStaff.Open; cdsStaff.IndexFieldNames := 'PhaseID;StageID'; cdsStaffView.CloneCursor(cdsStaff, True); cdsStaffUpdate.CloneCursor(cdsStaff, True); end; procedure TStaffData.ResetViewFilter(APhaseIndex: Integer); begin cdsStaffView.DisableControls; try cdsStaffView.Filtered := False; cdsStaffView.Filter := 'PhaseID = ' + IntToStr(APhaseIndex); cdsStaffView.Filtered := True; finally cdsStaffView.EnableControls; end; end; procedure TStaffData.Save; begin cdsStaff.ApplyUpdates(0); end; procedure TStaffData.UpdateDataForNewPhase; var iPhaseCount: Integer; begin iPhaseCount := TProjectData(FProjectData).ProjProperties.PhaseCount; InitStaffData(iPhaseCount); CopyStaffData(iPhaseCount, 0); end; procedure TStaffData.cdsStaffViewStageIDGetText(Sender: TField; var Text: String; DisplayText: Boolean); begin if Sender.AsInteger = 0 then Text := 'Ô­±¨' else if Sender.AsInteger > 0 then Text := Format('%dÉó', [Sender.AsInteger]); end; procedure TStaffData.UpdateDataForNewAudit; begin with TProjectData(FProjectData) do CopyStaffData(PhaseIndex, ProjProperties.AuditStatus); end; procedure TStaffData.LockedDataForAudit; begin with TProjectData(FProjectData) do if cdsStaff.FindKey([ProjProperties.PhaseCount, ProjProperties.AuditStatus]) then begin cdsStaff.Edit; cdsStaffLocked.AsBoolean := True; cdsStaff.Post; end; end; procedure TStaffData.LockedDataForReply; begin cdsStaff.Filter := 'PhaseID = ' + IntToStr(TProjectData(FProjectData).PhaseIndex); cdsStaff.Filtered := True; try cdsStaff.First; while not cdsStaff.Eof do begin cdsStaff.Edit; cdsStaffLocked.AsBoolean := True; cdsStaff.Post; cdsStaff.Next; end; finally cdsStaff.Filtered := False; end; end; function TStaffData.FinalStaffCompany: string; begin with TProjectData(FProjectData) do if cdsStaff.FindKey([ProjProperties.PhaseCount, ProjProperties.AuditStatus]) then Result := cdsStaffCompany.AsString; end; procedure TStaffData.CopyStaffData(APhaseIndex, AStageIndex: Integer); begin if cdsStaff.FindKey([APhaseIndex, AStageIndex]) then begin cdsStaff.Edit; if cdsStaffUpdate.FindKey([APhaseIndex-1, AStageIndex]) then begin cdsStaffCompany.AsString := cdsStaffUpdateCompany.AsString; cdsStaffRole.AsString := cdsStaffUpdateRole.AsString; cdsStaffName.AsString := cdsStaffUpdateName.AsString; end; cdsStaffEnable.AsBoolean := True; cdsStaff.Post; end; end; procedure TStaffData.Close; begin cdsStaff.Close; end; end.