StandardBillsFme.pas 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. unit StandardBillsFme;
  2. interface
  3. uses
  4. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5. Dialogs, XPMenu, ZjGridDBA, ZjGridTreeDBA, ZJGrid, StdCtrls, Buttons,
  6. ExtCtrls, StandardLibs, StandardLib, ActnList, dxBar, sdGridDBA,
  7. sdGridTreeDBA;
  8. type
  9. TBillsType = (btXm, btGcl);
  10. TStandardBillsFrame = class(TFrame)
  11. pnlTop: TPanel;
  12. spbtnLibs: TSpeedButton;
  13. edtLibName: TEdit;
  14. zgBills: TZJGrid;
  15. xpm: TXPMenu;
  16. ActionList1: TActionList;
  17. dxpmStandardBills: TdxBarPopupMenu;
  18. actnInsertBillsFromLib: TAction;
  19. stdBills: TsdGridTreeDBA;
  20. odLib: TOpenDialog;
  21. actnExportStdJson: TAction;
  22. procedure actnInsertBillsFromLibExecute(Sender: TObject);
  23. procedure zgBillsMouseDown(Sender: TObject; Button: TMouseButton;
  24. Shift: TShiftState; X, Y: Integer);
  25. procedure spbtnLibsClick(Sender: TObject);
  26. procedure dxpmStandardBillsPopup(Sender: TObject);
  27. procedure actnExportStdJsonExecute(Sender: TObject);
  28. private
  29. FStandardLibs: TStandardLibs;
  30. FBillsType: TBillsType;
  31. procedure SetBillsType(const Value: TBillsType);
  32. function GetStandardLib: TStandardLib;
  33. procedure AdjustColumnType;
  34. public
  35. constructor Create(AStandardLibs: TStandardLibs);
  36. procedure ConnectStandardLib;
  37. property BillsType: TBillsType read FBillsType write SetBillsType;
  38. property StandardLib: TStandardLib read GetStandardLib;
  39. end;
  40. implementation
  41. uses
  42. SupportUnit, Globals, ConditionalDefines, UtilMethods, MainFrm;
  43. {$R *.dfm}
  44. { TStandBillsFrame }
  45. procedure TStandardBillsFrame.AdjustColumnType;
  46. procedure AdjustXmColumnType;
  47. begin
  48. stdBills.Columns.Delete(stdBills.ColumnIndex('B_Code'));
  49. end;
  50. procedure AdjustGclColumnType;
  51. begin
  52. stdBills.Columns.Delete(stdBills.ColumnIndex('Code'));
  53. end;
  54. begin
  55. if FBillsType = btXm then
  56. AdjustXmColumnType
  57. else if FBillsType = btGcl then
  58. AdjustGclColumnType;
  59. end;
  60. procedure TStandardBillsFrame.ConnectStandardLib;
  61. begin
  62. stdBills.IDTree := StandardLib.StandardBillsData.BillsTree;
  63. edtLibName.Text := StandardLib.LibName;
  64. end;
  65. constructor TStandardBillsFrame.Create(AStandardLibs: TStandardLibs);
  66. begin
  67. inherited Create(nil);
  68. FStandardLibs := AStandardLibs;
  69. stdBills.TopLevelBold := False;
  70. end;
  71. function TStandardBillsFrame.GetStandardLib: TStandardLib;
  72. begin
  73. case FBillsType of
  74. btXm: Result := FStandardLibs.StandardXmLib;
  75. btGcl: Result := FStandardLibs.StandardGclLib;
  76. end;
  77. end;
  78. procedure TStandardBillsFrame.SetBillsType(const Value: TBillsType);
  79. begin
  80. FBillsType := Value;
  81. AdjustColumnType;
  82. end;
  83. procedure TStandardBillsFrame.zgBillsMouseDown(Sender: TObject;
  84. Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  85. begin
  86. if (Button = mbRight) and (_IsDebugView) then
  87. dxpmStandardBills.PopupFromCursorPos
  88. else if (Button = mbLeft) and (ssDouble in Shift) then
  89. actnInsertBillsFromLib.Execute;
  90. end;
  91. procedure TStandardBillsFrame.actnInsertBillsFromLibExecute(
  92. Sender: TObject);
  93. begin
  94. with OpenProjectManager.CurProjectData.BillsCompileData do
  95. if Assigned(stdBills.IDTree.Selected) then
  96. AddBillsFromLib(stdBills.IDTree.Selected, BillsType);
  97. end;
  98. procedure TStandardBillsFrame.spbtnLibsClick(Sender: TObject);
  99. procedure ChangeStandardBills(const sFileName: string);
  100. var
  101. sOldName: string;
  102. begin
  103. Screen.Cursor := crHourGlass;
  104. try
  105. try
  106. case FBillsType of
  107. btXm:
  108. begin
  109. sOldName := SupportManager.ConfigInfo.StandardXmLib;
  110. SupportManager.ConfigInfo.StandardXmLib := ExtractFileName(odLib.FileName);
  111. end;
  112. btGcl:
  113. begin
  114. sOldName := SupportManager.ConfigInfo.StandardGclLib;
  115. SupportManager.ConfigInfo.StandardGclLib := ExtractFileName(odLib.FileName);
  116. end;
  117. end;
  118. ConnectStandardLib;
  119. except
  120. ErrorMessage('选择的标准清单不可识别');
  121. case FBillsType of
  122. btXm: SupportManager.ConfigInfo.StandardXmLib := ExtractFileName(sOldName);
  123. btGcl: SupportManager.ConfigInfo.StandardGclLib := ExtractFileName(sOldName);
  124. end;
  125. ConnectStandardLib;
  126. end;
  127. finally
  128. Screen.Cursor := crDefault;
  129. end;
  130. end;
  131. var
  132. sLibPath, sSelectLib, sNewLib: string;
  133. vLib: TStandardLib;
  134. begin
  135. case FBillsType of
  136. btXm: sLibPath := ExtractFileDir(FStandardLibs.StandardXmLib.FileName);
  137. btGcl: sLibPath := ExtractFileDir(FStandardLibs.StandardGclLib.FileName);
  138. end;
  139. if odLib.Execute then
  140. begin
  141. sSelectLib := odLib.FileName;
  142. if ExtractFileDir(sSelectLib) <> sLibPath then
  143. begin
  144. sNewLib := sLibPath + '\' + ExtractFileName(sSelectLib);
  145. if FileExists(sNewLib) then
  146. begin
  147. if QuestMessageYesNo('选择的标准清单不在默认路径下,默认路径下存在同名标准清单,仅可打开默认路径下的标准清单,是否继续?') then
  148. ChangeStandardBills(sNewLib);
  149. end
  150. else if QuestMessageYesNo('选择的标准清单不在默认路径下,是否复制到默认路径下并打开?') then
  151. begin
  152. CopyFile(PChar(sSelectLib), PChar(sNewLib), false);
  153. ChangeStandardBills(sNewLib);
  154. end;
  155. end
  156. else
  157. ChangeStandardBills(sSelectLib);
  158. end;
  159. end;
  160. procedure TStandardBillsFrame.dxpmStandardBillsPopup(Sender: TObject);
  161. begin
  162. SetDxBtnAction(actnExportStdJson, MainForm.dxbtnExportStdJson);
  163. end;
  164. procedure TStandardBillsFrame.actnExportStdJsonExecute(Sender: TObject);
  165. var
  166. sFileName: string;
  167. begin
  168. if SaveFile(sFileName, '.json') then
  169. StandardLib.StandardBillsData.RecursiveExportBillsJson(sFileName);
  170. end;
  171. end.