ReportManagerFrm.pas 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. unit ReportManagerFrm;
  2. interface
  3. uses
  4. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5. Dialogs, ComCtrls, DB, DBClient, ZJGrid, StdCtrls, ExtCtrls, ZjGridDBA,
  6. cxLookAndFeelPainters, cxButtons;
  7. type
  8. TReportManagerForm = class(TForm)
  9. pcReport: TPageControl;
  10. tsLocal: TTabSheet;
  11. tsOnline: TTabSheet;
  12. tsCustom: TTabSheet;
  13. zgLoacl: TZJGrid;
  14. Panel1: TPanel;
  15. pnlInputCode: TPanel;
  16. edtCode: TEdit;
  17. Label2: TLabel;
  18. zaLocal: TZjGridDBA;
  19. Label1: TLabel;
  20. zgOnline: TZJGrid;
  21. zaOnline: TZjGridDBA;
  22. btnGet: TcxButton;
  23. pnlCustom: TPanel;
  24. pnlHint: TPanel;
  25. zgCustom: TZJGrid;
  26. zaCustom: TZjGridDBA;
  27. cbCategory: TComboBox;
  28. procedure FormCreate(Sender: TObject);
  29. procedure FormDestroy(Sender: TObject);
  30. procedure zgLoaclCellGetFont(Sender: TObject; ACoord: TPoint;
  31. AFont: TFont);
  32. procedure zgOnlineCellGetFont(Sender: TObject; ACoord: TPoint;
  33. AFont: TFont);
  34. procedure zgLoaclMouseDown(Sender: TObject; Button: TMouseButton;
  35. Shift: TShiftState; X, Y: Integer);
  36. procedure zgOnlineMouseDown(Sender: TObject; Button: TMouseButton;
  37. Shift: TShiftState; X, Y: Integer);
  38. procedure cbCategoryChange(Sender: TObject);
  39. procedure btnGetClick(Sender: TObject);
  40. procedure zgCustomCellGetFont(Sender: TObject; ACoord: TPoint;
  41. AFont: TFont);
  42. procedure zgCustomMouseDown(Sender: TObject; Button: TMouseButton;
  43. Shift: TShiftState; X, Y: Integer);
  44. procedure pcReportChange(Sender: TObject);
  45. procedure zgOnlineShowHint(var HintStr: String; var CanShow: Boolean;
  46. var HintInfo: THintInfo; const ACoord: TPoint);
  47. procedure zgLoaclShowHint(var HintStr: String; var CanShow: Boolean;
  48. var HintInfo: THintInfo; const ACoord: TPoint);
  49. procedure zgCustomShowHint(var HintStr: String; var CanShow: Boolean;
  50. var HintInfo: THintInfo; const ACoord: TPoint);
  51. private
  52. { Private declarations }
  53. FReports: TObject;
  54. FReportsForm: TObject;
  55. function CurValue(AGridDBA: TZjGridDBA; FieldName: string): Variant;
  56. function Col(AGridDBA: TZjGridDBA; FieldName: string): Integer;
  57. procedure GridGetFont(Sender: TObject; ACoord: TPoint; AFont: TFont; AGrid: TZjGrid; AGridDBA: TZjGridDBA);
  58. procedure GridMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer; AGrid: TZjGrid; AGridDBA: TZjGridDBA);
  59. procedure GridShowHint(var HintStr: String; var CanShow: Boolean; var HintInfo: THintInfo; const ACoord: TPoint; AGrid: TZjGrid; AGridDBA: TZjGridDBA);
  60. procedure SetReportsForm(const Value: TObject);
  61. public
  62. { Public declarations }
  63. property ReportsForm: TObject read FReportsForm write SetReportsForm;
  64. end;
  65. implementation
  66. uses ReportManagerDM, ReportHistoryFrm, ReportsFrm;
  67. {$R *.dfm}
  68. function TReportManagerForm.Col(AGridDBA: TZjGridDBA; FieldName: string): Integer;
  69. begin
  70. Result := AGridDBA.ColumnIndex(FieldName) + 1;
  71. end;
  72. function TReportManagerForm.CurValue(AGridDBA: TZjGridDBA; FieldName: string): Variant;
  73. begin
  74. Result := AGridDBA.DataSet.FieldByName(FieldName).AsVariant;
  75. end;
  76. procedure TReportManagerForm.FormCreate(Sender: TObject);
  77. begin
  78. FReportsForm := nil;
  79. FReports := TReports.Create(nil);
  80. zaLocal.DataSet := TReports(FReports).cdsLocal;
  81. zaLocal.Grid := zgLoacl;
  82. zaOnline.DataSet := TReports(FReports).cdsOnline;
  83. zaOnline.Grid := zgOnline;
  84. zaCustom.DataSet := TReports(FReports).cdsCustom;
  85. zaCustom.Grid := zgCustom;
  86. pnlHint.Visible := zaLocal.DataSet.RecordCount = 0;
  87. TReports(FReports).CategoryList(cbCategory.Items);
  88. cbCategory.ItemIndex := 0;
  89. pcReport.ActivePage := tsLocal;
  90. end;
  91. procedure TReportManagerForm.FormDestroy(Sender: TObject);
  92. begin
  93. FReports.Free;
  94. if (FReportsForm <> nil) then
  95. TReportsForm(FReportsForm).RefreshReportTemplets;
  96. end;
  97. procedure TReportManagerForm.GridGetFont(Sender: TObject; ACoord: TPoint;
  98. AFont: TFont; AGrid: TZjGrid; AGridDBA: TZjGridDBA);
  99. var
  100. OldActiveRecd: Integer;
  101. begin
  102. if ACoord.X = Col(AGridDBA, 'State') then
  103. begin
  104. if AGridDBA.ChangeActiveRecord(ACoord.Y - AGrid.FixedRowCount, OldActiveRecd)then
  105. begin
  106. try
  107. if (CurValue(AGridDBA, 'State') = '¸üÐÂ') or (CurValue(AGridDBA, 'State') = 'ÏÂÔØ') then
  108. AFont.Color := clBlue;
  109. finally
  110. AGridDBA.ChangeActiveRecord(OldActiveRecd, OldActiveRecd);
  111. end;
  112. end;
  113. end
  114. else if ACoord.X = Col(AGridDBA, 'History') then
  115. AFont.Color := clBlue;
  116. end;
  117. procedure TReportManagerForm.GridMouseDown(Sender: TObject;
  118. Button: TMouseButton; Shift: TShiftState; X, Y: Integer; AGrid: TZjGrid;
  119. AGridDBA: TZjGridDBA);
  120. var
  121. vForm: TReportHistoryForm;
  122. vReport: TReport;
  123. iID: Integer;
  124. begin
  125. if CurValue(AGridDBA, 'ID') = null then Exit;
  126. Screen.Cursor := crHourGlass;
  127. try
  128. iID := CurValue(AGridDBA, 'ID');
  129. vReport := TReports(FReports).FindReprot(iID);
  130. if AGrid.CurCol = Col(AGridDBA, 'State') then
  131. begin
  132. if not SameText(vReport.LocalVer, vReport.NewestVer) then
  133. vReport.Update(vReport.NewestVer);
  134. end
  135. else if AGrid.CurCol = Col(AGridDBA, 'History') then
  136. begin
  137. vReport.GetHistoryVer;
  138. vForm := TReportHistoryForm.Create(vReport);
  139. try
  140. vForm.ShowModal;
  141. finally
  142. vForm.Free;
  143. end;
  144. end;
  145. finally
  146. Screen.Cursor := crDefault;
  147. end;
  148. end;
  149. procedure TReportManagerForm.zgLoaclCellGetFont(Sender: TObject;
  150. ACoord: TPoint; AFont: TFont);
  151. begin
  152. GridGetFont(Sender, ACoord, AFont, zgLoacl, zaLocal);
  153. end;
  154. procedure TReportManagerForm.zgOnlineCellGetFont(Sender: TObject;
  155. ACoord: TPoint; AFont: TFont);
  156. begin
  157. GridGetFont(Sender, ACoord, AFont, zgOnline, zaOnline);
  158. end;
  159. procedure TReportManagerForm.zgLoaclMouseDown(Sender: TObject;
  160. Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  161. begin
  162. GridMouseDown(Sender, Button, Shift, X, Y, zgLoacl, zaLocal);
  163. end;
  164. procedure TReportManagerForm.zgOnlineMouseDown(Sender: TObject;
  165. Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  166. begin
  167. GridMouseDown(Sender, Button, Shift, X, Y, zgOnline, zaOnline);
  168. end;
  169. procedure TReportManagerForm.cbCategoryChange(Sender: TObject);
  170. begin
  171. if cbCategory.ItemIndex = 0 then
  172. TReports(FReports).CancelFilterCategory
  173. else
  174. TReports(FReports).FilterCategory(cbCategory.Text);
  175. end;
  176. procedure TReportManagerForm.btnGetClick(Sender: TObject);
  177. begin
  178. if Trim(edtCode.Text) = '' then Exit;
  179. if TReports(FReports).LoadCustom(Trim(edtCode.Text)) then
  180. begin
  181. pnlInputCode.Visible := False;
  182. end;
  183. end;
  184. procedure TReportManagerForm.zgCustomCellGetFont(Sender: TObject;
  185. ACoord: TPoint; AFont: TFont);
  186. begin
  187. GridGetFont(Sender, ACoord, AFont, zgCustom, zaCustom);
  188. end;
  189. procedure TReportManagerForm.zgCustomMouseDown(Sender: TObject;
  190. Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  191. begin
  192. GridMouseDown(Sender, Button, Shift, X, Y, zgCustom, zaCustom);
  193. end;
  194. procedure TReportManagerForm.pcReportChange(Sender: TObject);
  195. begin
  196. if pcReport.ActivePage = tsLocal then
  197. pnlHint.Visible := zaLocal.DataSet.RecordCount = 0;
  198. end;
  199. procedure TReportManagerForm.GridShowHint(var HintStr: String; var CanShow: Boolean;
  200. var HintInfo: THintInfo; const ACoord: TPoint; AGrid: TZjGrid; AGridDBA: TZjGridDBA);
  201. var vReport: TReport;
  202. OldActiveRecd, iID: Integer;
  203. begin
  204. if ACoord.X = 4 then
  205. begin
  206. if AGridDBA.ChangeActiveRecord(ACoord.Y - AGrid.FixedRowCount, OldActiveRecd) then
  207. begin
  208. try
  209. if CurValue(AGridDBA, 'ID') = null then Exit;
  210. iID := CurValue(AGridDBA, 'ID');
  211. vReport := TReports(FReports).FindReprot(iID);
  212. if vReport.NewestMemo = '' then
  213. HintInfo.HintStr := '[ÔÝÎÞ¸üÐÂ˵Ã÷]'
  214. else
  215. HintInfo.HintStr := vReport.NewestMemo;
  216. CanShow := True;
  217. HintInfo.HintMaxWidth := 250;
  218. HintInfo.HideTimeout := 30000;
  219. finally
  220. AGridDBA.ChangeActiveRecord(OldActiveRecd, OldActiveRecd);
  221. end;
  222. end;
  223. end;
  224. end;
  225. procedure TReportManagerForm.zgOnlineShowHint(var HintStr: String;
  226. var CanShow: Boolean; var HintInfo: THintInfo; const ACoord: TPoint);
  227. begin
  228. GridShowHint(HintStr, CanShow, HintInfo, ACoord, zgOnline, zaOnline);
  229. end;
  230. procedure TReportManagerForm.zgLoaclShowHint(var HintStr: String;
  231. var CanShow: Boolean; var HintInfo: THintInfo; const ACoord: TPoint);
  232. begin
  233. GridShowHint(HintStr, CanShow, HintInfo, ACoord, zgLoacl, zaLocal);
  234. end;
  235. procedure TReportManagerForm.zgCustomShowHint(var HintStr: String;
  236. var CanShow: Boolean; var HintInfo: THintInfo; const ACoord: TPoint);
  237. begin
  238. GridShowHint(HintStr, CanShow, HintInfo, ACoord, zgCustom, zaCustom);
  239. end;
  240. procedure TReportManagerForm.SetReportsForm(const Value: TObject);
  241. begin
  242. FReportsForm := Value;
  243. end;
  244. end.