DetailExcelImport.pas 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. unit DetailExcelImport;
  2. interface
  3. uses
  4. Classes, ProjectData, ScXlsOutput, MCacheTree, XLSAdapter, sdDB,
  5. Variants, Forms, Controls;
  6. type
  7. TDetailExcelImport = class
  8. private
  9. FProjectData: TProjectData;
  10. FTempFile: string;
  11. FExcel: TXlsOutPut;
  12. protected
  13. function GetCellValue(AXlsFile: TXLSFile; ARow, ACol: Integer): string;
  14. function GetCellValueFormat(AXlsFile: TXLSFile; ARow, ACol: Integer): string;
  15. function GetCellTrimStr(AXlsFile: TXLSFile; ARow, ACol: Integer): string;
  16. function GetCellFloat(AXlsFile: TXLSFile; ARow, ACol: Integer): Double;
  17. procedure BeginImport; virtual; abstract;
  18. procedure EndImport; virtual; abstract;
  19. procedure Import; virtual; abstract;
  20. public
  21. constructor Create(AProjectData: TProjectData); virtual;
  22. destructor Destroy; override;
  23. procedure ImportFile(const AFileName: string);
  24. property ProjectData: TProjectData read FProjectData;
  25. property Excel: TXlsOutPut read FExcel;
  26. end;
  27. // 平面分项清单格式导入,导入至某项目节节点之下
  28. TPlaneFxBillsExcelImport = class(TDetailExcelImport)
  29. private
  30. FParentID: Integer;
  31. FCacheTree: TBillsCacheTree;
  32. FCurRow: Integer;
  33. FXmjLevel1Col: Integer;
  34. FXmjLevel2Col: Integer;
  35. FXmjLevel3Col: Integer;
  36. FXmjLevel4Col: Integer;
  37. FXmjLevel5Col: Integer;
  38. FXmjLevel6Col: Integer;
  39. FXmjLevel7Col: Integer;
  40. FB_CodeCol: Integer;
  41. FNameCol: Integer;
  42. FUnitCol: Integer;
  43. FQuantityCol: Integer;
  44. FPriceCol: Integer;
  45. FDrawingCol: Integer;
  46. FMemoCol: Integer;
  47. procedure LoadXmjLevel1(AXlsFile: TXLSFile);
  48. procedure LoadXmjLevel2(AXlsFile: TXLSFile; AParent: TBillsCacheNode);
  49. procedure LoadXmjLevel3(AXlsFile: TXLSFile; AParent: TBillsCacheNode);
  50. procedure LoadXmjLevel4(AXlsFile: TXLSFile; AParent: TBillsCacheNode);
  51. procedure LoadXmjLevel5(AXlsFile: TXLSFile; AParent: TBillsCacheNode);
  52. procedure LoadXmjLevel6(AXlsFile: TXLSFile; AParent: TBillsCacheNode);
  53. procedure LoadXmjLevel7(AXlsFile: TXLSFile; AParent: TBillsCacheNode);
  54. procedure LoadBillsNode(AXlsFile: TXLSFile; AXmj: TBillsCacheNode);
  55. function LoadColumnsFromHead(AXlsFile: TXlsFile): Boolean;
  56. procedure LoadFxBills(AXlsFile: TXLSFile);
  57. procedure WriteNode(ADataSet: TsdDataSet; ANode: TBillsCacheNode);
  58. procedure WriteNodes(ADataSet: TsdDataSet);
  59. protected
  60. procedure BeginImport; override;
  61. procedure EndImport; override;
  62. procedure Import; override;
  63. public
  64. property ParentID: Integer read FParentID write FParentID;
  65. end;
  66. implementation
  67. uses
  68. UtilMethods, SysUtils, ZhAPI, SheetSelectFrm, UExcelAdapter, UFlxMessages,
  69. UFlxFormats, ProgressHintFrm;
  70. { TDetailExcelImport }
  71. constructor TDetailExcelImport.Create(AProjectData: TProjectData);
  72. begin
  73. FProjectData := AProjectData;
  74. FTempFile := GetTempFileName;
  75. end;
  76. destructor TDetailExcelImport.Destroy;
  77. begin
  78. if FileExists(FTempFile) then
  79. DeleteFile(FTempFile);
  80. inherited;
  81. end;
  82. function TDetailExcelImport.GetCellFloat(AXlsFile: TXLSFile; ARow,
  83. ACol: Integer): Double;
  84. begin
  85. Result := StrToFloatDef(GetCellTrimStr(AXlsFile, ARow, ACol), 0);
  86. end;
  87. function TDetailExcelImport.GetCellTrimStr(AXlsFile: TXLSFile; ARow,
  88. ACol: Integer): string;
  89. begin
  90. Result := Trim(GetCellValue(AXlsFile, ARow, ACol));
  91. end;
  92. function TDetailExcelImport.GetCellValue(AXlsFile: TXLSFile; ARow,
  93. ACol: Integer): string;
  94. var
  95. xlsCell: TXlsCellValue;
  96. begin
  97. Result := '';
  98. if not Assigned(AXlsFile) or (ARow = -1) or (ACol = -1) then Exit;
  99. xlsCell := AXlsFile.CellValueX[ARow, ACol];
  100. Result := VarToStrDef(xlsCell.Value, '');
  101. end;
  102. function TDetailExcelImport.GetCellValueFormat(AXlsFile: TXLSFile; ARow,
  103. ACol: Integer): string;
  104. function GetDigit(AFormat: WideString): Integer;
  105. var
  106. I: Integer;
  107. bDigit: Boolean;
  108. begin
  109. Result := 0;
  110. bDigit := False;
  111. for I := 1 to Length(AFormat) do
  112. begin
  113. if AFormat[I] = '.' then
  114. begin
  115. if bDigit then Break
  116. else bDigit := True;
  117. end
  118. else if AFormat[I] = ';' then Break
  119. else if bDigit and (AFormat[I] = '0') then
  120. Dec(Result);
  121. end;
  122. end;
  123. function FormatNum(AValue: Variant; AFormat: WideString): string;
  124. begin
  125. Result := AValue;
  126. if not VarIsNull(AValue) then
  127. begin
  128. if CheckNumeric(Result) then
  129. begin
  130. if Pos('%', AFormat) <> 0 then AValue := AValue * 100;
  131. if AFormat <> '' then
  132. Result := FloatToStr(AdvRoundTo(AValue, GetDigit(AFormat)))
  133. else
  134. Result := FloatToStr(AdvRoundTo(AValue, -2));
  135. if Pos('%', AFormat) <> 0 then Result := Result + '%';
  136. if AValue = '0' then Result := '';
  137. end;
  138. end;
  139. end;
  140. var
  141. xlsCell: TXlsCellValue;
  142. FlxFormat: TFlxFormat;
  143. begin
  144. Result := '';
  145. if not Assigned(AXlsFile) or (ARow = -1) or (ACol = -1) then Exit;
  146. xlsCell := AXlsFile.GetCellDataX(ARow, ACol);
  147. Result := xlsCell.Value;
  148. if xlsCell.XF <> -1 then
  149. begin
  150. FlxFormat := AXlsFile.FormatList[xlsCell.XF];
  151. Result := FormatNum(xlsCell.Value, FlxFormat.Format);
  152. end;
  153. end;
  154. procedure TDetailExcelImport.ImportFile(const AFileName: string);
  155. begin
  156. CopyFileOrFolder(AFileName, FTempFile);
  157. FExcel := TXlsOutPut.Create(FTempFile);
  158. BeginImport;
  159. try
  160. Import;
  161. finally
  162. EndImport;
  163. FExcel.Free;
  164. end;
  165. end;
  166. { TPlaneFxBillsExcelImport }
  167. procedure TPlaneFxBillsExcelImport.Import;
  168. begin
  169. FCurRow := 1;
  170. if LoadColumnsFromHead(FExcel.XlsFile) then
  171. begin
  172. LoadFxBills(FExcel.XlsFile);
  173. WriteNodes(FProjectData.BillsData.sddBills);
  174. end
  175. else
  176. ErrorMessage('导入的Excel格式有误!');
  177. end;
  178. procedure TPlaneFxBillsExcelImport.LoadBillsNode(AXlsFile: TXLSFile;
  179. AXmj: TBillsCacheNode);
  180. var
  181. sB_Code, sName, sUnits: string;
  182. vGclNode: TBillsCacheNode;
  183. fPrice: Double;
  184. begin
  185. sB_Code := Trim(GetCellValue(AXlsFile, FCurRow, FB_CodeCol));
  186. sName := Trim(GetCellValue(AXlsFile, FCurRow, FNameCol));
  187. sUnits := Trim(GetCellValue(AXlsFile, FCurRow, FUnitCol));
  188. fPrice := StrToFloatDef(GetCellValue(AXlsFile, FCurRow, FPriceCol), 0);
  189. if sB_Code <> '' then
  190. begin
  191. vGclNode := FCacheTree.FindGclChild(AXmj, sB_Code, sName, sUnits, fPrice);
  192. if not Assigned(vGclNode) then
  193. begin
  194. vGclNode := FCacheTree.AddNode(AXmj, nil);
  195. vGclNode.B_Code := sB_Code;
  196. vGclNode.Name := sName;
  197. vGclNode.Units := sUnits;
  198. vGclNode.Quantity := StrToFloatDef(GetCellValue(AXlsFile, FCurRow, FQuantityCol), 0);
  199. vGclNode.Price := fPrice;
  200. vGclNode.DrawingCode := Trim(GetCellValue(AXlsFile, FCurRow, FDrawingCol));
  201. vGclNode.MemoStr := Trim(GetCellValue(AXlsFile, FCurRow, FMemoCol));
  202. end
  203. else
  204. vGclNode.Quantity := vGclNode.Quantity + StrToFloatDef(GetCellValue(AXlsFile, FCurRow, FQuantityCol), 0);
  205. end;
  206. Inc(FCurRow);
  207. end;
  208. function TPlaneFxBillsExcelImport.LoadColumnsFromHead(AXlsFile: TXlsFile): Boolean;
  209. var
  210. iCol: Integer;
  211. sColName: string;
  212. begin
  213. Result := False;
  214. FXmjLevel1Col := -1;
  215. FXmjLevel2Col := -1;
  216. FXmjLevel3Col := -1;
  217. FXmjLevel4Col := -1;
  218. FXmjLevel5Col := -1;
  219. FXmjLevel6Col := -1;
  220. FXmjLevel7Col := -1;
  221. FB_CodeCol := -1;
  222. FNameCol := -1;
  223. FUnitCol := -1;
  224. FQuantityCol := -1;
  225. FPriceCol := -1;
  226. FDrawingCol := -1;
  227. FMemoCol := -1;
  228. UpdateProgressHint('正在识别Excel数据格式');
  229. UpdateProgressPosition(0);
  230. while not Result and (FCurRow <= AXlsFile.MaxRow) do
  231. begin
  232. for iCol := 1 to AXlsFile.MaxCol do
  233. begin
  234. sColName := Trim(GetCellValue(AXlsFile, FCurRow, iCol));
  235. if sColName = '第1层' then
  236. FXmjLevel1Col := iCol
  237. else if sColName = '第2层' then
  238. FXmjLevel2Col := iCol
  239. else if sColName = '第3层' then
  240. FXmjLevel3Col := iCol
  241. else if sColName = '第4层' then
  242. FXmjLevel4Col := iCol
  243. else if sColName = '第5层' then
  244. FXmjLevel5Col := iCol
  245. else if sColName = '第6层' then
  246. FXmjLevel6Col := iCol
  247. else if sColName = '第7层' then
  248. FXmjLevel7Col := iCol
  249. else if sColName = '清单号' then
  250. FB_CodeCol := iCol
  251. else if sColName = '清单名称' then
  252. FNameCol := iCol
  253. else if sColName = '单位' then
  254. FUnitCol := iCol
  255. else if sColName = '数量' then
  256. FQuantityCol := iCol
  257. else if sColName = '单价' then
  258. FPriceCol := iCol
  259. else if sColName = '图号' then
  260. FDrawingCol := iCol
  261. else if sColName = '备注' then
  262. FMemoCol := iCol
  263. end;
  264. Result := FXmjLevel1Col <> -1;
  265. Inc(FCurRow);
  266. end;
  267. end;
  268. procedure TPlaneFxBillsExcelImport.LoadFxBills(AXlsFile: TXLSFile);
  269. var
  270. iPos: Integer;
  271. begin
  272. UpdateProgressHint('正在解析平面台账数据');
  273. while FCurRow <= AXlsFile.MaxRow do
  274. begin
  275. iPos := FCurRow*100 div AXlsFile.MaxRow;
  276. UpdateProgressPosition(iPos);
  277. LoadXmjLevel1(AXlsFile);
  278. end;
  279. end;
  280. procedure TPlaneFxBillsExcelImport.LoadXmjLevel1(AXlsFile: TXLSFile);
  281. var
  282. sName: string;
  283. vXmj: TBillsCacheNode;
  284. iEndRow: Integer;
  285. begin
  286. sName := Trim(GetCellValue(AXlsFile, FCurRow, FXmjLevel1Col));
  287. with AXlsFile.CellMergedBounds[FCurRow, FXmjLevel1Col] do
  288. iEndRow := FCurRow + Bottom - Top;
  289. if sName <> '' then
  290. begin
  291. vXmj := FCacheTree.FindXmjChild(nil, '', sName);
  292. if not Assigned(vXmj) then
  293. begin
  294. vXmj := FCacheTree.AddNode(nil);
  295. vXmj.Name := sName;
  296. end;
  297. if FXmjLevel2Col <> -1 then
  298. begin
  299. while FCurRow <= iEndRow do
  300. LoadXmjLevel2(AXlsFile, vXmj);
  301. end
  302. else
  303. begin
  304. while FCurRow <= iEndRow do
  305. LoadBillsNode(AXlsFile, vXmj);
  306. end;
  307. end
  308. else
  309. Inc(FCurRow);
  310. end;
  311. procedure TPlaneFxBillsExcelImport.LoadXmjLevel2(AXlsFile: TXLSFile;
  312. AParent: TBillsCacheNode);
  313. var
  314. sName: string;
  315. vXmj: TBillsCacheNode;
  316. iEndRow: Integer;
  317. begin
  318. sName := Trim(GetCellValue(AXlsFile, FCurRow, FXmjLevel2Col));
  319. with AXlsFile.CellMergedBounds[FCurRow, FXmjLevel2Col] do
  320. iEndRow := FCurRow + Bottom - Top;
  321. if sName <> '' then
  322. begin
  323. vXmj := FCacheTree.FindXmjChild(AParent, '', sName);
  324. if not Assigned(vXmj) then
  325. begin
  326. vXmj := FCacheTree.AddNode(AParent);
  327. vXmj.Name := sName;
  328. end;
  329. if FXmjLevel3Col <> -1 then
  330. begin
  331. while FCurRow <= iEndRow do
  332. LoadXmjLevel3(AXlsFile, vXmj);
  333. end
  334. else
  335. begin
  336. while FCurRow <= iEndRow do
  337. LoadBillsNode(AXlsFile, vXmj);
  338. end;
  339. end
  340. else
  341. begin
  342. while FCurRow <= iEndRow do
  343. LoadBillsNode(AXlsFile, AParent);
  344. end;
  345. end;
  346. procedure TPlaneFxBillsExcelImport.LoadXmjLevel3(AXlsFile: TXLSFile;
  347. AParent: TBillsCacheNode);
  348. var
  349. sName: string;
  350. vXmj: TBillsCacheNode;
  351. iEndRow: Integer;
  352. begin
  353. sName := Trim(GetCellValue(AXlsFile, FCurRow, FXmjLevel3Col));
  354. with AXlsFile.CellMergedBounds[FCurRow, FXmjLevel3Col] do
  355. iEndRow := FCurRow + Bottom - Top;
  356. if sName <> '' then
  357. begin
  358. vXmj := FCacheTree.FindXmjChild(AParent, '', sName);
  359. if not Assigned(vXmj) then
  360. begin
  361. vXmj := FCacheTree.AddNode(AParent);
  362. vXmj.Name := sName;
  363. end;
  364. if FXmjLevel4Col <> -1 then
  365. begin
  366. while FCurRow <= iEndRow do
  367. LoadXmjLevel4(AXlsFile, vXmj);
  368. end
  369. else
  370. begin
  371. while FCurRow <= iEndRow do
  372. LoadBillsNode(AXlsFile, vXmj);
  373. end;
  374. end
  375. else
  376. begin
  377. while FCurRow <= iEndRow do
  378. LoadBillsNode(AXlsFile, AParent);
  379. end;
  380. end;
  381. procedure TPlaneFxBillsExcelImport.LoadXmjLevel4(AXlsFile: TXLSFile;
  382. AParent: TBillsCacheNode);
  383. var
  384. sName: string;
  385. vXmj: TBillsCacheNode;
  386. iEndRow: Integer;
  387. begin
  388. sName := Trim(GetCellValue(AXlsFile, FCurRow, FXmjLevel4Col));
  389. with AXlsFile.CellMergedBounds[FCurRow, FXmjLevel4Col] do
  390. iEndRow := FCurRow + Bottom - Top;
  391. if sName <> '' then
  392. begin
  393. vXmj := FCacheTree.FindXmjChild(AParent, '', sName);
  394. if not Assigned(vXmj) then
  395. begin
  396. vXmj := FCacheTree.AddNode(AParent);
  397. vXmj.Name := sName;
  398. end;
  399. if FXmjLevel5Col <> -1 then
  400. begin
  401. while FCurRow <= iEndRow do
  402. LoadXmjLevel5(AXlsFile, vXmj);
  403. end
  404. else
  405. begin
  406. while FCurRow <= iEndRow do
  407. LoadBillsNode(AXlsFile, vXmj);
  408. end;
  409. end
  410. else
  411. begin
  412. while FCurRow <= iEndRow do
  413. LoadBillsNode(AXlsFile, AParent);
  414. end;
  415. end;
  416. procedure TPlaneFxBillsExcelImport.LoadXmjLevel5(AXlsFile: TXLSFile;
  417. AParent: TBillsCacheNode);
  418. var
  419. sName: string;
  420. vXmj: TBillsCacheNode;
  421. iEndRow: Integer;
  422. begin
  423. sName := Trim(GetCellValue(AXlsFile, FCurRow, FXmjLevel5Col));
  424. with AXlsFile.CellMergedBounds[FCurRow, FXmjLevel5Col] do
  425. iEndRow := FCurRow + Bottom - Top;
  426. if sName <> '' then
  427. begin
  428. vXmj := FCacheTree.FindXmjChild(AParent, '', sName);
  429. if not Assigned(vXmj) then
  430. begin
  431. vXmj := FCacheTree.AddNode(AParent);
  432. vXmj.Name := sName;
  433. end;
  434. if FXmjLevel6Col <> -1 then
  435. begin
  436. while FCurRow <= iEndRow do
  437. LoadXmjLevel6(AXlsFile, vXmj);
  438. end
  439. else
  440. begin
  441. while FCurRow <= iEndRow do
  442. LoadBillsNode(AXlsFile, vXmj);
  443. end;
  444. end
  445. else
  446. begin
  447. while FCurRow <= iEndRow do
  448. LoadBillsNode(AXlsFile, AParent);
  449. end;
  450. end;
  451. procedure TPlaneFxBillsExcelImport.LoadXmjLevel6(AXlsFile: TXLSFile;
  452. AParent: TBillsCacheNode);
  453. var
  454. sName: string;
  455. vXmj: TBillsCacheNode;
  456. iEndRow: Integer;
  457. begin
  458. sName := Trim(GetCellValue(AXlsFile, FCurRow, FXmjLevel6Col));
  459. with AXlsFile.CellMergedBounds[FCurRow, FXmjLevel6Col] do
  460. iEndRow := FCurRow + Bottom - Top;
  461. if sName <> '' then
  462. begin
  463. vXmj := FCacheTree.FindXmjChild(AParent, '', sName);
  464. if not Assigned(vXmj) then
  465. begin
  466. vXmj := FCacheTree.AddNode(AParent);
  467. vXmj.Name := sName;
  468. end;
  469. if FXmjLevel7Col <> -1 then
  470. begin
  471. while FCurRow <= iEndRow do
  472. LoadXmjLevel7(AXlsFile, vXmj);
  473. end
  474. else
  475. begin
  476. while FCurRow <= iEndRow do
  477. LoadBillsNode(AXlsFile, vXmj);
  478. end;
  479. end
  480. else
  481. begin
  482. while FCurRow <= iEndRow do
  483. LoadBillsNode(AXlsFile, AParent);
  484. end;
  485. end;
  486. procedure TPlaneFxBillsExcelImport.LoadXmjLevel7(AXlsFile: TXLSFile;
  487. AParent: TBillsCacheNode);
  488. var
  489. sName: string;
  490. vXmj: TBillsCacheNode;
  491. iEndRow: Integer;
  492. begin
  493. sName := Trim(GetCellValue(AXlsFile, FCurRow, FXmjLevel7Col));
  494. if sName <> '' then
  495. begin
  496. vXmj := FCacheTree.FindXmjChild(AParent, '', sName);
  497. if not Assigned(vXmj) then
  498. begin
  499. vXmj := FCacheTree.AddNode(AParent);
  500. vXmj.Name := sName;
  501. end;
  502. with AXlsFile.CellMergedBounds[FCurRow, FXmjLevel7Col] do
  503. iEndRow := FCurRow + Bottom - Top;
  504. while FCurRow <= iEndRow do
  505. LoadBillsNode(AXlsFile, vXmj);
  506. end
  507. else
  508. begin
  509. while FCurRow <= iEndRow do
  510. LoadBillsNode(AXlsFile, AParent);
  511. end;
  512. end;
  513. procedure TPlaneFxBillsExcelImport.WriteNodes(ADataSet: TsdDataSet);
  514. var
  515. i, iPos: Integer;
  516. begin
  517. UpdateProgressHint('写入读取的Excel数据');
  518. UpdateProgressPosition(0);
  519. for i := 0 to FCacheTree.CacheNodes.Count - 1 do
  520. begin
  521. WriteNode(ADataSet, TBillsCacheNode(FCacheTree.CacheNodes[i]));
  522. iPos := i*100 div FCacheTree.CacheNodes.Count;
  523. UpdateProgressPosition(iPos);
  524. end;
  525. UpdateProgressPosition(100);
  526. end;
  527. procedure TPlaneFxBillsExcelImport.WriteNode(ADataSet: TsdDataSet;
  528. ANode: TBillsCacheNode);
  529. var
  530. Rec: TsdDataRecord;
  531. begin
  532. if ANode.B_Code <> '' then
  533. UpdateProgressHint('写入读取的Excel数据 ' + ANode.B_Code)
  534. else
  535. UpdateProgressHint('写入读取的Excel数据 ' + ANode.Name);
  536. Rec := ADataSet.Add;
  537. Rec.ValueByName('ID').AsInteger := ANode.ID;
  538. if ANode.ParentID = -1 then
  539. Rec.ValueByName('ParentID').AsInteger := ParentID
  540. else
  541. Rec.ValueByName('ParentID').AsInteger := ANode.ParentID;
  542. Rec.ValueByName('NextSiblingID').AsInteger := ANode.NextSiblingID;
  543. Rec.ValueByName('B_Code').AsString := ANode.B_Code;
  544. Rec.ValueByName('Name').AsString := ANode.Name;
  545. Rec.ValueByName('Units').AsString := ANode.Units;
  546. Rec.ValueByName('Price').AsFloat := PriceRoundTo(ANode.Price);
  547. Rec.ValueByName('OrgQuantity').AsFloat := QuantityRoundTo(ANode.Quantity);
  548. Rec.ValueByName('DrawingCode').AsString := ANode.DrawingCode;
  549. Rec.ValueByName('MemoStr').AsString := ANode.MemoStr;
  550. // 解锁前,新增清单为变更清单,解锁后,新增清单为0号台账清单
  551. if FProjectData.ProjProperties.PhaseCount > 0 then
  552. Rec.ValueByName('IsMeasureAdd').AsBoolean := not FProjectData.CanUnlockInfo;
  553. end;
  554. procedure TPlaneFxBillsExcelImport.BeginImport;
  555. begin
  556. Screen.Cursor := crHourGlass;
  557. ShowProgressHint('导入Excel数据', 100);
  558. FCacheTree := TBillsCacheTree.Create;
  559. FCacheTree.NewNodeID := FProjectData.BillsData.GetMaxBillsID + 1;
  560. FProjectData.DisConnectTree;
  561. FProjectData.BillsData.DisableEvents;
  562. end;
  563. procedure TPlaneFxBillsExcelImport.EndImport;
  564. var
  565. ParentRec: TsdDataRecord;
  566. begin
  567. FCacheTree.Free;
  568. FProjectData.BillsData.EnableEvents;
  569. FProjectData.ReConnectTree;
  570. ParentRec := FProjectData.BillsData.sddBills.FindKey('idxID', ParentID);
  571. FProjectData.BillsCompileData.sdvBillsCompile.LocateInControl(ParentRec);
  572. FProjectData.BillsCompileData.CalculateAll;
  573. CloseProgressHint;
  574. Screen.Cursor := crDefault;
  575. end;
  576. end.