ImportWCostFrm.pas 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. unit ImportWCostFrm;
  2. interface
  3. uses
  4. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5. Dialogs, ExTreeView, StdCtrls, ExtCtrls, DB, ADODB, WCostUtils;
  6. type
  7. TImportWCostForm = class(TForm)
  8. etvFiles: TExTreeView;
  9. leSourceFile: TLabeledEdit;
  10. Label1: TLabel;
  11. Panel1: TPanel;
  12. btnOK: TButton;
  13. btnCancel: TButton;
  14. btnBrowseForWCT: TButton;
  15. odWCost: TOpenDialog;
  16. acWCT: TADOConnection;
  17. atFileName: TADOTable;
  18. atProject: TADOTable;
  19. atProjectPID: TAutoIncField;
  20. atProjectPType: TSmallintField;
  21. atProjectName: TWideStringField;
  22. atProjectUserName: TWideStringField;
  23. atProjectFileNo: TWideStringField;
  24. atProjectFZName: TWideStringField;
  25. atProjectBZName: TWideStringField;
  26. atProjectFHName: TWideStringField;
  27. atProjectLastDate: TDateTimeField;
  28. atProjectLastTime: TDateTimeField;
  29. atProjectoptJG: TSmallintField;
  30. atProjectFID_JG: TIntegerField;
  31. atProjectXS_JG: TFloatField;
  32. atProjectJSTitle: TSmallintField;
  33. atProjFile: TADOTable;
  34. procedure btnBrowseForWCTClick(Sender: TObject);
  35. procedure FormCreate(Sender: TObject);
  36. procedure FormDestroy(Sender: TObject);
  37. procedure btnOKClick(Sender: TObject);
  38. private
  39. { Private declarations }
  40. FPath: string;
  41. FApp: TApplication;
  42. FFileList: TwcFileList;
  43. FWCTFile: string;
  44. FSourceFileType: Integer;
  45. { FProjFiles: TStringList;
  46. FFeeFiles: TStringList;
  47. FRationLibFiles: TStringList;
  48. FPriceFiles: TStringList;}
  49. function TypeToExt(AType: Integer): string;
  50. function TypeToName(AType: Integer): string;
  51. function ExtToType(AExt: string): Integer;
  52. function FindParentNodeByType(AType: Integer): TExTreeNode;
  53. procedure InitTreeForWCT;
  54. procedure OpenWCT(AFileName: string);
  55. procedure AddSingleFile(AFileName: string; AType: Integer);
  56. public
  57. { Public declarations }
  58. procedure CheckFile(AFileName: string);
  59. procedure Init(App: TApplication);
  60. property FileList: TwcFileList read FFileList;
  61. property WCTFile: string read FWCTFile;
  62. property SourceFileType: Integer read FSourceFileType;
  63. { property ProjFiles: TStringList read FProjFiles;
  64. property FeeFiles: TStringList read FFeeFiles;
  65. property PriceFiles: TStringList read FPriceFiles;
  66. property RationLibFiles: TStringList read FRationLibFiles;}
  67. end;
  68. //var
  69. // ImportWCostForm: TImportWCostForm;
  70. implementation
  71. uses
  72. ScConsts, WCostConsts, ScUtils, ScOpenAPI;
  73. {$R *.dfm}
  74. procedure TImportWCostForm.btnBrowseForWCTClick(Sender: TObject);
  75. begin
  76. if odWCost.Execute then
  77. begin
  78. FWCTFile := '';
  79. CheckFile(odWCost.FileName);
  80. leSourceFile.Text := odWCost.FileName;
  81. FPath := ExtractFilePath(odWCost.FileName);
  82. if SameText(ExtractFileExt(odWCost.FileName), wcWCT) then
  83. begin
  84. FWCTFile := odWCost.FileName;
  85. FSourceFileType := wfWCT;
  86. end
  87. else if SameText(ExtractFileExt(odWCost.FileName), wcLX) then
  88. begin
  89. FWCTFile := '';
  90. FSourceFileType := wfLX;
  91. end
  92. else if SameText(ExtractFileExt(odWCost.FileName), wcLXB) then
  93. begin
  94. FWCTFile := '';
  95. FSourceFileType := wfLXB;
  96. end
  97. else if SameText(ExtractFileExt(odWCost.FileName), wcDQ) then
  98. begin
  99. FWCTFile := '';
  100. FSourceFileType := wfDQ;
  101. end
  102. else if SameText(ExtractFileExt(odWCost.FileName), wcDQB) then
  103. begin
  104. FWCTFile := '';
  105. FSourceFileType := wfDQB;
  106. end
  107. end;
  108. end;
  109. procedure TImportWCostForm.CheckFile(AFileName: string);
  110. var
  111. strExt: string;
  112. begin
  113. strExt := ExtractFileExt(AFileName);
  114. // WCT文件
  115. if SameText(wcWCT, strExt) then
  116. begin
  117. InitTreeForWCT;
  118. acWCT.ConnectionString := Format(SAdoConnectStr, [AFileName, 'Admin', '']);
  119. acWCT.Open;
  120. try
  121. OpenWCT(AFileName);
  122. etvFiles.FullExpandNodes := False;
  123. etvFiles.FullExpandNodes := True;
  124. finally
  125. acWCT.Close;
  126. end;
  127. end
  128. // 定额文件
  129. else if Pos(wcDE, strExt) > 0 then
  130. begin
  131. end
  132. // 其他
  133. else
  134. begin
  135. { acWCT.ConnectionString := Format(SAdoConnectStr, [AFileName, 'Admin', '']);
  136. acWCT.Open;
  137. try
  138. etvFiles.Items.Clear;
  139. AddSingleFile(AFileName, ExtToType(ExtractFileExt(AFileName)));
  140. etvFiles.FullExpandNodes := False;
  141. etvFiles.FullExpandNodes := True;
  142. finally
  143. acWCT.Close;
  144. end;}
  145. end;
  146. end;
  147. function TImportWCostForm.FindParentNodeByType(
  148. AType: Integer): TExTreeNode;
  149. var
  150. Node: TExTreeNode;
  151. begin
  152. Result := nil;
  153. Node := etvFiles.TopItem;
  154. while Node <> nil do
  155. begin
  156. if Integer(Node.Data) = AType then
  157. begin
  158. Result := Node;
  159. Break;
  160. end;
  161. Node := Node.getNextSibling;
  162. end;
  163. end;
  164. procedure TImportWCostForm.Init(App: TApplication);
  165. begin
  166. FApp := App;
  167. end;
  168. procedure TImportWCostForm.InitTreeForWCT;
  169. var
  170. Node: TExTreeNode;
  171. begin
  172. Node := nil;
  173. etvFiles.Items.Clear;
  174. case (FApp.MainForm as IScProjManager).Version of
  175. ScVer_Budget:
  176. begin
  177. Node := etvFiles.Items.AddObject(Node, wtLX, Pointer(wfLX));
  178. Node.Checked := csChecked;
  179. Node := etvFiles.Items.AddObject(Node, wtDQ, Pointer(wfDQ));
  180. Node.Checked := csChecked;
  181. end;
  182. ScVer_Bills:
  183. begin
  184. Node := etvFiles.Items.AddObject(Node, wtLXB, Pointer(wfLXB));
  185. Node.Checked := csChecked;
  186. Node := etvFiles.Items.AddObject(Node, wtDQB, Pointer(wfDQB));
  187. Node.Checked := csChecked;
  188. end;
  189. end;
  190. { Node := etvFiles.Items.AddObject(Node, wtFL, Pointer(wfFL));
  191. Node.Checked := csChecked;
  192. Node := etvFiles.Items.AddObject(Node, wtDJ, Pointer(wfDJ));
  193. Node.Checked := csChecked;
  194. Node := etvFiles.Items.AddObject(Node, wtDE, Pointer(wfDE1));
  195. Node.Checked := csChecked;}
  196. end;
  197. procedure TImportWCostForm.OpenWCT(AFileName: string);
  198. var
  199. ParentNode: TExTreeNode;
  200. iType: Integer;
  201. HasProjFile: Boolean;
  202. begin
  203. HasProjFile := False;
  204. atFileName.Open;
  205. atFileName.First;
  206. while not atFileName.Eof do
  207. begin
  208. ParentNode := nil;
  209. iType := atFileName.FieldByName(wFType).AsInteger;
  210. case iType of
  211. wfLX, wfDQ:
  212. begin
  213. if (FApp.MainForm as IScProjManager).Version = ScVer_Budget then
  214. begin
  215. ParentNode := FindParentNodeByType(iType);
  216. HasProjFile := True;
  217. end;
  218. end;
  219. wfLXB, wfDQB:
  220. begin
  221. if (FApp.MainForm as IScProjManager).Version = ScVer_Bills then
  222. begin
  223. ParentNode := FindParentNodeByType(iType);
  224. HasProjFile := True;
  225. end;
  226. end;
  227. { wfFL, wfDJ:
  228. begin
  229. ParentNode := FindParentNodeByType(iType);
  230. end;
  231. wfDE1, wfDE3, wfDE5, wfDE7:
  232. begin
  233. ParentNode := FindParentNodeByType(wfDE1);
  234. end;}
  235. end;
  236. if ParentNode <> nil then
  237. etvFiles.Items.AddChildObject(ParentNode, atFileName.FieldByName(wName).AsString,
  238. Pointer(atFileName.FieldByName(wFID).AsInteger)).Checked := csChecked;
  239. atFileName.Next;
  240. end;
  241. atFileName.Close;
  242. if not HasProjFile then
  243. MessageHint(0, '没有可导入的文件。'#13#10'提示:SmartCost概预算版只能导入概预算文件,SmartCost招投标版只能导入招投标文件。');
  244. end;
  245. function TImportWCostForm.TypeToExt(AType: Integer): string;
  246. begin
  247. Result := '';
  248. case AType of
  249. // 路线
  250. wfLX: Result := wcLX;
  251. // 路线标
  252. wfLXB: Result := wcLXB;
  253. // 独立桥梁(大桥)
  254. wfDQ: Result := wcDQ;
  255. // 独立桥梁标(大桥标)
  256. wfDQB: Result := wcDQB;
  257. // 费率
  258. wfFL: Result := wcFL;
  259. // 单价
  260. wfDJ: Result := wcDJ;
  261. // 预算定额库
  262. wfDE1: Result := wcDE1;
  263. // 概算定额库
  264. wfDE3: Result := wcDE3;
  265. // 估算分项指标
  266. wfDE5: Result := wcDE5;
  267. // 估算综合指标
  268. wfDE7: Result := wcDE7;
  269. end;
  270. end;
  271. procedure TImportWCostForm.FormCreate(Sender: TObject);
  272. begin
  273. { FProjFiles := TStringList.Create;
  274. FFeeFiles := TStringList.Create;
  275. FPriceFiles := TStringList.Create;
  276. FRationLibFiles := TStringList.Create;}
  277. FFileList := TwcFileList.Create;
  278. FSourceFileType := -1;
  279. end;
  280. procedure TImportWCostForm.FormDestroy(Sender: TObject);
  281. begin
  282. { FProjFiles.Free;
  283. FFeeFiles.Free;
  284. FPriceFiles.Free;
  285. FRationLibFiles.Free;}
  286. FFileList.Free;
  287. end;
  288. procedure TImportWCostForm.btnOKClick(Sender: TObject);
  289. function FindNode(AName: string): TExTreeNode;
  290. var
  291. I: Integer;
  292. begin
  293. Result := nil;
  294. for I := 0 to etvFiles.Items.Count - 1 do
  295. begin
  296. if SameText(AName, etvFiles.Items[I].Text) then
  297. Result := etvFiles.Items[I];
  298. end;
  299. end;
  300. var
  301. ParentNode, Node: TExTreeNode;
  302. I, iType, iPType: Integer;
  303. strName: string;
  304. begin
  305. FFileList.Clear;
  306. Node := etvFiles.TopItem;
  307. atProjFile.Open;
  308. atProject.Open;
  309. atFileName.Open;
  310. atFileName.First;
  311. while not atFileName.Eof do
  312. begin
  313. iPType := -1;
  314. iType := atFileName.FieldByName(wFType).AsInteger;
  315. strName := atFileName.FieldByName(wName).AsString;
  316. {$IFDEF _ScBudget}
  317. if (iType <> wfLXB) and (iType <> wfDQB) then
  318. {$ELSE}
  319. if (iType <> wfLX) and (iType <> wfDQ) then
  320. {$ENDIF}
  321. begin
  322. Node := FindNode(strName);
  323. if (iType in [wfLXB, wfDQB, wfLX, wfDQ]) and (Node <> nil) and (Node.Parent <> nil) then
  324. begin
  325. if atProjFile.Locate(wFID, atFileName.FieldByName(wFID).AsInteger, []) then
  326. if atProject.Locate('PID', atProjFile.FieldByName('PID').AsInteger, []) then
  327. iPType := atProjectPType.Value;
  328. end;
  329. if ((iType in [wfLXB, wfDQB, wfLX, wfDQ]) and (Node <> nil) and (Node.Checked = csChecked))
  330. or (iType in [wfFL, wfDJ, wfDE1, wfDE3, wfDE5, wfDE7]) then
  331. FFileList.AddItem(atFileName.FieldByName(wFID).AsInteger,
  332. atFileName.FieldByName(wFType).AsInteger,
  333. iPType,
  334. strName,
  335. FPath + strName + TypeToExt(iType)
  336. );
  337. end;
  338. atFileName.Next;
  339. end;
  340. atFileName.Close;
  341. atProjFile.Close;
  342. atProject.Close;
  343. { while Node <> nil do
  344. begin
  345. for I := 0 to Node.Count - 1 do
  346. begin
  347. if Node.Checked = csChecked then
  348. FFileList.AddItem(Integer(Node.Item[I].Data), Integer(Node.Data), Node.Item[I].Text,
  349. FPath + Node.Item[I].Text + TypeToExt(Integer(Node.Data)));
  350. end;}
  351. { ParentNode := Node;
  352. // 建立项目文件列表
  353. if (FApp.MainForm as IScProjManager).Version = ScVer_Budget then
  354. begin
  355. case Integer(Node.Data) of
  356. wfLX, wfDQ: ParentNode := Node;
  357. end;
  358. end
  359. else if (FApp.MainForm as IScProjManager).Version = ScVer_Bills then
  360. begin
  361. case Integer(Node.Data) of
  362. wfLXB, wfDQB: ParentNode := Node;
  363. end;
  364. end;
  365. case Integer(Node.Data) of
  366. // 费率
  367. wfFL:
  368. begin
  369. for I := 0 to Node.Count - 1 do
  370. begin
  371. FFeeFiles.Add(FPath + Node.Item[I].Text + TypeToExt(Integer(Node.Data)));
  372. end;
  373. end;
  374. // 单价
  375. wfDJ:
  376. begin
  377. for I := 0 to Node.Count - 1 do
  378. begin
  379. FPriceFiles.Add(FPath + Node.Item[I].Text + TypeToExt(Integer(Node.Data)));
  380. end;
  381. end;
  382. // 预算定额库
  383. wfDE1:
  384. begin
  385. end;
  386. // 概算定额库
  387. wfDE3:
  388. begin
  389. end;
  390. // 估算分项指标
  391. wfDE5:
  392. begin
  393. end;
  394. // 估算综合指标
  395. wfDE7:
  396. begin
  397. end;
  398. end;
  399. if ParentNode <> nil then
  400. for I := 0 to ParentNode.Count - 1 do
  401. begin
  402. FProjFiles.Add(FPath + ParentNode.Item[I].Text + TypeToExt(Integer(Node.Data)));
  403. end;}
  404. // Node := Node.getNextSibling;
  405. // end;
  406. end;
  407. function TImportWCostForm.ExtToType(AExt: string): Integer;
  408. begin
  409. Result := -1;
  410. if SameText(AExt, wcLX) then
  411. Result := wfLX
  412. else if SameText(AExt, wcLX) then
  413. Result := wfLX
  414. else if SameText(AExt, wcLXB) then
  415. Result := wfLXB
  416. else if SameText(AExt, wcDQ) then
  417. Result := wfDQ
  418. else if SameText(AExt, wcDQB) then
  419. Result := wfDQB
  420. else if SameText(AExt, wcDJ) then
  421. Result := wfDJ
  422. else if SameText(AExt, wcFL) then
  423. Result := wfFL
  424. else if SameText(AExt, wcDE1) then
  425. Result := wfDE1
  426. else if SameText(AExt, wcDE3) then
  427. Result := wfDE3
  428. else if SameText(AExt, wcDE5) then
  429. Result := wfDE5
  430. else if SameText(AExt, wcDE7) then
  431. Result := wfDE7;
  432. end;
  433. procedure TImportWCostForm.AddSingleFile(AFileName: string;
  434. AType: Integer);
  435. var
  436. ParentNode: TExTreeNode;
  437. begin
  438. if AType in [wfDE1, wfDE3, wfDE5, wfDE7] then
  439. AType := wfDE1;
  440. ParentNode := FindParentNodeByType(AType);
  441. if ParentNode = nil then
  442. begin
  443. ParentNode := etvFiles.Items.AddObject(nil, TypeToName(AType), Pointer(AType));
  444. ParentNode.Checked := csChecked;
  445. end;
  446. atFileName.Open;
  447. atFileName.First;
  448. while not atFileName.Eof do
  449. begin
  450. if ParentNode <> nil then
  451. etvFiles.Items.AddChildObject(ParentNode, atFileName.FieldByName(wName).AsString,
  452. Pointer(atFileName.FieldByName(wFID).AsInteger)).Checked := csChecked;
  453. atFileName.Next;
  454. end;
  455. atFileName.Close;
  456. end;
  457. function TImportWCostForm.TypeToName(AType: Integer): string;
  458. begin
  459. Result := '';
  460. case AType of
  461. // 路线
  462. wfLX: Result := wtLX;
  463. // 路线标
  464. wfLXB: Result := wtLXB;
  465. // 独立桥梁(大桥)
  466. wfDQ: Result := wtLX;
  467. // 独立桥梁标(大桥标)
  468. wfDQB: Result := wtDQB;
  469. // 费率
  470. wfFL: Result := wtFL;
  471. // 单价
  472. wfDJ: Result := wtDJ;
  473. // 定额库
  474. wfDE1, wfDE3, wfDE5, wfDE7: Result := wtDE;
  475. end;
  476. end;
  477. end.