|
@@ -4,7 +4,8 @@ unit stgGclSubGatherFile;
|
|
interface
|
|
interface
|
|
|
|
|
|
uses
|
|
uses
|
|
- stgGclSubGatherFileDm, ADODB, sdDB, stgGclGatherDm, SysUtils, StageDm, mDataRecord;
|
|
|
|
|
|
+ stgGclSubGatherFileDm, ADODB, sdDB, stgGclGatherDm, SysUtils, ProjectData,
|
|
|
|
+ StageDm, mDataRecord, BillsTree, DetailExcelImport, OExport;
|
|
|
|
|
|
type
|
|
type
|
|
TstgGclSubGatherFileHelper = class
|
|
TstgGclSubGatherFileHelper = class
|
|
@@ -35,16 +36,38 @@ type
|
|
TstgGclSubGatherFileImportor = class(TstgGclSubGatherFileHelper)
|
|
TstgGclSubGatherFileImportor = class(TstgGclSubGatherFileHelper)
|
|
private
|
|
private
|
|
procedure ClearOldData(AStageData: TStageData);
|
|
procedure ClearOldData(AStageData: TStageData);
|
|
- procedure ImportGatherData(AStageData: TStageData);
|
|
|
|
|
|
+ procedure ImportGatherData(AProjectData: TProjectData);
|
|
public
|
|
public
|
|
- procedure ImportGatherDataTo(AStageData: TStageData; const AFileName: string);
|
|
|
|
|
|
+ procedure ImportGatherDataTo(AProjectData: TProjectData; const AFileName: string);
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+ TstgGclSubGatherFileExcelImportor = class(TDetailExcelImport)
|
|
|
|
+ private
|
|
|
|
+ FCurRow: Integer;
|
|
|
|
+
|
|
|
|
+ FB_CodeCol: Integer;
|
|
|
|
+ FNameCol: Integer;
|
|
|
|
+ FUnitsCol: Integer;
|
|
|
|
+ FPriceCol: Integer;
|
|
|
|
+ FDealQuantityCol: Integer;
|
|
|
|
+
|
|
|
|
+ procedure ClearOldData(AStageData: TStageData);
|
|
|
|
+
|
|
|
|
+ function LoadColumnsFromHead(ASheet: TExportWorkSheet): Boolean;
|
|
|
|
+ procedure LoadGatherData(ASheet: TExportWorkSheet);
|
|
|
|
+ protected
|
|
|
|
+ procedure BeginImport; override;
|
|
|
|
+ procedure EndImport; override;
|
|
|
|
+
|
|
|
|
+ procedure Import; override;
|
|
end;
|
|
end;
|
|
|
|
|
|
implementation
|
|
implementation
|
|
|
|
|
|
|
|
|
|
uses
|
|
uses
|
|
- UtilMethods, ZhAPI, Connections, stgGclTables, ScAutoUpdateUnit, Math;
|
|
|
|
|
|
+ UtilMethods, ZhAPI, Connections, stgGclTables, ScAutoUpdateUnit, Math,
|
|
|
|
+ BillsMeasureDm;
|
|
|
|
|
|
{ TstgGclSubGatherFileExportor }
|
|
{ TstgGclSubGatherFileExportor }
|
|
|
|
|
|
@@ -170,35 +193,191 @@ begin
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure TstgGclSubGatherFileImportor.ImportGatherData(
|
|
procedure TstgGclSubGatherFileImportor.ImportGatherData(
|
|
- AStageData: TStageData);
|
|
|
|
|
|
+ AProjectData: TProjectData);
|
|
|
|
+
|
|
|
|
+ function FindBillsNode(ARec: TsdDataRecord): TBillsIDTreeNode;
|
|
|
|
+ var
|
|
|
|
+ i: Integer;
|
|
|
|
+ vNode: TBillsIDTreeNode;
|
|
|
|
+ begin
|
|
|
|
+ Result := nil;
|
|
|
|
+ for i := 0 to AProjectData.BillsMeasureData.BillsMeasureTree.Count - 1 do
|
|
|
|
+ begin
|
|
|
|
+ vNode := TBillsIDTreeNode(AProjectData.BillsMeasureData.BillsMeasureTree.Items[i]);
|
|
|
|
+ if (vNode.HasChildren) then Continue;
|
|
|
|
+ if (vNode.Rec.B_Code.AsString = ARec.ValueByName('B_Code').AsString) and
|
|
|
|
+ (vNode.Rec.Name.AsString = ARec.ValueByName('Name').AsString) and
|
|
|
|
+ (vNode.Rec.Units.AsString = ARec.ValueByName('Units').AsString) and
|
|
|
|
+ (CommonRoundTo(vNode.Rec.Price.AsFloat - ARec.ValueByName('Price').AsFloat, -6) = 0) then
|
|
|
|
+ begin
|
|
|
|
+ Result := vNode;
|
|
|
|
+ Break;
|
|
|
|
+ end;
|
|
|
|
+ end;
|
|
|
|
+ end;
|
|
|
|
+
|
|
var
|
|
var
|
|
i: Integer;
|
|
i: Integer;
|
|
|
|
+ vNode: TBillsIDTreeNode;
|
|
vOrgRec: TsdDataRecord;
|
|
vOrgRec: TsdDataRecord;
|
|
vStageRec: TStageRecord;
|
|
vStageRec: TStageRecord;
|
|
begin
|
|
begin
|
|
for i := 0 to GatherData.sddBills.RecordCount - 1 do
|
|
for i := 0 to GatherData.sddBills.RecordCount - 1 do
|
|
begin
|
|
begin
|
|
vOrgRec := GatherData.sddBills.Records[i];
|
|
vOrgRec := GatherData.sddBills.Records[i];
|
|
- if vOrgRec.ValueByName('IsSumBase').AsBoolean and vOrgRec.ValueByName('IsLeaf').AsBoolean then
|
|
|
|
|
|
+ vNode := FindBillsNode(vOrgRec);
|
|
|
|
+ if Assigned(vNode) then
|
|
begin
|
|
begin
|
|
- vStageRec := AStageData.StageRecordWithAdd(vOrgRec.ValueByName('ID').AsInteger);
|
|
|
|
|
|
+ vStageRec := AProjectData.PhaseData.StageData.StageRecordWithAdd(vNode.ID);
|
|
vStageRec.DealQuantity.AsFloat := vOrgRec.ValueByName('DealQuantity').AsFloat;
|
|
vStageRec.DealQuantity.AsFloat := vOrgRec.ValueByName('DealQuantity').AsFloat;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure TstgGclSubGatherFileImportor.ImportGatherDataTo(
|
|
procedure TstgGclSubGatherFileImportor.ImportGatherDataTo(
|
|
- AStageData: TStageData; const AFileName: string);
|
|
|
|
|
|
+ AProjectData: TProjectData; const AFileName: string);
|
|
begin
|
|
begin
|
|
Open(AFileName);
|
|
Open(AFileName);
|
|
- AStageData.sddStage.BeginUpdate;
|
|
|
|
- AStageData.BeforeBatchOperation;
|
|
|
|
|
|
+ AProjectData.PhaseData.StageData.sddStage.BeginUpdate;
|
|
|
|
+ AProjectData.PhaseData.StageData.BeforeBatchOperation;
|
|
try
|
|
try
|
|
- ClearOldData(AStageData);
|
|
|
|
- ImportGatherData(AStageData);
|
|
|
|
|
|
+ ClearOldData(AProjectData.PhaseData.StageData);
|
|
|
|
+ ImportGatherData(AProjectData);
|
|
finally
|
|
finally
|
|
- AStageData.AfterBatchOperation;
|
|
|
|
- AStageData.sddStage.EndUpdate;
|
|
|
|
|
|
+ AProjectData.PhaseData.StageData.AfterBatchOperation;
|
|
|
|
+ AProjectData.PhaseData.StageData.sddStage.EndUpdate;
|
|
|
|
+ end;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+{ TstgGclSubGatherFileExcelImportor }
|
|
|
|
+
|
|
|
|
+procedure TstgGclSubGatherFileExcelImportor.BeginImport;
|
|
|
|
+begin
|
|
|
|
+ inherited;
|
|
|
|
+ ProjectData.PhaseData.StageData.sddStage.BeginUpdate;
|
|
|
|
+ ProjectData.PhaseData.StageData.BeforeBatchOperation;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TstgGclSubGatherFileExcelImportor.ClearOldData(
|
|
|
|
+ AStageData: TStageData);
|
|
|
|
+var
|
|
|
|
+ i: Integer;
|
|
|
|
+ vRec: TStageRecord;
|
|
|
|
+begin
|
|
|
|
+ for i := 0 to AStageData.sddStage.RecordCount - 1 do
|
|
|
|
+ begin
|
|
|
|
+ vRec := TStageRecord(AStageData.sddStage.Records[i]);
|
|
|
|
+ vRec.DealQuantity.AsFloat := 0;
|
|
|
|
+ vRec.DealTotalPrice.AsFloat := 0;
|
|
|
|
+ vRec.DealFlag.AsInteger := 0;
|
|
|
|
+ vRec.DealFormula.AsString := '';
|
|
|
|
+ vRec.EndDealQuantity.AsFloat := vRec.PreDealQuantity.AsFloat;
|
|
|
|
+ vRec.EndDealTotalPrice.AsFloat := vRec.PreDealTotalPrice.AsFloat;
|
|
|
|
+ end;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TstgGclSubGatherFileExcelImportor.EndImport;
|
|
|
|
+begin
|
|
|
|
+ ProjectData.PhaseData.StageData.AfterBatchOperation;
|
|
|
|
+ ProjectData.PhaseData.StageData.sddStage.EndUpdate;
|
|
|
|
+ inherited;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TstgGclSubGatherFileExcelImportor.Import;
|
|
|
|
+begin
|
|
|
|
+ ClearOldData(ProjectData.PhaseData.StageData);
|
|
|
|
+
|
|
|
|
+ FCurRow := 0;
|
|
|
|
+ if LoadColumnsFromHead(OExport.OpenWorkSheet) then
|
|
|
|
+ LoadGatherData(OExport.OpenWorkSheet)
|
|
|
|
+ else
|
|
|
|
+ ErrorMessage('导入的Excel格式有误!');
|
|
|
|
+ inherited;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function TstgGclSubGatherFileExcelImportor.LoadColumnsFromHead(
|
|
|
|
+ ASheet: TExportWorkSheet): Boolean;
|
|
|
|
+var
|
|
|
|
+ vRow: TExportRow;
|
|
|
|
+ iCol: Integer;
|
|
|
|
+ sColName: String;
|
|
|
|
+begin
|
|
|
|
+ FB_CodeCol := -1;
|
|
|
|
+ FNameCol := -1;
|
|
|
|
+ FUnitsCol := -1;
|
|
|
|
+ FPriceCol := -1;
|
|
|
|
+ FDealQuantityCol := -1;
|
|
|
|
+
|
|
|
|
+ vRow := ASheet.Rows[FCurRow];
|
|
|
|
+ for iCol := 0 to vRow.Cells.Count - 1 do
|
|
|
|
+ begin
|
|
|
|
+ sColName := GetCellTrimStr(vRow, iCol);
|
|
|
|
+
|
|
|
|
+ if (sColName = '清单编号') then
|
|
|
|
+ FB_CodeCol := iCol
|
|
|
|
+ else if sColName = '名称' then
|
|
|
|
+ FNameCol := iCol
|
|
|
|
+ else if sColName = '单位' then
|
|
|
|
+ FUnitsCol := iCol
|
|
|
|
+ else if sColName = '单价' then
|
|
|
|
+ FPriceCol := iCol
|
|
|
|
+ else if (sColName = '合同计量') then
|
|
|
|
+ FDealQuantityCol := iCol;
|
|
|
|
+ end;
|
|
|
|
+ Result := (FB_CodeCol <> -1) and (FNameCol <> -1) and (FUnitsCol <> -1) and
|
|
|
|
+ (FPriceCol <> -1) and (FDealQuantityCol <> -1);
|
|
|
|
+ Inc(FCurRow);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TstgGclSubGatherFileExcelImportor.LoadGatherData(
|
|
|
|
+ ASheet: TExportWorkSheet);
|
|
|
|
+
|
|
|
|
+ function FindBillsNode(const AB_Code, AName, AUnits: string; APrice: Double): TBillsIDTreeNode;
|
|
|
|
+ var
|
|
|
|
+ i: Integer;
|
|
|
|
+ vNode: TBillsIDTreeNode;
|
|
|
|
+ begin
|
|
|
|
+ Result := nil;
|
|
|
|
+ for i := 0 to ProjectData.BillsMeasureData.BillsMeasureTree.Count - 1 do
|
|
|
|
+ begin
|
|
|
|
+ vNode := TBillsIDTreeNode(ProjectData.BillsMeasureData.BillsMeasureTree.Items[i]);
|
|
|
|
+ if (vNode.HasChildren) then Continue;
|
|
|
|
+ if (vNode.Rec.B_Code.AsString = AB_Code) and
|
|
|
|
+ (vNode.Rec.Name.AsString = AName) and
|
|
|
|
+ (vNode.Rec.Units.AsString = AUnits) and
|
|
|
|
+ (CommonRoundTo(vNode.Rec.Price.AsFloat - APrice, -6) = 0) then
|
|
|
|
+ begin
|
|
|
|
+ Result := vNode;
|
|
|
|
+ Break;
|
|
|
|
+ end;
|
|
|
|
+ end;
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+var
|
|
|
|
+ vRow: TExportRow;
|
|
|
|
+ sB_Code, sName, sUnits: string;
|
|
|
|
+ fPrice: Double;
|
|
|
|
+ vNode: TBillsIDTreeNode;
|
|
|
|
+ vStageRec: TStageRecord;
|
|
|
|
+begin
|
|
|
|
+ while FCurRow < ASheet.Rows.Count do
|
|
|
|
+ begin
|
|
|
|
+ vRow := ASheet.Rows[FCurRow];
|
|
|
|
+ Inc(FCurRow);
|
|
|
|
+
|
|
|
|
+ sB_Code := Trim(GetCellStr(vRow, FB_CodeCol));
|
|
|
|
+ sName := Trim(GetCellStr(vRow, FNameCol));
|
|
|
|
+ sUnits := Trim(GetCellStr(vRow, FUnitsCol));
|
|
|
|
+ fPrice := StrToFloatDef(GetCellStr(vRow, FPriceCol), 0);
|
|
|
|
+
|
|
|
|
+ if (sB_Code = '') then Continue;
|
|
|
|
+
|
|
|
|
+ vNode := FindBillsNode(sB_Code, sName, sUnits, fPrice);
|
|
|
|
+ if Assigned(vNode) then
|
|
|
|
+ begin
|
|
|
|
+ vStageRec := ProjectData.PhaseData.StageData.StageRecordWithAdd(vNode.ID);
|
|
|
|
+ vStageRec.DealQuantity.AsFloat := StrToFloatDef(GetCellStr(vRow, FDealQuantityCol), 0);
|
|
|
|
+ end;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|