|
@@ -0,0 +1,776 @@
|
|
|
|
+unit GclBillsGatherModel;
|
|
|
|
+// 单项目的工程量清单汇总
|
|
|
|
+
|
|
|
|
+interface
|
|
|
|
+
|
|
|
|
+uses
|
|
|
|
+ Classes, mDataRecord, BillsTree;
|
|
|
|
+
|
|
|
|
+type
|
|
|
|
+ TGatherDataWriteEvent = procedure (AGLJs: TList) of object;
|
|
|
|
+
|
|
|
|
+ TDetailGclNode = class
|
|
|
|
+ private
|
|
|
|
+ FID: Integer;
|
|
|
|
+ FBillsID: Integer;
|
|
|
|
+ FTreeSerialNo: Integer;
|
|
|
|
+
|
|
|
|
+ FLeafXmjID: Integer;
|
|
|
|
+ FXmjCode: string;
|
|
|
|
+ FXmjName: string;
|
|
|
|
+ FXmjUnits: string;
|
|
|
|
+ FPeg: string;
|
|
|
|
+ FNameDanWei: string;
|
|
|
|
+ FNameFenBu: string;
|
|
|
|
+ FNameFenXiang: string;
|
|
|
|
+ FNameUnit: string;
|
|
|
|
+ FPosition: string;
|
|
|
|
+ FDrawingCode: string;
|
|
|
|
+
|
|
|
|
+ FQuantity: Double;
|
|
|
|
+ FTotalPrice: Double;
|
|
|
|
+
|
|
|
|
+ FCurDealQuantity: Double;
|
|
|
|
+ FCurDealTotalPrice: Double;
|
|
|
|
+ FCurQcQuantity: Double;
|
|
|
|
+ FCurQcTotalPrice: Double;
|
|
|
|
+ FCurGatherQuantity: Double;
|
|
|
|
+ FCurGatherTotalPrice: Double;
|
|
|
|
+
|
|
|
|
+ FPreDealQuantity: Double;
|
|
|
|
+ FPreDealTotalPrice: Double;
|
|
|
|
+ FPreQcQuantity: Double;
|
|
|
|
+ FPreQcTotalPrice: Double;
|
|
|
|
+ FPreGatherQuantity: Double;
|
|
|
|
+ FPreGatherTotalPrice: Double;
|
|
|
|
+ public
|
|
|
|
+ constructor Create(AID: Integer);
|
|
|
|
+
|
|
|
|
+ procedure AddPosData(ALeafXmj, APeg: TBillsIDTreeNode);
|
|
|
|
+
|
|
|
|
+ property ID: Integer read FID;
|
|
|
|
+ property BillsID: Integer read FBillsID write FBillsID;
|
|
|
|
+ property TreeSerialNo: Integer read FTreeSerialNo write FTreeSerialNo;
|
|
|
|
+
|
|
|
|
+ property LeafXmjID: Integer read FLeafXmjID;
|
|
|
|
+ property XmjCode: string read FXmjCode;
|
|
|
|
+ property XmjName: string read FXmjName;
|
|
|
|
+ property XmjUnits: string read FXmjUnits;
|
|
|
|
+ property Peg: string read FPeg;
|
|
|
|
+ property NameDanWei: string read FNameDanWei;
|
|
|
|
+ property NameFenBu: string read FNameFenBu;
|
|
|
|
+ property NameFenXiang: string read FNameFenXiang;
|
|
|
|
+ property NameUnit: string read FNameUnit;
|
|
|
|
+ property Position: string read FPosition;
|
|
|
|
+ property DrawingCode: string read FDrawingCode;
|
|
|
|
+
|
|
|
|
+ property Quantity: Double read FQuantity write FQuantity;
|
|
|
|
+ property TotalPrice: Double read FTotalPrice write FTotalPrice;
|
|
|
|
+
|
|
|
|
+ property CurDealQuantity: Double read FCurDealQuantity write FCurDealQuantity;
|
|
|
|
+ property CurDealTotalPrice: Double read FCurDealTotalPrice write FCurDealTotalPrice;
|
|
|
|
+ property CurQcQuantity: Double read FCurQcQuantity write FCurQcQuantity;
|
|
|
|
+ property CurQcTotalPrice: Double read FCurQcTotalPrice write FCurQcTotalPrice;
|
|
|
|
+ property CurGatherQuantity: Double read FCurGatherQuantity write FCurGatherQuantity;
|
|
|
|
+ property CurGatherTotalPrice: Double read FCurGatherTotalPrice write FCurGatherTotalPrice;
|
|
|
|
+
|
|
|
|
+ property PreDealQuantity: Double read FPreDealQuantity write FPreDealQuantity;
|
|
|
|
+ property PreDealTotalPrice: Double read FPreGatherTotalPrice write FPreGatherTotalPrice;
|
|
|
|
+ property PreQcQuantity: Double read FPreQcQuantity write FPreQcQuantity;
|
|
|
|
+ property PreQcTotalPrice: Double read FPreQcTotalPrice write FPreQcTotalPrice;
|
|
|
|
+ property PreGatherQuantity: Double read FPreGatherQuantity write FPreGatherQuantity;
|
|
|
|
+ property PreGatherTotalPrice: Double read FPreGatherTotalPrice write FPreGatherTotalPrice;
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+ TDetailDealNode = class
|
|
|
|
+ private
|
|
|
|
+ FID: Integer;
|
|
|
|
+ FDealID: Integer;
|
|
|
|
+
|
|
|
|
+ FQuantity: Double;
|
|
|
|
+ FTotalPrice: Double;
|
|
|
|
+ public
|
|
|
|
+ constructor Create(AID: Integer);
|
|
|
|
+
|
|
|
|
+ property ID: Integer read FID;
|
|
|
|
+ property DealID: Integer read FDealID write FDealID;
|
|
|
|
+
|
|
|
|
+ property Quantity: Double read FQuantity write FQuantity;
|
|
|
|
+ property TotalPrice: Double read FTotalPrice write FTotalPrice;
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+ TDetailBGLNode = class
|
|
|
|
+ private
|
|
|
|
+ FID: Integer;
|
|
|
|
+ FBGLID: Integer;
|
|
|
|
+
|
|
|
|
+ FQuantity: Double;
|
|
|
|
+ FTotalPrice: Double;
|
|
|
|
+ public
|
|
|
|
+ constructor Create(AID: Integer);
|
|
|
|
+
|
|
|
|
+ property ID: Integer read FID;
|
|
|
|
+ property BGLID: Integer read FBGLID;
|
|
|
|
+
|
|
|
|
+ property Quantity: Double read FQuantity write FQuantity;
|
|
|
|
+ property TotalPrice: Double read FTotalPrice write FTotalPrice;
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+ TGclNode = class
|
|
|
|
+ private
|
|
|
|
+ FDetailGcls: TList;
|
|
|
|
+ FDetailDeals: TList;
|
|
|
|
+ FDetailBGLs: TList;
|
|
|
|
+
|
|
|
|
+ FID: Integer;
|
|
|
|
+
|
|
|
|
+ FB_Code: string;
|
|
|
|
+ FIndexCode: string;
|
|
|
|
+ FName: string;
|
|
|
|
+ FUnits: string;
|
|
|
|
+ FPrice: Double;
|
|
|
|
+
|
|
|
|
+ FQuantity: Double;
|
|
|
|
+ FTotalPrice: Double;
|
|
|
|
+
|
|
|
|
+ FCurDealQuantity: Double;
|
|
|
|
+ FCurDealTotalPrice: Double;
|
|
|
|
+ FCurQcQuantity: Double;
|
|
|
|
+ FCurQcTotalPrice: Double;
|
|
|
|
+ FCurGatherQuantity: Double;
|
|
|
|
+ FCurGatherTotalPrice: Double;
|
|
|
|
+
|
|
|
|
+ FPreDealQuantity: Double;
|
|
|
|
+ FPreDealTotalPrice: Double;
|
|
|
|
+ FPreQcQuantity: Double;
|
|
|
|
+ FPreQcTotalPrice: Double;
|
|
|
|
+ FPreGatherQuantity: Double;
|
|
|
|
+ FPreGatherTotalPrice: Double;
|
|
|
|
+
|
|
|
|
+ FDealQuantity: Double;
|
|
|
|
+ FDealTotalPrice: Double;
|
|
|
|
+
|
|
|
|
+ FBGLQuantity: Double;
|
|
|
|
+ FBGLTotalPrice: Double;
|
|
|
|
+
|
|
|
|
+ procedure InitCalculate;
|
|
|
|
+ procedure GatherDetailGcl;
|
|
|
|
+ procedure GatherDetailDeal;
|
|
|
|
+ procedure GatherDetailBGL;
|
|
|
|
+
|
|
|
|
+ procedure SetB_Code(const Value: string);
|
|
|
|
+ function GetDetailBGL(AIndex: Integer): TDetailBGLNode;
|
|
|
|
+ function GetDetailBGLCount: Integer;
|
|
|
|
+ function GetDetailDeal(AIndex: Integer): TDetailDealNode;
|
|
|
|
+ function GetDetailDealCount: Integer;
|
|
|
|
+ function GetDetailGcl(AIndex: Integer): TDetailGclNode;
|
|
|
|
+ function GetDetailGclCount: Integer;
|
|
|
|
+ public
|
|
|
|
+ constructor Create(AID: Integer);
|
|
|
|
+ destructor Destroy; override;
|
|
|
|
+
|
|
|
|
+ function AddDetailGcl(AID: Integer): TDetailGclNode;
|
|
|
|
+ function AddDetailDeal(AID: Integer): TDetailDealNode;
|
|
|
|
+ function AddDetailBGL(AID: Integer): TDetailBGLNode;
|
|
|
|
+
|
|
|
|
+ procedure Calculate;
|
|
|
|
+
|
|
|
|
+ property ID: Integer read FID;
|
|
|
|
+
|
|
|
|
+ property B_Code: string read FB_Code write SetB_Code;
|
|
|
|
+ property IndexCode: string read FIndexCode;
|
|
|
|
+ property Name: string read FName write FName;
|
|
|
|
+ property Units: string read FUnits write FUnits;
|
|
|
|
+ property Price: Double read FPrice write FPrice;
|
|
|
|
+
|
|
|
|
+ property Quantity: Double read FQuantity write FQuantity;
|
|
|
|
+ property TotalPrice: Double read FTotalPrice write FTotalPrice;
|
|
|
|
+
|
|
|
|
+ property CurDealQuantity: Double read FCurDealQuantity write FCurDealQuantity;
|
|
|
|
+ property CurDealTotalPrice: Double read FCurDealTotalPrice write FCurDealTotalPrice;
|
|
|
|
+ property CurQcQuantity: Double read FCurQcQuantity write FCurQcQuantity;
|
|
|
|
+ property CurQcTotalPrice: Double read FCurQcTotalPrice write FCurQcTotalPrice;
|
|
|
|
+ property CurGatherQuantity: Double read FCurGatherQuantity write FCurGatherQuantity;
|
|
|
|
+ property CurGatherTotalPrice: Double read FCurGatherTotalPrice write FCurGatherTotalPrice;
|
|
|
|
+
|
|
|
|
+ property PreDealQuantity: Double read FPreDealQuantity write FPreDealQuantity;
|
|
|
|
+ property PreDealTotalPrice: Double read FPreGatherTotalPrice write FPreGatherTotalPrice;
|
|
|
|
+ property PreQcQuantity: Double read FPreQcQuantity write FPreQcQuantity;
|
|
|
|
+ property PreQcTotalPrice: Double read FPreQcTotalPrice write FPreQcTotalPrice;
|
|
|
|
+ property PreGatherQuantity: Double read FPreGatherQuantity write FPreGatherQuantity;
|
|
|
|
+ property PreGatherTotalPrice: Double read FPreGatherTotalPrice write FPreGatherTotalPrice;
|
|
|
|
+
|
|
|
|
+ property DealQuantity: Double read FDealQuantity write FDealQuantity;
|
|
|
|
+ property DealTotalPrice: Double read FDealTotalPrice write FDealTotalPrice;
|
|
|
|
+
|
|
|
|
+ property BGLQuantity: Double read FBGLQuantity write FBGLQuantity;
|
|
|
|
+ property BGLTotalPrice: Double read FBGLTotalPrice write FBGLTotalPrice;
|
|
|
|
+
|
|
|
|
+ property DetailGclCount: Integer read GetDetailGclCount;
|
|
|
|
+ property DetailGcl[AIndex: Integer]: TDetailGclNode read GetDetailGcl;
|
|
|
|
+
|
|
|
|
+ property DetailDealCount: Integer read GetDetailDealCount;
|
|
|
|
+ property DetailDeal[AIndex: Integer]: TDetailDealNode read GetDetailDeal;
|
|
|
|
+
|
|
|
|
+ property DetailBGLCount: Integer read GetDetailBGLCount;
|
|
|
|
+ property DetailBGL[AIndex: Integer]: TDetailBGLNode read GetDetailBGL;
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+ TGclGatherModel = class
|
|
|
|
+ private
|
|
|
|
+ FProjectData: TObject;
|
|
|
|
+ FBillsTree: TBillsIDTree;
|
|
|
|
+ FGatherDeal: Boolean;
|
|
|
|
+ FGatherBGL: Boolean;
|
|
|
|
+
|
|
|
|
+ FGcls: TList;
|
|
|
|
+ FNewGclID: Integer;
|
|
|
|
+ FNewDetailGclID: Integer;
|
|
|
|
+ FNewDetailDealID: Integer;
|
|
|
|
+ FNewDetailBGLID: Integer;
|
|
|
|
+
|
|
|
|
+ FWriteGatherData: TGatherDataWriteEvent;
|
|
|
|
+
|
|
|
|
+ procedure BeginGather;
|
|
|
|
+ procedure EndGather;
|
|
|
|
+
|
|
|
|
+ function FindGclNode(const AB_Code, AName, AUnits: string; APrice: Double): TGclNode;
|
|
|
|
+ function NewGclNode(const AB_Code, AName, AUnits: string; APrice: Double): TGclNode;
|
|
|
|
+ function GetGclNode(const AB_Code, AName, AUnits: string; APrice: Double): TGclNode; overload;
|
|
|
|
+ function GetGclNode(ARec: TBillsRecord): TGclNode; overload;
|
|
|
|
+
|
|
|
|
+ procedure AddBillsNode(ANode: TBillsIDTreeNode);
|
|
|
|
+ procedure GatherBillsData;
|
|
|
|
+ procedure GatherDealData;
|
|
|
|
+ procedure GatherBGLData;
|
|
|
|
+
|
|
|
|
+ procedure CalculateAll;
|
|
|
|
+
|
|
|
|
+ function GetNewDetailBGLID: Integer;
|
|
|
|
+ function GetNewDetailDealID: Integer;
|
|
|
|
+ function GetNewDetailGclID: Integer;
|
|
|
|
+ public
|
|
|
|
+ constructor Create(AProjectData: TObject);
|
|
|
|
+ destructor Destroy; override;
|
|
|
|
+
|
|
|
|
+ procedure Execute;
|
|
|
|
+
|
|
|
|
+ property GatherDeal: Boolean read FGatherDeal write FGatherDeal;
|
|
|
|
+ property GatherBGL: Boolean read FGatherBGL write FGatherBGL;
|
|
|
|
+
|
|
|
|
+ property NewDetailGclID: Integer read GetNewDetailGclID;
|
|
|
|
+ property NewDetailDealID: Integer read GetNewDetailDealID;
|
|
|
|
+ property NewDetailBGLID: Integer read GetNewDetailBGLID;
|
|
|
|
+
|
|
|
|
+ // 在使用汇总模型的数据单元创建数据库写入方法,并赋值,否则汇总数据不写入
|
|
|
|
+ property WriteGatherData: TGatherDataWriteEvent read FWriteGatherData write FWriteGatherData;
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+implementation
|
|
|
|
+
|
|
|
|
+uses
|
|
|
|
+ ZhAPI, SysUtils, ProjectData, UtilMethods, sdDB, sdIDTree;
|
|
|
|
+
|
|
|
|
+{ TGclGatherModel }
|
|
|
|
+
|
|
|
|
+procedure TGclGatherModel.AddBillsNode(ANode: TBillsIDTreeNode);
|
|
|
|
+
|
|
|
|
+ function GetFirstXmjParent: TBillsIDTreeNode;
|
|
|
|
+ begin
|
|
|
|
+ Result := ANode;
|
|
|
|
+ while Assigned(Result) and (Result.Rec.B_Code.AsString <> '') do
|
|
|
|
+ Result := TBillsIDTreeNode(Result.Parent);
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+ function GetPegNode(ALeafXmj: TBillsIDTreeNode): TBillsIDTreeNode;
|
|
|
|
+ begin
|
|
|
|
+ Result := nil;
|
|
|
|
+ if not Assigned(ALeafXmj) then Exit;
|
|
|
|
+ if CheckPeg(ALeafXmj.Rec.Name.AsString) then
|
|
|
|
+ Result := ANode
|
|
|
|
+ else
|
|
|
|
+ Result := GetPegNode(TBillsIDTreeNode(ALeafXmj.Parent));
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+var
|
|
|
|
+ vGclNode: TGclNode;
|
|
|
|
+ vDetailGclNode: TDetailGclNode;
|
|
|
|
+ vLeafXmj, vPeg: TBillsIDTreeNode;
|
|
|
|
+begin
|
|
|
|
+ vGclNode := GetGclNode(ANode.Rec);
|
|
|
|
+ vDetailGclNode := vGclNode.AddDetailGcl(NewDetailGclID);
|
|
|
|
+ vDetailGclNode.BillsID := ANode.ID;
|
|
|
|
+ vDetailGclNode.TreeSerialNo := ANode.MajorIndex;
|
|
|
|
+
|
|
|
|
+ vDetailGclNode.Quantity := ANode.Rec.Quantity.AsFloat;
|
|
|
|
+ vDetailGclNode.TotalPrice := ANode.Rec.TotalPrice.AsFloat;
|
|
|
|
+
|
|
|
|
+ if Assigned(ANode.StageRec) then
|
|
|
|
+ begin
|
|
|
|
+ vDetailGclNode.CurDealQuantity := ANode.StageRec.DealQuantity.AsFloat;
|
|
|
|
+ vDetailGclNode.CurDealTotalPrice := ANode.StageRec.DealTotalPrice.AsFloat;
|
|
|
|
+ vDetailGclNode.CurQcQuantity := ANode.StageRec.QcQuantity.AsFloat;
|
|
|
|
+ vDetailGclNode.CurQcTotalPrice := ANode.StageRec.QcTotalPrice.AsFloat;
|
|
|
|
+ vDetailGclNode.CurGatherQuantity := ANode.StageRec.GatherQuantity.AsFloat;
|
|
|
|
+ vDetailGclNode.CurGatherTotalPrice := ANode.StageRec.GatherTotalPrice.AsFloat;
|
|
|
|
+
|
|
|
|
+ vDetailGclNode.PreDealQuantity := ANode.StageRec.PreDealQuantity.AsFloat;
|
|
|
|
+ vDetailGclNode.PreDealTotalPrice := ANode.StageRec.PreDealTotalPrice.AsFloat;
|
|
|
|
+ vDetailGclNode.PreQcQuantity := ANode.StageRec.PreQcQuantity.AsFloat;
|
|
|
|
+ vDetailGclNode.PreQcTotalPrice := ANode.StageRec.PreQcTotalPrice.AsFloat;
|
|
|
|
+ vDetailGclNode.PreGatherQuantity := ANode.StageRec.PreGatherQuantity.AsFloat;
|
|
|
|
+ vDetailGclNode.PreGatherTotalPrice := ANode.StageRec.PreGatherTotalPrice.AsFloat;
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+ vLeafXmj := GetFirstXmjParent;
|
|
|
|
+ vPeg := GetPegNode(vLeafXmj);
|
|
|
|
+ vDetailGclNode.AddPosData(vLeafXmj, vPeg);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TGclGatherModel.BeginGather;
|
|
|
|
+begin
|
|
|
|
+ FGcls := TList.Create;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TGclGatherModel.CalculateAll;
|
|
|
|
+var
|
|
|
|
+ iGcl: Integer;
|
|
|
|
+begin
|
|
|
|
+ for iGcl := 0 to FGcls.Count - 1 do
|
|
|
|
+ TGclNode(FGcls.Items[iGcl]).Calculate;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+constructor TGclGatherModel.Create(AProjectData: TObject);
|
|
|
|
+begin
|
|
|
|
+ FProjectData := AProjectData;
|
|
|
|
+ FBillsTree := TProjectData(FProjectData).BillsMeasureData.BillsMeasureTree;
|
|
|
|
+ FGatherDeal := False;
|
|
|
|
+ FGatherBGL := False;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+destructor TGclGatherModel.Destroy;
|
|
|
|
+begin
|
|
|
|
+ inherited;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TGclGatherModel.EndGather;
|
|
|
|
+begin
|
|
|
|
+ ClearObjects(FGcls);
|
|
|
|
+ FGcls.Free;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TGclGatherModel.Execute;
|
|
|
|
+begin
|
|
|
|
+ BeginGather;
|
|
|
|
+ try
|
|
|
|
+ GatherBillsData;
|
|
|
|
+ GatherDealData;
|
|
|
|
+ GatherBGLData;
|
|
|
|
+ CalculateAll;
|
|
|
|
+ if Assigned(FWriteGatherData) then
|
|
|
|
+ FWriteGatherData(FGcls);
|
|
|
|
+ finally
|
|
|
|
+ EndGather;
|
|
|
|
+ end;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function TGclGatherModel.FindGclNode(const AB_Code, AName, AUnits: string;
|
|
|
|
+ APrice: Double): TGclNode;
|
|
|
|
+var
|
|
|
|
+ i: Integer;
|
|
|
|
+ vGcl: TGclNode;
|
|
|
|
+begin
|
|
|
|
+ Result := nil;
|
|
|
|
+ for i := 0 to FGcls.Count - 1 do
|
|
|
|
+ begin
|
|
|
|
+ vGcl := TGclNode(FGcls.Items[i]);
|
|
|
|
+ if SameText(vGcl.B_Code, TrimRight(AB_Code)) and
|
|
|
|
+ SameText(vGcl.Name, TrimRight(AName)) and
|
|
|
|
+ SameText(vGcl.Units, TrimRight(AUnits)) and
|
|
|
|
+ (abs(vGcl.Price - APrice) < 0.001) then
|
|
|
|
+ begin
|
|
|
|
+ Result := vGcl;
|
|
|
|
+ Break;
|
|
|
|
+ end;
|
|
|
|
+ end;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TGclGatherModel.GatherBGLData;
|
|
|
|
+begin
|
|
|
|
+ if not FGatherBGL then Exit;
|
|
|
|
+ // To Do
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TGclGatherModel.GatherBillsData;
|
|
|
|
+var
|
|
|
|
+ i: Integer;
|
|
|
|
+ vNode: TBillsIDTreeNode;
|
|
|
|
+begin
|
|
|
|
+ for i := 0 to FBillsTree.Count - 1 do
|
|
|
|
+ begin
|
|
|
|
+ vNode := TBillsIDTreeNode(FBillsTree.Items[i]);
|
|
|
|
+ if not vNode.HasChildren and (vNode.Rec.B_Code.AsString <> '') then
|
|
|
|
+ AddBillsNode(vNode);
|
|
|
|
+ end;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TGclGatherModel.GatherDealData;
|
|
|
|
+var
|
|
|
|
+ vGclNode: TGclNode;
|
|
|
|
+ vDetailDeal: TDetailDealNode;
|
|
|
|
+ iDeal: Integer;
|
|
|
|
+ Rec: TsdDataRecord;
|
|
|
|
+begin
|
|
|
|
+ if not FGatherDeal then Exit;
|
|
|
|
+
|
|
|
|
+ with TProjectData(FProjectData).DealBillsData do
|
|
|
|
+ for iDeal := 0 to sddDealBills.RecordCount - 1 do
|
|
|
|
+ begin
|
|
|
|
+ Rec := sddDealBills.Records[iDeal];
|
|
|
|
+ vGclNode := GetGclNode(Rec.ValueByName('B_Code').AsString, Rec.ValueByName('Name').AsString,
|
|
|
|
+ Rec.ValueByName('Units').AsString, Rec.ValueByName('Price').AsFloat);
|
|
|
|
+ vDetailDeal := vGclNode.AddDetailDeal(NewDetailDealID);
|
|
|
|
+
|
|
|
|
+ vDetailDeal.Quantity := Rec.ValueByName('Quantity').AsFloat;
|
|
|
|
+ vDetailDeal.TotalPrice := Rec.ValueByName('TotalPrice').AsFloat;
|
|
|
|
+ end;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function TGclGatherModel.GetGclNode(ARec: TBillsRecord): TGclNode;
|
|
|
|
+begin
|
|
|
|
+ Result := GetGclNode(ARec.B_Code.AsString, ARec.Name.AsString,
|
|
|
|
+ ARec.Units.AsString, ARec.Price.AsFloat);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function TGclGatherModel.GetGclNode(const AB_Code, AName, AUnits: string;
|
|
|
|
+ APrice: Double): TGclNode;
|
|
|
|
+begin
|
|
|
|
+ Result := FindGclNode(AB_Code, AName, AUnits, APrice);
|
|
|
|
+ if not Assigned(Result) then
|
|
|
|
+ Result := NewGclNode(AB_Code, AName, AUnits, APrice);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function TGclGatherModel.GetNewDetailBGLID: Integer;
|
|
|
|
+begin
|
|
|
|
+ Result := FNewDetailBGLID;
|
|
|
|
+ Inc(FNewDetailBGLID)
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function TGclGatherModel.GetNewDetailDealID: Integer;
|
|
|
|
+begin
|
|
|
|
+ Result := FNewDetailDealID;
|
|
|
|
+ Inc(FNewDetailDealID);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function TGclGatherModel.GetNewDetailGclID: Integer;
|
|
|
|
+begin
|
|
|
|
+ Result := FNewDetailGclID;
|
|
|
|
+ Inc(FNewDetailGclID);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function TGclGatherModel.NewGclNode(const AB_Code, AName, AUnits: string;
|
|
|
|
+ APrice: Double): TGclNode;
|
|
|
|
+begin
|
|
|
|
+ Result := TGclNode.Create(FNewGclID);
|
|
|
|
+ FGcls.Add(Result);
|
|
|
|
+ Result.B_Code := TrimRight(AB_Code);
|
|
|
|
+ Result.Name := TrimRight(AName);
|
|
|
|
+ Result.Units := TrimRight(AUnits);
|
|
|
|
+ Result.Price := APrice;
|
|
|
|
+ Inc(FNewGclID);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+{ TGclNode }
|
|
|
|
+
|
|
|
|
+function TGclNode.AddDetailBGL(AID: Integer): TDetailBGLNode;
|
|
|
|
+begin
|
|
|
|
+ Result := TDetailBGLNode.Create(AID);
|
|
|
|
+ FDetailBGLs.Add(Result);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function TGclNode.AddDetailDeal(AID: Integer): TDetailDealNode;
|
|
|
|
+begin
|
|
|
|
+ Result := TDetailDealNode.Create(AID);
|
|
|
|
+ FDetailDeals.Add(Result);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function TGclNode.AddDetailGcl(AID: Integer): TDetailGclNode;
|
|
|
|
+begin
|
|
|
|
+ Result := TDetailGclNode.Create(AID);
|
|
|
|
+ FDetailGcls.Add(Result);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TGclNode.Calculate;
|
|
|
|
+begin
|
|
|
|
+ InitCalculate;
|
|
|
|
+ GatherDetailGcl;
|
|
|
|
+ GatherDetailDeal;
|
|
|
|
+ GatherDetailBGL;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+constructor TGclNode.Create(AID: Integer);
|
|
|
|
+begin
|
|
|
|
+ FID := AID;
|
|
|
|
+ FDetailGcls := TList.Create;
|
|
|
|
+ FDetailDeals := TList.Create;
|
|
|
|
+ FDetailBGLs := TList.Create;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+destructor TGclNode.Destroy;
|
|
|
|
+begin
|
|
|
|
+ ClearObjects(FDetailBGLs);
|
|
|
|
+ FDetailBGLs.Free;
|
|
|
|
+ ClearObjects(FDetailDeals);
|
|
|
|
+ FDetailDeals.Free;
|
|
|
|
+ ClearObjects(FDetailGcls);
|
|
|
|
+ FDetailGcls.Free;
|
|
|
|
+ inherited;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TGclNode.GatherDetailBGL;
|
|
|
|
+var
|
|
|
|
+ iBGL: Integer;
|
|
|
|
+ vDetailBGL: TDetailBGLNode;
|
|
|
|
+begin
|
|
|
|
+ for iBGL := 0 to DetailBGLCount - 1 do
|
|
|
|
+ begin
|
|
|
|
+ vDetailBGL := DetailBGL[iBGL];
|
|
|
|
+ FBGLQuantity := FBGLQuantity + vDetailBGL.Quantity;
|
|
|
|
+ FBGLTotalPrice := FBGLTotalPrice + vDetailBGL.TotalPrice;
|
|
|
|
+ end;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TGclNode.GatherDetailDeal;
|
|
|
|
+var
|
|
|
|
+ iDeal: Integer;
|
|
|
|
+ vDetailDeal: TDetailDealNode;
|
|
|
|
+begin
|
|
|
|
+ for iDeal := 0 to DetailDealCount - 1 do
|
|
|
|
+ begin
|
|
|
|
+ vDetailDeal := DetailDeal[iDeal];
|
|
|
|
+ FDealQuantity := FDealQuantity + vDetailDeal.Quantity;
|
|
|
|
+ FDealTotalPrice := FDealTotalPrice + vDetailDeal.TotalPrice;
|
|
|
|
+ end;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TGclNode.GatherDetailGcl;
|
|
|
|
+var
|
|
|
|
+ iGcl: Integer;
|
|
|
|
+ vDetailGcl: TDetailGclNode;
|
|
|
|
+begin
|
|
|
|
+ for iGcl := 0 to DetailGclCount - 1 do
|
|
|
|
+ begin
|
|
|
|
+ vDetailGcl := DetailGcl[iGcl];
|
|
|
|
+ FQuantity := FQuantity + vDetailGcl.Quantity;
|
|
|
|
+ FTotalPrice := FTotalPrice + vDetailGcl.TotalPrice;
|
|
|
|
+
|
|
|
|
+ FCurDealQuantity := FCurDealQuantity + vDetailGcl.CurDealQuantity;
|
|
|
|
+ FCurDealTotalPrice := FCurDealTotalPrice + vDetailGcl.CurDealTotalPrice;
|
|
|
|
+ FCurQcQuantity := FCurQcQuantity + vDetailGcl.CurQcQuantity;
|
|
|
|
+ FCurQcTotalPrice := FCurQcTotalPrice + vDetailGcl.CurQcTotalPrice;
|
|
|
|
+ FCurGatherQuantity := FCurGatherQuantity + vDetailGcl.CurGatherQuantity;
|
|
|
|
+ FCurGatherTotalPrice := FCurGatherTotalPrice + vDetailGcl.CurGatherTotalPrice;
|
|
|
|
+
|
|
|
|
+ FPreDealQuantity := FPreDealQuantity + vDetailGcl.PreDealQuantity;
|
|
|
|
+ FPreDealTotalPrice := FPreDealTotalPrice + vDetailGcl.PreDealTotalPrice;
|
|
|
|
+ FPreQcQuantity := FPreQcQuantity + vDetailGcl.PreQcQuantity;
|
|
|
|
+ FPreQcTotalPrice := FPreQcTotalPrice + vDetailGcl.PreQcTotalPrice;
|
|
|
|
+ FPreGatherQuantity := FPreGatherQuantity + vDetailGcl.PreGatherQuantity;
|
|
|
|
+ FPreGatherTotalPrice := FPreGatherTotalPrice + vDetailGcl.PreGatherTotalPrice;
|
|
|
|
+ end;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function TGclNode.GetDetailBGL(AIndex: Integer): TDetailBGLNode;
|
|
|
|
+begin
|
|
|
|
+ Result := TDetailBGLNode(FDetailBGLs.Items[AIndex]);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function TGclNode.GetDetailBGLCount: Integer;
|
|
|
|
+begin
|
|
|
|
+ Result := FDetailBGLs.Count;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function TGclNode.GetDetailDeal(AIndex: Integer): TDetailDealNode;
|
|
|
|
+begin
|
|
|
|
+ Result := TDetailDealNode(FDetailDeals.Items[AIndex]);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function TGclNode.GetDetailDealCount: Integer;
|
|
|
|
+begin
|
|
|
|
+ Result := FDetailDeals.Count;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function TGclNode.GetDetailGcl(AIndex: Integer): TDetailGclNode;
|
|
|
|
+begin
|
|
|
|
+ Result := TDetailGclNode(FDetailGcls.Items[AIndex]);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function TGclNode.GetDetailGclCount: Integer;
|
|
|
|
+begin
|
|
|
|
+ Result := FDetailGcls.Count;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TGclNode.InitCalculate;
|
|
|
|
+begin
|
|
|
|
+ FQuantity := 0;
|
|
|
|
+ FTotalPrice := 0;
|
|
|
|
+
|
|
|
|
+ FCurDealQuantity := 0;
|
|
|
|
+ FCurDealTotalPrice := 0;
|
|
|
|
+ FCurQcQuantity := 0;
|
|
|
|
+ FCurQcTotalPrice := 0;
|
|
|
|
+ FCurGatherQuantity := 0;
|
|
|
|
+ FCurGatherTotalPrice := 0;
|
|
|
|
+
|
|
|
|
+ FPreDealQuantity := 0;
|
|
|
|
+ FPreDealTotalPrice := 0;
|
|
|
|
+ FPreQcQuantity := 0;
|
|
|
|
+ FPreQcTotalPrice := 0;
|
|
|
|
+ FPreGatherQuantity := 0;
|
|
|
|
+ FPreGatherTotalPrice := 0;
|
|
|
|
+
|
|
|
|
+ FDealQuantity := 0;
|
|
|
|
+ FDealTotalPrice := 0;
|
|
|
|
+
|
|
|
|
+ FBGLQuantity := 0;
|
|
|
|
+ FBGLTotalPrice := 0;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TGclNode.SetB_Code(const Value: string);
|
|
|
|
+begin
|
|
|
|
+ FB_Code := Value;
|
|
|
|
+ FIndexCode := B_CodeToIndexCode(FB_Code);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+{ TDetailGclNode }
|
|
|
|
+
|
|
|
|
+procedure TDetailGclNode.AddPosData(ALeafXmj, APeg: TBillsIDTreeNode);
|
|
|
|
+
|
|
|
|
+ function GetPegName: string;
|
|
|
|
+ begin
|
|
|
|
+ if Assigned(APeg) then
|
|
|
|
+ Result := APeg.Rec.Name.AsString
|
|
|
|
+ else
|
|
|
|
+ Result := '';
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+ // 取树结构的第ALevel层节点的名称(level从0开始)
|
|
|
|
+ function GetNameByLevel(ANode: TBillsIDTreeNode; ALevel: Integer): string;
|
|
|
|
+ begin
|
|
|
|
+ Result := '';
|
|
|
|
+ if not Assigned(ANode) then Exit;
|
|
|
|
+ if ANode.Level = ALevel then
|
|
|
|
+ Result := ANode.Rec.Name.AsString
|
|
|
|
+ else if ANode.Level > ALevel then
|
|
|
|
+ Result := GetNameByLevel(TBillsIDTreeNode(ANode.Parent), ALevel);
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+ function GetNameDanWei(ANode: TBillsIDTreeNode): string;
|
|
|
|
+ begin
|
|
|
|
+ // 取树结构的第二层节点的名称
|
|
|
|
+ Result := GetNameByLevel(ANode, 1);
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+ // ANode为计量单元节点,APegNode为桩号节点
|
|
|
|
+ function GetNameFenBu(ANode, APegNode: TBillsIDTreeNode): string;
|
|
|
|
+ var
|
|
|
|
+ vCurNode: TBillsIDTreeNode;
|
|
|
|
+ begin
|
|
|
|
+ // 如果计量单元节点的名称为桩号(转化为判断计量单元节点与桩号节点为同一个)
|
|
|
|
+ if not Assigned(APegNode) or (ANode.ID = APegNode.ID) then
|
|
|
|
+ // 取树结构的第三层节点的名称
|
|
|
|
+ Result := GetNameByLevel(ANode, 2)
|
|
|
|
+ // 否则,取桩号节点的子节点的名称
|
|
|
|
+ else
|
|
|
|
+ begin
|
|
|
|
+ vCurNode := ANode;
|
|
|
|
+ while vCurNode.Level > APegNode.Level + 1 do
|
|
|
|
+ vCurNode := TBillsIDTreeNode(vCurNode.Parent);
|
|
|
|
+ Result := vCurNode.Rec.Name.AsString;
|
|
|
|
+ end;
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+ // ANode为计量单元节点,APegNode为桩号节点
|
|
|
|
+ function GetNameFenXiang(ANode, APegNode: TBillsIDTreeNode): string;
|
|
|
|
+ var
|
|
|
|
+ iTopLevel: Integer;
|
|
|
|
+ vCurNode: TBillsIDTreeNode;
|
|
|
|
+ begin
|
|
|
|
+ if Assigned(APegNode) then
|
|
|
|
+ begin
|
|
|
|
+ iTopLevel := 3;
|
|
|
|
+ if APegNode.ID <> ANode.ID then
|
|
|
|
+ iTopLevel := APegNode.Level + 2;
|
|
|
|
+ Result := '';
|
|
|
|
+ vCurNode := TBillsIDTreeNode(ANode.Parent);
|
|
|
|
+ while vCurNode.Level >= iTopLevel do
|
|
|
|
+ begin
|
|
|
|
+ Result := vCurNode.Rec.Name.AsString + ';' + Result;
|
|
|
|
+ vCurNode := TBillsIDTreeNode(vCurNode.Parent);
|
|
|
|
+ end;
|
|
|
|
+ end
|
|
|
|
+ else
|
|
|
|
+ Result := GetNameByLevel(ANode, 3);
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+ function GetNameUnit(ANode: TBillsIDTreeNode): string;
|
|
|
|
+ begin
|
|
|
|
+ Result := ANode.Rec.Name.AsString;
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+ function GetDrawingCode(ANode: TBillsIDTreeNode): string;
|
|
|
|
+ begin
|
|
|
|
+ Result := '';
|
|
|
|
+ if not Assigned(ANode) then Exit;
|
|
|
|
+ Result := ANode.Rec.DrawingCode.AsString;
|
|
|
|
+ if Result = '' then
|
|
|
|
+ Result := GetDrawingCode(TBillsIDTreeNode(ANode.Parent));
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+ function GetPosition(ANode, APegNode: TBillsIDTreeNode): string;
|
|
|
|
+ begin
|
|
|
|
+ // 如果计量单元节点的名称为桩号(转化为判断计量单元节点与桩号节点为同一个)
|
|
|
|
+ if not Assigned(APegNode) or (ANode.ID = APegNode.ID) then
|
|
|
|
+ // 取分部工程
|
|
|
|
+ Result := GetNameFenXiang(ANode, APegNode)
|
|
|
|
+ // 反之,取分项工程+计量单元
|
|
|
|
+ else
|
|
|
|
+ Result := GetNameFenXiang(ANode, APegNode) + GetNameUnit(ANode);
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+begin
|
|
|
|
+ if not Assigned(ALeafXmj) then Exit;
|
|
|
|
+
|
|
|
|
+ FLeafXmjID := ALeafXmj.ID;
|
|
|
|
+ FXmjCode := ALeafXmj.Rec.Code.AsString;
|
|
|
|
+ FXmjName := ALeafXmj.Rec.Name.AsString;
|
|
|
|
+ FXmjUnits := ALeafXmj.Rec.Units.AsString;
|
|
|
|
+ FPeg := GetPegName;
|
|
|
|
+ FNameDanWei := GetNameDanWei(ALeafXmj);
|
|
|
|
+ FNameFenBu := GetNameFenBu(ALeafXmj, APeg);
|
|
|
|
+ FNameFenXiang := GetNameFenXiang(ALeafXmj, APeg);
|
|
|
|
+ FNameUnit := GetNameUnit(ALeafXmj);
|
|
|
|
+ FPosition := GetPosition(ALeafXmj, APeg);
|
|
|
|
+ FDrawingCode := GetDrawingCode(ALeafXmj);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+constructor TDetailGclNode.Create(AID: Integer);
|
|
|
|
+begin
|
|
|
|
+ FID := AID;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+{ TDetailBGLNode }
|
|
|
|
+
|
|
|
|
+constructor TDetailBGLNode.Create(AID: Integer);
|
|
|
|
+begin
|
|
|
|
+ FID := AID;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+{ TDetailDealNode }
|
|
|
|
+
|
|
|
|
+constructor TDetailDealNode.Create(AID: Integer);
|
|
|
|
+begin
|
|
|
|
+ FID := AID;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+end.
|