StaffDm.pas 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. unit StaffDm;
  2. interface
  3. uses
  4. SysUtils, Classes, DB, DBClient, Provider, ADODB;
  5. type
  6. TStaffData = class(TDataModule)
  7. atStaff: TADOTable;
  8. dspStaff: TDataSetProvider;
  9. cdsStaff: TClientDataSet;
  10. cdsStaffPhaseID: TIntegerField;
  11. cdsStaffStageID: TIntegerField;
  12. cdsStaffCompany: TWideStringField;
  13. cdsStaffRole: TWideStringField;
  14. cdsStaffName: TWideStringField;
  15. cdsStaffLocked: TBooleanField;
  16. cdsStaffView: TClientDataSet;
  17. cdsStaffViewPhaseID: TIntegerField;
  18. cdsStaffViewStageID: TIntegerField;
  19. cdsStaffViewCompany: TWideStringField;
  20. cdsStaffViewRole: TWideStringField;
  21. cdsStaffViewName: TWideStringField;
  22. cdsStaffViewLocked: TBooleanField;
  23. cdsStaffUpdate: TClientDataSet;
  24. cdsStaffUpdatePhaseID: TIntegerField;
  25. cdsStaffUpdateStageID: TIntegerField;
  26. cdsStaffUpdateCompany: TWideStringField;
  27. cdsStaffUpdateRole: TWideStringField;
  28. cdsStaffUpdateName: TWideStringField;
  29. cdsStaffUpdateLocked: TBooleanField;
  30. cdsStaffEnable: TBooleanField;
  31. cdsStaffViewEnable: TBooleanField;
  32. cdsStaffUpdateEnable: TBooleanField;
  33. procedure cdsStaffViewStageIDGetText(Sender: TField; var Text: String;
  34. DisplayText: Boolean);
  35. private
  36. FProjectData: TObject;
  37. procedure InitStaffData(APhaseIndex: Integer);
  38. procedure CopyStaffData(APhaseIndex, AStageIndex: Integer);
  39. public
  40. constructor Create(AProjectData: TObject);
  41. destructor Destroy; override;
  42. procedure Open(AConnection: TADOConnection);
  43. procedure Close;
  44. procedure Save;
  45. procedure UpdateDataForNewPhase;
  46. procedure UpdateDataForNewAudit;
  47. procedure LockedDataForAudit;
  48. procedure LockedDataForReply;
  49. procedure ResetViewFilter(APhaseIndex: Integer);
  50. function FinalStaffCompany: string;
  51. end;
  52. implementation
  53. uses
  54. ProjectData;
  55. {$R *.dfm}
  56. { TStaffData }
  57. constructor TStaffData.Create(AProjectData: TObject);
  58. begin
  59. FProjectData := AProjectData;
  60. inherited Create(nil);
  61. end;
  62. destructor TStaffData.Destroy;
  63. begin
  64. inherited;
  65. end;
  66. procedure TStaffData.InitStaffData(APhaseIndex: Integer);
  67. var
  68. iStage: Integer;
  69. begin
  70. for iStage := 0 to 9 do
  71. begin
  72. cdsStaff.Append;
  73. cdsStaffPhaseID.AsInteger := APhaseIndex;
  74. cdsStaffStageID.AsInteger := iStage;
  75. cdsStaffLocked.AsBoolean := False;
  76. cdsStaffEnable.AsBoolean := iStage = 0;
  77. cdsStaff.Post;
  78. end;
  79. end;
  80. procedure TStaffData.Open(AConnection: TADOConnection);
  81. begin
  82. atStaff.Connection := AConnection;
  83. cdsStaff.Open;
  84. cdsStaff.IndexFieldNames := 'PhaseID;StageID';
  85. cdsStaffView.CloneCursor(cdsStaff, True);
  86. cdsStaffUpdate.CloneCursor(cdsStaff, True);
  87. end;
  88. procedure TStaffData.ResetViewFilter(APhaseIndex: Integer);
  89. begin
  90. cdsStaffView.DisableControls;
  91. try
  92. cdsStaffView.Filtered := False;
  93. cdsStaffView.Filter := 'PhaseID = ' + IntToStr(APhaseIndex);
  94. cdsStaffView.Filtered := True;
  95. finally
  96. cdsStaffView.EnableControls;
  97. end;
  98. end;
  99. procedure TStaffData.Save;
  100. begin
  101. cdsStaff.ApplyUpdates(0);
  102. end;
  103. procedure TStaffData.UpdateDataForNewPhase;
  104. var
  105. iPhaseCount: Integer;
  106. begin
  107. iPhaseCount := TProjectData(FProjectData).ProjProperties.PhaseCount;
  108. InitStaffData(iPhaseCount);
  109. CopyStaffData(iPhaseCount, 0);
  110. end;
  111. procedure TStaffData.cdsStaffViewStageIDGetText(Sender: TField;
  112. var Text: String; DisplayText: Boolean);
  113. begin
  114. if Sender.AsInteger = 0 then
  115. Text := 'Ô­±¨'
  116. else if Sender.AsInteger > 0 then
  117. Text := Format('%dÉó', [Sender.AsInteger]);
  118. end;
  119. procedure TStaffData.UpdateDataForNewAudit;
  120. begin
  121. with TProjectData(FProjectData) do
  122. CopyStaffData(PhaseIndex, ProjProperties.AuditStatus);
  123. end;
  124. procedure TStaffData.LockedDataForAudit;
  125. begin
  126. with TProjectData(FProjectData) do
  127. if cdsStaff.FindKey([ProjProperties.PhaseCount, ProjProperties.AuditStatus]) then
  128. begin
  129. cdsStaff.Edit;
  130. cdsStaffLocked.AsBoolean := True;
  131. cdsStaff.Post;
  132. end;
  133. end;
  134. procedure TStaffData.LockedDataForReply;
  135. begin
  136. cdsStaff.Filter := 'PhaseID = ' + IntToStr(TProjectData(FProjectData).PhaseIndex);
  137. cdsStaff.Filtered := True;
  138. try
  139. cdsStaff.First;
  140. while not cdsStaff.Eof do
  141. begin
  142. cdsStaff.Edit;
  143. cdsStaffLocked.AsBoolean := True;
  144. cdsStaff.Post;
  145. cdsStaff.Next;
  146. end;
  147. finally
  148. cdsStaff.Filtered := False;
  149. end;
  150. end;
  151. function TStaffData.FinalStaffCompany: string;
  152. begin
  153. with TProjectData(FProjectData) do
  154. if cdsStaff.FindKey([ProjProperties.PhaseCount, ProjProperties.AuditStatus]) then
  155. Result := cdsStaffCompany.AsString;
  156. end;
  157. procedure TStaffData.CopyStaffData(APhaseIndex, AStageIndex: Integer);
  158. begin
  159. if cdsStaff.FindKey([APhaseIndex, AStageIndex]) then
  160. begin
  161. cdsStaff.Edit;
  162. if cdsStaffUpdate.FindKey([APhaseIndex-1, AStageIndex]) then
  163. begin
  164. cdsStaffCompany.AsString := cdsStaffUpdateCompany.AsString;
  165. cdsStaffRole.AsString := cdsStaffUpdateRole.AsString;
  166. cdsStaffName.AsString := cdsStaffUpdateName.AsString;
  167. end;
  168. cdsStaffEnable.AsBoolean := True;
  169. cdsStaff.Post;
  170. end;
  171. end;
  172. procedure TStaffData.Close;
  173. begin
  174. cdsStaff.Close;
  175. end;
  176. end.