unit rmWeiWuZjjlGatherDm; interface uses SysUtils, Classes, ProjectData, DB, sdDB, DBClient; type TZjjl = class private FCode: string; FCertificateCode: string; FBGLCode: string; FPegName: string; FBeginPeg: string; FEndPeg: string; FFBFXName: string; FUnitName: string; FDrawingCode: string; FFormulaMemo: string; FRelaFile: string; FBillsCode: string; FBillsName: string; FBillsUnits: string; FBillsPrice: Double; FFilterDrawingCode: string; FBillsCurDealQuantity: Double; FBillsCurDealTotalPrice: Double; FBillsCurQcQuantity: Double; FBillsCurQcTotalPrice: Double; FBillsCurGatherQuantity: Double; FBillsCurGatherTotalPrice: Double; FBillsEndDealQuantity: Double; FBillsEndDealTotalPrice: Double; FBillsEndQcQuantity: Double; FBillsEndQcTotalPrice: Double; FBillsEndGatherQuantity: Double; FBillsEndGatherTotalPrice: Double; function MergeStr(AStr1, AStr2: string): string; public constructor Create(ARec, ABillsRec, AStageRec: TsdDataRecord); procedure Merge(ARec, ABillsRec, AStageRec: TsdDataRecord); end; TrmWeiWuZjjlGatherData = class(TDataModule) cdsZjjl: TClientDataSet; cdsZjjlCode: TWideStringField; cdsZjjlCertificateCode: TWideStringField; cdsZjjlBGLCode: TMemoField; cdsZjjlPegName: TWideStringField; cdsZjjlBeginPeg: TWideStringField; cdsZjjlEndPeg: TWideStringField; cdsZjjlFBFXName: TWideStringField; cdsZjjlUnitName: TWideStringField; cdsZjjlDrawingCode: TWideStringField; cdsZjjlFormulaMemo: TMemoField; cdsZjjlRelaFile: TMemoField; cdsZjjlBillsCode: TStringField; cdsZjjlBillsName: TWideStringField; cdsZjjlBillsUnits: TWideStringField; cdsZjjlBillsPrice: TFloatField; cdsZjjlFilterDrawingCode: TWideStringField; cdsZjjlBillsCurDealQuantity: TFloatField; cdsZjjlBillsCurDealTotalPrice: TFloatField; cdsZjjlBillsCurQcQuantity: TFloatField; cdsZjjlBillsCurQcTotalPrice: TFloatField; cdsZjjlBillsCurGatherQuantity: TFloatField; cdsZjjlBillsCurGatherTotalPrice: TFloatField; cdsZjjlBillsEndDealQuantity: TFloatField; cdsZjjlBillsEndDealTotalPrice: TFloatField; cdsZjjlBillsEndQcQuantity: TFloatField; cdsZjjlBillsEndQcTotalPrice: TFloatField; cdsZjjlBillsEndGatherQuantity: TFloatField; cdsZjjlBillsEndGatherTotalPrice: TFloatField; private FZjjlList: TList; function FindZjjl(ARec, ABillsRec: TsdDataRecord): TZjjl; procedure GatherZjjl(AProjectData: TProjectData); procedure WriteData; public function AssignData(AProjectData: TProjectData): TDataSet; end; implementation uses ZhAPI, PhaseData, UtilMethods; {$R *.dfm} function GetThirdPartString(const AStr: string; AFilter: Char = '-'): string; var sgs: TStringList; begin sgs := TStringList.Create; try sgs.Delimiter := AFilter; sgs.DelimitedText := AStr; while sgs.Count > 2 do sgs.Delete(sgs.Count - 1); Result := sgs.DelimitedText; finally sgs.Free; end; end; { TZjjl } constructor TZjjl.Create(ARec, ABillsRec, AStageRec: TsdDataRecord); begin FCode := ARec.ValueByName('Code').AsString; FCertificateCode := ARec.ValueByName('CertificateCode').AsString; FBGLCode := ARec.ValueByName('BGLCode').AsString; FPegName := ARec.ValueByName('PegName').AsString; FBeginPeg := ARec.ValueByName('BeginPeg').AsString; FEndPeg := ARec.ValueByName('EndPeg').AsString; FFBFXName := ARec.ValueByName('FBFXName').AsString; FUnitName := ARec.ValueByName('UnitName').AsString; FDrawingCode := ARec.ValueByName('DrawingCode').AsString; FFormulaMemo := ARec.ValueByName('FormulaMemo').AsString; FRelaFile := ARec.ValueByName('RelaFile').AsString; FBillsCode := ABillsRec.ValueByName('B_Code').AsString; FBillsName := ABillsRec.ValueByName('Name').AsString; FBillsUnits := ABillsRec.ValueByName('Units').AsString; FBillsPrice := ABillsRec.ValueByName('Price').AsFloat; FFilterDrawingCode := GetThirdPartString(ABillsRec.ValueByName('DrawingCode').AsString); if Assigned(AStageRec) then begin FBillsCurDealQuantity := AStageRec.ValueByName('DealQuantity').AsFloat; FBillsCurDealTotalPrice := AStageRec.ValueByName('DealTotalPrice').AsFloat; FBillsCurQcQuantity := AStageRec.ValueByName('QcQuantity').AsFloat; FBillsCurQcTotalPrice := AStageRec.ValueByName('QcTotalPrice').AsFloat; FBillsCurGatherQuantity := AStageRec.ValueByName('GatherQuantity').AsFloat; FBillsCurGatherTotalPrice := AStageRec.ValueByName('GatherTotalPrice').AsFloat; FBillsEndDealQuantity := AStageRec.ValueByName('DealQuantity').AsFloat; FBillsEndDealTotalPrice := AStageRec.ValueByName('DealTotalPrice').AsFloat; FBillsEndQcQuantity := AStageRec.ValueByName('QcQuantity').AsFloat; FBillsEndQcTotalPrice := AStageRec.ValueByName('QcTotalPrice').AsFloat; FBillsEndGatherQuantity := AStageRec.ValueByName('GatherQuantity').AsFloat; FBillsEndGatherTotalPrice := AStageRec.ValueByName('GatherTotalPrice').AsFloat; end; end; procedure TZjjl.Merge(ARec, ABillsRec, AStageRec: TsdDataRecord); begin FCertificateCode := MergeStr(FCertificateCode, ARec.ValueByName('CertificateCode').AsString); FBGLCode := MergeRelaBGL(FBGLCode, ARec.ValueByName('BGLCode').AsString); FDrawingCode := MergeStr(FDrawingCode, ARec.ValueByName('DrawingCode').AsString); FFormulaMemo := MergeStr(FFormulaMemo, ARec.ValueByName('FormulaMemo').AsString); FRelaFile := MergeStr(FRelaFile, ARec.ValueByName('RelaFile').AsString); if Assigned(AStageRec) then begin FBillsCurDealQuantity := FBillsCurDealQuantity + AStageRec.ValueByName('DealQuantity').AsFloat; FBillsCurDealTotalPrice := FBillsCurDealTotalPrice + AStageRec.ValueByName('DealTotalPrice').AsFloat; FBillsCurQcQuantity := FBillsCurQcQuantity + AStageRec.ValueByName('QcQuantity').AsFloat; FBillsCurQcTotalPrice := FBillsCurQcTotalPrice + AStageRec.ValueByName('QcTotalPrice').AsFloat; FBillsCurGatherQuantity := FBillsCurGatherQuantity + AStageRec.ValueByName('GatherQuantity').AsFloat; FBillsCurGatherTotalPrice := FBillsCurGatherTotalPrice + AStageRec.ValueByName('GatherTotalPrice').AsFloat; FBillsEndDealQuantity := FBillsEndDealQuantity + AStageRec.ValueByName('DealQuantity').AsFloat; FBillsEndDealTotalPrice := FBillsEndDealTotalPrice + AStageRec.ValueByName('DealTotalPrice').AsFloat; FBillsEndQcQuantity := FBillsEndQcQuantity + AStageRec.ValueByName('QcQuantity').AsFloat; FBillsEndQcTotalPrice := FBillsEndQcTotalPrice + AStageRec.ValueByName('QcTotalPrice').AsFloat; FBillsEndGatherQuantity := FBillsEndGatherQuantity + AStageRec.ValueByName('GatherQuantity').AsFloat; FBillsEndGatherTotalPrice := FBillsEndGatherTotalPrice + AStageRec.ValueByName('GatherTotalPrice').AsFloat; end; end; function TZjjl.MergeStr(AStr1, AStr2: string): string; begin if (AStr1 <> '') then begin if (AStr2 <> '') then Result := AStr1 + ';' + AStr2 else Result := AStr1; end else begin if (AStr2 <> '') then Result := AStr2 else Result := ''; end; end; { TrmWeiWuZjjlGatherData } function TrmWeiWuZjjlGatherData.AssignData( AProjectData: TProjectData): TDataSet; begin FZjjlList := TList.Create; try if AProjectData.PhaseData.Active then begin GatherZjjl(AProjectData); WriteData; end; Result := cdsZjjl; finally ClearObjects(FZjjlList); FZjjlList.Free; end; end; function TrmWeiWuZjjlGatherData.FindZjjl(ARec, ABillsRec: TsdDataRecord): TZjjl; var sCode, sName, sUnits, sDrawingCode: string; fPrice: Double; i: Integer; vZ: TZjjl; begin sCode := ABillsRec.ValueByName('B_Code').AsString; sName := ABillsRec.ValueByName('Name').AsString; sUnits := ABillsRec.ValueByName('Units').AsString; sDrawingCode := GetThirdPartString(ABillsRec.ValueByName('DrawingCode').AsString); fPrice := ABillsRec.valueByName('Price').AsFloat; Result := nil; for i := 0 to FZjjlList.Count - 1 do begin vZ := TZjjl(FZjjlList.Items[i]); if SameText(vZ.FBillsCode, sCode) and SameText(vZ.FBillsName, sName) and SameText(vZ.FBillsUnits, sUnits) and (PriceRoundTo(fPrice - vZ.FBillsPrice) < 0.00001) and SameText(sDrawingCode, vZ.FFilterDrawingCode) then begin Result := vZ; Break; end; end; end; procedure TrmWeiWuZjjlGatherData.GatherZjjl(AProjectData: TProjectData); var i: Integer; Rec, BillsRec, StageRec: TsdDataRecord; vZ: TZjjl; begin for i := 0 to AProjectData.PhaseData.ZJJLData.sddZJJL.RecordCount - 1 do begin Rec := AProjectData.PhaseData.ZJJLData.sddZJJL.Records[I]; BillsRec := AProjectData.BillsData.sddBills.FindKey('idxID', Rec.ValueByName('BillsID').AsInteger); StageRec := AProjectData.PhaseData.StageData.StageRecord(Rec.ValueByName('BillsID').AsInteger); if Assigned(Rec) and Assigned(BillsRec) then begin vZ := FindZjjl(Rec, BillsRec); if not Assigned(vZ) then begin vZ := TZjjl.Create(Rec, BillsRec, StageRec); FZjjlList.Add(vZ); end else vZ.Merge(Rec, BillsRec, StageRec); end; end; end; procedure TrmWeiWuZjjlGatherData.WriteData; var i: Integer; vZ: TZjjl; begin cdsZjjl.Active := True; cdsZjjl.EmptyDataSet; for i := 0 to FZjjlList.Count - 1 do begin vZ := TZjjl(FZjjlList.Items[i]); cdsZjjl.Append; cdsZjjlCode.AsString := vZ.FCode; cdsZjjlCertificateCode.AsString := vZ.FCertificateCode; cdsZjjlBGLCode.AsString := vZ.FBGLCode; cdsZjjlPegName.AsString := vZ.FPegName; cdsZjjlBeginPeg.AsString := vZ.FBeginPeg; cdsZjjlEndPeg.AsString := vZ.FEndPeg; cdsZjjlFBFXName.AsString := vZ.FFBFXName; cdsZjjlUnitName.AsString := vZ.FUnitName; cdsZjjlDrawingCode.AsString := vZ.FDrawingCode; cdsZjjlBillsCode.AsString := vZ.FBillsCode; cdsZjjlBillsName.AsString := vZ.FBillsName; cdsZjjlBillsUnits.AsString := vZ.FBillsUnits; cdsZjjlBillsPrice.AsFloat := vZ.FBillsPrice; cdsZjjlFilterDrawingCode.AsString := vZ.FFilterDrawingCode; cdsZjjlBillsCurDealQuantity.AsFloat := vZ.FBillsCurDealQuantity; cdsZjjlBillsCurDealTotalPrice.AsFloat := vZ.FBillsCurDealTotalPrice; cdsZjjlBillsCurQcQuantity.AsFloat := vZ.FBillsCurQcQuantity; cdsZjjlBillsCurQcTotalPrice.AsFloat := vZ.FBillsCurQcTotalPrice; cdsZjjlBillsCurGatherQuantity.AsFloat := vZ.FBillsCurGatherQuantity; cdsZjjlBillsCurGatherTotalPrice.AsFloat := vZ.FBillsCurGatherTotalPrice; cdsZjjlBillsEndDealQuantity.AsFloat := vZ.FBillsEndDealQuantity; cdsZjjlBillsEndDealTotalPrice.AsFloat := vZ.FBillsEndDealTotalPrice; cdsZjjlBillsEndQcQuantity.AsFloat := vZ.FBillsEndQcQuantity; cdsZjjlBillsEndQcTotalPrice.AsFloat := vZ.FBillsEndQcTotalPrice; cdsZjjlBillsEndGatherQuantity.AsFloat := vZ.FBillsEndGatherQuantity; cdsZjjlBillsEndGatherTotalPrice.AsFloat := vZ.FBillsEndGatherTotalPrice; cdsZjjl.Post; end; end; end.