| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344 | unit rmFxBillsAddDm;interfaceuses  SysUtils, Classes, ProjectData, PhaseData, StageDm, DB, DBClient,  MCacheTree, sdIDTree, sdDB;type  TrmFxBillsAddData = class(TDataModule)    cdsBills: TClientDataSet;    cdsBillsB_Code: TStringField;    cdsBillsCode: TStringField;    cdsBillsName: TWideStringField;    cdsBillsUnits: TWideStringField;    cdsBillsPrice: TFloatField;    cdsBillsQuantity: TFloatField;    cdsBillsTotalPrice: TFloatField;    cdsBillsQuantity1: TFloatField;    cdsBillsTotalPrice1: TFloatField;    cdsBillsQuantity2: TFloatField;    cdsBillsTotalPrice2: TFloatField;    cdsBillsQuantity3: TFloatField;    cdsBillsTotalPrice3: TFloatField;    cdsBillsQuantity4: TFloatField;    cdsBillsTotalPrice4: TFloatField;    cdsBillsQuantity5: TFloatField;    cdsBillsTotalPrice5: TFloatField;    cdsBillsQuantity6: TFloatField;    cdsBillsTotalPrice6: TFloatField;    cdsBillsQuantity7: TFloatField;    cdsBillsTotalPrice7: TFloatField;    cdsBillsQuantity8: TFloatField;    cdsBillsTotalPrice8: TFloatField;    cdsBillsQuantity9: TFloatField;    cdsBillsTotalPrice9: TFloatField;    cdsBillsQuantity10: TFloatField;    cdsBillsTotalPrice10: TFloatField;    cdsBillsQuantity11: TFloatField;    cdsBillsTotalPrice11: TFloatField;    cdsBillsQuantity12: TFloatField;    cdsBillsTotalPrice12: TFloatField;    cdsBillsQuantity13: TFloatField;    cdsBillsTotalPrice13: TFloatField;    cdsBillsQuantity14: TFloatField;    cdsBillsTotalPrice14: TFloatField;    cdsBillsQuantity15: TFloatField;    cdsBillsTotalPrice15: TFloatField;    cdsBillsQuantity16: TFloatField;    cdsBillsTotalPrice16: TFloatField;    cdsBillsQuantity17: TFloatField;    cdsBillsTotalPrice17: TFloatField;    cdsBillsQuantity18: TFloatField;    cdsBillsTotalPrice18: TFloatField;    cdsBillsQuantity19: TFloatField;    cdsBillsTotalPrice19: TFloatField;    cdsBillsQuantity20: TFloatField;    cdsBillsTotalPrice20: TFloatField;    cdsBillsQuantity21: TFloatField;    cdsBillsTotalPrice21: TFloatField;    cdsBillsQuantity22: TFloatField;    cdsBillsTotalPrice22: TFloatField;    cdsBillsQuantity23: TFloatField;    cdsBillsTotalPrice23: TFloatField;    cdsBillsQuantity24: TFloatField;    cdsBillsTotalPrice24: TFloatField;    cdsBillsQuantity25: TFloatField;    cdsBillsTotalPrice25: TFloatField;    cdsBillsQuantity26: TFloatField;    cdsBillsTotalPrice26: TFloatField;    cdsBillsQuantity27: TFloatField;    cdsBillsTotalPrice27: TFloatField;    cdsBillsQuantity28: TFloatField;    cdsBillsTotalPrice28: TFloatField;    cdsBillsQuantity29: TFloatField;    cdsBillsTotalPrice29: TFloatField;    cdsBillsQuantity30: TFloatField;    cdsBillsTotalPrice30: TFloatField;    cdsBillsQuantity31: TFloatField;    cdsBillsTotalPrice31: TFloatField;    cdsBillsQuantity32: TFloatField;    cdsBillsTotalPrice32: TFloatField;    cdsBillsQuantity33: TFloatField;    cdsBillsTotalPrice33: TFloatField;    cdsBillsQuantity34: TFloatField;    cdsBillsTotalPrice34: TFloatField;    cdsBillsQuantity35: TFloatField;    cdsBillsTotalPrice35: TFloatField;    cdsBillsQuantity36: TFloatField;    cdsBillsTotalPrice36: TFloatField;    cdsBillsQuantity37: TFloatField;    cdsBillsTotalPrice37: TFloatField;    cdsBillsQuantity38: TFloatField;    cdsBillsTotalPrice38: TFloatField;    cdsBillsQuantity39: TFloatField;    cdsBillsTotalPrice39: TFloatField;    cdsBillsQuantity40: TFloatField;    cdsBillsTotalPrice40: TFloatField;    cdsBillsQuantity41: TFloatField;    cdsBillsTotalPrice41: TFloatField;    cdsBillsQuantity42: TFloatField;    cdsBillsTotalPrice42: TFloatField;    cdsBillsQuantity43: TFloatField;    cdsBillsTotalPrice43: TFloatField;    cdsBillsQuantity44: TFloatField;    cdsBillsTotalPrice44: TFloatField;    cdsBillsQuantity45: TFloatField;    cdsBillsTotalPrice45: TFloatField;    cdsBillsQuantity46: TFloatField;    cdsBillsTotalPrice46: TFloatField;    cdsBillsQuantity47: TFloatField;    cdsBillsTotalPrice47: TFloatField;    cdsBillsQuantity48: TFloatField;    cdsBillsTotalPrice48: TFloatField;    cdsBillsQuantity49: TFloatField;    cdsBillsTotalPrice49: TFloatField;    cdsBillsQuantity50: TFloatField;    cdsBillsTotalPrice50: TFloatField;    cdsBillsMemoStr: TWideStringField;  private    FProjectData: TProjectData;    FAllPhaseCacheTree: TAllPhaseCacheTree;    function AddBills(ANode: TsdIDTreeNode; AParent: TAllPhaseCacheNode): TAllPhaseCacheNode;    procedure LoadStageData(AStageData: TStageData; APhaseIndex: Integer);    procedure LoadPhaseData(APhaseIndex: Integer);    procedure WriteBills(ANode: TAllPhaseCacheNode);  public    function AssignData(AProjectData: TProjectData): TDataSet;  end;implementationuses CacheTree;{$R *.dfm}{ TrmFxBillsAddData }function TrmFxBillsAddData.AddBills(ANode: TsdIDTreeNode;  AParent: TAllPhaseCacheNode): TAllPhaseCacheNode;begin  if not Assigned(ANode) then Exit;  Result := FAllPhaseCacheTree.AddNode(ANode.ID, AParent, nil);  Result.Code := ANode.Rec.ValueByName('Code').AsString;  Result.B_Code := ANode.Rec.ValueByName('B_Code').AsString;  Result.Name := ANode.Rec.ValueByName('Name').AsString;  Result.Units := ANode.Rec.ValueByName('Units').AsString;  Result.Price := ANode.Rec.ValueByName('Price').AsFloat;  Result.Quantity := ANode.Rec.ValueByName('Quantity').AsFloat;  Result.TotalPrice := ANode.Rec.ValueByName('TotalPrice').AsFloat;    AddBills(ANode.FirstChild, Result);  AddBills(ANode.NextSibling, AParent);end;function TrmFxBillsAddData.AssignData(  AProjectData: TProjectData): TDataSet;var  iPhase: Integer;begin  FProjectData := AProjectData;  cdsBills.DisableControls;  cdsBills.Active := True;  cdsBills.EmptyDataSet;  FAllPhaseCacheTree := TAllPhaseCacheTree.Create;  try    AddBills(FProjectData.BillsCompileData.BillsCompileTree.FirstNode, nil);    for iPhase := 1 to FProjectData.ProjProperties.PhaseCount do      LoadPhaseData(iPhase);    WriteBills(TAllPhaseCacheNode(FAllPhaseCacheTree.FirstNode));  finally    Result := cdsBills;    FAllPhaseCacheTree.Free;    cdsBills.EnableControls;  end;end;procedure TrmFxBillsAddData.LoadPhaseData(APhaseIndex: Integer);var  PhaseData: TPhaseData;  StageData: TStageData;begin  PhaseData := TPhaseData.Create(nil);  try    PhaseData.SimpleOpen(Format('%s\Phase%d.dat', [FProjectData.TempPath, APhaseIndex]));    if PhaseData.IsLastStage then      LoadStageData(PhaseData.StageData, APhaseIndex)    else    begin      try        StageData := TStageData.Create(PhaseData);        StageData.TableName := PhaseData.StageTableName[PhaseData.AuditCount];        StageData.Open(PhaseData.ADOConnection);        LoadStageData(StageData, APhaseIndex);      finally        StageData.Free;      end;    end;  finally    PhaseData.Free;  end;end;procedure TrmFxBillsAddData.LoadStageData(AStageData: TStageData;  APhaseIndex: Integer);var  i: Integer;  StageRec: TsdDataRecord;  stnNode: TsdIDTreeNode;  Node: TAllPhaseCacheNode;begin  for i := 0 to AStageData.sddStage.RecordCount - 1 do  begin    StageRec := AStageData.sddStage.Records[i];    with FProjectData.BillsCompileData.BillsCompileTree do      stnNode := FindNode(StageRec.ValueByName('BillsID').AsInteger);    Node := FAllPhaseCacheTree.FindNode(StageRec.ValueByName('BillsID').AsInteger);    if Assigned(Node) then    begin      Node.FP_Quantity[APhaseIndex] := StageRec.ValueByName('GatherQuantity').AsFloat;      Node.FP_TotalPrice[APhaseIndex] := StageRec.ValueByName('GatherTotalPrice').AsFloat;    end;  end;end;procedure TrmFxBillsAddData.WriteBills(ANode: TAllPhaseCacheNode);begin  if not Assigned(ANode) then Exit;  cdsBills.Append;  cdsBillsCode.AsString := ANode.Code;  cdsBillsB_Code.AsString := ANode.B_Code;  cdsBillsName.AsString := ANode.Name;  cdsBillsUnits.AsString := ANode.Units;  cdsBillsPrice.AsFloat := ANode.Price;  cdsBillsQuantity.AsFloat := ANode.Quantity;  cdsBillsTotalPrice.AsFloat := ANode.TotalPrice;  cdsBillsQuantity1.AsFloat := ANode.FP_Quantity[1];  cdsBillsTotalPrice1.AsFloat := ANode.FP_TotalPrice[1];  cdsBillsQuantity2.AsFloat := ANode.FP_Quantity[2];  cdsBillsTotalPrice2.AsFloat := ANode.FP_TotalPrice[2];  cdsBillsQuantity3.AsFloat := ANode.FP_Quantity[3];  cdsBillsTotalPrice3.AsFloat := ANode.FP_TotalPrice[3];  cdsBillsQuantity4.AsFloat := ANode.FP_Quantity[4];  cdsBillsTotalPrice4.AsFloat := ANode.FP_TotalPrice[4];  cdsBillsQuantity5.AsFloat := ANode.FP_Quantity[5];  cdsBillsTotalPrice5.AsFloat := ANode.FP_TotalPrice[5];  cdsBillsQuantity6.AsFloat := ANode.FP_Quantity[6];  cdsBillsTotalPrice6.AsFloat := ANode.FP_TotalPrice[6];  cdsBillsQuantity7.AsFloat := ANode.FP_Quantity[7];  cdsBillsTotalPrice7.AsFloat := ANode.FP_TotalPrice[7];  cdsBillsQuantity8.AsFloat := ANode.FP_Quantity[8];  cdsBillsTotalPrice8.AsFloat := ANode.FP_TotalPrice[8];  cdsBillsQuantity9.AsFloat := ANode.FP_Quantity[9];  cdsBillsTotalPrice9.AsFloat := ANode.FP_TotalPrice[9];  cdsBillsQuantity10.AsFloat := ANode.FP_Quantity[10];  cdsBillsTotalPrice10.AsFloat := ANode.FP_TotalPrice[10];  cdsBillsQuantity11.AsFloat := ANode.FP_Quantity[11];  cdsBillsTotalPrice11.AsFloat := ANode.FP_TotalPrice[11];  cdsBillsQuantity12.AsFloat := ANode.FP_Quantity[12];  cdsBillsTotalPrice12.AsFloat := ANode.FP_TotalPrice[12];  cdsBillsQuantity13.AsFloat := ANode.FP_Quantity[13];  cdsBillsTotalPrice13.AsFloat := ANode.FP_TotalPrice[13];  cdsBillsQuantity14.AsFloat := ANode.FP_Quantity[14];  cdsBillsTotalPrice14.AsFloat := ANode.FP_TotalPrice[14];  cdsBillsQuantity15.AsFloat := ANode.FP_Quantity[15];  cdsBillsTotalPrice15.AsFloat := ANode.FP_TotalPrice[15];  cdsBillsQuantity16.AsFloat := ANode.FP_Quantity[16];  cdsBillsTotalPrice16.AsFloat := ANode.FP_TotalPrice[16];  cdsBillsQuantity17.AsFloat := ANode.FP_Quantity[17];  cdsBillsTotalPrice17.AsFloat := ANode.FP_TotalPrice[17];  cdsBillsQuantity18.AsFloat := ANode.FP_Quantity[18];  cdsBillsTotalPrice18.AsFloat := ANode.FP_TotalPrice[18];  cdsBillsQuantity19.AsFloat := ANode.FP_Quantity[19];  cdsBillsTotalPrice19.AsFloat := ANode.FP_TotalPrice[19];  cdsBillsQuantity20.AsFloat := ANode.FP_Quantity[20];  cdsBillsTotalPrice20.AsFloat := ANode.FP_TotalPrice[20];  cdsBillsQuantity21.AsFloat := ANode.FP_Quantity[21];  cdsBillsTotalPrice21.AsFloat := ANode.FP_TotalPrice[21];  cdsBillsQuantity22.AsFloat := ANode.FP_Quantity[22];  cdsBillsTotalPrice22.AsFloat := ANode.FP_TotalPrice[22];  cdsBillsQuantity23.AsFloat := ANode.FP_Quantity[23];  cdsBillsTotalPrice23.AsFloat := ANode.FP_TotalPrice[23];  cdsBillsQuantity24.AsFloat := ANode.FP_Quantity[24];  cdsBillsTotalPrice24.AsFloat := ANode.FP_TotalPrice[24];  cdsBillsQuantity25.AsFloat := ANode.FP_Quantity[25];  cdsBillsTotalPrice25.AsFloat := ANode.FP_TotalPrice[25];  cdsBillsQuantity26.AsFloat := ANode.FP_Quantity[26];  cdsBillsTotalPrice26.AsFloat := ANode.FP_TotalPrice[26];  cdsBillsQuantity27.AsFloat := ANode.FP_Quantity[27];  cdsBillsTotalPrice27.AsFloat := ANode.FP_TotalPrice[27];  cdsBillsQuantity28.AsFloat := ANode.FP_Quantity[28];  cdsBillsTotalPrice28.AsFloat := ANode.FP_TotalPrice[28];  cdsBillsQuantity29.AsFloat := ANode.FP_Quantity[29];  cdsBillsTotalPrice29.AsFloat := ANode.FP_TotalPrice[29];  cdsBillsQuantity30.AsFloat := ANode.FP_Quantity[30];  cdsBillsTotalPrice30.AsFloat := ANode.FP_TotalPrice[30];  cdsBillsQuantity31.AsFloat := ANode.FP_Quantity[31];  cdsBillsTotalPrice31.AsFloat := ANode.FP_TotalPrice[31];  cdsBillsQuantity32.AsFloat := ANode.FP_Quantity[32];  cdsBillsTotalPrice32.AsFloat := ANode.FP_TotalPrice[32];  cdsBillsQuantity33.AsFloat := ANode.FP_Quantity[33];  cdsBillsTotalPrice33.AsFloat := ANode.FP_TotalPrice[33];  cdsBillsQuantity34.AsFloat := ANode.FP_Quantity[34];  cdsBillsTotalPrice34.AsFloat := ANode.FP_TotalPrice[34];  cdsBillsQuantity35.AsFloat := ANode.FP_Quantity[35];  cdsBillsTotalPrice35.AsFloat := ANode.FP_TotalPrice[35];  cdsBillsQuantity36.AsFloat := ANode.FP_Quantity[36];  cdsBillsTotalPrice36.AsFloat := ANode.FP_TotalPrice[36];  cdsBillsQuantity37.AsFloat := ANode.FP_Quantity[37];  cdsBillsTotalPrice37.AsFloat := ANode.FP_TotalPrice[37];  cdsBillsQuantity38.AsFloat := ANode.FP_Quantity[38];  cdsBillsTotalPrice38.AsFloat := ANode.FP_TotalPrice[38];  cdsBillsQuantity39.AsFloat := ANode.FP_Quantity[39];  cdsBillsTotalPrice39.AsFloat := ANode.FP_TotalPrice[39];  cdsBillsQuantity40.AsFloat := ANode.FP_Quantity[40];  cdsBillsTotalPrice40.AsFloat := ANode.FP_TotalPrice[40];  cdsBillsQuantity41.AsFloat := ANode.FP_Quantity[41];  cdsBillsTotalPrice41.AsFloat := ANode.FP_TotalPrice[41];  cdsBillsQuantity42.AsFloat := ANode.FP_Quantity[42];  cdsBillsTotalPrice42.AsFloat := ANode.FP_TotalPrice[42];  cdsBillsQuantity43.AsFloat := ANode.FP_Quantity[43];  cdsBillsTotalPrice43.AsFloat := ANode.FP_TotalPrice[43];  cdsBillsQuantity44.AsFloat := ANode.FP_Quantity[44];  cdsBillsTotalPrice44.AsFloat := ANode.FP_TotalPrice[44];  cdsBillsQuantity45.AsFloat := ANode.FP_Quantity[45];  cdsBillsTotalPrice45.AsFloat := ANode.FP_TotalPrice[45];  cdsBillsQuantity46.AsFloat := ANode.FP_Quantity[46];  cdsBillsTotalPrice46.AsFloat := ANode.FP_TotalPrice[46];  cdsBillsQuantity47.AsFloat := ANode.FP_Quantity[47];  cdsBillsTotalPrice47.AsFloat := ANode.FP_TotalPrice[47];  cdsBillsQuantity48.AsFloat := ANode.FP_Quantity[48];  cdsBillsTotalPrice48.AsFloat := ANode.FP_TotalPrice[48];  cdsBillsQuantity49.AsFloat := ANode.FP_Quantity[49];  cdsBillsTotalPrice49.AsFloat := ANode.FP_TotalPrice[49];  cdsBillsQuantity50.AsFloat := ANode.FP_Quantity[50];  cdsBillsTotalPrice50.AsFloat := ANode.FP_TotalPrice[50];  cdsBills.Post;  WriteBills(TAllPhaseCacheNode(ANode.FirstChild));  WriteBills(TAllPhaseCacheNode(ANode.NextSibling));end;end.
 |