ReportManager.pas 27 KB

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