BillsGatherFme.pas 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. unit BillsGatherFme;
  2. interface
  3. uses
  4. BillsGatherDm, Globals, sdDB,
  5. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  6. Dialogs, ZJGrid, ExtCtrls, ZjGridDBA, ZjGridTreeDBA, ComCtrls, ToolWin,
  7. XPMenu, sdGridDBA, JimPages, dxBar, ActnList, CslButton;
  8. type
  9. TLocateBillsEvent = procedure (AID: Integer) of object;
  10. TBillsGatherFrame = class(TFrame)
  11. pnlBillsGather: TPanel;
  12. zgGclBills: TZJGrid;
  13. pnlRelaXmj: TPanel;
  14. pnlRelaXmjType: TPanel;
  15. tbToolsButton: TToolBar;
  16. tobtnDetailGcl: TToolButton;
  17. sprBillsGather: TSplitter;
  18. xpm: TXPMenu;
  19. tobtnDetailDeal: TToolButton;
  20. tobtnDetailBGL: TToolButton;
  21. jpsRela: TJimPages;
  22. jpsRelaDetailGcl: TJimPage;
  23. jpsRelaDetailDeal: TJimPage;
  24. jpsRelaDetailBGL: TJimPage;
  25. zgDetailGcl: TZJGrid;
  26. saDetailGcl: TsdGridDBA;
  27. saDetailDeal: TsdGridDBA;
  28. saDetailBGL: TsdGridDBA;
  29. zgDetailBGL: TZJGrid;
  30. zgDetailDeal: TZJGrid;
  31. saGclBills: TsdGridDBA;
  32. dxpmDetailGcl: TdxBarPopupMenu;
  33. alBillsGather: TActionList;
  34. actnLocateMeasureBills: TAction;
  35. actnLocateCompileBills: TAction;
  36. pnlTop: TPanel;
  37. btnUploadBillsList: TCslButton;
  38. procedure zgGclBillsCellGetColor(Sender: TObject; ACoord: TPoint;
  39. var AColor: TColor);
  40. procedure tobtnDetailGclClick(Sender: TObject);
  41. procedure dxpmDetailGclPopup(Sender: TObject);
  42. procedure actnLocateMeasureBillsExecute(Sender: TObject);
  43. procedure actnLocateMeasureBillsUpdate(Sender: TObject);
  44. procedure zgDetailGclMouseDown(Sender: TObject; Button: TMouseButton;
  45. Shift: TShiftState; X, Y: Integer);
  46. procedure actnLocateCompileBillsExecute(Sender: TObject);
  47. procedure actnLocateCompileBillsUpdate(Sender: TObject);
  48. procedure btnUploadBillsListClick(Sender: TObject);
  49. private
  50. FBillsGatherData: TBillsGatherData;
  51. FShowPhaseData: Boolean;
  52. FShowPriceChange: Boolean;
  53. FOnLocateMeasureBills: TLocateBillsEvent;
  54. FOnLocateCompileBills: TLocateBillsEvent;
  55. procedure SetColumnVisible(const AColumn: string; AVisible: Boolean);
  56. procedure SetShowPhaseData(const Value: Boolean);
  57. procedure SetShowPriceChange(const Value: Boolean);
  58. public
  59. constructor Create(AProjectFrame: TFrame; ABillsGatherData: TBillsGatherData);
  60. destructor Destroy; override;
  61. procedure RefreshBills;
  62. property ShowPriceChange: Boolean read FShowPriceChange write SetShowPriceChange;
  63. property ShowPhaseData: Boolean read FShowPhaseData write SetShowPhaseData;
  64. property OnLocateMeasureBills: TLocateBillsEvent read FOnLocateMeasureBills write FOnLocateMeasureBills;
  65. property OnLocateCompileBills: TLocateBillsEvent read FOnLocateCompileBills write FOnLocateCompileBills;
  66. end;
  67. implementation
  68. uses
  69. ProjectData, UtilMethods, CalcDecimal, MainFrm, PHPWebDm, ConditionalDefines;
  70. {$R *.dfm}
  71. { TBillsGatherFrame }
  72. constructor TBillsGatherFrame.Create(AProjectFrame: TFrame;
  73. ABillsGatherData: TBillsGatherData);
  74. begin
  75. inherited Create(AProjectFrame);
  76. FBillsGatherData := ABillsGatherData;
  77. saGclBills.DataView := FBillsGatherData.sdvGclBills;
  78. saDetailGcl.DataView := FBillsGatherData.sdvDetailGclBills;
  79. saDetailDeal.DataView := FBillsGatherData.sdvDetailDealBills;
  80. saDetailBGL.DataView := FBillsGatherData.sdvDetailBGLBills;
  81. pnlTop.Visible := _IsCloud and (TProjectData(FBillsGatherData.ProjectData).WebChangeSwitch = 1);
  82. end;
  83. destructor TBillsGatherFrame.Destroy;
  84. begin
  85. inherited;
  86. end;
  87. procedure TBillsGatherFrame.RefreshBills;
  88. begin
  89. FBillsGatherData.RefreshBills;
  90. ShowPhaseData := TProjectData(FBillsGatherData.ProjectData).ProjProperties.PhaseCount > 0;
  91. end;
  92. procedure TBillsGatherFrame.SetColumnVisible(const AColumn: string;
  93. AVisible: Boolean);
  94. begin
  95. if AVisible then
  96. saGclBills.Columns.ColumnByName(AColumn).Width := 60
  97. else
  98. saGclBills.Columns.ColumnByName(AColumn).Width := 0;
  99. end;
  100. procedure TBillsGatherFrame.SetShowPhaseData(const Value: Boolean);
  101. begin
  102. FShowPhaseData := Value;
  103. SetColumnVisible('CurDealQuantity', FShowPhaseData);
  104. SetColumnVisible('CurDealTotalPrice', FShowPhaseData);
  105. SetColumnVisible('CurQcQuantity', FShowPhaseData);
  106. SetColumnVisible('CurQcTotalPrice', FShowPhaseData);
  107. SetColumnVisible('CurPcQuantity', FShowPhaseData and FShowPriceChange);
  108. SetColumnVisible('CurPcTotalPrice', FShowPhaseData and FShowPriceChange);
  109. SetColumnVisible('CurGatherQuantity', FShowPhaseData);
  110. SetColumnVisible('CurGatherTotalPrice', FShowPhaseData);
  111. SetColumnVisible('EndDealQuantity', FShowPhaseData);
  112. SetColumnVisible('EndDealTotalPrice', FShowPhaseData);
  113. SetColumnVisible('EndQcQuantity', FShowPhaseData);
  114. SetColumnVisible('EndQcTotalPrice', FShowPhaseData);
  115. SetColumnVisible('EndPcQuantity', FShowPhaseData and FShowPriceChange);
  116. SetColumnVisible('EndPcTotalPrice', FShowPhaseData and FShowPriceChange);
  117. SetColumnVisible('EndGatherQuantity', FShowPhaseData);
  118. SetColumnVisible('EndGatherTotalPrice', FShowPhaseData);
  119. end;
  120. procedure TBillsGatherFrame.SetShowPriceChange(const Value: Boolean);
  121. begin
  122. FShowPriceChange := Value;
  123. SetColumnVisible('NewPrice', FShowPriceChange);
  124. SetColumnVisible('CurPcQuantity', FShowPriceChange and FShowPhaseData);
  125. SetColumnVisible('CurPcTotalPrice', FShowPriceChange and FShowPhaseData);
  126. SetColumnVisible('EndPcQuantity', FShowPriceChange and FShowPhaseData);
  127. SetColumnVisible('EndPcTotalPrice', FShowPriceChange and FShowPhaseData);
  128. end;
  129. procedure TBillsGatherFrame.zgGclBillsCellGetColor(Sender: TObject;
  130. ACoord: TPoint; var AColor: TColor);
  131. function CheckSimilarBills(ARow1, ARow2: Integer): Boolean;
  132. var
  133. bHasSame, bHasDiffer: Boolean;
  134. begin
  135. bHasSame := SameText(zgGclBills.Cells[1, ARow1].Text, zgGclBills.Cells[1, ARow2].Text);
  136. bHasDiffer := (not SameText(zgGclBills.Cells[2, ARow1].Text, zgGclBills.Cells[2, ARow2].Text))
  137. or (not SameText(zgGclBills.Cells[3, ARow1].Text, zgGclBills.Cells[3, ARow2].Text))
  138. or (not SameText(zgGclBills.Cells[4, ARow1].Text, zgGclBills.Cells[4, ARow2].Text));
  139. Result := bHasSame and bHasDiffer;
  140. end;
  141. function CheckOverRangePercent(AQty, ACompareQty: Double): Boolean;
  142. var
  143. vQtyDecimal: TDecimal;
  144. fCompare: Double;
  145. begin
  146. vQtyDecimal := TProjectData(FBillsGatherData.ProjectData).ProjProperties.DecimalManager.Common.Quantity;
  147. fCompare := vQtyDecimal.RoundTo(AQty * SupportManager.ConfigInfo.OverRangePercent / 100);
  148. Result := vQtyDecimal.RoundTo(ACompareQty - fCompare) > vQtyDecimal.CompareValue;
  149. end;
  150. function CheckOverRange(ARecIndex: Integer): Boolean;
  151. var
  152. Rec: TsdDataRecord;
  153. fQuantity, fDealQuantity, fEndDealQuantity: Double;
  154. begin
  155. Rec := saGclBills.DataView.Records[ARecIndex];
  156. Result := False;
  157. if not Assigned(Rec) then Exit;
  158. fDealQuantity := Rec.ValueByName('DealQuantity').AsFloat;
  159. fQuantity := Rec.ValueByName('Quantity').AsFloat;
  160. fEndDealQuantity := Rec.ValueByName('EndDealQuantity').AsFloat;
  161. case SupportManager.ConfigInfo.OverRangeType of
  162. 0: Result := CheckOverRangePercent(fQuantity, fEndDealQuantity);
  163. 1: Result := CheckOverRangePercent(fDealQuantity, fEndDealQuantity);
  164. 2: Result := CheckOverRangePercent(fQuantity, fEndDealQuantity) or CheckOverRangePercent(fDealQuantity, fEndDealQuantity);
  165. end;
  166. end;
  167. var
  168. bSimilarBills: Boolean;
  169. begin
  170. if (ACoord.Y >= zgGclBills.FixedRowCount + 1) and (ACoord.Y < zgGclBills.FixedRowCount + saGclBills.DataView.RecordCount) then
  171. begin
  172. if ACoord.Y = zgGclBills.FixedRowCount + 1 then
  173. bSimilarBills := CheckSimilarBills(ACoord.Y, ACoord.Y + 1)
  174. else if ACoord.Y < zgGclBills.FixedRowCount + saGclBills.DataView.RecordCount then
  175. bSimilarBills := CheckSimilarBills(ACoord.Y, ACoord.Y - 1) or
  176. CheckSimilarBills(ACoord.Y, ACoord.Y + 1)
  177. else
  178. bSimilarBills := CheckSimilarBills(ACoord.Y, ACoord.Y - 1);
  179. {if bSimilarBills then
  180. AColor := $00646AFE;}
  181. if bSimilarBills then
  182. AColor := $0000FFFF; // 黄色
  183. if TProjectData(FBillsGatherData.ProjectData).ProjProperties.ShowOverRange and CheckOverRange(ACoord.Y - zgGclBills.FixedRowCount) then
  184. AColor := $00505AFF; // 红色
  185. end;
  186. end;
  187. procedure TBillsGatherFrame.tobtnDetailGclClick(Sender: TObject);
  188. begin
  189. jpsRela.ActivePageIndex := TToolButton(Sender).Tag;
  190. tobtnDetailGcl.Down := tobtnDetailGcl.Tag = TToolButton(Sender).Tag;
  191. tobtnDetailDeal.Down := tobtnDetailDeal.Tag = TToolButton(Sender).Tag;
  192. tobtnDetailBGL.Down := tobtnDetailBGL.Tag = TToolButton(Sender).Tag;
  193. end;
  194. procedure TBillsGatherFrame.dxpmDetailGclPopup(Sender: TObject);
  195. begin
  196. SetDxBtnAction(actnLocateMeasureBills, MainForm.dxbtnLocateMeasureBills);
  197. SetDxBtnAction(actnLocateCompileBills, MainForm.dxbtnLocateCompileBills);
  198. end;
  199. procedure TBillsGatherFrame.actnLocateMeasureBillsExecute(Sender: TObject);
  200. begin
  201. if Assigned(saDetailGcl.DataView.Current) and Assigned(FOnLocateMeasureBills) then
  202. FOnLocateMeasureBills(saDetailGcl.DataView.Current.ValueByName('RelaBillsID').AsInteger);
  203. end;
  204. procedure TBillsGatherFrame.actnLocateMeasureBillsUpdate(Sender: TObject);
  205. begin
  206. TAction(Sender).Enabled := Assigned(saDetailGcl.DataView.Current) and Assigned(FOnLocateMeasureBills);
  207. end;
  208. procedure TBillsGatherFrame.zgDetailGclMouseDown(Sender: TObject;
  209. Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  210. begin
  211. if Button = mbRight then
  212. dxpmDetailGcl.PopupFromCursorPos;
  213. end;
  214. procedure TBillsGatherFrame.actnLocateCompileBillsExecute(Sender: TObject);
  215. begin
  216. if Assigned(saDetailGcl.DataView.Current) and Assigned(FOnLocateCompileBills) then
  217. FOnLocateCompileBills(saDetailGcl.DataView.Current.ValueByName('RelaBillsID').AsInteger);
  218. end;
  219. procedure TBillsGatherFrame.actnLocateCompileBillsUpdate(Sender: TObject);
  220. begin
  221. TAction(Sender).Enabled := Assigned(saDetailGcl.DataView.Current) and Assigned(FOnLocateCompileBills);
  222. end;
  223. procedure TBillsGatherFrame.btnUploadBillsListClick(Sender: TObject);
  224. var
  225. sgsParam: TStrings;
  226. sResult: string;
  227. begin
  228. if saGclBills.DataView.RecordCount = 0 then
  229. begin
  230. WarningMessage('请先建立台账,再同步清单至云端。');
  231. Exit;
  232. end;
  233. sgsParam := TStringList.Create;
  234. try
  235. sgsParam.Add(Format('pmid=%d', [TProjectData(FBillsGatherData.ProjectData).WebID]));
  236. //sgsParam.Add(Format('pmid=%d', [1595]));
  237. sgsParam.Add(Format('listjson=%s', [FBillsGatherData.GetAllBillsJson]));
  238. if PHPWeb.UrlGet(PHPWeb.MeasureURL + 'change/list/create', sgsParam, sResult) = 1 then
  239. TipMessage('上传成功。')
  240. else
  241. WarningMessage(Format('上传数据失败:', [sResult]));
  242. finally
  243. sgsParam.Free;
  244. end;
  245. end;
  246. end.