ReportManager.pas 29 KB

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