BillsGatherFme.pas 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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;
  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. fCompare: Double;
  144. begin
  145. fCompare := TProjectData(FBillsGatherData.ProjectData).ProjProperties.DecimalManager.Common.Quantity.CompareValue;
  146. if Abs(AQty) > fCompare then
  147. Result := (ACompareQty / AQty * 100) > SupportManager.ConfigInfo.OverRangePercent
  148. else
  149. Result := Abs(ACompareQty) > fCompare;
  150. end;
  151. function CheckOverRange(ARecIndex: Integer): Boolean;
  152. var
  153. Rec: TsdDataRecord;
  154. fQuantity, fDealQuantity, fEndDealQuantity: Double;
  155. begin
  156. Rec := saGclBills.DataView.Records[ARecIndex];
  157. Result := False;
  158. if not Assigned(Rec) then Exit;
  159. fDealQuantity := Rec.ValueByName('DealQuantity').AsFloat;
  160. fQuantity := Rec.ValueByName('Quantity').AsFloat;
  161. fEndDealQuantity := Rec.ValueByName('EndDealQuantity').AsFloat;
  162. case SupportManager.ConfigInfo.OverRangeType of
  163. 0: Result := CheckOverRangePercent(fQuantity, fEndDealQuantity);
  164. 1: Result := CheckOverRangePercent(fDealQuantity, fEndDealQuantity);
  165. 2: Result := CheckOverRangePercent(fQuantity, fEndDealQuantity) or CheckOverRangePercent(fDealQuantity, fEndDealQuantity);
  166. end;
  167. (*
  168. case SupportManager.ConfigInfo.OverRangeType of
  169. 0: Result := QuantityRoundTo(fEndDealQuantity - fQuantity) > fCompare;
  170. 1: Result := QuantityRoundTo(fEndDealQuantity - fDealQuantity) > fCompare;
  171. 2: Result := (QuantityRoundTo(fEndDealQuantity - fQuantity) > fCompare)
  172. or (QuantityRoundTo(fEndDealQuantity - fDealQuantity) > fCompare);
  173. end;
  174. *)
  175. end;
  176. var
  177. bSimilarBills: Boolean;
  178. begin
  179. if (ACoord.Y >= zgGclBills.FixedRowCount + 1) and (ACoord.Y < zgGclBills.FixedRowCount + saGclBills.DataView.RecordCount) then
  180. begin
  181. if ACoord.Y = zgGclBills.FixedRowCount + 1 then
  182. bSimilarBills := CheckSimilarBills(ACoord.Y, ACoord.Y + 1)
  183. else if ACoord.Y < zgGclBills.FixedRowCount + saGclBills.DataView.RecordCount then
  184. bSimilarBills := CheckSimilarBills(ACoord.Y, ACoord.Y - 1) or
  185. CheckSimilarBills(ACoord.Y, ACoord.Y + 1)
  186. else
  187. bSimilarBills := CheckSimilarBills(ACoord.Y, ACoord.Y - 1);
  188. {if bSimilarBills then
  189. AColor := $00646AFE;}
  190. if bSimilarBills then
  191. AColor := $0000FFFF; // 黄色
  192. if TProjectData(FBillsGatherData.ProjectData).ProjProperties.ShowOverRange and CheckOverRange(ACoord.Y - zgGclBills.FixedRowCount) then
  193. AColor := $00505AFF; // 红色
  194. end;
  195. end;
  196. procedure TBillsGatherFrame.tobtnDetailGclClick(Sender: TObject);
  197. begin
  198. jpsRela.ActivePageIndex := TToolButton(Sender).Tag;
  199. tobtnDetailGcl.Down := tobtnDetailGcl.Tag = TToolButton(Sender).Tag;
  200. tobtnDetailDeal.Down := tobtnDetailDeal.Tag = TToolButton(Sender).Tag;
  201. tobtnDetailBGL.Down := tobtnDetailBGL.Tag = TToolButton(Sender).Tag;
  202. end;
  203. procedure TBillsGatherFrame.dxpmDetailGclPopup(Sender: TObject);
  204. begin
  205. SetDxBtnAction(actnLocateMeasureBills, MainForm.dxbtnLocateMeasureBills);
  206. SetDxBtnAction(actnLocateCompileBills, MainForm.dxbtnLocateCompileBills);
  207. end;
  208. procedure TBillsGatherFrame.actnLocateMeasureBillsExecute(Sender: TObject);
  209. begin
  210. if Assigned(saDetailGcl.DataView.Current) and Assigned(FOnLocateMeasureBills) then
  211. FOnLocateMeasureBills(saDetailGcl.DataView.Current.ValueByName('RelaBillsID').AsInteger);
  212. end;
  213. procedure TBillsGatherFrame.actnLocateMeasureBillsUpdate(Sender: TObject);
  214. begin
  215. TAction(Sender).Enabled := Assigned(saDetailGcl.DataView.Current) and Assigned(FOnLocateMeasureBills);
  216. end;
  217. procedure TBillsGatherFrame.zgDetailGclMouseDown(Sender: TObject;
  218. Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  219. begin
  220. if Button = mbRight then
  221. dxpmDetailGcl.PopupFromCursorPos;
  222. end;
  223. procedure TBillsGatherFrame.actnLocateCompileBillsExecute(Sender: TObject);
  224. begin
  225. if Assigned(saDetailGcl.DataView.Current) and Assigned(FOnLocateCompileBills) then
  226. FOnLocateCompileBills(saDetailGcl.DataView.Current.ValueByName('RelaBillsID').AsInteger);
  227. end;
  228. procedure TBillsGatherFrame.actnLocateCompileBillsUpdate(Sender: TObject);
  229. begin
  230. TAction(Sender).Enabled := Assigned(saDetailGcl.DataView.Current) and Assigned(FOnLocateCompileBills);
  231. end;
  232. procedure TBillsGatherFrame.btnUploadBillsListClick(Sender: TObject);
  233. var
  234. sgsParam: TStrings;
  235. sResult: string;
  236. begin
  237. if saGclBills.DataView.RecordCount = 0 then
  238. begin
  239. WarningMessage('请先建立台账,再同步清单至云端。');
  240. Exit;
  241. end;
  242. sgsParam := TStringList.Create;
  243. try
  244. sgsParam.Add(Format('pmid=%d', [TProjectData(FBillsGatherData.ProjectData).WebID]));
  245. //sgsParam.Add(Format('pmid=%d', [1595]));
  246. sgsParam.Add(Format('listjson=%s', [FBillsGatherData.GetAllBillsJson]));
  247. if PHPWeb.UrlGet(PHPWeb.MeasureURL + 'change/list/create', sgsParam, sResult) = 1 then
  248. TipMessage('上传成功。')
  249. else
  250. WarningMessage(Format('上传数据失败:', [sResult]));
  251. finally
  252. sgsParam.Free;
  253. end;
  254. end;
  255. end.