123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- unit ExcelImport_GclBills;
- // 导入工程量清单至项目节
- interface
- uses
- Classes, DetailExcelImport, MCacheTree, sdDB;
- type
- TDEI_GclBills = class(TDetailExcelImport)
- private
- FParentID: Integer;
- FSelectSheets: TList;
- FCacheTree: TGclCacheTree;
- FCurRow: Integer;
- FB_CodeCol: Integer;
- FNameCol: Integer;
- FUnitsCol: Integer;
- FPriceCol: Integer;
- FQuantityCol: Integer;
- protected
- procedure BeginImport; override;
- procedure EndImport; override;
- procedure Import; override;
- procedure ImportSheet;
- procedure WriteNode(ADataSet: TsdDataSet; ANode: TGclCacheNode);
- procedure WriteNodes(ADataSet: TsdDataSet);
- public
- procedure ImportToXmj(const AFileName: string; AParentID: Integer);
- end;
- implementation
- uses
- Forms, mDataRecord, Controls, ProgressHintFrm, UtilMethods;
- { TDEI_GclBills }
- procedure TDEI_GclBills.BeginImport;
- begin
- Screen.Cursor := crHourGlass;
- ShowProgressHint('导入Excel数据', 100);
- FCacheTree := TGclCacheTree.Create;
- FCacheTree.NewNodeID := ProjectData.BillsData.GetMaxBillsID + 1;
- ProjectData.DisConnectTree;
- ProjectData.BillsData.DisableEvents;
- FSelectSheets := TList.Create;
- FB_CodeCol := 1;
- FNameCol := 2;
- FUnitsCol := 3;
- FQuantityCol := 4;
- FPriceCol := 5;
- end;
- procedure TDEI_GclBills.EndImport;
- var
- ParentRec: TsdDataRecord;
- begin
- FSelectSheets.Free;
- FCacheTree.Free;
- ProjectData.BillsData.EnableEvents;
- ProjectData.ReConnectTree;
- ParentRec := ProjectData.BillsData.sddBills.FindKey('idxID', FParentID);
- ProjectData.BillsCompileData.sdvBillsCompile.LocateInControl(ParentRec);
- ProjectData.BillsCompileData.CalculateAll;
- CloseProgressHint;
- Screen.Cursor := crDefault;
- end;
- procedure TDEI_GclBills.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;
- WriteNodes(ProjectData.BillsData.sddBills);
- end;
- procedure TDEI_GclBills.ImportSheet;
- var
- iPos: Integer;
- sB_Code, sName: string;
- Node: TGclCacheNode;
- begin
- FCurRow := 2;
- while (FCurRow <= Excel.XlsFile.MaxRow) do
- begin
- sB_Code := GetCellTrimStr(Excel.XlsFile, FCurRow, FB_CodeCol);
- sName := GetCellTrimStr(Excel.XlsFile, FCurRow, FNameCol);
- if (sB_Code <> '') or (sName <> '') then
- begin
- Node := FCacheTree.AddNodeByData(sB_Code, sName);
- Node.B_Code := sB_Code;
- Node.Name := sName;
- Node.Units := GetCellTrimStr(Excel.XlsFile, FCurRow, FUnitsCol);
- Node.Price := GetCellFloat(Excel.XlsFile, FCurRow, FPriceCol);
- Node.Quantity := GetCellFloat(Excel.XlsFile, FCurRow, FQuantityCol);
- end;
- Inc(FCurRow);
- iPos := FCurRow * 100 div Excel.XlsFile.MaxRow;
- UpdateProgressPosition(iPos);
- end;
- end;
- procedure TDEI_GclBills.ImportToXmj(const AFileName: string;
- AParentID: Integer);
- begin
- FParentID := AParentID;
- ImportFile(AFileName);
- end;
- procedure TDEI_GclBills.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 := FParentID
- 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;
- procedure TDEI_GclBills.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;
- end.
|