rmHaBaiCustomizedDm.pas 40 KB

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