| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141 |
- unit ScProjGLJGatherDM;
- interface
- uses
- Windows, SysUtils, Classes, ProjectsDM, ScProjBaseDM, ScProjList, DB, ADODB,
- DBClient;
- type
- TReportType = (rtNone, rtTable_02_1);
-
- TScProjGLJGather = class(TDataModule)
- cdsGLJGather: TClientDataSet;
- aqProjGLJ: TADOQuery;
- cdsProjData: TClientDataSet;
- cdsProjDataBuildProjName: TWideStringField;
- cdsProjDataAuthor: TWideStringField;
- cdsProjDataAuditor: TWideStringField;
- cdsGLJGatherCode: TIntegerField;
- cdsGLJGatherName: TStringField;
- cdsGLJGatherUnit: TStringField;
- cdsGLJGatherProjectName: TStringField;
- cdsGLJGatherAmount: TFloatField;
- cdsGLJGatherProjectID: TIntegerField;
- cdsGLJGatherLibID: TIntegerField;
- cdsGLJGatherType: TIntegerField;
- aqProjGLJACode: TIntegerField;
- aqProjGLJAName: TWideStringField;
- aqProjGLJAUnit: TWideStringField;
- aqProjGLJUAmount: TFloatField;
- aqProjGLJAType: TIntegerField;
- cdsGLJGatherSumAmount: TFloatField;
- cdsGLJGatherPrice: TCurrencyField;
- aqProjGLJPrice: TCurrencyField;
- cdsGLJGatherD: TClientDataSet;
- aqMateBuildFee: TADOQuery;
- aqMateBuildFeeMateFee: TBCDField;
- aqMateBuildFeeBuildFee: TFloatField;
- aqMateBuildFeeFileName: TStringField;
- cdsGLJForReport: TClientDataSet;
- aqMateBuildFeeTenderMateFee: TBCDField;
- aqMateBuildFeeTenderBuildFee: TFloatField;
- aqProjGLJUTenderAmount: TFloatField;
- aqProjGLJTenderPrice: TCurrencyField;
- procedure DataModuleCreate(Sender: TObject);
- procedure DataModuleDestroy(Sender: TObject);
- private
- { Private declarations }
- FProjects: TList;
- FReportType: TReportType;
- FSumAmountAgg: TAggregate;
- FBuildProj: TScProjectItem;
- procedure AddProjRecord(AConnection: TADOConnection; AProjID: Integer;
- AProjName: string);
- procedure CheckProjects(ABuildProjName: string);
- procedure DoSumAmount;
- procedure MakeProjList(ABuildProj: TScProjectItem);
- public
- { Public declarations }
- function GatherProjs(ABuildProjName: string): Boolean;
- function GatherGLJ(ABuildProjName: string): Boolean;
- function GatherGLJForReport(ABuildProjName: string): Boolean;
- property ReportType: TReportType read FReportType write FReportType;
- end;
- var
- ScProjGLJGather: TScProjGLJGather;
- implementation
- uses
- ScIDTree, ScUtils, Math, ScProjectsGather, ScSelectGatherForm, ScFileArchiver,
- ScConsts;
- {$R *.dfm}
- // 旧查询语句,从02表来,因条件变化,现在改成直接从ProjectGLJ中查询
- {SELECT ACode, AName, AUnit, Sum(AAmount) AS UAmount, AType
- FROM
- (
- SELECT P.Code AS ACode, P.Name AS AName, P.Unit AS AUnit,
- Sum(G.Quantity*G.RationItemQuantity) AS AAmount, P.Type AS AType, P.LibID
- FROM ProjectGLJ AS P, GLJList AS G
- WHERE (P.Code=G.Code) AND (G.Type<>2) AND (P.LibID=G.LibID) AND
- ((SELECT Sum(G9.Quantity*G9.RationItemQuantity)
- FROM GLJList AS G9, ProjectGLJ AS P9
- WHERE (P9.Code=G9.Code) AND (G9.Type<>2) AND (P9.LibID=G9.LibID)
- )>0 )
- GROUP BY P.Code, P.Name, P.Unit, P.Type, P.LibID
- UNION ALL
- SELECT P1.Code AS ACode, P1.Name AS AName, P1.Unit AS AUnit,
- SUM(M1.RG*G1.Quantity*G1.RationItemQuantity) AS AAmount, P1.Type AS AType, P1.LibID
- FROM GLJList AS G1, MachinePrice AS M1, ProjectGLJ AS P1
- WHERE (P1.Code=3) AND (G1.Code=M1.Code) AND (P1.LibID=G1.LibID) AND
- ((SELECT SUM(M8.RG*G8.Quantity*G8.RationItemQuantity)
- FROM GLJList AS G8, MachinePrice AS M8, ProjectGLJ AS P8
- WHERE (P8.Code=3) AND (G8.Code=M8.Code) AND (P8.LibID=G8.LibID)
- )>0 )
- GROUP BY P1.Code, P1.Name, P1.Unit, P1.Type, P1.LibID
- UNION ALL
- SELECT P1.Code AS ACode, P1.Name AS AName, P1.Unit AS AUnit,
- SUM(M1.ZY*G1.Quantity*G1.RationItemQuantity) AS AAmount, P1.Type AS AType, P1.LibID
- FROM GLJList AS G1, MachinePrice AS M1, ProjectGLJ AS P1
- WHERE (P1.Code=263) AND (G1.Code=M1.Code) AND (P1.LibID=G1.LibID) AND
- ((SELECT SUM(M8.ZY*G8.Quantity*G8.RationItemQuantity)
- FROM GLJList AS G8, MachinePrice AS M8, ProjectGLJ AS P8
- WHERE (P8.Code=263) AND (G8.Code=M8.Code) AND (P8.LibID=G8.LibID)
- )>0 )
- GROUP BY P1.Code, P1.Name, P1.Unit, P1.Type, P1.LibID
- UNION ALL
- SELECT P1.Code AS ACode, P1.Name AS AName, P1.Unit AS AUnit,
- SUM(M1.QY*G1.Quantity*G1.RationItemQuantity) AS AAmount, P1.Type AS AType, P1.LibID
- FROM GLJList AS G1, MachinePrice AS M1, ProjectGLJ AS P1
- WHERE (P1.Code=264) AND (G1.Code=M1.Code) AND (P1.LibID=G1.LibID) AND
- ((SELECT SUM(M8.QY*G8.Quantity*G8.RationItemQuantity)
- FROM GLJList AS G8, MachinePrice AS M8, ProjectGLJ AS P8
- WHERE (P8.Code=264) AND (G8.Code=M8.Code) AND (P8.LibID=G8.LibID)
- )>0 )
- GROUP BY P1.Code, P1.Name, P1.Unit, P1.Type, P1.LibID
- UNION ALL
- SELECT P1.Code AS ACode, P1.Name AS AName, P1.Unit AS AUnit,
- SUM(M1.CY*G1.Quantity*G1.RationItemQuantity) AS AAmount, P1.Type AS AType, P1.LibID
- FROM GLJList AS G1, MachinePrice AS M1, ProjectGLJ AS P1
- WHERE (P1.Code=265) AND (G1.Code=M1.Code) AND (P1.LibID=G1.LibID) AND
- ((SELECT SUM(M8.CY*G8.Quantity*G8.RationItemQuantity)
- FROM GLJList AS G8, MachinePrice AS M8, ProjectGLJ AS P8
- WHERE (P8.Code=265) AND (G8.Code=M8.Code) AND (P8.LibID=G8.LibID)
- )>0 )
- GROUP BY P1.Code, P1.Name, P1.Unit, P1.Type, P1.LibID
- UNION ALL
- SELECT P1.Code AS ACode, P1.Name AS AName, P1.Unit AS AUnit,
- SUM(M1.Mei*G1.Quantity*G1.RationItemQuantity) AS AAmount, P1.Type AS AType, P1.LibID
- FROM GLJList AS G1, MachinePrice AS M1, ProjectGLJ AS P1
- WHERE (P1.Code=266) AND (G1.Code=M1.Code) AND (P1.LibID=G1.LibID) AND
- ((SELECT SUM(M8.Mei*G8.Quantity*G8.RationItemQuantity)
- FROM GLJList AS G8, MachinePrice AS M8, ProjectGLJ AS P8
- WHERE (P8.Code=266) AND (G8.Code=M8.Code) AND (P8.LibID=G8.LibID)
- )>0 )
- GROUP BY P1.Code, P1.Name, P1.Unit, P1.Type, P1.LibID
- UNION ALL
- SELECT P1.Code AS ACode, P1.Name AS AName, P1.Unit AS AUnit,
- SUM(M1.Dian*G1.Quantity*G1.RationItemQuantity) AS AAmount, P1.Type AS AType, P1.LibID
- FROM GLJList AS G1, MachinePrice AS M1, ProjectGLJ AS P1
- WHERE (P1.Code=267) AND (G1.Code=M1.Code) AND (P1.LibID=G1.LibID) AND
- ((SELECT SUM(M8.Dian*G8.Quantity*G8.RationItemQuantity)
- FROM GLJList AS G8, MachinePrice AS M8, ProjectGLJ AS P8
- WHERE (P8.Code=267) AND (G8.Code=M8.Code) AND (P8.LibID=G8.LibID)
- )>0 )
- GROUP BY P1.Code, P1.Name, P1.Unit, P1.Type, P1.LibID
- UNION ALL
- SELECT P1.Code AS ACode, P1.Name AS AName, P1.Unit AS AUnit,
- SUM(M1.Shui*G1.Quantity*G1.RationItemQuantity) AS AAmount, P1.Type AS AType, P1.LibID
- FROM GLJList AS G1, MachinePrice AS M1, ProjectGLJ AS P1
- WHERE (P1.Code=268) AND (G1.Code=M1.Code) AND (P1.LibID=G1.LibID) AND
- ((SELECT SUM(M8.Shui*G8.Quantity*G8.RationItemQuantity)
- FROM GLJList AS G8, MachinePrice AS M8, ProjectGLJ AS P8
- WHERE (P8.Code=268) AND (G8.Code=M8.Code) AND (P8.LibID=G8.LibID)
- )>0 )
- GROUP BY P1.Code, P1.Name, P1.Unit, P1.Type, P1.LibID
- UNION ALL
- SELECT P1.Code AS ACode, P1.Name AS AName, P1.Unit AS AUnit,
- SUM(M1.MC*G1.Quantity*G1.RationItemQuantity) AS AAmount, P1.Type AS AType, P1.LibID
- FROM GLJList AS G1, MachinePrice AS M1, ProjectGLJ AS P1
- WHERE (P1.Code=269) AND (G1.Code=M1.Code) AND (P1.LibID=G1.LibID) AND
- ((SELECT SUM(M8.MC*G8.Quantity*G8.RationItemQuantity)
- FROM GLJList AS G8, MachinePrice AS M8, ProjectGLJ AS P8
- WHERE (P8.Code=269) AND (G8.Code=M8.Code) AND (P8.LibID=G8.LibID)
- )>0 )
- GROUP BY P1.Code, P1.Name, P1.Unit, P1.Type, P1.LibID
- )
- GROUP BY ACode, AName, AUnit, AType'}
- { TScProjGLJGather }
- procedure TScProjGLJGather.AddProjRecord(AConnection: TADOConnection;
- AProjID: Integer; AProjName: string);
- var
- fMachineAmount: Currency;
- bIsEstimate: Boolean;
- begin
- bIsEstimate := False;
- {$IFDEF _ScEstimate}
- bIsEstimate := True;
- {$ENDIF}
- fMachineAmount := 0;
- aqProjGLJ.Close;
- aqProjGLJ.Connection := AConnection;
- aqProjGLJ.Open;
- aqProjGLJ.First;
- while not aqProjGLJ.Eof do
- begin
- if aqProjGLJACode.AsInteger = SJiJiaCode then
- begin
- aqProjGLJ.Next;
- Continue;
- end;
- if bIsEstimate then
- begin
- if ((aqProjGLJACode.AsInteger <> 400) {$IFDEF _ScGanSu}and (aqProjGLJACode.AsInteger <> 998){$ENDIF}) and (aqProjGLJAType.AsInteger = 4) then
- begin
- // fMachineAmount := fMachineAmount + aqProjGLJUAmount.AsFloat * aqProjGLJPrice.AsCurrency;
- aqProjGLJ.Next;
- Continue;
- end;
- end;
- {如果是02—1表,并且是混凝土,则不添加。 李涛 2010.4.29}
- if (FReportType = rtNone) or
- ((FReportType = rtTable_02_1) and (aqProjGLJAType.AsInteger <> 2)) then
- begin
- cdsGLJGather.Append;
- cdsGLJGatherCode.AsInteger := aqProjGLJACode.AsInteger;
- cdsGLJGatherName.AsString := aqProjGLJAName.AsString;
- cdsGLJGatherUnit.AsString := aqProjGLJAUnit.AsString;
- cdsGLJGatherProjectName.AsString := AProjName;
- cdsGLJGatherPrice.AsCurrency := aqProjGLJPrice.AsCurrency;
- cdsGLJGatherAmount.AsFloat := aqProjGLJUAmount.AsFloat;
- cdsGLJGatherProjectID.AsInteger := AProjID;
- cdsGLJGatherLibID.AsInteger := 0;
- cdsGLJGatherType.AsInteger := aqProjGLJAType.AsInteger;
- cdsGLJGather.Post;
- end;
- aqProjGLJ.Next;
- end;
- { if bIsEstimate then
- begin
- if cdsGLJGather.Locate('Code', 400, []) then
- begin
- cdsGLJGather.Edit;
- cdsGLJGatherAmount.Value := cdsGLJGatherAmount.Value + fMachineAmount;
- cdsGLJGather.Post;
- end
- else
- begin
- cdsGLJGather.Append;
- cdsGLJGatherCode.AsInteger := 400;
- cdsGLJGatherName.AsString := '机械使用费';
- cdsGLJGatherUnit.AsString := '元';
- cdsGLJGatherProjectName.AsString := AProjName;
- cdsGLJGatherPrice.AsCurrency := 1;
- cdsGLJGatherAmount.Value := fMachineAmount;
- cdsGLJGatherProjectID.AsInteger := AProjID;
- cdsGLJGatherLibID.AsInteger := 0;
- cdsGLJGatherType.AsInteger := 3;
- cdsGLJGather.Post;
- end;
- end;}
- end;
- procedure TScProjGLJGather.MakeProjList(ABuildProj: TScProjectItem);
- var
- Proj: TScProjectItem;
- ProjData: TScProjBaseData;
- pProjSum: PProjChapterSum;
- I, BaseFile: Integer;
- vProjList: TList;
- begin
- vProjList := TList.Create;
- try
- FProjects.Clear;
- Proj := TScProjectItem(ABuildProj.FirstChild);
- while Assigned(Proj) do
- begin
- if FileExists(Proj.FileName) then
- begin
- if IsSmartCostProjectFile(Proj.FileName) then
- begin
- New(pProjSum);
- ZeroMemory(pProjSum, Sizeof(TProjChapterSum));
- pProjSum^.ID := Proj.ID;
- pProjSum^.Name := Proj.Name;
- pProjSum^.FileName := Proj.FileName;
- pProjSum^.Selected := Proj.Selected;
- vProjList.Add(pProjSum);
- end
- else
- MessageWarning(0,
- Format('所选建设项目中,项目文件[%s]不是有效的SmartCost预算项目文件。'#13#10 +
- '请进入“建设项目管理”进行管理。', [Proj.Name]));
- end
- else
- MessageWarning(0,
- Format('所选建设项目中,项目文件[%s]不存在。'#13#10 +
- '请进入“建设项目管理”重新查找该项目。', [Proj.Name]));
- Proj := TScProjectItem(Proj.NextSibling);
- end;
- // *汇总表类型
- if SelectProjects(vProjList, BaseFile) then
- for I := 0 to vProjList.Count - 1 do
- begin
- pProjSum := PProjChapterSum(vProjList[I]);
- if pProjSum^.Selected then
- begin
- ProjData := ProjList.IndexByName(pProjSum^.FileName);
- if ProjData = nil then
- ProjData := ProjList.AddProj(pProjSum^.FileName);
- ProjData.Open;
- FProjects.Add(ProjData);
- end;
- Dispose(pProjSum);
- end;
- finally
- vProjList.Free;
- end;
- end;
- procedure TScProjGLJGather.CheckProjects(ABuildProjName: string);
- var
- I: Integer;
- Proj: TScProjectItem;
- ProjData: TScProjBaseData;
- begin
- Proj := ProjectManager.FindBuildProject(ABuildProjName);
- MakeProjList(Proj);
- if FProjects.Count = 0 then Exit;
- ProjData := TScProjBaseData(FProjects[0]);
- if Proj <> nil then
- begin
- cdsProjData.Active := True;
- cdsProjData.EmptyDataSet;
- cdsProjData.Append;
- cdsProjDataBuildProjName.Value := ProjData.BuildProjectName;
- cdsProjDataAuthor.Value := ProjData.Author;
- cdsProjDataAuditor.Value := ProjData.Auditor;
- cdsProjData.Post;
- cdsProjData.First;
- end;
- { if (Proj <> nil) and (Proj.FirstChild <> nil) then
- begin
- Proj := TScProjectItem(Proj.FirstChild);
- while Proj <> nil do
- begin
- ProjData := ProjList.IndexByName(Proj.FileName);
- if ProjData = nil then
- ProjData := ProjList.AddProj(Proj.FileName);
- if not ProjData.IsOpened then
- ProjData.Open;
- if Proj.PrevSibling = nil then
- begin
- cdsProjData.Active := True;
- cdsProjData.EmptyDataSet;
- cdsProjData.Append;
- cdsProjDataBuildProjName.Value := ProjData.BuildProjectName;
- cdsProjDataAuthor.Value := ProjData.Author;
- cdsProjDataAuditor.Value := ProjData.Auditor;
- cdsProjData.Post;
- cdsProjData.First;
- end;
- FProjects.Add(ProjList.IndexByName(Proj.FileName));
- Proj := TScProjectItem(Proj.NextSibling);
- end;
- end;}
- end;
- function TScProjGLJGather.GatherProjs(ABuildProjName: string): Boolean;
- var
- I: Integer;
- begin
- cdsGLJGather.Open;
- cdsGLJGather.EmptyDataSet;
- cdsGLJGather.IndexName := 'cdsGLJGatherIdxCalc';
- try
- if ABuildProjName = '' then
- ABuildProjName := strUnTypeProj;
- CheckProjects(ABuildProjName);
- for I := 0 to FProjects.Count - 1 do
- begin
- AddProjRecord(TScProjBaseData(FProjects[I]).Connection.Connection, I,
- TScProjBaseData(FProjects[I]).Alias);
- end;
- DoSumAmount;
- finally
- cdsGLJGather.IndexName := 'cdsGLJGatherIdxSort';
- end;
- end;
- procedure TScProjGLJGather.DataModuleCreate(Sender: TObject);
- begin
- FProjects := TList.Create;
- FSumAmountAgg := cdsGLJGather.Aggregates.Add;
- FSumAmountAgg.Expression := 'Sum(Amount)';
- FSumAmountAgg.IndexName := 'cdsGLJGatherIdxCalc';
- FSumAmountAgg.GroupingLevel := 1;
- FSumAmountAgg.Active := True;
- FReportType := rtNone;
- end;
- procedure TScProjGLJGather.DataModuleDestroy(Sender: TObject);
- begin
- FProjects.Free;
- end;
- procedure TScProjGLJGather.DoSumAmount;
- begin
- cdsGLJGather.First;
- while not cdsGLJGather.Eof do
- begin
- // lsm 2010-1-21删除消耗为0的工料机
- if ScVarToFloat(FSumAmountAgg.Value) = 0 then
- cdsGLJGather.Delete
- else
- begin
- cdsGLJGather.Edit;
- cdsGLJGatherSumAmount.AsFloat := RoundTo(ScVarToFloat(FSumAmountAgg.Value), -3);
- cdsGLJGather.Post;
- cdsGLJGather.Next;
- end;
- end;
- end;
- {aqProjGLJ的SQL
- SELECT ACode, AName, AUnit, Sum(AAmount) AS UAmount, AType
- FROM
- (
- SELECT P.Code AS ACode, P.Name AS AName, P.Unit AS AUnit,
- Sum(G.Quantity*G.RationItemQuantity) AS AAmount, P.Type AS AType, P.LibID
- FROM ProjectGLJ AS P, GLJList AS G
- WHERE (P.Code=G.Code) AND (G.Type<>2) AND (P.LibID=G.LibID) AND
- ((SELECT Sum(G9.Quantity*G9.RationItemQuantity)
- FROM GLJList AS G9, ProjectGLJ AS P9
- WHERE (P9.Code=G9.Code) AND (G9.Type<>2) AND (P9.LibID=G9.LibID)
- )>0 )
- GROUP BY P.Code, P.Name, P.Unit, P.Type, P.LibID
- UNION ALL
- SELECT P1.Code AS ACode, P1.Name AS AName, P1.Unit AS AUnit,
- SUM(M1.RG*G1.Quantity*G1.RationItemQuantity) AS AAmount, P1.Type AS AType, P1.LibID
- FROM GLJList AS G1, MachinePrice AS M1, ProjectGLJ AS P1
- WHERE (P1.Code=3) AND (G1.Code=M1.Code) AND (P1.LibID=G1.LibID) AND
- ((SELECT SUM(M8.RG*G8.Quantity*G8.RationItemQuantity)
- FROM GLJList AS G8, MachinePrice AS M8, ProjectGLJ AS P8
- WHERE (P8.Code=3) AND (G8.Code=M8.Code) AND (P8.LibID=G8.LibID)
- )>0 )
- GROUP BY P1.Code, P1.Name, P1.Unit, P1.Type, P1.LibID
- UNION ALL
- SELECT P1.Code AS ACode, P1.Name AS AName, P1.Unit AS AUnit,
- SUM(M1.ZY*G1.Quantity*G1.RationItemQuantity) AS AAmount, P1.Type AS AType, P1.LibID
- FROM GLJList AS G1, MachinePrice AS M1, ProjectGLJ AS P1
- WHERE (P1.Code=263) AND (G1.Code=M1.Code) AND (P1.LibID=G1.LibID) AND
- ((SELECT SUM(M8.ZY*G8.Quantity*G8.RationItemQuantity)
- FROM GLJList AS G8, MachinePrice AS M8, ProjectGLJ AS P8
- WHERE (P8.Code=263) AND (G8.Code=M8.Code) AND (P8.LibID=G8.LibID)
- )>0 )
- GROUP BY P1.Code, P1.Name, P1.Unit, P1.Type, P1.LibID
- UNION ALL
- SELECT P1.Code AS ACode, P1.Name AS AName, P1.Unit AS AUnit,
- SUM(M1.QY*G1.Quantity*G1.RationItemQuantity) AS AAmount, P1.Type AS AType, P1.LibID
- FROM GLJList AS G1, MachinePrice AS M1, ProjectGLJ AS P1
- WHERE (P1.Code=264) AND (G1.Code=M1.Code) AND (P1.LibID=G1.LibID) AND
- ((SELECT SUM(M8.QY*G8.Quantity*G8.RationItemQuantity)
- FROM GLJList AS G8, MachinePrice AS M8, ProjectGLJ AS P8
- WHERE (P8.Code=264) AND (G8.Code=M8.Code) AND (P8.LibID=G8.LibID)
- )>0 )
- GROUP BY P1.Code, P1.Name, P1.Unit, P1.Type, P1.LibID
- UNION ALL
- SELECT P1.Code AS ACode, P1.Name AS AName, P1.Unit AS AUnit,
- SUM(M1.CY*G1.Quantity*G1.RationItemQuantity) AS AAmount, P1.Type AS AType, P1.LibID
- FROM GLJList AS G1, MachinePrice AS M1, ProjectGLJ AS P1
- WHERE (P1.Code=265) AND (G1.Code=M1.Code) AND (P1.LibID=G1.LibID) AND
- ((SELECT SUM(M8.CY*G8.Quantity*G8.RationItemQuantity)
- FROM GLJList AS G8, MachinePrice AS M8, ProjectGLJ AS P8
- WHERE (P8.Code=265) AND (G8.Code=M8.Code) AND (P8.LibID=G8.LibID)
- )>0 )
- GROUP BY P1.Code, P1.Name, P1.Unit, P1.Type, P1.LibID
- UNION ALL
-
- SELECT P1.Code AS ACode, P1.Name AS AName, P1.Unit AS AUnit,
- SUM(M1.Mei*G1.Quantity*G1.RationItemQuantity) AS AAmount, P1.Type AS AType, P1.LibID
- FROM GLJList AS G1, MachinePrice AS M1, ProjectGLJ AS P1
- WHERE (P1.Code=266) AND (G1.Code=M1.Code) AND (P1.LibID=G1.LibID) AND
- ((SELECT SUM(M8.Mei*G8.Quantity*G8.RationItemQuantity)
- FROM GLJList AS G8, MachinePrice AS M8, ProjectGLJ AS P8
- WHERE (P8.Code=266) AND (G8.Code=M8.Code) AND (P8.LibID=G8.LibID)
- )>0 )
- GROUP BY P1.Code, P1.Name, P1.Unit, P1.Type, P1.LibID
- UNION ALL
- SELECT P1.Code AS ACode, P1.Name AS AName, P1.Unit AS AUnit,
- SUM(M1.Dian*G1.Quantity*G1.RationItemQuantity) AS AAmount, P1.Type AS AType, P1.LibID
- FROM GLJList AS G1, MachinePrice AS M1, ProjectGLJ AS P1
- WHERE (P1.Code=267) AND (G1.Code=M1.Code) AND (P1.LibID=G1.LibID) AND
- ((SELECT SUM(M8.Dian*G8.Quantity*G8.RationItemQuantity)
- FROM GLJList AS G8, MachinePrice AS M8, ProjectGLJ AS P8
- WHERE (P8.Code=267) AND (G8.Code=M8.Code) AND (P8.LibID=G8.LibID)
- )>0 )
- GROUP BY P1.Code, P1.Name, P1.Unit, P1.Type, P1.LibID
- UNION ALL
- SELECT P1.Code AS ACode, P1.Name AS AName, P1.Unit AS AUnit,
- SUM(M1.Shui*G1.Quantity*G1.RationItemQuantity) AS AAmount, P1.Type AS AType, P1.LibID
- FROM GLJList AS G1, MachinePrice AS M1, ProjectGLJ AS P1
- WHERE (P1.Code=268) AND (G1.Code=M1.Code) AND (P1.LibID=G1.LibID) AND
- ((SELECT SUM(M8.Shui*G8.Quantity*G8.RationItemQuantity)
- FROM GLJList AS G8, MachinePrice AS M8, ProjectGLJ AS P8
- WHERE (P8.Code=268) AND (G8.Code=M8.Code) AND (P8.LibID=G8.LibID)
- )>0 )
- GROUP BY P1.Code, P1.Name, P1.Unit, P1.Type, P1.LibID
- UNION ALL
- SELECT P1.Code AS ACode, P1.Name AS AName, P1.Unit AS AUnit,
- SUM(M1.MC*G1.Quantity*G1.RationItemQuantity) AS AAmount, P1.Type AS AType, P1.LibID
- FROM GLJList AS G1, MachinePrice AS M1, ProjectGLJ AS P1
- WHERE (P1.Code=269) AND (G1.Code=M1.Code) AND (P1.LibID=G1.LibID) AND
- ((SELECT SUM(M8.MC*G8.Quantity*G8.RationItemQuantity)
- FROM GLJList AS G8, MachinePrice AS M8, ProjectGLJ AS P8
- WHERE (P8.Code=269) AND (G8.Code=M8.Code) AND (P8.LibID=G8.LibID)
- )>0 )
- GROUP BY P1.Code, P1.Name, P1.Unit, P1.Type, P1.LibID
- )
- GROUP BY ACode, AName, AUnit, AType
- }
- function TScProjGLJGather.GatherGLJ(ABuildProjName: string): Boolean;
- procedure AddGLJFieldDef(ABuildProj: TScProjectItem);
- var
- I: Integer;
- begin
- // *生成汇总造价文件的列表
- MakeProjList(ABuildProj);
- // *添加cdsGLJGatherD的需要的字段
- if cdsGLJGatherD.Active then
- cdsGLJGatherD.Active := False;
- cdsGLJGatherD.Fields.Clear;
- with cdsGLJGatherD.FieldDefs do
- begin
- Clear;
- //Add(gfID, ftInteger);
- Add(gfCodeSN, ftInteger);
- Add(gfCodeDis, ftString, 12);
- Add(gfName, ftString, 50);
- Add(gfUnits, ftString, 12);
- Add(gfSumAmount, ftFloat);
- Add(gfTenderSumAmount, ftFloat);
- //Add(gfSumAmount, ftString, 50);
- Add(gfType, ftInteger);
- for I := 0 to FProjects.Count - 1 do
- begin
- Add(gfAmountPreFix + IntToStr(I), ftFloat);
- //Add(gfAmountPreFix + IntToStr(I), ftString, 50);
- Add(gfBudgetPricePrefix + IntToStr(I), ftFloat);
- Add(gfSumPricePrefix + IntToStr(I), ftFloat);
- Add(gfMateFeePrefix + IntToStr(I), ftFloat);
- Add(gfBuildFeePrefix + IntToStr(I), ftFloat);
- Add(gfFileNamePrefix + IntToStr(I), ftString, 50);
- Add(gfMatePercentPrefix + IntToStr(I), ftFloat);
- Add(gfBuildPercentPrefix + IntToStr(I), ftFloat);
- // lengshumei 2011-2-10 重庆成渝复线加调价后字段
- Add(gfTenderAmountPreFix + IntToStr(I), ftFloat);
- Add(gfTenderPricePrefix + IntToStr(I), ftFloat);
- Add(gfTenderSumPricePrefix + IntToStr(I), ftFloat);
- Add(gfTenderMateFeePrefix + IntToStr(I), ftFloat);
- Add(gfTenderBuildFeePrefix + IntToStr(I), ftFloat);
- Add(gfTenderMatePercentPrefix + IntToStr(I), ftFloat);
- Add(gfTenderBuildPercentPrefix + IntToStr(I), ftFloat);
- end;
- Add(gfAvgBudgetPrice, ftFloat);
- Add(gfBuildSumPrice, ftFloat);
- Add(gfTenderAvgBudgetPrice, ftFloat);
- Add(gfTenderBuildSumPrice, ftFloat);
- end;
- end;
- function LocateMaterial(ACode, AName: string): Boolean;
- var
- CodeLocated, NameLocated: Boolean;
- CodeCode, NameCode: Integer;
- begin
- // 直接Locate无效,怪!!!
- {Result := cdsSourceProj.Locate(SCode + ';' + SName, VarArrayOf([ACode, AName]), []);
- if not Result then
- Result := cdsSourceProj.Locate(SName, AName, []);}
- // 换笨办法
- Result := False;
- CodeLocated := False;
- NameLocated := False;
- CodeCode := -1;
- NameCode := -1;
- // *从cds中locate ACode, AName材料
- cdsGLJGatherD.First;
- while not cdsGLJGatherD.Eof do
- begin
- //todo
- if SameText(cdsGLJGatherD.FieldValues['CodeDis'], ACode) then
- begin
- CodeLocated := True;
- CodeCode := cdsGLJGatherD.FieldValues['CodeDis'];
- end;
- if SameText(Trim(cdsGLJGatherD.FieldValues['Name']), Trim(AName)) then
- begin
- NameLocated := True;
- NameCode := cdsGLJGatherD.FieldValues['CodeDis'];
- end;
- if CodeLocated and NameLocated and (CodeCode = NameCode) then
- begin
- Result := True;
- Break;
- end;
- cdsGLJGatherD.Next;
- end;
- end;
- procedure AddGLJRecords;
- var
- L: Integer;
- //TempMateFee, TempBuildFee, TempSumPrice: Double;
- TempMateFee, TempBuildFee: Double;
- TempTenderMateFee, TempTenderBuildFee: Double;
- ProjData: TScProjBaseData;
- AmountFieldName, BudgetPriceFieldName, PriceFieldName, MatePercentFieldName,
- BuildPercentFieldName, MateFeeFieldName, BuildFeeFieldName, FileNameFieldName, TempFileName: string;
- TenderAmountFieldName, TenderBudgetPriceFieldName, TenderPriceFieldName, TenderMatePercentFieldName,
- TenderBuildPercentFieldName, TenderMateFeeFieldName, TenderBuildFeeFieldName: string;
- begin
- //cdsGLJGatherD.CreateDataSet;
- cdsGLJGatherD.Open;
- for L := 0 to FProjects.Count - 1 do
- begin
- AmountFieldName := gfAmountPrefix + IntToStr(L);
- BudgetPriceFieldName := gfBudgetPricePrefix + IntToStr(L);
- PriceFieldName := gfSumPricePrefix + IntToStr(L);
- MatePercentFieldName := gfMatePercentPrefix + IntToStr(L);
- BuildPercentFieldName := gfBuildPercentPrefix + IntToStr(L);
- MateFeeFieldName := gfMateFeePrefix + IntToStr(L);
- BuildFeeFieldName := gfBuildFeePrefix + IntToStr(L);
- FileNameFieldName := gfFileNamePrefix + IntToStr(L);
- // lengshumei 2011-2-10 重庆成渝复线加调价后字段
- TenderAmountFieldName := gfTenderAmountPrefix + IntToStr(L);
- TenderBudgetPriceFieldName := gfTenderPricePrefix + IntToStr(L);
- TenderPriceFieldName := gfTenderSumPricePrefix + IntToStr(L);
- TenderMatePercentFieldName := gfTenderMatePercentPrefix + IntToStr(L);
- TenderBuildPercentFieldName := gfTenderBuildPercentPrefix + IntToStr(L);
- TenderMateFeeFieldName := gfTenderMateFeePrefix + IntToStr(L);
- TenderBuildFeeFieldName := gfTenderBuildFeePrefix + IntToStr(L);
- //TempSumPrice := 0;
- // 前面AddFileDef已经判断了文件是否存在,这里不用再判断
- ProjData := FProjects[L];
- aqMateBuildFee.Close;
- aqMateBuildFee.Connection := ProjData.Connection.Connection;
- aqMateBuildFee.Open;
- aqMateBuildFee.First;
- TempMateFee := RoundTo(aqMateBuildFeeMateFee.AsFloat, 0);
- TempBuildFee := RoundTo(aqMateBuildFeeBuildFee.AsFloat, 0);
- TempFileName := aqMateBuildFeeFileName.AsString;
- TempTenderMateFee := RoundTo(aqMateBuildFeeTenderMateFee.AsFloat, 0);
- TempTenderBuildFee := RoundTo(aqMateBuildFeeTenderBuildFee.AsFloat, 0);
- ProjData.Open;
- aqProjGLJ.Close;
- aqProjGLJ.Connection := ProjData.Connection.Connection;
- aqProjGLJ.Open;
- aqProjGLJ.First;
- // *将第一个项目的材料放到cdsGLJGatherD中
- if L = 0 then
- begin
- while not aqProjGLJ.Eof do
- begin
- if ((aqProjGLJAType.AsInteger = 1) or (aqProjGLJAType.AsInteger = 3) or (aqProjGLJAType.AsInteger = 4))
- and (RoundTo(aqProjGLJUAmount.AsFloat, -3) <> 0) then
- begin
- cdsGLJGatherD.Append;
- cdsGLJGatherD.FieldByName('CodeSN').AsInteger := aqProjGLJACode.AsInteger;
- cdsGLJGatherD.FieldByName('CodeDis').AsString := aqProjGLJACode.AsString;
- cdsGLJGatherD.FieldByName('Name').AsString := aqProjGLJAName.AsString;
- cdsGLJGatherD.FieldByName('Units').AsString := aqProjGLJAUnit.AsString;
- cdsGLJGatherD.FieldByName('Type').AsInteger := aqProjGLJAType.AsInteger;
- cdsGLJGatherD.FieldByName(AmountFieldName).AsFloat := RoundTo(aqProjGLJUAmount.AsFloat, -3);
- cdsGLJGatherD.FieldByName(BudgetPriceFieldName).AsFloat := RoundTo(aqProjGLJPrice.AsFloat, -2);
- cdsGLJGatherD.FieldByName(PriceFieldName).AsFloat := RoundTo(aqProjGLJUAmount.AsFloat * aqProjGLJPrice.AsFloat, 0);
- cdsGLJGatherD.FieldByName(MateFeeFieldName).AsFloat := TempMateFee;
- cdsGLJGatherD.FieldByName(BuildFeeFieldName).AsFloat := TempBuildFee;
- cdsGLJGatherD.FieldByName(FileNameFieldName).AsString := TempFileName;
- cdsGLJGatherD.FieldByName(TenderAmountFieldName).AsFloat := RoundTo(aqProjGLJUTenderAmount.AsFloat, -3);
- cdsGLJGatherD.FieldByName(TenderBudgetPriceFieldName).AsFloat := RoundTo(aqProjGLJTenderPrice.AsFloat, -2);
- cdsGLJGatherD.FieldByName(TenderPriceFieldName).AsFloat := RoundTo(aqProjGLJUTenderAmount.AsFloat * aqProjGLJTenderPrice.AsFloat, 0);
- cdsGLJGatherD.FieldByName(TenderMateFeeFieldName).AsFloat := TempTenderMateFee;
- cdsGLJGatherD.FieldByName(TenderBuildFeeFieldName).AsFloat := TempTenderBuildFee;
- if TempMateFee = 0 then
- cdsGLJGatherD.FieldByName(MatePercentFieldName).AsFloat := 0
- else
- cdsGLJGatherD.FieldByName(MatePercentFieldName).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(PriceFieldName).AsFloat * 100/ TempMateFee, -2);
- if TempBuildFee = 0 then
- cdsGLJGatherD.FieldByName(BuildPercentFieldName).AsFloat := 0
- else
- cdsGLJGatherD.FieldByName(BuildPercentFieldName).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(PriceFieldName).AsFloat * 100/ TempBuildFee, -2);
- if TempTenderMateFee = 0 then
- cdsGLJGatherD.FieldByName(TenderMatePercentFieldName).AsFloat := 0
- else
- cdsGLJGatherD.FieldByName(TenderMatePercentFieldName).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(TenderPriceFieldName).AsFloat * 100/ TempTenderMateFee, -2);
- if TempTenderBuildFee = 0 then
- cdsGLJGatherD.FieldByName(TenderBuildPercentFieldName).AsFloat := 0
- else
- cdsGLJGatherD.FieldByName(TenderBuildPercentFieldName).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(TenderPriceFieldName).AsFloat * 100/ TempTenderBuildFee, -2);
- //TempSumPrice := TempSumPrice + cdscdsGLJGatherD.FieldByName(PriceFieldName).AsFloat;
- cdsGLJGatherD.Post;
- aqProjGLJ.Next;
- end
- else
- aqProjGLJ.Next;
- end;
- end
- else
- begin
- while not aqProjGLJ.Eof do
- begin
- if ((aqProjGLJAType.AsInteger = 1) or (aqProjGLJAType.AsInteger = 3) or (aqProjGLJAType.AsInteger = 4))
- and (RoundTo(aqProjGLJUAmount.AsFloat, -3) <> 0) then
- begin
- if LocateMaterial(aqProjGLJACode.AsString, aqProjGLJAName.AsString) then
- begin
- cdsGLJGatherD.Edit;
- cdsGLJGatherD.FieldByName(AmountFieldName).AsFloat := RoundTo(aqProjGLJUAmount.AsFloat, -3);
- cdsGLJGatherD.FieldByName(BudgetPriceFieldName).AsFloat := RoundTo(aqProjGLJPrice.AsFloat, -2);
- cdsGLJGatherD.FieldByName(PriceFieldName).AsFloat := RoundTo(aqProjGLJUAmount.AsFloat * aqProjGLJPrice.AsFloat, 0);
- cdsGLJGatherD.FieldByName(MateFeeFieldName).AsFloat := TempMateFee;
- cdsGLJGatherD.FieldByName(BuildFeeFieldName).AsFloat := TempBuildFee;
- cdsGLJGatherD.FieldByName(FileNameFieldName).AsString := TempFileName;
- cdsGLJGatherD.FieldByName(TenderAmountFieldName).AsFloat := RoundTo(aqProjGLJUTenderAmount.AsFloat, -3);
- cdsGLJGatherD.FieldByName(TenderBudgetPriceFieldName).AsFloat := RoundTo(aqProjGLJTenderPrice.AsFloat, -2);
- cdsGLJGatherD.FieldByName(TenderPriceFieldName).AsFloat := RoundTo(aqProjGLJUTenderAmount.AsFloat * aqProjGLJTenderPrice.AsFloat, 0);
- cdsGLJGatherD.FieldByName(TenderMateFeeFieldName).AsFloat := TempTenderMateFee;
- cdsGLJGatherD.FieldByName(TenderBuildFeeFieldName).AsFloat := TempTenderBuildFee;
- if TempMateFee = 0 then
- cdsGLJGatherD.FieldByName(MatePercentFieldName).AsFloat := 0
- else
- cdsGLJGatherD.FieldByName(MatePercentFieldName).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(PriceFieldName).AsFloat * 100/ TempMateFee, -2);
- if TempBuildFee = 0 then
- cdsGLJGatherD.FieldByName(BuildPercentFieldName).AsFloat := 0
- else
- cdsGLJGatherD.FieldByName(BuildPercentFieldName).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(PriceFieldName).AsFloat * 100/ TempBuildFee, -2);
- if TempTenderMateFee = 0 then
- cdsGLJGatherD.FieldByName(TenderMatePercentFieldName).AsFloat := 0
- else
- cdsGLJGatherD.FieldByName(TenderMatePercentFieldName).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(TenderPriceFieldName).AsFloat * 100/ TempTenderMateFee, -2);
- if TempTenderBuildFee = 0 then
- cdsGLJGatherD.FieldByName(BuildPercentFieldName).AsFloat := 0
- else
- cdsGLJGatherD.FieldByName(TenderBuildPercentFieldName).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(TenderPriceFieldName).AsFloat * 100/ TempTenderBuildFee, -2);
- cdsGLJGatherD.Post;
- aqProjGLJ.Next;
- end
- else
- // *前面项目中没有的材料
- begin
- cdsGLJGatherD.Append;
- cdsGLJGatherD.FieldByName('CodeSN').AsInteger := aqProjGLJACode.AsInteger;
- cdsGLJGatherD.FieldByName('CodeDis').AsString := aqProjGLJACode.AsString;
- cdsGLJGatherD.FieldByName('Name').AsString := aqProjGLJAName.AsString;
- cdsGLJGatherD.FieldByName('Units').AsString := aqProjGLJAUnit.AsString;
- cdsGLJGatherD.FieldByName('Type').AsInteger := aqProjGLJAType.AsInteger;
- cdsGLJGatherD.FieldByName(AmountFieldName).AsFloat := RoundTo(aqProjGLJUAmount.AsFloat, -3);
- cdsGLJGatherD.FieldByName(BudgetPriceFieldName).AsFloat := RoundTo(aqProjGLJPrice.AsFloat, -2);
- cdsGLJGatherD.FieldByName(PriceFieldName).AsFloat := RoundTo(aqProjGLJUAmount.AsFloat * aqProjGLJPrice.AsFloat, 0);
- cdsGLJGatherD.FieldByName(MateFeeFieldName).AsFloat := TempMateFee;
- cdsGLJGatherD.FieldByName(BuildFeeFieldName).AsFloat := TempBuildFee;
- cdsGLJGatherD.FieldByName(FileNameFieldName).AsString := TempFileName;
- cdsGLJGatherD.FieldByName(TenderAmountFieldName).AsFloat := RoundTo(aqProjGLJUTenderAmount.AsFloat, -3);
- cdsGLJGatherD.FieldByName(TenderBudgetPriceFieldName).AsFloat := RoundTo(aqProjGLJTenderPrice.AsFloat, -2);
- cdsGLJGatherD.FieldByName(TenderPriceFieldName).AsFloat := RoundTo(aqProjGLJUTenderAmount.AsFloat * aqProjGLJTenderPrice.AsFloat, 0);
- cdsGLJGatherD.FieldByName(TenderMateFeeFieldName).AsFloat := TempTenderMateFee;
- cdsGLJGatherD.FieldByName(TenderBuildFeeFieldName).AsFloat := TempTenderBuildFee;
- if TempMateFee = 0 then
- cdsGLJGatherD.FieldByName(MatePercentFieldName).AsFloat := 0
- else
- cdsGLJGatherD.FieldByName(MatePercentFieldName).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(PriceFieldName).AsFloat * 100/ TempMateFee, -2);
- if TempBuildFee = 0 then
- cdsGLJGatherD.FieldByName(BuildPercentFieldName).AsFloat := 0
- else
- cdsGLJGatherD.FieldByName(BuildPercentFieldName).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(PriceFieldName).AsFloat * 100/ TempBuildFee, -2);
- if TempTenderMateFee = 0 then
- cdsGLJGatherD.FieldByName(TenderMatePercentFieldName).AsFloat := 0
- else
- cdsGLJGatherD.FieldByName(TenderMatePercentFieldName).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(TenderPriceFieldName).AsFloat * 100/ TempTenderMateFee, -2);
- if TempTenderBuildFee = 0 then
- cdsGLJGatherD.FieldByName(TenderBuildPercentFieldName).AsFloat := 0
- else
- cdsGLJGatherD.FieldByName(TenderBuildPercentFieldName).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(TenderPriceFieldName).AsFloat * 100/ TempTenderBuildFee, -2);
- cdsGLJGatherD.Post;
- aqProjGLJ.Next;
- end;
- end
- else
- aqProjGLJ.Next;
- end;
- end;
- end;
- end;
- // *计算总数量 和 总金额 和平均预算价
- procedure CalcSumAmount;
- var
- I, J: Integer;
- AmountFieldName, PriceFieldName, MateFeeFieldName, BuildFeeFieldName,
- MatePercentFieldName, BuildPercentFieldName: string;
- TenderAmountFieldName, TenderPriceFieldName, TenderMateFeeFieldName, TenderBuildFeeFieldName,
- TenderMatePercentFieldName, TenderBuildPercentFieldName: string;
- TempMateFee, TempBuildFee, TempSumPrice: Double;
- TempTenderMateFee, TempTenderBuildFee, TempTenderSumPrice: Double;
- begin
- cdsGLJGatherD.Open;
- cdsGLJGatherD.First;
- while not cdsGLJGatherD.Eof do
- begin
- cdsGLJGatherD.Edit;
- cdsGLJGatherD.FieldByName('SumAmount').AsFloat := 0;
- // lengshumei 2010-12-1 重庆定制报表加字段
- cdsGLJGatherD.FieldByName(gfAvgBudgetPrice).AsFloat := 0;
- cdsGLJGatherD.FieldByName(gfBuildSumPrice).AsFloat := 0;
- cdsGLJGatherD.FieldByName(gfTenderAvgBudgetPrice).AsFloat := 0;
- cdsGLJGatherD.FieldByName(gfTenderBuildSumPrice).AsFloat := 0;
- for I := 0 to FProjects.Count - 1 do
- begin
- AmountFieldName := gfAmountPrefix + IntToStr(I);
- cdsGLJGatherD.FieldByName(gfSumAmount).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(gfSumAmount).AsFloat
- + cdsGLJGatherD.FieldByName(AmountFieldName).AsFloat, -3);
- cdsGLJGatherD.FieldByName(gfBuildSumPrice).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(gfBuildSumPrice).AsFloat
- + cdsGLJGatherD.FieldByName(gfSumPricePrefix + IntToStr(I)).AsFloat, -2);
- TenderAmountFieldName := gfTenderAmountPrefix + IntToStr(I);
- cdsGLJGatherD.FieldByName(gfTenderSumAmount).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(gfTenderSumAmount).AsFloat
- + cdsGLJGatherD.FieldByName(TenderAmountFieldName).AsFloat, -3);
- cdsGLJGatherD.FieldByName(gfTenderBuildSumPrice).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(gfTenderBuildSumPrice).AsFloat
- + cdsGLJGatherD.FieldByName(gfTenderSumPricePrefix + IntToStr(I)).AsFloat, -2);
- end;
- cdsGLJGatherD.FieldByName(gfAvgBudgetPrice).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(gfBuildSumPrice).AsFloat
- / cdsGLJGatherD.FieldByName(gfSumAmount).AsFloat, -2);
- if cdsGLJGatherD.FieldByName(gfTenderSumAmount).AsFloat = 0 then
- cdsGLJGatherD.FieldByName(gfTenderAvgBudgetPrice).AsFloat := 0
- else
- cdsGLJGatherD.FieldByName(gfTenderAvgBudgetPrice).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(gfTenderBuildSumPrice).AsFloat
- / cdsGLJGatherD.FieldByName(gfTenderSumAmount).AsFloat, -2);
- cdsGLJGatherD.Post;
- cdsGLJGatherD.Next;
- end;
- // 如果工料机总消耗量为0 ,则删除
- cdsGLJGatherD.First;
- while not cdsGLJGatherD.Eof do
- begin
- if cdsGLJGatherD.FieldByName(gfSumAmount).AsFloat = 0 then
- begin
- cdsGLJGatherD.Delete;
- Continue;
- end;
- cdsGLJGatherD.Next;
- end;
- (*
- // 计算并添加合计行
- for I := 0 to FProjects.Count - 1 do
- begin
- cdsGLJGatherD.First;
- TempMateFee := 0;
- TempBuildFee := 0;
- TempSumPrice := 0;
- PriceFieldName := gfSumPricePrefix + IntToStr(I);
- MateFeeFieldName := gfMateFeePrefix + IntToStr(I);
- BuildFeeFieldName := gfBuildFeePrefix + IntToStr(I);
- MatePercentFieldName := gfMatePercentPrefix + IntToStr(I);
- BuildPercentFieldName := gfBuildPercentPrefix + IntToStr(I);
- while not cdsGLJGatherD.Eof do
- begin
- if cdsGLJGatherD.FieldByName('Name').AsString <> '合计' then
- begin
- TempSumPrice := TempSumPrice + cdsGLJGatherD.FieldByName(PriceFieldName).AsFloat;
- TempMateFee := cdsGLJGatherD.FieldByName(MateFeeFieldName).AsFloat;
- if TempBuildFee = 0 then
- TempBuildFee := cdsGLJGatherD.FieldByName(BuildFeeFieldName).AsFloat;
- end;
- cdsGLJGatherD.Next;
- end;
- if I = 0 then
- begin
- cdsGLJGatherD.Append;
- cdsGLJGatherD.FieldByName('CodeSN').AsInteger := 999999999;
- cdsGLJGatherD.FieldByName('Name').AsString := '合计';
- cdsGLJGatherD.FieldByName('Type').AsInteger := 5;
- cdsGLJGatherD.FieldByName(PriceFieldName).AsFloat := RoundTo(TempSumPrice, 0);
- if TempMateFee = 0 then
- cdsGLJGatherD.FieldByName(MatePercentFieldName).AsFloat := 0
- else
- cdsGLJGatherD.FieldByName(MatePercentFieldName).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(PriceFieldName).AsFloat * 100/ TempMateFee, -2);
- if TempBuildFee = 0 then
- cdsGLJGatherD.FieldByName(BuildPercentFieldName).AsFloat := 0
- else
- cdsGLJGatherD.FieldByName(BuildPercentFieldName).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(PriceFieldName).AsFloat * 100/ TempBuildFee, -2);
- cdsGLJGatherD.Post;
- end
- else
- begin
- cdsGLJGatherD.First;
- while not cdsGLJGatherD.Eof do
- begin
- if cdsGLJGatherD.FieldByName('Name').AsString = '合计' then
- begin
- cdsGLJGatherD.Edit;
- cdsGLJGatherD.FieldByName(PriceFieldName).AsFloat := RoundTo(TempSumPrice, 0);
- if TempMateFee = 0 then
- cdsGLJGatherD.FieldByName(MatePercentFieldName).AsFloat := 0
- else
- cdsGLJGatherD.FieldByName(MatePercentFieldName).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(PriceFieldName).AsFloat * 100/ TempMateFee, -2);
- if TempBuildFee = 0 then
- cdsGLJGatherD.FieldByName(BuildPercentFieldName).AsFloat := 0
- else
- cdsGLJGatherD.FieldByName(BuildPercentFieldName).AsFloat := RoundTo(cdsGLJGatherD.FieldByName(PriceFieldName).AsFloat * 100/ TempBuildFee, -2);
- cdsGLJGatherD.Post;
- end;
- cdsGLJGatherD.Next;
- end;
- end;
- end;*)
- end;
- begin
- Result := False;
- try
- // *如果已经初始化过,先清空cds
- if cdsGLJGatherD.Active then
- cdsGLJGatherD.EmptyDataSet;
- { if FBuildProj = nil then
- Exit;}
- FBuildProj := ProjectManager.FindBuildProject(ABuildProjName);
- // *添加cds中的字段
- AddGLJFieldDef(FBuildProj);
- cdsGLJGatherD.IndexName := '';
- cdsGLJGatherD.CreateDataSet;
- cdsGLJGatherD.IndexDefs.Clear;
- cdsGLJGatherD.AddIndex('idxSortByType', 'Type; CodeSN', [ixPrimary]);
- //cdsGLJGatherD.Active := True;
- cdsGLJGatherD.IndexName := 'idxSortByType';
- AddGLJRecords;
- CalcSumAmount;
- Result := True;
- finally
- cdsGLJGatherD.First;
- end;
- end;
- function TScProjGLJGather.GatherGLJForReport(
- ABuildProjName: string): Boolean;
- var
- ProjData: TScProjBaseData;
- procedure AddGLJFieldDef;
- begin
- // *添加cdsGLJGatherD的需要的字段
- if cdsGLJForReport.Active then
- cdsGLJForReport.Active := False;
- cdsGLJForReport.Fields.Clear;
- with cdsGLJForReport.FieldDefs do
- begin
- Clear;
- Add(gfCodeSN, ftInteger);
- Add(gfCodeDis, ftString, 12);
- Add(gfName, ftString, 50);
- Add(gfUnits, ftString, 12);
- Add(gfSumAmount, ftFloat);
- Add(gfType, ftInteger);
- Add(gfAmountPreFix, ftFloat);
- Add(gfBudgetPricePrefix, ftFloat);
- Add(gfSumPricePrefix, ftFloat);
- //Add(gfMateFeePrefix, ftFloat);
- //Add(gfBuildFeePrefix, ftFloat);
- //Add(gfFileNamePrefix, ftString, 50);
- Add(gfMatePercentPrefix, ftFloat);
- Add(gfBuildPercentPrefix, ftFloat);
- Add(gfProjectID, ftInteger);
- Add(gfProjectName, ftString, 50);
- // lengshumei 2010-12-1 重庆定制报表需加字段
- Add(gfAvgBudgetPrice, ftFloat);
- Add(gfBuildSumPrice, ftFloat);
- // lengshumei 2010-2-10 重庆成渝复线加调价后字段
- Add(gfTenderSumAmount, ftFloat);
- Add(gfTenderAmountPreFix, ftFloat);
- Add(gfTenderPricePrefix, ftFloat);
- Add(gfTenderSumPricePrefix, ftFloat);
- Add(gfTenderMatePercentPrefix, ftFloat);
- Add(gfTenderBuildPercentPrefix, ftFloat);
- Add(gfTenderAvgBudgetPrice, ftFloat);
- Add(gfTenderBuildSumPrice, ftFloat);
- end;
- cdsGLJForReport.IndexName := '';
- cdsGLJForReport.CreateDataSet;
- cdsGLJForReport.IndexDefs.Clear;
- cdsGLJForReport.AddIndex('idxSortBySN', gfCodeSN, []);
- cdsGLJForReport.Active := True;
- cdsGLJForReport.IndexName := 'idxSortBySN';
- end;
- procedure AddReportRecords;
- var
- I: Integer;
- ProjectID: Integer;
- ProjectName: string;
- begin
- cdsGLJForReport.EmptyDataSet;
- for I := 0 to FProjects.Count - 1 do
- begin
- ProjectID := I;
- ProjectName := {PProjChapterSum} TScProjBaseData(FProjects[I]).Alias;
- cdsGLJGatherD.First;
- while not cdsGLJGatherD.Eof do
- begin
- { if I = 0 then
- begin
- Node := FGatherTree.FindNode(cdsGLJGatherD.FieldByName(gfID).AsInteger);
- if Node <> nil then
- begin
- cdsGLJGatherD.Edit;
- cdsGLJGatherD.FieldByName(gfSerialNo).AsInteger := Node.MajorIndex;
- cdsGLJGatherD.Post;
- end;
- end;}
- cdsGLJForReport.Append;
- cdsGLJForReport.FieldByName(gfCodeSN).AsInteger := cdsGLJGatherD.FieldByName(gfCodeSN).AsInteger;
- cdsGLJForReport.FieldByName(gfCodeDis).AsString := cdsGLJGatherD.FieldByName(gfCodeDis).AsString;
- cdsGLJForReport.FieldByName(gfName).AsString := cdsGLJGatherD.FieldByName(gfName).AsString;
- cdsGLJForReport.FieldByName(gfUnits).AsString := cdsGLJGatherD.FieldByName(gfUnits).AsString;
- cdsGLJForReport.FieldByName(gfSumAmount).AsFloat := cdsGLJGatherD.FieldByName(gfSumAmount).AsFloat;
- cdsGLJForReport.FieldByName(gfType).AsInteger := cdsGLJGatherD.FieldByName(gfType).AsInteger;
- cdsGLJForReport.FieldByName(gfAmountPreFix).AsFloat := cdsGLJGatherD.FieldByName(gfAmountPreFix + IntToStr(I)).AsFloat;
- cdsGLJForReport.FieldByName(gfBudgetPricePrefix).AsFloat := cdsGLJGatherD.FieldByName(gfBudgetPricePrefix + IntToStr(I)).AsFloat;
- cdsGLJForReport.FieldByName(gfSumPricePrefix).AsFloat := cdsGLJGatherD.FieldByName(gfSumPricePrefix + IntToStr(I)).AsFloat;
- //cdsGLJForReport.FieldByName(gfMateFeePrefix).AsFloat := cdsGLJGatherD.FieldByName(gfMateFeePrefix + IntToStr(I)).AsFloat;
- //cdsGLJForReport.FieldByName(gfBuildFeePrefix).AsFloat := cdsGLJGatherD.FieldByName(gfBuildFeePrefix + IntToStr(I)).AsFloat;
- cdsGLJForReport.FieldByName(gfMatePercentPrefix).AsFloat := cdsGLJGatherD.FieldByName(gfMatePercentPrefix + IntToStr(I)).AsFloat;
- cdsGLJForReport.FieldByName(gfBuildPercentPrefix).AsFloat := cdsGLJGatherD.FieldByName(gfBuildPercentPrefix + IntToStr(I)).AsFloat;
- cdsGLJForReport.FieldByName(gfProjectID).AsInteger := I;
- // litao
- cdsGLJForReport.FieldByName(gfProjectName).AsString := ProjectName; //cdsGLJGatherD.FieldByName(gfFileNamePrefix + IntToStr(I)).AsString;
- // lengshumei 2010-12-1 重庆定制报表加字段
- cdsGLJForReport.FieldByName(gfAvgBudgetPrice).AsFloat := cdsGLJGatherD.FieldByName(gfAvgBudgetPrice).AsFloat;
- cdsGLJForReport.FieldByName(gfBuildSumPrice).AsFloat := cdsGLJGatherD.FieldByName(gfBuildSumPrice).AsFloat;
- // lengshumei 2010-2-10 重庆成渝复线加调价后字段
- cdsGLJForReport.FieldByName(gfTenderSumAmount).AsFloat := cdsGLJGatherD.FieldByName(gfTenderSumAmount).AsFloat;
- cdsGLJForReport.FieldByName(gfTenderAmountPreFix).AsFloat := cdsGLJGatherD.FieldByName(gfTenderAmountPreFix + IntToStr(I)).AsFloat;
- cdsGLJForReport.FieldByName(gfTenderPricePrefix).AsFloat := cdsGLJGatherD.FieldByName(gfTenderPricePrefix + IntToStr(I)).AsFloat;
- cdsGLJForReport.FieldByName(gfTenderSumPricePrefix).AsFloat := cdsGLJGatherD.FieldByName(gfTenderSumPricePrefix + IntToStr(I)).AsFloat;
- cdsGLJForReport.FieldByName(gfTenderMatePercentPrefix).AsFloat := cdsGLJGatherD.FieldByName(gfTenderMatePercentPrefix + IntToStr(I)).AsFloat;
- cdsGLJForReport.FieldByName(gfTenderBuildPercentPrefix).AsFloat := cdsGLJGatherD.FieldByName(gfTenderBuildPercentPrefix + IntToStr(I)).AsFloat;
- cdsGLJForReport.FieldByName(gfTenderAvgBudgetPrice).AsFloat := cdsGLJGatherD.FieldByName(gfTenderAvgBudgetPrice).AsFloat;
- cdsGLJForReport.FieldByName(gfTenderBuildSumPrice).AsFloat := cdsGLJGatherD.FieldByName(gfTenderBuildSumPrice).AsFloat;
- cdsGLJForReport.Post;
- cdsGLJGatherD.Next;
- end;
- end;
- end;
- begin
- Result := GatherGLJ(ABuildProjName);
- if Result then
- begin
- AddGLJFieldDef;
- AddReportRecords;
- cdsProjData.Active := True;
- cdsProjData.EmptyDataSet;
- cdsProjData.Append;
- if FProjects.Count > 0 then
- ProjData := ProjList.IndexByName(TScProjBaseData(FProjects[0]).FileName)
- else
- ProjData := nil;
- if ProjData <> nil then
- begin
- cdsProjDataBuildProjName.Value := ProjData.BuildProjectName;
- cdsProjDataAuthor.Value := ProjData.Author;
- cdsProjDataAuditor.Value := ProjData.Auditor;
- end
- else
- begin
- cdsProjDataBuildProjName.Value := '';
- cdsProjDataAuthor.Value := '';
- cdsProjDataAuditor.Value := '';
- end;
- cdsProjData.Post;
- cdsProjData.First;
- end;
- end;
- end.
|