ReportManager.pas 31 KB

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