ScProjGLJGatherDM.pas 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141
  1. unit ScProjGLJGatherDM;
  2. interface
  3. uses
  4. Windows, SysUtils, Classes, ProjectsDM, ScProjBaseDM, ScProjList, DB, ADODB,
  5. DBClient;
  6. type
  7. TReportType = (rtNone, rtTable_02_1);
  8. TScProjGLJGather = class(TDataModule)
  9. cdsGLJGather: TClientDataSet;
  10. aqProjGLJ: TADOQuery;
  11. cdsProjData: TClientDataSet;
  12. cdsProjDataBuildProjName: TWideStringField;
  13. cdsProjDataAuthor: TWideStringField;
  14. cdsProjDataAuditor: TWideStringField;
  15. cdsGLJGatherCode: TIntegerField;
  16. cdsGLJGatherName: TStringField;
  17. cdsGLJGatherUnit: TStringField;
  18. cdsGLJGatherProjectName: TStringField;
  19. cdsGLJGatherAmount: TFloatField;
  20. cdsGLJGatherProjectID: TIntegerField;
  21. cdsGLJGatherLibID: TIntegerField;
  22. cdsGLJGatherType: TIntegerField;
  23. aqProjGLJACode: TIntegerField;
  24. aqProjGLJAName: TWideStringField;
  25. aqProjGLJAUnit: TWideStringField;
  26. aqProjGLJUAmount: TFloatField;
  27. aqProjGLJAType: TIntegerField;
  28. cdsGLJGatherSumAmount: TFloatField;
  29. cdsGLJGatherPrice: TCurrencyField;
  30. aqProjGLJPrice: TCurrencyField;
  31. cdsGLJGatherD: TClientDataSet;
  32. aqMateBuildFee: TADOQuery;
  33. aqMateBuildFeeMateFee: TBCDField;
  34. aqMateBuildFeeBuildFee: TFloatField;
  35. aqMateBuildFeeFileName: TStringField;
  36. cdsGLJForReport: TClientDataSet;
  37. aqMateBuildFeeTenderMateFee: TBCDField;
  38. aqMateBuildFeeTenderBuildFee: TFloatField;
  39. aqProjGLJUTenderAmount: TFloatField;
  40. aqProjGLJTenderPrice: TCurrencyField;
  41. procedure DataModuleCreate(Sender: TObject);
  42. procedure DataModuleDestroy(Sender: TObject);
  43. private
  44. { Private declarations }
  45. FProjects: TList;
  46. FReportType: TReportType;
  47. FSumAmountAgg: TAggregate;
  48. FBuildProj: TScProjectItem;
  49. procedure AddProjRecord(AConnection: TADOConnection; AProjID: Integer;
  50. AProjName: string);
  51. procedure CheckProjects(ABuildProjName: string);
  52. procedure DoSumAmount;
  53. procedure MakeProjList(ABuildProj: TScProjectItem);
  54. public
  55. { Public declarations }
  56. function GatherProjs(ABuildProjName: string): Boolean;
  57. function GatherGLJ(ABuildProjName: string): Boolean;
  58. function GatherGLJForReport(ABuildProjName: string): Boolean;
  59. property ReportType: TReportType read FReportType write FReportType;
  60. end;
  61. var
  62. ScProjGLJGather: TScProjGLJGather;
  63. implementation
  64. uses
  65. ScIDTree, ScUtils, Math, ScProjectsGather, ScSelectGatherForm, ScFileArchiver,
  66. ScConsts;
  67. {$R *.dfm}
  68. // 旧查询语句,从02表来,因条件变化,现在改成直接从ProjectGLJ中查询
  69. {SELECT ACode, AName, AUnit, Sum(AAmount) AS UAmount, AType
  70. FROM
  71. (
  72. SELECT P.Code AS ACode, P.Name AS AName, P.Unit AS AUnit,
  73. Sum(G.Quantity*G.RationItemQuantity) AS AAmount, P.Type AS AType, P.LibID
  74. FROM ProjectGLJ AS P, GLJList AS G
  75. WHERE (P.Code=G.Code) AND (G.Type<>2) AND (P.LibID=G.LibID) AND
  76. ((SELECT Sum(G9.Quantity*G9.RationItemQuantity)
  77. FROM GLJList AS G9, ProjectGLJ AS P9
  78. WHERE (P9.Code=G9.Code) AND (G9.Type<>2) AND (P9.LibID=G9.LibID)
  79. )>0 )
  80. GROUP BY P.Code, P.Name, P.Unit, P.Type, P.LibID
  81. UNION ALL
  82. SELECT P1.Code AS ACode, P1.Name AS AName, P1.Unit AS AUnit,
  83. SUM(M1.RG*G1.Quantity*G1.RationItemQuantity) AS AAmount, P1.Type AS AType, P1.LibID
  84. FROM GLJList AS G1, MachinePrice AS M1, ProjectGLJ AS P1
  85. WHERE (P1.Code=3) AND (G1.Code=M1.Code) AND (P1.LibID=G1.LibID) AND
  86. ((SELECT SUM(M8.RG*G8.Quantity*G8.RationItemQuantity)
  87. FROM GLJList AS G8, MachinePrice AS M8, ProjectGLJ AS P8
  88. WHERE (P8.Code=3) AND (G8.Code=M8.Code) AND (P8.LibID=G8.LibID)
  89. )>0 )
  90. GROUP BY P1.Code, P1.Name, P1.Unit, P1.Type, P1.LibID
  91. UNION ALL
  92. SELECT P1.Code AS ACode, P1.Name AS AName, P1.Unit AS AUnit,
  93. SUM(M1.ZY*G1.Quantity*G1.RationItemQuantity) AS AAmount, P1.Type AS AType, P1.LibID
  94. FROM GLJList AS G1, MachinePrice AS M1, ProjectGLJ AS P1
  95. WHERE (P1.Code=263) AND (G1.Code=M1.Code) AND (P1.LibID=G1.LibID) AND
  96. ((SELECT SUM(M8.ZY*G8.Quantity*G8.RationItemQuantity)
  97. FROM GLJList AS G8, MachinePrice AS M8, ProjectGLJ AS P8
  98. WHERE (P8.Code=263) AND (G8.Code=M8.Code) AND (P8.LibID=G8.LibID)
  99. )>0 )
  100. GROUP BY P1.Code, P1.Name, P1.Unit, P1.Type, P1.LibID
  101. UNION ALL
  102. SELECT P1.Code AS ACode, P1.Name AS AName, P1.Unit AS AUnit,
  103. SUM(M1.QY*G1.Quantity*G1.RationItemQuantity) AS AAmount, P1.Type AS AType, P1.LibID
  104. FROM GLJList AS G1, MachinePrice AS M1, ProjectGLJ AS P1
  105. WHERE (P1.Code=264) AND (G1.Code=M1.Code) AND (P1.LibID=G1.LibID) AND
  106. ((SELECT SUM(M8.QY*G8.Quantity*G8.RationItemQuantity)
  107. FROM GLJList AS G8, MachinePrice AS M8, ProjectGLJ AS P8
  108. WHERE (P8.Code=264) AND (G8.Code=M8.Code) AND (P8.LibID=G8.LibID)
  109. )>0 )
  110. GROUP BY P1.Code, P1.Name, P1.Unit, P1.Type, P1.LibID
  111. UNION ALL
  112. SELECT P1.Code AS ACode, P1.Name AS AName, P1.Unit AS AUnit,
  113. SUM(M1.CY*G1.Quantity*G1.RationItemQuantity) AS AAmount, P1.Type AS AType, P1.LibID
  114. FROM GLJList AS G1, MachinePrice AS M1, ProjectGLJ AS P1
  115. WHERE (P1.Code=265) AND (G1.Code=M1.Code) AND (P1.LibID=G1.LibID) AND
  116. ((SELECT SUM(M8.CY*G8.Quantity*G8.RationItemQuantity)
  117. FROM GLJList AS G8, MachinePrice AS M8, ProjectGLJ AS P8
  118. WHERE (P8.Code=265) AND (G8.Code=M8.Code) AND (P8.LibID=G8.LibID)
  119. )>0 )
  120. GROUP BY P1.Code, P1.Name, P1.Unit, P1.Type, P1.LibID
  121. UNION ALL
  122. SELECT P1.Code AS ACode, P1.Name AS AName, P1.Unit AS AUnit,
  123. SUM(M1.Mei*G1.Quantity*G1.RationItemQuantity) AS AAmount, P1.Type AS AType, P1.LibID
  124. FROM GLJList AS G1, MachinePrice AS M1, ProjectGLJ AS P1
  125. WHERE (P1.Code=266) AND (G1.Code=M1.Code) AND (P1.LibID=G1.LibID) AND
  126. ((SELECT SUM(M8.Mei*G8.Quantity*G8.RationItemQuantity)
  127. FROM GLJList AS G8, MachinePrice AS M8, ProjectGLJ AS P8
  128. WHERE (P8.Code=266) AND (G8.Code=M8.Code) AND (P8.LibID=G8.LibID)
  129. )>0 )
  130. GROUP BY P1.Code, P1.Name, P1.Unit, P1.Type, P1.LibID
  131. UNION ALL
  132. SELECT P1.Code AS ACode, P1.Name AS AName, P1.Unit AS AUnit,
  133. SUM(M1.Dian*G1.Quantity*G1.RationItemQuantity) AS AAmount, P1.Type AS AType, P1.LibID
  134. FROM GLJList AS G1, MachinePrice AS M1, ProjectGLJ AS P1
  135. WHERE (P1.Code=267) AND (G1.Code=M1.Code) AND (P1.LibID=G1.LibID) AND
  136. ((SELECT SUM(M8.Dian*G8.Quantity*G8.RationItemQuantity)
  137. FROM GLJList AS G8, MachinePrice AS M8, ProjectGLJ AS P8
  138. WHERE (P8.Code=267) AND (G8.Code=M8.Code) AND (P8.LibID=G8.LibID)
  139. )>0 )
  140. GROUP BY P1.Code, P1.Name, P1.Unit, P1.Type, P1.LibID
  141. UNION ALL
  142. SELECT P1.Code AS ACode, P1.Name AS AName, P1.Unit AS AUnit,
  143. SUM(M1.Shui*G1.Quantity*G1.RationItemQuantity) AS AAmount, P1.Type AS AType, P1.LibID
  144. FROM GLJList AS G1, MachinePrice AS M1, ProjectGLJ AS P1
  145. WHERE (P1.Code=268) AND (G1.Code=M1.Code) AND (P1.LibID=G1.LibID) AND
  146. ((SELECT SUM(M8.Shui*G8.Quantity*G8.RationItemQuantity)
  147. FROM GLJList AS G8, MachinePrice AS M8, ProjectGLJ AS P8
  148. WHERE (P8.Code=268) AND (G8.Code=M8.Code) AND (P8.LibID=G8.LibID)
  149. )>0 )
  150. GROUP BY P1.Code, P1.Name, P1.Unit, P1.Type, P1.LibID
  151. UNION ALL
  152. SELECT P1.Code AS ACode, P1.Name AS AName, P1.Unit AS AUnit,
  153. SUM(M1.MC*G1.Quantity*G1.RationItemQuantity) AS AAmount, P1.Type AS AType, P1.LibID
  154. FROM GLJList AS G1, MachinePrice AS M1, ProjectGLJ AS P1
  155. WHERE (P1.Code=269) AND (G1.Code=M1.Code) AND (P1.LibID=G1.LibID) AND
  156. ((SELECT SUM(M8.MC*G8.Quantity*G8.RationItemQuantity)
  157. FROM GLJList AS G8, MachinePrice AS M8, ProjectGLJ AS P8
  158. WHERE (P8.Code=269) AND (G8.Code=M8.Code) AND (P8.LibID=G8.LibID)
  159. )>0 )
  160. GROUP BY P1.Code, P1.Name, P1.Unit, P1.Type, P1.LibID
  161. )
  162. GROUP BY ACode, AName, AUnit, AType'}
  163. { TScProjGLJGather }
  164. procedure TScProjGLJGather.AddProjRecord(AConnection: TADOConnection;
  165. AProjID: Integer; AProjName: string);
  166. var
  167. fMachineAmount: Currency;
  168. bIsEstimate: Boolean;
  169. begin
  170. bIsEstimate := False;
  171. {$IFDEF _ScEstimate}
  172. bIsEstimate := True;
  173. {$ENDIF}
  174. fMachineAmount := 0;
  175. aqProjGLJ.Close;
  176. aqProjGLJ.Connection := AConnection;
  177. aqProjGLJ.Open;
  178. aqProjGLJ.First;
  179. while not aqProjGLJ.Eof do
  180. begin
  181. if aqProjGLJACode.AsInteger = SJiJiaCode then
  182. begin
  183. aqProjGLJ.Next;
  184. Continue;
  185. end;
  186. if bIsEstimate then
  187. begin
  188. if ((aqProjGLJACode.AsInteger <> 400) {$IFDEF _ScGanSu}and (aqProjGLJACode.AsInteger <> 998){$ENDIF}) and (aqProjGLJAType.AsInteger = 4) then
  189. begin
  190. // fMachineAmount := fMachineAmount + aqProjGLJUAmount.AsFloat * aqProjGLJPrice.AsCurrency;
  191. aqProjGLJ.Next;
  192. Continue;
  193. end;
  194. end;
  195. {如果是02—1表,并且是混凝土,则不添加。 李涛 2010.4.29}
  196. if (FReportType = rtNone) or
  197. ((FReportType = rtTable_02_1) and (aqProjGLJAType.AsInteger <> 2)) then
  198. begin
  199. cdsGLJGather.Append;
  200. cdsGLJGatherCode.AsInteger := aqProjGLJACode.AsInteger;
  201. cdsGLJGatherName.AsString := aqProjGLJAName.AsString;
  202. cdsGLJGatherUnit.AsString := aqProjGLJAUnit.AsString;
  203. cdsGLJGatherProjectName.AsString := AProjName;
  204. cdsGLJGatherPrice.AsCurrency := aqProjGLJPrice.AsCurrency;
  205. cdsGLJGatherAmount.AsFloat := aqProjGLJUAmount.AsFloat;
  206. cdsGLJGatherProjectID.AsInteger := AProjID;
  207. cdsGLJGatherLibID.AsInteger := 0;
  208. cdsGLJGatherType.AsInteger := aqProjGLJAType.AsInteger;
  209. cdsGLJGather.Post;
  210. end;
  211. aqProjGLJ.Next;
  212. end;
  213. { if bIsEstimate then
  214. begin
  215. if cdsGLJGather.Locate('Code', 400, []) then
  216. begin
  217. cdsGLJGather.Edit;
  218. cdsGLJGatherAmount.Value := cdsGLJGatherAmount.Value + fMachineAmount;
  219. cdsGLJGather.Post;
  220. end
  221. else
  222. begin
  223. cdsGLJGather.Append;
  224. cdsGLJGatherCode.AsInteger := 400;
  225. cdsGLJGatherName.AsString := '机械使用费';
  226. cdsGLJGatherUnit.AsString := '元';
  227. cdsGLJGatherProjectName.AsString := AProjName;
  228. cdsGLJGatherPrice.AsCurrency := 1;
  229. cdsGLJGatherAmount.Value := fMachineAmount;
  230. cdsGLJGatherProjectID.AsInteger := AProjID;
  231. cdsGLJGatherLibID.AsInteger := 0;
  232. cdsGLJGatherType.AsInteger := 3;
  233. cdsGLJGather.Post;
  234. end;
  235. end;}
  236. end;
  237. procedure TScProjGLJGather.MakeProjList(ABuildProj: TScProjectItem);
  238. var
  239. Proj: TScProjectItem;
  240. ProjData: TScProjBaseData;
  241. pProjSum: PProjChapterSum;
  242. I, BaseFile: Integer;
  243. vProjList: TList;
  244. begin
  245. vProjList := TList.Create;
  246. try
  247. FProjects.Clear;
  248. Proj := TScProjectItem(ABuildProj.FirstChild);
  249. while Assigned(Proj) do
  250. begin
  251. if FileExists(Proj.FileName) then
  252. begin
  253. if IsSmartCostProjectFile(Proj.FileName) then
  254. begin
  255. New(pProjSum);
  256. ZeroMemory(pProjSum, Sizeof(TProjChapterSum));
  257. pProjSum^.ID := Proj.ID;
  258. pProjSum^.Name := Proj.Name;
  259. pProjSum^.FileName := Proj.FileName;
  260. pProjSum^.Selected := Proj.Selected;
  261. vProjList.Add(pProjSum);
  262. end
  263. else
  264. MessageWarning(0,
  265. Format('所选建设项目中,项目文件[%s]不是有效的SmartCost预算项目文件。'#13#10 +
  266. '请进入“建设项目管理”进行管理。', [Proj.Name]));
  267. end
  268. else
  269. MessageWarning(0,
  270. Format('所选建设项目中,项目文件[%s]不存在。'#13#10 +
  271. '请进入“建设项目管理”重新查找该项目。', [Proj.Name]));
  272. Proj := TScProjectItem(Proj.NextSibling);
  273. end;
  274. // *汇总表类型
  275. if SelectProjects(vProjList, BaseFile) then
  276. for I := 0 to vProjList.Count - 1 do
  277. begin
  278. pProjSum := PProjChapterSum(vProjList[I]);
  279. if pProjSum^.Selected then
  280. begin
  281. ProjData := ProjList.IndexByName(pProjSum^.FileName);
  282. if ProjData = nil then
  283. ProjData := ProjList.AddProj(pProjSum^.FileName);
  284. ProjData.Open;
  285. FProjects.Add(ProjData);
  286. end;
  287. Dispose(pProjSum);
  288. end;
  289. finally
  290. vProjList.Free;
  291. end;
  292. end;
  293. procedure TScProjGLJGather.CheckProjects(ABuildProjName: string);
  294. var
  295. I: Integer;
  296. Proj: TScProjectItem;
  297. ProjData: TScProjBaseData;
  298. begin
  299. Proj := ProjectManager.FindBuildProject(ABuildProjName);
  300. MakeProjList(Proj);
  301. if FProjects.Count = 0 then Exit;
  302. ProjData := TScProjBaseData(FProjects[0]);
  303. if Proj <> nil then
  304. begin
  305. cdsProjData.Active := True;
  306. cdsProjData.EmptyDataSet;
  307. cdsProjData.Append;
  308. cdsProjDataBuildProjName.Value := ProjData.BuildProjectName;
  309. cdsProjDataAuthor.Value := ProjData.Author;
  310. cdsProjDataAuditor.Value := ProjData.Auditor;
  311. cdsProjData.Post;
  312. cdsProjData.First;
  313. end;
  314. { if (Proj <> nil) and (Proj.FirstChild <> nil) then
  315. begin
  316. Proj := TScProjectItem(Proj.FirstChild);
  317. while Proj <> nil do
  318. begin
  319. ProjData := ProjList.IndexByName(Proj.FileName);
  320. if ProjData = nil then
  321. ProjData := ProjList.AddProj(Proj.FileName);
  322. if not ProjData.IsOpened then
  323. ProjData.Open;
  324. if Proj.PrevSibling = nil then
  325. begin
  326. cdsProjData.Active := True;
  327. cdsProjData.EmptyDataSet;
  328. cdsProjData.Append;
  329. cdsProjDataBuildProjName.Value := ProjData.BuildProjectName;
  330. cdsProjDataAuthor.Value := ProjData.Author;
  331. cdsProjDataAuditor.Value := ProjData.Auditor;
  332. cdsProjData.Post;
  333. cdsProjData.First;
  334. end;
  335. FProjects.Add(ProjList.IndexByName(Proj.FileName));
  336. Proj := TScProjectItem(Proj.NextSibling);
  337. end;
  338. end;}
  339. end;
  340. function TScProjGLJGather.GatherProjs(ABuildProjName: string): Boolean;
  341. var
  342. I: Integer;
  343. begin
  344. cdsGLJGather.Open;
  345. cdsGLJGather.EmptyDataSet;
  346. cdsGLJGather.IndexName := 'cdsGLJGatherIdxCalc';
  347. try
  348. if ABuildProjName = '' then
  349. ABuildProjName := strUnTypeProj;
  350. CheckProjects(ABuildProjName);
  351. for I := 0 to FProjects.Count - 1 do
  352. begin
  353. AddProjRecord(TScProjBaseData(FProjects[I]).Connection.Connection, I,
  354. TScProjBaseData(FProjects[I]).Alias);
  355. end;
  356. DoSumAmount;
  357. finally
  358. cdsGLJGather.IndexName := 'cdsGLJGatherIdxSort';
  359. end;
  360. end;
  361. procedure TScProjGLJGather.DataModuleCreate(Sender: TObject);
  362. begin
  363. FProjects := TList.Create;
  364. FSumAmountAgg := cdsGLJGather.Aggregates.Add;
  365. FSumAmountAgg.Expression := 'Sum(Amount)';
  366. FSumAmountAgg.IndexName := 'cdsGLJGatherIdxCalc';
  367. FSumAmountAgg.GroupingLevel := 1;
  368. FSumAmountAgg.Active := True;
  369. FReportType := rtNone;
  370. end;
  371. procedure TScProjGLJGather.DataModuleDestroy(Sender: TObject);
  372. begin
  373. FProjects.Free;
  374. end;
  375. procedure TScProjGLJGather.DoSumAmount;
  376. begin
  377. cdsGLJGather.First;
  378. while not cdsGLJGather.Eof do
  379. begin
  380. // lsm 2010-1-21删除消耗为0的工料机
  381. if ScVarToFloat(FSumAmountAgg.Value) = 0 then
  382. cdsGLJGather.Delete
  383. else
  384. begin
  385. cdsGLJGather.Edit;
  386. cdsGLJGatherSumAmount.AsFloat := RoundTo(ScVarToFloat(FSumAmountAgg.Value), -3);
  387. cdsGLJGather.Post;
  388. cdsGLJGather.Next;
  389. end;
  390. end;
  391. end;
  392. {aqProjGLJ的SQL
  393. SELECT ACode, AName, AUnit, Sum(AAmount) AS UAmount, AType
  394. FROM
  395. (
  396. SELECT P.Code AS ACode, P.Name AS AName, P.Unit AS AUnit,
  397. Sum(G.Quantity*G.RationItemQuantity) AS AAmount, P.Type AS AType, P.LibID
  398. FROM ProjectGLJ AS P, GLJList AS G
  399. WHERE (P.Code=G.Code) AND (G.Type<>2) AND (P.LibID=G.LibID) AND
  400. ((SELECT Sum(G9.Quantity*G9.RationItemQuantity)
  401. FROM GLJList AS G9, ProjectGLJ AS P9
  402. WHERE (P9.Code=G9.Code) AND (G9.Type<>2) AND (P9.LibID=G9.LibID)
  403. )>0 )
  404. GROUP BY P.Code, P.Name, P.Unit, P.Type, P.LibID
  405. UNION ALL
  406. SELECT P1.Code AS ACode, P1.Name AS AName, P1.Unit AS AUnit,
  407. SUM(M1.RG*G1.Quantity*G1.RationItemQuantity) AS AAmount, P1.Type AS AType, P1.LibID
  408. FROM GLJList AS G1, MachinePrice AS M1, ProjectGLJ AS P1
  409. WHERE (P1.Code=3) AND (G1.Code=M1.Code) AND (P1.LibID=G1.LibID) AND
  410. ((SELECT SUM(M8.RG*G8.Quantity*G8.RationItemQuantity)
  411. FROM GLJList AS G8, MachinePrice AS M8, ProjectGLJ AS P8
  412. WHERE (P8.Code=3) AND (G8.Code=M8.Code) AND (P8.LibID=G8.LibID)
  413. )>0 )
  414. GROUP BY P1.Code, P1.Name, P1.Unit, P1.Type, P1.LibID
  415. UNION ALL
  416. SELECT P1.Code AS ACode, P1.Name AS AName, P1.Unit AS AUnit,
  417. SUM(M1.ZY*G1.Quantity*G1.RationItemQuantity) AS AAmount, P1.Type AS AType, P1.LibID
  418. FROM GLJList AS G1, MachinePrice AS M1, ProjectGLJ AS P1
  419. WHERE (P1.Code=263) AND (G1.Code=M1.Code) AND (P1.LibID=G1.LibID) AND
  420. ((SELECT SUM(M8.ZY*G8.Quantity*G8.RationItemQuantity)
  421. FROM GLJList AS G8, MachinePrice AS M8, ProjectGLJ AS P8
  422. WHERE (P8.Code=263) AND (G8.Code=M8.Code) AND (P8.LibID=G8.LibID)
  423. )>0 )
  424. GROUP BY P1.Code, P1.Name, P1.Unit, P1.Type, P1.LibID
  425. UNION ALL
  426. SELECT P1.Code AS ACode, P1.Name AS AName, P1.Unit AS AUnit,
  427. SUM(M1.QY*G1.Quantity*G1.RationItemQuantity) AS AAmount, P1.Type AS AType, P1.LibID
  428. FROM GLJList AS G1, MachinePrice AS M1, ProjectGLJ AS P1
  429. WHERE (P1.Code=264) AND (G1.Code=M1.Code) AND (P1.LibID=G1.LibID) AND
  430. ((SELECT SUM(M8.QY*G8.Quantity*G8.RationItemQuantity)
  431. FROM GLJList AS G8, MachinePrice AS M8, ProjectGLJ AS P8
  432. WHERE (P8.Code=264) AND (G8.Code=M8.Code) AND (P8.LibID=G8.LibID)
  433. )>0 )
  434. GROUP BY P1.Code, P1.Name, P1.Unit, P1.Type, P1.LibID
  435. UNION ALL
  436. SELECT P1.Code AS ACode, P1.Name AS AName, P1.Unit AS AUnit,
  437. SUM(M1.CY*G1.Quantity*G1.RationItemQuantity) AS AAmount, P1.Type AS AType, P1.LibID
  438. FROM GLJList AS G1, MachinePrice AS M1, ProjectGLJ AS P1
  439. WHERE (P1.Code=265) AND (G1.Code=M1.Code) AND (P1.LibID=G1.LibID) AND
  440. ((SELECT SUM(M8.CY*G8.Quantity*G8.RationItemQuantity)
  441. FROM GLJList AS G8, MachinePrice AS M8, ProjectGLJ AS P8
  442. WHERE (P8.Code=265) AND (G8.Code=M8.Code) AND (P8.LibID=G8.LibID)
  443. )>0 )
  444. GROUP BY P1.Code, P1.Name, P1.Unit, P1.Type, P1.LibID
  445. UNION ALL
  446. SELECT P1.Code AS ACode, P1.Name AS AName, P1.Unit AS AUnit,
  447. SUM(M1.Mei*G1.Quantity*G1.RationItemQuantity) AS AAmount, P1.Type AS AType, P1.LibID
  448. FROM GLJList AS G1, MachinePrice AS M1, ProjectGLJ AS P1
  449. WHERE (P1.Code=266) AND (G1.Code=M1.Code) AND (P1.LibID=G1.LibID) AND
  450. ((SELECT SUM(M8.Mei*G8.Quantity*G8.RationItemQuantity)
  451. FROM GLJList AS G8, MachinePrice AS M8, ProjectGLJ AS P8
  452. WHERE (P8.Code=266) AND (G8.Code=M8.Code) AND (P8.LibID=G8.LibID)
  453. )>0 )
  454. GROUP BY P1.Code, P1.Name, P1.Unit, P1.Type, P1.LibID
  455. UNION ALL
  456. SELECT P1.Code AS ACode, P1.Name AS AName, P1.Unit AS AUnit,
  457. SUM(M1.Dian*G1.Quantity*G1.RationItemQuantity) AS AAmount, P1.Type AS AType, P1.LibID
  458. FROM GLJList AS G1, MachinePrice AS M1, ProjectGLJ AS P1
  459. WHERE (P1.Code=267) AND (G1.Code=M1.Code) AND (P1.LibID=G1.LibID) AND
  460. ((SELECT SUM(M8.Dian*G8.Quantity*G8.RationItemQuantity)
  461. FROM GLJList AS G8, MachinePrice AS M8, ProjectGLJ AS P8
  462. WHERE (P8.Code=267) AND (G8.Code=M8.Code) AND (P8.LibID=G8.LibID)
  463. )>0 )
  464. GROUP BY P1.Code, P1.Name, P1.Unit, P1.Type, P1.LibID
  465. UNION ALL
  466. SELECT P1.Code AS ACode, P1.Name AS AName, P1.Unit AS AUnit,
  467. SUM(M1.Shui*G1.Quantity*G1.RationItemQuantity) AS AAmount, P1.Type AS AType, P1.LibID
  468. FROM GLJList AS G1, MachinePrice AS M1, ProjectGLJ AS P1
  469. WHERE (P1.Code=268) AND (G1.Code=M1.Code) AND (P1.LibID=G1.LibID) AND
  470. ((SELECT SUM(M8.Shui*G8.Quantity*G8.RationItemQuantity)
  471. FROM GLJList AS G8, MachinePrice AS M8, ProjectGLJ AS P8
  472. WHERE (P8.Code=268) AND (G8.Code=M8.Code) AND (P8.LibID=G8.LibID)
  473. )>0 )
  474. GROUP BY P1.Code, P1.Name, P1.Unit, P1.Type, P1.LibID
  475. UNION ALL
  476. SELECT P1.Code AS ACode, P1.Name AS AName, P1.Unit AS AUnit,
  477. SUM(M1.MC*G1.Quantity*G1.RationItemQuantity) AS AAmount, P1.Type AS AType, P1.LibID
  478. FROM GLJList AS G1, MachinePrice AS M1, ProjectGLJ AS P1
  479. WHERE (P1.Code=269) AND (G1.Code=M1.Code) AND (P1.LibID=G1.LibID) AND
  480. ((SELECT SUM(M8.MC*G8.Quantity*G8.RationItemQuantity)
  481. FROM GLJList AS G8, MachinePrice AS M8, ProjectGLJ AS P8
  482. WHERE (P8.Code=269) AND (G8.Code=M8.Code) AND (P8.LibID=G8.LibID)
  483. )>0 )
  484. GROUP BY P1.Code, P1.Name, P1.Unit, P1.Type, P1.LibID
  485. )
  486. GROUP BY ACode, AName, AUnit, AType
  487. }
  488. function TScProjGLJGather.GatherGLJ(ABuildProjName: string): Boolean;
  489. procedure AddGLJFieldDef(ABuildProj: TScProjectItem);
  490. var
  491. I: Integer;
  492. begin
  493. // *生成汇总造价文件的列表
  494. MakeProjList(ABuildProj);
  495. // *添加cdsGLJGatherD的需要的字段
  496. if cdsGLJGatherD.Active then
  497. cdsGLJGatherD.Active := False;
  498. cdsGLJGatherD.Fields.Clear;
  499. with cdsGLJGatherD.FieldDefs do
  500. begin
  501. Clear;
  502. //Add(gfID, ftInteger);
  503. Add(gfCodeSN, ftInteger);
  504. Add(gfCodeDis, ftString, 12);
  505. Add(gfName, ftString, 50);
  506. Add(gfUnits, ftString, 12);
  507. Add(gfSumAmount, ftFloat);
  508. Add(gfTenderSumAmount, ftFloat);
  509. //Add(gfSumAmount, ftString, 50);
  510. Add(gfType, ftInteger);
  511. for I := 0 to FProjects.Count - 1 do
  512. begin
  513. Add(gfAmountPreFix + IntToStr(I), ftFloat);
  514. //Add(gfAmountPreFix + IntToStr(I), ftString, 50);
  515. Add(gfBudgetPricePrefix + IntToStr(I), ftFloat);
  516. Add(gfSumPricePrefix + IntToStr(I), ftFloat);
  517. Add(gfMateFeePrefix + IntToStr(I), ftFloat);
  518. Add(gfBuildFeePrefix + IntToStr(I), ftFloat);
  519. Add(gfFileNamePrefix + IntToStr(I), ftString, 50);
  520. Add(gfMatePercentPrefix + IntToStr(I), ftFloat);
  521. Add(gfBuildPercentPrefix + IntToStr(I), ftFloat);
  522. // lengshumei 2011-2-10 重庆成渝复线加调价后字段
  523. Add(gfTenderAmountPreFix + IntToStr(I), ftFloat);
  524. Add(gfTenderPricePrefix + IntToStr(I), ftFloat);
  525. Add(gfTenderSumPricePrefix + IntToStr(I), ftFloat);
  526. Add(gfTenderMateFeePrefix + IntToStr(I), ftFloat);
  527. Add(gfTenderBuildFeePrefix + IntToStr(I), ftFloat);
  528. Add(gfTenderMatePercentPrefix + IntToStr(I), ftFloat);
  529. Add(gfTenderBuildPercentPrefix + IntToStr(I), ftFloat);
  530. end;
  531. Add(gfAvgBudgetPrice, ftFloat);
  532. Add(gfBuildSumPrice, ftFloat);
  533. Add(gfTenderAvgBudgetPrice, ftFloat);
  534. Add(gfTenderBuildSumPrice, ftFloat);
  535. end;
  536. end;
  537. function LocateMaterial(ACode, AName: string): Boolean;
  538. var
  539. CodeLocated, NameLocated: Boolean;
  540. CodeCode, NameCode: Integer;
  541. begin
  542. // 直接Locate无效,怪!!!
  543. {Result := cdsSourceProj.Locate(SCode + ';' + SName, VarArrayOf([ACode, AName]), []);
  544. if not Result then
  545. Result := cdsSourceProj.Locate(SName, AName, []);}
  546. // 换笨办法
  547. Result := False;
  548. CodeLocated := False;
  549. NameLocated := False;
  550. CodeCode := -1;
  551. NameCode := -1;
  552. // *从cds中locate ACode, AName材料
  553. cdsGLJGatherD.First;
  554. while not cdsGLJGatherD.Eof do
  555. begin
  556. //todo
  557. if SameText(cdsGLJGatherD.FieldValues['CodeDis'], ACode) then
  558. begin
  559. CodeLocated := True;
  560. CodeCode := cdsGLJGatherD.FieldValues['CodeDis'];
  561. end;
  562. if SameText(Trim(cdsGLJGatherD.FieldValues['Name']), Trim(AName)) then
  563. begin
  564. NameLocated := True;
  565. NameCode := cdsGLJGatherD.FieldValues['CodeDis'];
  566. end;
  567. if CodeLocated and NameLocated and (CodeCode = NameCode) then
  568. begin
  569. Result := True;
  570. Break;
  571. end;
  572. cdsGLJGatherD.Next;
  573. end;
  574. end;
  575. procedure AddGLJRecords;
  576. var
  577. L: Integer;
  578. //TempMateFee, TempBuildFee, TempSumPrice: Double;
  579. TempMateFee, TempBuildFee: Double;
  580. TempTenderMateFee, TempTenderBuildFee: Double;
  581. ProjData: TScProjBaseData;
  582. AmountFieldName, BudgetPriceFieldName, PriceFieldName, MatePercentFieldName,
  583. BuildPercentFieldName, MateFeeFieldName, BuildFeeFieldName, FileNameFieldName, TempFileName: string;
  584. TenderAmountFieldName, TenderBudgetPriceFieldName, TenderPriceFieldName, TenderMatePercentFieldName,
  585. TenderBuildPercentFieldName, TenderMateFeeFieldName, TenderBuildFeeFieldName: string;
  586. begin
  587. //cdsGLJGatherD.CreateDataSet;
  588. cdsGLJGatherD.Open;
  589. for L := 0 to FProjects.Count - 1 do
  590. begin
  591. AmountFieldName := gfAmountPrefix + IntToStr(L);
  592. BudgetPriceFieldName := gfBudgetPricePrefix + IntToStr(L);
  593. PriceFieldName := gfSumPricePrefix + IntToStr(L);
  594. MatePercentFieldName := gfMatePercentPrefix + IntToStr(L);
  595. BuildPercentFieldName := gfBuildPercentPrefix + IntToStr(L);
  596. MateFeeFieldName := gfMateFeePrefix + IntToStr(L);
  597. BuildFeeFieldName := gfBuildFeePrefix + IntToStr(L);
  598. FileNameFieldName := gfFileNamePrefix + IntToStr(L);
  599. // lengshumei 2011-2-10 重庆成渝复线加调价后字段
  600. TenderAmountFieldName := gfTenderAmountPrefix + IntToStr(L);
  601. TenderBudgetPriceFieldName := gfTenderPricePrefix + IntToStr(L);
  602. TenderPriceFieldName := gfTenderSumPricePrefix + IntToStr(L);
  603. TenderMatePercentFieldName := gfTenderMatePercentPrefix + IntToStr(L);
  604. TenderBuildPercentFieldName := gfTenderBuildPercentPrefix + IntToStr(L);
  605. TenderMateFeeFieldName := gfTenderMateFeePrefix + IntToStr(L);
  606. TenderBuildFeeFieldName := gfTenderBuildFeePrefix + IntToStr(L);
  607. //TempSumPrice := 0;
  608. // 前面AddFileDef已经判断了文件是否存在,这里不用再判断
  609. ProjData := FProjects[L];
  610. aqMateBuildFee.Close;
  611. aqMateBuildFee.Connection := ProjData.Connection.Connection;
  612. aqMateBuildFee.Open;
  613. aqMateBuildFee.First;
  614. TempMateFee := RoundTo(aqMateBuildFeeMateFee.AsFloat, 0);
  615. TempBuildFee := RoundTo(aqMateBuildFeeBuildFee.AsFloat, 0);
  616. TempFileName := aqMateBuildFeeFileName.AsString;
  617. TempTenderMateFee := RoundTo(aqMateBuildFeeTenderMateFee.AsFloat, 0);
  618. TempTenderBuildFee := RoundTo(aqMateBuildFeeTenderBuildFee.AsFloat, 0);
  619. ProjData.Open;
  620. aqProjGLJ.Close;
  621. aqProjGLJ.Connection := ProjData.Connection.Connection;
  622. aqProjGLJ.Open;
  623. aqProjGLJ.First;
  624. // *将第一个项目的材料放到cdsGLJGatherD中
  625. if L = 0 then
  626. begin
  627. while not aqProjGLJ.Eof do
  628. begin
  629. if ((aqProjGLJAType.AsInteger = 1) or (aqProjGLJAType.AsInteger = 3) or (aqProjGLJAType.AsInteger = 4))
  630. and (RoundTo(aqProjGLJUAmount.AsFloat, -3) <> 0) then
  631. begin
  632. cdsGLJGatherD.Append;
  633. cdsGLJGatherD.FieldByName('CodeSN').AsInteger := aqProjGLJACode.AsInteger;
  634. cdsGLJGatherD.FieldByName('CodeDis').AsString := aqProjGLJACode.AsString;
  635. cdsGLJGatherD.FieldByName('Name').AsString := aqProjGLJAName.AsString;
  636. cdsGLJGatherD.FieldByName('Units').AsString := aqProjGLJAUnit.AsString;
  637. cdsGLJGatherD.FieldByName('Type').AsInteger := aqProjGLJAType.AsInteger;
  638. cdsGLJGatherD.FieldByName(AmountFieldName).AsFloat := RoundTo(aqProjGLJUAmount.AsFloat, -3);
  639. cdsGLJGatherD.FieldByName(BudgetPriceFieldName).AsFloat := RoundTo(aqProjGLJPrice.AsFloat, -2);
  640. cdsGLJGatherD.FieldByName(PriceFieldName).AsFloat := RoundTo(aqProjGLJUAmount.AsFloat * aqProjGLJPrice.AsFloat, 0);
  641. cdsGLJGatherD.FieldByName(MateFeeFieldName).AsFloat := TempMateFee;
  642. cdsGLJGatherD.FieldByName(BuildFeeFieldName).AsFloat := TempBuildFee;
  643. cdsGLJGatherD.FieldByName(FileNameFieldName).AsString := TempFileName;
  644. cdsGLJGatherD.FieldByName(TenderAmountFieldName).AsFloat := RoundTo(aqProjGLJUTenderAmount.AsFloat, -3);
  645. cdsGLJGatherD.FieldByName(TenderBudgetPriceFieldName).AsFloat := RoundTo(aqProjGLJTenderPrice.AsFloat, -2);
  646. cdsGLJGatherD.FieldByName(TenderPriceFieldName).AsFloat := RoundTo(aqProjGLJUTenderAmount.AsFloat * aqProjGLJTenderPrice.AsFloat, 0);
  647. cdsGLJGatherD.FieldByName(TenderMateFeeFieldName).AsFloat := TempTenderMateFee;
  648. cdsGLJGatherD.FieldByName(TenderBuildFeeFieldName).AsFloat := TempTenderBuildFee;
  649. if TempMateFee = 0 then
  650. cdsGLJGatherD.FieldByName(MatePercentFieldName).AsFloat := 0
  651. else
  652. cdsGLJGatherD.FieldByName(MatePercentFieldName).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(PriceFieldName).AsFloat * 100/ TempMateFee, -2);
  653. if TempBuildFee = 0 then
  654. cdsGLJGatherD.FieldByName(BuildPercentFieldName).AsFloat := 0
  655. else
  656. cdsGLJGatherD.FieldByName(BuildPercentFieldName).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(PriceFieldName).AsFloat * 100/ TempBuildFee, -2);
  657. if TempTenderMateFee = 0 then
  658. cdsGLJGatherD.FieldByName(TenderMatePercentFieldName).AsFloat := 0
  659. else
  660. cdsGLJGatherD.FieldByName(TenderMatePercentFieldName).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(TenderPriceFieldName).AsFloat * 100/ TempTenderMateFee, -2);
  661. if TempTenderBuildFee = 0 then
  662. cdsGLJGatherD.FieldByName(TenderBuildPercentFieldName).AsFloat := 0
  663. else
  664. cdsGLJGatherD.FieldByName(TenderBuildPercentFieldName).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(TenderPriceFieldName).AsFloat * 100/ TempTenderBuildFee, -2);
  665. //TempSumPrice := TempSumPrice + cdscdsGLJGatherD.FieldByName(PriceFieldName).AsFloat;
  666. cdsGLJGatherD.Post;
  667. aqProjGLJ.Next;
  668. end
  669. else
  670. aqProjGLJ.Next;
  671. end;
  672. end
  673. else
  674. begin
  675. while not aqProjGLJ.Eof do
  676. begin
  677. if ((aqProjGLJAType.AsInteger = 1) or (aqProjGLJAType.AsInteger = 3) or (aqProjGLJAType.AsInteger = 4))
  678. and (RoundTo(aqProjGLJUAmount.AsFloat, -3) <> 0) then
  679. begin
  680. if LocateMaterial(aqProjGLJACode.AsString, aqProjGLJAName.AsString) then
  681. begin
  682. cdsGLJGatherD.Edit;
  683. cdsGLJGatherD.FieldByName(AmountFieldName).AsFloat := RoundTo(aqProjGLJUAmount.AsFloat, -3);
  684. cdsGLJGatherD.FieldByName(BudgetPriceFieldName).AsFloat := RoundTo(aqProjGLJPrice.AsFloat, -2);
  685. cdsGLJGatherD.FieldByName(PriceFieldName).AsFloat := RoundTo(aqProjGLJUAmount.AsFloat * aqProjGLJPrice.AsFloat, 0);
  686. cdsGLJGatherD.FieldByName(MateFeeFieldName).AsFloat := TempMateFee;
  687. cdsGLJGatherD.FieldByName(BuildFeeFieldName).AsFloat := TempBuildFee;
  688. cdsGLJGatherD.FieldByName(FileNameFieldName).AsString := TempFileName;
  689. cdsGLJGatherD.FieldByName(TenderAmountFieldName).AsFloat := RoundTo(aqProjGLJUTenderAmount.AsFloat, -3);
  690. cdsGLJGatherD.FieldByName(TenderBudgetPriceFieldName).AsFloat := RoundTo(aqProjGLJTenderPrice.AsFloat, -2);
  691. cdsGLJGatherD.FieldByName(TenderPriceFieldName).AsFloat := RoundTo(aqProjGLJUTenderAmount.AsFloat * aqProjGLJTenderPrice.AsFloat, 0);
  692. cdsGLJGatherD.FieldByName(TenderMateFeeFieldName).AsFloat := TempTenderMateFee;
  693. cdsGLJGatherD.FieldByName(TenderBuildFeeFieldName).AsFloat := TempTenderBuildFee;
  694. if TempMateFee = 0 then
  695. cdsGLJGatherD.FieldByName(MatePercentFieldName).AsFloat := 0
  696. else
  697. cdsGLJGatherD.FieldByName(MatePercentFieldName).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(PriceFieldName).AsFloat * 100/ TempMateFee, -2);
  698. if TempBuildFee = 0 then
  699. cdsGLJGatherD.FieldByName(BuildPercentFieldName).AsFloat := 0
  700. else
  701. cdsGLJGatherD.FieldByName(BuildPercentFieldName).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(PriceFieldName).AsFloat * 100/ TempBuildFee, -2);
  702. if TempTenderMateFee = 0 then
  703. cdsGLJGatherD.FieldByName(TenderMatePercentFieldName).AsFloat := 0
  704. else
  705. cdsGLJGatherD.FieldByName(TenderMatePercentFieldName).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(TenderPriceFieldName).AsFloat * 100/ TempTenderMateFee, -2);
  706. if TempTenderBuildFee = 0 then
  707. cdsGLJGatherD.FieldByName(BuildPercentFieldName).AsFloat := 0
  708. else
  709. cdsGLJGatherD.FieldByName(TenderBuildPercentFieldName).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(TenderPriceFieldName).AsFloat * 100/ TempTenderBuildFee, -2);
  710. cdsGLJGatherD.Post;
  711. aqProjGLJ.Next;
  712. end
  713. else
  714. // *前面项目中没有的材料
  715. begin
  716. cdsGLJGatherD.Append;
  717. cdsGLJGatherD.FieldByName('CodeSN').AsInteger := aqProjGLJACode.AsInteger;
  718. cdsGLJGatherD.FieldByName('CodeDis').AsString := aqProjGLJACode.AsString;
  719. cdsGLJGatherD.FieldByName('Name').AsString := aqProjGLJAName.AsString;
  720. cdsGLJGatherD.FieldByName('Units').AsString := aqProjGLJAUnit.AsString;
  721. cdsGLJGatherD.FieldByName('Type').AsInteger := aqProjGLJAType.AsInteger;
  722. cdsGLJGatherD.FieldByName(AmountFieldName).AsFloat := RoundTo(aqProjGLJUAmount.AsFloat, -3);
  723. cdsGLJGatherD.FieldByName(BudgetPriceFieldName).AsFloat := RoundTo(aqProjGLJPrice.AsFloat, -2);
  724. cdsGLJGatherD.FieldByName(PriceFieldName).AsFloat := RoundTo(aqProjGLJUAmount.AsFloat * aqProjGLJPrice.AsFloat, 0);
  725. cdsGLJGatherD.FieldByName(MateFeeFieldName).AsFloat := TempMateFee;
  726. cdsGLJGatherD.FieldByName(BuildFeeFieldName).AsFloat := TempBuildFee;
  727. cdsGLJGatherD.FieldByName(FileNameFieldName).AsString := TempFileName;
  728. cdsGLJGatherD.FieldByName(TenderAmountFieldName).AsFloat := RoundTo(aqProjGLJUTenderAmount.AsFloat, -3);
  729. cdsGLJGatherD.FieldByName(TenderBudgetPriceFieldName).AsFloat := RoundTo(aqProjGLJTenderPrice.AsFloat, -2);
  730. cdsGLJGatherD.FieldByName(TenderPriceFieldName).AsFloat := RoundTo(aqProjGLJUTenderAmount.AsFloat * aqProjGLJTenderPrice.AsFloat, 0);
  731. cdsGLJGatherD.FieldByName(TenderMateFeeFieldName).AsFloat := TempTenderMateFee;
  732. cdsGLJGatherD.FieldByName(TenderBuildFeeFieldName).AsFloat := TempTenderBuildFee;
  733. if TempMateFee = 0 then
  734. cdsGLJGatherD.FieldByName(MatePercentFieldName).AsFloat := 0
  735. else
  736. cdsGLJGatherD.FieldByName(MatePercentFieldName).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(PriceFieldName).AsFloat * 100/ TempMateFee, -2);
  737. if TempBuildFee = 0 then
  738. cdsGLJGatherD.FieldByName(BuildPercentFieldName).AsFloat := 0
  739. else
  740. cdsGLJGatherD.FieldByName(BuildPercentFieldName).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(PriceFieldName).AsFloat * 100/ TempBuildFee, -2);
  741. if TempTenderMateFee = 0 then
  742. cdsGLJGatherD.FieldByName(TenderMatePercentFieldName).AsFloat := 0
  743. else
  744. cdsGLJGatherD.FieldByName(TenderMatePercentFieldName).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(TenderPriceFieldName).AsFloat * 100/ TempTenderMateFee, -2);
  745. if TempTenderBuildFee = 0 then
  746. cdsGLJGatherD.FieldByName(TenderBuildPercentFieldName).AsFloat := 0
  747. else
  748. cdsGLJGatherD.FieldByName(TenderBuildPercentFieldName).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(TenderPriceFieldName).AsFloat * 100/ TempTenderBuildFee, -2);
  749. cdsGLJGatherD.Post;
  750. aqProjGLJ.Next;
  751. end;
  752. end
  753. else
  754. aqProjGLJ.Next;
  755. end;
  756. end;
  757. end;
  758. end;
  759. // *计算总数量 和 总金额 和平均预算价
  760. procedure CalcSumAmount;
  761. var
  762. I, J: Integer;
  763. AmountFieldName, PriceFieldName, MateFeeFieldName, BuildFeeFieldName,
  764. MatePercentFieldName, BuildPercentFieldName: string;
  765. TenderAmountFieldName, TenderPriceFieldName, TenderMateFeeFieldName, TenderBuildFeeFieldName,
  766. TenderMatePercentFieldName, TenderBuildPercentFieldName: string;
  767. TempMateFee, TempBuildFee, TempSumPrice: Double;
  768. TempTenderMateFee, TempTenderBuildFee, TempTenderSumPrice: Double;
  769. begin
  770. cdsGLJGatherD.Open;
  771. cdsGLJGatherD.First;
  772. while not cdsGLJGatherD.Eof do
  773. begin
  774. cdsGLJGatherD.Edit;
  775. cdsGLJGatherD.FieldByName('SumAmount').AsFloat := 0;
  776. // lengshumei 2010-12-1 重庆定制报表加字段
  777. cdsGLJGatherD.FieldByName(gfAvgBudgetPrice).AsFloat := 0;
  778. cdsGLJGatherD.FieldByName(gfBuildSumPrice).AsFloat := 0;
  779. cdsGLJGatherD.FieldByName(gfTenderAvgBudgetPrice).AsFloat := 0;
  780. cdsGLJGatherD.FieldByName(gfTenderBuildSumPrice).AsFloat := 0;
  781. for I := 0 to FProjects.Count - 1 do
  782. begin
  783. AmountFieldName := gfAmountPrefix + IntToStr(I);
  784. cdsGLJGatherD.FieldByName(gfSumAmount).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(gfSumAmount).AsFloat
  785. + cdsGLJGatherD.FieldByName(AmountFieldName).AsFloat, -3);
  786. cdsGLJGatherD.FieldByName(gfBuildSumPrice).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(gfBuildSumPrice).AsFloat
  787. + cdsGLJGatherD.FieldByName(gfSumPricePrefix + IntToStr(I)).AsFloat, -2);
  788. TenderAmountFieldName := gfTenderAmountPrefix + IntToStr(I);
  789. cdsGLJGatherD.FieldByName(gfTenderSumAmount).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(gfTenderSumAmount).AsFloat
  790. + cdsGLJGatherD.FieldByName(TenderAmountFieldName).AsFloat, -3);
  791. cdsGLJGatherD.FieldByName(gfTenderBuildSumPrice).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(gfTenderBuildSumPrice).AsFloat
  792. + cdsGLJGatherD.FieldByName(gfTenderSumPricePrefix + IntToStr(I)).AsFloat, -2);
  793. end;
  794. cdsGLJGatherD.FieldByName(gfAvgBudgetPrice).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(gfBuildSumPrice).AsFloat
  795. / cdsGLJGatherD.FieldByName(gfSumAmount).AsFloat, -2);
  796. if cdsGLJGatherD.FieldByName(gfTenderSumAmount).AsFloat = 0 then
  797. cdsGLJGatherD.FieldByName(gfTenderAvgBudgetPrice).AsFloat := 0
  798. else
  799. cdsGLJGatherD.FieldByName(gfTenderAvgBudgetPrice).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(gfTenderBuildSumPrice).AsFloat
  800. / cdsGLJGatherD.FieldByName(gfTenderSumAmount).AsFloat, -2);
  801. cdsGLJGatherD.Post;
  802. cdsGLJGatherD.Next;
  803. end;
  804. // 如果工料机总消耗量为0 ,则删除
  805. cdsGLJGatherD.First;
  806. while not cdsGLJGatherD.Eof do
  807. begin
  808. if cdsGLJGatherD.FieldByName(gfSumAmount).AsFloat = 0 then
  809. begin
  810. cdsGLJGatherD.Delete;
  811. Continue;
  812. end;
  813. cdsGLJGatherD.Next;
  814. end;
  815. (*
  816. // 计算并添加合计行
  817. for I := 0 to FProjects.Count - 1 do
  818. begin
  819. cdsGLJGatherD.First;
  820. TempMateFee := 0;
  821. TempBuildFee := 0;
  822. TempSumPrice := 0;
  823. PriceFieldName := gfSumPricePrefix + IntToStr(I);
  824. MateFeeFieldName := gfMateFeePrefix + IntToStr(I);
  825. BuildFeeFieldName := gfBuildFeePrefix + IntToStr(I);
  826. MatePercentFieldName := gfMatePercentPrefix + IntToStr(I);
  827. BuildPercentFieldName := gfBuildPercentPrefix + IntToStr(I);
  828. while not cdsGLJGatherD.Eof do
  829. begin
  830. if cdsGLJGatherD.FieldByName('Name').AsString <> '合计' then
  831. begin
  832. TempSumPrice := TempSumPrice + cdsGLJGatherD.FieldByName(PriceFieldName).AsFloat;
  833. TempMateFee := cdsGLJGatherD.FieldByName(MateFeeFieldName).AsFloat;
  834. if TempBuildFee = 0 then
  835. TempBuildFee := cdsGLJGatherD.FieldByName(BuildFeeFieldName).AsFloat;
  836. end;
  837. cdsGLJGatherD.Next;
  838. end;
  839. if I = 0 then
  840. begin
  841. cdsGLJGatherD.Append;
  842. cdsGLJGatherD.FieldByName('CodeSN').AsInteger := 999999999;
  843. cdsGLJGatherD.FieldByName('Name').AsString := '合计';
  844. cdsGLJGatherD.FieldByName('Type').AsInteger := 5;
  845. cdsGLJGatherD.FieldByName(PriceFieldName).AsFloat := RoundTo(TempSumPrice, 0);
  846. if TempMateFee = 0 then
  847. cdsGLJGatherD.FieldByName(MatePercentFieldName).AsFloat := 0
  848. else
  849. cdsGLJGatherD.FieldByName(MatePercentFieldName).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(PriceFieldName).AsFloat * 100/ TempMateFee, -2);
  850. if TempBuildFee = 0 then
  851. cdsGLJGatherD.FieldByName(BuildPercentFieldName).AsFloat := 0
  852. else
  853. cdsGLJGatherD.FieldByName(BuildPercentFieldName).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(PriceFieldName).AsFloat * 100/ TempBuildFee, -2);
  854. cdsGLJGatherD.Post;
  855. end
  856. else
  857. begin
  858. cdsGLJGatherD.First;
  859. while not cdsGLJGatherD.Eof do
  860. begin
  861. if cdsGLJGatherD.FieldByName('Name').AsString = '合计' then
  862. begin
  863. cdsGLJGatherD.Edit;
  864. cdsGLJGatherD.FieldByName(PriceFieldName).AsFloat := RoundTo(TempSumPrice, 0);
  865. if TempMateFee = 0 then
  866. cdsGLJGatherD.FieldByName(MatePercentFieldName).AsFloat := 0
  867. else
  868. cdsGLJGatherD.FieldByName(MatePercentFieldName).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(PriceFieldName).AsFloat * 100/ TempMateFee, -2);
  869. if TempBuildFee = 0 then
  870. cdsGLJGatherD.FieldByName(BuildPercentFieldName).AsFloat := 0
  871. else
  872. cdsGLJGatherD.FieldByName(BuildPercentFieldName).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(PriceFieldName).AsFloat * 100/ TempBuildFee, -2);
  873. cdsGLJGatherD.Post;
  874. end;
  875. cdsGLJGatherD.Next;
  876. end;
  877. end;
  878. end;*)
  879. end;
  880. begin
  881. Result := False;
  882. try
  883. // *如果已经初始化过,先清空cds
  884. if cdsGLJGatherD.Active then
  885. cdsGLJGatherD.EmptyDataSet;
  886. { if FBuildProj = nil then
  887. Exit;}
  888. FBuildProj := ProjectManager.FindBuildProject(ABuildProjName);
  889. // *添加cds中的字段
  890. AddGLJFieldDef(FBuildProj);
  891. cdsGLJGatherD.IndexName := '';
  892. cdsGLJGatherD.CreateDataSet;
  893. cdsGLJGatherD.IndexDefs.Clear;
  894. cdsGLJGatherD.AddIndex('idxSortByType', 'Type; CodeSN', [ixPrimary]);
  895. //cdsGLJGatherD.Active := True;
  896. cdsGLJGatherD.IndexName := 'idxSortByType';
  897. AddGLJRecords;
  898. CalcSumAmount;
  899. Result := True;
  900. finally
  901. cdsGLJGatherD.First;
  902. end;
  903. end;
  904. function TScProjGLJGather.GatherGLJForReport(
  905. ABuildProjName: string): Boolean;
  906. var
  907. ProjData: TScProjBaseData;
  908. procedure AddGLJFieldDef;
  909. begin
  910. // *添加cdsGLJGatherD的需要的字段
  911. if cdsGLJForReport.Active then
  912. cdsGLJForReport.Active := False;
  913. cdsGLJForReport.Fields.Clear;
  914. with cdsGLJForReport.FieldDefs do
  915. begin
  916. Clear;
  917. Add(gfCodeSN, ftInteger);
  918. Add(gfCodeDis, ftString, 12);
  919. Add(gfName, ftString, 50);
  920. Add(gfUnits, ftString, 12);
  921. Add(gfSumAmount, ftFloat);
  922. Add(gfType, ftInteger);
  923. Add(gfAmountPreFix, ftFloat);
  924. Add(gfBudgetPricePrefix, ftFloat);
  925. Add(gfSumPricePrefix, ftFloat);
  926. //Add(gfMateFeePrefix, ftFloat);
  927. //Add(gfBuildFeePrefix, ftFloat);
  928. //Add(gfFileNamePrefix, ftString, 50);
  929. Add(gfMatePercentPrefix, ftFloat);
  930. Add(gfBuildPercentPrefix, ftFloat);
  931. Add(gfProjectID, ftInteger);
  932. Add(gfProjectName, ftString, 50);
  933. // lengshumei 2010-12-1 重庆定制报表需加字段
  934. Add(gfAvgBudgetPrice, ftFloat);
  935. Add(gfBuildSumPrice, ftFloat);
  936. // lengshumei 2010-2-10 重庆成渝复线加调价后字段
  937. Add(gfTenderSumAmount, ftFloat);
  938. Add(gfTenderAmountPreFix, ftFloat);
  939. Add(gfTenderPricePrefix, ftFloat);
  940. Add(gfTenderSumPricePrefix, ftFloat);
  941. Add(gfTenderMatePercentPrefix, ftFloat);
  942. Add(gfTenderBuildPercentPrefix, ftFloat);
  943. Add(gfTenderAvgBudgetPrice, ftFloat);
  944. Add(gfTenderBuildSumPrice, ftFloat);
  945. end;
  946. cdsGLJForReport.IndexName := '';
  947. cdsGLJForReport.CreateDataSet;
  948. cdsGLJForReport.IndexDefs.Clear;
  949. cdsGLJForReport.AddIndex('idxSortBySN', gfCodeSN, []);
  950. cdsGLJForReport.Active := True;
  951. cdsGLJForReport.IndexName := 'idxSortBySN';
  952. end;
  953. procedure AddReportRecords;
  954. var
  955. I: Integer;
  956. ProjectID: Integer;
  957. ProjectName: string;
  958. begin
  959. cdsGLJForReport.EmptyDataSet;
  960. for I := 0 to FProjects.Count - 1 do
  961. begin
  962. ProjectID := I;
  963. ProjectName := {PProjChapterSum} TScProjBaseData(FProjects[I]).Alias;
  964. cdsGLJGatherD.First;
  965. while not cdsGLJGatherD.Eof do
  966. begin
  967. { if I = 0 then
  968. begin
  969. Node := FGatherTree.FindNode(cdsGLJGatherD.FieldByName(gfID).AsInteger);
  970. if Node <> nil then
  971. begin
  972. cdsGLJGatherD.Edit;
  973. cdsGLJGatherD.FieldByName(gfSerialNo).AsInteger := Node.MajorIndex;
  974. cdsGLJGatherD.Post;
  975. end;
  976. end;}
  977. cdsGLJForReport.Append;
  978. cdsGLJForReport.FieldByName(gfCodeSN).AsInteger := cdsGLJGatherD.FieldByName(gfCodeSN).AsInteger;
  979. cdsGLJForReport.FieldByName(gfCodeDis).AsString := cdsGLJGatherD.FieldByName(gfCodeDis).AsString;
  980. cdsGLJForReport.FieldByName(gfName).AsString := cdsGLJGatherD.FieldByName(gfName).AsString;
  981. cdsGLJForReport.FieldByName(gfUnits).AsString := cdsGLJGatherD.FieldByName(gfUnits).AsString;
  982. cdsGLJForReport.FieldByName(gfSumAmount).AsFloat := cdsGLJGatherD.FieldByName(gfSumAmount).AsFloat;
  983. cdsGLJForReport.FieldByName(gfType).AsInteger := cdsGLJGatherD.FieldByName(gfType).AsInteger;
  984. cdsGLJForReport.FieldByName(gfAmountPreFix).AsFloat := cdsGLJGatherD.FieldByName(gfAmountPreFix + IntToStr(I)).AsFloat;
  985. cdsGLJForReport.FieldByName(gfBudgetPricePrefix).AsFloat := cdsGLJGatherD.FieldByName(gfBudgetPricePrefix + IntToStr(I)).AsFloat;
  986. cdsGLJForReport.FieldByName(gfSumPricePrefix).AsFloat := cdsGLJGatherD.FieldByName(gfSumPricePrefix + IntToStr(I)).AsFloat;
  987. //cdsGLJForReport.FieldByName(gfMateFeePrefix).AsFloat := cdsGLJGatherD.FieldByName(gfMateFeePrefix + IntToStr(I)).AsFloat;
  988. //cdsGLJForReport.FieldByName(gfBuildFeePrefix).AsFloat := cdsGLJGatherD.FieldByName(gfBuildFeePrefix + IntToStr(I)).AsFloat;
  989. cdsGLJForReport.FieldByName(gfMatePercentPrefix).AsFloat := cdsGLJGatherD.FieldByName(gfMatePercentPrefix + IntToStr(I)).AsFloat;
  990. cdsGLJForReport.FieldByName(gfBuildPercentPrefix).AsFloat := cdsGLJGatherD.FieldByName(gfBuildPercentPrefix + IntToStr(I)).AsFloat;
  991. cdsGLJForReport.FieldByName(gfProjectID).AsInteger := I;
  992. // litao
  993. cdsGLJForReport.FieldByName(gfProjectName).AsString := ProjectName; //cdsGLJGatherD.FieldByName(gfFileNamePrefix + IntToStr(I)).AsString;
  994. // lengshumei 2010-12-1 重庆定制报表加字段
  995. cdsGLJForReport.FieldByName(gfAvgBudgetPrice).AsFloat := cdsGLJGatherD.FieldByName(gfAvgBudgetPrice).AsFloat;
  996. cdsGLJForReport.FieldByName(gfBuildSumPrice).AsFloat := cdsGLJGatherD.FieldByName(gfBuildSumPrice).AsFloat;
  997. // lengshumei 2010-2-10 重庆成渝复线加调价后字段
  998. cdsGLJForReport.FieldByName(gfTenderSumAmount).AsFloat := cdsGLJGatherD.FieldByName(gfTenderSumAmount).AsFloat;
  999. cdsGLJForReport.FieldByName(gfTenderAmountPreFix).AsFloat := cdsGLJGatherD.FieldByName(gfTenderAmountPreFix + IntToStr(I)).AsFloat;
  1000. cdsGLJForReport.FieldByName(gfTenderPricePrefix).AsFloat := cdsGLJGatherD.FieldByName(gfTenderPricePrefix + IntToStr(I)).AsFloat;
  1001. cdsGLJForReport.FieldByName(gfTenderSumPricePrefix).AsFloat := cdsGLJGatherD.FieldByName(gfTenderSumPricePrefix + IntToStr(I)).AsFloat;
  1002. cdsGLJForReport.FieldByName(gfTenderMatePercentPrefix).AsFloat := cdsGLJGatherD.FieldByName(gfTenderMatePercentPrefix + IntToStr(I)).AsFloat;
  1003. cdsGLJForReport.FieldByName(gfTenderBuildPercentPrefix).AsFloat := cdsGLJGatherD.FieldByName(gfTenderBuildPercentPrefix + IntToStr(I)).AsFloat;
  1004. cdsGLJForReport.FieldByName(gfTenderAvgBudgetPrice).AsFloat := cdsGLJGatherD.FieldByName(gfTenderAvgBudgetPrice).AsFloat;
  1005. cdsGLJForReport.FieldByName(gfTenderBuildSumPrice).AsFloat := cdsGLJGatherD.FieldByName(gfTenderBuildSumPrice).AsFloat;
  1006. cdsGLJForReport.Post;
  1007. cdsGLJGatherD.Next;
  1008. end;
  1009. end;
  1010. end;
  1011. begin
  1012. Result := GatherGLJ(ABuildProjName);
  1013. if Result then
  1014. begin
  1015. AddGLJFieldDef;
  1016. AddReportRecords;
  1017. cdsProjData.Active := True;
  1018. cdsProjData.EmptyDataSet;
  1019. cdsProjData.Append;
  1020. if FProjects.Count > 0 then
  1021. ProjData := ProjList.IndexByName(TScProjBaseData(FProjects[0]).FileName)
  1022. else
  1023. ProjData := nil;
  1024. if ProjData <> nil then
  1025. begin
  1026. cdsProjDataBuildProjName.Value := ProjData.BuildProjectName;
  1027. cdsProjDataAuthor.Value := ProjData.Author;
  1028. cdsProjDataAuditor.Value := ProjData.Auditor;
  1029. end
  1030. else
  1031. begin
  1032. cdsProjDataBuildProjName.Value := '';
  1033. cdsProjDataAuthor.Value := '';
  1034. cdsProjDataAuditor.Value := '';
  1035. end;
  1036. cdsProjData.Post;
  1037. cdsProjData.First;
  1038. end;
  1039. end;
  1040. end.