BGLDm.pas 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. unit BGLDm;
  2. interface
  3. uses
  4. SysUtils, Classes, DB, DBClient, Provider, ADODB, sdIDTree,
  5. sdDB;
  6. type
  7. TBGLSelectInfo = class(TObject)
  8. private
  9. FB_Code: string;
  10. FName: string;
  11. FUnits: string;
  12. FPrice: Double;
  13. FIsOrg: Boolean;
  14. FTotalNum: Double;
  15. FNums: TStrings;
  16. FCodes: TStrings;
  17. procedure SetMergedCode(const Value: string);
  18. procedure SetMergedNum(const Value: string);
  19. function GetCount: Integer;
  20. function GetMergedCode: string;
  21. function GetMergedNum: string;
  22. public
  23. constructor Create(ARec: TsdDataRecord; ATotalNum: Double; AIsOrg: Boolean);
  24. destructor Destroy; override;
  25. procedure Clear;
  26. property MergedCode: string read GetMergedCode write SetMergedCode;
  27. property MergedNum: string read GetMergedNum write SetMergedNum;
  28. property Codes: TStrings read FCodes;
  29. property Nums: TStrings read FNums;
  30. property Count: Integer read GetCount;
  31. property TotalNum: Double read FTotalNum write FTotalNum;
  32. property IsOrg: Boolean read FIsOrg;
  33. property B_Code: string read FB_Code;
  34. property Name: string read FName;
  35. property Units: string read FUnits;
  36. property Price: Double read FPrice;
  37. end;
  38. TBGLData = class(TDataModule)
  39. atBGL: TADOTable;
  40. dspBGL: TDataSetProvider;
  41. cdsBGL: TClientDataSet;
  42. cdsBGLID: TIntegerField;
  43. cdsBGLTotalPrice: TFloatField;
  44. cdsBGLName: TWideStringField;
  45. cdsBGLCode: TWideStringField;
  46. cdsBGLPos_Reason: TWideStringField;
  47. cdsBGLDirection: TWideStringField;
  48. cdsBGLDrawingCode: TWideStringField;
  49. cdsBGLLocked: TBooleanField;
  50. cdsBGLApprovalCode: TWideStringField;
  51. cdsBGLCreatePhaseID: TIntegerField;
  52. cdsBGLView: TClientDataSet;
  53. cdsBGLViewID: TIntegerField;
  54. cdsBGLViewName: TWideStringField;
  55. cdsBGLViewTotalPrice: TFloatField;
  56. cdsBGLViewCode: TWideStringField;
  57. cdsBGLViewPos_Reason: TWideStringField;
  58. cdsBGLViewDirection: TWideStringField;
  59. cdsBGLViewDrawingCode: TWideStringField;
  60. cdsBGLViewLocked: TBooleanField;
  61. cdsBGLViewApprovalCode: TWideStringField;
  62. cdsBGLViewCreatePhaseID: TIntegerField;
  63. dsBGL: TDataSource;
  64. atBGBills: TADOTable;
  65. dspBGBills: TDataSetProvider;
  66. cdsBGBills: TClientDataSet;
  67. cdsBGBillsID: TIntegerField;
  68. cdsBGBillsBGID: TIntegerField;
  69. cdsBGBillsB_Code: TWideStringField;
  70. cdsBGBillsName: TWideStringField;
  71. cdsBGBillsUnits: TWideStringField;
  72. cdsBGBillsPrice: TFloatField;
  73. cdsBGBillsQuantity: TFloatField;
  74. cdsBGBillsTotalPrice: TFloatField;
  75. cdsBGBillsUsedQuantity: TFloatField;
  76. cdsBGBillsLocked: TBooleanField;
  77. cdsBGBillsView: TClientDataSet;
  78. cdsBGBillsViewID: TIntegerField;
  79. cdsBGBillsViewBGID: TIntegerField;
  80. cdsBGBillsViewB_Code: TWideStringField;
  81. cdsBGBillsViewName: TWideStringField;
  82. cdsBGBillsViewUnits: TWideStringField;
  83. cdsBGBillsViewPrice: TFloatField;
  84. cdsBGBillsViewQuantity: TFloatField;
  85. cdsBGBillsViewTotalPrice: TFloatField;
  86. cdsBGBillsViewUsedQuantity: TFloatField;
  87. cdsBGBillsViewLocked: TBooleanField;
  88. cdsBGLExecutionRate: TFloatField;
  89. cdsBGLViewExecutionRate: TFloatField;
  90. procedure cdsBGBillsViewAfterInsert(DataSet: TDataSet);
  91. procedure cdsBGBillsViewAfterPost(DataSet: TDataSet);
  92. procedure cdsBGBillsViewQuantityChange(Sender: TField);
  93. procedure cdsBGBillsViewBeforePost(DataSet: TDataSet);
  94. procedure cdsBGLViewBeforePost(DataSet: TDataSet);
  95. procedure cdsBGLViewBeforeDelete(DataSet: TDataSet);
  96. procedure cdsBGBillsViewBeforeDelete(DataSet: TDataSet);
  97. procedure cdsBGBillsViewAfterDelete(DataSet: TDataSet);
  98. procedure cdsBGLViewNewRecord(DataSet: TDataSet);
  99. procedure cdsBGBillsViewQuantitySetText(Sender: TField;
  100. const Text: String);
  101. procedure cdsBGBillsViewPriceSetText(Sender: TField;
  102. const Text: String);
  103. procedure cdsBGLViewCodeChange(Sender: TField);
  104. private
  105. FProjectData: TObject;
  106. procedure GatherBGLTotalPrice(ABGLID: Integer);
  107. procedure UpdateBGLTotalPrice(ABGLID: Integer; ADiffer: Double);
  108. procedure UpdateBGLExecutionRate(ABGLID: Integer);
  109. procedure ApplyBGL(ABGLInfo: TBGLSelectInfo); overload;
  110. procedure DeleteBGBills(ABGID: Integer);
  111. function CheckSameB_Code(ABGID: Integer; const AB_Code: string): Boolean;
  112. function CheckBGLUsed(ABGID: Integer): Boolean;
  113. function LocateBGL(const ACode: string): Boolean;
  114. procedure LockAllBGL;
  115. procedure LockAllBGBills;
  116. public
  117. constructor Create(AProjectData: TObject);
  118. destructor Destroy; override;
  119. procedure Open(AConnection: TADOConnection);
  120. procedure Close;
  121. procedure Save;
  122. function AllBGLTotalPrice: Double;
  123. procedure AddBGL(const sCode: string);
  124. procedure ApplyBGL(AOrgBGL, ANewBGL: TBGLSelectInfo); overload;
  125. procedure BatchWritePos_Reason;
  126. procedure LockAll;
  127. property ProjectData: TObject read FProjectData;
  128. end;
  129. implementation
  130. uses
  131. ZhAPI, Math, ProjectData, BillsDm, Variants, UtilMethods;
  132. {$R *.dfm}
  133. { TBGLSelectInfo }
  134. procedure TBGLSelectInfo.Clear;
  135. begin
  136. FCodes.Clear;
  137. FNums.Clear;
  138. end;
  139. constructor TBGLSelectInfo.Create(ARec: TsdDataRecord;
  140. ATotalNum: Double; AIsOrg: Boolean);
  141. begin
  142. FB_Code := ARec.ValueByName('B_Code').AsString;
  143. FName := ARec.ValueByName('Name').AsString;
  144. FUnits := ARec.ValueByName('Units').AsString;
  145. FPrice := ARec.ValueByName('Price').AsFloat;
  146. FTotalNum := ATotalNum;
  147. FIsOrg := AIsOrg;
  148. FCodes := TStringList.Create;
  149. FCodes.Delimiter := ';';
  150. FNums := TStringList.Create;
  151. FNums.Delimiter := ';';
  152. end;
  153. destructor TBGLSelectInfo.Destroy;
  154. begin
  155. FNums.Free;
  156. FCodes.Free;
  157. inherited;
  158. end;
  159. function TBGLSelectInfo.GetCount: Integer;
  160. begin
  161. Result := Min(FCodes.Count, FNums.Count);
  162. end;
  163. function TBGLSelectInfo.GetMergedCode: string;
  164. begin
  165. Result := FCodes.DelimitedText;
  166. end;
  167. function TBGLSelectInfo.GetMergedNum: string;
  168. begin
  169. Result := FNums.DelimitedText;
  170. end;
  171. procedure TBGLSelectInfo.SetMergedCode(const Value: string);
  172. begin
  173. if Value <> '' then
  174. FCodes.DelimitedText := Value
  175. else
  176. FCodes.Clear;
  177. end;
  178. procedure TBGLSelectInfo.SetMergedNum(const Value: string);
  179. begin
  180. if Value <> '' then
  181. FNums.DelimitedText := Value
  182. else
  183. FNums.Clear;
  184. end;
  185. { TBGLData }
  186. constructor TBGLData.Create(AProjectData: TObject);
  187. begin
  188. inherited Create(nil);
  189. FProjectData := AProjectData;
  190. end;
  191. destructor TBGLData.Destroy;
  192. begin
  193. inherited;
  194. end;
  195. procedure TBGLData.Open(AConnection: TADOConnection);
  196. begin
  197. atBGL.Connection := AConnection;
  198. cdsBGL.Open;
  199. cdsBGL.AddIndex('idxID', 'ID', []);
  200. cdsBGL.AddIndex('idxCode', 'Code', []);
  201. cdsBGL.IndexName := 'idxID';
  202. cdsBGLView.CloneCursor(cdsBGL, True);
  203. atBGBills.Connection := AConnection;
  204. cdsBGBills.Open;
  205. cdsBGBillsView.CloneCursor(cdsBGBills, True);
  206. cdsBGBills.IndexFieldNames := 'ID';
  207. cdsBGBillsView.MasterSource := dsBGL;
  208. cdsBGBillsView.MasterFields := 'ID';
  209. cdsBGBillsView.IndexFieldNames := 'BGID;ID';
  210. end;
  211. procedure TBGLData.Save;
  212. begin
  213. cdsBGL.ApplyUpdates(0);
  214. cdsBGBills.ApplyUpdates(0);
  215. end;
  216. procedure TBGLData.cdsBGBillsViewAfterInsert(DataSet: TDataSet);
  217. begin
  218. cdsBGBillsViewID.AsInteger := GetNewIDOfIndex(cdsBGBills);
  219. cdsBGBillsViewBGID.AsInteger := cdsBGLViewID.AsInteger;
  220. end;
  221. procedure TBGLData.AddBGL(const sCode: string);
  222. begin
  223. cdsBGLView.DisableControls;
  224. cdsBGLView.Append;
  225. cdsBGLViewCode.AsString := sCode;
  226. cdsBGLView.Post;
  227. cdsBGLView.EnableControls;
  228. end;
  229. procedure TBGLData.cdsBGBillsViewAfterPost(DataSet: TDataSet);
  230. procedure DoB_CodeChange;
  231. var
  232. Rec: TsdDataRecord;
  233. begin
  234. cdsBGBillsViewB_Code.Tag := 0;
  235. cdsBGBillsView.Edit;
  236. with TProjectData(FProjectData).BillsData do
  237. begin
  238. Rec := sddBills.Locate('B_Code', cdsBGBillsViewB_Code.AsString);
  239. if Rec <> nil then
  240. begin
  241. cdsBGBillsViewName.AsString := Rec.ValueByName('Name').AsString;
  242. cdsBGBillsViewUnits.AsString := Rec.ValueByName('Units').AsString;
  243. cdsBGBillsViewPrice.AsString := Rec.ValueByName('Price').AsString;
  244. end;
  245. end;
  246. cdsBGBillsView.Post;
  247. end;
  248. procedure ClearChangeTag;
  249. begin
  250. cdsBGBillsViewB_Code.Tag := 0;
  251. cdsBGBillsViewName.Tag := 0;
  252. cdsBGBillsViewUnits.Tag := 0;
  253. cdsBGBillsViewPrice.Tag := 0;
  254. cdsBGBillsViewQuantity.Tag := 0;
  255. end;
  256. var
  257. fTotalPrice, Differ: Double;
  258. begin
  259. if (cdsBGBillsViewB_Code.Tag = 1) then
  260. DoB_CodeChange;
  261. if (cdsBGBillsViewPrice.Tag = 1) or
  262. (cdsBGBillsViewQuantity.Tag = 1) then
  263. begin
  264. cdsBGBillsViewPrice.Tag := 0;
  265. cdsBGBillsViewQuantity.Tag := 0;
  266. fTotalPrice := TotalPriceRoundTo(cdsBGBillsViewPrice.AsFloat * cdsBGBillsViewQuantity.AsFloat);
  267. UpdateBGLTotalPrice(cdsBGBillsViewBGID.AsInteger, fTotalPrice - cdsBGBillsViewTotalPrice.AsFloat);
  268. cdsBGBillsView.Edit;
  269. cdsBGBillsViewTotalPrice.AsFloat := fTotalPrice;
  270. cdsBGBillsView.Post;
  271. end;
  272. ClearChangeTag;
  273. end;
  274. procedure TBGLData.cdsBGBillsViewQuantityChange(Sender: TField);
  275. begin
  276. Sender.Tag := 1;
  277. end;
  278. procedure TBGLData.GatherBGLTotalPrice(ABGLID: Integer);
  279. var
  280. fGather: Double;
  281. begin
  282. cdsBGBills.Filter := 'BGID = ' + IntToStr(ABGLID);
  283. cdsBGBills.Filtered := True;
  284. try
  285. fGather := 0;
  286. cdsBGBills.First;
  287. while not cdsBGBills.Eof do
  288. begin
  289. fGather := fGather + cdsBGBillsTotalPrice.AsFloat;
  290. cdsBGBills.Next;
  291. end;
  292. if cdsBGL.FindKey([ABGLID]) then
  293. begin
  294. cdsBGL.Edit;
  295. cdsBGLTotalPrice.AsFloat := fGather;
  296. cdsBGL.Post;
  297. end;
  298. finally
  299. cdsBGBills.Filtered := False;
  300. end;
  301. end;
  302. procedure TBGLData.UpdateBGLTotalPrice(ABGLID: Integer; ADiffer: Double);
  303. begin
  304. if cdsBGL.FindKey([ABGLID]) then
  305. begin
  306. cdsBGL.Edit;
  307. cdsBGLTotalPrice.AsFloat := cdsBGLTotalPrice.AsFloat + ADiffer;
  308. cdsBGL.Post;
  309. end;
  310. end;
  311. procedure TBGLData.ApplyBGL(AOrgBGL, ANewBGL: TBGLSelectInfo);
  312. begin
  313. ApplyBGL(AOrgBGL);
  314. ApplyBGL(ANewBGL);
  315. end;
  316. procedure TBGLData.ApplyBGL(ABGLInfo: TBGLSelectInfo);
  317. var
  318. I: Integer;
  319. begin
  320. for I := 0 to ABGLInfo.Count - 1 do
  321. if LocateBGL(ABGLInfo.Codes[I]) and
  322. cdsBGBills.Locate('BGID;B_Code', VarArrayOf([cdsBGLID.AsInteger, ABGLInfo.B_Code]), []) then
  323. begin
  324. cdsBGBills.Edit;
  325. if ABGLInfo.IsOrg then
  326. cdsBGBillsUsedQuantity.AsFloat := cdsBGBillsUsedQuantity.AsFloat
  327. - QuantityRoundTo(StrToFloatDef(ABGLInfo.Nums[I], 0))
  328. else
  329. cdsBGBillsUsedQuantity.AsFloat := cdsBGBillsUsedQuantity.AsFloat
  330. + QuantityRoundTo(StrToFloatDef(ABGLInfo.Nums[I], 0));
  331. cdsBGBills.Post;
  332. UpdateBGLExecutionRate(cdsBGBillsBGID.AsInteger);
  333. end;
  334. end;
  335. procedure TBGLData.cdsBGBillsViewBeforePost(DataSet: TDataSet);
  336. procedure DisplayErrorMessage(const AHint: string);
  337. begin
  338. cdsBGBillsViewB_Code.Tag := 0;
  339. cdsBGBillsViewName.Tag := 0;
  340. cdsBGBillsViewUnits.Tag := 0;
  341. cdsBGBillsViewPrice.Tag := 0;
  342. cdsBGBillsViewQuantity.Tag := 0;
  343. ShowErrorMessage(AHint);
  344. Abort;
  345. end;
  346. begin
  347. if (cdsBGBillsViewB_Code.Tag = 1) or
  348. (cdsBGBillsViewName.Tag = 1) or
  349. (cdsBGBillsViewUnits.Tag = 1) or
  350. (cdsBGBillsViewPrice.Tag = 1) then
  351. begin
  352. if cdsBGBillsViewLocked.AsBoolean then
  353. DisplayErrorMessage('变更清单已被锁定,不可修改!');
  354. if cdsBGBillsViewUsedQuantity.AsFloat <> 0 then
  355. DisplayErrorMessage('变更令已被应用至清单,不可修改!');
  356. end;
  357. if (cdsBGBillsViewQuantity.Tag = 1) then
  358. begin
  359. if cdsBGBillsViewLocked.AsBoolean then
  360. DisplayErrorMessage('变更清单已被锁定,不可修改!');
  361. if (cdsBGBillsViewUsedQuantity.AsFloat <> 0) and
  362. (cdsBGBillsViewQuantity.AsFloat < cdsBGBillsViewUsedQuantity.AsFloat) then
  363. DisplayErrorMessage('变更清单的清单数量应大于已变更数量!');
  364. end;
  365. if cdsBGBillsViewB_Code.Tag = 1 then
  366. if CheckSameB_Code(cdsBGBillsViewBGID.AsInteger, cdsBGBillsViewB_Code.AsString) then
  367. begin
  368. cdsBGBillsViewB_Code.Tag := 0;
  369. ShowErrorMessage('不允许存在同编号变更清单!');
  370. Abort;
  371. end;
  372. end;
  373. procedure TBGLData.cdsBGLViewBeforePost(DataSet: TDataSet);
  374. var
  375. iIncrement: Integer;
  376. sNewCode: string;
  377. begin
  378. if cdsBGLViewCode.Tag = 1 then
  379. begin
  380. cdsBGLViewCode.Tag := 0;
  381. if cdsBGLViewLocked.AsBoolean then
  382. begin
  383. ShowErrorMessage('当前变更令已锁定,不可修改');
  384. Abort;
  385. end;
  386. if CheckBGLUsed(cdsBGLViewID.AsInteger) then
  387. begin
  388. ShowErrorMessage('当前变更令下变更清单已被应用到清单,不可修改');
  389. Abort;
  390. end;
  391. end;
  392. sNewCode := cdsBGLViewCode.AsString;
  393. if Pos(';', sNewCode) > 0 then
  394. begin
  395. ShowErrorMessage('变更令号不可输入'';'',请使用其他符号代替!');
  396. Abort;
  397. end;
  398. // 相同变更令号应递增[1],[2]...
  399. iIncrement := 1;
  400. while LocateBGL(sNewCode) and (cdsBGLID.AsInteger <> cdsBGLViewID.AsInteger) do
  401. begin
  402. sNewCode := Format('%s[%d]', [cdsBGLViewCode.AsString, iIncrement]);
  403. Inc(iIncrement);
  404. end;
  405. cdsBGLViewCode.AsString := sNewCode;
  406. end;
  407. procedure TBGLData.DeleteBGBills(ABGID: Integer);
  408. begin
  409. cdsBGBills.Filter := 'BGID = ' + IntToStr(ABGID);
  410. cdsBGBills.Filtered := True;
  411. try
  412. cdsBGBills.First;
  413. while not cdsBGBills.Eof do
  414. cdsBGBills.Delete;
  415. finally
  416. cdsBGBills.Filtered := False;
  417. end;
  418. end;
  419. procedure TBGLData.cdsBGLViewBeforeDelete(DataSet: TDataSet);
  420. begin
  421. if cdsBGLViewLocked.AsBoolean then
  422. raise Exception.Create('变更令已被锁定,不可删除!');
  423. if CheckBGLUsed(cdsBGLViewID.AsInteger) then
  424. raise Exception.Create('变更令下变更清单已被应用到清单,不可删除!');
  425. DeleteBGBills(cdsBGLViewID.AsInteger);
  426. end;
  427. function TBGLData.CheckSameB_Code(ABGID: Integer;
  428. const AB_Code: string): Boolean;
  429. begin
  430. Result := False;
  431. cdsBGBills.Filter := 'BGID = ' + IntToStr(ABGID);
  432. cdsBGBills.Filtered := True;
  433. try
  434. cdsBGBills.First;
  435. while (not cdsBGBills.Eof) and (not Result) do
  436. begin
  437. Result := Result or SameText(cdsBGBillsB_Code.AsString, AB_Code);
  438. cdsBGBills.Next;
  439. end;
  440. finally
  441. cdsBGBills.Filtered := False;
  442. end;
  443. end;
  444. procedure TBGLData.cdsBGBillsViewBeforeDelete(DataSet: TDataSet);
  445. begin
  446. if cdsBGBillsViewLocked.AsBoolean then
  447. raise Exception.Create('变更清单已被锁定,不可删除!');
  448. if cdsBGBillsViewUsedQuantity.AsFloat <> 0 then
  449. raise Exception.Create('变更清单已被应用至清单,不可删除!');
  450. end;
  451. function TBGLData.CheckBGLUsed(ABGID: Integer): Boolean;
  452. begin
  453. Result := False;
  454. cdsBGBills.Filter := 'BGID = ' + IntToStr(ABGID);
  455. cdsBGBills.Filtered := True;
  456. try
  457. cdsBGBills.First;
  458. while (not cdsBGBills.Eof) and (not Result) do
  459. begin
  460. Result := Result or (cdsBGBillsUsedQuantity.AsFloat <> 0);
  461. cdsBGBills.Next;
  462. end;
  463. finally
  464. cdsBGBills.Filtered := False;
  465. end;
  466. end;
  467. procedure TBGLData.LockAll;
  468. begin
  469. LockAllBGL;
  470. LockAllBGBills;
  471. end;
  472. procedure TBGLData.LockAllBGBills;
  473. begin
  474. cdsBGBills.First;
  475. while not cdsBGBills.Eof do
  476. begin
  477. cdsBGBills.Edit;
  478. cdsBGBillsLocked.AsBoolean := True;
  479. cdsBGBills.Post;
  480. cdsBGBills.Next;
  481. end;
  482. end;
  483. procedure TBGLData.LockAllBGL;
  484. begin
  485. cdsBGL.First;
  486. while not cdsBGL.Eof do
  487. begin
  488. cdsBGL.Edit;
  489. cdsBGLLocked.AsBoolean := True;
  490. cdsBGL.Post;
  491. cdsBGL.Next;
  492. end;
  493. end;
  494. procedure TBGLData.cdsBGBillsViewAfterDelete(DataSet: TDataSet);
  495. begin
  496. GatherBGLTotalPrice(cdsBGLViewID.AsInteger);
  497. end;
  498. procedure TBGLData.BatchWritePos_Reason;
  499. begin
  500. cdsBGL.First;
  501. while not cdsBGL.Eof do
  502. begin
  503. cdsBGL.Edit;
  504. cdsBGLPos_Reason.AsString := cdsBGLName.AsString;
  505. cdsBGL.Post;
  506. cdsBGL.Next;
  507. end;
  508. end;
  509. procedure TBGLData.cdsBGLViewNewRecord(DataSet: TDataSet);
  510. begin
  511. cdsBGLViewID.AsInteger := GetNewIDOfIndex(cdsBGL);
  512. cdsBGLViewCreatePhaseID.AsInteger := TProjectData(FProjectData).PhaseIndex;
  513. end;
  514. procedure TBGLData.UpdateBGLExecutionRate(ABGLID: Integer);
  515. function GetBGLExecutionTotalPrice: Double;
  516. var
  517. cdsTemp: TClientDataSet;
  518. begin
  519. Result := 0;
  520. cdsTemp := TClientDataSet.Create(nil);
  521. try
  522. cdsTemp.CloneCursor(cdsBGBills, True);
  523. cdsTemp.Filter := Format('BGID = %d', [ABGLID]);
  524. cdsTemp.Filtered := True;
  525. cdsTemp.First;
  526. while not cdsTemp.Eof do
  527. begin
  528. Result := Result + TotalPriceRoundTo(
  529. cdsTemp.FieldByName('UsedQuantity').AsFloat * cdsTemp.FieldByName('Price').AsFloat);
  530. cdsTemp.Next;
  531. end;
  532. finally
  533. cdsTemp.Free;
  534. end;
  535. end;
  536. begin
  537. if cdsBGL.FindKey([ABGLID]) then
  538. begin
  539. cdsBGL.Edit;
  540. cdsBGLExecutionRate.AsFloat := AdvRoundTo(GetBGLExecutionTotalPrice/cdsBGLTotalPrice.AsFloat*100);
  541. cdsBGL.Post;
  542. end;
  543. end;
  544. function TBGLData.AllBGLTotalPrice: Double;
  545. begin
  546. Result := 0;
  547. cdsBGL.First;
  548. while not cdsBGL.Eof do
  549. begin
  550. Result := Result + cdsBGLTotalPrice.AsFloat;
  551. cdsBGL.Next;
  552. end;
  553. end;
  554. procedure TBGLData.cdsBGBillsViewQuantitySetText(Sender: TField;
  555. const Text: String);
  556. begin
  557. Sender.AsFloat := QuantityRoundTo(StrToFloatDef(Text, 0));
  558. end;
  559. procedure TBGLData.cdsBGBillsViewPriceSetText(Sender: TField;
  560. const Text: String);
  561. begin
  562. Sender.AsFloat := PriceRoundTo(StrToFloatDef(Text, 0));
  563. end;
  564. procedure TBGLData.cdsBGLViewCodeChange(Sender: TField);
  565. begin
  566. Sender.Tag := 1;
  567. end;
  568. procedure TBGLData.Close;
  569. begin
  570. cdsBGL.IndexName := '';
  571. cdsBGL.Close;
  572. cdsBGBills.Close;
  573. end;
  574. function TBGLData.LocateBGL(const ACode: string): Boolean;
  575. begin
  576. cdsBGL.IndexName := 'idxCode';
  577. try
  578. Result := cdsBGL.FindKey([ACode]);
  579. finally
  580. cdsBGL.IndexName := 'idxID';
  581. end;
  582. end;
  583. end.