rmFxBillsAddDm.pas 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. unit rmFxBillsAddDm;
  2. interface
  3. uses
  4. SysUtils, Classes, ProjectData, PhaseData, StageDm, DB, DBClient,
  5. MCacheTree, sdIDTree, sdDB;
  6. type
  7. TrmFxBillsAddData = class(TDataModule)
  8. cdsBills: TClientDataSet;
  9. cdsBillsB_Code: TStringField;
  10. cdsBillsCode: TStringField;
  11. cdsBillsName: TWideStringField;
  12. cdsBillsUnits: TWideStringField;
  13. cdsBillsPrice: TFloatField;
  14. cdsBillsQuantity: TFloatField;
  15. cdsBillsTotalPrice: TFloatField;
  16. cdsBillsQuantity1: TFloatField;
  17. cdsBillsTotalPrice1: TFloatField;
  18. cdsBillsQuantity2: TFloatField;
  19. cdsBillsTotalPrice2: TFloatField;
  20. cdsBillsQuantity3: TFloatField;
  21. cdsBillsTotalPrice3: TFloatField;
  22. cdsBillsQuantity4: TFloatField;
  23. cdsBillsTotalPrice4: TFloatField;
  24. cdsBillsQuantity5: TFloatField;
  25. cdsBillsTotalPrice5: TFloatField;
  26. cdsBillsQuantity6: TFloatField;
  27. cdsBillsTotalPrice6: TFloatField;
  28. cdsBillsQuantity7: TFloatField;
  29. cdsBillsTotalPrice7: TFloatField;
  30. cdsBillsQuantity8: TFloatField;
  31. cdsBillsTotalPrice8: TFloatField;
  32. cdsBillsQuantity9: TFloatField;
  33. cdsBillsTotalPrice9: TFloatField;
  34. cdsBillsQuantity10: TFloatField;
  35. cdsBillsTotalPrice10: TFloatField;
  36. cdsBillsQuantity11: TFloatField;
  37. cdsBillsTotalPrice11: TFloatField;
  38. cdsBillsQuantity12: TFloatField;
  39. cdsBillsTotalPrice12: TFloatField;
  40. cdsBillsQuantity13: TFloatField;
  41. cdsBillsTotalPrice13: TFloatField;
  42. cdsBillsQuantity14: TFloatField;
  43. cdsBillsTotalPrice14: TFloatField;
  44. cdsBillsQuantity15: TFloatField;
  45. cdsBillsTotalPrice15: TFloatField;
  46. cdsBillsQuantity16: TFloatField;
  47. cdsBillsTotalPrice16: TFloatField;
  48. cdsBillsQuantity17: TFloatField;
  49. cdsBillsTotalPrice17: TFloatField;
  50. cdsBillsQuantity18: TFloatField;
  51. cdsBillsTotalPrice18: TFloatField;
  52. cdsBillsQuantity19: TFloatField;
  53. cdsBillsTotalPrice19: TFloatField;
  54. cdsBillsQuantity20: TFloatField;
  55. cdsBillsTotalPrice20: TFloatField;
  56. cdsBillsQuantity21: TFloatField;
  57. cdsBillsTotalPrice21: TFloatField;
  58. cdsBillsQuantity22: TFloatField;
  59. cdsBillsTotalPrice22: TFloatField;
  60. cdsBillsQuantity23: TFloatField;
  61. cdsBillsTotalPrice23: TFloatField;
  62. cdsBillsQuantity24: TFloatField;
  63. cdsBillsTotalPrice24: TFloatField;
  64. cdsBillsQuantity25: TFloatField;
  65. cdsBillsTotalPrice25: TFloatField;
  66. cdsBillsQuantity26: TFloatField;
  67. cdsBillsTotalPrice26: TFloatField;
  68. cdsBillsQuantity27: TFloatField;
  69. cdsBillsTotalPrice27: TFloatField;
  70. cdsBillsQuantity28: TFloatField;
  71. cdsBillsTotalPrice28: TFloatField;
  72. cdsBillsQuantity29: TFloatField;
  73. cdsBillsTotalPrice29: TFloatField;
  74. cdsBillsQuantity30: TFloatField;
  75. cdsBillsTotalPrice30: TFloatField;
  76. cdsBillsQuantity31: TFloatField;
  77. cdsBillsTotalPrice31: TFloatField;
  78. cdsBillsQuantity32: TFloatField;
  79. cdsBillsTotalPrice32: TFloatField;
  80. cdsBillsQuantity33: TFloatField;
  81. cdsBillsTotalPrice33: TFloatField;
  82. cdsBillsQuantity34: TFloatField;
  83. cdsBillsTotalPrice34: TFloatField;
  84. cdsBillsQuantity35: TFloatField;
  85. cdsBillsTotalPrice35: TFloatField;
  86. cdsBillsQuantity36: TFloatField;
  87. cdsBillsTotalPrice36: TFloatField;
  88. cdsBillsQuantity37: TFloatField;
  89. cdsBillsTotalPrice37: TFloatField;
  90. cdsBillsQuantity38: TFloatField;
  91. cdsBillsTotalPrice38: TFloatField;
  92. cdsBillsQuantity39: TFloatField;
  93. cdsBillsTotalPrice39: TFloatField;
  94. cdsBillsQuantity40: TFloatField;
  95. cdsBillsTotalPrice40: TFloatField;
  96. cdsBillsQuantity41: TFloatField;
  97. cdsBillsTotalPrice41: TFloatField;
  98. cdsBillsQuantity42: TFloatField;
  99. cdsBillsTotalPrice42: TFloatField;
  100. cdsBillsQuantity43: TFloatField;
  101. cdsBillsTotalPrice43: TFloatField;
  102. cdsBillsQuantity44: TFloatField;
  103. cdsBillsTotalPrice44: TFloatField;
  104. cdsBillsQuantity45: TFloatField;
  105. cdsBillsTotalPrice45: TFloatField;
  106. cdsBillsQuantity46: TFloatField;
  107. cdsBillsTotalPrice46: TFloatField;
  108. cdsBillsQuantity47: TFloatField;
  109. cdsBillsTotalPrice47: TFloatField;
  110. cdsBillsQuantity48: TFloatField;
  111. cdsBillsTotalPrice48: TFloatField;
  112. cdsBillsQuantity49: TFloatField;
  113. cdsBillsTotalPrice49: TFloatField;
  114. cdsBillsQuantity50: TFloatField;
  115. cdsBillsTotalPrice50: TFloatField;
  116. cdsBillsMemoStr: TWideStringField;
  117. private
  118. FProjectData: TProjectData;
  119. FAllPhaseCacheTree: TAllPhaseCacheTree;
  120. function AddBills(ANode: TsdIDTreeNode; AParent: TAllPhaseCacheNode): TAllPhaseCacheNode;
  121. procedure LoadStageData(AStageData: TStageData; APhaseIndex: Integer);
  122. procedure LoadPhaseData(APhaseIndex: Integer);
  123. procedure WriteBills(ANode: TAllPhaseCacheNode);
  124. public
  125. function AssignData(AProjectData: TProjectData): TDataSet;
  126. end;
  127. implementation
  128. uses CacheTree;
  129. {$R *.dfm}
  130. { TrmFxBillsAddData }
  131. function TrmFxBillsAddData.AddBills(ANode: TsdIDTreeNode;
  132. AParent: TAllPhaseCacheNode): TAllPhaseCacheNode;
  133. begin
  134. if not Assigned(ANode) then Exit;
  135. Result := FAllPhaseCacheTree.AddNode(ANode.ID, AParent, nil);
  136. Result.Code := ANode.Rec.ValueByName('Code').AsString;
  137. Result.B_Code := ANode.Rec.ValueByName('B_Code').AsString;
  138. Result.Name := ANode.Rec.ValueByName('Name').AsString;
  139. Result.Units := ANode.Rec.ValueByName('Units').AsString;
  140. Result.Price := ANode.Rec.ValueByName('Price').AsFloat;
  141. Result.Quantity := ANode.Rec.ValueByName('Quantity').AsFloat;
  142. Result.TotalPrice := ANode.Rec.ValueByName('TotalPrice').AsFloat;
  143. AddBills(ANode.FirstChild, Result);
  144. AddBills(ANode.NextSibling, AParent);
  145. end;
  146. function TrmFxBillsAddData.AssignData(
  147. AProjectData: TProjectData): TDataSet;
  148. var
  149. iPhase: Integer;
  150. begin
  151. FProjectData := AProjectData;
  152. cdsBills.DisableControls;
  153. cdsBills.Active := True;
  154. cdsBills.EmptyDataSet;
  155. FAllPhaseCacheTree := TAllPhaseCacheTree.Create;
  156. try
  157. AddBills(FProjectData.BillsCompileData.BillsCompileTree.FirstNode, nil);
  158. for iPhase := 1 to FProjectData.ProjProperties.PhaseCount do
  159. LoadPhaseData(iPhase);
  160. WriteBills(TAllPhaseCacheNode(FAllPhaseCacheTree.FirstNode));
  161. finally
  162. Result := cdsBills;
  163. FAllPhaseCacheTree.Free;
  164. cdsBills.EnableControls;
  165. end;
  166. end;
  167. procedure TrmFxBillsAddData.LoadPhaseData(APhaseIndex: Integer);
  168. var
  169. PhaseData: TPhaseData;
  170. StageData: TStageData;
  171. begin
  172. PhaseData := TPhaseData.Create(nil);
  173. try
  174. PhaseData.SimpleOpen(Format('%s\Phase%d.dat', [FProjectData.TempPath, APhaseIndex]));
  175. if PhaseData.IsLastStage then
  176. LoadStageData(PhaseData.StageData, APhaseIndex)
  177. else
  178. begin
  179. try
  180. StageData := TStageData.Create(PhaseData);
  181. StageData.TableName := PhaseData.StageTableName[PhaseData.AuditCount];
  182. StageData.Open(PhaseData.ADOConnection);
  183. LoadStageData(StageData, APhaseIndex);
  184. finally
  185. StageData.Free;
  186. end;
  187. end;
  188. finally
  189. PhaseData.Free;
  190. end;
  191. end;
  192. procedure TrmFxBillsAddData.LoadStageData(AStageData: TStageData;
  193. APhaseIndex: Integer);
  194. var
  195. i: Integer;
  196. StageRec: TsdDataRecord;
  197. stnNode: TsdIDTreeNode;
  198. Node: TAllPhaseCacheNode;
  199. begin
  200. for i := 0 to AStageData.sddStage.RecordCount - 1 do
  201. begin
  202. StageRec := AStageData.sddStage.Records[i];
  203. with FProjectData.BillsCompileData.BillsCompileTree do
  204. stnNode := FindNode(StageRec.ValueByName('BillsID').AsInteger);
  205. Node := FAllPhaseCacheTree.FindNode(StageRec.ValueByName('BillsID').AsInteger);
  206. if Assigned(Node) then
  207. begin
  208. Node.FP_Quantity[APhaseIndex] := StageRec.ValueByName('GatherQuantity').AsFloat;
  209. Node.FP_TotalPrice[APhaseIndex] := StageRec.ValueByName('GatherTotalPrice').AsFloat;
  210. end;
  211. end;
  212. end;
  213. procedure TrmFxBillsAddData.WriteBills(ANode: TAllPhaseCacheNode);
  214. begin
  215. if not Assigned(ANode) then Exit;
  216. cdsBills.Append;
  217. cdsBillsCode.AsString := ANode.Code;
  218. cdsBillsB_Code.AsString := ANode.B_Code;
  219. cdsBillsName.AsString := ANode.Name;
  220. cdsBillsUnits.AsString := ANode.Units;
  221. cdsBillsPrice.AsFloat := ANode.Price;
  222. cdsBillsQuantity.AsFloat := ANode.Quantity;
  223. cdsBillsTotalPrice.AsFloat := ANode.TotalPrice;
  224. cdsBillsQuantity1.AsFloat := ANode.FP_Quantity[1];
  225. cdsBillsTotalPrice1.AsFloat := ANode.FP_TotalPrice[1];
  226. cdsBillsQuantity2.AsFloat := ANode.FP_Quantity[2];
  227. cdsBillsTotalPrice2.AsFloat := ANode.FP_TotalPrice[2];
  228. cdsBillsQuantity3.AsFloat := ANode.FP_Quantity[3];
  229. cdsBillsTotalPrice3.AsFloat := ANode.FP_TotalPrice[3];
  230. cdsBillsQuantity4.AsFloat := ANode.FP_Quantity[4];
  231. cdsBillsTotalPrice4.AsFloat := ANode.FP_TotalPrice[4];
  232. cdsBillsQuantity5.AsFloat := ANode.FP_Quantity[5];
  233. cdsBillsTotalPrice5.AsFloat := ANode.FP_TotalPrice[5];
  234. cdsBillsQuantity6.AsFloat := ANode.FP_Quantity[6];
  235. cdsBillsTotalPrice6.AsFloat := ANode.FP_TotalPrice[6];
  236. cdsBillsQuantity7.AsFloat := ANode.FP_Quantity[7];
  237. cdsBillsTotalPrice7.AsFloat := ANode.FP_TotalPrice[7];
  238. cdsBillsQuantity8.AsFloat := ANode.FP_Quantity[8];
  239. cdsBillsTotalPrice8.AsFloat := ANode.FP_TotalPrice[8];
  240. cdsBillsQuantity9.AsFloat := ANode.FP_Quantity[9];
  241. cdsBillsTotalPrice9.AsFloat := ANode.FP_TotalPrice[9];
  242. cdsBillsQuantity10.AsFloat := ANode.FP_Quantity[10];
  243. cdsBillsTotalPrice10.AsFloat := ANode.FP_TotalPrice[10];
  244. cdsBillsQuantity11.AsFloat := ANode.FP_Quantity[11];
  245. cdsBillsTotalPrice11.AsFloat := ANode.FP_TotalPrice[11];
  246. cdsBillsQuantity12.AsFloat := ANode.FP_Quantity[12];
  247. cdsBillsTotalPrice12.AsFloat := ANode.FP_TotalPrice[12];
  248. cdsBillsQuantity13.AsFloat := ANode.FP_Quantity[13];
  249. cdsBillsTotalPrice13.AsFloat := ANode.FP_TotalPrice[13];
  250. cdsBillsQuantity14.AsFloat := ANode.FP_Quantity[14];
  251. cdsBillsTotalPrice14.AsFloat := ANode.FP_TotalPrice[14];
  252. cdsBillsQuantity15.AsFloat := ANode.FP_Quantity[15];
  253. cdsBillsTotalPrice15.AsFloat := ANode.FP_TotalPrice[15];
  254. cdsBillsQuantity16.AsFloat := ANode.FP_Quantity[16];
  255. cdsBillsTotalPrice16.AsFloat := ANode.FP_TotalPrice[16];
  256. cdsBillsQuantity17.AsFloat := ANode.FP_Quantity[17];
  257. cdsBillsTotalPrice17.AsFloat := ANode.FP_TotalPrice[17];
  258. cdsBillsQuantity18.AsFloat := ANode.FP_Quantity[18];
  259. cdsBillsTotalPrice18.AsFloat := ANode.FP_TotalPrice[18];
  260. cdsBillsQuantity19.AsFloat := ANode.FP_Quantity[19];
  261. cdsBillsTotalPrice19.AsFloat := ANode.FP_TotalPrice[19];
  262. cdsBillsQuantity20.AsFloat := ANode.FP_Quantity[20];
  263. cdsBillsTotalPrice20.AsFloat := ANode.FP_TotalPrice[20];
  264. cdsBillsQuantity21.AsFloat := ANode.FP_Quantity[21];
  265. cdsBillsTotalPrice21.AsFloat := ANode.FP_TotalPrice[21];
  266. cdsBillsQuantity22.AsFloat := ANode.FP_Quantity[22];
  267. cdsBillsTotalPrice22.AsFloat := ANode.FP_TotalPrice[22];
  268. cdsBillsQuantity23.AsFloat := ANode.FP_Quantity[23];
  269. cdsBillsTotalPrice23.AsFloat := ANode.FP_TotalPrice[23];
  270. cdsBillsQuantity24.AsFloat := ANode.FP_Quantity[24];
  271. cdsBillsTotalPrice24.AsFloat := ANode.FP_TotalPrice[24];
  272. cdsBillsQuantity25.AsFloat := ANode.FP_Quantity[25];
  273. cdsBillsTotalPrice25.AsFloat := ANode.FP_TotalPrice[25];
  274. cdsBillsQuantity26.AsFloat := ANode.FP_Quantity[26];
  275. cdsBillsTotalPrice26.AsFloat := ANode.FP_TotalPrice[26];
  276. cdsBillsQuantity27.AsFloat := ANode.FP_Quantity[27];
  277. cdsBillsTotalPrice27.AsFloat := ANode.FP_TotalPrice[27];
  278. cdsBillsQuantity28.AsFloat := ANode.FP_Quantity[28];
  279. cdsBillsTotalPrice28.AsFloat := ANode.FP_TotalPrice[28];
  280. cdsBillsQuantity29.AsFloat := ANode.FP_Quantity[29];
  281. cdsBillsTotalPrice29.AsFloat := ANode.FP_TotalPrice[29];
  282. cdsBillsQuantity30.AsFloat := ANode.FP_Quantity[30];
  283. cdsBillsTotalPrice30.AsFloat := ANode.FP_TotalPrice[30];
  284. cdsBillsQuantity31.AsFloat := ANode.FP_Quantity[31];
  285. cdsBillsTotalPrice31.AsFloat := ANode.FP_TotalPrice[31];
  286. cdsBillsQuantity32.AsFloat := ANode.FP_Quantity[32];
  287. cdsBillsTotalPrice32.AsFloat := ANode.FP_TotalPrice[32];
  288. cdsBillsQuantity33.AsFloat := ANode.FP_Quantity[33];
  289. cdsBillsTotalPrice33.AsFloat := ANode.FP_TotalPrice[33];
  290. cdsBillsQuantity34.AsFloat := ANode.FP_Quantity[34];
  291. cdsBillsTotalPrice34.AsFloat := ANode.FP_TotalPrice[34];
  292. cdsBillsQuantity35.AsFloat := ANode.FP_Quantity[35];
  293. cdsBillsTotalPrice35.AsFloat := ANode.FP_TotalPrice[35];
  294. cdsBillsQuantity36.AsFloat := ANode.FP_Quantity[36];
  295. cdsBillsTotalPrice36.AsFloat := ANode.FP_TotalPrice[36];
  296. cdsBillsQuantity37.AsFloat := ANode.FP_Quantity[37];
  297. cdsBillsTotalPrice37.AsFloat := ANode.FP_TotalPrice[37];
  298. cdsBillsQuantity38.AsFloat := ANode.FP_Quantity[38];
  299. cdsBillsTotalPrice38.AsFloat := ANode.FP_TotalPrice[38];
  300. cdsBillsQuantity39.AsFloat := ANode.FP_Quantity[39];
  301. cdsBillsTotalPrice39.AsFloat := ANode.FP_TotalPrice[39];
  302. cdsBillsQuantity40.AsFloat := ANode.FP_Quantity[40];
  303. cdsBillsTotalPrice40.AsFloat := ANode.FP_TotalPrice[40];
  304. cdsBillsQuantity41.AsFloat := ANode.FP_Quantity[41];
  305. cdsBillsTotalPrice41.AsFloat := ANode.FP_TotalPrice[41];
  306. cdsBillsQuantity42.AsFloat := ANode.FP_Quantity[42];
  307. cdsBillsTotalPrice42.AsFloat := ANode.FP_TotalPrice[42];
  308. cdsBillsQuantity43.AsFloat := ANode.FP_Quantity[43];
  309. cdsBillsTotalPrice43.AsFloat := ANode.FP_TotalPrice[43];
  310. cdsBillsQuantity44.AsFloat := ANode.FP_Quantity[44];
  311. cdsBillsTotalPrice44.AsFloat := ANode.FP_TotalPrice[44];
  312. cdsBillsQuantity45.AsFloat := ANode.FP_Quantity[45];
  313. cdsBillsTotalPrice45.AsFloat := ANode.FP_TotalPrice[45];
  314. cdsBillsQuantity46.AsFloat := ANode.FP_Quantity[46];
  315. cdsBillsTotalPrice46.AsFloat := ANode.FP_TotalPrice[46];
  316. cdsBillsQuantity47.AsFloat := ANode.FP_Quantity[47];
  317. cdsBillsTotalPrice47.AsFloat := ANode.FP_TotalPrice[47];
  318. cdsBillsQuantity48.AsFloat := ANode.FP_Quantity[48];
  319. cdsBillsTotalPrice48.AsFloat := ANode.FP_TotalPrice[48];
  320. cdsBillsQuantity49.AsFloat := ANode.FP_Quantity[49];
  321. cdsBillsTotalPrice49.AsFloat := ANode.FP_TotalPrice[49];
  322. cdsBillsQuantity50.AsFloat := ANode.FP_Quantity[50];
  323. cdsBillsTotalPrice50.AsFloat := ANode.FP_TotalPrice[50];
  324. cdsBills.Post;
  325. WriteBills(TAllPhaseCacheNode(ANode.FirstChild));
  326. WriteBills(TAllPhaseCacheNode(ANode.NextSibling));
  327. end;
  328. end.