StandardBillsFme.pas 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. procedure actnInsertBillsFromLibExecute(Sender: TObject);
  22. procedure zgBillsMouseDown(Sender: TObject; Button: TMouseButton;
  23. Shift: TShiftState; X, Y: Integer);
  24. procedure spbtnLibsClick(Sender: TObject);
  25. private
  26. FStandardLibs: TStandardLibs;
  27. FBillsType: TBillsType;
  28. procedure SetBillsType(const Value: TBillsType);
  29. function GetStandardLib: TStandardLib;
  30. procedure AdjustColumnType;
  31. public
  32. constructor Create(AStandardLibs: TStandardLibs);
  33. procedure ConnectStandardLib;
  34. property BillsType: TBillsType read FBillsType write SetBillsType;
  35. property StandardLib: TStandardLib read GetStandardLib;
  36. end;
  37. implementation
  38. uses
  39. SupportUnit, Globals, ConditionalDefines, UtilMethods;
  40. {$R *.dfm}
  41. { TStandBillsFrame }
  42. procedure TStandardBillsFrame.AdjustColumnType;
  43. procedure AdjustXmColumnType;
  44. begin
  45. stdBills.Columns.Delete(stdBills.ColumnIndex('B_Code'));
  46. end;
  47. procedure AdjustGclColumnType;
  48. begin
  49. stdBills.Columns.Delete(stdBills.ColumnIndex('Code'));
  50. end;
  51. begin
  52. if FBillsType = btXm then
  53. AdjustXmColumnType
  54. else if FBillsType = btGcl then
  55. AdjustGclColumnType;
  56. end;
  57. procedure TStandardBillsFrame.ConnectStandardLib;
  58. begin
  59. stdBills.IDTree := StandardLib.StandardBillsData.BillsTree;
  60. edtLibName.Text := StandardLib.LibName;
  61. end;
  62. constructor TStandardBillsFrame.Create(AStandardLibs: TStandardLibs);
  63. begin
  64. inherited Create(nil);
  65. FStandardLibs := AStandardLibs;
  66. stdBills.TopLevelBold := False;
  67. end;
  68. function TStandardBillsFrame.GetStandardLib: TStandardLib;
  69. begin
  70. case FBillsType of
  71. btXm: Result := FStandardLibs.StandardXmLib;
  72. btGcl: Result := FStandardLibs.StandardGclLib;
  73. end;
  74. end;
  75. procedure TStandardBillsFrame.SetBillsType(const Value: TBillsType);
  76. begin
  77. FBillsType := Value;
  78. AdjustColumnType;
  79. end;
  80. procedure TStandardBillsFrame.zgBillsMouseDown(Sender: TObject;
  81. Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  82. begin
  83. if (Button = mbRight) and (_IsDebugView) then
  84. dxpmStandardBills.PopupFromCursorPos
  85. else if (Button = mbLeft) and (ssDouble in Shift) then
  86. actnInsertBillsFromLib.Execute;
  87. end;
  88. procedure TStandardBillsFrame.actnInsertBillsFromLibExecute(
  89. Sender: TObject);
  90. begin
  91. with OpenProjectManager.CurProjectData.BillsCompileData do
  92. if Assigned(stdBills.IDTree.Selected) then
  93. AddBillsFromLib(stdBills.IDTree.Selected, BillsType);
  94. end;
  95. procedure TStandardBillsFrame.spbtnLibsClick(Sender: TObject);
  96. procedure ChangeStandardBills(const sFileName: string);
  97. var
  98. sOldName: string;
  99. begin
  100. Screen.Cursor := crHourGlass;
  101. try
  102. try
  103. case FBillsType of
  104. btXm:
  105. begin
  106. sOldName := SupportManager.ConfigInfo.StandardXmLib;
  107. SupportManager.ConfigInfo.StandardXmLib := ExtractFileName(odLib.FileName);
  108. end;
  109. btGcl:
  110. begin
  111. sOldName := SupportManager.ConfigInfo.StandardGclLib;
  112. SupportManager.ConfigInfo.StandardGclLib := ExtractFileName(odLib.FileName);
  113. end;
  114. end;
  115. ConnectStandardLib;
  116. except
  117. ErrorMessage('选择的标准清单不可识别');
  118. case FBillsType of
  119. btXm: SupportManager.ConfigInfo.StandardXmLib := ExtractFileName(sOldName);
  120. btGcl: SupportManager.ConfigInfo.StandardGclLib := ExtractFileName(sOldName);
  121. end;
  122. ConnectStandardLib;
  123. end;
  124. finally
  125. Screen.Cursor := crDefault;
  126. end;
  127. end;
  128. var
  129. sLibPath, sSelectLib, sNewLib: string;
  130. vLib: TStandardLib;
  131. begin
  132. case FBillsType of
  133. btXm: sLibPath := ExtractFileDir(FStandardLibs.StandardXmLib.FileName);
  134. btGcl: sLibPath := ExtractFileDir(FStandardLibs.StandardGclLib.FileName);
  135. end;
  136. if odLib.Execute then
  137. begin
  138. sSelectLib := odLib.FileName;
  139. if ExtractFileDir(sSelectLib) <> sLibPath then
  140. begin
  141. sNewLib := sLibPath + '\' + ExtractFileName(sSelectLib);
  142. if FileExists(sNewLib) then
  143. begin
  144. if QuestMessageYesNo('选择的标准清单不在默认路径下,默认路径下存在同名标准清单,仅可打开默认路径下的标准清单,是否继续?') then
  145. ChangeStandardBills(sNewLib);
  146. end
  147. else if QuestMessageYesNo('选择的标准清单不在默认路径下,是否复制到默认路径下并打开?') then
  148. begin
  149. CopyFile(PChar(sSelectLib), PChar(sNewLib), false);
  150. ChangeStandardBills(sNewLib);
  151. end;
  152. end
  153. else
  154. ChangeStandardBills(sSelectLib);
  155. end;
  156. end;
  157. end.