ReportManager.pas 30 KB

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