BillsGatherFme.pas 9.8 KB

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