ReportsFrm.pas 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519
  1. unit ReportsFrm;
  2. interface
  3. // 导出PDF须定义该编译指令
  4. {$DEFINE cplPrint}
  5. // 导出Excel须定义该编译指令
  6. {$DEFINE cplOutputToExcelRange}
  7. uses
  8. ProjectData, ScFileArchiver, ReportManager, ConditionalDefines,
  9. PrintComTypeDefUnit, ADODB, DB, ReportPrepare, ReportConnection,
  10. AuditSelectFrm,
  11. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  12. Dialogs, PrintCom, PrintComXML, ExtCtrls, ExTreeView, ImgList,
  13. dxBarExtItems, dxBar, ComCtrls, ToolWin, StdCtrls;
  14. type
  15. TReportsForm = class(TForm)
  16. xmReports: TdxBarManager;
  17. xlbPrint: TdxBarLargeButton;
  18. xlbToExcel: TdxBarLargeButton;
  19. xlbToPDF: TdxBarLargeButton;
  20. xlbRealSize: TdxBarLargeButton;
  21. xlbOnePage: TdxBarLargeButton;
  22. xlbTwoPage: TdxBarLargeButton;
  23. xlbFourPage: TdxBarLargeButton;
  24. xcbPages: TdxBarCombo;
  25. xlbFirstPage: TdxBarLargeButton;
  26. xlbPrePage: TdxBarLargeButton;
  27. xlbNextPage: TdxBarLargeButton;
  28. xlbLastPage: TdxBarLargeButton;
  29. xcbStartPage: TdxBarCombo;
  30. xcbEndPage: TdxBarCombo;
  31. xlbSetup: TdxBarLargeButton;
  32. xlbClose: TdxBarLargeButton;
  33. xlbPrintCurPage: TdxBarLargeButton;
  34. dxcciSafePrint: TdxBarControlContainerItem;
  35. ilstLarge: TImageList;
  36. pnlReportsList: TPanel;
  37. extvReport: TExTreeView;
  38. sprReportPreview: TSplitter;
  39. sbReportsPreview: TScrollBox;
  40. PreviewBox: TImage;
  41. PreviewComXML: TPrintComXML;
  42. ilstTree: TImageList;
  43. pnlTopButton: TPanel;
  44. tobaTemplateManager: TToolBar;
  45. tbImportSrt: TToolButton;
  46. tbExportSrt: TToolButton;
  47. tbDeleteSrt: TToolButton;
  48. ilstTemplateContorl: TImageList;
  49. pnlPaperSize: TPanel;
  50. rdbtnA3: TRadioButton;
  51. rdbtnA4: TRadioButton;
  52. chkFillZero: TCheckBox;
  53. dxcciPageSize: TdxBarControlContainerItem;
  54. pnlExcelMode: TPanel;
  55. chkExcelMode: TCheckBox;
  56. chkExcel2010: TCheckBox;
  57. dxcciExcelMode: TdxBarControlContainerItem;
  58. pnlReports: TPanel;
  59. procedure PreviewComXMLGetDataConnection(var ADOCon: TADOConnection);
  60. procedure xlbRealSizeClick(Sender: TObject);
  61. procedure xlbOnePageClick(Sender: TObject);
  62. procedure xlbTwoPageClick(Sender: TObject);
  63. procedure xlbFourPageClick(Sender: TObject);
  64. procedure xlbFirstPageClick(Sender: TObject);
  65. procedure xlbPrePageClick(Sender: TObject);
  66. procedure xlbNextPageClick(Sender: TObject);
  67. procedure xlbLastPageClick(Sender: TObject);
  68. procedure xcbPagesChange(Sender: TObject);
  69. procedure xlbPrintCurPageClick(Sender: TObject);
  70. procedure xcbStartPageChange(Sender: TObject);
  71. procedure xlbPrintClick(Sender: TObject);
  72. procedure xlbToPDFClick(Sender: TObject);
  73. procedure xlbToExcelClick(Sender: TObject);
  74. procedure extvReportClick(Sender: TObject);
  75. procedure xlbCloseClick(Sender: TObject);
  76. procedure tbImportSrtClick(Sender: TObject);
  77. procedure tbDeleteSrtClick(Sender: TObject);
  78. procedure tbExportSrtClick(Sender: TObject);
  79. procedure PreviewComXMLContentDisplay(var contentFontRec: TFontRec;
  80. dataType: Integer; isReading: Boolean; DrawType: Integer;
  81. isPrinting: Boolean);
  82. procedure xlbSetupClick(Sender: TObject);
  83. procedure PreviewComXMLCrossTabLabelShow(valIDX: Integer; var ExLeft,
  84. ExRight: Double; var isShow: Boolean; CrsTabShowType: Integer);
  85. procedure rdbtnA4Click(Sender: TObject);
  86. procedure chkFillZeroClick(Sender: TObject);
  87. procedure PreviewComXMLGetDatasetEvent(DatasetInfo: PDatasetInfoRec;
  88. var ADataset: TDataSet);
  89. private
  90. FProjectData: TProjectData;
  91. FCurPage: Integer;
  92. FiPageGroup: Integer;
  93. FiCenterPerPage: Integer;
  94. FbNormal : Boolean;
  95. FDisplayCount: Integer;
  96. FLockForm: Boolean;
  97. // 数据库管理
  98. FReportCon: TReportConnection;
  99. // 报表数据准备
  100. FReportDataPrepare: TReportPrepare;
  101. procedure InitPageSettings;
  102. procedure InitFont;
  103. procedure InitPaperSettings(ATemplate: TTemplateNode);
  104. function GetHintStr: string;
  105. function AddClassNode(AParent: TExTreeNode; const AName: string): TExTreeNode;
  106. function GetClassNode(ANode: TTemplateNode): TExTreeNode;
  107. function GetSubClassNode(AClassNode: TExTreeNode; ANode: TTemplateNode): TExTreeNode;
  108. procedure AddReportTemplate(ANode: TTemplateNode);
  109. procedure LoadReportTemplets;
  110. procedure SaveAuditOpinion(ATemplate: TTemplateNode);
  111. procedure SaveReportInteractData(ATemplate: TTemplateNode);
  112. procedure ResizePreviewBox;
  113. procedure PreviewReportCurPage;
  114. procedure RepaintCurPagePreview;
  115. procedure LoadTemplet(ATemplate: TTemplateNode);
  116. procedure LoadTempletAndDisplay;
  117. procedure BeforeExport;
  118. procedure AfterExport;
  119. procedure LoadExcelBorder(var Border : TColumnLineRec);
  120. procedure PrintReport(ATemplateNode: TTemplateNode; isPDF, isExcel: boolean;
  121. ExcelOutputName, TemplateFileName: string);
  122. procedure ExportXlsReport(AStartPage, AEndPage: Integer; const AFileName: string);
  123. procedure ExportCurXlsReport;
  124. procedure ExportAllSelectedXlsReports;
  125. procedure PrintAllSelectedReports;
  126. procedure ExportAllSelectedPDFReports;
  127. procedure SetProjectData(const Value: TProjectData);
  128. procedure SetCurPage(const Value: Integer);
  129. function GetPrintEndPage: Integer;
  130. function GetPrintStartPage: Integer;
  131. function GetPageCount: Integer;
  132. function GetPrecededCount: Integer;
  133. function GetExcelMode: TOutputExcelMode;
  134. function GetIsExcel2010: Boolean;
  135. public
  136. destructor Destroy; override;
  137. procedure InitFormView;
  138. procedure InitReportSettings(ATemplate: TTemplateNode = nil);
  139. property ProjectData: TProjectData read FProjectData write SetProjectData;
  140. // 当前预览的页码
  141. property CurPage: Integer read FCurPage write SetCurPage;
  142. // 显示几页
  143. property DisplayCount: Integer read FDisplayCount write FDisplayCount;
  144. // 翻到的页数(例如:当前显示9页,显示4页,则翻到的页数为3)
  145. property PrecededCount: Integer read GetPrecededCount;
  146. property PrintStartPage: Integer read GetPrintStartPage;
  147. property PrintEndPage: Integer read GetPrintEndPage;
  148. property PageCount: Integer read GetPageCount;
  149. property ExcelMode: TOutputExcelMode read GetExcelMode;
  150. property IsExcel2010: Boolean read GetIsExcel2010;
  151. property LockForm: Boolean read FLockForm write FLockForm;
  152. end;
  153. procedure DisplayReportsForm(AProjectData: TProjectData);
  154. implementation
  155. uses
  156. UtilMethods, Math, DirectPrintUnit, Globals, ZhAPI, ReportAdjustFrm,
  157. Contnrs, mEncryptUnit, Printers, WinSpool, MainFrm, ConstUnit,
  158. GclBillsGatherModel;
  159. {$R *.dfm}
  160. procedure DisplayReportsForm(AProjectData: TProjectData);
  161. var
  162. ReportsForm: TReportsForm;
  163. begin
  164. ReportsForm := TReportsForm.Create(nil);
  165. {ReportsForm.BorderIcons := ReportsForm.BorderIcons - [biMaximize];
  166. ReportsForm.WindowState := wsMaximized;}
  167. ReportsForm.ProjectData := AProjectData;
  168. ReportsForm.InitReportSettings;
  169. ReportsForm.InitFormView;
  170. try
  171. ReportsForm.ShowModal;
  172. finally
  173. ReportsForm.Free;
  174. AProjectData.ClearReportCacheData;
  175. end;
  176. end;
  177. { TReportsForm }
  178. procedure TReportsForm.LoadReportTemplets;
  179. var
  180. iTemplate: Integer;
  181. TemplateNode: TTemplateNode;
  182. ClassNode: TExTreeNode;
  183. begin
  184. extvReport.Items.Clear;
  185. for iTemplate := 0 to ReportTemplateManager.Count - 1 do
  186. begin
  187. TemplateNode := ReportTemplateManager.Template[iTemplate];
  188. AddReportTemplate(TemplateNode);
  189. end;
  190. extvReport.AlphaSort;
  191. // 强制展开全部节点
  192. // 某些情况下,创建节点处的展开方法失效
  193. ClassNode := extvReport.Items.GetFirstNode;
  194. while Assigned(ClassNode) do
  195. begin
  196. ClassNode.ForcedExpand(True);
  197. ClassNode := ClassNode.getNextSibling;
  198. end;
  199. extvReport.Selected := extvReport.Items.GetFirstNode;
  200. end;
  201. procedure TReportsForm.LoadTempletAndDisplay;
  202. procedure ResetReportsVariant;
  203. var
  204. iPage: Integer;
  205. begin
  206. FbNormal := False;
  207. xcbPages.Items.Clear;
  208. for iPage := 1 to PreviewComXML.TotalPages do
  209. xcbPages.Items.Add(IntToStr(iPage));
  210. xcbStartPage.Items.Assign(xcbPages.Items);
  211. xcbStartPage.ItemIndex := 0;
  212. xcbEndPage.Items.Assign(xcbPages.Items);
  213. xcbEndPage.ItemIndex := xcbEndPage.Items.Count - 1;
  214. xlbRealSize.Down := True;
  215. DisplayCount := 1;
  216. CurPage := 1;
  217. end;
  218. procedure WaringAndEmptyPreview(AStr: string);
  219. var
  220. OldBrushColor, OldPenColor: TColor;
  221. begin
  222. TipMessage(AStr, Handle);
  223. OldBrushColor := PreviewBox.Canvas.Brush.Color;
  224. OldPenColor := PreviewBox.Canvas.Pen.Color;
  225. try
  226. PreviewBox.Canvas.Brush.Color := clBtnFace;
  227. PreviewBox.Canvas.Pen.Color := clBlack;
  228. PreviewBox.Canvas.Rectangle(PreviewBox.BoundsRect);
  229. finally
  230. PreviewBox.Canvas.Brush.Color := OldBrushColor;
  231. PreviewBox.Canvas.Pen.Color := OldPenColor;
  232. end;
  233. end;
  234. procedure PreviewTemplet;
  235. begin
  236. try
  237. ResizePreviewBox;
  238. ResetReportsVariant;
  239. except
  240. WaringAndEmptyPreview('当前报表显示可能存在问题,请与纵横客服中心联系:(0756)3850888。');
  241. end;
  242. end;
  243. procedure LoadEmptyTempletAndDisplay;
  244. begin
  245. WaringAndEmptyPreview('报表无数据,请选择其他报表。');
  246. end;
  247. var
  248. vTemplateNode: TTemplateNode;
  249. pNode: PTemplateNode;
  250. begin
  251. if not Assigned(extvReport.Selected) then Exit;
  252. vTemplateNode := TTemplateNode(extvReport.Selected.Data);
  253. if not Assigned(vTemplateNode) then Exit;
  254. ReportTemplateManager.Current := vTemplateNode;
  255. // 交互表
  256. if vTemplateNode.InteractFlag <> 0 then
  257. SaveReportInteractData(vTemplateNode);
  258. // 准备额外数据
  259. if vTemplateNode.DataPrepareFlag <> 0 then
  260. FReportDataPrepare.PrepareData(vTemplateNode.DataPrepareFlag);
  261. FReportCon.RefreshConnection(vTemplateNode);
  262. Screen.Cursor := crHourGlass;
  263. try
  264. LoadTemplet(vTemplateNode);
  265. if PreviewComXML.TotalPages > 0 then
  266. PreviewTemplet
  267. else
  268. LoadEmptyTempletAndDisplay;
  269. finally
  270. Screen.Cursor := crDefault;
  271. end;
  272. end;
  273. procedure TReportsForm.SetProjectData(const Value: TProjectData);
  274. begin
  275. FProjectData := Value;
  276. FReportDataPrepare := TReportPrepare.Create(FProjectData);
  277. FReportCon := TReportConnection.Create(FProjectData);
  278. extvReport.Selected := extvReport.Items[0];
  279. LoadReportTemplets;
  280. LoadTempletAndDisplay;
  281. end;
  282. procedure TReportsForm.PreviewComXMLGetDataConnection(
  283. var ADOCon: TADOConnection);
  284. begin
  285. ADOCon := FReportCon.Connection;
  286. end;
  287. procedure TReportsForm.PreviewReportCurPage;
  288. begin
  289. if FbNormal then
  290. PreviewComXML.PrintPreviewCanvas(-1, PrecededCount, PreviewBox.Canvas)
  291. else //强制1:1显示
  292. PreviewComXML.PrintPreviewCanvas(CurPage, 0, PreviewBox.Canvas);
  293. end;
  294. procedure TReportsForm.ResizePreviewBox;
  295. var
  296. iHeight, iWidth: Integer;
  297. begin
  298. if FbNormal then
  299. begin
  300. iHeight := sbReportsPreview.ClientHeight;
  301. iWidth := sbReportsPreview.ClientWidth;
  302. end
  303. else
  304. begin
  305. iHeight := Max(PreviewComXML.PrintHeight + 20, sbReportsPreview.ClientHeight);
  306. iWidth := Max(PreviewComXML.PrintWidth + 20, sbReportsPreview.ClientWidth);
  307. end;
  308. if PreviewBox.Height <> iHeight then
  309. begin
  310. PreviewBox.Height := iHeight;
  311. PreviewBox.Picture.Bitmap.Height := iHeight;
  312. end;
  313. if PreviewBox.Width <> iWidth then
  314. begin
  315. PreviewBox.Width := iWidth;
  316. PreviewBox.Picture.Bitmap.Width := iWidth;
  317. end;
  318. end;
  319. procedure TReportsForm.RepaintCurPagePreview;
  320. begin
  321. ResizePreviewBox;
  322. PreviewReportCurPage;
  323. end;
  324. procedure TReportsForm.xlbRealSizeClick(Sender: TObject);
  325. begin
  326. FbNormal := False;
  327. DisplayCount := TdxBarLargeButton(Sender).Tag;
  328. RepaintCurPagePreview;
  329. end;
  330. procedure TReportsForm.xlbOnePageClick(Sender: TObject);
  331. begin
  332. PreviewComXML.PreviewRows := 1;
  333. PreviewComXML.PreviewCols := 1;
  334. DisplayCount := TdxBarLargeButton(Sender).Tag;
  335. FbNormal := True;
  336. RepaintCurPagePreview;
  337. end;
  338. procedure TReportsForm.xlbTwoPageClick(Sender: TObject);
  339. begin
  340. if PreviewComXML.ReportSize.X > PreviewComXML.ReportSize.Y then
  341. begin
  342. PreviewComXML.PreviewRows := 2;
  343. PreviewComXML.PreviewCols := 1;
  344. end
  345. else
  346. begin
  347. PreviewComXML.PreviewRows := 1;
  348. PreviewComXML.PreviewCols := 2;
  349. end;
  350. DisplayCount := TdxBarLargeButton(Sender).Tag;
  351. FbNormal := true;
  352. RepaintCurPagePreview;
  353. end;
  354. procedure TReportsForm.xlbFourPageClick(Sender: TObject);
  355. begin
  356. PreviewComXML.PreviewRows := 2;
  357. PreviewComXML.PreviewCols := 2;
  358. DisplayCount := TdxBarLargeButton(Sender).Tag;
  359. FbNormal := true;
  360. RepaintCurPagePreview;
  361. end;
  362. procedure TReportsForm.xlbFirstPageClick(Sender: TObject);
  363. begin
  364. CurPage := 1;
  365. end;
  366. procedure TReportsForm.SetCurPage(const Value: Integer);
  367. begin
  368. if (Value < 0) or (Value > PageCount) then Exit;
  369. FCurPage := Value;
  370. xcbPages.Text := IntToStr(FCurPage);
  371. //PreviewComXML.FillZero := chkFillZero.Checked;
  372. PreviewReportCurPage;
  373. end;
  374. function TReportsForm.GetPrintEndPage: Integer;
  375. begin
  376. Result := StrToIntDef(xcbEndPage.Text, 0);
  377. end;
  378. function TReportsForm.GetPrintStartPage: Integer;
  379. begin
  380. Result := StrToIntDef(xcbStartPage.Text, 0);
  381. end;
  382. function TReportsForm.GetPageCount: Integer;
  383. begin
  384. Result := PreviewComXML.TotalPages;
  385. end;
  386. function TReportsForm.GetPrecededCount: Integer;
  387. begin
  388. Result := (CurPage + (DisplayCount - 1)) div DisplayCount;
  389. end;
  390. procedure TReportsForm.xlbPrePageClick(Sender: TObject);
  391. begin
  392. if CurPage > 1 then
  393. CurPage := CurPage - 1;
  394. end;
  395. procedure TReportsForm.xlbNextPageClick(Sender: TObject);
  396. begin
  397. if CurPage < PageCount then
  398. CurPage := CurPage + 1;
  399. end;
  400. procedure TReportsForm.xlbLastPageClick(Sender: TObject);
  401. begin
  402. CurPage := PageCount;
  403. end;
  404. procedure TReportsForm.xcbPagesChange(Sender: TObject);
  405. begin
  406. if (StrToIntDef(xcbPages.Text, 0) > 0) and
  407. (StrToIntDef(xcbPages.Text, 0) <= PageCount) then
  408. CurPage := StrToIntDef(xcbPages.Text, 0)
  409. else
  410. xcbPages.Text := IntToStr(CurPage);
  411. end;
  412. procedure TReportsForm.xlbPrintCurPageClick(Sender: TObject);
  413. begin
  414. if _IsEncrypt or G_IsCloud then
  415. PreviewComXML.Print(CurPage, 1)
  416. else
  417. TipMessage(GetHintStr, Handle);
  418. end;
  419. procedure TReportsForm.xcbStartPageChange(Sender: TObject);
  420. begin
  421. if (StrToIntDef(TdxBarCombo(Sender).Text, 0) > 0) and
  422. (StrToIntDef(TdxBarCombo(Sender).Text, 0) <= PageCount) then
  423. TdxBarCombo(Sender).Tag := StrToIntDef(TdxBarCombo(Sender).Text, 0)
  424. else
  425. TdxBarCombo(Sender).Text := IntToStr(TdxBarCombo(Sender).Tag);
  426. end;
  427. procedure TReportsForm.xlbPrintClick(Sender: TObject);
  428. begin
  429. if _IsEncrypt or G_IsCloud then
  430. begin
  431. if extvReport.LeafCheckedCount > 0 then
  432. PrintAllSelectedReports
  433. else
  434. PreviewComXML.PrintMultiPages(PrintStartPage, PrintEndPage);
  435. end
  436. else
  437. TipMessage(GetHintStr, Handle);
  438. end;
  439. procedure TReportsForm.PrintAllSelectedReports;
  440. var
  441. iIndex: Integer;
  442. Node: TExTreeNode;
  443. vTemplateNode: TTemplateNode;
  444. begin
  445. for iIndex := 0 to extvReport.Items.Count - 1 do
  446. begin
  447. Node := extvReport.Items[iIndex];
  448. if Node.HasChildren or (Node.Checked <> csChecked) or (Node.Data = nil) then Continue;
  449. vTemplateNode := TTemplateNode(Node.Data);
  450. if FileExists(vTemplateNode.FileName) then
  451. directPrintReport(PreviewBox.Canvas, vTemplateNode.FileName,
  452. PreviewComXML, False, False, oemNormal,'','', IsExcel2010);
  453. end;
  454. extvReport.ClearChecked;
  455. end;
  456. procedure TReportsForm.xlbToPDFClick(Sender: TObject);
  457. begin
  458. if _IsEncrypt or G_IsCloud then
  459. begin
  460. if extvReport.LeafCheckedCount > 0 then
  461. ExportAllSelectedPDFReports
  462. else
  463. PreviewComXML.PrintPDF(PrintStartPage, PrintEndPage);
  464. end
  465. else
  466. TipMessage(GetHintStr, Handle);
  467. end;
  468. procedure TReportsForm.ExportAllSelectedPDFReports;
  469. var
  470. iIndex: Integer;
  471. Node: TExTreeNode;
  472. vTemplateNode: TTemplateNode;
  473. begin
  474. for iIndex := 0 to extvReport.Items.Count - 1 do
  475. begin
  476. Node := extvReport.Items[iIndex];
  477. if Node.HasChildren or (Node.Checked <> csChecked) or (Node.Data = nil) then Continue;
  478. vTemplateNode := TTemplateNode(Node.Data);
  479. if FileExists(vTemplateNode.FileName) then
  480. PrintReport(vTemplateNode, True, False,'','');
  481. end;
  482. extvReport.ClearChecked;
  483. end;
  484. procedure TReportsForm.xlbToExcelClick(Sender: TObject);
  485. begin
  486. if _IsEncrypt or G_IsCloud then
  487. begin
  488. if extvReport.LeafCheckedCount > 0 then
  489. ExportAllSelectedXlsReports
  490. else
  491. ExportCurXlsReport;
  492. end
  493. else
  494. TipMessage(GetHintStr, Handle);
  495. end;
  496. procedure TReportsForm.ExportAllSelectedXlsReports;
  497. var
  498. iIndex: Integer;
  499. Node: TExTreeNode;
  500. vTemplateNode: TTemplateNode;
  501. sPath, sOutputFileName: String;
  502. begin
  503. if BrowseFolder(sPath, '请选择导出报表路径', Handle) then
  504. begin
  505. for iIndex := 0 to extvReport.Items.Count - 1 do
  506. begin
  507. Node := extvReport.Items[iIndex];
  508. if Node.HasChildren or (Node.Checked <> csChecked) or (Node.Data = nil) then Continue;
  509. vTemplateNode := TTemplateNode(Node.Data);
  510. sOutputFileName := sPath + ExtractSimpleFileName(vTemplateNode.FileName) + '.xls';
  511. if FileExists(vTemplateNode.FileName) then
  512. PrintReport(vTemplateNode, False, True, sOutputFileName, GetTemplateXlsFileName);
  513. end;
  514. extvReport.ClearChecked;
  515. end;
  516. end;
  517. procedure TReportsForm.ExportCurXlsReport;
  518. var
  519. sFileName: string;
  520. begin
  521. sFileName := extvReport.Selected.Text;
  522. if (PrintStartPage <= PrintEndPage) and SaveFile(sFileName, '.xls') then
  523. ExportXlsReport(PrintStartPage, PrintEndPage, sFileName);
  524. end;
  525. procedure TReportsForm.AfterExport;
  526. begin
  527. // ToDo - 关闭进度条
  528. // ToDo - 取消设置Update进度条事件
  529. // PreviewComXML.OnProgress := nil;
  530. Screen.Cursor := crDefault;
  531. end;
  532. procedure TReportsForm.BeforeExport;
  533. begin
  534. Screen.Cursor := crHourGlass;
  535. // ToDo - 设置Update进度条事件
  536. // PreviewComXML.OnProgress := PreviewComXMLProgress;
  537. // ToDo - 打开进度条
  538. end;
  539. function TReportsForm.GetExcelMode: TOutputExcelMode;
  540. begin
  541. if chkExcelMode.Checked then
  542. Result := oemOneSheet
  543. else
  544. Result := oemNormal;
  545. end;
  546. procedure TReportsForm.extvReportClick(Sender: TObject);
  547. begin
  548. LoadTempletAndDisplay;
  549. end;
  550. procedure TReportsForm.xlbCloseClick(Sender: TObject);
  551. begin
  552. Close;
  553. end;
  554. procedure TReportsForm.AddReportTemplate(ANode: TTemplateNode);
  555. var
  556. vClassNode, vNode: TExTreeNode;
  557. begin
  558. vClassNode := GetClassNode(ANode);
  559. if ANode.SubClassNum <> '' then
  560. vClassNode := GetSubClassNode(vClassNode, ANode);
  561. vNode := extvReport.Items.AddChildObject(vClassNode, ANode.TemplateName, Pointer(ANode));
  562. vNode.ImageIndex := 2;
  563. vNode.SelectedIndex := 3;
  564. vNode.Checked := csUnchecked;
  565. if (vClassNode <> nil) and not vClassNode.Expanded then
  566. vClassNode.Expanded := True;
  567. end;
  568. function TReportsForm.GetClassNode(ANode: TTemplateNode): TExTreeNode;
  569. function FindClassNode(const AName: string): TExTreeNode;
  570. var
  571. I: Integer;
  572. vNode: TExTreeNode;
  573. begin
  574. Result := nil;
  575. for I := 0 to extvReport.Items.Count - 1 do
  576. begin
  577. vNode := extvReport.Items.Item[I];
  578. if SameText(vNode.Text, AName) then
  579. begin
  580. Result := vNode;
  581. Break;
  582. end;
  583. end;
  584. end;
  585. begin
  586. Result := FindClassNode(ANode.ClassNum + '.' + ANode.ClassName);
  587. if not Assigned(Result) then
  588. Result := AddClassNode(nil, ANode.ClassNum + '.' + ANode.ClassName);
  589. end;
  590. procedure TReportsForm.tbImportSrtClick(Sender: TObject);
  591. procedure ImportReportTemplate(const AFileName: string);
  592. var
  593. sNewFileName: string;
  594. vTemplateNode: TTemplateNode;
  595. begin
  596. sNewFileName := GetReportTemplatePath + ExtractFileName(AFileName);
  597. if not FileExists(sNewFileName) then
  598. begin
  599. CopyFile(PChar(AFileName), PChar(sNewFileName), True);
  600. vTemplateNode := ReportTemplateManager.AddReportTemplate(sNewFileName);
  601. AddReportTemplate(vTemplateNode);
  602. end
  603. else
  604. if QuestMessage('已存在报表模板' + ExtractFileName(AFileName) + ',是否覆盖原模板?', Handle) then
  605. CopyFile(PChar(AFileName), PChar(sNewFileName), False)
  606. else
  607. Exit;
  608. end;
  609. var
  610. sgsFiles: TStrings;
  611. iFile: Integer;
  612. begin
  613. sgsFiles := TStringList.Create;
  614. try
  615. if SelectFiles(sgsFiles, '.srt') then
  616. begin
  617. for iFile := 0 to sgsFiles.Count - 1 do
  618. ImportReportTemplate(sgsFiles.Strings[iFile]);
  619. end;
  620. finally
  621. sgsFiles.Free;
  622. end;
  623. end;
  624. procedure TReportsForm.tbDeleteSrtClick(Sender: TObject);
  625. var
  626. vTemplateNode: TTemplateNode;
  627. begin
  628. if not Assigned(extvReport.Selected) then Exit;
  629. vTemplateNode := TTemplateNode(extvReport.Selected.Data);
  630. if not Assigned(vTemplateNode) then Exit;
  631. extvReport.Items.Delete(extvReport.Selected);
  632. DeleteFile(vTemplateNode.FileName);
  633. ReportTemplateManager.DeleteReportTemplate(vTemplateNode);
  634. LoadTempletAndDisplay;
  635. end;
  636. procedure TReportsForm.tbExportSrtClick(Sender: TObject);
  637. var
  638. vTemplateNode: TTemplateNode;
  639. sFileName: string;
  640. begin
  641. if not Assigned(extvReport.Selected) then Exit;
  642. vTemplateNode := TTemplateNode(extvReport.Selected.Data);
  643. if not Assigned(vTemplateNode) then Exit;
  644. sFileName := vTemplateNode.TemplateName;
  645. if SaveFile(sFileName, '.srt') then
  646. begin
  647. if not FileExists(sFileName) or QuestMessage('存在同名文件,是否覆盖?', Handle) then
  648. CopyFile(PChar(vTemplateNode.FileName), PChar(sFileName), False);
  649. end;
  650. end;
  651. procedure TReportsForm.PreviewComXMLContentDisplay(
  652. var contentFontRec: TFontRec; dataType: Integer; isReading: Boolean;
  653. DrawType: Integer; isPrinting: Boolean);
  654. begin
  655. if ReportConfig.ContentIsNarrow then
  656. begin
  657. if (isReading) then
  658. begin
  659. begin
  660. contentFontRec.FontName := 'Arial Narrow';
  661. contentFontRec.FontHeight := Round(ReportConfig.ContentFont.Size*4/3) * 4 div 3;
  662. end;
  663. end else
  664. begin
  665. if (DrawType = 3) or (DrawType = 5) then
  666. begin
  667. contentFontRec.FontHeight := Round(ReportConfig.ContentFont.Size*4/3);
  668. end else if (isPrinting) then
  669. begin
  670. contentFontRec.FontName := 'Arial Narrow';
  671. contentFontRec.FontHeight := Round(ReportConfig.ContentFont.Size*4/3) * 7 div 6;
  672. end else
  673. begin
  674. contentFontRec.FontHeight := Round(ReportConfig.ContentFont.Size*4/3) * 4 div 3;
  675. end;
  676. end;
  677. end;
  678. end;
  679. procedure TReportsForm.xlbSetupClick(Sender: TObject);
  680. begin
  681. if AdjustReport then
  682. LoadTempletAndDisplay;
  683. end;
  684. procedure TReportsForm.InitReportSettings(ATemplate: TTemplateNode);
  685. begin
  686. PreviewComXML.FillZero := chkFillZero.Checked;
  687. InitPageSettings;
  688. InitPaperSettings(ATemplate);
  689. end;
  690. procedure TReportsForm.InitPageSettings;
  691. begin
  692. // 设置页面大小
  693. PreviewComXML.setPageSize(ReportConfig.PageSize);
  694. // 设置边距
  695. PreviewComXML.setEdge(0, '', ReportConfig.LeftEdge/10);
  696. PreviewComXML.setEdge(1, '', ReportConfig.RightEdge/10);
  697. PreviewComXML.setEdge(2, '', ReportConfig.UpEdge/10);
  698. PreviewComXML.setEdge(3, '', ReportConfig.DownEdge/10);
  699. end;
  700. procedure TReportsForm.InitPaperSettings(ATemplate: TTemplateNode);
  701. procedure InitRepBorderLine;
  702. var
  703. i: Integer;
  704. ObjList : TList;
  705. ShapeRec : PPicRec;
  706. begin
  707. ObjList := TList.Create;
  708. try
  709. PreviewComXML.getAllShapeObjs(1, ObjList);
  710. for i := 0 to ObjList.Count - 1 do
  711. begin
  712. ShapeRec := ObjList[i];
  713. // 设置报表边框线粗
  714. ShapeRec.PenWidth := ReportConfig.BorderLine;
  715. // 设置是否绘制报表边框横线
  716. if (ShapeRec.ExArea.ExLeft <> ShapeRec.ExArea.ExRight) then
  717. begin
  718. if not ReportConfig.RepBorderUnderLine then
  719. ShapeRec.PenStyle := integer(psClear)
  720. else
  721. ShapeRec.PenStyle := integer(psSolid);
  722. end;
  723. // 设置是否绘制报表边框竖线
  724. if (ShapeRec.ExArea.ExTop <> ShapeRec.ExArea.ExBottom) and
  725. ((ShapeRec.ExArea.ExLeft = 0) or (ShapeRec.ExArea.ExLeft = 100)) then
  726. begin //这里的判断条件是约定好的
  727. if not ReportConfig.RepBorderVerLine then
  728. ShapeRec.PenStyle := integer(psClear)
  729. else
  730. ShapeRec.PenStyle := integer(psSolid)
  731. end;
  732. PreviewComXML.setShapeObj(ShapeRec);
  733. end;
  734. finally
  735. ObjList.Free;
  736. end;
  737. end;
  738. procedure InitRepCellLine;
  739. var
  740. i: Integer;
  741. ObjList : TList;
  742. ColumnRec : PColumnRec;
  743. FlowContentRec : PContentRec;
  744. CrossContentRec : PCrossContentRec;
  745. begin
  746. ObjList := TList.Create;
  747. try
  748. PreviewComXML.getAllFlowShowContentObjs(ObjList);
  749. // 设置报表表格横线
  750. for i := 0 to ObjList.Count - 1 do
  751. begin
  752. FlowContentRec := ObjList[i];
  753. FlowContentRec.LineInfo.TopThick := ReportConfig.CellHorLineWidth;
  754. FlowContentRec.LineInfo.BottomThick := ReportConfig.CellHorLineWidth;
  755. PreviewComXML.setFlowContentObj(FlowContentRec);
  756. end;
  757. PreviewComXML.getAllCrossContentObjs(ObjList);
  758. for i := 0 to ObjList.Count - 1 do
  759. begin
  760. CrossContentRec := ObjList[i];
  761. CrossContentRec.CrossContent.LineInfo.TopThick := ReportConfig.CellHorLineWidth;
  762. CrossContentRec.CrossContent.LineInfo.BottomThick := ReportConfig.CellHorLineWidth;
  763. PreviewComXML.setCrossContentObj(CrossContentRec);
  764. end;
  765. // 设置报表表格竖线
  766. PreviewComXML.getAllFlowShowContentObjs(ObjList);
  767. for i := 0 to ObjList.Count - 1 do
  768. begin
  769. FlowContentRec := ObjList[i];
  770. FlowContentRec.LineInfo.LeftThick := ReportConfig.CellVerLineWidth;
  771. FlowContentRec.LineInfo.RightThick := ReportConfig.CellVerLineWidth;
  772. // 如果设置无表格边框线,则两端的表格竖线线粗为0
  773. if (not ReportConfig.RepBorderVerLine) then
  774. if (i = 0) then
  775. FlowContentRec.LineInfo.LeftThick := 0
  776. else if (i = ObjList.Count - 1) then
  777. FlowContentRec.LineInfo.RightThick := 0;
  778. PreviewComXML.setFlowContentObj(FlowContentRec);
  779. end;
  780. PreviewComXML.getAllCrossContentObjs(ObjList);
  781. for i := 0 to ObjList.Count - 1 do
  782. begin
  783. CrossContentRec := ObjList[i];
  784. CrossContentRec.CrossContent.LineInfo.LeftThick := ReportConfig.CellVerLineWidth;
  785. CrossContentRec.CrossContent.LineInfo.RightThick := ReportConfig.CellVerLineWidth;
  786. ColumnRec := CrossContentRec.CrossContent.Column;
  787. //这里还要判断如果没有边框竖线的情况下,表格竖线边缘的线粗也为0
  788. //前提是所属表栏最右位置位于边缘
  789. if (not ReportConfig.RepBorderVerLine) and (ColumnRec<>nil) and
  790. ((ColumnRec.ExArea.ExRight = 100.0) or (ColumnRec.ExArea.ExLeft = 0.0)) then
  791. begin
  792. case CrossContentRec.CrossType of
  793. 0 : //交叉行
  794. begin
  795. if (CrossContentRec.CrossContent.ExArea.ExLeft = ColumnRec.ExArea.ExLeft ) then
  796. CrossContentRec.CrossContent.LineInfo.LeftThick := 0;
  797. if (CrossContentRec.CrossContent.ExArea.ExRight = ColumnRec.ExArea.ExRight ) then
  798. CrossContentRec.CrossContent.LineInfo.RightThick := 0;
  799. end;
  800. 1 : //交叉列
  801. begin
  802. if (CrossContentRec.CrossContent.ExArea.ExLeft = ColumnRec.ExArea.ExLeft ) then
  803. CrossContentRec.CrossContent.LineInfo.LeftThick := 0;
  804. if (CrossContentRec.CrossContent.ExArea.ExRight = ColumnRec.ExArea.ExRight ) then
  805. CrossContentRec.CrossContent.LineInfo.RightThick := 0;
  806. //(*
  807. if (CrossContentRec.CrossContent.isSpecialBorder) then
  808. begin
  809. if (CrossContentRec.CrossContent.ExArea.ExRight = ColumnRec.ExArea.ExRight ) then
  810. CrossContentRec.CrossContent.SpecialLineInfo.RightThick := 0;
  811. end;
  812. //*)
  813. end;
  814. 2 : //显示数据
  815. begin
  816. if (CrossContentRec.CrossContent.ExArea.ExLeft = ColumnRec.ExArea.ExLeft ) then
  817. CrossContentRec.CrossContent.LineInfo.LeftThick := 0;
  818. if (CrossContentRec.CrossContent.ExArea.ExRight = ColumnRec.ExArea.ExRight ) then
  819. CrossContentRec.CrossContent.LineInfo.RightThick := 0;
  820. end;
  821. 3 : //固定LABEL
  822. begin
  823. if (CrossContentRec.CrossContent.ExArea.ExLeft = ColumnRec.ExArea.ExLeft ) then
  824. CrossContentRec.CrossContent.LineInfo.LeftThick := 0;
  825. if (CrossContentRec.CrossContent.ExArea.ExRight = ColumnRec.ExArea.ExRight ) then
  826. CrossContentRec.CrossContent.LineInfo.RightThick := 0;
  827. end;
  828. 4 : //序号
  829. begin
  830. if (CrossContentRec.CrossContent.ExArea.ExLeft = ColumnRec.ExArea.ExLeft ) then
  831. CrossContentRec.CrossContent.LineInfo.LeftThick := 0;
  832. if (CrossContentRec.CrossContent.ExArea.ExRight = ColumnRec.ExArea.ExRight ) then
  833. CrossContentRec.CrossContent.LineInfo.RightThick := 0;
  834. end;
  835. 5 : //横向统计
  836. begin
  837. if (CrossContentRec.CrossContent.ExArea.ExLeft = ColumnRec.ExArea.ExLeft ) then
  838. CrossContentRec.CrossContent.LineInfo.LeftThick := 0;
  839. if (CrossContentRec.CrossContent.ExArea.ExRight = ColumnRec.ExArea.ExRight ) then
  840. CrossContentRec.CrossContent.LineInfo.RightThick := 0;
  841. end;
  842. end;
  843. end;
  844. PreviewComXML.setCrossContentObj(CrossContentRec);
  845. end;
  846. finally
  847. ObjList.Free;
  848. end;
  849. end;
  850. procedure InitOtherArea;
  851. procedure SetPTRBorder(PTR : PTextRec);
  852. procedure SetLeftRightBorder;
  853. begin
  854. if PTR.ExArea.ExLeft = 0.0 then
  855. begin
  856. if BorderWidth = 0.0 then
  857. PTR.LineInfo.LeftThick := ReportConfig.BorderUnderLineWidth;
  858. end;
  859. if PTR.ExArea.ExRight = 100.0 then
  860. begin
  861. if BorderWidth = 0.0 then
  862. PTR.LineInfo.RightThick := ReportConfig.BorderUnderLineWidth
  863. end;
  864. end;
  865. procedure SetHorLine;
  866. begin
  867. if (PTR.LineInfo.TopThick >= 0.2) and (BorderWidth <= 0.2) then
  868. PTR.LineInfo.TopThick := ReportConfig.CellHorLineWidth;
  869. if (PTR.LineInfo.BottomThick >= 0.2) and (BorderWidth <= 0.2) then
  870. PTR.LineInfo.BottomThick := ReportConfig.CellHorLineWidth;
  871. end;
  872. begin
  873. SetLeftRightBorder;
  874. SetHorLine;
  875. end;
  876. procedure SetPCRBorder(PCR : PColumnRec);
  877. procedure SetLeftRightBorder;
  878. begin
  879. if PCR.ExArea.ExLeft = 0.0 then
  880. begin
  881. if BorderWidth = 0.0 then
  882. PCR.LineInfo.LeftThick := ReportConfig.BorderUnderLineWidth
  883. end;
  884. if PCR.ExArea.ExRight = 100.0 then
  885. begin
  886. if BorderWidth = 0.0 then
  887. PCR.LineInfo.RightThick := ReportConfig.BorderUnderLineWidth;
  888. end;
  889. end;
  890. procedure SetVerLine;
  891. begin
  892. if PCR.ExArea.ExLeft = 0.0 then
  893. PCR.LineInfo.LeftThick := ReportConfig.CellVerLineWidth;
  894. if PCR.ExArea.ExRight = 100.0 then
  895. PCR.LineInfo.RightThick := ReportConfig.CellVerLineWidth;
  896. end;
  897. procedure SetHorLine;
  898. begin
  899. if (PCR.LineInfo.TopThick >= 0.2) and (BorderWidth <= 0.2) then
  900. PCR.LineInfo.TopThick := ReportConfig.CellHorLineWidth;
  901. if (PCR.LineInfo.BottomThick >= 0.2) and (BorderWidth <= 0.2) then
  902. PCR.LineInfo.BottomThick := ReportConfig.CellHorLineWidth;
  903. end;
  904. begin
  905. SetLeftRightBorder;
  906. SetVerLine;
  907. SetHorLine;
  908. end;
  909. var i,k : integer;
  910. ObjList : TList;
  911. ActAreaRec : PActiveAreaRec;
  912. PSR : PShowElementRec;
  913. begin
  914. ObjList := TList.Create;
  915. try
  916. ActAreaRec := nil;
  917. PreviewComXML.getAllActAreaObjs(ObjList);
  918. for i := 0 to ObjList.Count - 1 do
  919. begin
  920. ActAreaRec := ObjList[i];
  921. if (ActAreaRec.ShowType < 0) or (ActAreaRec.ShowType > 2) then Continue;
  922. if not Assigned(ActAreaRec.ElementList) then Continue;
  923. for k := 0 to ActAreaRec.ElementList.Count - 1 do
  924. begin
  925. PSR := PShowElementRec(ActAreaRec.ElementList[k]);
  926. case PSR.ElementType of
  927. 0..2 : SetPTRBorder(PSR.Data); //文本,参数,字段,表栏
  928. 7 : SetPCRBorder(PSR.Data) //Column
  929. end;
  930. PreviewComXML.setActShowElementObj(PSR);
  931. end;
  932. end;
  933. finally
  934. ObjList.Free;
  935. end;
  936. end;
  937. begin
  938. if not Assigned(ATemplate) or (ATemplate.SelfFormat = 0) then
  939. begin
  940. InitFont; // 各类字体
  941. InitRepBorderLine; // 报表边框
  942. InitRepCellLine; // 报表表格
  943. InitOtherArea; // 活动区域
  944. end;
  945. end;
  946. procedure TReportsForm.PreviewComXMLCrossTabLabelShow(valIDX: Integer;
  947. var ExLeft, ExRight: Double; var isShow: Boolean;
  948. CrsTabShowType: Integer);
  949. var field : PFieldRec;
  950. begin
  951. if (CrsTabShowType = -1) then exit;
  952. field := PreviewComXML.getFieldByID(6);
  953. if (field <> nil) then
  954. begin
  955. if (field.DataLen > valIDX) and (valIDX >= 0) then
  956. begin
  957. if (field.Value[valIDX] = 1.5) then
  958. begin
  959. case CrsTabShowType of
  960. 1 : begin
  961. isShow := false;
  962. end;
  963. 2 : begin
  964. ExLeft := 0;
  965. ExRight := 100;
  966. end;
  967. 3 : begin
  968. //
  969. end
  970. else
  971. begin
  972. //
  973. end;
  974. end;
  975. end;
  976. end;
  977. end;
  978. end;
  979. procedure TReportsForm.rdbtnA4Click(Sender: TObject);
  980. begin
  981. ReportConfig.PageSize := TRadioButton(Sender).Caption;
  982. SetPrinterPageSize(ReportConfig.PageSize);
  983. LoadTempletAndDisplay;
  984. end;
  985. procedure TReportsForm.chkFillZeroClick(Sender: TObject);
  986. begin
  987. PreviewComXML.FillZero := chkFillZero.Checked;
  988. PreviewReportCurPage;
  989. end;
  990. procedure TReportsForm.InitFont;
  991. procedure AssignFontRec(AFontRec: TFontRec; AFont: TFont);
  992. begin
  993. AFontRec.FontName := AFont.Name;
  994. AFontRec.FontHeight := Round(AFont.Size*4/3) ;
  995. AFontRec.FontBold := 400 + Integer(fsBold in AFont.Style)*200;
  996. AFontRec.FontItalic := Integer(fsItalic in AFont.Style);
  997. AFontRec.FontUnderLine := Integer(fsUnderLine in AFont.Style);
  998. end;
  999. procedure InitTitleFont;
  1000. var
  1001. TitleRec : PTitleRec;
  1002. begin
  1003. TitleRec := PreviewComXML.getTitleByID(1);
  1004. if TitleRec <> nil then
  1005. begin
  1006. AssignFontRec(TitleRec.FontRec, ReportConfig.TitleFont);
  1007. PreviewComXML.setTitleObj(TitleRec);
  1008. end;
  1009. end;
  1010. procedure InitColumnFont;
  1011. procedure InitColumnThick(AColumnRec: PColumnRec);
  1012. begin
  1013. if (ReportConfig.ReportCellLine > 0.2) then
  1014. begin
  1015. if (AColumnRec.LineInfo.LeftThick > 0.2) then
  1016. AColumnRec.LineInfo.LeftThick := ReportConfig.ReportCellLine;
  1017. if (AColumnRec.LineInfo.RightThick > 0.2) then
  1018. AColumnRec.LineInfo.RightThick := ReportConfig.ReportCellLine;
  1019. if (AColumnRec.LineInfo.TopThick > 0.2) then
  1020. AColumnRec.LineInfo.TopThick := ReportConfig.ReportCellLine;
  1021. if (AColumnRec.LineInfo.BottomThick > 0.2) then
  1022. AColumnRec.LineInfo.BottomThick := ReportConfig.ReportCellLine;
  1023. end;
  1024. end;
  1025. var
  1026. i, j: Integer;
  1027. ObjList: TList;
  1028. ColumnRec : PColumnRec;
  1029. AAR : PActiveAreaRec;
  1030. SER : PShowElementRec;
  1031. begin
  1032. ObjList := TList.Create;
  1033. try
  1034. PreviewComXML.getAllColumnHeadObjs(ObjList);
  1035. for i := 0 to ObjList.Count - 1 do
  1036. begin
  1037. ColumnRec := ObjList[i];
  1038. AssignFontRec(ColumnRec.FontRec, ReportConfig.ColumnFont);
  1039. InitColumnThick(ColumnRec);
  1040. PreviewComXML.setColumnHeadTailObj(0, ColumnRec);
  1041. end;
  1042. PreviewComXML.getAllColumnTailObjs(ObjList);
  1043. for i := 0 to ObjList.Count - 1 do
  1044. begin
  1045. ColumnRec := ObjList[i];
  1046. AssignFontRec(ColumnRec.FontRec, ReportConfig.ColumnFont);
  1047. InitColumnThick(ColumnRec);
  1048. PreviewComXML.setColumnHeadTailObj(1,ColumnRec);
  1049. end;
  1050. PreviewComXML.getAllActAreaObjs(ObjList);
  1051. for i := 0 to ObjList.Count - 1 do
  1052. begin
  1053. AAR := ObjList[i];
  1054. for j := 0 to AAR.ElementList.Count - 1 do
  1055. begin
  1056. SER := AAR.ElementList[j];
  1057. if (SER.ElementType = 7) then
  1058. begin
  1059. ColumnRec := SER.Data;
  1060. AssignFontRec(ColumnRec.FontRec, ReportConfig.ColumnFont);
  1061. InitColumnThick(ColumnRec);
  1062. PreviewComXML.setActShowElementObj(SER);
  1063. end;
  1064. end;
  1065. end;
  1066. finally
  1067. ObjList.Free;
  1068. end;
  1069. end;
  1070. procedure InitContentAndGatherFont;
  1071. var
  1072. i, j: Integer;
  1073. ObjList: TList;
  1074. FlowContentRec : PContentRec;
  1075. CrossContentRec : PCrossContentRec;
  1076. SumRec : PSumRec;
  1077. begin
  1078. ObjList := TList.Create;
  1079. try
  1080. // 设置表正文
  1081. PreviewComXML.getAllFlowShowContentObjs(ObjList);
  1082. for i := 0 to ObjList.Count - 1 do
  1083. begin
  1084. FlowContentRec := ObjList[i];
  1085. if not (FlowContentRec.Fixed) then
  1086. begin
  1087. AssignFontRec(FlowContentRec.FontRec, ReportConfig.ContentFont);
  1088. PreviewComXML.setFlowContentObj(FlowContentRec);
  1089. end;
  1090. end;
  1091. PreviewComXML.getAllBillShowContentObjs(ObjList);
  1092. for i := 0 to ObjList.Count - 1 do
  1093. begin
  1094. FlowContentRec := ObjList[i];
  1095. if not(FlowContentRec.Fixed) then
  1096. begin
  1097. AssignFontRec(FlowContentRec.FontRec, ReportConfig.ContentFont);
  1098. PreviewComXML.setBillContentObj(FlowContentRec);
  1099. end;
  1100. end;
  1101. PreviewComXML.getAllCrossContentObjs(ObjList);
  1102. for i := 0 to ObjList.Count - 1 do
  1103. begin
  1104. CrossContentRec := ObjList[i];
  1105. if not(CrossContentRec.CrossContent.Fixed) then
  1106. begin
  1107. AssignFontRec(CrossContentRec.CrossContent.FontRec, ReportConfig.ContentFont);
  1108. PreviewComXML.setCrossContentObj(CrossContentRec);
  1109. end;
  1110. end;
  1111. // 设置表合计
  1112. for i := 0 to 2 do
  1113. begin
  1114. PreviewComXML.getAllSumObjs(i,ObjList);
  1115. for j := 0 to ObjList.Count - 1 do
  1116. begin
  1117. SumRec := ObjList[j];
  1118. AssignFontRec(SumRec.FontRec, ReportConfig.GatherFont);
  1119. PreviewComXML.setSumObj(SumRec);
  1120. end;
  1121. end;
  1122. finally
  1123. ObjList.Free;
  1124. end;
  1125. end;
  1126. procedure InitGridHeaderFont;
  1127. var
  1128. i: Integer;
  1129. ObjList: TList;
  1130. HeadTailRec : PHeadRec;
  1131. begin
  1132. ObjList := TList.Create;
  1133. try
  1134. PreviewComXML.getAllHeadObjs(ObjList);
  1135. for i := 0 to ObjList.Count - 1 do
  1136. begin
  1137. HeadTailRec := ObjList[i];
  1138. AssignFontRec(HeadTailRec.FontRec, ReportConfig.GridHeaderFont);
  1139. PreviewComXML.setHeadTailObj(0, HeadTailRec);
  1140. end;
  1141. PreviewComXML.getAllTailObjs(ObjList);
  1142. for i := 0 to ObjList.Count - 1 do
  1143. begin
  1144. HeadTailRec := ObjList[i];
  1145. AssignFontRec(HeadTailRec.FontRec, ReportConfig.GridHeaderFont);
  1146. PreviewComXML.setHeadTailObj(1, HeadTailRec);
  1147. end;
  1148. finally
  1149. ObjList.Free;
  1150. end;
  1151. end;
  1152. begin
  1153. InitTitleFont;
  1154. InitColumnFont;
  1155. InitContentAndGatherFont;
  1156. InitGridHeaderFont;
  1157. end;
  1158. procedure TReportsForm.PreviewComXMLGetDatasetEvent(
  1159. DatasetInfo: PDatasetInfoRec; var ADataset: TDataSet);
  1160. begin
  1161. if DatasetInfo.ID = 0 then
  1162. ADataSet := MemoryReportManager.GetSqlResultDataSet(ReportTemplateManager.Current.InteractInfo.Sql, FProjectData)
  1163. else
  1164. ADataset := MemoryReportManager.GetMemoryDataSet(DatasetInfo.ID, FProjectData);
  1165. end;
  1166. function TReportsForm.GetIsExcel2010: Boolean;
  1167. begin
  1168. Result := chkExcel2010.Checked;
  1169. end;
  1170. procedure TReportsForm.InitFormView;
  1171. begin
  1172. rdbtnA3.Checked := SameText(rdbtnA3.Caption, ReportConfig.PageSize);
  1173. rdbtnA4.Checked := SameText(rdbtnA4.Caption, ReportConfig.PageSize);
  1174. SetPrinterPageSize(ReportConfig.PageSize);
  1175. end;
  1176. procedure TReportsForm.LoadExcelBorder(var Border: TColumnLineRec);
  1177. begin
  1178. Border.LeftThick := 0.5;
  1179. Border.TopThick := 0.5;
  1180. Border.RightThick := 0.5;
  1181. Border.BottomThick := 0.5;
  1182. if not ReportConfig.RepBorderVerLine then
  1183. begin
  1184. Border.LeftThick := 0;
  1185. Border.RightThick := 0;
  1186. end;
  1187. end;
  1188. procedure TReportsForm.PrintReport(ATemplateNode: TTemplateNode;
  1189. isPDF, isExcel: boolean; ExcelOutputName, TemplateFileName: string);
  1190. function CheckPrinterReady: Boolean;
  1191. var
  1192. PrinterHD: THandle;
  1193. NoJobs: Word;
  1194. s: LongWord;
  1195. Job_Info: Array[0..10] of Job_INFO_1;
  1196. cbNeeded: Cardinal;
  1197. cReturned: Cardinal;
  1198. ret: LongBool;
  1199. begin
  1200. if OpenPrinter(PChar(Printer.Printers[Printer.PrinterIndex]), PrinterHD, 0) then
  1201. begin
  1202. s := SizeOf(Job_Info);
  1203. cbNeeded := 0;
  1204. cReturned := 0;
  1205. NoJobs := 10;
  1206. ret := ENumJobs(PrinterHD, 0, NoJobs, 1, @Job_Info, s, cbNeeded, cReturned);
  1207. Result := not((cReturned > 0) and (Job_Info[0].TotalPages > 0));
  1208. end
  1209. else
  1210. Result := True;
  1211. end;
  1212. procedure PrintTemplet;
  1213. begin
  1214. if isPDF then
  1215. begin
  1216. PreviewComXML.PrintPDFAll;
  1217. while not CheckPrinterReady do
  1218. Sleep(1000);
  1219. end
  1220. else if not isExcel then
  1221. PreviewComXML.PrintAll(1)
  1222. else
  1223. ExportXlsReport(1, PreviewComXML.TotalPages, ExcelOutputName);
  1224. end;
  1225. var
  1226. strRptName : string;
  1227. begin
  1228. if not FileExists(ATemplateNode.FileName) then Exit;
  1229. ClearReportOprList;
  1230. ClearReportFuncList;
  1231. Screen.Cursor := crHourGlass;
  1232. try
  1233. LoadTemplet(ATemplateNode);
  1234. if PreviewComXML.TotalPages > 0 then
  1235. PrintTemplet
  1236. {else if strRptName <> '' then
  1237. begin
  1238. LoadTemplet(RptArchiverObj, strRptName);
  1239. PrintEmptyTemplet;
  1240. end;}
  1241. finally
  1242. Screen.Cursor := crDefault;
  1243. end;
  1244. end;
  1245. procedure TReportsForm.ExportXlsReport(AStartPage, AEndPage: Integer;
  1246. const AFileName: string);
  1247. procedure ExportPagesXlsReport(AStartPage, AEndPage: Integer; const AFileName: string);
  1248. var
  1249. Border : TColumnLineRec;
  1250. begin
  1251. LoadExcelBorder(Border);
  1252. if IsExcel2010 then
  1253. // 康博士代码中写批量打印是,用Printer.Canvas,打印当前时,用PreviewBox.Canvas。不懂为什么
  1254. PreViewComXML.OutputToExcelRangeXMLEx(PreviewBox.Canvas, AStartPage,
  1255. AEndPage, GetTemplateXlsFileName, AFileName, Border, ExcelMode)
  1256. else
  1257. PreViewComXML.OutputToExcelFile(PreviewBox.Canvas, AStartPage,
  1258. AEndPage, GetTemplateXlsFileName, AFileName, ExcelMode, Border);
  1259. end;
  1260. var
  1261. iStartPage, iEndPage, iCount: Integer;
  1262. sFileName: string;
  1263. begin
  1264. BeforeExport;
  1265. try
  1266. if (ExcelMode = oemNormal) and (PrintEndPage - PrintStartPage > 30) then
  1267. begin
  1268. iStartPage := PrintStartPage;
  1269. iEndPage := iStartPage + 19;
  1270. iCount := 1;
  1271. repeat
  1272. begin
  1273. sFileName := Format('%s[%d].xls', [ExtractSimpleFileName(AFileName), iCount]);
  1274. ExportPagesXlsReport(iStartPage, iEndPage, sFileName);
  1275. iStartPage := iStartPage + 20;
  1276. iEndPage := Min(iEndPage + 20, PrintEndPage);
  1277. Inc(iCount);
  1278. end
  1279. until iStartPage > iEndPage;
  1280. end
  1281. else
  1282. ExportPagesXlsReport(PrintStartPage, PrintEndPage, AFileName);
  1283. finally
  1284. AfterExport;
  1285. end;
  1286. end;
  1287. procedure TReportsForm.LoadTemplet(ATemplate: TTemplateNode);
  1288. var
  1289. RptArchiverObj: TReportArchiver;
  1290. Mem: TMemoryStream;
  1291. begin
  1292. RptArchiverObj := TReportArchiver.Create;
  1293. if ATemplate.IsMulti then
  1294. RptArchiverObj.FileName := ATemplate.MultiFileNames[FProjectData.PhaseIndex]
  1295. else
  1296. RptArchiverObj.FileName := ATemplate.FileName;
  1297. Mem := RptArchiverObj.Extract;
  1298. try
  1299. // 以下代码有顺序限制,不可修改,主要保证在不修改报表模板文件的基础上可以用户定制报表格式
  1300. // 私以为,原因在于这些设置修改后,并不能生效,需要保存再读取方可生效
  1301. // 读取报表模板
  1302. if not PreviewComXML.ReadReportStream(Mem) then Exit;
  1303. // 将报表设置中的数据覆盖掉原模板的数据
  1304. InitReportSettings(ATemplate);
  1305. // 保存
  1306. PreviewComXML.SaveToStream(Mem);
  1307. // 再次读取,使报表设置中的设置生效
  1308. PreviewComXML.ReadReportStream(Mem);
  1309. // ReadReportStream之后会将PreviewComXML的FillZero值赋为True,故再赋值一次
  1310. PreviewComXML.FillZero := chkFillZero.Checked;
  1311. PreviewComXML.ReadDBData;
  1312. PreviewComXML.AnalyseData;
  1313. finally
  1314. if Mem <> nil then
  1315. Mem.Free;
  1316. RptArchiverObj.Free;
  1317. end;
  1318. end;
  1319. function TReportsForm.GetHintStr: string;
  1320. begin
  1321. Result := #13#10 +
  1322. '对不起,学习版不提供报表打印、导出功能。'#13#10 +
  1323. #13#10 +
  1324. '以下为收费服务项目,请在必要时联系纵横:'#13#10 +
  1325. #13#10 +
  1326. '企业QQ:800003850 客服热线:(0756)3850888';
  1327. end;
  1328. function TReportsForm.GetSubClassNode(AClassNode: TExTreeNode;
  1329. ANode: TTemplateNode): TExTreeNode;
  1330. function FindNode(AParent: TExTreeNode; const AName: string): TExTreeNode;
  1331. var
  1332. I: Integer;
  1333. vNode: TExTreeNode;
  1334. begin
  1335. Result := nil;
  1336. if Assigned(AParent) then
  1337. vNode := AParent.getFirstChild
  1338. else
  1339. vNode := extvReport.Items.GetFirstNode;
  1340. while not Assigned(Result) and Assigned(vNode) do
  1341. begin
  1342. if SameText(vNode.Text, AName) then
  1343. Result := vNode;
  1344. vNode := vNode.getNextSibling;
  1345. end;
  1346. end;
  1347. begin
  1348. Result := FindNode(AClassNode, ANode.SubClassNum + '.' + ANode.SubClassName);
  1349. if not Assigned(Result) then
  1350. Result := AddClassNode(AClassNode, ANode.SubClassNum + '.' + ANode.SubClassName);
  1351. end;
  1352. function TReportsForm.AddClassNode(AParent: TExTreeNode;
  1353. const AName: string): TExTreeNode;
  1354. begin
  1355. Result := extvReport.Items.AddChildObject(AParent, AName, Pointer(nil));
  1356. Result.ImageIndex := 0;
  1357. Result.SelectedIndex := 1;
  1358. Result.Checked := csUnchecked;
  1359. Result.Expanded := True;
  1360. end;
  1361. procedure TReportsForm.SaveReportInteractData(ATemplate: TTemplateNode);
  1362. begin
  1363. case ATemplate.InteractFlag of
  1364. 1: SaveAuditOpinion(ATemplate);
  1365. end;
  1366. end;
  1367. procedure TReportsForm.SaveAuditOpinion(ATemplate: TTemplateNode);
  1368. var
  1369. SelectForm: TAuditSelctForm;
  1370. begin
  1371. SelectForm := TAuditSelctForm.Create(FProjectData, ATemplate);
  1372. try
  1373. if SelectForm.ShowModal = mrOk then
  1374. SelectForm.SaveAuditData;
  1375. finally
  1376. SelectForm.Free;
  1377. end;
  1378. end;
  1379. destructor TReportsForm.Destroy;
  1380. begin
  1381. FReportCon.Free;
  1382. FReportDataPrepare.Free;
  1383. inherited;
  1384. end;
  1385. end.