ReportManager.pas 28 KB

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