BGLDm.pas 17 KB

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