rmHaBaiCustomizedDm.pas 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208
  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. finally
  780. sgs.Free;
  781. end;
  782. end;
  783. procedure TGclControl.CalculateChapterGather;
  784. var
  785. iIndex, iProject: Integer;
  786. vGclChapter: TGclChapter;
  787. begin
  788. FGclChapterGather.TotalPrice := 0;
  789. FGclChapterGather.CurGatherTotalPrice := 0;
  790. FGclChapterGather.EndGatherTotalPrice := 0;
  791. FGclChapterGather.PreGatherTotalPrice := 0;
  792. for iProject := 0 to FProjectCount - 1 do
  793. begin
  794. FGclChapterGather.P_TotalPrice[iProject] := 0;
  795. FGclChapterGather.P_CurGatherTotalPrice[iProject] := 0;
  796. FGclChapterGather.P_EndGatherTotalPrice[iProject] := 0;
  797. end;
  798. for iIndex := 0 to FGclChapters.Count - 1 do
  799. begin
  800. vGclChapter := TGclChapter(FGclChapters.Items[iIndex]);
  801. with FGclChapterGather do
  802. begin
  803. TotalPrice := TotalPrice + vGclChapter.TotalPrice;
  804. CurGatherTotalPrice := CurGatherTotalPrice + vGclChapter.CurGatherTotalPrice;
  805. EndGatherTotalPrice := EndGatherTotalPrice + vGclChapter.EndGatherTotalPrice;
  806. PreGatherTotalPrice := PreGatherTotalPrice + vGclChapter.PreGatherTotalPrice;
  807. for iProject := 0 to FProjectCount - 1 do
  808. begin
  809. P_TotalPrice[iProject] := P_TotalPrice[iProject] + vGclChapter.P_TotalPrice[iProject];
  810. P_CurGatherTotalPrice[iProject] := P_CurGatherTotalPrice[iProject] + vGclChapter.P_CurGatherTotalPrice[iProject];
  811. P_EndGatherTotalPrice[iProject] := P_EndGatherTotalPrice[iProject] + vGclChapter.P_EndGatherTotalPrice[iProject];
  812. end;
  813. end;
  814. end;
  815. end;
  816. constructor TGclControl.Create(AProjectCount: Integer);
  817. function CreateGclChapter(AChapterID: Integer; const AName: string): TGclChapter;
  818. begin
  819. Result := TGclChapter.Create(AChapterID, AName, FProjectCount);
  820. FGclChapters.Add(Result);
  821. end;
  822. begin
  823. FProjectCount := AProjectCount;
  824. SetLength(FProjectName, AProjectCount);
  825. FGclNodes := TList.Create;
  826. FGclChapters := TList.Create;
  827. CreateGclChapter(1, '总 则');
  828. CreateGclChapter(2, '路 基');
  829. CreateGclChapter(3, '路 面');
  830. CreateGclChapter(4, '桥梁、涵洞工程');
  831. CreateGclChapter(5, '隧 道');
  832. CreateGclChapter(6, '安全设计及预埋管线');
  833. CreateGclChapter(7, '绿化及环境保护工程');
  834. CreateGclChapter(8, '房建工程');
  835. CreateGclChapter(9, '机电工程');
  836. FOtherGcl := TGclChapter.Create(19, '非标准清单', FProjectCount);
  837. FGclChapterGather := TGclChapter.Create(20, '第100章至900章合计', FProjectCount);
  838. end;
  839. destructor TGclControl.Destroy;
  840. begin
  841. FOtherGcl.Free;
  842. FGclChapterGather.Free;
  843. ClearObjects(FGclChapters);
  844. FGclChapters.Free;
  845. ClearObjects(FGclNodes);
  846. FGclNodes.Free;
  847. end;
  848. function TGclControl.FindGclNode(ARec: TBillsRecord): TGclNode;
  849. var
  850. iIndex: Integer;
  851. vGclNode: TGclNode;
  852. bSameCode, bSameName, bSameUnits, bSamePrice: Boolean;
  853. begin
  854. Result := nil;
  855. for iIndex := 0 to FGclNodes.Count - 1 do
  856. begin
  857. vGclNode := TGclNode(FGclNodes.Items[iIndex]);
  858. if (vGclNode.B_Code = ARec.B_Code.AsString) and
  859. (vGclNode.Name = ARec.Name.AsString) and
  860. (vGclNode.Units = ARec.Units.AsString) and
  861. (vGclNode.Price = ARec.Price.AsFloat) then
  862. begin
  863. Result := vGclNode;
  864. Break;
  865. end;
  866. end;
  867. end;
  868. function TGclControl.FindGclChapter(AChapterID: Integer): TGclChapter;
  869. var
  870. iIndex: Integer;
  871. vChapter: TGclChapter;
  872. begin
  873. Result := nil;
  874. for iIndex := 0 to FGclChapters.Count - 1 do
  875. begin
  876. vChapter := TGclChapter(FGclChapters.Items[iIndex]);
  877. if vChapter.ChapterID = AChapterID then
  878. begin
  879. Result := vChapter;
  880. Break;
  881. end;
  882. end;
  883. end;
  884. function TGclControl.GetGclChapter(AIndex: Integer): TGclChapter;
  885. begin
  886. Result := TGclChapter(FGclChapters.Items[AIndex]);
  887. end;
  888. function TGclControl.GetGclChapterCount: Integer;
  889. begin
  890. Result := FGclChapters.Count;
  891. end;
  892. procedure TGclControl.LinkGclChapter(AGclNode: TGclNode);
  893. var
  894. iChapterID: Integer;
  895. vChapter: TGclChapter;
  896. begin
  897. iChapterID := B_CodeToChapter(AGclNode.B_Code);
  898. vChapter := FindGclChapter(iChapterID);
  899. if Assigned(vChapter) then
  900. vChapter.AddGclNode(AGclNode)
  901. else
  902. FOtherGcl.AddGclNode(AGclNode);
  903. end;
  904. function TGclControl.NewGclNode(ARec: TBillsRecord): TGclNode;
  905. begin
  906. Result := TGclNode.Create(FProjectCount);
  907. FGclNodes.Add(Result);
  908. Result.B_Code := ARec.B_Code.AsString;
  909. Result.Name := ARec.Name.AsString;
  910. Result.Units := ARec.Units.AsString;
  911. Result.Price := ARec.Price.AsFloat;
  912. LinkGclChapter(Result);
  913. end;
  914. procedure TGclControl.Calculate;
  915. var
  916. i: Integer;
  917. begin
  918. for i := 0 to GclChapterCount - 1 do
  919. GclChapter[i].CalculateChapter;
  920. CalculateChapterGather;
  921. end;
  922. { TGclChapter }
  923. procedure TGclChapter.AddGclNode(AGclNode: TGclNode);
  924. begin
  925. FGclNodes.Add(AGclNode);
  926. end;
  927. procedure TGclChapter.CalculateChapter;
  928. var
  929. iIndex, iProject: Integer;
  930. vGclNode: TGclNode;
  931. begin
  932. FTotalPrice := 0;
  933. FCurGatherTotalPrice := 0;
  934. FEndGatherTotalPrice := 0;
  935. FPreGatherTotalPrice := 0;
  936. for iProject := 0 to FProjectCount - 1 do
  937. begin
  938. FP_TotalPrice[iProject] := 0;
  939. FP_CurGatherTotalPrice[iProject] := 0;
  940. FP_EndGatherTotalPrice[iProject] := 0;
  941. end;
  942. for iIndex := 0 to FGclNodes.Count - 1 do
  943. begin
  944. vGclNode := TGclNode(FGclNodes.Items[iIndex]);
  945. FTotalPrice := FTotalPrice + vGclNode.TotalPrice;
  946. FCurGatherTotalPrice := FCurGatherTotalPrice + vGclNode.FCurGatherTotalPrice;
  947. FEndGatherTotalPrice := FEndGatherTotalPrice + vGclNode.FEndGatherTotalPrice;
  948. FPreGatherTotalPrice := FPreGatherTotalPrice + vGclNode.FPreGatherTotalPrice;
  949. for iProject := 0 to FProjectCount - 1 do
  950. begin
  951. FP_TotalPrice[iProject] := FP_TotalPrice[iProject] + vGclNode.P_TotalPrice[iProject];
  952. FP_CurGatherTotalPrice[iProject] := FP_CurGatherTotalPrice[iProject] + vGclNode.P_CurGatherTotalPrice[iProject];
  953. FP_EndGatherTotalPrice[iProject] := FP_EndGatherTotalPrice[iProject] + vGclNode.P_EndGatherTotalPrice[iProject];
  954. end;
  955. end;
  956. end;
  957. constructor TGclChapter.Create(AChapterID: Integer; const AName: string;
  958. AProjectCount: Integer);
  959. begin
  960. FGclNodes := TList.Create;
  961. FChapterID := AChapterID;
  962. if FChapterID < 19 then
  963. begin
  964. FChapterBegin := FChapterID * 100;
  965. FChapterEnd := FChapterBegin + 99;
  966. FChapterName := Format('第%d章', [FChapterBegin]);
  967. end;
  968. FName := AName;
  969. FProjectCount := AProjectCount;
  970. SetLength(FP_TotalPrice, FProjectCount);
  971. SetLength(FP_CurGatherTotalPrice, FProjectCount);
  972. SetLength(FP_EndGatherTotalPrice, FProjectCount);
  973. end;
  974. destructor TGclChapter.Destroy;
  975. begin
  976. FGclNodes.Free;
  977. inherited;
  978. end;
  979. function TGclChapter.GetCurPercent: Double;
  980. begin
  981. if TotalPrice <> 0 then
  982. Result := CurGatherTotalPrice/TotalPrice*100
  983. else
  984. Result := 0;
  985. end;
  986. function TGclChapter.GetEndPercent: Double;
  987. begin
  988. if TotalPrice <> 0 then
  989. Result := EndGatherTotalPrice/TotalPrice*100
  990. else
  991. Result := 0;
  992. end;
  993. function TGclChapter.GetGclNode(AIndex: Integer): TGclNode;
  994. begin
  995. Result := TGclNode(FGclNodes.Items[AIndex]);
  996. end;
  997. function TGclChapter.GetGclNodeCount: Integer;
  998. begin
  999. Result := FGclNodes.Count;
  1000. end;
  1001. { TDealPayControl }
  1002. function TDealPayControl.AddPayNode(const AName: string;
  1003. AIsMinus: Boolean): TPayNode;
  1004. begin
  1005. Result := FindPayNode(AName, AIsMinus);
  1006. if not Assigned(Result) then
  1007. Result := NewPayNode(AName, AIsMinus);
  1008. end;
  1009. constructor TDealPayControl.Create;
  1010. begin
  1011. FPayNodes := TList.Create;
  1012. FGatherPayNode := TPayNode.Create;
  1013. end;
  1014. destructor TDealPayControl.Destroy;
  1015. begin
  1016. FGatherPayNode.Free;
  1017. ClearObjects(FPayNodes);
  1018. FPayNodes.Free;
  1019. inherited;
  1020. end;
  1021. function TDealPayControl.FindPayNode(const AName: string;
  1022. AIsMinus: Boolean): TPayNode;
  1023. var
  1024. iIndex: Integer;
  1025. vPayNode: TPayNode;
  1026. begin
  1027. Result := nil;
  1028. for iIndex := 0 to FPayNodes.Count -1 do
  1029. begin
  1030. vPayNode := TPayNode(FPayNodes.Items[iIndex]);
  1031. if (vPayNode.Name = AName) and (vPayNode.IsMinus = AIsMinus) then
  1032. begin
  1033. Result := vPayNode;
  1034. Break;
  1035. end;
  1036. end;
  1037. end;
  1038. function TDealPayControl.GetPayCount: Integer;
  1039. begin
  1040. Result := FPayNodes.Count;
  1041. end;
  1042. function TDealPayControl.GetPayNode(AIndex: Integer): TPayNode;
  1043. begin
  1044. Result := TPayNode(FPayNodes.Items[AIndex]);
  1045. end;
  1046. function TDealPayControl.NewPayNode(const AName: string;
  1047. AIsMinus: Boolean): TPayNode;
  1048. begin
  1049. Result := TPayNode.Create;
  1050. FPayNodes.Add(Result);
  1051. Result.Name := AName;
  1052. Result.IsMinus := AIsMinus;
  1053. end;
  1054. end.