ReportManager.pas 32 KB

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