ProjectGLDm.pas 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. unit ProjectGLDm;
  2. interface
  3. uses
  4. SysUtils, Classes, sdDB, sdProvider, ADODB, mDataRecord;
  5. type
  6. TProjectGLData = class(TDataModule)
  7. sdpProjectGL: TsdADOProvider;
  8. sddProjectGL: TsdDataSet;
  9. sdvProjectGL: TsdDataView;
  10. procedure sddProjectGLAfterAddRecord(ARecord: TsdDataRecord);
  11. procedure sddProjectGLBeforeValueChange(AValue: TsdValue;
  12. const NewValue: Variant; var Allow: Boolean);
  13. procedure sddProjectGLAfterValueChanged(AValue: TsdValue);
  14. procedure sdvProjectGLGetText(var Text: String; ARecord: TsdDataRecord;
  15. AValue: TsdValue; AColumn: TsdViewColumn; DisplayText: Boolean);
  16. procedure sddProjectGLGetRecordClass(var ARecordClass: TsdRecordClass);
  17. procedure sdvProjectGLSetText(var Text: String; ARecord: TsdDataRecord;
  18. AValue: TsdValue; AColumn: TsdViewColumn; var Allow: Boolean);
  19. procedure sddProjectGLBeforeDeleteRecord(ARecord: TsdDataRecord;
  20. var Allow: Boolean);
  21. private
  22. FProjectData: TObject;
  23. FTempGLs: TList;
  24. function CheckSameCode(ACode: Integer): Boolean;
  25. function CheckApplied(AGLID: Integer): Boolean;
  26. procedure LoadDetailGLs(AGLID: Integer);
  27. procedure CalculateDeltaPrice(ARec: TProjectGLRecord);
  28. procedure CalculatePrice;
  29. procedure CalculatePM_Quantity(ARec: TProjectGLRecord);
  30. procedure CalculatePM_TotalPrice(ARec: TProjectGLRecord);
  31. procedure CalculatePriceMargin;
  32. procedure CalculateRelaBills(ARec: TProjectGLRecord);
  33. procedure ExecuteSql(const ASql: string);
  34. procedure SaveGLPrice;
  35. procedure SavePM_CurData;
  36. procedure BeforeBatchOperation;
  37. procedure AfterBatchOperation;
  38. function GetValidDeltaPrice(AID: Integer): Double;
  39. function GetPM_TotalPrice: Double;
  40. function GetActive: Boolean;
  41. public
  42. constructor Create(AProjectData: TObject);
  43. destructor Destroy; override;
  44. procedure Open(AConnection: TADOConnection);
  45. procedure Save;
  46. procedure LoadCurPhaseInfoPrice;
  47. procedure LoadStagePM_CalcData;
  48. procedure CalculateAll;
  49. procedure CalculateGL_PM(AGLID: Integer);
  50. procedure CalculateGLs_PM(ADetailGLs: TList);
  51. property ProjectData: TObject read FProjectData write FProjectData;
  52. property Active: Boolean read GetActive;
  53. property ValidDeltaPrice[AID: Integer]: Double read GetValidDeltaPrice;
  54. property PM_TotalPrice: Double read GetPM_TotalPrice;
  55. end;
  56. implementation
  57. uses
  58. ProjectData, UtilMethods, DB, Variants, PhaseData, DetailGLDm,
  59. BillsMeasureDm, BillsTree, sdIDTree, PhasePayDm, DateUtils;
  60. {$R *.dfm}
  61. { TProjectGLData }
  62. function TProjectGLData.CheckSameCode(ACode: Integer): Boolean;
  63. var
  64. Rec: TsdDataRecord;
  65. begin
  66. Rec := sddProjectGL.FindKey('idxCode', ACode);
  67. Result := Assigned(Rec);
  68. end;
  69. constructor TProjectGLData.Create(AProjectData: TObject);
  70. begin
  71. inherited Create(nil);
  72. FProjectData := AProjectData;
  73. FTempGLs := TList.Create;
  74. end;
  75. destructor TProjectGLData.Destroy;
  76. begin
  77. FTempGLs.Free;
  78. inherited;
  79. end;
  80. procedure TProjectGLData.LoadCurPhaseInfoPrice;
  81. const
  82. sSelectSql = 'Select * From GLPrice Where PhaseID = %d';
  83. var
  84. sSql: string;
  85. vQuery: TADOQuery;
  86. procedure LoadInfoPrice;
  87. var
  88. iRec: Integer;
  89. Rec: TProjectGLRecord;
  90. begin
  91. for iRec := 0 to sddProjectGL.RecordCount - 1 do
  92. begin
  93. Rec := TProjectGLRecord(sddProjectGL.Records[iRec]);
  94. if vQuery.Active and vQuery.Locate('GLID', Rec.ValueByName('ID').AsInteger, []) then
  95. begin
  96. Rec.InfoPrice.AsFloat := vQuery.FieldByName('InfoPrice').AsFloat;
  97. Rec.InfoDate.AsString := vQuery.FieldByName('InfoDate').AsString;
  98. Rec.DeltaPrice.AsFloat := vQuery.FieldByName('DeltaPrice').AsFloat;
  99. Rec.ValidDeltaPrice.AsFloat := vQuery.FieldByName('ValidDeltaPrice').AsFloat;
  100. end
  101. else
  102. begin
  103. Rec.InfoPrice.AsFloat := 0;
  104. Rec.InfoDate.AsString := '';
  105. Rec.DeltaPrice.AsFloat := 0;
  106. Rec.ValidDeltaPrice.AsFloat := 0;
  107. end;
  108. end;
  109. end;
  110. begin
  111. BeforeBatchOperation;
  112. vQuery := TADOQuery.Create(nil);
  113. try
  114. vQuery.Connection := sdpProjectGL.Connection;
  115. sSql := Format(sSelectSql, [TProjectData(FProjectData).PhaseIndex]);
  116. vQuery.SQL.Clear;
  117. vQuery.SQL.Add(sSql);
  118. vQuery.Open;
  119. LoadInfoPrice;
  120. finally
  121. vQuery.Free;
  122. AfterBatchOperation;
  123. end;
  124. end;
  125. procedure TProjectGLData.Open(AConnection: TADOConnection);
  126. begin
  127. sdpProjectGL.Connection := AConnection;
  128. sddProjectGL.Open;
  129. if not Assigned(sddProjectGL.IndexList.FindByName('idxID')) then
  130. sddProjectGL.AddIndex('idxID', 'ID');
  131. if not Assigned(sddProjectGL.IndexList.FindByName('idxCode')) then
  132. sddProjectGL.AddIndex('idxCode', 'Code');
  133. sdvProjectGL.Open;
  134. sdvProjectGL.IndexName := 'idxCode';
  135. LoadCurPhaseInfoPrice;
  136. LoadStagePM_CalcData;
  137. end;
  138. procedure TProjectGLData.Save;
  139. begin
  140. sddProjectGL.Save;
  141. if not TProjectData(FProjectData).PriceMarginReadOnly then
  142. SaveGLPrice;
  143. if not TProjectData(FProjectData).StageDataReadOnly then
  144. SavePM_CurData;
  145. end;
  146. procedure TProjectGLData.SaveGLPrice;
  147. const
  148. sDeleteSql = 'Delete From GLPrice Where PhaseID = %d';
  149. sInsertSql = 'Insert Into GLPrice'+
  150. ' Select ID As GLID, %d As PhaseID, InfoPrice, InfoDate, DeltaPrice, ValidDeltaPrice' +
  151. ' From ProjectGL';
  152. sUpdateSql = 'Update GLPrice As G, ProjectGL As P'+
  153. ' Set G.PM_PreQuantity = P.PM_PreQuantity, G.PM_PreTotalPrice = P.PM_PreTotalPrice'+
  154. ' Where (G.PhaseID = %d) and (G.GLID = P.ID)';
  155. var
  156. iPhaseID: Integer;
  157. sSql: String;
  158. begin
  159. iPhaseID := TProjectData(FProjectData).ProjProperties.PhaseCount;
  160. sSql := Format(sDeleteSql, [iPhaseID]);
  161. ExecuteSql(sSql);
  162. sSql := Format(sInsertSql, [iPhaseID]);
  163. ExecuteSql(sSql);
  164. sSql := Format(sUpdateSql, [iPhaseID]);
  165. ExecuteSql(sSql);
  166. end;
  167. procedure TProjectGLData.sddProjectGLAfterAddRecord(
  168. ARecord: TsdDataRecord);
  169. begin
  170. ARecord.ValueByName('ID').AsInteger := GetsdDataSetNewID(sddProjectGL, 'idxID');
  171. ARecord.ValueByName('CreatePhaseID').AsInteger := TProjectData(FProjectData).ProjProperties.PhaseCount;
  172. end;
  173. procedure TProjectGLData.sddProjectGLBeforeValueChange(AValue: TsdValue;
  174. const NewValue: Variant; var Allow: Boolean);
  175. var
  176. Rec: TProjectGLRecord;
  177. begin
  178. Rec := TProjectGLRecord(AValue.Owner);
  179. if SameText(AValue.FieldName, 'Code') then
  180. begin
  181. if VarIsNull(NewValue) then
  182. DataSetErrorMessage(Allow, '编号不可为空。')
  183. else if CheckSameCode(NewValue) then
  184. DataSetErrorMessage(Allow, '编号不可重复。')
  185. else if CheckApplied(Rec.ID.AsInteger) then
  186. DataSetErrorMessage(Allow, '工料已被应用,不可修改编号。');
  187. end
  188. else if not(SameText(AValue.FieldName, 'ID') or
  189. SameText(AValue.FieldName, 'CreatePhaseID')) then
  190. begin
  191. if (Rec.Code.AsString = '') then
  192. begin
  193. DataSetErrorMessage(Allow, '编号不可为空,请先填写编号,再填写其他信息。');
  194. sddProjectGL.Remove(AValue.Owner);
  195. end;
  196. end;
  197. end;
  198. procedure TProjectGLData.sddProjectGLAfterValueChanged(AValue: TsdValue);
  199. begin
  200. if SameText(AValue.FieldName, 'BasePrice') or
  201. SameText(AValue.FieldName, 'RiskRange') or
  202. SameText(AValue.FieldName, 'InfoPrice') then
  203. begin
  204. CalculateDeltaPrice(TProjectGLRecord(AValue.Owner));
  205. CalculatePM_Quantity(TProjectGLRecord(AValue.Owner));
  206. CalculatePM_TotalPrice(TProjectGLRecord(AValue.Owner));
  207. CalculateRelaBills(TProjectGLRecord(AValue.Owner));
  208. end;
  209. end;
  210. procedure TProjectGLData.CalculateDeltaPrice(ARec: TProjectGLRecord);
  211. var
  212. C0, Ci, r, DeltaC, RiskC, ValidDeltaC: Double;
  213. begin
  214. C0 := ARec.BasePrice.AsFloat;
  215. Ci := ARec.InfoPrice.AsFloat;
  216. r := ARec.RiskRange.AsFloat;
  217. DeltaC := Ci - C0;
  218. RiskC := C0 * r / 100;
  219. if (DeltaC > 0) and (DeltaC - RiskC > 0) then
  220. ValidDeltaC := DeltaC - RiskC
  221. else if (DeltaC < 0) and (DeltaC + RiskC < 0) then
  222. ValidDeltaC := DeltaC + RiskC
  223. else
  224. ValidDeltaC := 0;
  225. if DeltaC <> ARec.DeltaPrice.AsFloat then
  226. ARec.DeltaPrice.AsFloat := PriceRoundTo(DeltaC);
  227. if ValidDeltaC <> ARec.ValidDeltaPrice.AsFloat then
  228. ARec.ValidDeltaPrice.AsFloat := PriceRoundTo(ValidDeltaC);
  229. end;
  230. procedure TProjectGLData.sdvProjectGLGetText(var Text: String;
  231. ARecord: TsdDataRecord; AValue: TsdValue; AColumn: TsdViewColumn;
  232. DisplayText: Boolean);
  233. procedure GetDisplayText;
  234. begin
  235. if ((Pos('Price', AColumn.FieldName) > 0) or
  236. (Pos('Quantity', AColumn.FieldName) > 0) or
  237. SameText('RiskRange', AColumn.FieldName)) then
  238. begin
  239. if AValue.AsFloat = 0 then
  240. Text := '';
  241. end;
  242. end;
  243. begin
  244. if DisplayText then
  245. GetDisplayText;
  246. end;
  247. procedure TProjectGLData.CalculateAll;
  248. begin
  249. CalculatePrice;
  250. CalculatePriceMargin;
  251. end;
  252. procedure TProjectGLData.ExecuteSql(const ASql: string);
  253. var
  254. vQuery: TADOQuery;
  255. begin
  256. vQuery := TADOQuery.Create(nil);
  257. try
  258. vQuery.Connection := sdpProjectGL.Connection;
  259. vQuery.SQL.Add(ASql);
  260. vQuery.ExecSQL;
  261. finally
  262. vQuery.Free;
  263. end;
  264. end;
  265. function TProjectGLData.GetValidDeltaPrice(AID: Integer): Double;
  266. var
  267. Rec: TProjectGLRecord;
  268. begin
  269. Rec := TProjectGLRecord(sddProjectGL.FindKey('idxID', AID));
  270. if Assigned(Rec) then
  271. Result := Rec.ValidDeltaPrice.AsFloat
  272. else
  273. Result := 0;
  274. end;
  275. procedure TProjectGLData.CalculatePrice;
  276. var
  277. iRec: Integer;
  278. begin
  279. if TProjectData(FProjectData).PriceMarginReadOnly then Exit;
  280. for iRec := 0 to sddProjectGL.RecordCount - 1 do
  281. CalculateDeltaPrice(TProjectGLRecord(sddProjectGL.Records[iRec]));
  282. end;
  283. procedure TProjectGLData.CalculatePriceMargin;
  284. var
  285. iRec: Integer;
  286. Rec: TProjectGLRecord;
  287. begin
  288. if TProjectData(FProjectData).PhaseData.StageDataReadOnly then Exit;
  289. for iRec := 0 to sddProjectGL.RecordCount - 1 do
  290. begin
  291. Rec := TProjectGLRecord(sddProjectGL.Records[iRec]);
  292. CalculatePM_Quantity(Rec);
  293. CalculatePM_TotalPrice(Rec);
  294. end;
  295. end;
  296. procedure TProjectGLData.CalculatePM_Quantity(ARec: TProjectGLRecord);
  297. var
  298. vGLs: TList;
  299. fQuantity: Double;
  300. i: Integer;
  301. GLRec: TsdDataRecord;
  302. BillsNode: TBillsIDTreeNode;
  303. begin
  304. vGLs := TList.Create;
  305. try
  306. fQuantity := 0;
  307. with TProjectData(FProjectData).DetailGLData do
  308. LoadProjectGL_DetailGLs(ARec.ValueByName('ID').AsInteger, vGLs);
  309. for i := 0 to vGLs.Count - 1 do
  310. begin
  311. GLRec := TsdDataRecord(vGLs.Items[i]);
  312. with TProjectData(FProjectData).BillsMeasureData do
  313. BillsNode := TBillsIDTreeNode(BillsMeasureTree.FindNode(GLRec.ValueByName('BillsID').AsInteger));
  314. if Assigned(BillsNode.StageRec) then
  315. fQuantity := fQuantity + BillsNode.StageRec.GatherQuantity.AsFloat * GLRec.ValueByName('Quantity').AsFloat;
  316. end;
  317. if fQuantity <> ARec.PM_Quantity.AsFloat then
  318. ARec.PM_Quantity.AsFloat := fQuantity;
  319. finally
  320. vGLs.Free;
  321. end;
  322. end;
  323. procedure TProjectGLData.CalculatePM_TotalPrice(ARec: TProjectGLRecord);
  324. var
  325. fTotalPrice: Double;
  326. begin
  327. fTotalPrice := ARec.ValidDeltaPrice.AsFloat * ARec.PM_Quantity.AsFloat;
  328. if fTotalPrice <> ARec.PM_TotalPrice.AsFloat then
  329. ARec.PM_TotalPrice.AsFloat := fTotalPrice;
  330. end;
  331. procedure TProjectGLData.sddProjectGLGetRecordClass(
  332. var ARecordClass: TsdRecordClass);
  333. begin
  334. ARecordClass := TProjectGLRecord;
  335. end;
  336. function TProjectGLData.GetPM_TotalPrice: Double;
  337. var
  338. i: Integer;
  339. Rec: TProjectGLRecord;
  340. begin
  341. Result := 0;
  342. for i := 0 to sddProjectGL.RecordCount - 1 do
  343. begin
  344. Rec := TProjectGLRecord(sddProjectGL.Records[i]);
  345. Result := Result + Rec.PM_TotalPrice.AsFloat;
  346. end;
  347. end;
  348. procedure TProjectGLData.SavePM_CurData;
  349. const
  350. sUpdateSql = 'Update GLPrice As G, ProjectGL As P'+
  351. ' Set G.PM_Quantity%d = P.PM_Quantity, G.PM_TotalPrice%d = P.PM_TotalPrice,'+
  352. ' G.PM_Quantity_F = P.PM_Quantity, G.PM_TotalPrice_F = P.PM_TotalPrice'+
  353. ' Where (G.PhaseID = %d) and (G.GLID = P.ID)';
  354. var
  355. iStageIndex: Integer;
  356. iPhaseCount: Integer;
  357. sSql: string;
  358. begin
  359. iStageIndex := TProjectData(FProjectData).PhaseData.StageIndex;
  360. iPhaseCount := TProjectData(FProjectData).ProjProperties.PhaseCount;
  361. sSql := Format(sUpdateSql, [iStageIndex, iStageIndex, iPhaseCount]);
  362. ExecuteSql(sSql);
  363. end;
  364. procedure TProjectGLData.CalculateGL_PM(AGLID: Integer);
  365. var
  366. Rec: TProjectGLRecord;
  367. begin
  368. Rec := TProjectGLRecord(sddProjectGL.FindKey('idxID', AGLID));
  369. if not Assigned(Rec) then Exit;
  370. CalculatePM_Quantity(Rec);
  371. CalculatePM_TotalPrice(Rec);
  372. end;
  373. procedure TProjectGLData.CalculateGLs_PM(ADetailGLs: TList);
  374. var
  375. i: Integer;
  376. DetailGLRec: TDetailGLRecord;
  377. begin
  378. for i := 0 to ADetailGLs.Count - 1 do
  379. begin
  380. DetailGLRec := TDetailGLRecord(ADetailGLs.Items[i]);
  381. CalculateGL_PM(DetailGLRec.GLID.AsInteger);
  382. end;
  383. end;
  384. procedure TProjectGLData.CalculateRelaBills(ARec: TProjectGLRecord);
  385. var
  386. iGL: Integer;
  387. DetailGLRec: TDetailGLRecord;
  388. begin
  389. LoadDetailGLs(ARec.ID.AsInteger);
  390. for iGL := 0 to FTempGLs.Count - 1 do
  391. begin
  392. DetailGLRec := TDetailGLRecord(FTempGLs.Items[iGL]);
  393. with TProjectData(FProjectData).PhaseData do
  394. StageData.CalculatePriceMargin(DetailGLRec.BillsID.AsInteger);
  395. end;
  396. with TProjectData(FProjectData).PhaseData do
  397. StageData.CalculatePriceMarginNode;
  398. end;
  399. procedure TProjectGLData.LoadDetailGLs(AGLID: Integer);
  400. begin
  401. FTempGLs.Clear;
  402. with TProjectData(FProjectData).DetailGLData do
  403. LoadProjectGL_DetailGLs(AGLID, FTempGLs);
  404. end;
  405. function TProjectGLData.GetActive: Boolean;
  406. begin
  407. Result := sddProjectGL.Active;
  408. end;
  409. procedure TProjectGLData.sdvProjectGLSetText(var Text: String;
  410. ARecord: TsdDataRecord; AValue: TsdValue; AColumn: TsdViewColumn;
  411. var Allow: Boolean);
  412. var
  413. iPhaseID: Integer;
  414. begin
  415. if SameText(AColumn.FieldName, 'Code') or
  416. SameText(AColumn.FieldName, 'Name') or
  417. SameText(AColumn.FieldName, 'Units') or
  418. SameText(AColumn.FieldName, 'Specs') or
  419. SameText(AColumn.FieldName, 'BasePrice') or
  420. SameText(AColumn.FieldName, 'RiskRange') then
  421. begin
  422. iPhaseID := TProjectGLRecord(ARecord).LockedPhaseID.AsInteger;
  423. if iPhaseID > 0 then
  424. DataSetErrorMessage(Allow, Format('该工料在第%d期已进行调差计算,不可修改基础数据。', [iPhaseID]));
  425. end;
  426. end;
  427. procedure TProjectGLData.LoadStagePM_CalcData;
  428. const
  429. sSelectSql = 'Select GLID, PhaseID, PM_PreQuantity, PM_PreTotalPrice,'+
  430. ' PM_Quantity%d As PM_Quantity, PM_TotalPrice%d As PM_TotalPrice'+
  431. ' From GLPrice Where PhaseID = %d';
  432. var
  433. sSql: string;
  434. vQuery: TADOQuery;
  435. procedure LoadPM_Calc;
  436. var
  437. iRec: Integer;
  438. Rec: TProjectGLRecord;
  439. begin
  440. for iRec := 0 to sddProjectGL.RecordCount - 1 do
  441. begin
  442. Rec := TProjectGLRecord(sddProjectGL.Records[iRec]);
  443. if vQuery.Active and vQuery.Locate('GLID', Rec.ValueByName('ID').AsInteger, []) then
  444. begin
  445. Rec.PM_Quantity.AsFloat := vQuery.FieldByName('PM_Quantity').AsFloat;
  446. Rec.PM_TotalPrice.AsFloat := vQuery.FieldByName('PM_TotalPrice').AsFloat;
  447. end
  448. else
  449. begin
  450. Rec.PM_Quantity.AsFloat := 0;
  451. Rec.PM_TotalPrice.AsFloat := 0;
  452. end;
  453. end;
  454. end;
  455. begin
  456. BeforeBatchOperation;
  457. vQuery := TADOQuery.Create(nil);
  458. try
  459. vQuery.Connection := sdpProjectGL.Connection;
  460. with TProjectData(FProjectData) do
  461. sSql := Format(sSelectSql, [StageIndex, StageIndex, PhaseIndex]);
  462. vQuery.SQL.Clear;
  463. vQuery.SQL.Add(sSql);
  464. vQuery.Open;
  465. LoadPM_Calc;
  466. finally
  467. vQuery.Free;
  468. AfterBatchOperation;
  469. end;
  470. end;
  471. procedure TProjectGLData.AfterBatchOperation;
  472. begin
  473. sddProjectGL.EndUpdate;
  474. sddProjectGL.EnableControls;
  475. sddProjectGL.BeforeValueChange := sddProjectGLBeforeValueChange;
  476. sddProjectGL.AfterValueChanged := sddProjectGLAfterValueChanged;
  477. end;
  478. procedure TProjectGLData.BeforeBatchOperation;
  479. begin
  480. sddProjectGL.AfterValueChanged := nil;
  481. sddProjectGL.BeforeValueChange := nil;
  482. sddProjectGL.DisableControls;
  483. sddProjectGL.BeginUpdate;
  484. end;
  485. function TProjectGLData.CheckApplied(AGLID: Integer): Boolean;
  486. begin
  487. LoadDetailGLs(AGLID);
  488. Result := FTempGLs.Count > 0;
  489. end;
  490. procedure TProjectGLData.sddProjectGLBeforeDeleteRecord(
  491. ARecord: TsdDataRecord; var Allow: Boolean);
  492. begin
  493. Allow := not CheckApplied(ARecord.ValueByName('ID').AsInteger);
  494. if not Allow then
  495. ErrorMessage('工料已被应用,不可删除。');
  496. end;
  497. end.