| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 | 
							- 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.
 
 
  |