| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355 | 
							- unit rmHaBaiCustomizedDm;
 
- // 内蒙古 哈白项目定制汇总表 严禁任何其他项目或标表调用该单元
 
- // 包括支表2/3/14/3-1/4-1
 
- interface
 
- uses
 
-   SysUtils, Classes, DB, rmSelectProjectFrm, ProjectData, mDataRecord,
 
-   BillsTree, DBClient;
 
- type
 
-   TDoubleArray = array of Double;
 
-   TStringArray = array of string;
 
-   TGclNode = class
 
-   private
 
-     FProjectCount: Integer;
 
-     FB_Code: string;
 
-     FIndexCode: string;
 
-     FName: string;
 
-     FUnits: string;
 
-     FPrice: Double;
 
-     FQuantity: Double;
 
-     FTotalPrice: Double;
 
-     FCurGatherQuantity: Double;
 
-     FCurGatherTotalPrice: Double;
 
-     FEndGatherQuantity: Double;
 
-     FEndGatherTotalPrice: Double;
 
-     FPreGatherQuantity: Double;
 
-     FPreGatherTotalPrice: Double;
 
-     FP_Quantity: TDoubleArray;
 
-     FP_TotalPrice: TDoubleArray;
 
-     FP_CurGatherQuantity: TDoubleArray;
 
-     FP_CurGatherTotalPrice: TDoubleArray;
 
-     FP_EndGatherQuantity: TDoubleArray;
 
-     FP_EndGatherTotalPrice: TDoubleArray;
 
-     procedure SetB_Code(const Value: string);
 
-     function GetCurPercent: Double;
 
-     function GetEndPercent: Double;
 
-   public
 
-     constructor Create(AProjectCount: Integer);
 
-     procedure Calculate;
 
-     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 CurGatherQuantity: Double read FCurGatherQuantity write FCurGatherQuantity;
 
-     property CurGatherTotalPrice: Double read FCurGatherTotalPrice write FCurGatherTotalPrice;
 
-     property EndGatherQuantity: Double read FEndGatherQuantity write FEndGatherQuantity;
 
-     property EndGatherTotalPrice: Double read FEndGatherTotalPrice write FEndGatherTotalPrice;
 
-     property PreGatherQuantity: Double read FPreGatherQuantity write FPreGatherQuantity;
 
-     property PreGatherTotalPrice: Double read FPreGatherTotalPrice write FPreGatherTotalPrice;
 
-     property P_Quantity: TDoubleArray read FP_Quantity write FP_Quantity;
 
-     property P_TotalPrice: TDoubleArray read FP_TotalPrice write FP_TotalPrice;
 
-     property P_CurGatherQuantity: TDoubleArray read FP_CurGatherQuantity write FP_CurGatherQuantity;
 
-     property P_CurGatherTotalPrice: TDoubleArray read FP_CurGatherTotalPrice write FP_CurGatherTotalPrice;
 
-     property P_EndGatherQuantity: TDoubleArray read FP_EndGatherQuantity write FP_EndGatherQuantity;
 
-     property P_EndGatherTotalPrice: TDoubleArray read FP_EndGatherTotalPrice write FP_EndGatherTotalPrice;
 
-     property CurPercent: Double read GetCurPercent;
 
-     property EndPercent: Double read GetEndPercent;
 
-   end;
 
-   TGclChapter = class
 
-   private
 
-     FProjectCount: Integer;
 
-     FGclNodes: TList;
 
-     FChapterID: Integer;
 
-     FChapterBegin: Integer;
 
-     FChapterEnd: Integer;
 
-     FChapterName: string;
 
-     FName: string;
 
-     FTotalPrice: Double;
 
-     FCurGatherTotalPrice: Double;
 
-     FEndGatherTotalPrice: Double;
 
-     FPreGatherTotalPrice: Double;
 
-     FP_TotalPrice: TDoubleArray;
 
-     FP_CurGatherTotalPrice: TDoubleArray;
 
-     FP_EndGatherTotalPrice: TDoubleArray;
 
-     function GetGclNode(AIndex: Integer): TGclNode;
 
-     function GetGclNodeCount: Integer;
 
-     function GetCurPercent: Double;
 
-     function GetEndPercent: Double;
 
-   public
 
-     constructor Create(AChapterID: Integer; const AName: string; AProjectCount: Integer);
 
-     destructor Destroy; override;
 
-     procedure AddGclNode(AGclNode: TGclNode);
 
-     procedure CalculateChapter;
 
-     property ChapterID: Integer read FChapterID;
 
-     property ChapterBegin: Integer read FChapterBegin;
 
-     property ChapterEnd: Integer read FChapterEnd;
 
-     property ChapterName: string read FChapterName;
 
-     property Name: string read FName;
 
-     property TotalPrice: Double read FTotalPrice write FTotalPrice;
 
-     property CurGatherTotalPrice: Double read FCurGatherTotalPrice write FCurGatherTotalPrice;
 
-     property EndGatherTotalPrice: Double read FEndGatherTotalPrice write FEndGatherTotalPrice;
 
-     property PreGatherTotalPrice: Double read FPreGatherTotalPrice write FPreGatherTotalPrice;
 
-     property P_TotalPrice: TDoubleArray read FP_TotalPrice write FP_TotalPrice;
 
-     property P_CurGatherTotalPrice: TDoubleArray read FP_CurGatherTotalPrice write FP_CurGatherTotalPrice;
 
-     property P_EndGatherTotalPrice: TDoubleArray read FP_EndGatherTotalPrice write FP_EndGatherTotalPrice;
 
-     property CurPercent: Double read GetCurPercent;
 
-     property EndPercent: Double read GetEndPercent;
 
-     property GclNodeCount: Integer read GetGclNodeCount;
 
-     property GclNode[AIndex: Integer]: TGclNode read GetGclNode;
 
-   end;
 
-   TGclControl = class
 
-   private
 
-     FProjectCount: Integer;
 
-     FProjectName: TStringArray;
 
-     FGclNodes: TList;
 
-     FGclChapters: TList;
 
-     FGclChapterGather: TGclChapter;
 
-     FOtherGcl: TGclChapter;
 
-     function FindGclNode(ARec: TBillsRecord): TGclNode;
 
-     function NewGclNode(ARec: TBillsRecord): TGclNode;
 
-     function B_CodeToChapter(const AB_Code: string): Integer;
 
-     procedure LinkGclChapter(AGclNode: TGclNode);
 
-     function FindGclChapter(AChapterID: Integer): TGclChapter;
 
-     procedure CalculateChapterGather;
 
-     function GetGclChapterCount: Integer;
 
-     function GetGclChapter(AIndex: Integer): TGclChapter;
 
-   public
 
-     constructor Create(AProjectCount: Integer);
 
-     destructor Destroy;
 
-     function AddGclNode(ANode: TBillsIDTreeNode; AProjectIndex: Integer): TGclNode;
 
-     procedure ReCalculateTotalPrice;
 
-     procedure Calculate;
 
-     property GclChapterCount: Integer read GetGclChapterCount;
 
-     property GclChapter[AIndex: Integer]: TGclChapter read GetGclChapter;
 
-     property GclChapterGather: TGclChapter read FGclChapterGather;
 
-     property ProjectName: TStringArray read FProjectName write FProjectName;
 
-     property ProjectCount: Integer read FProjectCount;
 
-   end;
 
-   TPayNode = class
 
-   private
 
-     FName: string;
 
-     FIsMinus: Boolean;
 
-     FCurTotalPrice: Double;
 
-     FEndTotalPrice: Double;
 
-     FPreTotalPrice: Double;
 
-   public
 
-     property Name: string read FName write FName;
 
-     property IsMinus: Boolean read FIsMinus write FisMinus;
 
-     property CurTotalPrice: Double read FCurTotalPrice write FCurTotalPrice;
 
-     property EndTotalPrice: Double read FEndTotalPrice write FEndTotalPrice;
 
-     property PreTotalPrice: Double read FPreTotalPrice write FPreTotalPrice;
 
-   end;
 
-   TDealPayControl = class
 
-   private
 
-     FPlusPayNodes: TList;
 
-     FMinusPayNodes: TList;
 
-     FPlusGather: TPayNode;
 
-     FMinusGather: TPayNode;
 
-     FGatherPayNode: TPayNode;
 
-     function FindPlusPayNode(const AName: string): TPayNode;
 
-     function NewPlusPayNode(const AName: string): TPayNode;
 
-     function AddPlusPayNode(const AName: string): TPayNode;
 
-     function FindMinusPayNode(const AName: string): TPayNode;
 
-     function NewMinusPayNode(const AName: string): TPayNode;
 
-     function AddMinusPayNode(const AName: string): TPayNode;
 
-     procedure CalculateGather(AGather: TPayNode; ANodes: TList);
 
-     function GetMinusPayCount: Integer;
 
-     function GetMinusPayNode(AIndex: Integer): TPayNode;
 
-     function GetPlusPayCount: Integer;
 
-     function GetPlusPayNode(AIndex: Integer): TPayNode;
 
-   public
 
-     constructor Create;
 
-     destructor Destroy; override;
 
-     function AddPayNode(const AName: string; AIsMinus: Boolean): TPayNode;
 
-     procedure CalculateAll;
 
-     property PlusPayCount: Integer read GetPlusPayCount;
 
-     property PlusPayNode[AIndex: Integer]: TPayNode read GetPlusPayNode;
 
-     property PlusGather: TPayNode read FPlusGather;
 
-     property MinusPayCount: Integer read GetMinusPayCount;
 
-     property MinusPayNode[AIndex: Integer]:TPayNode read GetMinusPayNode;
 
-     property MinusGather: TPayNode read FMinusGather;
 
-     property GatherPayNode: TPayNode read FGatherPayNode;
 
-   end;
 
-   // 分别对应5张定制汇总表的编号,详见文档
 
-   THaBaiGatherType = (hbgt2, hbgt3, hbgt14, hbgt3_1, hbgt4_1);
 
-   TrmHaBaiCustomizedData = class(TDataModule)
 
-     cdsCustom2: TClientDataSet;
 
-     cdsCustom2Chapter: TIntegerField;
 
-     cdsCustom2Name: TWideStringField;
 
-     cdsCustom2TotalPrice: TFloatField;
 
-     cdsCustom2CTotalPrice: TFloatField;
 
-     cdsCustom2GTotalPrice: TFloatField;
 
-     cdsCustom2EndGatherTotalPrice: TFloatField;
 
-     cdsCustom2PreGatherTotalPrice: TFloatField;
 
-     cdsCustom2CurGatherTotalPrice: TFloatField;
 
-     cdsCustom2Percent: TFloatField;
 
-     cdsCustom3: TClientDataSet;
 
-     cdsCustom3ChapterID: TIntegerField;
 
-     cdsCustom3InnerPartID: TIntegerField;
 
-     cdsCustom3IndexCode: TStringField;
 
-     cdsCustom3B_Code: TWideStringField;
 
-     cdsCustom3Name: TWideStringField;
 
-     cdsCustom3Units: TWideStringField;
 
-     cdsCustom3Price: TFloatField;
 
-     cdsCustom3Quantity: TFloatField;
 
-     cdsCustom3TotalPrice: TFloatField;
 
-     cdsCustom3PreGatherQuantity: TFloatField;
 
-     cdsCustom3PreGatherTotalPrice: TFloatField;
 
-     cdsCustom3EndGatherQuantity: TFloatField;
 
-     cdsCustom3EndGatherTotalPrice: TFloatField;
 
-     cdsCustom3CurGatherQuantity: TFloatField;
 
-     cdsCustom3CurGatherTotalPrice: TFloatField;
 
-     cdsCustom3Percent: TFloatField;
 
-     cdsCustom14: TClientDataSet;
 
-     cdsCustom14IndexCode: TWideStringField;
 
-     cdsCustom14B_Code: TWideStringField;
 
-     cdsCustom14Name: TWideStringField;
 
-     cdsCustom14Units: TWideStringField;
 
-     cdsCustom14Price: TFloatField;
 
-     cdsCustom14Quantity: TFloatField;
 
-     cdsCustom14TotalPrice: TFloatField;
 
-     cdsCustom14CertificateCode: TWideStringField;
 
-     cdsCustomProj: TClientDataSet;
 
-     cdsCustomProjProjectID: TIntegerField;
 
-     cdsCustomProjProjectName: TWideStringField;
 
-     cdsCustomProjChapterID: TIntegerField;
 
-     cdsCustomProjInnerPartID: TIntegerField;
 
-     cdsCustomProjIndexCode: TWideStringField;
 
-     cdsCustomProjB_Code: TWideStringField;
 
-     cdsCustomProjName: TWideStringField;
 
-     cdsCustomProjUnits: TWideStringField;
 
-     cdsCustomProjPrice: TFloatField;
 
-     cdsCustomProjQuantity: TFloatField;
 
-     cdsCustomProjTotalPrice: TFloatField;
 
-     cdsCustomProjCurGatherQuantity: TFloatField;
 
-     cdsCustomProjCurGatherTotalPrice: TFloatField;
 
-     cdsCustomProjEndGatherQuantity: TFloatField;
 
-     cdsCustomProjEndGatherTotalPrice: TFloatField;
 
-     cdsCustomProjP_CurGatherQuantity: TFloatField;
 
-     cdsCustomProjP_CurGatherTotalPrice: TFloatField;
 
-     cdsCustomProjP_EndGatherQuantity: TFloatField;
 
-     cdsCustomProjP_EndGatherTotalPrice: TFloatField;
 
-     cdsCustomProjCurPercent: TFloatField;
 
-     cdsCustomProjEndPercent: TFloatField;
 
-     cdsCustomProjSerialNo: TIntegerField;
 
-   private
 
-     FhbGatherType: THaBaiGatherType;
 
-     FProjectData: TProjectData;
 
-     FProjectName: string;
 
-     FGclControl: TGclControl;
 
-     FDealPayControl: TDealPayControl;
 
-     procedure BeforeGather(AProjectCount: Integer);
 
-     procedure AfterGather;
 
-     procedure OpenProjectData(AProject: TSelectProject);
 
-     procedure FreeProjectData;
 
-     procedure GatherProject(AProject: TSelectProject; AProjectIndex: Integer);
 
-     procedure FilterGcl(AProjectIndex: Integer);
 
-     procedure FilterDealPay;
 
-     procedure WriteFlowData;
 
-     procedure WriteReport2;
 
-     procedure WriteReport3;
 
-     procedure WriteReport3_1;
 
-     procedure WriteReport4_1;
 
-     procedure WriteData;
 
-   public
 
-     function AssignData(AProjects: TList; AhbGatherType: THaBaiGatherType): TDataSet;
 
-   end;
 
- implementation
 
- uses
 
-   UtilMethods, ZhAPI, BillsCompileDm, sdDB, Globals, Math, BillsMeasureDm,
 
-   ZJJLDm;
 
- {$R *.dfm}
 
- { TrmHaBaiCustomizedData }
 
- function TrmHaBaiCustomizedData.AssignData(AProjects: TList;
 
-   AhbGatherType: THaBaiGatherType): TDataSet;
 
- var
 
-   iProject: Integer;
 
- begin
 
-   FhbGatherType := AhbGatherType;
 
-   BeforeGather(AProjects.Count);
 
-   try
 
-     for iProject := 0 to AProjects.Count - 1 do
 
-       GatherProject(TSelectProject(AProjects.Items[iProject]), iProject);
 
-     FGclControl.ReCalculateTotalPrice;
 
-     FGclControl.Calculate;
 
-     WriteData;
 
-   finally
 
-     AfterGather;
 
-     case FhbGatherType of
 
-       hbgt2: Result := cdsCustom2;
 
-       hbgt3: Result := cdsCustom3;
 
-       hbgt14: Result := cdsCustom14;
 
-       hbgt3_1, hbgt4_1: Result := cdsCustomProj;
 
-     end;
 
-   end;
 
- end;
 
- procedure TrmHaBaiCustomizedData.BeforeGather(AProjectCount: Integer);
 
- begin
 
-   cdsCustom2.DisableControls;
 
-   cdsCustom2.Active := True;
 
-   cdsCustom2.EmptyDataSet;
 
-   cdsCustom3.DisableControls;
 
-   cdsCustom3.Active := True;
 
-   cdsCustom3.EmptyDataSet;
 
-   cdsCustom14.DisableControls;
 
-   cdsCustom14.Active := True;
 
-   cdsCustom14.EmptyDataSet;
 
-   cdsCustomProj.DisableControls;
 
-   cdsCustomProj.Active := True;
 
-   cdsCustomProj.EmptyDataSet;
 
-   FGclControl := TGclControl.Create(AProjectCount);
 
-   FDealPayControl := TDealPayControl.Create;
 
- end;
 
- procedure TrmHaBaiCustomizedData.AfterGather;
 
- begin
 
-   FDealPayControl.Free;
 
-   FGclControl.Free;
 
-   cdsCustomProj.EnableControls;
 
-   cdsCustom14.EnableControls;
 
-   cdsCustom3.EnableControls;
 
-   cdsCustom2.EnableControls;
 
- end;
 
- procedure TrmHaBaiCustomizedData.FreeProjectData;
 
- begin
 
-   if not Assigned(OpenProjectManager.FindProjectData(FProjectData.ProjectID)) then
 
-     FProjectData.Free;
 
- end;
 
- procedure TrmHaBaiCustomizedData.OpenProjectData(AProject: TSelectProject);
 
- var
 
-   Rec: TsdDataRecord;
 
- begin
 
-   FProjectData := OpenProjectManager.FindProjectData(AProject.ProjectID);
 
-   Rec := ProjectManager.sddProjectsInfo.FindKey('idxID', AProject.ProjectID);
 
-   if not Assigned(FProjectData) then
 
-   begin
 
-     FProjectData := TProjectData.Create;
 
-     FProjectData.OpenForReport3(GetMyProjectsFilePath + Rec.ValueByName('FileName').AsString);
 
-   end;
 
-   FProjectName := Rec.ValueByName('Name').AsString;
 
- end;
 
- procedure TrmHaBaiCustomizedData.GatherProject(AProject: TSelectProject;
 
-   AProjectIndex: Integer);
 
- begin
 
-   OpenProjectData(AProject);
 
-   try
 
-     FGclControl.ProjectName[AProjectIndex] := FProjectName;
 
-     if FhbGatherType in [hbgt2, hbgt3, hbgt3_1, hbgt4_1] then
 
-       FilterGcl(AProjectIndex);
 
-     if FhbGatherType = hbgt2 then
 
-       FilterDealPay;
 
-     if FhbGatherType = hbgt14 then
 
-       WriteFlowData;
 
-   finally
 
-     FreeProjectData;
 
-   end;
 
- end;
 
- procedure TrmHaBaiCustomizedData.FilterGcl(AProjectIndex: Integer);
 
- var
 
-   i: Integer;
 
-   vNode: TBillsIDTreeNode;
 
-   GclNode: TGclNode;
 
- begin
 
-   with FProjectData.BillsMeasureData do
 
-   begin
 
-     for i := 0 to BillsMeasureTree.Count - 1 do
 
-     begin
 
-       vNode := TBillsIDTreeNode(BillsMeasureTree.Items[i]);
 
-       if not vNode.HasChildren and (vNode.Rec.B_Code.AsString <> '') then
 
-         GclNode := FGclControl.AddGclNode(vNode, AProjectIndex);
 
-     end;
 
-   end;
 
- end;
 
- procedure TrmHaBaiCustomizedData.FilterDealPay;
 
- var
 
-   sCurField, sPreField, sEndField: string;
 
-   procedure GatherCommonDealPayData;
 
-   var
 
-     iRec: Integer;
 
-     Rec, StageRec: TsdDataRecord;
 
-     DealPay: TPayNode;
 
-   begin
 
-     with FProjectData.DealPaymentData do
 
-     begin
 
-       for iRec := 0 to sddDealPayment.RecordCount - 1 do
 
-       begin
 
-         Rec := sddDealPayment.Records[iRec];
 
-         if SameText(Rec.ValueByName('Name').AsString, '本期完成计量') or
 
-            SameText(Rec.ValueByName('Name').AsString, '本期应付') or
 
-            SameText(Rec.ValueByName('Name').AsString, '本期实付') then
 
-           Continue;
 
-         StageRec := FProjectData.PhaseData.PhasePayData.PayRecord(Rec.ValueByName('ID').AsInteger);
 
-         DealPay := FDealPayControl.AddPayNode(Rec.ValueByName('Name').AsString, Rec.ValueByName('IsMinus').AsBoolean);
 
-         DealPay.CurTotalPrice := DealPay.CurTotalPrice + StageRec.ValueByName(sCurField).AsFloat;
 
-         DealPay.PreTotalPrice := DealPay.PreTotalPrice + StageRec.ValueByName(sPreField).AsFloat;
 
-         DealPay.EndTotalPrice := DealPay.EndTotalPrice + StageRec.ValueByName(sEndField).AsFloat;
 
-       end;
 
-     end;
 
-   end;
 
-   procedure GatherPayData;
 
-   var
 
-     Rec, StageRec: TsdDataRecord;
 
-   begin
 
-     Rec := FProjectData.DealPaymentData.DealPayRecord('本期应付');
 
-     StageRec := FProjectData.PhaseData.PhasePayData.PayRecord(Rec.ValueByName('ID').AsInteger);
 
-     with FDealPayControl.GatherPayNode do
 
-     begin
 
-       CurTotalPrice := CurTotalPrice + StageRec.ValueByName(sCurField).AsFloat;
 
-       PreTotalPrice := PreTotalPrice + StageRec.ValueByName(sPreField).AsFloat;
 
-       EndTotalPrice := EndTotalPrice + StageRec.ValueByName(sEndField).AsFloat;
 
-     end;
 
-   end;
 
- begin
 
-   sCurField := 'TotalPrice' + IntToStr(FProjectData.PhaseData.AuditCount);
 
-   sPreField := 'PreTotalPrice' + IntToStr(FProjectData.PhaseData.AuditCount);
 
-   sEndField := 'EndTotalPrice' + IntToStr(FProjectData.PhaseData.AuditCount);
 
-   GatherCommonDealPayData;
 
-   GatherPayData;
 
-   FDealPayControl.CalculateAll;
 
- end;
 
- procedure TrmHaBaiCustomizedData.WriteData;
 
- begin
 
-   case FhbGatherType of
 
-     hbgt2: WriteReport2;
 
-     hbgt3: WriteReport3;
 
-     hbgt3_1: WriteReport3_1;
 
-     hbgt4_1: WriteReport4_1;
 
-   end;
 
- end;
 
- procedure TrmHaBaiCustomizedData.WriteReport2;
 
-   procedure WriteGclChapter(AGclChapter: TGclChapter; const AName: string = '');
 
-   begin
 
-     cdsCustom2.Append;
 
-     if AGclChapter.ChapterBegin > 0 then
 
-       cdsCustom2Chapter.AsInteger := AGclChapter.ChapterBegin;
 
-     if AName = '' then
 
-       cdsCustom2Name.AsString := AGclChapter.Name
 
-     else
 
-       cdsCustom2Name.AsString := AName;
 
-     cdsCustom2TotalPrice.AsFloat := AGclChapter.TotalPrice;
 
-     cdsCustom2GTotalPrice.AsFloat := AGclChapter.TotalPrice;
 
-     cdsCustom2EndGatherTotalPrice.AsFloat := AGclChapter.EndGatherTotalPrice;
 
-     cdsCustom2PreGatherTotalPrice.AsFloat := AGclChapter.PreGatherTotalPrice;
 
-     cdsCustom2CurGatherTotalPrice.AsFloat := AGclChapter.CurGatherTotalPrice;
 
-     cdsCustom2Percent.AsFloat := AGclChapter.EndPercent;
 
-     cdsCustom2.Post;
 
-   end;
 
-   procedure WriteBlankRecord(const AName: string);
 
-   begin
 
-     cdsCustom2.Append;
 
-     cdsCustom2Name.AsString := AName;
 
-     cdsCustom2.Post;
 
-   end;
 
-   procedure WritePayNode(APayNode: TPayNode; const AName: string = '');
 
-   begin
 
-     cdsCustom2.Append;
 
-     if AName = '' then
 
-       cdsCustom2Name.AsString := APayNode.Name
 
-     else
 
-       cdsCustom2Name.AsString := AName;
 
-     cdsCustom2EndGatherTotalPrice.AsFloat := APayNode.EndTotalPrice;
 
-     cdsCustom2PreGatherTotalPrice.AsFloat := APayNode.PreTotalPrice;
 
-     cdsCustom2CurGatherTotalPrice.AsFloat := APayNode.CurTotalPrice;
 
-     cdsCustom2.Post;
 
-   end;
 
-   procedure WriteSpecialRecord;
 
-   begin
 
-     cdsCustom2.Append;
 
-     cdsCustom2Name.AsString := '合  计';
 
-     cdsCustom2EndGatherTotalPrice.AsFloat := FGclControl.GclChapterGather.EndGatherTotalPrice + FDealPayControl.PlusGather.EndTotalPrice;
 
-     cdsCustom2PreGatherTotalPrice.AsFloat := FGclControl.GclChapterGather.PreGatherTotalPrice + FDealPayControl.PlusGather.PreTotalPrice;
 
-     cdsCustom2CurGatherTotalPrice.AsFloat := FGclControl.GclChapterGather.CurGatherTotalPrice + FDealPayControl.PlusGather.CurTotalPrice;
 
-     cdsCustom2.Post;
 
-   end;
 
- var
 
-   iIndex: Integer;
 
- begin
 
-   for iIndex := 0 to FGclControl.GclChapterCount - 1 do
 
-     WriteGclChapter(FGclControl.GclChapter[iIndex]);
 
-   WriteGclChapter(FGclControl.GclChapterGather);
 
-   WriteGclChapter(FGclControl.GclChapterGather, '小  计');
 
-   WriteBlankRecord('价格调整');
 
-   WriteBlankRecord('违约罚金');
 
-   WriteBlankRecord('迟付款利息');
 
-   for iIndex := 0 to FDealPayControl.PlusPayCount - 1 do
 
-     WritePayNode(FDealPayControl.PlusPayNode[iIndex]);
 
-   WriteSpecialRecord;
 
-   for iIndex := 0 to FDealPayControl.MinusPayCount - 1 do
 
-     WritePayNode(FDealPayControl.MinusPayNode[iIndex]);
 
-   WritePayNode(FDealPayControl.GatherPayNode, '支  付');
 
- end;
 
- procedure TrmHaBaiCustomizedData.WriteReport3;
 
-   procedure WriteChapterName(AGclChapter: TGclChapter);
 
-   begin
 
-     cdsCustom3.Append;
 
-     cdsCustom3ChapterID.AsInteger := AGclChapter.ChapterID;
 
-     cdsCustom3InnerPartID.AsInteger := 1;
 
-     cdsCustom3B_Code.AsString := AGclChapter.ChapterName;
 
-     cdsCustom3Name.AsString := AGclChapter.Name;
 
-     cdsCustom3.Post;
 
-   end;
 
-   procedure WriteGclNodeData(AGclNode: TGclNode; AChapterID: Integer);
 
-   begin
 
-     cdsCustom3.Append;
 
-     cdsCustom3ChapterID.AsInteger := AChapterID;
 
-     cdsCustom3InnerPartID.AsInteger := 2;
 
-     cdsCustom3IndexCode.AsString := AGclNode.IndexCode;
 
-     cdsCustom3B_Code.AsString := AGclNode.B_Code;
 
-     cdsCustom3Name.AsString := AGclNode.Name;
 
-     cdsCustom3Units.AsString := AGclNode.Units;
 
-     cdsCustom3Price.AsFloat := AGclNode.Price;
 
-     cdsCustom3Quantity.AsFloat := AGclNode.Quantity;
 
-     cdsCustom3TotalPrice.AsFloat := AGclNode.TotalPrice;
 
-     cdsCustom3CurGatherQuantity.AsFloat := AGclNode.CurGatherQuantity;
 
-     cdsCustom3CurGatherTotalPrice.AsFloat := AGclNode.CurGatherTotalPrice;
 
-     cdsCustom3EndGatherQuantity.AsFloat := AGclNode.EndGatherQuantity;
 
-     cdsCustom3EndGatherTotalPrice.AsFloat := AGclNode.EndGatherTotalPrice;
 
-     cdsCustom3PreGatherQuantity.AsFloat := AGclNode.PreGatherQuantity;
 
-     cdsCustom3PreGatherTotalPrice.AsFloat := AGclNode.PreGatherTotalPrice;
 
-     cdsCustom3Percent.AsFloat := AGclNode.EndPercent;
 
-     cdsCustom3.Post;
 
-   end;
 
-   procedure WriteChapterGather(AGclChapter: TGclChapter; const AName: string = '');
 
-   begin
 
-     cdsCustom3.Append;
 
-     cdsCustom3ChapterID.AsInteger := AGclChapter.ChapterID;
 
-     cdsCustom3InnerPartID.AsInteger := 3;
 
-     if AName = '' then
 
-       cdsCustom3Name.AsString := AGclChapter.Name
 
-     else
 
-       cdsCustom3Name.AsString := AName;
 
-     cdsCustom3TotalPrice.AsFloat := AGclChapter.TotalPrice;
 
-     cdsCustom3CurGatherTotalPrice.AsFloat := AGclChapter.CurGatherTotalPrice;
 
-     cdsCustom3EndGatherTotalPrice.AsFloat := AGclChapter.EndGatherTotalPrice;
 
-     cdsCustom3PreGatherTotalPrice.AsFloat := AGclChapter.PreGatherTotalPrice;
 
-     cdsCustom3Percent.AsFloat := AGclChapter.EndPercent;
 
-     cdsCustom3.Post;
 
-   end;
 
-   procedure WriteGclChapterData(AGclChapter: TGclChapter);
 
-   var
 
-     iGcl: Integer;
 
-   begin
 
-     if AGclChapter.GclNodeCount = 0 then Exit;
 
-     WriteChapterName(AGclChapter);
 
-     for iGcl := 0 to AGclChapter.GclNodeCount - 1 do
 
-       WriteGclNodeData(AGclChapter.GclNode[iGcl], AGclChapter.ChapterID);
 
-     WriteChapterGather(AGclChapter, Format('%s  小计', [AGclChapter.ChapterName]));
 
-   end;
 
- var
 
-   iIndex: Integer;
 
- begin
 
-   for iIndex := 0 to FGclControl.GclChapterCount - 1 do
 
-     WriteGclChapterData(FGclControl.GclChapter[iIndex]);
 
-   WriteChapterGather(FGclControl.GclChapterGather, '第100章~第900章  合计');
 
- end;
 
- procedure TrmHaBaiCustomizedData.WriteReport3_1;
 
- var
 
-   iProject, iChapter: Integer;
 
-   sProjectName: string;
 
-   procedure WriteChapterName(AGclChapter: TGclChapter);
 
-   begin
 
-     cdsCustomProj.Append;
 
-     cdsCustomProjProjectID.AsInteger := iProject;
 
-     cdsCustomProjProjectName.AsString := sProjectName;
 
-     cdsCustomProjChapterID.AsInteger := AGclChapter.ChapterID;
 
-     cdsCustomProjInnerPartID.AsInteger := 1;
 
-     cdsCustomProjB_Code.AsString := AGclChapter.ChapterName;
 
-     cdsCustomProjName.AsString := AGclChapter.Name;
 
-     cdsCustomProj.Post;
 
-   end;
 
-   procedure WriteGclNodeData(AGclNode: TGclNode; AChapterID: Integer);
 
-   begin
 
-     cdsCustomProj.Append;
 
-     cdsCustomProjProjectID.AsInteger := iProject;
 
-     cdsCustomProjProjectName.AsString := sProjectName;
 
-     cdsCustomProjChapterID.AsInteger := AChapterID;
 
-     cdsCustomProjInnerPartID.AsInteger := 2;
 
-     cdsCustomProjIndexCode.AsString := AGclNode.IndexCode;
 
-     cdsCustomProjB_Code.AsString := AGclNode.B_Code;
 
-     cdsCustomProjName.AsString := AGclNode.Name;
 
-     cdsCustomProjUnits.AsString := AGclNode.Units;
 
-     cdsCustomProjPrice.AsFloat := AGclNode.Price;
 
-     cdsCustomProjQuantity.AsFloat := AGclNode.Quantity;
 
-     cdsCustomProjTotalPrice.AsFloat := AGclNode.TotalPrice;
 
-     cdsCustomProjCurGatherQuantity.AsFloat := AGclNode.CurGatherQuantity;
 
-     cdsCustomProjCurGatherTotalPrice.AsFloat := AGclNode.CurGatherTotalPrice;
 
-     cdsCustomProjEndGatherQuantity.AsFloat := AGclNode.EndGatherQuantity;
 
-     cdsCustomProjEndGatherTotalPrice.AsFloat := AGclNode.EndGatherTotalPrice;
 
-     cdsCustomProjP_CurGatherQuantity.AsFloat := AGclNode.P_CurGatherQuantity[iProject];
 
-     cdsCustomProjP_CurGatherTotalPrice.AsFloat := AGclNode.P_CurGatherTotalPrice[iProject];
 
-     cdsCustomProjP_EndGatherQuantity.AsFloat := AGclNode.P_EndGatherQuantity[iProject];
 
-     cdsCustomProjP_EndGatherTotalPrice.AsFloat := AGclNode.P_EndGatherTotalPrice[iProject];
 
-     cdsCustomProjCurPercent.AsFloat := AGclNode.CurPercent;
 
-     cdsCustomProjEndPercent.AsFloat := AGclNode.EndPercent;
 
-     cdsCustomProj.Post;
 
-   end;
 
-   procedure WriteChapterGather(AGclChapter: TGclChapter; const AName: string = '');
 
-   begin
 
-     cdsCustomProj.Append;
 
-     cdsCustomProjProjectID.AsInteger := iProject;
 
-     cdsCustomProjProjectName.AsString := sProjectName;
 
-     cdsCustomProjChapterID.AsInteger := AGclChapter.ChapterID;
 
-     cdsCustomProjInnerPartID.AsInteger := 3;
 
-     if AName = '' then
 
-       cdsCustomProjName.AsString := AGclChapter.Name
 
-     else
 
-       cdsCustomProjName.AsString := AName;
 
-     cdsCustomProjTotalPrice.AsFloat := AGclChapter.TotalPrice;
 
-     cdsCustomProjCurGatherTotalPrice.AsFloat := AGclChapter.CurGatherTotalPrice;
 
-     cdsCustomProjEndGatherTotalPrice.AsFloat := AGclChapter.EndGatherTotalPrice;
 
-     cdsCustomProjP_CurGatherTotalPrice.AsFloat := AGclChapter.P_CurGatherTotalPrice[iProject];
 
-     cdsCustomProjP_EndGatherTotalPrice.AsFloat := AGclChapter.P_EndGatherTotalPrice[iProject];
 
-     cdsCustomProjCurPercent.AsFloat := AGclChapter.CurPercent;
 
-     cdsCustomProjEndPercent.AsFloat := AGclChapter.EndPercent;
 
-     cdsCustomProj.Post;
 
-   end;
 
-   procedure WriteGclChapterData(AGclChapter: TGclChapter);
 
-   var
 
-     iGcl: Integer;
 
-   begin
 
-     if AGclChapter.GclNodeCount = 0 then Exit;
 
-     WriteChapterName(AGclChapter);
 
-     for iGcl := 0 to AGclChapter.GclNodeCount - 1 do
 
-       WriteGclNodeData(AGclChapter.GclNode[iGcl], AGclChapter.ChapterID);
 
-     WriteChapterGather(AGclChapter, Format('%s  小计', [AGclChapter.ChapterName]));
 
-   end;
 
- begin
 
-   for iProject := 0 to FGclControl.ProjectCount - 1 do
 
-   begin
 
-     sProjectName := FGclControl.ProjectName[iProject];
 
-     for iChapter := 0 to FGclControl.GclChapterCount - 1 do
 
-       WriteGclChapterData(FGclControl.GclChapter[iChapter]);
 
-     WriteChapterGather(FGclControl.GclChapterGather, '第100章至第900章  合计');
 
-   end;
 
- end;
 
- procedure TrmHaBaiCustomizedData.WriteReport4_1;
 
- var
 
-   iProject, iChapter, iSerial: Integer;
 
-   sProjectName: string;
 
-   procedure WriteGclNodeData(AGclNode: TGclNode; AChapterID: Integer);
 
-   begin
 
-     cdsCustomProj.Append;
 
-     cdsCustomProjProjectID.AsInteger := iProject;
 
-     cdsCustomProjProjectName.AsString := sProjectName;
 
-     cdsCustomProjChapterID.AsInteger := AChapterID;
 
-     cdsCustomProjInnerPartID.AsInteger := 2;
 
-     cdsCustomProjIndexCode.AsString := AGclNode.IndexCode;
 
-     cdsCustomProjB_Code.AsString := AGclNode.B_Code;
 
-     cdsCustomProjName.AsString := AGclNode.Name;
 
-     cdsCustomProjUnits.AsString := AGclNode.Units;
 
-     cdsCustomProjPrice.AsFloat := AGclNode.Price;
 
-     cdsCustomProjQuantity.AsFloat := AGclNode.Quantity;
 
-     cdsCustomProjTotalPrice.AsFloat := AGclNode.TotalPrice;
 
-     cdsCustomProjCurGatherQuantity.AsFloat := AGclNode.CurGatherQuantity;
 
-     cdsCustomProjCurGatherTotalPrice.AsFloat := AGclNode.CurGatherTotalPrice;
 
-     cdsCustomProjEndGatherQuantity.AsFloat := AGclNode.EndGatherQuantity;
 
-     cdsCustomProjEndGatherTotalPrice.AsFloat := AGclNode.EndGatherTotalPrice;
 
-     cdsCustomProjP_CurGatherQuantity.AsFloat := AGclNode.P_CurGatherQuantity[iProject];
 
-     cdsCustomProjP_CurGatherTotalPrice.AsFloat := AGclNode.P_CurGatherTotalPrice[iProject];
 
-     cdsCustomProjP_EndGatherQuantity.AsFloat := AGclNode.P_EndGatherQuantity[iProject];
 
-     cdsCustomProjP_EndGatherTotalPrice.AsFloat := AGclNode.P_EndGatherTotalPrice[iProject];
 
-     cdsCustomProjCurPercent.AsFloat := AGclNode.CurPercent;
 
-     cdsCustomProjEndPercent.AsFloat := AGclNode.EndPercent;
 
-     cdsCustomProj.Post;
 
-   end;
 
-   procedure WriteGclChapterData(AGclChapter: TGclChapter);
 
-   var
 
-     iGcl: Integer;
 
-   begin
 
-     if AGclChapter.GclNodeCount = 0 then Exit;
 
-     for iGcl := 0 to AGclChapter.GclNodeCount - 1 do
 
-       WriteGclNodeData(AGclChapter.GclNode[iGcl], AGclChapter.ChapterID);
 
-   end;
 
-   procedure WriteChapterGather(AGclChapter: TGclChapter; const AName: string = '');
 
-   begin
 
-     cdsCustomProj.Append;
 
-     cdsCustomProjProjectID.AsInteger := iProject;
 
-     cdsCustomProjProjectName.AsString := sProjectName;
 
-     cdsCustomProjChapterID.AsInteger := AGclChapter.ChapterID;
 
-     cdsCustomProjInnerPartID.AsInteger := 3;
 
-     if AName = '' then
 
-       cdsCustomProjName.AsString := AGclChapter.Name
 
-     else
 
-       cdsCustomProjName.AsString := AName;
 
-     cdsCustomProjTotalPrice.AsFloat := AGclChapter.TotalPrice;
 
-     cdsCustomProjCurGatherTotalPrice.AsFloat := AGclChapter.CurGatherTotalPrice;
 
-     cdsCustomProjEndGatherTotalPrice.AsFloat := AGclChapter.EndGatherTotalPrice;
 
-     cdsCustomProjP_CurGatherTotalPrice.AsFloat := AGclChapter.P_CurGatherTotalPrice[iProject];
 
-     cdsCustomProjP_EndGatherTotalPrice.AsFloat := AGclChapter.P_EndGatherTotalPrice[iProject];
 
-     cdsCustomProjCurPercent.AsFloat := AGclChapter.CurPercent;
 
-     cdsCustomProjEndPercent.AsFloat := AGclChapter.EndPercent;
 
-     cdsCustomProj.Post;
 
-   end;
 
-   procedure ResortSerialNo;
 
-   var
 
-     iSerialNo, iProject: Integer;
 
-   begin
 
-     iSerialNo := 1;
 
-     cdsCustomProj.First;
 
-     iProject := cdsCustomProjProjectID.AsInteger;
 
-     while not cdsCustomProj.Eof do
 
-     begin
 
-       if iProject <> cdsCustomProjProjectID.AsInteger then
 
-       begin
 
-         iProject := cdsCustomProjProjectID.AsInteger;
 
-         iSerialNo := 1;
 
-       end;
 
-       cdsCustomProj.Edit;
 
-       cdsCustomProjSerialNo.AsInteger := iSerialNo;
 
-       cdsCustomProj.Post;
 
-       Inc(iSerialNo);
 
-       cdsCustomProj.Next;
 
-     end;
 
-   end;
 
- begin
 
-   for iProject := 0 to FGclControl.ProjectCount - 1 do
 
-   begin
 
-     sProjectName := FGclControl.ProjectName[iProject];
 
-     for iChapter := 0 to FGclControl.GclChapterCount - 1 do
 
-       WriteGclChapterData(FGclControl.GclChapter[iChapter]);
 
-     WriteChapterGather(FGclControl.GclChapterGather, '第100章至第900章  合计');
 
-   end;
 
-   ResortSerialNo;
 
- end;
 
- procedure TrmHaBaiCustomizedData.WriteFlowData;
 
-   procedure AddNodeData(ANode: TBillsIDTreeNode);
 
-   begin
 
-     cdsCustom14.Append;
 
-     cdsCustom14IndexCode.AsString := ANode.Rec.IndexCode.AsString;
 
-     cdsCustom14B_Code.AsString := ANode.Rec.B_Code.AsString;
 
-     cdsCustom14Name.AsString := ANode.Rec.Name.AsString;
 
-     cdsCustom14Units.AsString := ANode.Rec.Units.AsString;
 
-     cdsCustom14Price.AsFloat := ANode.Rec.Price.AsFloat;
 
-     cdsCustom14Quantity.AsFloat := ANode.StageRec.GatherQuantity.AsFloat;
 
-     cdsCustom14TotalPrice.AsFloat := ANode.StageRec.GatherTotalPrice.AsFloat;
 
-     with FProjectData.PhaseData.ZJJLData do
 
-       if cdsZJJL.Locate('BillsID', ANode.ID, []) then
 
-         cdsCustom14CertificateCode.AsString := cdsZJJLCertificateCode.AsString;
 
-     cdsCustom14.Post;
 
-   end;
 
- var
 
-   iIndex: Integer;
 
-   vNode: TBillsIDTreeNode;
 
- begin
 
-   for iIndex := 0 to FProjectData.BillsMeasureData.BillsMeasureTree.Count - 1 do
 
-   begin
 
-     vNode := TBillsIDTreeNode(FProjectData.BillsMeasureData.BillsMeasureTree.Items[iIndex]);
 
-     if (not vNode.HasChildren) and (vNode.Rec.B_Code.AsString <> '') and
 
-         Assigned(vNode.StageRec) and (vNode.StageRec.GatherTotalPrice.AsFloat <> 0) then
 
-       AddNodeData(vNode);
 
-   end;
 
- end;
 
- { TGclNode }
 
- procedure TGclNode.Calculate;
 
- var
 
-   i: Integer;
 
- begin
 
-   FTotalPrice := FPrice * FQuantity;
 
-   FCurGatherTotalPrice := FPrice * FCurGatherQuantity;
 
-   FEndGatherTotalPrice := FPrice * FEndGatherQuantity;
 
-   FPreGatherTotalPrice := FPrice * FPreGatherQuantity;
 
-   for i := 0 to FProjectCount - 1 do
 
-   begin
 
-     FP_TotalPrice[i] := FPrice * FP_Quantity[i];
 
-     FP_CurGatherTotalPrice[i] := FPrice * FP_CurGatherQuantity[i];
 
-     FP_EndGatherTotalPrice[i] := FPrice * FP_EndGatherQuantity[i];
 
-   end;
 
- end;
 
- constructor TGclNode.Create(AProjectCount: Integer);
 
- begin
 
-   FProjectCount := AProjectCount;
 
-   SetLength(FP_Quantity, FProjectCount);
 
-   SetLength(FP_TotalPrice, FProjectCount);
 
-   SetLength(FP_CurGatherQuantity, FProjectCount);
 
-   SetLength(FP_CurGatherTotalPrice, FProjectCount);
 
-   SetLength(FP_EndGatherQuantity, FProjectCount);
 
-   SetLength(FP_EndGatherTotalPrice, FProjectCount);
 
- end;
 
- function TGclNode.GetCurPercent: Double;
 
- begin
 
-   if TotalPrice <> 0 then
 
-     Result := CurGatherTotalPrice/TotalPrice*100
 
-   else
 
-     Result := 0;
 
- end;
 
- function TGclNode.GetEndPercent: Double;
 
- begin
 
-   if TotalPrice <> 0 then
 
-     Result := EndGatherTotalPrice/TotalPrice*100
 
-   else
 
-     Result := 0;
 
- end;
 
- procedure TGclNode.SetB_Code(const Value: string);
 
- begin
 
-   FB_Code := Value;
 
-   FIndexCode := B_CodeToIndexCode(FB_Code);
 
- end;
 
- { TGclControl }
 
- function TGclControl.AddGclNode(ANode: TBillsIDTreeNode; AProjectIndex: Integer): TGclNode;
 
- begin
 
-   Result := FindGclNode(ANode.Rec);
 
-   if not Assigned(Result) then
 
-     Result := NewGclNode(ANode.Rec);
 
-   with ANode.Rec do
 
-   begin
 
-     Result.Quantity := Result.Quantity + Quantity.AsFloat;
 
-     Result.TotalPrice := Result.TotalPrice + TotalPrice.AsFloat;
 
-     Result.P_Quantity[AProjectIndex] := Result.P_Quantity[AProjectIndex] + Quantity.AsFloat;
 
-     Result.P_TotalPrice[AProjectIndex] := Result.P_TotalPrice[AProjectIndex] + TotalPrice.AsFloat;
 
-   end;
 
-   if Assigned(ANode.StageRec) then
 
-     with ANode.StageRec do
 
-     begin
 
-       Result.CurGatherQuantity := Result.CurGatherQuantity + GatherQuantity.AsFloat;
 
-       Result.CurGatherTotalPrice := Result.CurGatherTotalPrice + GatherTotalPrice.AsFloat;
 
-       Result.P_CurGatherQuantity[AProjectIndex] := Result.P_CurGatherQuantity[AProjectIndex] + GatherQuantity.AsFloat;
 
-       Result.P_CurGatherTotalPrice[AProjectIndex] := Result.P_CurGatherTotalPrice[AProjectIndex] + GatherTotalPrice.AsFloat;
 
-       Result.EndGatherQuantity := Result.EndGatherQuantity + EndGatherQuantity.AsFloat;
 
-       Result.EndGatherTotalPrice := Result.EndGatherTotalPrice + EndGatherTotalPrice.AsFloat;
 
-       Result.P_EndGatherQuantity[AProjectIndex] := Result.P_EndGatherQuantity[AProjectIndex] + EndGatherQuantity.AsFloat;
 
-       Result.P_EndGatherTotalPrice[AProjectIndex] := Result.P_EndGatherTotalPrice[AProjectIndex] + EndGatherTotalPrice.AsFloat;
 
-       Result.PreGatherQuantity := Result.PreGatherQuantity + PreGatherQuantity.AsFloat;
 
-       Result.PreGatherTotalPrice := Result.PreGatherTotalPrice + PreGatherTotalPrice.AsFloat;
 
-     end;
 
- end;
 
- function TGclControl.B_CodeToChapter(const AB_Code: string): Integer;
 
- var
 
-   sgs: TStrings;
 
-   iFirst, iSecond: Integer;
 
- begin
 
-   Result := 0;
 
-   sgs := TStringList.Create;
 
-   try
 
-     sgs.Delimiter := '-';
 
-     sgs.DelimitedText := AB_Code;
 
-     iFirst := StrToIntDef(sgs.Strings[0], 0);
 
-     Result := Trunc(iFirst/100);
 
-     if (Result >= 90) and (Result < 100) then
 
-       Result := 9;
 
-   finally
 
-     sgs.Free;
 
-   end;
 
- end;
 
- procedure TGclControl.CalculateChapterGather;
 
- var
 
-   iIndex, iProject: Integer;
 
-   vGclChapter: TGclChapter;
 
- begin
 
-   FGclChapterGather.TotalPrice := 0;
 
-   FGclChapterGather.CurGatherTotalPrice := 0;
 
-   FGclChapterGather.EndGatherTotalPrice := 0;
 
-   FGclChapterGather.PreGatherTotalPrice := 0;
 
-   for iProject := 0 to FProjectCount - 1 do
 
-   begin
 
-     FGclChapterGather.P_TotalPrice[iProject] := 0;
 
-     FGclChapterGather.P_CurGatherTotalPrice[iProject] := 0;
 
-     FGclChapterGather.P_EndGatherTotalPrice[iProject] := 0;
 
-   end;
 
-   for iIndex := 0 to FGclChapters.Count - 1 do
 
-   begin
 
-     vGclChapter := TGclChapter(FGclChapters.Items[iIndex]);
 
-     with FGclChapterGather do
 
-     begin
 
-       TotalPrice := TotalPrice + vGclChapter.TotalPrice;
 
-       CurGatherTotalPrice := CurGatherTotalPrice + vGclChapter.CurGatherTotalPrice;
 
-       EndGatherTotalPrice := EndGatherTotalPrice + vGclChapter.EndGatherTotalPrice;
 
-       PreGatherTotalPrice := PreGatherTotalPrice + vGclChapter.PreGatherTotalPrice;
 
-       for iProject := 0 to FProjectCount - 1 do
 
-       begin
 
-         P_TotalPrice[iProject] := P_TotalPrice[iProject] + vGclChapter.P_TotalPrice[iProject];
 
-         P_CurGatherTotalPrice[iProject] := P_CurGatherTotalPrice[iProject] + vGclChapter.P_CurGatherTotalPrice[iProject];
 
-         P_EndGatherTotalPrice[iProject] := P_EndGatherTotalPrice[iProject] + vGclChapter.P_EndGatherTotalPrice[iProject];
 
-       end;
 
-     end;
 
-   end;
 
- end;
 
- constructor TGclControl.Create(AProjectCount: Integer);
 
-   function CreateGclChapter(AChapterID: Integer; const AName: string): TGclChapter;
 
-   begin
 
-     Result := TGclChapter.Create(AChapterID, AName, FProjectCount);
 
-     FGclChapters.Add(Result);
 
-   end;
 
- begin
 
-   FProjectCount := AProjectCount;
 
-   SetLength(FProjectName, AProjectCount);
 
-   FGclNodes := TList.Create;
 
-   FGclChapters := TList.Create;
 
-   CreateGclChapter(1, '总 则');
 
-   CreateGclChapter(2, '路 基');
 
-   CreateGclChapter(3, '路 面');
 
-   CreateGclChapter(4, '桥梁、涵洞工程');
 
-   CreateGclChapter(5, '隧 道');
 
-   CreateGclChapter(6, '安全设计及预埋管线');
 
-   CreateGclChapter(7, '绿化及环境保护工程');
 
-   CreateGclChapter(8, '房建工程');
 
-   CreateGclChapter(9, '机电工程');
 
-   FOtherGcl := TGclChapter.Create(19, '非标准清单', FProjectCount);
 
-   FGclChapterGather := TGclChapter.Create(20, '第100章至900章合计', FProjectCount);
 
- end;
 
- destructor TGclControl.Destroy;
 
- begin
 
-   FOtherGcl.Free;
 
-   FGclChapterGather.Free;
 
-   ClearObjects(FGclChapters);
 
-   FGclChapters.Free;
 
-   ClearObjects(FGclNodes);
 
-   FGclNodes.Free;
 
- end;
 
- function TGclControl.FindGclNode(ARec: TBillsRecord): TGclNode;
 
- var
 
-   iIndex: Integer;
 
-   vGclNode: TGclNode;
 
-   bSameCode, bSameName, bSameUnits, bSamePrice: Boolean;
 
- begin
 
-   Result := nil;
 
-   for iIndex := 0 to FGclNodes.Count - 1 do
 
-   begin
 
-     vGclNode := TGclNode(FGclNodes.Items[iIndex]);
 
-     if (vGclNode.B_Code = ARec.B_Code.AsString) and
 
-         (vGclNode.Name = ARec.Name.AsString) and
 
-         (vGclNode.Units = ARec.Units.AsString) and
 
-         (vGclNode.Price = ARec.Price.AsFloat) then
 
-       begin
 
-         Result := vGclNode;
 
-         Break;
 
-       end;
 
-   end;
 
- end;
 
- function TGclControl.FindGclChapter(AChapterID: Integer): TGclChapter;
 
- var
 
-   iIndex: Integer;
 
-   vChapter: TGclChapter;
 
- begin
 
-   Result := nil;
 
-   for iIndex := 0 to FGclChapters.Count - 1 do
 
-   begin
 
-     vChapter := TGclChapter(FGclChapters.Items[iIndex]);
 
-     if vChapter.ChapterID = AChapterID then
 
-     begin
 
-       Result := vChapter;
 
-       Break;
 
-     end;
 
-   end;
 
- end;
 
- function TGclControl.GetGclChapter(AIndex: Integer): TGclChapter;
 
- begin
 
-   Result := TGclChapter(FGclChapters.Items[AIndex]);
 
- end;
 
- function TGclControl.GetGclChapterCount: Integer;
 
- begin
 
-   Result := FGclChapters.Count;
 
- end;
 
- procedure TGclControl.LinkGclChapter(AGclNode: TGclNode);
 
- var
 
-   iChapterID: Integer;
 
-   vChapter: TGclChapter;
 
- begin
 
-   iChapterID := B_CodeToChapter(AGclNode.B_Code);
 
-   vChapter := FindGclChapter(iChapterID);
 
-   if Assigned(vChapter) then
 
-     vChapter.AddGclNode(AGclNode)
 
-   else
 
-     FOtherGcl.AddGclNode(AGclNode);
 
- end;
 
- function TGclControl.NewGclNode(ARec: TBillsRecord): TGclNode;
 
- begin
 
-   Result := TGclNode.Create(FProjectCount);
 
-   FGclNodes.Add(Result);
 
-   Result.B_Code := ARec.B_Code.AsString;
 
-   Result.Name := ARec.Name.AsString;
 
-   Result.Units := ARec.Units.AsString;
 
-   Result.Price := ARec.Price.AsFloat;
 
-   LinkGclChapter(Result);
 
- end;
 
- procedure TGclControl.Calculate;
 
- var
 
-   i: Integer;
 
- begin
 
-   for i := 0 to GclChapterCount - 1 do
 
-     GclChapter[i].CalculateChapter;
 
-   CalculateChapterGather;
 
- end;
 
- procedure TGclControl.ReCalculateTotalPrice;
 
- var
 
-   iGcl: Integer;
 
- begin
 
-   for iGcl := 0 to FGclNodes.Count - 1 do
 
-     TGclNode(FGclNodes[iGcl]).Calculate;
 
- end;
 
- { TGclChapter }
 
- procedure TGclChapter.AddGclNode(AGclNode: TGclNode);
 
- begin
 
-   FGclNodes.Add(AGclNode);
 
- end;
 
- procedure TGclChapter.CalculateChapter;
 
- var
 
-   iIndex, iProject: Integer;
 
-   vGclNode: TGclNode;
 
- begin
 
-   FTotalPrice := 0;
 
-   FCurGatherTotalPrice := 0;
 
-   FEndGatherTotalPrice := 0;
 
-   FPreGatherTotalPrice := 0;
 
-   for iProject := 0 to FProjectCount - 1 do
 
-   begin
 
-     FP_TotalPrice[iProject] := 0;
 
-     FP_CurGatherTotalPrice[iProject] := 0;
 
-     FP_EndGatherTotalPrice[iProject] := 0;
 
-   end;
 
-   for iIndex := 0 to FGclNodes.Count - 1 do
 
-   begin
 
-     vGclNode := TGclNode(FGclNodes.Items[iIndex]);
 
-     FTotalPrice := FTotalPrice + vGclNode.TotalPrice;
 
-     FCurGatherTotalPrice := FCurGatherTotalPrice + vGclNode.FCurGatherTotalPrice;
 
-     FEndGatherTotalPrice := FEndGatherTotalPrice + vGclNode.FEndGatherTotalPrice;
 
-     FPreGatherTotalPrice := FPreGatherTotalPrice + vGclNode.FPreGatherTotalPrice;
 
-     for iProject := 0 to FProjectCount - 1 do
 
-     begin
 
-       FP_TotalPrice[iProject] := FP_TotalPrice[iProject] + vGclNode.P_TotalPrice[iProject];
 
-       FP_CurGatherTotalPrice[iProject] := FP_CurGatherTotalPrice[iProject] + vGclNode.P_CurGatherTotalPrice[iProject];
 
-       FP_EndGatherTotalPrice[iProject] := FP_EndGatherTotalPrice[iProject] + vGclNode.P_EndGatherTotalPrice[iProject];
 
-     end;
 
-   end;
 
- end;
 
- constructor TGclChapter.Create(AChapterID: Integer; const AName: string;
 
-   AProjectCount: Integer);
 
- begin
 
-   FGclNodes := TList.Create;
 
-   FChapterID := AChapterID;
 
-   if FChapterID < 19 then
 
-   begin
 
-     FChapterBegin := FChapterID * 100;
 
-     FChapterEnd := FChapterBegin + 99;
 
-     FChapterName := Format('第%d章', [FChapterBegin]);
 
-   end;
 
-   FName := AName;
 
-   FProjectCount := AProjectCount;
 
-   SetLength(FP_TotalPrice, FProjectCount);
 
-   SetLength(FP_CurGatherTotalPrice, FProjectCount);
 
-   SetLength(FP_EndGatherTotalPrice, FProjectCount);
 
- end;
 
- destructor TGclChapter.Destroy;
 
- begin
 
-   FGclNodes.Free;
 
-   inherited;
 
- end;
 
- function TGclChapter.GetCurPercent: Double;
 
- begin
 
-   if TotalPrice <> 0 then
 
-     Result := CurGatherTotalPrice/TotalPrice*100
 
-   else
 
-     Result := 0;
 
- end;
 
- function TGclChapter.GetEndPercent: Double;
 
- begin
 
-   if TotalPrice <> 0 then
 
-     Result := EndGatherTotalPrice/TotalPrice*100
 
-   else
 
-     Result := 0;
 
- end;
 
- function TGclChapter.GetGclNode(AIndex: Integer): TGclNode;
 
- begin
 
-   Result := TGclNode(FGclNodes.Items[AIndex]);
 
- end;
 
- function TGclChapter.GetGclNodeCount: Integer;
 
- begin
 
-   Result := FGclNodes.Count;
 
- end;
 
- { TDealPayControl }
 
- function TDealPayControl.AddMinusPayNode(const AName: string): TPayNode;
 
- begin
 
-   Result := FindMinusPayNode(AName);
 
-   if not Assigned(Result) then
 
-     Result := NewMinusPayNode(AName);
 
- end;
 
- function TDealPayControl.AddPayNode(const AName: string;
 
-   AIsMinus: Boolean): TPayNode;
 
- begin
 
-   if AIsMinus then
 
-     Result := AddMinusPayNode(AName)
 
-   else
 
-     Result := AddPlusPayNode(AName);
 
- end;
 
- function TDealPayControl.AddPlusPayNode(const AName: string): TPayNode;
 
- begin
 
-   Result := FindPlusPayNode(AName);
 
-   if not Assigned(Result) then
 
-     Result := NewPlusPayNode(AName);
 
- end;
 
- procedure TDealPayControl.CalculateAll;
 
- begin
 
-   CalculateGather(FPlusGather, FPlusPayNodes);
 
-   CalculateGather(FMinusGather, FMinusPayNodes);
 
- end;
 
- procedure TDealPayControl.CalculateGather(AGather: TPayNode; ANodes: TList);
 
- var
 
-   i: Integer;
 
-   vPayNode: TPayNode;
 
- begin
 
-   AGather.CurTotalPrice := 0;
 
-   AGather.EndTotalPrice := 0;
 
-   AGather.PreTotalPrice := 0;
 
-   for i := 0 to ANodes.Count - 1 do
 
-   begin
 
-     vPayNode := TPayNode(ANodes.Items[i]);
 
-     AGather.CurTotalPrice := AGather.CurTotalPrice + vPayNode.CurTotalPrice;
 
-     AGather.EndTotalPrice := AGather.EndTotalPrice + vPayNode.EndTotalPrice;
 
-     AGather.PreTotalPrice := AGather.PreTotalPrice + vPayNode.PreTotalPrice;
 
-   end;
 
- end;
 
- constructor TDealPayControl.Create;
 
- begin
 
-   FPlusPayNodes := TList.Create;
 
-   FMinusPayNodes := TList.Create;
 
-   FPlusGather := TPayNode.Create;
 
-   FMinusGather := TPayNode.Create;
 
-   FGatherPayNode := TPayNode.Create;
 
- end;
 
- destructor TDealPayControl.Destroy;
 
- begin
 
-   FGatherPayNode.Free;
 
-   FMinusGather.Free;
 
-   FPlusGather.Free;
 
-   ClearObjects(FMinusPayNodes);
 
-   FMinusPayNodes.Free;
 
-   ClearObjects(FPlusPayNodes);
 
-   FPlusPayNodes.Free;
 
-   inherited;
 
- end;
 
- function TDealPayControl.FindMinusPayNode(const AName: string): TPayNode;
 
- var
 
-   iIndex: Integer;
 
-   vPayNode: TPayNode;
 
- begin
 
-   Result := nil;
 
-   for iIndex := 0 to FMinusPayNodes.Count -1 do
 
-   begin
 
-     vPayNode := TPayNode(FMinusPayNodes.Items[iIndex]);
 
-     if (vPayNode.Name = AName) then
 
-     begin
 
-       Result := vPayNode;
 
-       Break;
 
-     end;
 
-   end;
 
- end;
 
- function TDealPayControl.FindPlusPayNode(const AName: string): TPayNode;
 
- var
 
-   iIndex: Integer;
 
-   vPayNode: TPayNode;
 
- begin
 
-   Result := nil;
 
-   for iIndex := 0 to FPlusPayNodes.Count -1 do
 
-   begin
 
-     vPayNode := TPayNode(FPlusPayNodes.Items[iIndex]);
 
-     if (vPayNode.Name = AName) then
 
-     begin
 
-       Result := vPayNode;
 
-       Break;
 
-     end;
 
-   end;
 
- end;
 
- function TDealPayControl.GetMinusPayCount: Integer;
 
- begin
 
-   Result := FMinusPayNodes.Count;
 
- end;
 
- function TDealPayControl.GetMinusPayNode(AIndex: Integer): TPayNode;
 
- begin
 
-   Result := TPayNode(FMinusPayNodes.Items[AIndex]);
 
- end;
 
- function TDealPayControl.GetPlusPayCount: Integer;
 
- begin
 
-   Result := FPlusPayNodes.Count;
 
- end;
 
- function TDealPayControl.GetPlusPayNode(AIndex: Integer): TPayNode;
 
- begin
 
-   Result := TPayNode(FPlusPayNodes.Items[AIndex]);
 
- end;
 
- function TDealPayControl.NewMinusPayNode(const AName: string): TPayNode;
 
- begin
 
-   Result := TPayNode.Create;
 
-   FMinusPayNodes.Add(Result);
 
-   Result.Name := AName;
 
-   Result.IsMinus := True;
 
- end;
 
- function TDealPayControl.NewPlusPayNode(const AName: string): TPayNode;
 
- begin
 
-   Result := TPayNode.Create;
 
-   FPlusPayNodes.Add(Result);
 
-   Result.Name := AName;
 
-   Result.IsMinus := False;
 
- end;
 
- end.
 
 
  |