rmHaBaiCustomizedDm.pas 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213
  1. unit rmHaBaiCustomizedDm;
  2. // 内蒙古 哈白项目定制汇总表 严禁任何其他项目或标表调用该单元
  3. // 包括支表2/3/14/3-1/4-1
  4. interface
  5. uses
  6. SysUtils, Classes, DB, rmSelectProjectFrm, ProjectData, mDataRecord,
  7. BillsTree, DBClient;
  8. type
  9. TDoubleArray = array of Double;
  10. TStringArray = array of string;
  11. TGclNode = class
  12. private
  13. FB_Code: string;
  14. FIndexCode: string;
  15. FName: string;
  16. FUnits: string;
  17. FPrice: Double;
  18. FQuantity: Double;
  19. FTotalPrice: Double;
  20. FCurGatherQuantity: Double;
  21. FCurGatherTotalPrice: Double;
  22. FEndGatherQuantity: Double;
  23. FEndGatherTotalPrice: Double;
  24. FPreGatherQuantity: Double;
  25. FPreGatherTotalPrice: Double;
  26. FP_Quantity: TDoubleArray;
  27. FP_TotalPrice: TDoubleArray;
  28. FP_CurGatherQuantity: TDoubleArray;
  29. FP_CurGatherTotalPrice: TDoubleArray;
  30. FP_EndGatherQuantity: TDoubleArray;
  31. FP_EndGatherTotalPrice: TDoubleArray;
  32. procedure SetB_Code(const Value: string);
  33. function GetCurPercent: Double;
  34. function GetEndPercent: Double;
  35. public
  36. constructor Create(AProjectCount: Integer);
  37. property B_Code: string read FB_Code write SetB_Code;
  38. property IndexCode: string read FIndexCode;
  39. property Name: string read FName write FName;
  40. property Units: string read FUnits write FUnits;
  41. property Price: Double read FPrice write FPrice;
  42. property Quantity: Double read FQuantity write FQuantity;
  43. property TotalPrice: Double read FTotalPrice write FTotalPrice;
  44. property CurGatherQuantity: Double read FCurGatherQuantity write FCurGatherQuantity;
  45. property CurGatherTotalPrice: Double read FCurGatherTotalPrice write FCurGatherTotalPrice;
  46. property EndGatherQuantity: Double read FEndGatherQuantity write FEndGatherQuantity;
  47. property EndGatherTotalPrice: Double read FEndGatherTotalPrice write FEndGatherTotalPrice;
  48. property PreGatherQuantity: Double read FPreGatherQuantity write FPreGatherQuantity;
  49. property PreGatherTotalPrice: Double read FPreGatherTotalPrice write FPreGatherTotalPrice;
  50. property P_Quantity: TDoubleArray read FP_Quantity write FP_Quantity;
  51. property P_TotalPrice: TDoubleArray read FP_TotalPrice write FP_TotalPrice;
  52. property P_CurGatherQuantity: TDoubleArray read FP_CurGatherQuantity write FP_CurGatherQuantity;
  53. property P_CurGatherTotalPrice: TDoubleArray read FP_CurGatherTotalPrice write FP_CurGatherTotalPrice;
  54. property P_EndGatherQuantity: TDoubleArray read FP_EndGatherQuantity write FP_EndGatherQuantity;
  55. property P_EndGatherTotalPrice: TDoubleArray read FP_EndGatherTotalPrice write FP_EndGatherTotalPrice;
  56. property CurPercent: Double read GetCurPercent;
  57. property EndPercent: Double read GetEndPercent;
  58. end;
  59. TGclChapter = class
  60. private
  61. FProjectCount: Integer;
  62. FGclNodes: TList;
  63. FChapterID: Integer;
  64. FChapterBegin: Integer;
  65. FChapterEnd: Integer;
  66. FChapterName: string;
  67. FName: string;
  68. FTotalPrice: Double;
  69. FCurGatherTotalPrice: Double;
  70. FEndGatherTotalPrice: Double;
  71. FPreGatherTotalPrice: Double;
  72. FP_TotalPrice: TDoubleArray;
  73. FP_CurGatherTotalPrice: TDoubleArray;
  74. FP_EndGatherTotalPrice: TDoubleArray;
  75. function GetGclNode(AIndex: Integer): TGclNode;
  76. function GetGclNodeCount: Integer;
  77. function GetCurPercent: Double;
  78. function GetEndPercent: Double;
  79. public
  80. constructor Create(AChapterID: Integer; const AName: string; AProjectCount: Integer);
  81. destructor Destroy; override;
  82. procedure AddGclNode(AGclNode: TGclNode);
  83. procedure CalculateChapter;
  84. property ChapterID: Integer read FChapterID;
  85. property ChapterBegin: Integer read FChapterBegin;
  86. property ChapterEnd: Integer read FChapterEnd;
  87. property ChapterName: string read FChapterName;
  88. property Name: string read FName;
  89. property TotalPrice: Double read FTotalPrice write FTotalPrice;
  90. property CurGatherTotalPrice: Double read FCurGatherTotalPrice write FCurGatherTotalPrice;
  91. property EndGatherTotalPrice: Double read FEndGatherTotalPrice write FEndGatherTotalPrice;
  92. property PreGatherTotalPrice: Double read FPreGatherTotalPrice write FPreGatherTotalPrice;
  93. property P_TotalPrice: TDoubleArray read FP_TotalPrice write FP_TotalPrice;
  94. property P_CurGatherTotalPrice: TDoubleArray read FP_CurGatherTotalPrice write FP_CurGatherTotalPrice;
  95. property P_EndGatherTotalPrice: TDoubleArray read FP_EndGatherTotalPrice write FP_EndGatherTotalPrice;
  96. property CurPercent: Double read GetCurPercent;
  97. property EndPercent: Double read GetEndPercent;
  98. property GclNodeCount: Integer read GetGclNodeCount;
  99. property GclNode[AIndex: Integer]: TGclNode read GetGclNode;
  100. end;
  101. TGclControl = class
  102. private
  103. FProjectCount: Integer;
  104. FProjectName: TStringArray;
  105. FGclNodes: TList;
  106. FGclChapters: TList;
  107. FGclChapterGather: TGclChapter;
  108. FOtherGcl: TGclChapter;
  109. function FindGclNode(ARec: TBillsRecord): TGclNode;
  110. function NewGclNode(ARec: TBillsRecord): TGclNode;
  111. function B_CodeToChapter(const AB_Code: string): Integer;
  112. procedure LinkGclChapter(AGclNode: TGclNode);
  113. function FindGclChapter(AChapterID: Integer): TGclChapter;
  114. procedure CalculateChapterGather;
  115. function GetGclChapterCount: Integer;
  116. function GetGclChapter(AIndex: Integer): TGclChapter;
  117. public
  118. constructor Create(AProjectCount: Integer);
  119. destructor Destroy;
  120. function AddGclNode(ANode: TBillsIDTreeNode; AProjectIndex: Integer): TGclNode;
  121. procedure Calculate;
  122. property GclChapterCount: Integer read GetGclChapterCount;
  123. property GclChapter[AIndex: Integer]: TGclChapter read GetGclChapter;
  124. property GclChapterGather: TGclChapter read FGclChapterGather;
  125. property ProjectName: TStringArray read FProjectName write FProjectName;
  126. property ProjectCount: Integer read FProjectCount;
  127. end;
  128. TPayNode = class
  129. private
  130. FName: string;
  131. FIsMinus: Boolean;
  132. FCurTotalPrice: Double;
  133. FEndTotalPrice: Double;
  134. FPreTotalPrice: Double;
  135. public
  136. property Name: string read FName write FName;
  137. property IsMinus: Boolean read FIsMinus write FisMinus;
  138. property CurTotalPrice: Double read FCurTotalPrice write FCurTotalPrice;
  139. property EndTotalPrice: Double read FEndTotalPrice write FEndTotalPrice;
  140. property PreTotalPrice: Double read FPreTotalPrice write FPreTotalPrice;
  141. end;
  142. TDealPayControl = class
  143. private
  144. FPayNodes: TList;
  145. FGatherPayNode: TPayNode;
  146. function FindPayNode(const AName: string; AIsMinus: Boolean): TPayNode;
  147. function NewPayNode(const AName: string; AIsMinus: Boolean): TPayNode;
  148. function GetPayCount: Integer;
  149. function GetPayNode(AIndex: Integer): TPayNode;
  150. public
  151. constructor Create;
  152. destructor Destroy; override;
  153. function AddPayNode(const AName: string; AIsMinus: Boolean): TPayNode;
  154. property PayCount: Integer read GetPayCount;
  155. property PayNode[AIndex: Integer]: TPayNode read GetPayNode;
  156. property GatherPayNode: TPayNode read FGatherPayNode;
  157. end;
  158. // 分别对应5张定制汇总表的编号,详见文档
  159. THaBaiGatherType = (hbgt2, hbgt3, hbgt14, hbgt3_1, hbgt4_1);
  160. TrmHaBaiCustomizedData = class(TDataModule)
  161. cdsCustom2: TClientDataSet;
  162. cdsCustom2Chapter: TIntegerField;
  163. cdsCustom2Name: TWideStringField;
  164. cdsCustom2TotalPrice: TFloatField;
  165. cdsCustom2CTotalPrice: TFloatField;
  166. cdsCustom2GTotalPrice: TFloatField;
  167. cdsCustom2EndGatherTotalPrice: TFloatField;
  168. cdsCustom2PreGatherTotalPrice: TFloatField;
  169. cdsCustom2CurGatherTotalPrice: TFloatField;
  170. cdsCustom2Percent: TFloatField;
  171. cdsCustom3: TClientDataSet;
  172. cdsCustom3ChapterID: TIntegerField;
  173. cdsCustom3InnerPartID: TIntegerField;
  174. cdsCustom3IndexCode: TStringField;
  175. cdsCustom3B_Code: TWideStringField;
  176. cdsCustom3Name: TWideStringField;
  177. cdsCustom3Units: TWideStringField;
  178. cdsCustom3Price: TFloatField;
  179. cdsCustom3Quantity: TFloatField;
  180. cdsCustom3TotalPrice: TFloatField;
  181. cdsCustom3PreGatherQuantity: TFloatField;
  182. cdsCustom3PreGatherTotalPrice: TFloatField;
  183. cdsCustom3EndGatherQuantity: TFloatField;
  184. cdsCustom3EndGatherTotalPrice: TFloatField;
  185. cdsCustom3CurGatherQuantity: TFloatField;
  186. cdsCustom3CurGatherTotalPrice: TFloatField;
  187. cdsCustom3Percent: TFloatField;
  188. cdsCustom14: TClientDataSet;
  189. cdsCustom14IndexCode: TWideStringField;
  190. cdsCustom14B_Code: TWideStringField;
  191. cdsCustom14Name: TWideStringField;
  192. cdsCustom14Units: TWideStringField;
  193. cdsCustom14Price: TFloatField;
  194. cdsCustom14Quantity: TFloatField;
  195. cdsCustom14TotalPrice: TFloatField;
  196. cdsCustom14CertificateCode: TWideStringField;
  197. cdsCustomProj: TClientDataSet;
  198. cdsCustomProjProjectID: TIntegerField;
  199. cdsCustomProjProjectName: TWideStringField;
  200. cdsCustomProjChapterID: TIntegerField;
  201. cdsCustomProjInnerPartID: TIntegerField;
  202. cdsCustomProjIndexCode: TWideStringField;
  203. cdsCustomProjB_Code: TWideStringField;
  204. cdsCustomProjName: TWideStringField;
  205. cdsCustomProjUnits: TWideStringField;
  206. cdsCustomProjPrice: TFloatField;
  207. cdsCustomProjQuantity: TFloatField;
  208. cdsCustomProjTotalPrice: TFloatField;
  209. cdsCustomProjCurGatherQuantity: TFloatField;
  210. cdsCustomProjCurGatherTotalPrice: TFloatField;
  211. cdsCustomProjEndGatherQuantity: TFloatField;
  212. cdsCustomProjEndGatherTotalPrice: TFloatField;
  213. cdsCustomProjP_CurGatherQuantity: TFloatField;
  214. cdsCustomProjP_CurGatherTotalPrice: TFloatField;
  215. cdsCustomProjP_EndGatherQuantity: TFloatField;
  216. cdsCustomProjP_EndGatherTotalPrice: TFloatField;
  217. cdsCustomProjCurPercent: TFloatField;
  218. cdsCustomProjEndPercent: TFloatField;
  219. cdsCustomProjSerialNo: TIntegerField;
  220. private
  221. FhbGatherType: THaBaiGatherType;
  222. FProjectData: TProjectData;
  223. FProjectName: string;
  224. FGclControl: TGclControl;
  225. FDealPayControl: TDealPayControl;
  226. procedure BeforeGather(AProjectCount: Integer);
  227. procedure AfterGather;
  228. procedure OpenProjectData(AProject: TSelectProject);
  229. procedure FreeProjectData;
  230. procedure GatherProject(AProject: TSelectProject; AProjectIndex: Integer);
  231. procedure FilterGcl(AProjectIndex: Integer);
  232. procedure FilterDealPay;
  233. procedure WriteFlowData;
  234. procedure WriteReport2;
  235. procedure WriteReport3;
  236. procedure WriteReport3_1;
  237. procedure WriteReport4_1;
  238. procedure WriteData;
  239. public
  240. function AssignData(AProjects: TList; AhbGatherType: THaBaiGatherType): TDataSet;
  241. end;
  242. implementation
  243. uses
  244. UtilMethods, ZhAPI, BillsCompileDm, sdDB, Globals, Math, BillsMeasureDm,
  245. ZJJLDm;
  246. {$R *.dfm}
  247. { TrmHaBaiCustomizedData }
  248. function TrmHaBaiCustomizedData.AssignData(AProjects: TList;
  249. AhbGatherType: THaBaiGatherType): TDataSet;
  250. var
  251. iProject: Integer;
  252. begin
  253. FhbGatherType := AhbGatherType;
  254. BeforeGather(AProjects.Count);
  255. try
  256. for iProject := 0 to AProjects.Count - 1 do
  257. GatherProject(TSelectProject(AProjects.Items[iProject]), iProject);
  258. FGclControl.Calculate;
  259. WriteData;
  260. finally
  261. AfterGather;
  262. case FhbGatherType of
  263. hbgt2: Result := cdsCustom2;
  264. hbgt3: Result := cdsCustom3;
  265. hbgt14: Result := cdsCustom14;
  266. hbgt3_1, hbgt4_1: Result := cdsCustomProj;
  267. end;
  268. end;
  269. end;
  270. procedure TrmHaBaiCustomizedData.BeforeGather(AProjectCount: Integer);
  271. begin
  272. cdsCustom2.DisableControls;
  273. cdsCustom2.Active := True;
  274. cdsCustom2.EmptyDataSet;
  275. cdsCustom3.DisableControls;
  276. cdsCustom3.Active := True;
  277. cdsCustom3.EmptyDataSet;
  278. cdsCustom14.DisableControls;
  279. cdsCustom14.Active := True;
  280. cdsCustom14.EmptyDataSet;
  281. cdsCustomProj.DisableControls;
  282. cdsCustomProj.Active := True;
  283. cdsCustomProj.EmptyDataSet;
  284. FGclControl := TGclControl.Create(AProjectCount);
  285. FDealPayControl := TDealPayControl.Create;
  286. end;
  287. procedure TrmHaBaiCustomizedData.AfterGather;
  288. begin
  289. FDealPayControl.Free;
  290. FGclControl.Free;
  291. cdsCustomProj.EnableControls;
  292. cdsCustom14.EnableControls;
  293. cdsCustom3.EnableControls;
  294. cdsCustom2.EnableControls;
  295. end;
  296. procedure TrmHaBaiCustomizedData.FreeProjectData;
  297. begin
  298. if not Assigned(OpenProjectManager.FindProjectData(FProjectData.ProjectID)) then
  299. FProjectData.Free;
  300. end;
  301. procedure TrmHaBaiCustomizedData.OpenProjectData(AProject: TSelectProject);
  302. var
  303. Rec: TsdDataRecord;
  304. begin
  305. FProjectData := OpenProjectManager.FindProjectData(AProject.ProjectID);
  306. Rec := ProjectManager.sddProjectsInfo.FindKey('idxID', AProject.ProjectID);
  307. if not Assigned(FProjectData) then
  308. begin
  309. FProjectData := TProjectData.Create;
  310. FProjectData.OpenForReport3(GetMyProjectsFilePath + Rec.ValueByName('FileName').AsString);
  311. end;
  312. FProjectName := Rec.ValueByName('Name').AsString;
  313. end;
  314. procedure TrmHaBaiCustomizedData.GatherProject(AProject: TSelectProject;
  315. AProjectIndex: Integer);
  316. begin
  317. OpenProjectData(AProject);
  318. try
  319. FGclControl.ProjectName[AProjectIndex] := FProjectName;
  320. if FhbGatherType in [hbgt2, hbgt3, hbgt3_1, hbgt4_1] then
  321. FilterGcl(AProjectIndex);
  322. if FhbGatherType = hbgt2 then
  323. FilterDealPay;
  324. if FhbGatherType = hbgt14 then
  325. WriteFlowData;
  326. finally
  327. FreeProjectData;
  328. end;
  329. end;
  330. procedure TrmHaBaiCustomizedData.FilterGcl(AProjectIndex: Integer);
  331. var
  332. i: Integer;
  333. vNode: TBillsIDTreeNode;
  334. GclNode: TGclNode;
  335. begin
  336. with FProjectData.BillsMeasureData do
  337. begin
  338. for i := 0 to BillsMeasureTree.Count - 1 do
  339. begin
  340. vNode := TBillsIDTreeNode(BillsMeasureTree.Items[i]);
  341. if not vNode.HasChildren and (vNode.Rec.B_Code.AsString <> '') then
  342. GclNode := FGclControl.AddGclNode(vNode, AProjectIndex);
  343. end;
  344. end;
  345. end;
  346. procedure TrmHaBaiCustomizedData.FilterDealPay;
  347. var
  348. sCurField, sPreField, sEndField: string;
  349. procedure GatherCommonDealPayData;
  350. var
  351. iRec: Integer;
  352. Rec, StageRec: TsdDataRecord;
  353. DealPay: TPayNode;
  354. begin
  355. with FProjectData.DealPaymentData do
  356. begin
  357. for iRec := 0 to sddDealPayment.RecordCount - 1 do
  358. begin
  359. Rec := sddDealPayment.Records[iRec];
  360. if SameText(Rec.ValueByName('Name').AsString, '本期完成计量') or
  361. SameText(Rec.ValueByName('Name').AsString, '本期应付') or
  362. SameText(Rec.ValueByName('Name').AsString, '本期实付') then
  363. Continue;
  364. StageRec := FProjectData.PhaseData.PhasePayData.PayRecord(Rec.ValueByName('ID').AsInteger);
  365. DealPay := FDealPayControl.AddPayNode(Rec.ValueByName('Name').AsString, Rec.ValueByName('IsMinus').AsBoolean);
  366. DealPay.CurTotalPrice := DealPay.CurTotalPrice + StageRec.ValueByName(sCurField).AsFloat;
  367. DealPay.PreTotalPrice := DealPay.PreTotalPrice + StageRec.ValueByName(sPreField).AsFloat;
  368. DealPay.EndTotalPrice := DealPay.EndTotalPrice + StageRec.ValueByName(sEndField).AsFloat;
  369. end;
  370. end;
  371. end;
  372. procedure GatherPayData;
  373. var
  374. Rec, StageRec: TsdDataRecord;
  375. begin
  376. Rec := FProjectData.DealPaymentData.DealPayRecord('本期应付');
  377. StageRec := FProjectData.PhaseData.PhasePayData.PayRecord(Rec.ValueByName('ID').AsInteger);
  378. with FDealPayControl.GatherPayNode do
  379. begin
  380. CurTotalPrice := CurTotalPrice + StageRec.ValueByName(sCurField).AsFloat;
  381. PreTotalPrice := PreTotalPrice + StageRec.ValueByName(sPreField).AsFloat;
  382. EndTotalPrice := EndTotalPrice + StageRec.ValueByName(sEndField).AsFloat;
  383. end;
  384. end;
  385. begin
  386. sCurField := 'TotalPrice' + IntToStr(FProjectData.PhaseData.AuditCount);
  387. sPreField := 'PreTotalPrice' + IntToStr(FProjectData.PhaseData.AuditCount);
  388. sEndField := 'EndTotalPrice' + IntToStr(FProjectData.PhaseData.AuditCount);
  389. GatherCommonDealPayData;
  390. GatherPayData;
  391. end;
  392. procedure TrmHaBaiCustomizedData.WriteData;
  393. begin
  394. case FhbGatherType of
  395. hbgt2: WriteReport2;
  396. hbgt3: WriteReport3;
  397. hbgt3_1: WriteReport3_1;
  398. hbgt4_1: WriteReport4_1;
  399. end;
  400. end;
  401. procedure TrmHaBaiCustomizedData.WriteReport2;
  402. procedure WriteGclChapter(AGclChapter: TGclChapter; const AName: string = '');
  403. begin
  404. cdsCustom2.Append;
  405. if AGclChapter.ChapterBegin > 0 then
  406. cdsCustom2Chapter.AsInteger := AGclChapter.ChapterBegin;
  407. if AName = '' then
  408. cdsCustom2Name.AsString := AGclChapter.Name
  409. else
  410. cdsCustom2Name.AsString := AName;
  411. cdsCustom2TotalPrice.AsFloat := AGclChapter.TotalPrice;
  412. cdsCustom2GTotalPrice.AsFloat := AGclChapter.TotalPrice;
  413. cdsCustom2EndGatherTotalPrice.AsFloat := AGclChapter.EndGatherTotalPrice;
  414. cdsCustom2PreGatherTotalPrice.AsFloat := AGclChapter.PreGatherTotalPrice;
  415. cdsCustom2CurGatherTotalPrice.AsFloat := AGclChapter.CurGatherTotalPrice;
  416. cdsCustom2Percent.AsFloat := AGclChapter.EndPercent;
  417. cdsCustom2.Post;
  418. end;
  419. procedure WriteBlankRecord(const AName: string);
  420. begin
  421. cdsCustom2.Append;
  422. cdsCustom2Name.AsString := AName;
  423. cdsCustom2.Post;
  424. end;
  425. procedure WritePayNode(APayNode: TPayNode; const AName: string = '');
  426. begin
  427. cdsCustom2.Append;
  428. if AName = '' then
  429. cdsCustom2Name.AsString := APayNode.Name
  430. else
  431. cdsCustom2Name.AsString := AName;
  432. cdsCustom2EndGatherTotalPrice.AsFloat := APayNode.EndTotalPrice;
  433. cdsCustom2PreGatherTotalPrice.AsFloat := APayNode.PreTotalPrice;
  434. cdsCustom2CurGatherTotalPrice.AsFloat := APayNode.CurTotalPrice;
  435. cdsCustom2.Post;
  436. end;
  437. var
  438. iIndex: Integer;
  439. begin
  440. for iIndex := 0 to FGclControl.GclChapterCount - 1 do
  441. WriteGclChapter(FGclControl.GclChapter[iIndex]);
  442. WriteGclChapter(FGclControl.GclChapterGather);
  443. WriteGclChapter(FGclControl.GclChapterGather, '小 计');
  444. WriteBlankRecord('价格调整');
  445. WriteBlankRecord('违约罚金');
  446. WriteBlankRecord('迟付款利息');
  447. WriteGclChapter(FGclControl.GclChapterGather, '合 计');
  448. for iIndex := 0 to FDealPayControl.PayCount - 1 do
  449. WritePayNode(FDealPayControl.PayNode[iIndex]);
  450. WritePayNode(FDealPayControl.GatherPayNode, '支 付');
  451. end;
  452. procedure TrmHaBaiCustomizedData.WriteReport3;
  453. procedure WriteChapterName(AGclChapter: TGclChapter);
  454. begin
  455. cdsCustom3.Append;
  456. cdsCustom3ChapterID.AsInteger := AGclChapter.ChapterID;
  457. cdsCustom3InnerPartID.AsInteger := 1;
  458. cdsCustom3B_Code.AsString := AGclChapter.ChapterName;
  459. cdsCustom3Name.AsString := AGclChapter.Name;
  460. cdsCustom3.Post;
  461. end;
  462. procedure WriteGclNodeData(AGclNode: TGclNode; AChapterID: Integer);
  463. begin
  464. cdsCustom3.Append;
  465. cdsCustom3ChapterID.AsInteger := AChapterID;
  466. cdsCustom3InnerPartID.AsInteger := 2;
  467. cdsCustom3IndexCode.AsString := AGclNode.IndexCode;
  468. cdsCustom3B_Code.AsString := AGclNode.B_Code;
  469. cdsCustom3Name.AsString := AGclNode.Name;
  470. cdsCustom3Units.AsString := AGclNode.Units;
  471. cdsCustom3Price.AsFloat := AGclNode.Price;
  472. cdsCustom3Quantity.AsFloat := AGclNode.Quantity;
  473. cdsCustom3TotalPrice.AsFloat := AGclNode.TotalPrice;
  474. cdsCustom3CurGatherQuantity.AsFloat := AGclNode.CurGatherQuantity;
  475. cdsCustom3CurGatherTotalPrice.AsFloat := AGclNode.CurGatherTotalPrice;
  476. cdsCustom3EndGatherQuantity.AsFloat := AGclNode.EndGatherQuantity;
  477. cdsCustom3EndGatherTotalPrice.AsFloat := AGclNode.EndGatherTotalPrice;
  478. cdsCustom3PreGatherQuantity.AsFloat := AGclNode.PreGatherQuantity;
  479. cdsCustom3PreGatherTotalPrice.AsFloat := AGclNode.PreGatherTotalPrice;
  480. cdsCustom3Percent.AsFloat := AGclNode.EndPercent;
  481. cdsCustom3.Post;
  482. end;
  483. procedure WriteChapterGather(AGclChapter: TGclChapter; const AName: string = '');
  484. begin
  485. cdsCustom3.Append;
  486. cdsCustom3ChapterID.AsInteger := AGclChapter.ChapterID;
  487. cdsCustom3InnerPartID.AsInteger := 3;
  488. if AName = '' then
  489. cdsCustom3Name.AsString := AGclChapter.Name
  490. else
  491. cdsCustom3Name.AsString := AName;
  492. cdsCustom3TotalPrice.AsFloat := AGclChapter.TotalPrice;
  493. cdsCustom3CurGatherTotalPrice.AsFloat := AGclChapter.CurGatherTotalPrice;
  494. cdsCustom3EndGatherTotalPrice.AsFloat := AGclChapter.EndGatherTotalPrice;
  495. cdsCustom3PreGatherTotalPrice.AsFloat := AGclChapter.PreGatherTotalPrice;
  496. cdsCustom3Percent.AsFloat := AGclChapter.EndPercent;
  497. cdsCustom3.Post;
  498. end;
  499. procedure WriteGclChapterData(AGclChapter: TGclChapter);
  500. var
  501. iGcl: Integer;
  502. begin
  503. if AGclChapter.GclNodeCount = 0 then Exit;
  504. WriteChapterName(AGclChapter);
  505. for iGcl := 0 to AGclChapter.GclNodeCount - 1 do
  506. WriteGclNodeData(AGclChapter.GclNode[iGcl], AGclChapter.ChapterID);
  507. WriteChapterGather(AGclChapter, Format('%s 小计', [AGclChapter.ChapterName]));
  508. end;
  509. var
  510. iIndex: Integer;
  511. begin
  512. for iIndex := 0 to FGclControl.GclChapterCount - 1 do
  513. WriteGclChapterData(FGclControl.GclChapter[iIndex]);
  514. WriteChapterGather(FGclControl.GclChapterGather, '第100章~第900章 合计');
  515. end;
  516. procedure TrmHaBaiCustomizedData.WriteReport3_1;
  517. var
  518. iProject, iChapter: Integer;
  519. sProjectName: string;
  520. procedure WriteChapterName(AGclChapter: TGclChapter);
  521. begin
  522. cdsCustomProj.Append;
  523. cdsCustomProjProjectID.AsInteger := iProject;
  524. cdsCustomProjProjectName.AsString := sProjectName;
  525. cdsCustomProjChapterID.AsInteger := AGclChapter.ChapterID;
  526. cdsCustomProjInnerPartID.AsInteger := 1;
  527. cdsCustomProjB_Code.AsString := AGclChapter.ChapterName;
  528. cdsCustomProjName.AsString := AGclChapter.Name;
  529. cdsCustomProj.Post;
  530. end;
  531. procedure WriteGclNodeData(AGclNode: TGclNode; AChapterID: Integer);
  532. begin
  533. cdsCustomProj.Append;
  534. cdsCustomProjProjectID.AsInteger := iProject;
  535. cdsCustomProjProjectName.AsString := sProjectName;
  536. cdsCustomProjChapterID.AsInteger := AChapterID;
  537. cdsCustomProjInnerPartID.AsInteger := 2;
  538. cdsCustomProjIndexCode.AsString := AGclNode.IndexCode;
  539. cdsCustomProjB_Code.AsString := AGclNode.B_Code;
  540. cdsCustomProjName.AsString := AGclNode.Name;
  541. cdsCustomProjUnits.AsString := AGclNode.Units;
  542. cdsCustomProjPrice.AsFloat := AGclNode.Price;
  543. cdsCustomProjQuantity.AsFloat := AGclNode.Quantity;
  544. cdsCustomProjTotalPrice.AsFloat := AGclNode.TotalPrice;
  545. cdsCustomProjCurGatherQuantity.AsFloat := AGclNode.CurGatherQuantity;
  546. cdsCustomProjCurGatherTotalPrice.AsFloat := AGclNode.CurGatherTotalPrice;
  547. cdsCustomProjEndGatherQuantity.AsFloat := AGclNode.EndGatherQuantity;
  548. cdsCustomProjEndGatherTotalPrice.AsFloat := AGclNode.EndGatherTotalPrice;
  549. cdsCustomProjP_CurGatherQuantity.AsFloat := AGclNode.P_CurGatherQuantity[iProject];
  550. cdsCustomProjP_CurGatherTotalPrice.AsFloat := AGclNode.P_CurGatherTotalPrice[iProject];
  551. cdsCustomProjP_EndGatherQuantity.AsFloat := AGclNode.P_EndGatherQuantity[iProject];
  552. cdsCustomProjP_EndGatherTotalPrice.AsFloat := AGclNode.P_EndGatherTotalPrice[iProject];
  553. cdsCustomProjCurPercent.AsFloat := AGclNode.CurPercent;
  554. cdsCustomProjEndPercent.AsFloat := AGclNode.EndPercent;
  555. cdsCustomProj.Post;
  556. end;
  557. procedure WriteChapterGather(AGclChapter: TGclChapter; const AName: string = '');
  558. begin
  559. cdsCustomProj.Append;
  560. cdsCustomProjProjectID.AsInteger := iProject;
  561. cdsCustomProjProjectName.AsString := sProjectName;
  562. cdsCustomProjChapterID.AsInteger := AGclChapter.ChapterID;
  563. cdsCustomProjInnerPartID.AsInteger := 3;
  564. if AName = '' then
  565. cdsCustomProjName.AsString := AGclChapter.Name
  566. else
  567. cdsCustomProjName.AsString := AName;
  568. cdsCustomProjTotalPrice.AsFloat := AGclChapter.TotalPrice;
  569. cdsCustomProjCurGatherTotalPrice.AsFloat := AGclChapter.CurGatherTotalPrice;
  570. cdsCustomProjEndGatherTotalPrice.AsFloat := AGclChapter.EndGatherTotalPrice;
  571. cdsCustomProjP_CurGatherTotalPrice.AsFloat := AGclChapter.P_CurGatherTotalPrice[iProject];
  572. cdsCustomProjP_EndGatherTotalPrice.AsFloat := AGclChapter.P_EndGatherTotalPrice[iProject];
  573. cdsCustomProjCurPercent.AsFloat := AGclChapter.CurPercent;
  574. cdsCustomProjEndPercent.AsFloat := AGclChapter.EndPercent;
  575. cdsCustomProj.Post;
  576. end;
  577. procedure WriteGclChapterData(AGclChapter: TGclChapter);
  578. var
  579. iGcl: Integer;
  580. begin
  581. if AGclChapter.GclNodeCount = 0 then Exit;
  582. WriteChapterName(AGclChapter);
  583. for iGcl := 0 to AGclChapter.GclNodeCount - 1 do
  584. WriteGclNodeData(AGclChapter.GclNode[iGcl], AGclChapter.ChapterID);
  585. WriteChapterGather(AGclChapter, Format('%s 小计', [AGclChapter.ChapterName]));
  586. end;
  587. begin
  588. for iProject := 0 to FGclControl.ProjectCount - 1 do
  589. begin
  590. sProjectName := FGclControl.ProjectName[iProject];
  591. for iChapter := 0 to FGclControl.GclChapterCount - 1 do
  592. WriteGclChapterData(FGclControl.GclChapter[iChapter]);
  593. WriteChapterGather(FGclControl.GclChapterGather, '第100章至第900章 合计');
  594. end;
  595. end;
  596. procedure TrmHaBaiCustomizedData.WriteReport4_1;
  597. var
  598. iProject, iChapter, iSerial: Integer;
  599. sProjectName: string;
  600. procedure WriteGclNodeData(AGclNode: TGclNode; AChapterID: Integer);
  601. begin
  602. cdsCustomProj.Append;
  603. cdsCustomProjProjectID.AsInteger := iProject;
  604. cdsCustomProjProjectName.AsString := sProjectName;
  605. cdsCustomProjChapterID.AsInteger := AChapterID;
  606. cdsCustomProjInnerPartID.AsInteger := 2;
  607. cdsCustomProjIndexCode.AsString := AGclNode.IndexCode;
  608. cdsCustomProjB_Code.AsString := AGclNode.B_Code;
  609. cdsCustomProjName.AsString := AGclNode.Name;
  610. cdsCustomProjUnits.AsString := AGclNode.Units;
  611. cdsCustomProjPrice.AsFloat := AGclNode.Price;
  612. cdsCustomProjQuantity.AsFloat := AGclNode.Quantity;
  613. cdsCustomProjTotalPrice.AsFloat := AGclNode.TotalPrice;
  614. cdsCustomProjCurGatherQuantity.AsFloat := AGclNode.CurGatherQuantity;
  615. cdsCustomProjCurGatherTotalPrice.AsFloat := AGclNode.CurGatherTotalPrice;
  616. cdsCustomProjEndGatherQuantity.AsFloat := AGclNode.EndGatherQuantity;
  617. cdsCustomProjEndGatherTotalPrice.AsFloat := AGclNode.EndGatherTotalPrice;
  618. cdsCustomProjP_CurGatherQuantity.AsFloat := AGclNode.P_CurGatherQuantity[iProject];
  619. cdsCustomProjP_CurGatherTotalPrice.AsFloat := AGclNode.P_CurGatherTotalPrice[iProject];
  620. cdsCustomProjP_EndGatherQuantity.AsFloat := AGclNode.P_EndGatherQuantity[iProject];
  621. cdsCustomProjP_EndGatherTotalPrice.AsFloat := AGclNode.P_EndGatherTotalPrice[iProject];
  622. cdsCustomProjCurPercent.AsFloat := AGclNode.CurPercent;
  623. cdsCustomProjEndPercent.AsFloat := AGclNode.EndPercent;
  624. cdsCustomProj.Post;
  625. end;
  626. procedure WriteGclChapterData(AGclChapter: TGclChapter);
  627. var
  628. iGcl: Integer;
  629. begin
  630. if AGclChapter.GclNodeCount = 0 then Exit;
  631. for iGcl := 0 to AGclChapter.GclNodeCount - 1 do
  632. WriteGclNodeData(AGclChapter.GclNode[iGcl], AGclChapter.ChapterID);
  633. end;
  634. procedure WriteChapterGather(AGclChapter: TGclChapter; const AName: string = '');
  635. begin
  636. cdsCustomProj.Append;
  637. cdsCustomProjProjectID.AsInteger := iProject;
  638. cdsCustomProjProjectName.AsString := sProjectName;
  639. cdsCustomProjChapterID.AsInteger := AGclChapter.ChapterID;
  640. cdsCustomProjInnerPartID.AsInteger := 3;
  641. if AName = '' then
  642. cdsCustomProjName.AsString := AGclChapter.Name
  643. else
  644. cdsCustomProjName.AsString := AName;
  645. cdsCustomProjTotalPrice.AsFloat := AGclChapter.TotalPrice;
  646. cdsCustomProjCurGatherTotalPrice.AsFloat := AGclChapter.CurGatherTotalPrice;
  647. cdsCustomProjEndGatherTotalPrice.AsFloat := AGclChapter.EndGatherTotalPrice;
  648. cdsCustomProjP_CurGatherTotalPrice.AsFloat := AGclChapter.P_CurGatherTotalPrice[iProject];
  649. cdsCustomProjP_EndGatherTotalPrice.AsFloat := AGclChapter.P_EndGatherTotalPrice[iProject];
  650. cdsCustomProjCurPercent.AsFloat := AGclChapter.CurPercent;
  651. cdsCustomProjEndPercent.AsFloat := AGclChapter.EndPercent;
  652. cdsCustomProj.Post;
  653. end;
  654. procedure ResortSerialNo;
  655. var
  656. iSerialNo, iProject: Integer;
  657. begin
  658. iSerialNo := 1;
  659. cdsCustomProj.First;
  660. iProject := cdsCustomProjProjectID.AsInteger;
  661. while not cdsCustomProj.Eof do
  662. begin
  663. if iProject <> cdsCustomProjProjectID.AsInteger then
  664. begin
  665. iProject := cdsCustomProjProjectID.AsInteger;
  666. iSerialNo := 1;
  667. end;
  668. cdsCustomProj.Edit;
  669. cdsCustomProjSerialNo.AsInteger := iSerialNo;
  670. cdsCustomProj.Post;
  671. Inc(iSerialNo);
  672. cdsCustomProj.Next;
  673. end;
  674. end;
  675. begin
  676. for iProject := 0 to FGclControl.ProjectCount - 1 do
  677. begin
  678. sProjectName := FGclControl.ProjectName[iProject];
  679. for iChapter := 0 to FGclControl.GclChapterCount - 1 do
  680. WriteGclChapterData(FGclControl.GclChapter[iChapter]);
  681. WriteChapterGather(FGclControl.GclChapterGather, '第100章至第900章 合计');
  682. end;
  683. ResortSerialNo;
  684. end;
  685. procedure TrmHaBaiCustomizedData.WriteFlowData;
  686. procedure AddNodeData(ANode: TBillsIDTreeNode);
  687. begin
  688. cdsCustom14.Append;
  689. cdsCustom14IndexCode.AsString := ANode.Rec.IndexCode.AsString;
  690. cdsCustom14B_Code.AsString := ANode.Rec.B_Code.AsString;
  691. cdsCustom14Name.AsString := ANode.Rec.Name.AsString;
  692. cdsCustom14Units.AsString := ANode.Rec.Units.AsString;
  693. cdsCustom14Price.AsFloat := ANode.Rec.Price.AsFloat;
  694. cdsCustom14Quantity.AsFloat := ANode.StageRec.GatherQuantity.AsFloat;
  695. cdsCustom14TotalPrice.AsFloat := ANode.StageRec.GatherTotalPrice.AsFloat;
  696. with FProjectData.PhaseData.ZJJLData do
  697. if cdsZJJL.Locate('BillsID', ANode.ID, []) then
  698. cdsCustom14CertificateCode.AsString := cdsZJJLCertificateCode.AsString;
  699. cdsCustom14.Post;
  700. end;
  701. var
  702. iIndex: Integer;
  703. vNode: TBillsIDTreeNode;
  704. begin
  705. for iIndex := 0 to FProjectData.BillsMeasureData.BillsMeasureTree.Count - 1 do
  706. begin
  707. vNode := TBillsIDTreeNode(FProjectData.BillsMeasureData.BillsMeasureTree.Items[iIndex]);
  708. if (not vNode.HasChildren) and (vNode.Rec.B_Code.AsString <> '') and
  709. Assigned(vNode.StageRec) and (vNode.StageRec.GatherTotalPrice.AsFloat <> 0) then
  710. AddNodeData(vNode);
  711. end;
  712. end;
  713. { TGclNode }
  714. constructor TGclNode.Create(AProjectCount: Integer);
  715. begin
  716. SetLength(FP_Quantity, AProjectCount);
  717. SetLength(FP_TotalPrice, AProjectCount);
  718. SetLength(FP_CurGatherQuantity, AProjectCount);
  719. SetLength(FP_CurGatherTotalPrice, AProjectCount);
  720. SetLength(FP_EndGatherQuantity, AProjectCount);
  721. SetLength(FP_EndGatherTotalPrice, AProjectCount);
  722. end;
  723. function TGclNode.GetCurPercent: Double;
  724. begin
  725. if TotalPrice <> 0 then
  726. Result := CurGatherTotalPrice/TotalPrice*100
  727. else
  728. Result := 0;
  729. end;
  730. function TGclNode.GetEndPercent: Double;
  731. begin
  732. if TotalPrice <> 0 then
  733. Result := EndGatherTotalPrice/TotalPrice*100
  734. else
  735. Result := 0;
  736. end;
  737. procedure TGclNode.SetB_Code(const Value: string);
  738. begin
  739. FB_Code := Value;
  740. FIndexCode := B_CodeToIndexCode(FB_Code);
  741. end;
  742. { TGclControl }
  743. function TGclControl.AddGclNode(ANode: TBillsIDTreeNode; AProjectIndex: Integer): TGclNode;
  744. begin
  745. Result := FindGclNode(ANode.Rec);
  746. if not Assigned(Result) then
  747. Result := NewGclNode(ANode.Rec);
  748. with ANode.Rec do
  749. begin
  750. Result.Quantity := Result.Quantity + Quantity.AsFloat;
  751. Result.TotalPrice := Result.TotalPrice + TotalPrice.AsFloat;
  752. Result.P_Quantity[AProjectIndex] := Result.P_Quantity[AProjectIndex] + Quantity.AsFloat;
  753. Result.P_TotalPrice[AProjectIndex] := Result.P_TotalPrice[AProjectIndex] + TotalPrice.AsFloat;
  754. end;
  755. if Assigned(ANode.StageRec) then
  756. with ANode.StageRec do
  757. begin
  758. Result.CurGatherQuantity := Result.CurGatherQuantity + GatherQuantity.AsFloat;
  759. Result.CurGatherTotalPrice := Result.CurGatherTotalPrice + GatherTotalPrice.AsFloat;
  760. Result.P_CurGatherQuantity[AProjectIndex] := Result.P_CurGatherQuantity[AProjectIndex] + GatherQuantity.AsFloat;
  761. Result.P_CurGatherTotalPrice[AProjectIndex] := Result.P_CurGatherTotalPrice[AProjectIndex] + GatherTotalPrice.AsFloat;
  762. Result.EndGatherQuantity := Result.EndGatherQuantity + EndGatherQuantity.AsFloat;
  763. Result.EndGatherTotalPrice := Result.EndGatherTotalPrice + EndGatherTotalPrice.AsFloat;
  764. Result.P_EndGatherQuantity[AProjectIndex] := Result.P_EndGatherQuantity[AProjectIndex] + EndGatherQuantity.AsFloat;
  765. Result.P_EndGatherTotalPrice[AProjectIndex] := Result.P_EndGatherTotalPrice[AProjectIndex] + EndGatherTotalPrice.AsFloat;
  766. Result.PreGatherQuantity := Result.PreGatherQuantity + PreGatherQuantity.AsFloat;
  767. Result.PreGatherTotalPrice := Result.PreGatherTotalPrice + PreGatherTotalPrice.AsFloat;
  768. end;
  769. end;
  770. function TGclControl.B_CodeToChapter(const AB_Code: string): Integer;
  771. var
  772. sgs: TStrings;
  773. iFirst, iSecond: Integer;
  774. begin
  775. Result := 0;
  776. sgs := TStringList.Create;
  777. try
  778. sgs.Delimiter := '-';
  779. sgs.DelimitedText := AB_Code;
  780. iFirst := StrToIntDef(sgs.Strings[0], 0);
  781. Result := Trunc(iFirst/100);
  782. if (Result >= 90) and (Result < 100) then
  783. Result := 9;
  784. finally
  785. sgs.Free;
  786. end;
  787. end;
  788. procedure TGclControl.CalculateChapterGather;
  789. var
  790. iIndex, iProject: Integer;
  791. vGclChapter: TGclChapter;
  792. begin
  793. FGclChapterGather.TotalPrice := 0;
  794. FGclChapterGather.CurGatherTotalPrice := 0;
  795. FGclChapterGather.EndGatherTotalPrice := 0;
  796. FGclChapterGather.PreGatherTotalPrice := 0;
  797. for iProject := 0 to FProjectCount - 1 do
  798. begin
  799. FGclChapterGather.P_TotalPrice[iProject] := 0;
  800. FGclChapterGather.P_CurGatherTotalPrice[iProject] := 0;
  801. FGclChapterGather.P_EndGatherTotalPrice[iProject] := 0;
  802. end;
  803. for iIndex := 0 to FGclChapters.Count - 1 do
  804. begin
  805. vGclChapter := TGclChapter(FGclChapters.Items[iIndex]);
  806. with FGclChapterGather do
  807. begin
  808. TotalPrice := TotalPrice + vGclChapter.TotalPrice;
  809. CurGatherTotalPrice := CurGatherTotalPrice + vGclChapter.CurGatherTotalPrice;
  810. EndGatherTotalPrice := EndGatherTotalPrice + vGclChapter.EndGatherTotalPrice;
  811. PreGatherTotalPrice := PreGatherTotalPrice + vGclChapter.PreGatherTotalPrice;
  812. for iProject := 0 to FProjectCount - 1 do
  813. begin
  814. P_TotalPrice[iProject] := P_TotalPrice[iProject] + vGclChapter.P_TotalPrice[iProject];
  815. P_CurGatherTotalPrice[iProject] := P_CurGatherTotalPrice[iProject] + vGclChapter.P_CurGatherTotalPrice[iProject];
  816. P_EndGatherTotalPrice[iProject] := P_EndGatherTotalPrice[iProject] + vGclChapter.P_EndGatherTotalPrice[iProject];
  817. end;
  818. end;
  819. end;
  820. end;
  821. constructor TGclControl.Create(AProjectCount: Integer);
  822. function CreateGclChapter(AChapterID: Integer; const AName: string): TGclChapter;
  823. begin
  824. Result := TGclChapter.Create(AChapterID, AName, FProjectCount);
  825. FGclChapters.Add(Result);
  826. end;
  827. begin
  828. FProjectCount := AProjectCount;
  829. SetLength(FProjectName, AProjectCount);
  830. FGclNodes := TList.Create;
  831. FGclChapters := TList.Create;
  832. CreateGclChapter(1, '总 则');
  833. CreateGclChapter(2, '路 基');
  834. CreateGclChapter(3, '路 面');
  835. CreateGclChapter(4, '桥梁、涵洞工程');
  836. CreateGclChapter(5, '隧 道');
  837. CreateGclChapter(6, '安全设计及预埋管线');
  838. CreateGclChapter(7, '绿化及环境保护工程');
  839. CreateGclChapter(8, '房建工程');
  840. CreateGclChapter(9, '机电工程');
  841. FOtherGcl := TGclChapter.Create(19, '非标准清单', FProjectCount);
  842. FGclChapterGather := TGclChapter.Create(20, '第100章至900章合计', FProjectCount);
  843. end;
  844. destructor TGclControl.Destroy;
  845. begin
  846. FOtherGcl.Free;
  847. FGclChapterGather.Free;
  848. ClearObjects(FGclChapters);
  849. FGclChapters.Free;
  850. ClearObjects(FGclNodes);
  851. FGclNodes.Free;
  852. end;
  853. function TGclControl.FindGclNode(ARec: TBillsRecord): TGclNode;
  854. var
  855. iIndex: Integer;
  856. vGclNode: TGclNode;
  857. bSameCode, bSameName, bSameUnits, bSamePrice: Boolean;
  858. begin
  859. Result := nil;
  860. for iIndex := 0 to FGclNodes.Count - 1 do
  861. begin
  862. vGclNode := TGclNode(FGclNodes.Items[iIndex]);
  863. if (vGclNode.B_Code = ARec.B_Code.AsString) and
  864. (vGclNode.Name = ARec.Name.AsString) and
  865. (vGclNode.Units = ARec.Units.AsString) and
  866. (vGclNode.Price = ARec.Price.AsFloat) then
  867. begin
  868. Result := vGclNode;
  869. Break;
  870. end;
  871. end;
  872. end;
  873. function TGclControl.FindGclChapter(AChapterID: Integer): TGclChapter;
  874. var
  875. iIndex: Integer;
  876. vChapter: TGclChapter;
  877. begin
  878. Result := nil;
  879. for iIndex := 0 to FGclChapters.Count - 1 do
  880. begin
  881. vChapter := TGclChapter(FGclChapters.Items[iIndex]);
  882. if vChapter.ChapterID = AChapterID then
  883. begin
  884. Result := vChapter;
  885. Break;
  886. end;
  887. end;
  888. end;
  889. function TGclControl.GetGclChapter(AIndex: Integer): TGclChapter;
  890. begin
  891. Result := TGclChapter(FGclChapters.Items[AIndex]);
  892. end;
  893. function TGclControl.GetGclChapterCount: Integer;
  894. begin
  895. Result := FGclChapters.Count;
  896. end;
  897. procedure TGclControl.LinkGclChapter(AGclNode: TGclNode);
  898. var
  899. iChapterID: Integer;
  900. vChapter: TGclChapter;
  901. begin
  902. iChapterID := B_CodeToChapter(AGclNode.B_Code);
  903. vChapter := FindGclChapter(iChapterID);
  904. if Assigned(vChapter) then
  905. vChapter.AddGclNode(AGclNode)
  906. else
  907. FOtherGcl.AddGclNode(AGclNode);
  908. end;
  909. function TGclControl.NewGclNode(ARec: TBillsRecord): TGclNode;
  910. begin
  911. Result := TGclNode.Create(FProjectCount);
  912. FGclNodes.Add(Result);
  913. Result.B_Code := ARec.B_Code.AsString;
  914. Result.Name := ARec.Name.AsString;
  915. Result.Units := ARec.Units.AsString;
  916. Result.Price := ARec.Price.AsFloat;
  917. LinkGclChapter(Result);
  918. end;
  919. procedure TGclControl.Calculate;
  920. var
  921. i: Integer;
  922. begin
  923. for i := 0 to GclChapterCount - 1 do
  924. GclChapter[i].CalculateChapter;
  925. CalculateChapterGather;
  926. end;
  927. { TGclChapter }
  928. procedure TGclChapter.AddGclNode(AGclNode: TGclNode);
  929. begin
  930. FGclNodes.Add(AGclNode);
  931. end;
  932. procedure TGclChapter.CalculateChapter;
  933. var
  934. iIndex, iProject: Integer;
  935. vGclNode: TGclNode;
  936. begin
  937. FTotalPrice := 0;
  938. FCurGatherTotalPrice := 0;
  939. FEndGatherTotalPrice := 0;
  940. FPreGatherTotalPrice := 0;
  941. for iProject := 0 to FProjectCount - 1 do
  942. begin
  943. FP_TotalPrice[iProject] := 0;
  944. FP_CurGatherTotalPrice[iProject] := 0;
  945. FP_EndGatherTotalPrice[iProject] := 0;
  946. end;
  947. for iIndex := 0 to FGclNodes.Count - 1 do
  948. begin
  949. vGclNode := TGclNode(FGclNodes.Items[iIndex]);
  950. FTotalPrice := FTotalPrice + vGclNode.TotalPrice;
  951. FCurGatherTotalPrice := FCurGatherTotalPrice + vGclNode.FCurGatherTotalPrice;
  952. FEndGatherTotalPrice := FEndGatherTotalPrice + vGclNode.FEndGatherTotalPrice;
  953. FPreGatherTotalPrice := FPreGatherTotalPrice + vGclNode.FPreGatherTotalPrice;
  954. for iProject := 0 to FProjectCount - 1 do
  955. begin
  956. FP_TotalPrice[iProject] := FP_TotalPrice[iProject] + vGclNode.P_TotalPrice[iProject];
  957. FP_CurGatherTotalPrice[iProject] := FP_CurGatherTotalPrice[iProject] + vGclNode.P_CurGatherTotalPrice[iProject];
  958. FP_EndGatherTotalPrice[iProject] := FP_EndGatherTotalPrice[iProject] + vGclNode.P_EndGatherTotalPrice[iProject];
  959. end;
  960. end;
  961. end;
  962. constructor TGclChapter.Create(AChapterID: Integer; const AName: string;
  963. AProjectCount: Integer);
  964. begin
  965. FGclNodes := TList.Create;
  966. FChapterID := AChapterID;
  967. if FChapterID < 19 then
  968. begin
  969. FChapterBegin := FChapterID * 100;
  970. FChapterEnd := FChapterBegin + 99;
  971. FChapterName := Format('第%d章', [FChapterBegin]);
  972. end;
  973. FName := AName;
  974. FProjectCount := AProjectCount;
  975. SetLength(FP_TotalPrice, FProjectCount);
  976. SetLength(FP_CurGatherTotalPrice, FProjectCount);
  977. SetLength(FP_EndGatherTotalPrice, FProjectCount);
  978. end;
  979. destructor TGclChapter.Destroy;
  980. begin
  981. FGclNodes.Free;
  982. inherited;
  983. end;
  984. function TGclChapter.GetCurPercent: Double;
  985. begin
  986. if TotalPrice <> 0 then
  987. Result := CurGatherTotalPrice/TotalPrice*100
  988. else
  989. Result := 0;
  990. end;
  991. function TGclChapter.GetEndPercent: Double;
  992. begin
  993. if TotalPrice <> 0 then
  994. Result := EndGatherTotalPrice/TotalPrice*100
  995. else
  996. Result := 0;
  997. end;
  998. function TGclChapter.GetGclNode(AIndex: Integer): TGclNode;
  999. begin
  1000. Result := TGclNode(FGclNodes.Items[AIndex]);
  1001. end;
  1002. function TGclChapter.GetGclNodeCount: Integer;
  1003. begin
  1004. Result := FGclNodes.Count;
  1005. end;
  1006. { TDealPayControl }
  1007. function TDealPayControl.AddPayNode(const AName: string;
  1008. AIsMinus: Boolean): TPayNode;
  1009. begin
  1010. Result := FindPayNode(AName, AIsMinus);
  1011. if not Assigned(Result) then
  1012. Result := NewPayNode(AName, AIsMinus);
  1013. end;
  1014. constructor TDealPayControl.Create;
  1015. begin
  1016. FPayNodes := TList.Create;
  1017. FGatherPayNode := TPayNode.Create;
  1018. end;
  1019. destructor TDealPayControl.Destroy;
  1020. begin
  1021. FGatherPayNode.Free;
  1022. ClearObjects(FPayNodes);
  1023. FPayNodes.Free;
  1024. inherited;
  1025. end;
  1026. function TDealPayControl.FindPayNode(const AName: string;
  1027. AIsMinus: Boolean): TPayNode;
  1028. var
  1029. iIndex: Integer;
  1030. vPayNode: TPayNode;
  1031. begin
  1032. Result := nil;
  1033. for iIndex := 0 to FPayNodes.Count -1 do
  1034. begin
  1035. vPayNode := TPayNode(FPayNodes.Items[iIndex]);
  1036. if (vPayNode.Name = AName) and (vPayNode.IsMinus = AIsMinus) then
  1037. begin
  1038. Result := vPayNode;
  1039. Break;
  1040. end;
  1041. end;
  1042. end;
  1043. function TDealPayControl.GetPayCount: Integer;
  1044. begin
  1045. Result := FPayNodes.Count;
  1046. end;
  1047. function TDealPayControl.GetPayNode(AIndex: Integer): TPayNode;
  1048. begin
  1049. Result := TPayNode(FPayNodes.Items[AIndex]);
  1050. end;
  1051. function TDealPayControl.NewPayNode(const AName: string;
  1052. AIsMinus: Boolean): TPayNode;
  1053. begin
  1054. Result := TPayNode.Create;
  1055. FPayNodes.Add(Result);
  1056. Result.Name := AName;
  1057. Result.IsMinus := AIsMinus;
  1058. end;
  1059. end.