|
@@ -104,72 +104,6 @@ type
|
|
|
property WithoutGclBills: Boolean read FWithoutGclBills write FWithoutGclBills;
|
|
|
end;
|
|
|
|
|
|
- TGclBillsExcelImport = class(TExcelImport)
|
|
|
- private
|
|
|
- FParentID: Integer;
|
|
|
- FSelectSheets: TList;
|
|
|
- FCacheTree: TGclCacheTree;
|
|
|
- FCurRow: Integer;
|
|
|
-
|
|
|
- FB_CodeCol: Integer;
|
|
|
- FNameCol: Integer;
|
|
|
- FUnitsCol: Integer;
|
|
|
- FPriceCol: Integer;
|
|
|
- FQuantityCol: Integer;
|
|
|
-
|
|
|
- procedure BeginImport; override;
|
|
|
- procedure EndImport; override;
|
|
|
-
|
|
|
- procedure LoadNode(ASheet: TSpreadSheet);
|
|
|
- procedure ImportSheet(ASheet: TSpreadSheet);
|
|
|
-
|
|
|
- procedure WriteNode(ADataSet: TsdDataSet; ANode: TGclCacheNode);
|
|
|
- procedure WriteNodes(ADataSet: TsdDataSet);
|
|
|
-
|
|
|
- procedure Import; override;
|
|
|
- public
|
|
|
- property ParentID: Integer read FParentID write FParentID;
|
|
|
- end;
|
|
|
-
|
|
|
- // 清单单价
|
|
|
- TBillsPriceExcelImport = class(TExcelImport)
|
|
|
- private
|
|
|
- FCurRow: Integer;
|
|
|
-
|
|
|
- FB_CodeCol: Integer;
|
|
|
- FNameCol: Integer;
|
|
|
- FPriceCol: Integer;
|
|
|
-
|
|
|
- procedure BeginImport; override;
|
|
|
- procedure EndImport; override;
|
|
|
-
|
|
|
- procedure LoadColumnsFromHead(ASheet: TSpreadSheet);
|
|
|
- procedure UpdateBillsPrice(const AB_Code: string; APrice: Double);
|
|
|
- procedure ImportBillsPriceData(ASheet: TSpreadSheet);
|
|
|
- procedure Import; override;
|
|
|
- end;
|
|
|
-
|
|
|
- // 合同清单
|
|
|
- {TDealBillsExcelImport = class(TExcelImport)
|
|
|
- private
|
|
|
- FCurRow: Integer;
|
|
|
- FBillsID: Integer;
|
|
|
-
|
|
|
- FB_CodeCol: Integer;
|
|
|
- FNameCol: Integer;
|
|
|
- FUnitsCol: Integer;
|
|
|
- FPriceCol: Integer;
|
|
|
- FQuantityCol: Integer;
|
|
|
- FTotalPriceCol: Integer;
|
|
|
-
|
|
|
- procedure BeginImport; override;
|
|
|
- procedure EndImport; override;
|
|
|
-
|
|
|
- procedure LoadColumnsFromHead(ASheet: TSpreadSheet);
|
|
|
- procedure LoadDealBillsData(ASheet: TSpreadSheet);
|
|
|
- procedure Import; override;
|
|
|
- end;}
|
|
|
-
|
|
|
implementation
|
|
|
|
|
|
uses Variants, CacheTree, SysUtils, UtilMethods, sdDataSet, BillsDm,
|
|
@@ -662,343 +596,4 @@ begin
|
|
|
end;
|
|
|
end;
|
|
|
|
|
|
-{ TBillsPriceExcelImport }
|
|
|
-
|
|
|
-procedure TBillsPriceExcelImport.BeginImport;
|
|
|
-begin
|
|
|
- ShowProgressHint('导入Excel清单单价', 100);
|
|
|
- FProjectData.BillsData.sddBills.BeginUpdate;
|
|
|
-end;
|
|
|
-
|
|
|
-procedure TBillsPriceExcelImport.EndImport;
|
|
|
-begin
|
|
|
- FProjectData.BillsData.sddBills.EndUpdate;
|
|
|
- UpdateProgressHint('正在计算导入后的数据');
|
|
|
- FProjectData.BillsCompileData.CalculateAll;
|
|
|
- CloseProgressHint;
|
|
|
-end;
|
|
|
-
|
|
|
-procedure TBillsPriceExcelImport.Import;
|
|
|
-begin
|
|
|
- LoadColumnsFromHead(FMSExcel.Sheets.Spreadsheet(0));
|
|
|
- ImportBillsPriceData(FMSExcel.Sheets.Spreadsheet(0));
|
|
|
-end;
|
|
|
-
|
|
|
-procedure TBillsPriceExcelImport.ImportBillsPriceData(ASheet: TSpreadSheet);
|
|
|
-
|
|
|
- function CheckIsBillsCode(ACode: string): Boolean;
|
|
|
- const
|
|
|
- FBillsCodeSet: set of char = ['0'..'9', '-', 'a'..'z', 'A'..'Z'];
|
|
|
- var
|
|
|
- I: Integer;
|
|
|
- begin
|
|
|
- Result := True;
|
|
|
- I := 1;
|
|
|
- while I < Length(ACode) do
|
|
|
- if ACode[I] in FBillsCodeSet then
|
|
|
- Inc(I)
|
|
|
- else
|
|
|
- begin
|
|
|
- Result := False;
|
|
|
- Break;
|
|
|
- end;
|
|
|
- end;
|
|
|
-
|
|
|
-var
|
|
|
- iPos: Integer;
|
|
|
- sB_Code: string;
|
|
|
- fPrice: Double;
|
|
|
-begin
|
|
|
- UpdateProgressHint('写入读取的Excel数据');
|
|
|
- UpdateProgressPosition(0);
|
|
|
- while (FCurRow < ASheet.Cells.UsedRowCount) do
|
|
|
- begin
|
|
|
- sB_Code := GetCellTrimText(ASheet, FB_CodeCol, FCurRow);
|
|
|
- if (sB_Code <> '') and CheckIsBillsCode(sB_Code) then
|
|
|
- begin
|
|
|
- fPrice := StrToFloatDef(VarToStrDef(ASheet.Cells.GetValue(FPriceCol, FCurRow), ''), 0);
|
|
|
- UpdateBillsPrice(sB_Code, fPrice);
|
|
|
- end;
|
|
|
- Inc(FCurRow);
|
|
|
- iPos := FCurRow * 100 div ASheet.Cells.UsedRowCount;
|
|
|
- UpdateProgressPosition(iPos);
|
|
|
- end;
|
|
|
- UpdateProgressPosition(100);
|
|
|
-end;
|
|
|
-
|
|
|
-procedure TBillsPriceExcelImport.LoadColumnsFromHead(ASheet: TSpreadSheet);
|
|
|
-var
|
|
|
- iCol: Integer;
|
|
|
- sColName: string;
|
|
|
-begin
|
|
|
- FB_CodeCol := -1;
|
|
|
- FNameCol := -1;
|
|
|
- FPriceCol := -1;
|
|
|
- while ((FB_CodeCol = -1) or (FPriceCol = -1)) and (FCurRow < ASheet.Cells.UsedRowCount) do
|
|
|
- begin
|
|
|
- for iCol := 0 to ASheet.Cells.UsedColCount do
|
|
|
- begin
|
|
|
- sColName := GetCellTrimText(ASheet, iCol, FCurRow);
|
|
|
- if SameText(sColName, '清单编号') or SameText(sColName, '子目号') then
|
|
|
- FB_CodeCol := iCol
|
|
|
- else if SameText(sColName, '名称') then
|
|
|
- FNameCol := iCol
|
|
|
- else if Pos('单价', sColName) = 1 then
|
|
|
- FPriceCol := iCol;
|
|
|
- end;
|
|
|
- Inc(FCurRow);
|
|
|
- end;
|
|
|
-end;
|
|
|
-
|
|
|
-procedure TBillsPriceExcelImport.UpdateBillsPrice(const AB_Code: string;
|
|
|
- APrice: Double);
|
|
|
-var
|
|
|
- iIndex: Integer;
|
|
|
- Rec: TBillsRecord;
|
|
|
-begin
|
|
|
- with FProjectData.BillsData do
|
|
|
- begin
|
|
|
- for iIndex := 0 to sddBills.RecordCount - 1 do
|
|
|
- begin
|
|
|
- Rec := TBillsRecord(sddBills.Records[iIndex]);
|
|
|
- if SameText(AB_Code, Rec.B_Code.AsString) then
|
|
|
- Rec.Price.AsFloat := PriceRoundTo(APrice);
|
|
|
- end;
|
|
|
- end;
|
|
|
-end;
|
|
|
-
|
|
|
-{ TDealBillsExcelImport }
|
|
|
-
|
|
|
-{procedure TDealBillsExcelImport.BeginImport;
|
|
|
-begin
|
|
|
- FProjectData.DealBillsData.sddDealBills.BeginUpdate;
|
|
|
-end;
|
|
|
-
|
|
|
-procedure TDealBillsExcelImport.EndImport;
|
|
|
-begin
|
|
|
- FProjectData.DealBillsData.sddDealBills.EndUpdate;
|
|
|
-end;
|
|
|
-
|
|
|
-procedure TDealBillsExcelImport.Import;
|
|
|
-begin
|
|
|
- LoadColumnsFromHead(FMSExcel.Sheets.Spreadsheet(0));
|
|
|
- FBillsID := 1;
|
|
|
- FProjectData.DealBillsData.Clear;
|
|
|
- FProjectData.DealBillsData.DisableEvent;
|
|
|
- LoadDealBillsData(FMSExcel.Sheets.Spreadsheet(0));
|
|
|
- FProjectData.DealBillsData.EnableEvent;
|
|
|
-end;
|
|
|
-
|
|
|
-procedure TDealBillsExcelImport.LoadColumnsFromHead(ASheet: TSpreadSheet);
|
|
|
-var
|
|
|
- iCol: Integer;
|
|
|
- sColName: string;
|
|
|
-begin
|
|
|
- FB_CodeCol := -1;
|
|
|
- FNameCol := 1;
|
|
|
- FUnitsCol := 2;
|
|
|
- FPriceCol := 3;
|
|
|
- FQuantityCol := 4;
|
|
|
- FTotalPriceCol := 5;
|
|
|
- while ((FB_CodeCol = -1) or (FPriceCol = -1)) and (FCurRow < ASheet.Cells.UsedRowCount) do
|
|
|
- begin
|
|
|
- for iCol := 0 to ASheet.Cells.UsedColCount do
|
|
|
- begin
|
|
|
- sColName := GetCellTrimText(ASheet, iCol, FCurRow);
|
|
|
- if SameText(sColName, '清单编号') or SameText(sColName, '子目号') then
|
|
|
- FB_CodeCol := iCol
|
|
|
- else if SameText(sColName, '名称') then
|
|
|
- FNameCol := iCol
|
|
|
- else if SameText(sColName, '单位') then
|
|
|
- FUnitsCol := iCol
|
|
|
- else if Pos('单价', sColName) = 1 then
|
|
|
- FPriceCol := iCol
|
|
|
- else if SameText(sColName, '数量') then
|
|
|
- FQuantityCol := iCol
|
|
|
- else if SameText(sColName, '金额') then
|
|
|
- FTotalPriceCol := iCol;
|
|
|
- end;
|
|
|
- Inc(FCurRow);
|
|
|
- end;
|
|
|
-end;
|
|
|
-
|
|
|
-procedure TDealBillsExcelImport.LoadDealBillsData(ASheet: TSpreadSheet);
|
|
|
-
|
|
|
- function CheckIsBillsCode(ACode: string): Boolean;
|
|
|
- const
|
|
|
- FBillsCodeSet: set of char = ['0'..'9', '-', 'a'..'z', 'A'..'Z'];
|
|
|
- var
|
|
|
- I: Integer;
|
|
|
- begin
|
|
|
- Result := True;
|
|
|
- I := 1;
|
|
|
- while I < Length(ACode) do
|
|
|
- if ACode[I] in FBillsCodeSet then
|
|
|
- Inc(I)
|
|
|
- else
|
|
|
- begin
|
|
|
- Result := False;
|
|
|
- Break;
|
|
|
- end;
|
|
|
- end;
|
|
|
-
|
|
|
-var
|
|
|
- sB_Code: string;
|
|
|
- Rec: TsdDataRecord;
|
|
|
-begin
|
|
|
- while (FCurRow < ASheet.Cells.UsedRowCount) do
|
|
|
- begin
|
|
|
- sB_Code := GetCellTrimText(ASheet, FB_CodeCol, FCurRow);
|
|
|
- if (sB_Code <> '') and CheckIsBillsCode(sB_Code) then
|
|
|
- begin
|
|
|
- Rec := FProjectData.DealBillsData.sddDealBills.Add;
|
|
|
- Rec.ValueByName('ID').AsInteger := FBillsID;
|
|
|
- Rec.ValueByName('B_Code').AsString := sB_Code;
|
|
|
- Rec.ValueByName('IndexCode').AsString := B_CodeToIndexCode(sB_Code);
|
|
|
- Rec.ValueByName('Name').AsString := GetCellTrimText(ASheet, FNameCol, FCurRow);
|
|
|
- Rec.ValueByName('Units').AsString := GetCellTrimText(ASheet, FUnitsCol, FCurRow);
|
|
|
- Rec.ValueByName('Price').AsFloat := PriceRoundTo(
|
|
|
- StrToFloatDef(GetCellTrimText(ASheet, FPriceCol, FCurRow), 0));
|
|
|
- Rec.ValueByName('Quantity').AsFloat := QuantityRoundTo(
|
|
|
- StrToFloatDef(GetCellTrimText(ASheet, FQuantityCol, FCurRow), 0));
|
|
|
- Rec.ValueByName('TotalPrice').AsFloat := TotalPriceRoundTo(
|
|
|
- StrToFloatDef(GetCellTrimText(ASheet, FTotalPriceCol, FCurRow), 0));
|
|
|
- Inc(FBillsID);
|
|
|
- end;
|
|
|
- Inc(FCurRow);
|
|
|
- end;
|
|
|
-end;}
|
|
|
-
|
|
|
-{ TGclBillsExcelImport }
|
|
|
-
|
|
|
-procedure TGclBillsExcelImport.BeginImport;
|
|
|
-begin
|
|
|
- Screen.Cursor := crHourGlass;
|
|
|
- ShowProgressHint('导入Excel数据', 100);
|
|
|
-
|
|
|
- FCacheTree := TGclCacheTree.Create;
|
|
|
- FCacheTree.NewNodeID := FProjectData.BillsData.GetMaxBillsID + 1;
|
|
|
-
|
|
|
- FProjectData.DisConnectTree;
|
|
|
- FProjectData.BillsData.DisableEvents;
|
|
|
-
|
|
|
- FSelectSheets := TList.Create;
|
|
|
-
|
|
|
- FB_CodeCol := 0;
|
|
|
- FNameCol := 1;
|
|
|
- FUnitsCol := 2;
|
|
|
- FQuantityCol := 3;
|
|
|
- FPriceCol := 4;
|
|
|
-end;
|
|
|
-
|
|
|
-procedure TGclBillsExcelImport.EndImport;
|
|
|
-var
|
|
|
- ParentRec: TsdDataRecord;
|
|
|
-begin
|
|
|
- FSelectSheets.Free;
|
|
|
-
|
|
|
- FCacheTree.Free;
|
|
|
-
|
|
|
- FProjectData.BillsData.EnableEvents;
|
|
|
- FProjectData.ReConnectTree;
|
|
|
-
|
|
|
- ParentRec := FProjectData.BillsData.sddBills.FindKey('idxID', ParentID);
|
|
|
- FProjectData.BillsCompileData.sdvBillsCompile.LocateInControl(ParentRec);
|
|
|
-
|
|
|
- FProjectData.BillsCompileData.CalculateAll;
|
|
|
-
|
|
|
- CloseProgressHint;
|
|
|
- Screen.Cursor := crDefault;
|
|
|
-end;
|
|
|
-
|
|
|
-procedure TGclBillsExcelImport.Import;
|
|
|
-var
|
|
|
- i: Integer;
|
|
|
-begin
|
|
|
- {if SelectSheets(FMSExcel, FSelectSheets) then
|
|
|
- begin
|
|
|
- for i := 0 to FSelectSheets.Count - 1 do
|
|
|
- begin
|
|
|
- UpdateProgressHint(Format('导入Excel数据--工作表[%s]', [FMSExcel.SheetNames.Strings[i]]));
|
|
|
- UpdateProgressPosition(0);
|
|
|
- ImportSheet(FSelectSheets.Items[i]);
|
|
|
- end;
|
|
|
- end;}
|
|
|
- ImportSheet(FMSExcel.Sheets.Spreadsheet(0));
|
|
|
- WriteNodes(FProjectData.BillsData.sddBills);
|
|
|
-end;
|
|
|
-
|
|
|
-procedure TGclBillsExcelImport.ImportSheet(ASheet: TSpreadSheet);
|
|
|
-var
|
|
|
- iPos: Integer;
|
|
|
-begin
|
|
|
- FCurRow := 1;
|
|
|
- while (FCurRow < ASheet.Cells.UsedRowCount) do
|
|
|
- begin
|
|
|
- LoadNode(ASheet);
|
|
|
- Inc(FCurRow);
|
|
|
- iPos := FCurRow * 100 div ASheet.Cells.UsedRowCount;
|
|
|
- UpdateProgressPosition(iPos);
|
|
|
- end;
|
|
|
-end;
|
|
|
-
|
|
|
-procedure TGclBillsExcelImport.LoadNode(ASheet: TSpreadSheet);
|
|
|
-var
|
|
|
- sB_Code, sName: string;
|
|
|
- Node: TGclCacheNode;
|
|
|
-begin
|
|
|
- with ASheet.Cells do
|
|
|
- begin
|
|
|
- sB_Code := Trim(VarToStrDef(GetValue(FB_CodeCol, FCurRow), ''));
|
|
|
- sName := Trim(VarToStrDef(GetValue(FNameCol, FCurRow), ''));
|
|
|
-
|
|
|
- Node := FCacheTree.AddNodeByData(sB_Code, sName);
|
|
|
-
|
|
|
- Node.B_Code := sB_Code;
|
|
|
- Node.Name := sName;
|
|
|
- Node.Units := Trim(VarToStrDef(GetValue(FUnitsCol, FCurRow), ''));
|
|
|
- Node.Price := StrToFloatDef(VarToStrDef(GetValue(FPriceCol, FCurRow), ''), 0);
|
|
|
- Node.Quantity := StrToFloatDef(VarToStrDef(GetValue(FQuantityCol, FCurRow), ''), 0);
|
|
|
- end;
|
|
|
-end;
|
|
|
-
|
|
|
-procedure TGclBillsExcelImport.WriteNodes(ADataSet: TsdDataSet);
|
|
|
-var
|
|
|
- i, iPos: Integer;
|
|
|
-begin
|
|
|
- UpdateProgressHint('写入读取的Excel数据');
|
|
|
- UpdateProgressPosition(0);
|
|
|
- for i := 0 to FCacheTree.CacheNodes.Count - 1 do
|
|
|
- begin
|
|
|
- WriteNode(ADataSet, TGclCacheNode(FCacheTree.CacheNodes[i]));
|
|
|
- iPos := i*100 div FCacheTree.CacheNodes.Count;
|
|
|
- UpdateProgressPosition(iPos);
|
|
|
- end;
|
|
|
- UpdateProgressPosition(100);
|
|
|
-end;
|
|
|
-
|
|
|
-procedure TGclBillsExcelImport.WriteNode(ADataSet: TsdDataSet;
|
|
|
- ANode: TGclCacheNode);
|
|
|
-var
|
|
|
- Rec: TBillsRecord;
|
|
|
-begin
|
|
|
- if ANode.B_Code <> '' then
|
|
|
- UpdateProgressHint('写入读取的Excel数据 ' + ANode.B_Code)
|
|
|
- else
|
|
|
- UpdateProgressHint('写入读取的Excel数据 ' + ANode.Name);
|
|
|
-
|
|
|
- Rec := TBillsRecord(ADataSet.Add);
|
|
|
- Rec.ID.AsInteger := ANode.ID;
|
|
|
- if ANode.ParentID = -1 then
|
|
|
- Rec.ParentID.AsInteger := ParentID
|
|
|
- else
|
|
|
- Rec.ParentID.AsInteger := ANode.ParentID;
|
|
|
- Rec.NextSiblingID.AsInteger := ANode.NextSiblingID;
|
|
|
- Rec.B_Code.AsString := ANode.B_Code;
|
|
|
- Rec.Name.AsString := ANode.Name;
|
|
|
- Rec.Units.AsString := ANode.Units;
|
|
|
- Rec.Price.AsFloat := PriceRoundTo(ANode.Price);
|
|
|
- Rec.OrgQuantity.AsFloat := QuantityRoundTo(ANode.Quantity);
|
|
|
-end;
|
|
|
-
|
|
|
end.
|