ReportManagerFrm.pas 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. cbCategory: TComboBox;
  16. pnlInputCode: TPanel;
  17. edtCode: TEdit;
  18. Label2: TLabel;
  19. zaLocal: TZjGridDBA;
  20. Label1: TLabel;
  21. zgOnline: TZJGrid;
  22. zaOnline: TZjGridDBA;
  23. btnGet: TcxButton;
  24. pnlCustom: TPanel;
  25. pnlHint: TPanel;
  26. zgCustom: TZJGrid;
  27. zaCustom: TZjGridDBA;
  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. private
  46. { Private declarations }
  47. FReports: TObject;
  48. function CurValue(AGridDBA: TZjGridDBA; FieldName: string): Variant;
  49. function Col(AGridDBA: TZjGridDBA; FieldName: string): Integer;
  50. procedure GridGetFont(Sender: TObject; ACoord: TPoint; AFont: TFont; AGrid: TZjGrid; AGridDBA: TZjGridDBA);
  51. procedure GridMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer; AGrid: TZjGrid; AGridDBA: TZjGridDBA);
  52. public
  53. { Public declarations }
  54. end;
  55. implementation
  56. uses ReportManagerDM, ReportHistoryFrm;
  57. {$R *.dfm}
  58. function TReportManagerForm.Col(AGridDBA: TZjGridDBA; FieldName: string): Integer;
  59. begin
  60. Result := AGridDBA.ColumnIndex(FieldName) + 1;
  61. end;
  62. function TReportManagerForm.CurValue(AGridDBA: TZjGridDBA; FieldName: string): Variant;
  63. begin
  64. Result := AGridDBA.DataSet.FieldByName(FieldName).AsVariant;
  65. end;
  66. procedure TReportManagerForm.FormCreate(Sender: TObject);
  67. begin
  68. FReports := TReports.Create(nil);
  69. zaLocal.DataSet := TReports(FReports).cdsLocal;
  70. zaLocal.Grid := zgLoacl;
  71. zaOnline.DataSet := TReports(FReports).cdsOnline;
  72. zaOnline.Grid := zgOnline;
  73. zaCustom.DataSet := TReports(FReports).cdsCustom;
  74. zaCustom.Grid := zgCustom;
  75. pnlHint.Visible := zaLocal.DataSet.RecordCount = 0;
  76. TReports(FReports).CategoryList(cbCategory.Items);
  77. cbCategory.ItemIndex := 0;
  78. pcReport.ActivePage := tsLocal;
  79. end;
  80. procedure TReportManagerForm.FormDestroy(Sender: TObject);
  81. begin
  82. FReports.Free;
  83. end;
  84. procedure TReportManagerForm.GridGetFont(Sender: TObject; ACoord: TPoint;
  85. AFont: TFont; AGrid: TZjGrid; AGridDBA: TZjGridDBA);
  86. var
  87. OldActiveRecd: Integer;
  88. begin
  89. if ACoord.X = Col(AGridDBA, 'State') then
  90. begin
  91. if AGridDBA.ChangeActiveRecord(ACoord.Y - AGrid.FixedRowCount, OldActiveRecd)then
  92. begin
  93. try
  94. if (CurValue(AGridDBA, 'State') = '¸üÐÂ') or (CurValue(AGridDBA, 'State') = 'ÏÂÔØ') then
  95. AFont.Color := clBlue;
  96. finally
  97. AGridDBA.ChangeActiveRecord(OldActiveRecd, OldActiveRecd);
  98. end;
  99. end;
  100. end
  101. else if ACoord.X = Col(AGridDBA, 'History') then
  102. AFont.Color := clBlue;
  103. end;
  104. procedure TReportManagerForm.GridMouseDown(Sender: TObject;
  105. Button: TMouseButton; Shift: TShiftState; X, Y: Integer; AGrid: TZjGrid;
  106. AGridDBA: TZjGridDBA);
  107. var
  108. vForm: TReportHistoryForm;
  109. vReport: TReport;
  110. iID: Integer;
  111. begin
  112. if CurValue(AGridDBA, 'ID') = null then Exit;
  113. Screen.Cursor := crHourGlass;
  114. try
  115. iID := CurValue(AGridDBA, 'ID');
  116. vReport := TReports(FReports).FindReprot(iID);
  117. if AGrid.CurCol = Col(AGridDBA, 'State') then
  118. begin
  119. if not SameText(vReport.LocalVer, vReport.NewestVer) then
  120. vReport.Update(vReport.NewestVer);
  121. end
  122. else if AGrid.CurCol = Col(AGridDBA, 'History') then
  123. begin
  124. vReport.GetHistoryVer;
  125. vForm := TReportHistoryForm.Create(vReport);
  126. try
  127. vForm.ShowModal;
  128. finally
  129. vForm.Free;
  130. end;
  131. end;
  132. finally
  133. Screen.Cursor := crDefault;
  134. end;
  135. end;
  136. procedure TReportManagerForm.zgLoaclCellGetFont(Sender: TObject;
  137. ACoord: TPoint; AFont: TFont);
  138. begin
  139. GridGetFont(Sender, ACoord, AFont, zgLoacl, zaLocal);
  140. end;
  141. procedure TReportManagerForm.zgOnlineCellGetFont(Sender: TObject;
  142. ACoord: TPoint; AFont: TFont);
  143. begin
  144. GridGetFont(Sender, ACoord, AFont, zgOnline, zaOnline);
  145. end;
  146. procedure TReportManagerForm.zgLoaclMouseDown(Sender: TObject;
  147. Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  148. begin
  149. GridMouseDown(Sender, Button, Shift, X, Y, zgLoacl, zaLocal);
  150. end;
  151. procedure TReportManagerForm.zgOnlineMouseDown(Sender: TObject;
  152. Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  153. begin
  154. GridMouseDown(Sender, Button, Shift, X, Y, zgOnline, zaOnline);
  155. end;
  156. procedure TReportManagerForm.cbCategoryChange(Sender: TObject);
  157. begin
  158. if cbCategory.ItemIndex = 0 then
  159. TReports(FReports).CancelFilterCategory
  160. else
  161. TReports(FReports).FilterCategory(cbCategory.Text);
  162. end;
  163. procedure TReportManagerForm.btnGetClick(Sender: TObject);
  164. begin
  165. if Trim(edtCode.Text) = '' then Exit;
  166. if TReports(FReports).LoadCustom(Trim(edtCode.Text)) then
  167. begin
  168. pnlInputCode.Visible := False;
  169. end;
  170. end;
  171. procedure TReportManagerForm.zgCustomCellGetFont(Sender: TObject;
  172. ACoord: TPoint; AFont: TFont);
  173. begin
  174. GridGetFont(Sender, ACoord, AFont, zgCustom, zaCustom);
  175. end;
  176. procedure TReportManagerForm.zgCustomMouseDown(Sender: TObject;
  177. Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  178. begin
  179. GridMouseDown(Sender, Button, Shift, X, Y, zgCustom, zaCustom);
  180. end;
  181. procedure TReportManagerForm.pcReportChange(Sender: TObject);
  182. begin
  183. if pcReport.ActivePage = tsLocal then
  184. pnlHint.Visible := zaLocal.DataSet.RecordCount = 0;
  185. end;
  186. end.