rmHaBaiCustomizedDm.pas 40 KB

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