ReportManager.pas 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946
  1. unit ReportManager;
  2. interface
  3. uses
  4. rmGclBillsBGDm, rmGclBillsCompareDm, rmGridHeaderDm, rmFxBillsCompareDm,
  5. rmBGLExecutionDm, rmGclBillsAddDm, rmFxBillsAddDm, rmBillsGatherDm,
  6. rmGclBillsAuditCompareDm, rmDealInfosDm, rmXmjBGLDetailDm,
  7. rmOtherReport1Dm, rmGcl_XmjBillsDm, rmGclBillsPlaneDm,
  8. rmMentalCustomized1Dm, rmCustomized2Dm, rmHaBaiCustomizedDm,
  9. rmWeiWuZjjlGatherDm, rmZhongKaiDm, rmWuJiuZqzfGatherDm,
  10. rmTestFrm,
  11. ReportInteractInfo,
  12. Classes, ScFileArchiver, IniFiles, Graphics, DB, ProjectData,
  13. sdDB, ADODB;
  14. type
  15. TTemplateNode = class
  16. private
  17. FFileName: string;
  18. FPropertyStr: String;
  19. FTemplateName: string;
  20. FClassNum: string;
  21. FClassName: string;
  22. FSubClassNum: string;
  23. FSubClassName: string;
  24. FHasPriceChange: Boolean;
  25. FIsMulti: Boolean;
  26. FIsExtra: Boolean;
  27. FInteractFlag: Integer;
  28. FInteractSubFlag: Integer;
  29. FInteractInfo: TInteractInfo;
  30. FDataPrepareFlag: Integer;
  31. FDataBaseFlag: Integer;
  32. FSelfFormat: Integer;
  33. procedure ReadPropertyStr;
  34. procedure AnalyzePropertyStr;
  35. procedure LoadReportInteract;
  36. procedure LoadTemplateProperties;
  37. function GetMultiFileNames(APhaseIndex: Integer): string;
  38. public
  39. constructor Create(AFileName: string);
  40. destructor Destroy; override;
  41. procedure RefreshTemplateProperties;
  42. property FileName: string read FFileName write FFileName;
  43. property TemplateName: string read FTemplateName;
  44. property ClassNum: string read FClassNum;
  45. property ClassName: string read FClassName;
  46. property SubClassNum: string read FSubClassNum;
  47. property SubClassName: string read FSubClassName;
  48. property HasPriceChange: Boolean read FHasPriceChange;
  49. // 多表筛选
  50. property IsMulti: Boolean read FIsMulti;
  51. property MultiFileNames[APhaseIndex: Integer]: string read GetMultiFileNames;
  52. // 含附加
  53. property IsExtra: Boolean read FIsExtra;
  54. // 交互表 -- 部分数据需要用户选择后存入指定的数据表中
  55. property InteractFlag: Integer read FInteractFlag;
  56. property InteractSubFlag: Integer read FInteractSubFlag;
  57. // 数据准备类型
  58. property DataPrepareFlag: Integer read FDataPrepareFlag;
  59. // 链接数据库
  60. property DataBaseFlag: Integer read FDataBaseFlag;
  61. // 自主格式
  62. property SelfFormat: Integer read FSelfFormat;
  63. property InteractInfo: TInteractInfo read FInteractInfo;
  64. end;
  65. PTemplateNode = ^TTemplateNode;
  66. TTemplateManager = class
  67. private
  68. FTemplateList: TList;
  69. FTemplateNode: TTemplateNode;
  70. procedure Clear;
  71. function GetCount: Integer;
  72. function GetTemplate(AIndex: Integer): TTemplateNode;
  73. public
  74. constructor Create;
  75. destructor Destroy; override;
  76. procedure RefreshTemplates;
  77. procedure LoadReportTemplates(const sTemplateDir: String);
  78. function AddReportTemplate(const AFileName: string): TTemplateNode;
  79. procedure DeleteReportTemplate(ANode: TTemplateNode);
  80. function FindTemplate(const AFileName: string): TTemplateNode;
  81. property Count: Integer read GetCount;
  82. property Template[AIndex: Integer]: TTemplateNode read GetTemplate;
  83. property Current: TTemplateNode read FTemplateNode write FTemplateNode;
  84. end;
  85. TReportConfig = class
  86. private
  87. FIniFile: TIniFile;
  88. FLeftEdge: Integer;
  89. FRightEdge: Integer;
  90. FDownEdge: Integer;
  91. FUpEdge: Integer;
  92. FContentIsNarrow: Boolean;
  93. FRepCellVerLine: Boolean;
  94. FRepCellHorLine: Boolean;
  95. FRepBorderUnderLine: Boolean;
  96. FAutoRetLine: Boolean;
  97. FRepBorderVerLine: Boolean;
  98. FBorderLine: Integer;
  99. FReportCellLine: Double;
  100. FPageSize: string;
  101. FGridHeaderFont: TFont;
  102. FHeaderFont: TFont;
  103. FTitleFont: TFont;
  104. FColumnFont: TFont;
  105. FGatherFont: TFont;
  106. FContentFont: TFont;
  107. FGatherLevel: Integer;
  108. FGclCompare: Integer;
  109. FXmjCompare: Integer;
  110. procedure LoadPaperSettings;
  111. procedure LoadPageSettings;
  112. procedure LoadGatherSettings;
  113. procedure SavePaperSettings;
  114. procedure SavePageSettings;
  115. procedure SaveGatherSettings;
  116. function GetBorderUnderLineWidth: Integer;
  117. function GetBorderVerLineWidth: Integer;
  118. function GetCellHorLineWidth: Double;
  119. function GetCellVerLineWidth: Double;
  120. public
  121. constructor Create;
  122. destructor Destroy; override;
  123. procedure Load;
  124. procedure Save;
  125. //------------- 纸张 -------------
  126. // Size
  127. property PageSize: string read FPageSize write FPageSize;
  128. // 上边距
  129. property UpEdge: Integer read FUpEdge write FUpEdge;
  130. // 下边距
  131. property DownEdge: Integer read FDownEdge write FDownEdge;
  132. // 左边距
  133. property LeftEdge: Integer read FLeftEdge write FLeftEdge;
  134. // 右边距
  135. property RightEdge: Integer read FRightEdge write FRightEdge;
  136. //------------- 页面 -------------
  137. {字体}
  138. // 表标题
  139. property TitleFont: TFont read FTitleFont write FTitleFont;
  140. // 列标题
  141. property ColumnFont: TFont read FColumnFont write FColumnFont;
  142. // 表正文
  143. property ContentFont: TFont read FContentFont write FContentFont;
  144. // 表合计
  145. property GatherFont: TFont read FGatherFont write FGatherFont;
  146. // 表眉/表脚
  147. property GridHeaderFont: TFont read FGridHeaderFont write FGridHeaderFont;
  148. // 页眉/页脚
  149. property HeaderFont: TFont read FHeaderFont write FHeaderFont;
  150. {其他}
  151. // 表格线粗
  152. property ReportCellLine: Double read FReportCellLine write FReportCellLine;
  153. // 边框线粗
  154. property BorderLine: Integer read FBorderLine write FBorderLine;
  155. // 表格边框横线
  156. property RepBorderUnderLine: Boolean read FRepBorderUnderLine write FRepBorderUnderLine;
  157. property BorderUnderLineWidth: Integer read GetBorderUnderLineWidth;
  158. // 表格边框竖线
  159. property RepBorderVerLine: Boolean read FRepBorderVerLine write FRepBorderVerLine;
  160. property BorderVerLineWidth: Integer read GetBorderVerLineWidth;
  161. // 报表表格横线
  162. property RepCellHorLine: Boolean read FRepCellHorLine write FRepCellHorLine;
  163. property CellHorLineWidth: Double read GetCellHorLineWidth;
  164. // 报表表格竖线
  165. property RepCellVerLine: Boolean read FRepCellVerLine write FRepCellVerLine;
  166. property CellVerLineWidth: Double read GetCellVerLineWidth;
  167. // 自动换行打印
  168. property AutoRetLine: Boolean read FAutoRetLine write FAutoRetLine;
  169. // 报表内容窄体
  170. property ContentIsNarrow: Boolean read FContentIsNarrow write FContentIsNarrow;
  171. //------------- 汇总 -------------
  172. property GatherLevel: Integer read FGatherLevel write FGatherLevel;
  173. property XmjCompare: Integer read FXmjCompare write FXmjCompare;
  174. property GclCompare: Integer read FGclCompare write FGclCompare;
  175. end;
  176. TMemoryReportManager = class
  177. private
  178. FrmGridHeaderData: TrmGridHeaderData;
  179. FrmGclBillsBGData: TrmGclBillsBGData;
  180. FrmGclBillsCompareData: TrmGclBillsCompareData;
  181. FrmFxBillsCompareData: TrmFxBillsCompareData;
  182. FrmBGLExecutionData: TrmBGLExecutionData;
  183. FrmGclBillsAddData: TrmGclBillsAddData;
  184. FrmFxBillsAddData: TrmFxBillsAddData;
  185. FrmBillsGatherData: TrmBillsGatherData;
  186. FrmGclBillsAuditCompareData: TrmGclBillsAuditCompareData;
  187. FrmDealInfosData: TrmDealInfosData;
  188. FrmXmjBGLDetailData: TrmXmjBGLDetailData;
  189. FrmOtherReport1Data: TrmOtherReport1Data;
  190. FrmGcl_XmjBillsData: TrmGcl_XmjBillsData;
  191. FrmGclBillsPlaneData: TrmGclBillsPlaneData;
  192. FrmMentalCustomized1Data: TrmMentalCustomized1Data;
  193. FrmCustomized2Data: TrmCustomized2Data;
  194. FrmHaBaiCustomizedData: TrmHaBaiCustomizedData;
  195. FrmWeiWuZjjlGatherData: TrmWeiWuZjjlGatherData;
  196. FrmZhongKaiData: TrmZhongKaiData;
  197. FrmWuJiuZqzfGatherData: TrmWuJiuZqzfGatherData;
  198. FMemoryQuery: TADOQuery;
  199. FProjectID: Integer;
  200. FTenders: TList; // 仅储存选择汇总标段后,剔除项目分类节点的数据,为方便汇总做一次中转
  201. FProjects: TList; // 普通汇总
  202. FE_PCDProjects: TList; // 须选择初步设计,施工图设计
  203. FE_AProjects: TList; // 须选择批准概算
  204. FDealProjects: TList; // 可选择多合同项目
  205. function OpenProject(ARec: TsdDataRecord): TProjectData;
  206. procedure FreeProject(AProjectData: TProjectData);
  207. function SelectProjectID: Integer;
  208. function SelectProjectIDs(AProjects: TList; ADataSetID: Integer): Boolean;
  209. procedure GenerateTenders(AProjects: TList);
  210. function SelectSourceAndAssignData(ADataSetID: Integer;
  211. AProjectData: TProjectData): TDataSet;
  212. function SelectProjectsAndAssignData(ADataSetID: Integer): TDataSet;
  213. public
  214. constructor Create;
  215. destructor Destroy; override;
  216. function GetMemoryDataSet(ADataSetID: Integer;
  217. AProjectData: TProjectData): TDataSet;
  218. function GetSqlResultDataSet(const ASql: string; AProjectData: TProjectData): TDataSet;
  219. end;
  220. implementation
  221. uses
  222. SysUtils, ZhAPI, UtilMethods, Globals, ProjectManagerDm,
  223. rmSelectProjectFrm, Controls, ConditionalDefines;
  224. { TTemplateNode }
  225. procedure TTemplateNode.AnalyzePropertyStr;
  226. var
  227. sgs: TStrings;
  228. I: Integer;
  229. begin
  230. if FPropertyStr <> '' then
  231. begin
  232. sgs := TStringList.Create;
  233. try
  234. sgs.Text := FPropertyStr;
  235. for I := 0 to sgs.Count - 1 do
  236. begin
  237. if SameText(sgs.Names[I], '名称') then
  238. FTemplateName := sgs.Values[sgs.Names[I]]
  239. else if SameText(sgs.Names[I], '分类') then
  240. FClassNum := sgs.Values[sgs.Names[I]]
  241. else if SameText(sgs.Names[I], '分类名称') then
  242. FClassName := sgs.Values[sgs.Names[I]]
  243. else if SameText(sgs.Names[I], '子分类') then
  244. FSubClassNum := sgs.Values[sgs.Names[I]]
  245. else if SameText(sgs.Names[I], '子分类名称') then
  246. FSubClassName := sgs.Values[sgs.Names[I]]
  247. else if SameText(sgs.Names[I], '含单价变更') then
  248. FHasPriceChange := SameText(sgs.Values[sgs.Names[I]], '是')
  249. else if SameText(sgs.Names[I], '多表筛选') then
  250. FIsMulti := SameText(sgs.Values[sgs.Names[I]], '是')
  251. else if SameText(sgs.Names[I], '含附加') then
  252. FIsExtra := SameText(sgs.Values[sgs.Names[I]], '是')
  253. else if SameText(sgs.Names[I], '交互类型') then
  254. FInteractFlag := StrToIntDef(sgs.Values[sgs.Names[I]], 0)
  255. else if SameText(sgs.Names[I], '交互子类型') then
  256. FInteractSubFlag := StrToIntDef(sgs.Values[sgs.Names[I]], 0)
  257. else if SameText(sgs.Names[I], '数据准备') then
  258. FDataPrepareFlag := StrToIntDef(sgs.Values[sgs.Names[I]], 0)
  259. else if SameText(sgs.Names[I], '数据库') then
  260. FDataBaseFlag := StrToIntDef(sgs.Values[sgs.Names[I]], 0)
  261. else if SameText(sgs.Names[I], '自主格式') then
  262. FSelfFormat := StrToIntDef(sgs.Values[sgs.Names[I]], 0);
  263. end;
  264. finally
  265. sgs.Free;
  266. end;
  267. end;
  268. end;
  269. constructor TTemplateNode.Create(AFileName: string);
  270. begin
  271. FFileName := AFileName;
  272. FInteractFlag := 0;
  273. FInteractSubFlag := 0;
  274. FDataPrepareFlag := 0;
  275. FDataBaseFlag := 0;
  276. FSelfFormat := 0;
  277. LoadTemplateProperties;
  278. end;
  279. destructor TTemplateNode.Destroy;
  280. begin
  281. if Assigned(FInteractInfo) then
  282. FInteractInfo.Free;
  283. inherited;
  284. end;
  285. function TTemplateNode.GetMultiFileNames(APhaseIndex: Integer): string;
  286. var
  287. sName, sPath: string;
  288. begin
  289. sPath := ExtractFilePath(FFileName);
  290. sName := ExtractSimpleFileName(FFileName);
  291. Result := Format('%s%s\%s_%d.srt', [sPath, sName, sName, APhaseIndex]);
  292. end;
  293. procedure TTemplateNode.LoadReportInteract;
  294. begin
  295. if Assigned(FInteractInfo) then
  296. FInteractInfo.LoadXmlFromStream
  297. else
  298. FInteractInfo := TInteractInfo.Create(FileName);
  299. end;
  300. procedure TTemplateNode.LoadTemplateProperties;
  301. begin
  302. try
  303. ReadPropertyStr;
  304. AnalyzePropertyStr;
  305. if FIsExtra then
  306. LoadReportInteract;
  307. except
  308. on E: Exception do
  309. begin
  310. TipMessage(Format('报表文件[%s]无法打开,错误信息:'#13#10'%s.'#13#10 +
  311. '请与纵横软件客服中心联系:(0756)3850888。', [FFileName, E.Message]));
  312. end;
  313. end;
  314. end;
  315. procedure TTemplateNode.ReadPropertyStr;
  316. var
  317. vStream: TFileStream;
  318. FileHead: TScFileHead;
  319. begin
  320. vStream := TFileStream.Create(FFileName, fmOpenRead);
  321. try
  322. vStream.Seek($00, soFromBeginning);
  323. vStream.Read(FileHead, Sizeof(TScFileHead));
  324. if FileHead.ReportProperties[0] <> #0 then
  325. SetString(FPropertyStr, FileHead.ReportProperties, 256);
  326. finally
  327. vStream.Free;
  328. end;
  329. end;
  330. procedure TTemplateNode.RefreshTemplateProperties;
  331. begin
  332. FInteractFlag := 0;
  333. FInteractSubFlag := 0;
  334. FDataPrepareFlag := 0;
  335. FDataBaseFlag := 0;
  336. FSelfFormat := 0;
  337. LoadTemplateProperties;
  338. end;
  339. { TTemplateManager }
  340. function TTemplateManager.AddReportTemplate(const AFileName: string): TTemplateNode;
  341. begin
  342. Result := TTemplateNode.Create(AFileName);
  343. FTemplateList.Add(Result);
  344. end;
  345. procedure TTemplateManager.Clear;
  346. begin
  347. ClearObjects(FTemplateList);
  348. end;
  349. constructor TTemplateManager.Create;
  350. begin
  351. FTemplateList := TList.Create;
  352. LoadReportTemplates(GetAppFilePath + 'ReportTemplates');
  353. end;
  354. procedure TTemplateManager.DeleteReportTemplate(ANode: TTemplateNode);
  355. begin
  356. FTemplateList.Remove(ANode);
  357. ANode.Free;
  358. end;
  359. destructor TTemplateManager.Destroy;
  360. begin
  361. Clear;
  362. FTemplateList.Free;
  363. inherited;
  364. end;
  365. function TTemplateManager.FindTemplate(
  366. const AFileName: string): TTemplateNode;
  367. var
  368. iTemplate: Integer;
  369. vTemplate: TTemplateNode;
  370. begin
  371. Result := nil;
  372. for iTemplate := 0 to FTemplateList.Count - 1 do
  373. begin
  374. vTemplate := Template[iTemplate];
  375. if vTemplate.FileName = AFileName then
  376. begin
  377. Result := vTemplate;
  378. Break;
  379. end;
  380. end;
  381. end;
  382. function TTemplateManager.GetCount: Integer;
  383. begin
  384. Result := FTemplateList.Count;
  385. end;
  386. function TTemplateManager.GetTemplate(AIndex: Integer): TTemplateNode;
  387. begin
  388. Result := TTemplateNode(FTemplateList.Items[AIndex]);
  389. end;
  390. procedure TTemplateManager.LoadReportTemplates(const sTemplateDir: String);
  391. var
  392. sFiles: TStringList;
  393. I: Integer;
  394. begin
  395. Clear;
  396. sFiles := TStringList.Create;
  397. try
  398. FilterFiles(sTemplateDir, '.srt', sFiles);
  399. for I := 0 to sFiles.Count - 1 do
  400. AddReportTemplate(sTemplateDir + '\' + sFiles[I]);
  401. finally
  402. sFiles.Free;
  403. end;
  404. end;
  405. procedure TTemplateManager.RefreshTemplates;
  406. begin
  407. LoadReportTemplates(GetAppFilePath + 'ReportTemplates');
  408. end;
  409. { TReportConfig }
  410. constructor TReportConfig.Create;
  411. begin
  412. inherited Create;
  413. FTitleFont := TFont.Create;
  414. FColumnFont := TFont.Create;
  415. FContentFont := TFont.Create;
  416. FGatherFont := TFont.Create;
  417. FGridHeaderFont := TFont.Create;
  418. FHeaderFont := TFont.Create;
  419. Load;
  420. end;
  421. destructor TReportConfig.Destroy;
  422. begin
  423. Save;
  424. FHeaderFont.Free;
  425. FGridHeaderFont.Free;
  426. FGatherFont.Free;
  427. FContentFont.Free;
  428. FColumnFont.Free;
  429. FTitleFont.Free;
  430. inherited;
  431. end;
  432. function TReportConfig.GetBorderUnderLineWidth: Integer;
  433. begin
  434. Result := 0;
  435. if RepBorderUnderLine then
  436. Result := BorderLine;
  437. end;
  438. function TReportConfig.GetBorderVerLineWidth: Integer;
  439. begin
  440. Result := 0;
  441. if RepBorderVerLine then
  442. Result := BorderLine;
  443. end;
  444. function TReportConfig.GetCellHorLineWidth: Double;
  445. begin
  446. Result := 0;
  447. if RepCellHorLine then
  448. Result := ReportCellLine;
  449. end;
  450. function TReportConfig.GetCellVerLineWidth: Double;
  451. begin
  452. Result := 0;
  453. if RepCellVerLine then
  454. Result := ReportCellLine;
  455. end;
  456. procedure TReportConfig.Load;
  457. begin
  458. try
  459. FIniFile := TIniFile.Create(GetAppFilePath + 'Report.ini');
  460. LoadPaperSettings;
  461. LoadPageSettings;
  462. LoadGatherSettings;
  463. finally
  464. FIniFile.Free;
  465. end;
  466. end;
  467. procedure TReportConfig.LoadGatherSettings;
  468. begin
  469. FGatherLevel := FIniFile.ReadInteger('汇总', '层次', 5);
  470. FXmjCompare := FIniFile.ReadInteger('汇总', '项目节规则', 0);
  471. FGclCompare := FIniFile.ReadInteger('汇总', '清单规则', 0);
  472. end;
  473. procedure TReportConfig.LoadPageSettings;
  474. procedure LoadFont(const AFontName: string; AFont: TFont);
  475. begin
  476. AFont.Name := FIniFile.ReadString('页面', AFontName + '_字体', 'SmartSumSun');
  477. AFont.Size := FIniFile.ReadInteger('页面', AFontName + '_字体大小', 9);
  478. if FIniFile.ReadBool('页面', AFontName + '_字体粗', False) then
  479. AFont.Style := AFont.Style + [fsBold]
  480. else
  481. AFont.Style := AFont.Style - [fsBold];
  482. if FIniFile.ReadBool('页面', AFontName + '_字体斜', False) then
  483. AFont.Style := AFont.Style + [fsItalic]
  484. else
  485. AFont.Style := AFont.Style - [fsItalic];
  486. if FIniFile.ReadBool('页面', AFontName + '_字体下划线', False) then
  487. AFont.Style := AFont.Style + [fsUnderline]
  488. else
  489. AFont.Style := AFont.Style - [fsUnderline];
  490. //AFont.Height := FIniFile.ReadInteger('页面', AFontName + '_行高', 9);
  491. end;
  492. begin
  493. LoadFont('表标题', TitleFont);
  494. LoadFont('列标题', ColumnFont);
  495. LoadFont('表正文', ContentFont);
  496. LoadFont('表合计', GatherFont);
  497. LoadFont('表眉/表脚', GridHeaderFont);
  498. LoadFont('页眉/页脚', HeaderFont);
  499. FReportCellLine := FIniFile.ReadFloat('页面', '表格线粗', 0.75);
  500. FBorderLine := FIniFile.ReadInteger('页面', '边框线粗', 2);
  501. FRepBorderUnderLine := FIniFile.ReadBool('页面', '报表边框横线', True);
  502. FRepBorderVerLine := FIniFile.ReadBool('页面', '报表边框竖线', False);
  503. FRepCellHorLine := FIniFile.ReadBool('页面', '报表表格横线', True);
  504. FRepCellVerLine := FIniFile.ReadBool('页面', '报表表格竖线', True);
  505. FAutoRetLine := FIniFile.ReadBool('页面', '自动换行打印', False);
  506. FContentIsNarrow := FIniFile.ReadBool('页面', '内容窄体输出', False);
  507. end;
  508. procedure TReportConfig.LoadPaperSettings;
  509. begin
  510. FPageSize := FIniFile.ReadString('纸张', '幅面', 'A4');
  511. FUpEdge := FIniFile.ReadInteger('纸张', '上边距', 12);
  512. FDownEdge := FIniFile.ReadInteger('纸张', '下边距', 12);
  513. FLeftEdge := FIniFile.ReadInteger('纸张', '左边距', 12);
  514. FRightEdge := FIniFile.ReadInteger('纸张', '右边距', 12);
  515. end;
  516. procedure TReportConfig.Save;
  517. begin
  518. try
  519. FIniFile := TIniFile.Create(GetAppFilePath + 'Report.ini');
  520. SavePaperSettings;
  521. SavePageSettings;
  522. finally
  523. FIniFile.Free;
  524. end;
  525. end;
  526. procedure TReportConfig.SaveGatherSettings;
  527. begin
  528. FIniFile.WriteInteger('汇总', '层次', FGatherLevel);
  529. FIniFile.WriteInteger('汇总', '项目节规则', FXmjCompare);
  530. FIniFile.WriteInteger('汇总', '清单规则', FGclCompare);
  531. end;
  532. procedure TReportConfig.SavePageSettings;
  533. procedure SaveFont(const AFontName: string; AFont: TFont);
  534. begin
  535. FIniFile.WriteString('页面', AFontName + '_字体', AFont.Name);
  536. FIniFile.WriteInteger('页面', AFontName + '_字体大小', AFont.Size);
  537. FIniFile.WriteBool('页面', AFontName + '_字体粗', fsBold in AFont.Style);
  538. FIniFile.WriteBool('页面', AFontName + '_字体斜', fsItalic in AFont.Style);
  539. FIniFile.WriteBool('页面', AFontName + '_字体下划线', fsUnderline in AFont.Style);
  540. FIniFile.WriteInteger('页面', AFontName + '_行高', AFont.Height);
  541. end;
  542. begin
  543. SaveFont('表标题', TitleFont);
  544. SaveFont('列标题', ColumnFont);
  545. SaveFont('表正文', ContentFont);
  546. SaveFont('表合计', GatherFont);
  547. SaveFont('表眉/表脚', GridHeaderFont);
  548. SaveFont('页眉/页脚', HeaderFont);
  549. FIniFile.WriteFloat('页面', '表格线粗', FReportCellLine);
  550. FIniFile.WriteInteger('页面', '边框线粗', FBorderLine);
  551. FIniFile.WriteBool('页面', '报表边框横线', FRepBorderUnderLine);
  552. FIniFile.WriteBool('页面', '报表边框竖线', FRepBorderVerLine);
  553. FIniFile.WriteBool('页面', '报表表格横线', FRepCellHorLine);
  554. FIniFile.WriteBool('页面', '报表表格竖线', FRepCellVerLine);
  555. FIniFile.WriteBool('页面', '自动换行打印', FAutoRetLine);
  556. FIniFile.WriteBool('页面', '内容窄体输出', FContentIsNarrow);
  557. end;
  558. procedure TReportConfig.SavePaperSettings;
  559. begin
  560. FIniFile.WriteString('纸张', '幅面', FPageSize);
  561. FIniFile.WriteInteger('纸张', '上边距', FUpEdge);
  562. FIniFile.WriteInteger('纸张', '下边距', FDownEdge);
  563. FIniFile.WriteInteger('纸张', '左边距', FLeftEdge);
  564. FIniFile.WriteInteger('纸张', '右边距', FRightEdge);
  565. end;
  566. { TMemoryReportManager }
  567. constructor TMemoryReportManager.Create;
  568. begin
  569. FrmGridHeaderData := TrmGridHeaderData.Create(nil);
  570. FrmGclBillsBGData := TrmGclBillsBGData.Create;
  571. FrmGclBillsCompareData := TrmGclBillsCompareData.Create;
  572. FrmFxBillsCompareData := TrmFxBillsCompareData.Create(nil);
  573. FrmBGLExecutionData := TrmBGLExecutionData.Create(nil);
  574. FrmGclBillsAddData := TrmGclBillsAddData.Create(nil);
  575. FrmFxBillsAddData := TrmFxBillsAddData.Create(nil);
  576. FrmBillsGatherData := TrmBillsGatherData.Create(nil);
  577. FrmGclBillsAuditCompareData := TrmGclBillsAuditCompareData.Create;
  578. FrmDealInfosData := TrmDealInfosData.Create(nil);
  579. FrmXmjBGLDetailData := TrmXmjBGLDetailData.Create(nil);
  580. FrmOtherReport1Data := TrmOtherReport1Data.Create(nil);
  581. FrmGcl_XmjBillsData := TrmGcl_XmjBillsData.Create(nil);
  582. FrmGclBillsPlaneData := TrmGclBillsPlaneData.Create(nil);
  583. FrmMentalCustomized1Data := TrmMentalCustomized1Data.Create(nil);
  584. FrmCustomized2Data := TrmCustomized2Data.Create(nil);
  585. FrmHaBaiCustomizedData := TrmHaBaiCustomizedData.Create(nil);
  586. FrmWeiWuZjjlGatherData := TrmWeiWuZjjlGatherData.Create(nil);
  587. FrmZhongKaiData := TrmZhongKaiData.Create(nil);
  588. FrmWuJiuZqzfGatherData := TrmWuJiuZqzfGatherData.Create(nil);
  589. FMemoryQuery := TADOQuery.Create(nil);
  590. FProjectID := -1;
  591. FTenders := TList.Create;
  592. FProjects := TList.Create;
  593. FE_PCDProjects := TList.Create;
  594. FE_AProjects := TList.Create;
  595. FDealProjects := TList.Create;
  596. end;
  597. destructor TMemoryReportManager.Destroy;
  598. begin
  599. FTenders.Free;
  600. ClearObjects(FProjects);
  601. FProjects.Free;
  602. ClearObjects(FE_PCDProjects);
  603. FE_PCDProjects.Free;
  604. ClearObjects(FE_AProjects);
  605. FE_AProjects.Free;
  606. ClearObjects(FDealProjects);
  607. FDealProjects.Free;
  608. FMemoryQuery.Free;
  609. FrmWuJiuZqzfGatherData.Free;
  610. FrmZhongKaiData.Free;
  611. FrmWeiWuZjjlGatherData.Free;
  612. FrmHaBaiCustomizedData.Free;
  613. FrmCustomized2Data.Free;
  614. FrmMentalCustomized1Data.Free;
  615. FrmGclBillsPlaneData.Free;
  616. FrmGcl_XmjBillsData.Free;
  617. FrmOtherReport1Data.Free;
  618. FrmXmjBGLDetailData.Free;
  619. FrmDealInfosData.Free;
  620. FrmGclBillsAuditCompareData.Free;
  621. FrmBillsGatherData.Free;
  622. FrmFxBillsAddData.Free;
  623. FrmGclBillsAddData.Free;
  624. FrmBGLExecutionData.Free;
  625. FrmFxBillsCompareData.Free;
  626. FrmGclBillsCompareData.Free;
  627. FrmGclBillsBGData.Free;
  628. FrmGridHeaderData.Free;
  629. inherited;
  630. end;
  631. procedure TMemoryReportManager.FreeProject(AProjectData: TProjectData);
  632. begin
  633. if not Assigned(OpenProjectManager.FindProjectData(AProjectData.ProjectID)) then
  634. AProjectData.Free;
  635. end;
  636. procedure TMemoryReportManager.GenerateTenders(AProjects: TList);
  637. var
  638. i: Integer;
  639. SelectProject: TSelectProject;
  640. begin
  641. FTenders.Clear;
  642. for i := 0 to AProjects.Count - 1 do
  643. begin
  644. SelectProject := TSelectProject(AProjects.Items[i]);
  645. if SelectProject.IsTender then
  646. FTenders.Add(SelectProject);
  647. end;
  648. end;
  649. function TMemoryReportManager.GetMemoryDataSet(
  650. ADataSetID: Integer; AProjectData: TProjectData): TDataSet;
  651. begin
  652. //ADataSetID := 59;
  653. case ADataSetID of
  654. 1: Result := FrmGridHeaderData.AssginData(AProjectData); // 各表表头
  655. 2: Result := FrmGclBillsBGData.AssignData(AProjectData, rmtPhaseGather, rmgtGather); // 工程量清单[本期完成]
  656. 3, 4, 41:
  657. // 审表01、02, 粤台 账07
  658. Result := SelectSourceAndAssignData(ADataSetID, AProjectData);
  659. 5: Result := FrmBGLExecutionData.AssignData(AProjectData); // 支表09
  660. 6: Result := FrmGclBillsBGData.AssignData(AProjectData, rmtEndGather, rmgtGather); // 工程量清单[截止本期完成]
  661. 7: Result := FrmGclBillsAddData.AssignData(AProjectData); // 多审表02
  662. 8: Result := FrmFxBillsAddData.AssignData(AProjectData); // 多审表02-1
  663. 9, 10, 11, 12, 13,
  664. // 决算04, 05, 05-2, 04-1, 02,
  665. 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
  666. // 02/03部颁, 07部颁, 08部颁, 09部颁, 11部颁, 12部颁, 16部颁, 17部颁, 18部颁, 19部颁,
  667. 32, 33, 35, 36, 39, 40, 44,
  668. // 粤竣9, 粤竣06-1, 粤竣04, 粤竣01, 工程量清单进度[甘肃高管局定制], [广东肇庆定制]计量汇总表
  669. 45, 46, 47, 48, 49, 50,
  670. // 内蒙古哈白定制表(支表2, 支表3, 支表14, 支表3-1, 支表4-1, 会签)
  671. 52, 53, 54, 55,
  672. // 内蒙古306国道定制(支表2, 支表3, 支表3-1, 支表4-1)
  673. 57, 58:
  674. // 中开高速定制表(支表2, 支表3)
  675. Result := SelectProjectsAndAssignData(ADataSetID);
  676. 14: Result := FrmGclBillsBGData.AssignData(AProjectData, rmtPhaseDeal, rmgtGather); // 工程量清单[本期合同]
  677. 15: Result := FrmGclBillsBGData.AssignData(AProjectData, rmtPhaseQc, rmgtGather); // 工程量清单[本期数量变更]
  678. 16: Result := FrmGclBillsBGData.AssignData(AProjectData, rmtPhasePc, rmgtGather); // 工程量清单[本期单价变更]
  679. 17: Result := FrmGclBillsBGData.AssignData(AProjectData, rmtEndDeal, rmgtGather); // 工程量清单[截止本期合同]
  680. 18: Result := FrmGclBillsBGData.AssignData(AProjectData, rmtEndQc, rmgtGather); // 工程量清单[截止本期数量变更]
  681. 19: Result := FrmGclBillsBGData.AssignData(AProjectData, rmtEndPc, rmgtGather); // 工程量清单[截止本期单价变更]
  682. 30: Result := FrmGclBillsBGData.AssignData(AProjectData, rmtPhaseQc, rmgtFlow);
  683. 31: Result := FrmGclBillsAuditCompareData.AssignData(AProjectData, rmftPhaseGather); // 工程量清单[原报&批复,完成]
  684. 34: Result := FrmXmjBGLDetailData.AssignData(AProjectData); // 变更台账
  685. 37: Result := FrmGcl_XmjBillsData.AssignData(AProjectData, gxtTopGcl); // 工程量清单审核
  686. 38: Result := FrmGclBillsPlaneData.AssignData(AProjectData); // 工程量清单平面表[福建0号台账]
  687. 42: Result := FrmGcl_XmjBillsData.AssignData(AProjectData, gxtFlowGcl); // 云南标准表,台账明细表
  688. 43: Result := FrmGcl_XmjBillsData.AssignData(AProjectData, gxtWithoutXmj); // 云南标准表,单标段清单汇总表
  689. 51: Result := FrmHaBaiCustomizedData.AssignAssistantData(hbgt_CS); //内蒙古哈白、国道306定制表--会签辅助表
  690. 56: Result := FrmWeiWuZjjlGatherData.AssignData(AProjectData); // 甘肃渭武 -- 单标段、计量支付汇总表
  691. 59: Result := FrmWuJiuZqzfGatherData.AssignData(AProjectData);
  692. end;
  693. // For Inner Test
  694. if _IsDebugView then
  695. ShowTestForm(Result);
  696. end;
  697. function TMemoryReportManager.GetSqlResultDataSet(const ASql: string;
  698. AProjectData: TProjectData): TDataSet;
  699. begin
  700. if ASql <> '' then
  701. begin
  702. FMemoryQuery.Close;
  703. FMemoryQuery.Connection := AProjectData.ADOConnection;
  704. FMemoryQuery.SQL.Clear;
  705. FMemoryQuery.SQL.Add(ASql);
  706. FMemoryQuery.Open;
  707. end;
  708. Result := FMemoryQuery;
  709. //ShowTestForm(Result);
  710. end;
  711. function TMemoryReportManager.OpenProject(
  712. ARec: TsdDataRecord): TProjectData;
  713. begin
  714. Result := OpenProjectManager.FindProjectData(ARec.ValueByName('ID').AsInteger);
  715. if not Assigned(Result) then
  716. begin
  717. Result := TProjectData.Create;
  718. Result.OpenForReport(GetMyProjectsFilePath + ARec.ValueByName('FileName').AsString);
  719. end;
  720. end;
  721. function TMemoryReportManager.SelectProjectID: Integer;
  722. var
  723. SelectFrm: TProjectSelectForm;
  724. begin
  725. Result := -1;
  726. SelectFrm := TProjectSelectForm.Create(False, FProjectID, FProjects);
  727. //SelectFrm.LoadHistorySelect(FProjectID);
  728. try
  729. if SelectFrm.ShowModal = mrOk then
  730. begin
  731. SelectFrm.SelectResult(FProjectID);
  732. Result := FProjectID;
  733. end;
  734. finally
  735. SelectFrm.Free;
  736. end;
  737. end;
  738. function TMemoryReportManager.SelectProjectIDs(AProjects: TList;
  739. ADataSetID: Integer): Boolean;
  740. var
  741. SelectFrm: TProjectSelectForm;
  742. begin
  743. Result := False;
  744. SelectFrm := TProjectSelectForm.Create(True, FProjectID, AProjects);
  745. case ADataSetID of
  746. 13, 33: SelectFrm.MultiSelectType := mstE_PCD;
  747. 20, 36: SelectFrm.MultiSelectType := mstE_A;
  748. 32: SelectFrm.MultiSelectType := mstDeal;
  749. 40: SelectFrm.MultiSelectType := mstMental1;
  750. else SelectFrm.MultiSelectType := mstCommon;
  751. end;
  752. try
  753. if SelectFrm.ShowModal = mrOk then
  754. begin
  755. SelectFrm.SelectResult(AProjects);
  756. Result := True;
  757. end;
  758. finally
  759. SelectFrm.Free;
  760. end;
  761. end;
  762. function TMemoryReportManager.SelectProjectsAndAssignData(
  763. ADataSetID: Integer): TDataSet;
  764. var
  765. Projects: TList;
  766. begin
  767. Result := nil;
  768. case ADataSetID of
  769. 13, 33: Projects := FE_PCDProjects;
  770. 20, 36: Projects := FE_AProjects;
  771. 32: Projects := FDealProjects;
  772. else Projects := FProjects;
  773. end;
  774. if SelectProjectIDs(Projects, ADataSetID) then
  775. begin
  776. case ADataSetID of
  777. 9: FrmBillsGatherData.GatherType := bgtFx;
  778. 10: FrmBillsGatherData.GatherType := bgtXmj;
  779. 11: FrmBillsGatherData.GatherType := bgtGcl;
  780. 12: FrmBillsGatherData.GatherType := bgtMultiXmj;
  781. 13: FrmBillsGatherData.GatherType := bgtEstimate; // 决算02
  782. 20: FrmBillsGatherData.GatherType := bgtEstimate1; // 决算02/03部颁
  783. 21: FrmBillsGatherData.GatherType := bgtFinal07; // 决算07
  784. 22: FrmBillsGatherData.GatherType := bgtFinal08;
  785. 23: FrmBillsGatherData.GatherType := bgtFinal09;
  786. 24: FrmBillsGatherData.GatherType := bgtFinal11;
  787. 25: FrmBillsGatherData.GatherType := bgtFinal12;
  788. 26: FrmBillsGatherData.GatherType := bgtFinal16;
  789. 27: FrmBillsGatherData.GatherType := bgtFinal17;
  790. 28: FrmBillsGatherData.GatherType := bgtFinal18;
  791. 29: FrmBillsGatherData.GatherType := bgtFinal19;
  792. 33: FrmBillsGatherData.GatherType := bgtG_Final06_1;
  793. 35: FrmBillsGatherData.GatherType := bgtG_Final04;
  794. 39: FrmMentalCustomized1Data.MentalType := 0;
  795. 40: FrmMentalCustomized1Data.MentalType := 1;
  796. end;
  797. GenerateTenders(Projects);
  798. case ADataSetID of
  799. 32: Result := FrmDealInfosData.AssignData(FTenders);
  800. 36: Result := FrmOtherReport1Data.AssignData(FTenders);
  801. 39, 40: Result := FrmMentalCustomized1Data.AssignData(FTenders);
  802. 44: Result := FrmCustomized2Data.AssignData(FTenders);
  803. 45: Result := FrmHaBaiCustomizedData.AssignData(FTenders, hbgt2, True);
  804. 46: Result := FrmHaBaiCustomizedData.AssignData(FTenders, hbgt3, True);
  805. 47: Result := FrmHaBaiCustomizedData.AssignData(FTenders, hbgt14, True);
  806. 48: Result := FrmHaBaiCustomizedData.AssignData(FTenders, hbgt3_1, True);
  807. 49: Result := FrmHaBaiCustomizedData.AssignData(FTenders, hbgt4_1, True);
  808. 50: Result := FrmHaBaiCustomizedData.AssignData(FTenders, hbgt_CS, True);
  809. 52: Result := FrmHaBaiCustomizedData.AssignData(FTenders, hbgt2, False);
  810. 53: Result := FrmHaBaiCustomizedData.AssignData(FTenders, hbgt3, False);
  811. 54: Result := FrmHaBaiCustomizedData.AssignData(FTenders, hbgt3_1, False);
  812. 55: Result := FrmHaBaiCustomizedData.AssignData(FTenders, hbgt4_1, False);
  813. 57: Result := FrmZhongKaiData.AssignData(FTenders, zkgt2);
  814. 58: Result := FrmZhongKaiData.AssignData(FTenders, zkgt3);
  815. else Result := FrmBillsGatherData.AssignData(FTenders);
  816. end;
  817. end;
  818. end;
  819. function TMemoryReportManager.SelectSourceAndAssignData(
  820. ADataSetID: Integer; AProjectData: TProjectData): TDataSet;
  821. var
  822. sRec, cRec: TsdDataRecord;
  823. sProject, cProject: TProjectData;
  824. begin
  825. sRec := ProjectManager.sddProjectsInfo.FindKey('idxID', SelectProjectID);
  826. cRec := ProjectManager.sddProjectsInfo.FindKey('idxID', AProjectData.ProjectID);
  827. if Assigned(sRec) and Assigned(cRec) then
  828. begin
  829. sProject := OpenProject(sRec);
  830. cProject := OpenProject(cRec);
  831. try
  832. case ADataSetID of
  833. 4: FrmFxBillsCompareData.CompareType := fctCommon;
  834. 41: FrmFxBillsCompareData.CompareType := fctG07;
  835. end;
  836. case ADataSetID of
  837. 3: Result := FrmGclBillsCompareData.AssignData(sProject, cProject);
  838. 4: Result := FrmFxBillsCompareData.AssignData(sProject, cProject);
  839. 41: Result := FrmFxBillsCompareData.AssignData(sProject, cProject);
  840. end;
  841. finally
  842. FreeProject(sProject);
  843. FreeProject(cProject);
  844. end;
  845. end;
  846. end;
  847. end.