| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510 |
- unit ImportWCostFrm;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, ExTreeView, StdCtrls, ExtCtrls, DB, ADODB, WCostUtils;
- type
- TImportWCostForm = class(TForm)
- etvFiles: TExTreeView;
- leSourceFile: TLabeledEdit;
- Label1: TLabel;
- Panel1: TPanel;
- btnOK: TButton;
- btnCancel: TButton;
- btnBrowseForWCT: TButton;
- odWCost: TOpenDialog;
- acWCT: TADOConnection;
- atFileName: TADOTable;
- atProject: TADOTable;
- atProjectPID: TAutoIncField;
- atProjectPType: TSmallintField;
- atProjectName: TWideStringField;
- atProjectUserName: TWideStringField;
- atProjectFileNo: TWideStringField;
- atProjectFZName: TWideStringField;
- atProjectBZName: TWideStringField;
- atProjectFHName: TWideStringField;
- atProjectLastDate: TDateTimeField;
- atProjectLastTime: TDateTimeField;
- atProjectoptJG: TSmallintField;
- atProjectFID_JG: TIntegerField;
- atProjectXS_JG: TFloatField;
- atProjectJSTitle: TSmallintField;
- atProjFile: TADOTable;
- procedure btnBrowseForWCTClick(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure btnOKClick(Sender: TObject);
- private
- { Private declarations }
- FPath: string;
- FApp: TApplication;
- FFileList: TwcFileList;
- FWCTFile: string;
- FSourceFileType: Integer;
- { FProjFiles: TStringList;
- FFeeFiles: TStringList;
- FRationLibFiles: TStringList;
- FPriceFiles: TStringList;}
- function TypeToExt(AType: Integer): string;
- function TypeToName(AType: Integer): string;
- function ExtToType(AExt: string): Integer;
- function FindParentNodeByType(AType: Integer): TExTreeNode;
- procedure InitTreeForWCT;
- procedure OpenWCT(AFileName: string);
- procedure AddSingleFile(AFileName: string; AType: Integer);
- public
- { Public declarations }
- procedure CheckFile(AFileName: string);
- procedure Init(App: TApplication);
- property FileList: TwcFileList read FFileList;
- property WCTFile: string read FWCTFile;
- property SourceFileType: Integer read FSourceFileType;
- { property ProjFiles: TStringList read FProjFiles;
- property FeeFiles: TStringList read FFeeFiles;
- property PriceFiles: TStringList read FPriceFiles;
- property RationLibFiles: TStringList read FRationLibFiles;}
- end;
- //var
- // ImportWCostForm: TImportWCostForm;
- implementation
- uses
- ScConsts, WCostConsts, ScUtils, ScOpenAPI;
- {$R *.dfm}
- procedure TImportWCostForm.btnBrowseForWCTClick(Sender: TObject);
- begin
- if odWCost.Execute then
- begin
- FWCTFile := '';
- CheckFile(odWCost.FileName);
- leSourceFile.Text := odWCost.FileName;
- FPath := ExtractFilePath(odWCost.FileName);
- if SameText(ExtractFileExt(odWCost.FileName), wcWCT) then
- begin
- FWCTFile := odWCost.FileName;
- FSourceFileType := wfWCT;
- end
- else if SameText(ExtractFileExt(odWCost.FileName), wcLX) then
- begin
- FWCTFile := '';
- FSourceFileType := wfLX;
- end
- else if SameText(ExtractFileExt(odWCost.FileName), wcLXB) then
- begin
- FWCTFile := '';
- FSourceFileType := wfLXB;
- end
- else if SameText(ExtractFileExt(odWCost.FileName), wcDQ) then
- begin
- FWCTFile := '';
- FSourceFileType := wfDQ;
- end
- else if SameText(ExtractFileExt(odWCost.FileName), wcDQB) then
- begin
- FWCTFile := '';
- FSourceFileType := wfDQB;
- end
- end;
- end;
- procedure TImportWCostForm.CheckFile(AFileName: string);
- var
- strExt: string;
- begin
- strExt := ExtractFileExt(AFileName);
- // WCT文件
- if SameText(wcWCT, strExt) then
- begin
- InitTreeForWCT;
- acWCT.ConnectionString := Format(SAdoConnectStr, [AFileName, 'Admin', '']);
- acWCT.Open;
- try
- OpenWCT(AFileName);
- etvFiles.FullExpandNodes := False;
- etvFiles.FullExpandNodes := True;
- finally
- acWCT.Close;
- end;
- end
- // 定额文件
- else if Pos(wcDE, strExt) > 0 then
- begin
- end
- // 其他
- else
- begin
- { acWCT.ConnectionString := Format(SAdoConnectStr, [AFileName, 'Admin', '']);
- acWCT.Open;
- try
- etvFiles.Items.Clear;
- AddSingleFile(AFileName, ExtToType(ExtractFileExt(AFileName)));
- etvFiles.FullExpandNodes := False;
- etvFiles.FullExpandNodes := True;
- finally
- acWCT.Close;
- end;}
- end;
- end;
- function TImportWCostForm.FindParentNodeByType(
- AType: Integer): TExTreeNode;
- var
- Node: TExTreeNode;
- begin
- Result := nil;
- Node := etvFiles.TopItem;
- while Node <> nil do
- begin
- if Integer(Node.Data) = AType then
- begin
- Result := Node;
- Break;
- end;
- Node := Node.getNextSibling;
- end;
- end;
- procedure TImportWCostForm.Init(App: TApplication);
- begin
- FApp := App;
- end;
- procedure TImportWCostForm.InitTreeForWCT;
- var
- Node: TExTreeNode;
- begin
- Node := nil;
- etvFiles.Items.Clear;
- case (FApp.MainForm as IScProjManager).Version of
- ScVer_Budget:
- begin
- Node := etvFiles.Items.AddObject(Node, wtLX, Pointer(wfLX));
- Node.Checked := csChecked;
- Node := etvFiles.Items.AddObject(Node, wtDQ, Pointer(wfDQ));
- Node.Checked := csChecked;
- end;
- ScVer_Bills:
- begin
- Node := etvFiles.Items.AddObject(Node, wtLXB, Pointer(wfLXB));
- Node.Checked := csChecked;
- Node := etvFiles.Items.AddObject(Node, wtDQB, Pointer(wfDQB));
- Node.Checked := csChecked;
- end;
- end;
- { Node := etvFiles.Items.AddObject(Node, wtFL, Pointer(wfFL));
- Node.Checked := csChecked;
- Node := etvFiles.Items.AddObject(Node, wtDJ, Pointer(wfDJ));
- Node.Checked := csChecked;
- Node := etvFiles.Items.AddObject(Node, wtDE, Pointer(wfDE1));
- Node.Checked := csChecked;}
- end;
- procedure TImportWCostForm.OpenWCT(AFileName: string);
- var
- ParentNode: TExTreeNode;
- iType: Integer;
- HasProjFile: Boolean;
- begin
- HasProjFile := False;
- atFileName.Open;
- atFileName.First;
- while not atFileName.Eof do
- begin
- ParentNode := nil;
- iType := atFileName.FieldByName(wFType).AsInteger;
- case iType of
- wfLX, wfDQ:
- begin
- if (FApp.MainForm as IScProjManager).Version = ScVer_Budget then
- begin
- ParentNode := FindParentNodeByType(iType);
- HasProjFile := True;
- end;
- end;
- wfLXB, wfDQB:
- begin
- if (FApp.MainForm as IScProjManager).Version = ScVer_Bills then
- begin
- ParentNode := FindParentNodeByType(iType);
- HasProjFile := True;
- end;
- end;
- { wfFL, wfDJ:
- begin
- ParentNode := FindParentNodeByType(iType);
- end;
- wfDE1, wfDE3, wfDE5, wfDE7:
- begin
- ParentNode := FindParentNodeByType(wfDE1);
- end;}
- end;
- if ParentNode <> nil then
- etvFiles.Items.AddChildObject(ParentNode, atFileName.FieldByName(wName).AsString,
- Pointer(atFileName.FieldByName(wFID).AsInteger)).Checked := csChecked;
- atFileName.Next;
- end;
- atFileName.Close;
- if not HasProjFile then
- MessageHint(0, '没有可导入的文件。'#13#10'提示:SmartCost概预算版只能导入概预算文件,SmartCost招投标版只能导入招投标文件。');
- end;
- function TImportWCostForm.TypeToExt(AType: Integer): string;
- begin
- Result := '';
- case AType of
- // 路线
- wfLX: Result := wcLX;
- // 路线标
- wfLXB: Result := wcLXB;
- // 独立桥梁(大桥)
- wfDQ: Result := wcDQ;
- // 独立桥梁标(大桥标)
- wfDQB: Result := wcDQB;
- // 费率
- wfFL: Result := wcFL;
- // 单价
- wfDJ: Result := wcDJ;
- // 预算定额库
- wfDE1: Result := wcDE1;
- // 概算定额库
- wfDE3: Result := wcDE3;
- // 估算分项指标
- wfDE5: Result := wcDE5;
- // 估算综合指标
- wfDE7: Result := wcDE7;
- end;
- end;
- procedure TImportWCostForm.FormCreate(Sender: TObject);
- begin
- { FProjFiles := TStringList.Create;
- FFeeFiles := TStringList.Create;
- FPriceFiles := TStringList.Create;
- FRationLibFiles := TStringList.Create;}
- FFileList := TwcFileList.Create;
- FSourceFileType := -1;
- end;
- procedure TImportWCostForm.FormDestroy(Sender: TObject);
- begin
- { FProjFiles.Free;
- FFeeFiles.Free;
- FPriceFiles.Free;
- FRationLibFiles.Free;}
- FFileList.Free;
- end;
- procedure TImportWCostForm.btnOKClick(Sender: TObject);
- function FindNode(AName: string): TExTreeNode;
- var
- I: Integer;
- begin
- Result := nil;
- for I := 0 to etvFiles.Items.Count - 1 do
- begin
- if SameText(AName, etvFiles.Items[I].Text) then
- Result := etvFiles.Items[I];
- end;
- end;
- var
- ParentNode, Node: TExTreeNode;
- I, iType, iPType: Integer;
- strName: string;
- begin
- FFileList.Clear;
- Node := etvFiles.TopItem;
- atProjFile.Open;
- atProject.Open;
- atFileName.Open;
- atFileName.First;
- while not atFileName.Eof do
- begin
- iPType := -1;
- iType := atFileName.FieldByName(wFType).AsInteger;
- strName := atFileName.FieldByName(wName).AsString;
- {$IFDEF _ScBudget}
- if (iType <> wfLXB) and (iType <> wfDQB) then
- {$ELSE}
- if (iType <> wfLX) and (iType <> wfDQ) then
- {$ENDIF}
- begin
- Node := FindNode(strName);
- if (iType in [wfLXB, wfDQB, wfLX, wfDQ]) and (Node <> nil) and (Node.Parent <> nil) then
- begin
- if atProjFile.Locate(wFID, atFileName.FieldByName(wFID).AsInteger, []) then
- if atProject.Locate('PID', atProjFile.FieldByName('PID').AsInteger, []) then
- iPType := atProjectPType.Value;
- end;
- if ((iType in [wfLXB, wfDQB, wfLX, wfDQ]) and (Node <> nil) and (Node.Checked = csChecked))
- or (iType in [wfFL, wfDJ, wfDE1, wfDE3, wfDE5, wfDE7]) then
- FFileList.AddItem(atFileName.FieldByName(wFID).AsInteger,
- atFileName.FieldByName(wFType).AsInteger,
- iPType,
- strName,
- FPath + strName + TypeToExt(iType)
- );
- end;
- atFileName.Next;
- end;
- atFileName.Close;
- atProjFile.Close;
- atProject.Close;
- { while Node <> nil do
- begin
- for I := 0 to Node.Count - 1 do
- begin
- if Node.Checked = csChecked then
- FFileList.AddItem(Integer(Node.Item[I].Data), Integer(Node.Data), Node.Item[I].Text,
- FPath + Node.Item[I].Text + TypeToExt(Integer(Node.Data)));
- end;}
- { ParentNode := Node;
- // 建立项目文件列表
- if (FApp.MainForm as IScProjManager).Version = ScVer_Budget then
- begin
- case Integer(Node.Data) of
- wfLX, wfDQ: ParentNode := Node;
- end;
- end
- else if (FApp.MainForm as IScProjManager).Version = ScVer_Bills then
- begin
- case Integer(Node.Data) of
- wfLXB, wfDQB: ParentNode := Node;
- end;
- end;
- case Integer(Node.Data) of
- // 费率
- wfFL:
- begin
- for I := 0 to Node.Count - 1 do
- begin
- FFeeFiles.Add(FPath + Node.Item[I].Text + TypeToExt(Integer(Node.Data)));
- end;
- end;
- // 单价
- wfDJ:
- begin
- for I := 0 to Node.Count - 1 do
- begin
- FPriceFiles.Add(FPath + Node.Item[I].Text + TypeToExt(Integer(Node.Data)));
- end;
- end;
- // 预算定额库
- wfDE1:
- begin
- end;
- // 概算定额库
- wfDE3:
- begin
- end;
- // 估算分项指标
- wfDE5:
- begin
- end;
- // 估算综合指标
- wfDE7:
- begin
- end;
- end;
- if ParentNode <> nil then
- for I := 0 to ParentNode.Count - 1 do
- begin
- FProjFiles.Add(FPath + ParentNode.Item[I].Text + TypeToExt(Integer(Node.Data)));
- end;}
- // Node := Node.getNextSibling;
- // end;
- end;
- function TImportWCostForm.ExtToType(AExt: string): Integer;
- begin
- Result := -1;
- if SameText(AExt, wcLX) then
- Result := wfLX
- else if SameText(AExt, wcLX) then
- Result := wfLX
- else if SameText(AExt, wcLXB) then
- Result := wfLXB
- else if SameText(AExt, wcDQ) then
- Result := wfDQ
- else if SameText(AExt, wcDQB) then
- Result := wfDQB
- else if SameText(AExt, wcDJ) then
- Result := wfDJ
- else if SameText(AExt, wcFL) then
- Result := wfFL
- else if SameText(AExt, wcDE1) then
- Result := wfDE1
- else if SameText(AExt, wcDE3) then
- Result := wfDE3
- else if SameText(AExt, wcDE5) then
- Result := wfDE5
- else if SameText(AExt, wcDE7) then
- Result := wfDE7;
- end;
- procedure TImportWCostForm.AddSingleFile(AFileName: string;
- AType: Integer);
- var
- ParentNode: TExTreeNode;
- begin
- if AType in [wfDE1, wfDE3, wfDE5, wfDE7] then
- AType := wfDE1;
- ParentNode := FindParentNodeByType(AType);
- if ParentNode = nil then
- begin
- ParentNode := etvFiles.Items.AddObject(nil, TypeToName(AType), Pointer(AType));
- ParentNode.Checked := csChecked;
- end;
- atFileName.Open;
- atFileName.First;
- while not atFileName.Eof do
- begin
- if ParentNode <> nil then
- etvFiles.Items.AddChildObject(ParentNode, atFileName.FieldByName(wName).AsString,
- Pointer(atFileName.FieldByName(wFID).AsInteger)).Checked := csChecked;
- atFileName.Next;
- end;
- atFileName.Close;
- end;
- function TImportWCostForm.TypeToName(AType: Integer): string;
- begin
- Result := '';
- case AType of
- // 路线
- wfLX: Result := wtLX;
- // 路线标
- wfLXB: Result := wtLXB;
- // 独立桥梁(大桥)
- wfDQ: Result := wtLX;
- // 独立桥梁标(大桥标)
- wfDQB: Result := wtDQB;
- // 费率
- wfFL: Result := wtFL;
- // 单价
- wfDJ: Result := wtDJ;
- // 定额库
- wfDE1, wfDE3, wfDE5, wfDE7: Result := wtDE;
- end;
- end;
- end.
|