ReportManager.pas 29 KB

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