rmHaBaiCustomizedDm.pas 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190
  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, iSerialNo: 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. cdsCustomProjSerialNo.AsInteger := iSerialNo;
  622. cdsCustomProj.Post;
  623. Inc(iSerialNo);
  624. end;
  625. procedure WriteGclChapterData(AGclChapter: TGclChapter);
  626. var
  627. iGcl: Integer;
  628. begin
  629. if AGclChapter.GclNodeCount = 0 then Exit;
  630. for iGcl := 0 to AGclChapter.GclNodeCount - 1 do
  631. WriteGclNodeData(AGclChapter.GclNode[iGcl], AGclChapter.ChapterID);
  632. end;
  633. procedure WriteChapterGather(AGclChapter: TGclChapter; const AName: string = '');
  634. begin
  635. cdsCustomProj.Append;
  636. cdsCustomProjProjectID.AsInteger := iProject;
  637. cdsCustomProjProjectName.AsString := sProjectName;
  638. cdsCustomProjChapterID.AsInteger := AGclChapter.ChapterID;
  639. cdsCustomProjInnerPartID.AsInteger := 3;
  640. if AName = '' then
  641. cdsCustomProjName.AsString := AGclChapter.Name
  642. else
  643. cdsCustomProjName.AsString := AName;
  644. cdsCustomProjTotalPrice.AsFloat := AGclChapter.TotalPrice;
  645. cdsCustomProjCurGatherTotalPrice.AsFloat := AGclChapter.CurGatherTotalPrice;
  646. cdsCustomProjEndGatherTotalPrice.AsFloat := AGclChapter.EndGatherTotalPrice;
  647. cdsCustomProjP_CurGatherTotalPrice.AsFloat := AGclChapter.P_CurGatherTotalPrice[iProject];
  648. cdsCustomProjP_EndGatherTotalPrice.AsFloat := AGclChapter.P_EndGatherTotalPrice[iProject];
  649. cdsCustomProjCurPercent.AsFloat := AGclChapter.CurPercent;
  650. cdsCustomProjEndPercent.AsFloat := AGclChapter.EndPercent;
  651. cdsCustomProjSerialNo.AsInteger := iSerialNo;
  652. cdsCustomProj.Post;
  653. Inc(iSerialNo);
  654. end;
  655. begin
  656. for iProject := 0 to FGclControl.ProjectCount - 1 do
  657. begin
  658. iSerialNo := 1;
  659. sProjectName := FGclControl.ProjectName[iProject];
  660. for iChapter := 0 to FGclControl.GclChapterCount - 1 do
  661. WriteGclChapterData(FGclControl.GclChapter[iChapter]);
  662. WriteChapterGather(FGclControl.GclChapterGather, '第100章至第900章 合计');
  663. end;
  664. end;
  665. procedure TrmHaBaiCustomizedData.WriteFlowData;
  666. procedure AddNodeData(ANode: TBillsIDTreeNode);
  667. begin
  668. cdsCustom14.Append;
  669. cdsCustom14IndexCode.AsString := ANode.Rec.IndexCode.AsString;
  670. cdsCustom14B_Code.AsString := ANode.Rec.B_Code.AsString;
  671. cdsCustom14Name.AsString := ANode.Rec.Name.AsString;
  672. cdsCustom14Units.AsString := ANode.Rec.Units.AsString;
  673. cdsCustom14Price.AsFloat := ANode.Rec.Price.AsFloat;
  674. cdsCustom14Quantity.AsFloat := ANode.StageRec.GatherQuantity.AsFloat;
  675. cdsCustom14TotalPrice.AsFloat := ANode.StageRec.GatherTotalPrice.AsFloat;
  676. with FProjectData.PhaseData.ZJJLData do
  677. if cdsZJJL.Locate('BillsID', ANode.ID, []) then
  678. cdsCustom14CertificateCode.AsString := cdsZJJLCertificateCode.AsString;
  679. cdsCustom14.Post;
  680. end;
  681. var
  682. iIndex: Integer;
  683. vNode: TBillsIDTreeNode;
  684. begin
  685. for iIndex := 0 to FProjectData.BillsMeasureData.BillsMeasureTree.Count - 1 do
  686. begin
  687. vNode := TBillsIDTreeNode(FProjectData.BillsMeasureData.BillsMeasureTree.Items[iIndex]);
  688. if (not vNode.HasChildren) and (vNode.Rec.B_Code.AsString <> '') and
  689. Assigned(vNode.StageRec) and (vNode.StageRec.GatherTotalPrice.AsFloat <> 0) then
  690. AddNodeData(vNode);
  691. end;
  692. end;
  693. { TGclNode }
  694. constructor TGclNode.Create(AProjectCount: Integer);
  695. begin
  696. SetLength(FP_Quantity, AProjectCount);
  697. SetLength(FP_TotalPrice, AProjectCount);
  698. SetLength(FP_CurGatherQuantity, AProjectCount);
  699. SetLength(FP_CurGatherTotalPrice, AProjectCount);
  700. SetLength(FP_EndGatherQuantity, AProjectCount);
  701. SetLength(FP_EndGatherTotalPrice, AProjectCount);
  702. end;
  703. function TGclNode.GetCurPercent: Double;
  704. begin
  705. if TotalPrice <> 0 then
  706. Result := CurGatherTotalPrice/TotalPrice*100
  707. else
  708. Result := 0;
  709. end;
  710. function TGclNode.GetEndPercent: Double;
  711. begin
  712. if TotalPrice <> 0 then
  713. Result := EndGatherTotalPrice/TotalPrice*100
  714. else
  715. Result := 0;
  716. end;
  717. procedure TGclNode.SetB_Code(const Value: string);
  718. begin
  719. FB_Code := Value;
  720. FIndexCode := B_CodeToIndexCode(FB_Code);
  721. end;
  722. { TGclControl }
  723. function TGclControl.AddGclNode(ANode: TBillsIDTreeNode; AProjectIndex: Integer): TGclNode;
  724. begin
  725. Result := FindGclNode(ANode.Rec);
  726. if not Assigned(Result) then
  727. Result := NewGclNode(ANode.Rec);
  728. with ANode.Rec do
  729. begin
  730. Result.Quantity := Result.Quantity + Quantity.AsFloat;
  731. Result.TotalPrice := Result.TotalPrice + TotalPrice.AsFloat;
  732. Result.P_Quantity[AProjectIndex] := Result.P_Quantity[AProjectIndex] + Quantity.AsFloat;
  733. Result.P_TotalPrice[AProjectIndex] := Result.P_TotalPrice[AProjectIndex] + TotalPrice.AsFloat;
  734. end;
  735. if Assigned(ANode.StageRec) then
  736. with ANode.StageRec do
  737. begin
  738. Result.CurGatherQuantity := Result.CurGatherQuantity + GatherQuantity.AsFloat;
  739. Result.CurGatherTotalPrice := Result.CurGatherTotalPrice + GatherTotalPrice.AsFloat;
  740. Result.P_CurGatherQuantity[AProjectIndex] := Result.P_CurGatherQuantity[AProjectIndex] + GatherQuantity.AsFloat;
  741. Result.P_CurGatherTotalPrice[AProjectIndex] := Result.P_CurGatherTotalPrice[AProjectIndex] + GatherTotalPrice.AsFloat;
  742. Result.EndGatherQuantity := Result.EndGatherQuantity + EndGatherQuantity.AsFloat;
  743. Result.EndGatherTotalPrice := Result.EndGatherTotalPrice + EndGatherTotalPrice.AsFloat;
  744. Result.P_EndGatherQuantity[AProjectIndex] := Result.P_EndGatherQuantity[AProjectIndex] + EndGatherQuantity.AsFloat;
  745. Result.P_EndGatherTotalPrice[AProjectIndex] := Result.P_EndGatherTotalPrice[AProjectIndex] + EndGatherTotalPrice.AsFloat;
  746. Result.PreGatherQuantity := Result.PreGatherQuantity + PreGatherQuantity.AsFloat;
  747. Result.PreGatherTotalPrice := Result.PreGatherTotalPrice + PreGatherTotalPrice.AsFloat;
  748. end;
  749. end;
  750. function TGclControl.B_CodeToChapter(const AB_Code: string): Integer;
  751. var
  752. sgs: TStrings;
  753. iFirst, iSecond: Integer;
  754. begin
  755. Result := 0;
  756. sgs := TStringList.Create;
  757. try
  758. sgs.Delimiter := '-';
  759. sgs.DelimitedText := AB_Code;
  760. iFirst := StrToIntDef(sgs.Strings[0], 0);
  761. Result := Trunc(iFirst/100);
  762. finally
  763. sgs.Free;
  764. end;
  765. end;
  766. procedure TGclControl.CalculateChapterGather;
  767. var
  768. iIndex, iProject: Integer;
  769. vGclChapter: TGclChapter;
  770. begin
  771. FGclChapterGather.TotalPrice := 0;
  772. FGclChapterGather.CurGatherTotalPrice := 0;
  773. FGclChapterGather.EndGatherTotalPrice := 0;
  774. FGclChapterGather.PreGatherTotalPrice := 0;
  775. for iProject := 0 to FProjectCount - 1 do
  776. begin
  777. FGclChapterGather.P_TotalPrice[iProject] := 0;
  778. FGclChapterGather.P_CurGatherTotalPrice[iProject] := 0;
  779. FGclChapterGather.P_EndGatherTotalPrice[iProject] := 0;
  780. end;
  781. for iIndex := 0 to FGclChapters.Count - 1 do
  782. begin
  783. vGclChapter := TGclChapter(FGclChapters.Items[iIndex]);
  784. with FGclChapterGather do
  785. begin
  786. TotalPrice := TotalPrice + vGclChapter.TotalPrice;
  787. CurGatherTotalPrice := CurGatherTotalPrice + vGclChapter.CurGatherTotalPrice;
  788. EndGatherTotalPrice := EndGatherTotalPrice + vGclChapter.EndGatherTotalPrice;
  789. PreGatherTotalPrice := PreGatherTotalPrice + vGclChapter.PreGatherTotalPrice;
  790. for iProject := 0 to FProjectCount - 1 do
  791. begin
  792. P_TotalPrice[iProject] := P_TotalPrice[iProject] + vGclChapter.P_TotalPrice[iProject];
  793. P_CurGatherTotalPrice[iProject] := P_CurGatherTotalPrice[iProject] + vGclChapter.P_CurGatherTotalPrice[iProject];
  794. P_EndGatherTotalPrice[iProject] := P_EndGatherTotalPrice[iProject] + vGclChapter.P_EndGatherTotalPrice[iProject];
  795. end;
  796. end;
  797. end;
  798. end;
  799. constructor TGclControl.Create(AProjectCount: Integer);
  800. function CreateGclChapter(AChapterID: Integer; const AName: string): TGclChapter;
  801. begin
  802. Result := TGclChapter.Create(AChapterID, AName, FProjectCount);
  803. FGclChapters.Add(Result);
  804. end;
  805. begin
  806. FProjectCount := AProjectCount;
  807. SetLength(FProjectName, AProjectCount);
  808. FGclNodes := TList.Create;
  809. FGclChapters := TList.Create;
  810. CreateGclChapter(1, '总 则');
  811. CreateGclChapter(2, '路 基');
  812. CreateGclChapter(3, '路 面');
  813. CreateGclChapter(4, '桥梁、涵洞工程');
  814. CreateGclChapter(5, '隧 道');
  815. CreateGclChapter(6, '安全设计及预埋管线');
  816. CreateGclChapter(7, '绿化及环境保护工程');
  817. CreateGclChapter(8, '房建工程');
  818. CreateGclChapter(9, '机电工程');
  819. FOtherGcl := TGclChapter.Create(19, '非标准清单', FProjectCount);
  820. FGclChapterGather := TGclChapter.Create(20, '第100章至900章合计', FProjectCount);
  821. end;
  822. destructor TGclControl.Destroy;
  823. begin
  824. FOtherGcl.Free;
  825. FGclChapterGather.Free;
  826. ClearObjects(FGclChapters);
  827. FGclChapters.Free;
  828. ClearObjects(FGclNodes);
  829. FGclNodes.Free;
  830. end;
  831. function TGclControl.FindGclNode(ARec: TBillsRecord): TGclNode;
  832. var
  833. iIndex: Integer;
  834. vGclNode: TGclNode;
  835. bSameCode, bSameName, bSameUnits, bSamePrice: Boolean;
  836. begin
  837. Result := nil;
  838. for iIndex := 0 to FGclNodes.Count - 1 do
  839. begin
  840. vGclNode := TGclNode(FGclNodes.Items[iIndex]);
  841. if (vGclNode.B_Code = ARec.B_Code.AsString) and
  842. (vGclNode.Name = ARec.Name.AsString) and
  843. (vGclNode.Units = ARec.Units.AsString) and
  844. (vGclNode.Price = ARec.Price.AsFloat) then
  845. begin
  846. Result := vGclNode;
  847. Break;
  848. end;
  849. end;
  850. end;
  851. function TGclControl.FindGclChapter(AChapterID: Integer): TGclChapter;
  852. var
  853. iIndex: Integer;
  854. vChapter: TGclChapter;
  855. begin
  856. Result := nil;
  857. for iIndex := 0 to FGclChapters.Count - 1 do
  858. begin
  859. vChapter := TGclChapter(FGclChapters.Items[iIndex]);
  860. if vChapter.ChapterID = AChapterID then
  861. begin
  862. Result := vChapter;
  863. Break;
  864. end;
  865. end;
  866. end;
  867. function TGclControl.GetGclChapter(AIndex: Integer): TGclChapter;
  868. begin
  869. Result := TGclChapter(FGclChapters.Items[AIndex]);
  870. end;
  871. function TGclControl.GetGclChapterCount: Integer;
  872. begin
  873. Result := FGclChapters.Count;
  874. end;
  875. procedure TGclControl.LinkGclChapter(AGclNode: TGclNode);
  876. var
  877. iChapterID: Integer;
  878. vChapter: TGclChapter;
  879. begin
  880. iChapterID := B_CodeToChapter(AGclNode.B_Code);
  881. vChapter := FindGclChapter(iChapterID);
  882. if Assigned(vChapter) then
  883. vChapter.AddGclNode(AGclNode)
  884. else
  885. FOtherGcl.AddGclNode(AGclNode);
  886. end;
  887. function TGclControl.NewGclNode(ARec: TBillsRecord): TGclNode;
  888. begin
  889. Result := TGclNode.Create(FProjectCount);
  890. FGclNodes.Add(Result);
  891. Result.B_Code := ARec.B_Code.AsString;
  892. Result.Name := ARec.Name.AsString;
  893. Result.Units := ARec.Units.AsString;
  894. Result.Price := ARec.Price.AsFloat;
  895. LinkGclChapter(Result);
  896. end;
  897. procedure TGclControl.Calculate;
  898. var
  899. i: Integer;
  900. begin
  901. for i := 0 to GclChapterCount - 1 do
  902. GclChapter[i].CalculateChapter;
  903. CalculateChapterGather;
  904. end;
  905. { TGclChapter }
  906. procedure TGclChapter.AddGclNode(AGclNode: TGclNode);
  907. begin
  908. FGclNodes.Add(AGclNode);
  909. end;
  910. procedure TGclChapter.CalculateChapter;
  911. var
  912. iIndex, iProject: Integer;
  913. vGclNode: TGclNode;
  914. begin
  915. FTotalPrice := 0;
  916. FCurGatherTotalPrice := 0;
  917. FEndGatherTotalPrice := 0;
  918. FPreGatherTotalPrice := 0;
  919. for iProject := 0 to FProjectCount - 1 do
  920. begin
  921. FP_TotalPrice[iProject] := 0;
  922. FP_CurGatherTotalPrice[iProject] := 0;
  923. FP_EndGatherTotalPrice[iProject] := 0;
  924. end;
  925. for iIndex := 0 to FGclNodes.Count - 1 do
  926. begin
  927. vGclNode := TGclNode(FGclNodes.Items[iIndex]);
  928. FTotalPrice := FTotalPrice + vGclNode.TotalPrice;
  929. FCurGatherTotalPrice := FCurGatherTotalPrice + vGclNode.FCurGatherTotalPrice;
  930. FEndGatherTotalPrice := FEndGatherTotalPrice + vGclNode.FEndGatherTotalPrice;
  931. FPreGatherTotalPrice := FPreGatherTotalPrice + vGclNode.FPreGatherTotalPrice;
  932. for iProject := 0 to FProjectCount - 1 do
  933. begin
  934. FP_TotalPrice[iProject] := FP_TotalPrice[iProject] + vGclNode.P_TotalPrice[iProject];
  935. FP_CurGatherTotalPrice[iProject] := FP_CurGatherTotalPrice[iProject] + vGclNode.P_CurGatherTotalPrice[iProject];
  936. FP_EndGatherTotalPrice[iProject] := FP_EndGatherTotalPrice[iProject] + vGclNode.P_EndGatherTotalPrice[iProject];
  937. end;
  938. end;
  939. end;
  940. constructor TGclChapter.Create(AChapterID: Integer; const AName: string;
  941. AProjectCount: Integer);
  942. begin
  943. FGclNodes := TList.Create;
  944. FChapterID := AChapterID;
  945. if FChapterID < 19 then
  946. begin
  947. FChapterBegin := FChapterID * 100;
  948. FChapterEnd := FChapterBegin + 99;
  949. FChapterName := Format('第%d章', [FChapterBegin]);
  950. end;
  951. FName := AName;
  952. FProjectCount := AProjectCount;
  953. SetLength(FP_TotalPrice, FProjectCount);
  954. SetLength(FP_CurGatherTotalPrice, FProjectCount);
  955. SetLength(FP_EndGatherTotalPrice, FProjectCount);
  956. end;
  957. destructor TGclChapter.Destroy;
  958. begin
  959. FGclNodes.Free;
  960. inherited;
  961. end;
  962. function TGclChapter.GetCurPercent: Double;
  963. begin
  964. if TotalPrice <> 0 then
  965. Result := CurGatherTotalPrice/TotalPrice*100
  966. else
  967. Result := 0;
  968. end;
  969. function TGclChapter.GetEndPercent: Double;
  970. begin
  971. if TotalPrice <> 0 then
  972. Result := EndGatherTotalPrice/TotalPrice*100
  973. else
  974. Result := 0;
  975. end;
  976. function TGclChapter.GetGclNode(AIndex: Integer): TGclNode;
  977. begin
  978. Result := TGclNode(FGclNodes.Items[AIndex]);
  979. end;
  980. function TGclChapter.GetGclNodeCount: Integer;
  981. begin
  982. Result := FGclNodes.Count;
  983. end;
  984. { TDealPayControl }
  985. function TDealPayControl.AddPayNode(const AName: string;
  986. AIsMinus: Boolean): TPayNode;
  987. begin
  988. Result := FindPayNode(AName, AIsMinus);
  989. if not Assigned(Result) then
  990. Result := NewPayNode(AName, AIsMinus);
  991. end;
  992. constructor TDealPayControl.Create;
  993. begin
  994. FPayNodes := TList.Create;
  995. FGatherPayNode := TPayNode.Create;
  996. end;
  997. destructor TDealPayControl.Destroy;
  998. begin
  999. FGatherPayNode.Free;
  1000. ClearObjects(FPayNodes);
  1001. FPayNodes.Free;
  1002. inherited;
  1003. end;
  1004. function TDealPayControl.FindPayNode(const AName: string;
  1005. AIsMinus: Boolean): TPayNode;
  1006. var
  1007. iIndex: Integer;
  1008. vPayNode: TPayNode;
  1009. begin
  1010. Result := nil;
  1011. for iIndex := 0 to FPayNodes.Count -1 do
  1012. begin
  1013. vPayNode := TPayNode(FPayNodes.Items[iIndex]);
  1014. if (vPayNode.Name = AName) and (vPayNode.IsMinus = AIsMinus) then
  1015. begin
  1016. Result := vPayNode;
  1017. Break;
  1018. end;
  1019. end;
  1020. end;
  1021. function TDealPayControl.GetPayCount: Integer;
  1022. begin
  1023. Result := FPayNodes.Count;
  1024. end;
  1025. function TDealPayControl.GetPayNode(AIndex: Integer): TPayNode;
  1026. begin
  1027. Result := TPayNode(FPayNodes.Items[AIndex]);
  1028. end;
  1029. function TDealPayControl.NewPayNode(const AName: string;
  1030. AIsMinus: Boolean): TPayNode;
  1031. begin
  1032. Result := TPayNode.Create;
  1033. FPayNodes.Add(Result);
  1034. Result.Name := AName;
  1035. Result.IsMinus := AIsMinus;
  1036. end;
  1037. end.