ZJJLFme.pas 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. unit ZJJLFme;
  2. interface
  3. uses
  4. ZJJLDm,
  5. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  6. Dialogs, ExtCtrls, StdCtrls, DBCtrls, Mask, JimLabels, DB, ComCtrls,
  7. ToolWin, ActnList, ZjGridDBA, ZJGrid, dxBar, sdGridDBA, sdDB;
  8. type
  9. TRowIndex = (riCurGatherMeasure, riBGLCode, riPegName, riBeginPeg, riEndPeg, riFBFXName, riUnitName, riDrawingCode,
  10. riFormulaMemoTitle, riFormulaMemoValue, riRelaFileTitle, riRelaFileValue);
  11. const
  12. RowFields: array [TRowIndex] of string = ('', 'BGLCode', 'PegName', 'BeginPeg', 'EndPeg', 'FBFXName', 'UnitName', 'DrawingCode',
  13. '', 'FormulaMemo', '', 'RelaFile');
  14. RowFormats: array [TRowIndex] of string = ('本期计量%s:%s', '变更令号:', '部位:', '起始桩号:', '终止桩号:', '分部分项工程:', '计量单元:', '图号:',
  15. '计算式说明:', '', '计算草图几何尺寸:', '');
  16. type
  17. TZJJLFrame = class(TFrame)
  18. labTitle: TJimGradLabel;
  19. alBGL: TActionList;
  20. actnGenerate: TAction;
  21. pnlTop: TPanel;
  22. pnlButton: TPanel;
  23. tobaTop: TToolBar;
  24. tobtnGenerate: TToolButton;
  25. lePreText: TLabeledEdit;
  26. pnlZJJL: TPanel;
  27. zgZJJL: TZJGrid;
  28. pnlListTitle: TPanel;
  29. pnlListBar: TPanel;
  30. lblListTitle: TLabel;
  31. pnlZJJLProperty: TPanel;
  32. pnlDataTitle: TPanel;
  33. lblDataTiel: TLabel;
  34. pnlDataBar: TPanel;
  35. dxpmZJJL: TdxBarPopupMenu;
  36. actnLocateBills: TAction;
  37. dxpmAutoGenerate: TdxBarPopupMenu;
  38. actnGenerateFxZJJL: TAction;
  39. actnGenerateGclZJJL: TAction;
  40. saZJJL: TsdGridDBA;
  41. zgDetailInfo: TZJGrid;
  42. actnGenerateGclGatherZJJL: TAction;
  43. procedure actnGenerateExecute(Sender: TObject);
  44. procedure lePreTextExit(Sender: TObject);
  45. procedure zgZJJLMouseDown(Sender: TObject; Button: TMouseButton;
  46. Shift: TShiftState; X, Y: Integer);
  47. procedure dxpmZJJLPopup(Sender: TObject);
  48. procedure actnLocateBillsExecute(Sender: TObject);
  49. procedure actnLocateBillsUpdate(Sender: TObject);
  50. procedure dxpmAutoGeneratePopup(Sender: TObject);
  51. procedure actnGenerateFxZJJLExecute(Sender: TObject);
  52. procedure actnGenerateGclZJJLExecute(Sender: TObject);
  53. procedure actnGenerateUpdate(Sender: TObject);
  54. procedure zgDetailInfoGetCellText(Sender: TObject;
  55. const ACoord: TPoint; var Value: String; DisplayText: Boolean);
  56. procedure zgDetailInfoSetCellText(Sender: TObject;
  57. const ACoord: TPoint; var Value: String; DisplayText: Boolean);
  58. procedure zgDetailInfoCellCanEdit(Sender: TObject;
  59. const ACoord: TPoint; var Allow: Boolean);
  60. procedure actnGenerateGclGatherZJJLExecute(Sender: TObject);
  61. private
  62. FZJJLData: TZJJLData;
  63. FDataReadOnly: Boolean;
  64. procedure SetDataReadOnly(const Value: Boolean);
  65. procedure RefreshTitle;
  66. procedure RefreshDetailGrid;
  67. procedure GenerateZJJL;
  68. procedure InitDetailGrid;
  69. public
  70. constructor Create(AParent: TFrame; AZJJLData: TZJJLData);
  71. destructor Destroy; override;
  72. procedure ResetFrameLink(AZJJLData: TZJJLData);
  73. property DataReadOnly: Boolean read FDataReadOnly write SetDataReadOnly;
  74. end;
  75. implementation
  76. uses
  77. MergeTextFrm, PhaseData, MainFrm, ProjectData, UtilMethods,
  78. PhaseProperty, Math;
  79. {$R *.dfm}
  80. { TZJJLFrame }
  81. constructor TZJJLFrame.Create(AParent: TFrame; AZJJLData: TZJJLData);
  82. begin
  83. inherited Create(AParent);
  84. zgDetailInfo.RowCount := Integer(riRelaFileValue) + 1;
  85. ResetFrameLink(AZJJLData);
  86. if TPhaseData(FZJJLData.PhaseData).Active then
  87. begin
  88. with TPhaseData(FZJJLData.PhaseData).PhaseProperty do
  89. lePreText.Text := ZJJLPreText;
  90. end;
  91. RefreshTitle;
  92. FZJJLData.RefreshDetailGrid := RefreshDetailGrid;
  93. end;
  94. destructor TZJJLFrame.Destroy;
  95. begin
  96. inherited;
  97. end;
  98. procedure TZJJLFrame.ResetFrameLink(AZJJLData: TZJJLData);
  99. begin
  100. FZJJLData := AZJJLData;
  101. saZJJL.DataView := FZJJLData.sdvZJJL;
  102. InitDetailGrid;
  103. if (saZJJL.DataView.RecordCount > 0) then
  104. saZJJL.DataView.LocateInControl(saZJJL.DataView.Records[0]);
  105. FZJJLData.RefreshDetailGrid := RefreshDetailGrid;
  106. zgDetailInfo.Invalidate;
  107. end;
  108. procedure TZJJLFrame.actnGenerateExecute(Sender: TObject);
  109. var
  110. bIsRefer: Boolean;
  111. P: TPoint;
  112. begin
  113. with TProjectData(TPhaseData(FZJJLData.PhaseData).ProjectData) do
  114. bIsRefer := ProjProperties.AuditStatus = 0;
  115. if bIsRefer then
  116. begin
  117. P := pnlButton.ClientToScreen(Point(tobtnGenerate.Left, tobtnGenerate.Top + tobtnGenerate.Height));
  118. dxpmAutoGenerate.Popup(P.X, P.Y);
  119. end
  120. else
  121. GenerateZJJL;
  122. end;
  123. procedure TZJJLFrame.lePreTextExit(Sender: TObject);
  124. begin
  125. with TProjectData(TPhaseData(FZJJLData.PhaseData).ProjectData) do
  126. begin
  127. ProjProperties.ZJJLPreText := lePreText.Text;
  128. PhaseData.PhaseProperty.ZJJLPreText := lePreText.Text;
  129. end;
  130. end;
  131. procedure TZJJLFrame.SetDataReadOnly(const Value: Boolean);
  132. begin
  133. FDataReadOnly := Value;
  134. actnGenerate.Enabled := not FDataReadOnly;
  135. lePreText.Enabled := not FDataReadOnly;
  136. saZJJL.Columns.ColumnByName('Code').ReadOnly := FDataReadOnly;
  137. saZJJL.Columns.ColumnByName('CertificateCode').ReadOnly := FDataReadOnly;
  138. lePreText.Enabled := not Value;
  139. end;
  140. procedure TZJJLFrame.zgZJJLMouseDown(Sender: TObject; Button: TMouseButton;
  141. Shift: TShiftState; X, Y: Integer);
  142. begin
  143. if Button = mbRight then
  144. dxpmZJJL.PopupFromCursorPos
  145. else if (ssDouble in Shift) and (zgZJJL.CurCol = 1) and (zgZJJL.CurRow > 0) then
  146. begin
  147. if saZJJL.DataView.RecordCount > 0 then
  148. FZJJLData.LocateBills;
  149. end;
  150. end;
  151. procedure TZJJLFrame.dxpmZJJLPopup(Sender: TObject);
  152. begin
  153. SetDxBtnAction(actnLocateBills, MainForm.dxbtnLocateBills);
  154. end;
  155. procedure TZJJLFrame.actnLocateBillsExecute(Sender: TObject);
  156. begin
  157. FZJJLData.LocateBills;
  158. end;
  159. procedure TZJJLFrame.actnLocateBillsUpdate(Sender: TObject);
  160. begin
  161. TAction(Sender).Enabled := Assigned(FZJJLData.sdvZJJL.Current);
  162. end;
  163. procedure TZJJLFrame.RefreshTitle;
  164. var
  165. iType: Integer;
  166. begin
  167. if not TPhaseData(FZJJLData.PhaseData).Active then Exit;
  168. iType := TPhaseData(FZJJLData.PhaseData).PhaseProperty.ZJJLType;
  169. case iType of
  170. 0: labTitle.Caption := '中间计量(0号台账)';
  171. 1: labTitle.Caption := '中间计量(总量控制)';
  172. 2: labTitle.Caption := '中间计量(计量汇总)';
  173. end;
  174. end;
  175. procedure TZJJLFrame.dxpmAutoGeneratePopup(Sender: TObject);
  176. begin
  177. SetDxBtnAction(actnGenerateFxZJJL, MainForm.dxbtnFxZJJL);
  178. SetDxBtnAction(actnGenerateGclZJJL, MainForm.dxbtnGclZJJL);
  179. SetDxBtnAction(actnGenerateGclGatherZJJL, MainForm.dxbtnGclGatherZJJL);
  180. end;
  181. procedure TZJJLFrame.actnGenerateFxZJJLExecute(Sender: TObject);
  182. begin
  183. with TPhaseData(FZJJLData.PhaseData).PhaseProperty do
  184. begin
  185. ZJJLType := 0;
  186. GenerateZJJL;
  187. end;
  188. end;
  189. procedure TZJJLFrame.GenerateZJJL;
  190. var
  191. iType: Integer;
  192. begin
  193. with TProjectData(TPhaseData(FZJJLData.PhaseData).ProjectData) do
  194. ProjProperties.ZJJLPreText := lePreText.Text;
  195. iType := TPhaseData(FZJJLData.PhaseData).PhaseProperty.ZJJLType;
  196. case iType of
  197. 0: FZJJLData.GenerateAll;
  198. 1: FZJJLData.GenerateAllByB_Code;
  199. 2: FZJJLData.GenerateAllByB_CodeGather;
  200. end;
  201. RefreshTitle;
  202. if (saZJJL.DataView.RecordCount > 0) then
  203. saZJJL.DataView.LocateInControl(saZJJL.DataView.Records[0]);
  204. zgDetailInfo.Invalidate;
  205. end;
  206. procedure TZJJLFrame.actnGenerateGclZJJLExecute(Sender: TObject);
  207. begin
  208. with TPhaseData(FZJJLData.PhaseData).PhaseProperty do
  209. begin
  210. ZJJLType := 1;
  211. GenerateZJJL;
  212. end;
  213. end;
  214. procedure TZJJLFrame.actnGenerateUpdate(Sender: TObject);
  215. begin
  216. with TProjectData(TPhaseData(FZJJLData.PhaseData).ProjectData) do
  217. TAction(Sender).Enabled := not StageDataReadOnly;
  218. end;
  219. procedure TZJJLFrame.zgDetailInfoGetCellText(Sender: TObject;
  220. const ACoord: TPoint; var Value: String; DisplayText: Boolean);
  221. function GetDefaultValue(ARec: TsdDataRecord; AFieldName: string): string;
  222. begin
  223. if Assigned(ARec) and (AFieldName <> '') then
  224. Result := ARec.ValueByName(AFieldName).AsString
  225. else
  226. Result := '';
  227. end;
  228. function GetText(ARow: TRowIndex): string;
  229. var
  230. Rec: TsdDataRecord;
  231. begin
  232. Rec := saZJJL.DataView.Current;
  233. if DisplayText then
  234. Result := RowFormats[ARow] + GetDefaultValue(Rec, RowFields[ARow])
  235. else
  236. Result := GetDefaultValue(Rec, RowFields[ARow]);
  237. end;
  238. function GetFloatStr(ANum: Double): string;
  239. begin
  240. if ANum = 0 then
  241. Result := ''
  242. else
  243. Result := FloatToStr(ANum);
  244. end;
  245. function GetCurGatherMeasure: string;
  246. var
  247. Rec: TsdDataRecord;
  248. begin
  249. Rec := saZJJL.DataView.Current;
  250. if Rec.ValueByName('Type').AsInteger = Integer(ztFx) then
  251. Result := Format(RowFormats[riCurGatherMeasure], ['金额', GetFloatStr(FZJJLData.GetZJJLCalcData(Rec, 'GatherTotalPrice'))])
  252. else
  253. Result := Format(RowFormats[riCurGatherMeasure], ['数量', GetFloatStr(FZJJLData.GetZJJLCalcData(Rec, 'GatherQuantity'))]);
  254. end;
  255. begin
  256. if (ACoord.Y = Integer(riCurGatherMeasure)) then
  257. Value := GetCurGatherMeasure
  258. else if (ACoord.Y > Integer(riCurGatherMeasure)) and (ACoord.Y <= Integer(riRelaFileValue)) then
  259. Value := GetText(TRowIndex(ACoord.Y));
  260. end;
  261. procedure TZJJLFrame.InitDetailGrid;
  262. var
  263. iRowIndex: Integer;
  264. begin
  265. zgDetailInfo.DefaultColWidth := zgDetailInfo.Width - 25;
  266. for iRowIndex := 0 to zgDetailInfo.RowCount - 1 do
  267. zgDetailInfo[0, iRowIndex].Align := gaTopLeft;
  268. zgDetailInfo.RowHeights[Integer(riFormulaMemoValue)] := 57;
  269. zgDetailInfo.Cells[0, Integer(riFormulaMemoValue)].Align := gaTopLeft;
  270. zgDetailInfo.RowHeights[Integer(riRelaFileValue)] := 57;
  271. zgDetailInfo.Cells[0, Integer(riRelaFileValue)].Align := gaTopLeft;
  272. end;
  273. procedure TZJJLFrame.zgDetailInfoSetCellText(Sender: TObject;
  274. const ACoord: TPoint; var Value: String; DisplayText: Boolean);
  275. var
  276. Rec: TsdDataRecord;
  277. sFieldName: string;
  278. begin
  279. Rec := saZJJL.DataView.Current;
  280. if Assigned(Rec) then
  281. begin
  282. sFieldName := RowFields[TRowIndex(ACoord.Y)];
  283. if (sFieldName <> '') then
  284. begin
  285. saZJJL.DataView.Text[saZJJL.DataView.IndexOf(Rec), saZJJL.DataView.FindColumn(sFieldName).Index] := Value;
  286. end;
  287. end;
  288. end;
  289. procedure TZJJLFrame.zgDetailInfoCellCanEdit(Sender: TObject;
  290. const ACoord: TPoint; var Allow: Boolean);
  291. var
  292. sFieldName: string;
  293. begin
  294. sFieldName := RowFields[TRowIndex(ACoord.Y)];
  295. Allow := (not FDataReadOnly) and (sFieldName <> '') and Assigned(saZJJL.DataView.Current);
  296. end;
  297. procedure TZJJLFrame.actnGenerateGclGatherZJJLExecute(Sender: TObject);
  298. begin
  299. with TPhaseData(FZJJLData.PhaseData).PhaseProperty do
  300. begin
  301. ZJJLType := Integer(ztGclGather);
  302. GenerateZJJL;
  303. end;
  304. end;
  305. procedure TZJJLFrame.RefreshDetailGrid;
  306. begin
  307. zgDetailInfo.Invalidate;
  308. end;
  309. end.