ReportManager.pas 32 KB

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