rmHaBaiCustomizedDm.pas 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210
  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. cdsCustom2.Post;
  417. end;
  418. procedure WriteBlankRecord(const AName: string);
  419. begin
  420. cdsCustom2.Append;
  421. cdsCustom2Name.AsString := AName;
  422. cdsCustom2.Post;
  423. end;
  424. procedure WritePayNode(APayNode: TPayNode; const AName: string = '');
  425. begin
  426. cdsCustom2.Append;
  427. if AName = '' then
  428. cdsCustom2Name.AsString := APayNode.Name
  429. else
  430. cdsCustom2Name.AsString := AName;
  431. cdsCustom2EndGatherTotalPrice.AsFloat := APayNode.EndTotalPrice;
  432. cdsCustom2PreGatherTotalPrice.AsFloat := APayNode.PreTotalPrice;
  433. cdsCustom2CurGatherTotalPrice.AsFloat := APayNode.CurTotalPrice;
  434. cdsCustom2.Post;
  435. end;
  436. var
  437. iIndex: Integer;
  438. begin
  439. for iIndex := 0 to FGclControl.GclChapterCount - 1 do
  440. WriteGclChapter(FGclControl.GclChapter[iIndex]);
  441. WriteGclChapter(FGclControl.GclChapterGather);
  442. WriteGclChapter(FGclControl.GclChapterGather, '小 计');
  443. WriteBlankRecord('价格调整');
  444. WriteBlankRecord('违约罚金');
  445. WriteBlankRecord('迟付款利息');
  446. WriteGclChapter(FGclControl.GclChapterGather, '合 计');
  447. for iIndex := 0 to FDealPayControl.PayCount - 1 do
  448. WritePayNode(FDealPayControl.PayNode[iIndex]);
  449. WritePayNode(FDealPayControl.GatherPayNode, '支 付');
  450. end;
  451. procedure TrmHaBaiCustomizedData.WriteReport3;
  452. procedure WriteChapterName(AGclChapter: TGclChapter);
  453. begin
  454. cdsCustom3.Append;
  455. cdsCustom3ChapterID.AsInteger := AGclChapter.ChapterID;
  456. cdsCustom3InnerPartID.AsInteger := 1;
  457. cdsCustom3B_Code.AsString := AGclChapter.ChapterName;
  458. cdsCustom3Name.AsString := AGclChapter.Name;
  459. cdsCustom3.Post;
  460. end;
  461. procedure WriteGclNodeData(AGclNode: TGclNode; AChapterID: Integer);
  462. begin
  463. cdsCustom3.Append;
  464. cdsCustom3ChapterID.AsInteger := AChapterID;
  465. cdsCustom3InnerPartID.AsInteger := 2;
  466. cdsCustom3IndexCode.AsString := AGclNode.IndexCode;
  467. cdsCustom3B_Code.AsString := AGclNode.B_Code;
  468. cdsCustom3Name.AsString := AGclNode.Name;
  469. cdsCustom3Units.AsString := AGclNode.Units;
  470. cdsCustom3Price.AsFloat := AGclNode.Price;
  471. cdsCustom3Quantity.AsFloat := AGclNode.Quantity;
  472. cdsCustom3TotalPrice.AsFloat := AGclNode.TotalPrice;
  473. cdsCustom3CurGatherQuantity.AsFloat := AGclNode.CurGatherQuantity;
  474. cdsCustom3CurGatherTotalPrice.AsFloat := AGclNode.CurGatherTotalPrice;
  475. cdsCustom3EndGatherQuantity.AsFloat := AGclNode.EndGatherQuantity;
  476. cdsCustom3EndGatherTotalPrice.AsFloat := AGclNode.EndGatherTotalPrice;
  477. cdsCustom3PreGatherQuantity.AsFloat := AGclNode.PreGatherQuantity;
  478. cdsCustom3PreGatherTotalPrice.AsFloat := AGclNode.PreGatherTotalPrice;
  479. cdsCustom3.Post;
  480. end;
  481. procedure WriteChapterGather(AGclChapter: TGclChapter; const AName: string = '');
  482. begin
  483. cdsCustom3.Append;
  484. cdsCustom3ChapterID.AsInteger := AGclChapter.ChapterID;
  485. cdsCustom3InnerPartID.AsInteger := 3;
  486. if AName = '' then
  487. cdsCustom3Name.AsString := AGclChapter.Name
  488. else
  489. cdsCustom3Name.AsString := AName;
  490. cdsCustom3TotalPrice.AsFloat := AGclChapter.TotalPrice;
  491. cdsCustom3CurGatherTotalPrice.AsFloat := AGclChapter.CurGatherTotalPrice;
  492. cdsCustom3EndGatherTotalPrice.AsFloat := AGclChapter.EndGatherTotalPrice;
  493. cdsCustom3PreGatherTotalPrice.AsFloat := AGclChapter.PreGatherTotalPrice;
  494. cdsCustom3.Post;
  495. end;
  496. procedure WriteGclChapterData(AGclChapter: TGclChapter);
  497. var
  498. iGcl: Integer;
  499. begin
  500. if AGclChapter.GclNodeCount = 0 then Exit;
  501. WriteChapterName(AGclChapter);
  502. for iGcl := 0 to AGclChapter.GclNodeCount - 1 do
  503. WriteGclNodeData(AGclChapter.GclNode[iGcl], AGclChapter.ChapterID);
  504. WriteChapterGather(AGclChapter, Format('%s 小计', [AGclChapter.ChapterName]));
  505. end;
  506. var
  507. iIndex: Integer;
  508. begin
  509. for iIndex := 0 to FGclControl.GclChapterCount - 1 do
  510. WriteGclChapterData(FGclControl.GclChapter[iIndex]);
  511. WriteChapterGather(FGclControl.GclChapterGather, '第100章~第900章 合计');
  512. end;
  513. procedure TrmHaBaiCustomizedData.WriteReport3_1;
  514. var
  515. iProject, iChapter: Integer;
  516. sProjectName: string;
  517. procedure WriteChapterName(AGclChapter: TGclChapter);
  518. begin
  519. cdsCustomProj.Append;
  520. cdsCustomProjProjectID.AsInteger := iProject;
  521. cdsCustomProjProjectName.AsString := sProjectName;
  522. cdsCustomProjChapterID.AsInteger := AGclChapter.ChapterID;
  523. cdsCustomProjInnerPartID.AsInteger := 1;
  524. cdsCustomProjB_Code.AsString := AGclChapter.ChapterName;
  525. cdsCustomProjName.AsString := AGclChapter.Name;
  526. cdsCustomProj.Post;
  527. end;
  528. procedure WriteGclNodeData(AGclNode: TGclNode; AChapterID: Integer);
  529. begin
  530. cdsCustomProj.Append;
  531. cdsCustomProjProjectID.AsInteger := iProject;
  532. cdsCustomProjProjectName.AsString := sProjectName;
  533. cdsCustomProjChapterID.AsInteger := AChapterID;
  534. cdsCustomProjInnerPartID.AsInteger := 2;
  535. cdsCustomProjIndexCode.AsString := AGclNode.IndexCode;
  536. cdsCustomProjB_Code.AsString := AGclNode.B_Code;
  537. cdsCustomProjName.AsString := AGclNode.Name;
  538. cdsCustomProjUnits.AsString := AGclNode.Units;
  539. cdsCustomProjPrice.AsFloat := AGclNode.Price;
  540. cdsCustomProjQuantity.AsFloat := AGclNode.Quantity;
  541. cdsCustomProjTotalPrice.AsFloat := AGclNode.TotalPrice;
  542. cdsCustomProjCurGatherQuantity.AsFloat := AGclNode.CurGatherQuantity;
  543. cdsCustomProjCurGatherTotalPrice.AsFloat := AGclNode.CurGatherTotalPrice;
  544. cdsCustomProjEndGatherQuantity.AsFloat := AGclNode.EndGatherQuantity;
  545. cdsCustomProjEndGatherTotalPrice.AsFloat := AGclNode.EndGatherTotalPrice;
  546. cdsCustomProjP_CurGatherQuantity.AsFloat := AGclNode.P_CurGatherQuantity[iProject];
  547. cdsCustomProjP_CurGatherTotalPrice.AsFloat := AGclNode.P_CurGatherTotalPrice[iProject];
  548. cdsCustomProjP_EndGatherQuantity.AsFloat := AGclNode.P_EndGatherQuantity[iProject];
  549. cdsCustomProjP_EndGatherTotalPrice.AsFloat := AGclNode.P_EndGatherTotalPrice[iProject];
  550. cdsCustomProjCurPercent.AsFloat := AGclNode.CurPercent;
  551. cdsCustomProjEndPercent.AsFloat := AGclNode.EndPercent;
  552. cdsCustomProj.Post;
  553. end;
  554. procedure WriteChapterGather(AGclChapter: TGclChapter; const AName: string = '');
  555. begin
  556. cdsCustomProj.Append;
  557. cdsCustomProjProjectID.AsInteger := iProject;
  558. cdsCustomProjProjectName.AsString := sProjectName;
  559. cdsCustomProjChapterID.AsInteger := AGclChapter.ChapterID;
  560. cdsCustomProjInnerPartID.AsInteger := 3;
  561. if AName = '' then
  562. cdsCustomProjName.AsString := AGclChapter.Name
  563. else
  564. cdsCustomProjName.AsString := AName;
  565. cdsCustomProjTotalPrice.AsFloat := AGclChapter.TotalPrice;
  566. cdsCustomProjCurGatherTotalPrice.AsFloat := AGclChapter.CurGatherTotalPrice;
  567. cdsCustomProjEndGatherTotalPrice.AsFloat := AGclChapter.EndGatherTotalPrice;
  568. cdsCustomProjP_CurGatherTotalPrice.AsFloat := AGclChapter.P_CurGatherTotalPrice[iProject];
  569. cdsCustomProjP_EndGatherTotalPrice.AsFloat := AGclChapter.P_EndGatherTotalPrice[iProject];
  570. cdsCustomProjCurPercent.AsFloat := AGclChapter.CurPercent;
  571. cdsCustomProjEndPercent.AsFloat := AGclChapter.EndPercent;
  572. cdsCustomProj.Post;
  573. end;
  574. procedure WriteGclChapterData(AGclChapter: TGclChapter);
  575. var
  576. iGcl: Integer;
  577. begin
  578. if AGclChapter.GclNodeCount = 0 then Exit;
  579. WriteChapterName(AGclChapter);
  580. for iGcl := 0 to AGclChapter.GclNodeCount - 1 do
  581. WriteGclNodeData(AGclChapter.GclNode[iGcl], AGclChapter.ChapterID);
  582. WriteChapterGather(AGclChapter, Format('%s 小计', [AGclChapter.ChapterName]));
  583. end;
  584. begin
  585. for iProject := 0 to FGclControl.ProjectCount - 1 do
  586. begin
  587. sProjectName := FGclControl.ProjectName[iProject];
  588. for iChapter := 0 to FGclControl.GclChapterCount - 1 do
  589. WriteGclChapterData(FGclControl.GclChapter[iChapter]);
  590. WriteChapterGather(FGclControl.GclChapterGather, '第100章至第900章 合计');
  591. end;
  592. end;
  593. procedure TrmHaBaiCustomizedData.WriteReport4_1;
  594. var
  595. iProject, iChapter, iSerial: Integer;
  596. sProjectName: string;
  597. procedure WriteGclNodeData(AGclNode: TGclNode; AChapterID: Integer);
  598. begin
  599. cdsCustomProj.Append;
  600. cdsCustomProjProjectID.AsInteger := iProject;
  601. cdsCustomProjProjectName.AsString := sProjectName;
  602. cdsCustomProjChapterID.AsInteger := AChapterID;
  603. cdsCustomProjInnerPartID.AsInteger := 2;
  604. cdsCustomProjIndexCode.AsString := AGclNode.IndexCode;
  605. cdsCustomProjB_Code.AsString := AGclNode.B_Code;
  606. cdsCustomProjName.AsString := AGclNode.Name;
  607. cdsCustomProjUnits.AsString := AGclNode.Units;
  608. cdsCustomProjPrice.AsFloat := AGclNode.Price;
  609. cdsCustomProjQuantity.AsFloat := AGclNode.Quantity;
  610. cdsCustomProjTotalPrice.AsFloat := AGclNode.TotalPrice;
  611. cdsCustomProjCurGatherQuantity.AsFloat := AGclNode.CurGatherQuantity;
  612. cdsCustomProjCurGatherTotalPrice.AsFloat := AGclNode.CurGatherTotalPrice;
  613. cdsCustomProjEndGatherQuantity.AsFloat := AGclNode.EndGatherQuantity;
  614. cdsCustomProjEndGatherTotalPrice.AsFloat := AGclNode.EndGatherTotalPrice;
  615. cdsCustomProjP_CurGatherQuantity.AsFloat := AGclNode.P_CurGatherQuantity[iProject];
  616. cdsCustomProjP_CurGatherTotalPrice.AsFloat := AGclNode.P_CurGatherTotalPrice[iProject];
  617. cdsCustomProjP_EndGatherQuantity.AsFloat := AGclNode.P_EndGatherQuantity[iProject];
  618. cdsCustomProjP_EndGatherTotalPrice.AsFloat := AGclNode.P_EndGatherTotalPrice[iProject];
  619. cdsCustomProjCurPercent.AsFloat := AGclNode.CurPercent;
  620. cdsCustomProjEndPercent.AsFloat := AGclNode.EndPercent;
  621. cdsCustomProj.Post;
  622. end;
  623. procedure WriteGclChapterData(AGclChapter: TGclChapter);
  624. var
  625. iGcl: Integer;
  626. begin
  627. if AGclChapter.GclNodeCount = 0 then Exit;
  628. for iGcl := 0 to AGclChapter.GclNodeCount - 1 do
  629. WriteGclNodeData(AGclChapter.GclNode[iGcl], AGclChapter.ChapterID);
  630. end;
  631. procedure WriteChapterGather(AGclChapter: TGclChapter; const AName: string = '');
  632. begin
  633. cdsCustomProj.Append;
  634. cdsCustomProjProjectID.AsInteger := iProject;
  635. cdsCustomProjProjectName.AsString := sProjectName;
  636. cdsCustomProjChapterID.AsInteger := AGclChapter.ChapterID;
  637. cdsCustomProjInnerPartID.AsInteger := 3;
  638. if AName = '' then
  639. cdsCustomProjName.AsString := AGclChapter.Name
  640. else
  641. cdsCustomProjName.AsString := AName;
  642. cdsCustomProjTotalPrice.AsFloat := AGclChapter.TotalPrice;
  643. cdsCustomProjCurGatherTotalPrice.AsFloat := AGclChapter.CurGatherTotalPrice;
  644. cdsCustomProjEndGatherTotalPrice.AsFloat := AGclChapter.EndGatherTotalPrice;
  645. cdsCustomProjP_CurGatherTotalPrice.AsFloat := AGclChapter.P_CurGatherTotalPrice[iProject];
  646. cdsCustomProjP_EndGatherTotalPrice.AsFloat := AGclChapter.P_EndGatherTotalPrice[iProject];
  647. cdsCustomProjCurPercent.AsFloat := AGclChapter.CurPercent;
  648. cdsCustomProjEndPercent.AsFloat := AGclChapter.EndPercent;
  649. cdsCustomProj.Post;
  650. end;
  651. procedure ResortSerialNo;
  652. var
  653. iSerialNo, iProject: Integer;
  654. begin
  655. iSerialNo := 1;
  656. cdsCustomProj.First;
  657. iProject := cdsCustomProjProjectID.AsInteger;
  658. while not cdsCustomProj.Eof do
  659. begin
  660. if iProject <> cdsCustomProjProjectID.AsInteger then
  661. begin
  662. iProject := cdsCustomProjProjectID.AsInteger;
  663. iSerialNo := 1;
  664. end;
  665. cdsCustomProj.Edit;
  666. cdsCustomProjSerialNo.AsInteger := iSerialNo;
  667. cdsCustomProj.Post;
  668. Inc(iSerialNo);
  669. cdsCustomProj.Next;
  670. end;
  671. end;
  672. begin
  673. for iProject := 0 to FGclControl.ProjectCount - 1 do
  674. begin
  675. sProjectName := FGclControl.ProjectName[iProject];
  676. for iChapter := 0 to FGclControl.GclChapterCount - 1 do
  677. WriteGclChapterData(FGclControl.GclChapter[iChapter]);
  678. WriteChapterGather(FGclControl.GclChapterGather, '第100章至第900章 合计');
  679. end;
  680. ResortSerialNo;
  681. end;
  682. procedure TrmHaBaiCustomizedData.WriteFlowData;
  683. procedure AddNodeData(ANode: TBillsIDTreeNode);
  684. begin
  685. cdsCustom14.Append;
  686. cdsCustom14IndexCode.AsString := ANode.Rec.IndexCode.AsString;
  687. cdsCustom14B_Code.AsString := ANode.Rec.B_Code.AsString;
  688. cdsCustom14Name.AsString := ANode.Rec.Name.AsString;
  689. cdsCustom14Units.AsString := ANode.Rec.Units.AsString;
  690. cdsCustom14Price.AsFloat := ANode.Rec.Price.AsFloat;
  691. cdsCustom14Quantity.AsFloat := ANode.StageRec.GatherQuantity.AsFloat;
  692. cdsCustom14TotalPrice.AsFloat := ANode.StageRec.GatherTotalPrice.AsFloat;
  693. with FProjectData.PhaseData.ZJJLData do
  694. if cdsZJJL.Locate('BillsID', ANode.ID, []) then
  695. cdsCustom14CertificateCode.AsString := cdsZJJLCertificateCode.AsString;
  696. cdsCustom14.Post;
  697. end;
  698. var
  699. iIndex: Integer;
  700. vNode: TBillsIDTreeNode;
  701. begin
  702. for iIndex := 0 to FProjectData.BillsMeasureData.BillsMeasureTree.Count - 1 do
  703. begin
  704. vNode := TBillsIDTreeNode(FProjectData.BillsMeasureData.BillsMeasureTree.Items[iIndex]);
  705. if (not vNode.HasChildren) and (vNode.Rec.B_Code.AsString <> '') and
  706. Assigned(vNode.StageRec) and (vNode.StageRec.GatherTotalPrice.AsFloat <> 0) then
  707. AddNodeData(vNode);
  708. end;
  709. end;
  710. { TGclNode }
  711. constructor TGclNode.Create(AProjectCount: Integer);
  712. begin
  713. SetLength(FP_Quantity, AProjectCount);
  714. SetLength(FP_TotalPrice, AProjectCount);
  715. SetLength(FP_CurGatherQuantity, AProjectCount);
  716. SetLength(FP_CurGatherTotalPrice, AProjectCount);
  717. SetLength(FP_EndGatherQuantity, AProjectCount);
  718. SetLength(FP_EndGatherTotalPrice, AProjectCount);
  719. end;
  720. function TGclNode.GetCurPercent: Double;
  721. begin
  722. if TotalPrice <> 0 then
  723. Result := CurGatherTotalPrice/TotalPrice*100
  724. else
  725. Result := 0;
  726. end;
  727. function TGclNode.GetEndPercent: Double;
  728. begin
  729. if TotalPrice <> 0 then
  730. Result := EndGatherTotalPrice/TotalPrice*100
  731. else
  732. Result := 0;
  733. end;
  734. procedure TGclNode.SetB_Code(const Value: string);
  735. begin
  736. FB_Code := Value;
  737. FIndexCode := B_CodeToIndexCode(FB_Code);
  738. end;
  739. { TGclControl }
  740. function TGclControl.AddGclNode(ANode: TBillsIDTreeNode; AProjectIndex: Integer): TGclNode;
  741. begin
  742. Result := FindGclNode(ANode.Rec);
  743. if not Assigned(Result) then
  744. Result := NewGclNode(ANode.Rec);
  745. with ANode.Rec do
  746. begin
  747. Result.Quantity := Result.Quantity + Quantity.AsFloat;
  748. Result.TotalPrice := Result.TotalPrice + TotalPrice.AsFloat;
  749. Result.P_Quantity[AProjectIndex] := Result.P_Quantity[AProjectIndex] + Quantity.AsFloat;
  750. Result.P_TotalPrice[AProjectIndex] := Result.P_TotalPrice[AProjectIndex] + TotalPrice.AsFloat;
  751. end;
  752. if Assigned(ANode.StageRec) then
  753. with ANode.StageRec do
  754. begin
  755. Result.CurGatherQuantity := Result.CurGatherQuantity + GatherQuantity.AsFloat;
  756. Result.CurGatherTotalPrice := Result.CurGatherTotalPrice + GatherTotalPrice.AsFloat;
  757. Result.P_CurGatherQuantity[AProjectIndex] := Result.P_CurGatherQuantity[AProjectIndex] + GatherQuantity.AsFloat;
  758. Result.P_CurGatherTotalPrice[AProjectIndex] := Result.P_CurGatherTotalPrice[AProjectIndex] + GatherTotalPrice.AsFloat;
  759. Result.EndGatherQuantity := Result.EndGatherQuantity + EndGatherQuantity.AsFloat;
  760. Result.EndGatherTotalPrice := Result.EndGatherTotalPrice + EndGatherTotalPrice.AsFloat;
  761. Result.P_EndGatherQuantity[AProjectIndex] := Result.P_EndGatherQuantity[AProjectIndex] + EndGatherQuantity.AsFloat;
  762. Result.P_EndGatherTotalPrice[AProjectIndex] := Result.P_EndGatherTotalPrice[AProjectIndex] + EndGatherTotalPrice.AsFloat;
  763. Result.PreGatherQuantity := Result.PreGatherQuantity + PreGatherQuantity.AsFloat;
  764. Result.PreGatherTotalPrice := Result.PreGatherTotalPrice + PreGatherTotalPrice.AsFloat;
  765. end;
  766. end;
  767. function TGclControl.B_CodeToChapter(const AB_Code: string): Integer;
  768. var
  769. sgs: TStrings;
  770. iFirst, iSecond: Integer;
  771. begin
  772. Result := 0;
  773. sgs := TStringList.Create;
  774. try
  775. sgs.Delimiter := '-';
  776. sgs.DelimitedText := AB_Code;
  777. iFirst := StrToIntDef(sgs.Strings[0], 0);
  778. Result := Trunc(iFirst/100);
  779. if (Result >= 90) and (Result < 100) then
  780. Result := 9;
  781. finally
  782. sgs.Free;
  783. end;
  784. end;
  785. procedure TGclControl.CalculateChapterGather;
  786. var
  787. iIndex, iProject: Integer;
  788. vGclChapter: TGclChapter;
  789. begin
  790. FGclChapterGather.TotalPrice := 0;
  791. FGclChapterGather.CurGatherTotalPrice := 0;
  792. FGclChapterGather.EndGatherTotalPrice := 0;
  793. FGclChapterGather.PreGatherTotalPrice := 0;
  794. for iProject := 0 to FProjectCount - 1 do
  795. begin
  796. FGclChapterGather.P_TotalPrice[iProject] := 0;
  797. FGclChapterGather.P_CurGatherTotalPrice[iProject] := 0;
  798. FGclChapterGather.P_EndGatherTotalPrice[iProject] := 0;
  799. end;
  800. for iIndex := 0 to FGclChapters.Count - 1 do
  801. begin
  802. vGclChapter := TGclChapter(FGclChapters.Items[iIndex]);
  803. with FGclChapterGather do
  804. begin
  805. TotalPrice := TotalPrice + vGclChapter.TotalPrice;
  806. CurGatherTotalPrice := CurGatherTotalPrice + vGclChapter.CurGatherTotalPrice;
  807. EndGatherTotalPrice := EndGatherTotalPrice + vGclChapter.EndGatherTotalPrice;
  808. PreGatherTotalPrice := PreGatherTotalPrice + vGclChapter.PreGatherTotalPrice;
  809. for iProject := 0 to FProjectCount - 1 do
  810. begin
  811. P_TotalPrice[iProject] := P_TotalPrice[iProject] + vGclChapter.P_TotalPrice[iProject];
  812. P_CurGatherTotalPrice[iProject] := P_CurGatherTotalPrice[iProject] + vGclChapter.P_CurGatherTotalPrice[iProject];
  813. P_EndGatherTotalPrice[iProject] := P_EndGatherTotalPrice[iProject] + vGclChapter.P_EndGatherTotalPrice[iProject];
  814. end;
  815. end;
  816. end;
  817. end;
  818. constructor TGclControl.Create(AProjectCount: Integer);
  819. function CreateGclChapter(AChapterID: Integer; const AName: string): TGclChapter;
  820. begin
  821. Result := TGclChapter.Create(AChapterID, AName, FProjectCount);
  822. FGclChapters.Add(Result);
  823. end;
  824. begin
  825. FProjectCount := AProjectCount;
  826. SetLength(FProjectName, AProjectCount);
  827. FGclNodes := TList.Create;
  828. FGclChapters := TList.Create;
  829. CreateGclChapter(1, '总 则');
  830. CreateGclChapter(2, '路 基');
  831. CreateGclChapter(3, '路 面');
  832. CreateGclChapter(4, '桥梁、涵洞工程');
  833. CreateGclChapter(5, '隧 道');
  834. CreateGclChapter(6, '安全设计及预埋管线');
  835. CreateGclChapter(7, '绿化及环境保护工程');
  836. CreateGclChapter(8, '房建工程');
  837. CreateGclChapter(9, '机电工程');
  838. FOtherGcl := TGclChapter.Create(19, '非标准清单', FProjectCount);
  839. FGclChapterGather := TGclChapter.Create(20, '第100章至900章合计', FProjectCount);
  840. end;
  841. destructor TGclControl.Destroy;
  842. begin
  843. FOtherGcl.Free;
  844. FGclChapterGather.Free;
  845. ClearObjects(FGclChapters);
  846. FGclChapters.Free;
  847. ClearObjects(FGclNodes);
  848. FGclNodes.Free;
  849. end;
  850. function TGclControl.FindGclNode(ARec: TBillsRecord): TGclNode;
  851. var
  852. iIndex: Integer;
  853. vGclNode: TGclNode;
  854. bSameCode, bSameName, bSameUnits, bSamePrice: Boolean;
  855. begin
  856. Result := nil;
  857. for iIndex := 0 to FGclNodes.Count - 1 do
  858. begin
  859. vGclNode := TGclNode(FGclNodes.Items[iIndex]);
  860. if (vGclNode.B_Code = ARec.B_Code.AsString) and
  861. (vGclNode.Name = ARec.Name.AsString) and
  862. (vGclNode.Units = ARec.Units.AsString) and
  863. (vGclNode.Price = ARec.Price.AsFloat) then
  864. begin
  865. Result := vGclNode;
  866. Break;
  867. end;
  868. end;
  869. end;
  870. function TGclControl.FindGclChapter(AChapterID: Integer): TGclChapter;
  871. var
  872. iIndex: Integer;
  873. vChapter: TGclChapter;
  874. begin
  875. Result := nil;
  876. for iIndex := 0 to FGclChapters.Count - 1 do
  877. begin
  878. vChapter := TGclChapter(FGclChapters.Items[iIndex]);
  879. if vChapter.ChapterID = AChapterID then
  880. begin
  881. Result := vChapter;
  882. Break;
  883. end;
  884. end;
  885. end;
  886. function TGclControl.GetGclChapter(AIndex: Integer): TGclChapter;
  887. begin
  888. Result := TGclChapter(FGclChapters.Items[AIndex]);
  889. end;
  890. function TGclControl.GetGclChapterCount: Integer;
  891. begin
  892. Result := FGclChapters.Count;
  893. end;
  894. procedure TGclControl.LinkGclChapter(AGclNode: TGclNode);
  895. var
  896. iChapterID: Integer;
  897. vChapter: TGclChapter;
  898. begin
  899. iChapterID := B_CodeToChapter(AGclNode.B_Code);
  900. vChapter := FindGclChapter(iChapterID);
  901. if Assigned(vChapter) then
  902. vChapter.AddGclNode(AGclNode)
  903. else
  904. FOtherGcl.AddGclNode(AGclNode);
  905. end;
  906. function TGclControl.NewGclNode(ARec: TBillsRecord): TGclNode;
  907. begin
  908. Result := TGclNode.Create(FProjectCount);
  909. FGclNodes.Add(Result);
  910. Result.B_Code := ARec.B_Code.AsString;
  911. Result.Name := ARec.Name.AsString;
  912. Result.Units := ARec.Units.AsString;
  913. Result.Price := ARec.Price.AsFloat;
  914. LinkGclChapter(Result);
  915. end;
  916. procedure TGclControl.Calculate;
  917. var
  918. i: Integer;
  919. begin
  920. for i := 0 to GclChapterCount - 1 do
  921. GclChapter[i].CalculateChapter;
  922. CalculateChapterGather;
  923. end;
  924. { TGclChapter }
  925. procedure TGclChapter.AddGclNode(AGclNode: TGclNode);
  926. begin
  927. FGclNodes.Add(AGclNode);
  928. end;
  929. procedure TGclChapter.CalculateChapter;
  930. var
  931. iIndex, iProject: Integer;
  932. vGclNode: TGclNode;
  933. begin
  934. FTotalPrice := 0;
  935. FCurGatherTotalPrice := 0;
  936. FEndGatherTotalPrice := 0;
  937. FPreGatherTotalPrice := 0;
  938. for iProject := 0 to FProjectCount - 1 do
  939. begin
  940. FP_TotalPrice[iProject] := 0;
  941. FP_CurGatherTotalPrice[iProject] := 0;
  942. FP_EndGatherTotalPrice[iProject] := 0;
  943. end;
  944. for iIndex := 0 to FGclNodes.Count - 1 do
  945. begin
  946. vGclNode := TGclNode(FGclNodes.Items[iIndex]);
  947. FTotalPrice := FTotalPrice + vGclNode.TotalPrice;
  948. FCurGatherTotalPrice := FCurGatherTotalPrice + vGclNode.FCurGatherTotalPrice;
  949. FEndGatherTotalPrice := FEndGatherTotalPrice + vGclNode.FEndGatherTotalPrice;
  950. FPreGatherTotalPrice := FPreGatherTotalPrice + vGclNode.FPreGatherTotalPrice;
  951. for iProject := 0 to FProjectCount - 1 do
  952. begin
  953. FP_TotalPrice[iProject] := FP_TotalPrice[iProject] + vGclNode.P_TotalPrice[iProject];
  954. FP_CurGatherTotalPrice[iProject] := FP_CurGatherTotalPrice[iProject] + vGclNode.P_CurGatherTotalPrice[iProject];
  955. FP_EndGatherTotalPrice[iProject] := FP_EndGatherTotalPrice[iProject] + vGclNode.P_EndGatherTotalPrice[iProject];
  956. end;
  957. end;
  958. end;
  959. constructor TGclChapter.Create(AChapterID: Integer; const AName: string;
  960. AProjectCount: Integer);
  961. begin
  962. FGclNodes := TList.Create;
  963. FChapterID := AChapterID;
  964. if FChapterID < 19 then
  965. begin
  966. FChapterBegin := FChapterID * 100;
  967. FChapterEnd := FChapterBegin + 99;
  968. FChapterName := Format('第%d章', [FChapterBegin]);
  969. end;
  970. FName := AName;
  971. FProjectCount := AProjectCount;
  972. SetLength(FP_TotalPrice, FProjectCount);
  973. SetLength(FP_CurGatherTotalPrice, FProjectCount);
  974. SetLength(FP_EndGatherTotalPrice, FProjectCount);
  975. end;
  976. destructor TGclChapter.Destroy;
  977. begin
  978. FGclNodes.Free;
  979. inherited;
  980. end;
  981. function TGclChapter.GetCurPercent: Double;
  982. begin
  983. if TotalPrice <> 0 then
  984. Result := CurGatherTotalPrice/TotalPrice*100
  985. else
  986. Result := 0;
  987. end;
  988. function TGclChapter.GetEndPercent: Double;
  989. begin
  990. if TotalPrice <> 0 then
  991. Result := EndGatherTotalPrice/TotalPrice*100
  992. else
  993. Result := 0;
  994. end;
  995. function TGclChapter.GetGclNode(AIndex: Integer): TGclNode;
  996. begin
  997. Result := TGclNode(FGclNodes.Items[AIndex]);
  998. end;
  999. function TGclChapter.GetGclNodeCount: Integer;
  1000. begin
  1001. Result := FGclNodes.Count;
  1002. end;
  1003. { TDealPayControl }
  1004. function TDealPayControl.AddPayNode(const AName: string;
  1005. AIsMinus: Boolean): TPayNode;
  1006. begin
  1007. Result := FindPayNode(AName, AIsMinus);
  1008. if not Assigned(Result) then
  1009. Result := NewPayNode(AName, AIsMinus);
  1010. end;
  1011. constructor TDealPayControl.Create;
  1012. begin
  1013. FPayNodes := TList.Create;
  1014. FGatherPayNode := TPayNode.Create;
  1015. end;
  1016. destructor TDealPayControl.Destroy;
  1017. begin
  1018. FGatherPayNode.Free;
  1019. ClearObjects(FPayNodes);
  1020. FPayNodes.Free;
  1021. inherited;
  1022. end;
  1023. function TDealPayControl.FindPayNode(const AName: string;
  1024. AIsMinus: Boolean): TPayNode;
  1025. var
  1026. iIndex: Integer;
  1027. vPayNode: TPayNode;
  1028. begin
  1029. Result := nil;
  1030. for iIndex := 0 to FPayNodes.Count -1 do
  1031. begin
  1032. vPayNode := TPayNode(FPayNodes.Items[iIndex]);
  1033. if (vPayNode.Name = AName) and (vPayNode.IsMinus = AIsMinus) then
  1034. begin
  1035. Result := vPayNode;
  1036. Break;
  1037. end;
  1038. end;
  1039. end;
  1040. function TDealPayControl.GetPayCount: Integer;
  1041. begin
  1042. Result := FPayNodes.Count;
  1043. end;
  1044. function TDealPayControl.GetPayNode(AIndex: Integer): TPayNode;
  1045. begin
  1046. Result := TPayNode(FPayNodes.Items[AIndex]);
  1047. end;
  1048. function TDealPayControl.NewPayNode(const AName: string;
  1049. AIsMinus: Boolean): TPayNode;
  1050. begin
  1051. Result := TPayNode.Create;
  1052. FPayNodes.Add(Result);
  1053. Result.Name := AName;
  1054. Result.IsMinus := AIsMinus;
  1055. end;
  1056. end.