BillsDm.pas 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. unit BillsDm;
  2. interface
  3. uses
  4. StandardBillsFme,
  5. ZhAPI, StandardLib, StageDm, BillsTree, mDataRecord,
  6. SysUtils, Classes, sdDB, sdProvider, ADODB, sdIDTree, Math;
  7. const
  8. DealIndex = 0;
  9. AddDealIndex = 1;
  10. AddQcIndex = 2;
  11. AddPcIndex = 3;
  12. AddGatherIndex = 4;
  13. type
  14. TRecChangeEvent = procedure (ARec: TsdDataRecord) of object;
  15. TBillsData = class(TDataModule)
  16. sdpBills: TsdADOProvider;
  17. sddBills: TsdDataSet;
  18. procedure sddBillsAfterAddRecord(ARecord: TsdDataRecord);
  19. procedure sddBillsBeforeDeleteRecord(ARecord: TsdDataRecord;
  20. var Allow: Boolean);
  21. procedure sddBillsBeforeValueChange(AValue: TsdValue;
  22. const NewValue: Variant; var Allow: Boolean);
  23. procedure sddBillsGetRecordClass(var ARecordClass: TsdRecordClass);
  24. private
  25. FProjectData: TObject;
  26. FCurPhaseIndex: Integer;
  27. FBeforeChangeTotalPrice: Double;
  28. FBeforeChangeParentID: Integer;
  29. //procedure RecursiveCalculate(ABillsID: Integer);
  30. function GetStageData: TStageData;
  31. function GetBuildLoadInterest(AIndex: Integer): Double;
  32. function GetFirstPart(AIndex: Integer): Double;
  33. function GetOtherFee(AIndex: Integer): Double;
  34. function GetOtherProjectFee(AIndex: Integer): Double;
  35. function GetRecyclingFee(AIndex: Integer): Double;
  36. function GetReservedFee(AIndex: Integer): Double;
  37. function GetSecondPart(AIndex: Integer): Double;
  38. function GetStageSettlement(AIndex: Integer): Double;
  39. function GetThirdPart(AIndex: Integer): Double;
  40. public
  41. constructor Create(AProjectData: TObject);
  42. destructor Destroy; override;
  43. procedure Open(AConnection: TADOConnection);
  44. procedure Close;
  45. procedure Save;
  46. procedure InitBills;
  47. // 计算 -- 均采用增量汇总方式计算父项
  48. {procedure Calculate(ABillsID: Integer);
  49. procedure CalculateDeal(ABillsID: Integer); // 合同计量
  50. procedure CalculateQuantityChange(ABillsID: Integer); // 数量变更计量
  51. procedure CalculatePriceChange(ABillsID: Integer); // 单价变更计量}
  52. // 上报审核批复过程 -- 锁定数据
  53. procedure LockedBaseData;
  54. // 解锁数据
  55. procedure UnLockedBaseData;
  56. procedure DisableEvents;
  57. procedure EnableEvents;
  58. function GetMaxBillsID: Integer;
  59. function GetGatherTotalPrice(ABillsID, AIndex: Integer): Double;
  60. property ProjectData: TObject read FProjectData;
  61. property StageData: TStageData read GetStageData;
  62. {累计完成 可查数据}
  63. // AIndex表示不同类型,取值如下:
  64. // 0: 0号台账合同 1: 累计合同计量 2: 累计数量变更计量 3: 累计单价变更计量 4: 累计完成计量
  65. // 第一部分
  66. property FirstPart[AIndex: Integer]: Double read GetFirstPart;
  67. // 第二部分
  68. property SecondPart[AIndex: Integer]: Double read GetSecondPart;
  69. // 第三部分
  70. property ThirdPart[AIndex: Integer]: Double read GetThirdPart;
  71. // 预留费用
  72. property ReservedFee[AIndex: Integer]: Double read GetReservedFee;
  73. // 其他费用项目
  74. property OtherFee[AIndex: Integer]: Double read GetOtherFee;
  75. // 建设期贷款利息
  76. property BuildLoadInterest[AIndex: Integer]: Double read GetBuildLoadInterest;
  77. // 回收金额
  78. property RecyclingFee[AIndex: Integer]: Double read GetRecyclingFee;
  79. // 公路工程以外的工程费用
  80. property OtherProjectFee[AIndex: Integer]: Double read GetOtherProjectFee;
  81. // 结算价
  82. property Settlement[AIndex: Integer]: Double read GetStageSettlement;
  83. end;
  84. implementation
  85. uses
  86. Variants, UtilMethods, Globals, ProjectData, ExcelImport, BillsCommand,
  87. PhaseData, BillsCompileDm, ConditionalDefines, FormulaCalc;
  88. {$R *.dfm}
  89. { TBillsData }
  90. procedure TBillsData.Close;
  91. begin
  92. sddBills.Close;
  93. end;
  94. constructor TBillsData.Create(AProjectData: TObject);
  95. begin
  96. inherited Create(nil);
  97. FProjectData := AProjectData;
  98. end;
  99. destructor TBillsData.Destroy;
  100. begin
  101. inherited;
  102. end;
  103. procedure TBillsData.Open(AConnection: TADOConnection);
  104. begin
  105. sdpBills.Connection := AConnection;
  106. sddBills.Open;
  107. if not Assigned(sddBills.IndexList.FindByName('idxID')) then
  108. sddBills.AddIndex('idxID', 'ID');
  109. if not Assigned(sddBills.IndexList.FindByName('idxSerialNo')) then
  110. sddBills.AddIndex('idxSerialNo', 'SerialNo');
  111. sddBills.FieldByName('OrgQuantity').ValidChars := sddBills.FieldByName('Quantity').ValidChars + ArithmeticCharSet;
  112. sddBills.FieldByName('OrgTotalPrice').ValidChars := sddBills.FieldByName('OrgQuantity').ValidChars;
  113. sddBills.FieldByName('MisQuantity').ValidChars := sddBills.FieldByName('OrgQuantity').ValidChars;
  114. sddBills.FieldByName('MisTotalPrice').ValidChars := sddBills.FieldByName('OrgQuantity').ValidChars;
  115. sddBills.FieldByName('OthQuantity').ValidChars := sddBills.FieldByName('OrgQuantity').ValidChars;
  116. sddBills.FieldByName('OthTotalPrice').ValidChars := sddBills.FieldByName('OrgQuantity').ValidChars;
  117. end;
  118. procedure TBillsData.Save;
  119. procedure ResolveCode(ARec: TBillsRecord);
  120. var
  121. sgs: TStrings;
  122. i: Integer;
  123. sXiangCode, sMuCode, sJieCode, sXiMuCode: string;
  124. begin
  125. sgs := TStringList.Create;
  126. try
  127. sgs.Delimiter := '-';
  128. sgs.DelimitedText := ARec.Code.AsString;
  129. case sgs.Count of
  130. 1: sXiangCode := '';
  131. 2: sXiangCode := ChinessNum(StrToIntDef(sgs[1], 0));
  132. 3: sMuCode := sgs[2];
  133. 4: sJieCode := sgs[3];
  134. else
  135. begin
  136. for i := 4 to sgs.Count - 1 do
  137. if sXiMuCode = '' then
  138. sXiMuCode := sgs[i]
  139. else
  140. sXiMuCode := sXiMuCode + '-' + sgs[i];
  141. end;
  142. end;
  143. finally
  144. ARec.SetStrValue(ARec.XiangCode, sXiangCode);
  145. ARec.SetStrValue(ARec.MuCode, sMuCode);
  146. ARec.SetStrValue(ARec.JieCode, sJieCode);
  147. ARec.SetStrValue(ARec.XimuCode, sXiMuCode);
  148. sgs.Free;
  149. end;
  150. end;
  151. function GetB_CodeChapter(const AB_Code: string): Integer;
  152. var
  153. iValue, iError: Integer;
  154. begin
  155. Result := -1;
  156. Val(AB_Code, iValue, iError);
  157. if iValue > 0 then
  158. Result := iValue div 100;
  159. end;
  160. procedure SaveReportsRela;
  161. var
  162. iIndex: Integer;
  163. stnNode: TBillsIDTreeNode;
  164. iLeafXmjParentID, iChapterParentID: Integer;
  165. sIndexCode: string;
  166. begin
  167. sddBills.BeginUpdate;
  168. try
  169. with TProjectData(FProjectData).BillsCompileData do
  170. for iIndex := 0 to BillsCompileTree.Count - 1 do
  171. begin
  172. stnNode := TBillsIDTreeNode(BillsCompileTree.Items[iIndex]);
  173. // 分项清单排序
  174. if (stnNode.Rec.SerialNo.AsString = '') or
  175. (stnNode.MajorIndex <> stnNode.Rec.SerialNo.AsInteger) then
  176. stnNode.Rec.SerialNo.AsInteger := stnNode.MajorIndex;
  177. // 叶子节点
  178. stnNode.Rec.SetBoolValue(stnNode.Rec.IsLeaf, not stnNode.HasChildren);
  179. // 最底项目节父节点ID
  180. if (stnNode.Rec.B_Code.AsString <> '') then
  181. iLeafXmjParentID := GetLeafXmjParentID(stnNode.ID)
  182. else
  183. iLeafXmjParentID := -1;
  184. stnNode.Rec.SetIntValue(stnNode.Rec.LeafXmjParentID, iLeafXmjParentID);
  185. stnNode.Rec.SetIntValue(stnNode.Rec.ChapterParentID, stnNode.ChapterParentID);
  186. // 分解项目节编号为项、目、节、细目
  187. if stnNode.Rec.Code.AsString <> '' then
  188. ResolveCode(stnNode.Rec);
  189. // 工程量清单排序Code
  190. if (stnNode.Rec.B_Code.AsString <> '') then
  191. begin
  192. sIndexCode := B_CodeToIndexCode(stnNode.Rec.B_Code.AsString);
  193. stnNode.Rec.SetStrValue(stnNode.Rec.IndexCode, sIndexCode);
  194. end;
  195. stnNode.Rec.SetIntValue(stnNode.Rec.NodeLevel, stnNode.Level);
  196. // 工程量清单所属章级
  197. stnNode.Rec.SetIntValue(stnNode.Rec.B_CodeChapter, GetB_CodeChapter(stnNode.Rec.B_Code.AsString));
  198. end;
  199. finally
  200. sddBills.EndUpdate;
  201. end;
  202. end;
  203. begin
  204. if TProjectData(FProjectData).BillsCompileData.Active then
  205. SaveReportsRela; // 保存 SerialNo, IsLeaf, LeafXmjParentID, 分解Code
  206. sddBills.Save;
  207. end;
  208. {procedure TBillsData.Calculate(ABillsID: Integer);
  209. var
  210. stnNode: TsdIDTreeNode;
  211. iChild: Integer;
  212. begin
  213. stnNode := FBillsTree.FindNode(ABillsID);
  214. if stnNode.HasChildren then
  215. begin
  216. for iChild := 0 to stnNode.ChildCount - 1 do
  217. Calculate(stnNode.ChildNodes[iChild].ID);
  218. end
  219. else
  220. begin
  221. CalculateOrg(ABillsID);
  222. CalculateDeal(ABillsID);
  223. CalculateQuantityChange(ABillsID);
  224. CalculatePriceChange(ABillsID);
  225. end;
  226. end;
  227. procedure TBillsData.CalculateDeal(ABillsID: Integer);
  228. var
  229. iIndex: Integer;
  230. fQuantity, fTotalPrice: Double;
  231. Rec: TsdDataRecord;
  232. begin
  233. fQuantity := 0;
  234. fTotalPrice := 0;
  235. with TProjectData(FProjectData) do
  236. for iIndex := 0 to PhaseCount - 1 do
  237. begin
  238. Rec := PhaseData[iIndex].PhaseRecord(ABillsID);
  239. if not Assigned(Rec) then Continue;
  240. fQuantity := fQuantity + Rec.ValueByName('DealQuantity').AsFloat;
  241. fTotalPrice := fTotalPrice + Rec.ValueByName('DealTotalPrice').AsFloat;
  242. end;
  243. with FBillsTree.FindNode(ABillsID).Rec do
  244. UpdateRecordDeal(ABillsID, fQuantity - ValueByName('AddDealQuantity').AsFloat,
  245. fTotalPrice - ValueByName('AddDealTotalPrice').AsFloat);
  246. end;
  247. procedure TBillsData.CalculatePriceChange(ABillsID: Integer);
  248. var
  249. iIndex: Integer;
  250. fQuantity, fTotalPrice: Double;
  251. Rec: TsdDataRecord;
  252. begin
  253. fQuantity := 0;
  254. fTotalPrice := 0;
  255. with TProjectData(FProjectData) do
  256. for iIndex := 0 to PhaseCount - 1 do
  257. begin
  258. Rec := PhaseData[iIndex].PhaseRecord(ABillsID);
  259. if not Assigned(Rec) then Continue;
  260. fQuantity := fQuantity + Rec.ValueByName('PcQuantity').AsFloat;
  261. fTotalPrice := fTotalPrice + Rec.ValueByName('PcTotalPrice').AsFloat;
  262. end;
  263. with FBillsTree.FindNode(ABillsID).Rec do
  264. UpdateRecordPc(ABillsID, fQuantity - ValueByName('AddPcQuantity').AsFloat,
  265. fTotalPrice - ValueByName('AddPcTotalPrice').AsFloat);
  266. end;
  267. procedure TBillsData.CalculateQuantityChange(ABillsID: Integer);
  268. var
  269. iIndex: Integer;
  270. fQuantity, fTotalPrice: Double;
  271. Rec: TsdDataRecord;
  272. begin
  273. fQuantity := 0;
  274. fTotalPrice := 0;
  275. with TProjectData(FProjectData) do
  276. for iIndex := 0 to PhaseCount - 1 do
  277. begin
  278. Rec := PhaseData[iIndex].PhaseRecord(ABillsID);
  279. if not Assigned(Rec) then Continue;
  280. fQuantity := fQuantity + Rec.ValueByName('QcQuantity').AsFloat;
  281. fTotalPrice := fTotalPrice + Rec.ValueByName('QcTotalPrice').AsFloat;
  282. end;
  283. with FBillsTree.FindNode(ABillsID).Rec do
  284. UpdateRecordQc(ABillsID, fQuantity - ValueByName('AddQcQuantity').AsFloat,
  285. fTotalPrice - ValueByName('AddQcTotalPrice').AsFloat);
  286. end; }
  287. {
  288. procedure TBillsData.RecursiveCalculate(ABillsID: Integer);
  289. procedure GatherChildValue(ANode: TsdIDTreeNode);
  290. var
  291. CacheRecord: TCacheRecord;
  292. iChild: Integer;
  293. begin
  294. CacheRecord := TCacheRecord.Create;
  295. try
  296. for iChild := 0 to ANode.ChildCount - 1 do
  297. with ANode.ChildNodes[iChild].Rec do
  298. begin
  299. CacheRecord.FTotalPrice := CacheRecord.FTotalPrice + ValueByName('TotalPrice').AsFloat;
  300. CacheRecord.FDealQuantity := CacheRecord.FDealQuantity + ValueByName('AddDealQuantity').AsFloat;
  301. CacheRecord.FDealTotalPrice := CacheRecord.FDealTotalPrice + ValueByName('AddDealTotalPrice').AsFloat;
  302. CacheRecord.FQcQuantity := CacheRecord.FQcQuantity + ValueByName('AddQcQuantity').AsFloat;
  303. CacheRecord.FQcTotalPrice := CacheRecord.FQcTotalPrice + ValueByName('AddQcTotalPrice').AsFloat;
  304. CacheRecord.FPcQuantity := CacheRecord.FPcQuantity + ValueByName('AddPcQuantity').AsFloat;
  305. CacheRecord.FPcTotalPrice := CacheRecord.FPcTotalPrice + ValueByName('AddPcTotalPrice').AsFloat;
  306. end;
  307. finally
  308. CacheRecord.SetBillsRecord(ANode);
  309. CacheRecord.Free;
  310. end;
  311. end;
  312. procedure CalculateLeafNode(ANode: TsdIDTreeNode; ACacheRecord: TCacheRecord);
  313. begin
  314. with ANode.Rec do
  315. begin
  316. if ValueByName('QtyFlag').AsInteger = 1 then
  317. ValueByName('Quantity').AsFloat := EvaluateExprs(ValueByName('QtyFormula').AsString);
  318. if ValueByName('QtyFlag').AsInteger < 2 then
  319. ACacheRecord.FTotalPrice := ValueByName('Quantity').AsFloat * ValueByName('Price').AsFloat
  320. else
  321. begin
  322. FFormulaCalc.SetRecordText(ValueByName('QtyFormula').AsString);
  323. ACacheRecord.FTotalPrice := FFormulaCalc.Value;
  324. end;
  325. end;
  326. end;
  327. procedure GatherPhaseValue(ANode: TsdIDTreeNode);
  328. var
  329. CacheRecord: TCacheRecord;
  330. iIndex: Integer;
  331. Rec: TsdDataRecord;
  332. begin
  333. CacheRecord := TCacheRecord.Create;
  334. try
  335. CalculateLeafNode(ANode, CacheRecord);
  336. {with TProjectData(FProjectData) do
  337. for iIndex := 0 to PhaseCount - 1 do
  338. begin
  339. PhaseData[iIndex].ReCalculate(ANode.ID);
  340. Rec := PhaseData[iIndex].PhaseRecord(ANode.ID);
  341. if not Assigned(Rec) then Continue;
  342. CacheRecord.FDealQuantity := CacheRecord.FDealQuantity + Rec.ValueByName('DealQuantity').AsFloat;
  343. CacheRecord.FDealTotalPrice := CacheRecord.FDealTotalPrice + Rec.ValueByName('DealTotalPrice').AsFloat;
  344. CacheRecord.FQcQuantity := CacheRecord.FQcQuantity + Rec.ValueByName('QcQuantity').AsFloat;
  345. CacheRecord.FQcTotalPrice := CacheRecord.FQcTotalPrice + Rec.ValueByName('QcTotalPrice').AsFloat;
  346. CacheRecord.FPcQuantity := CacheRecord.FPcQuantity + Rec.ValueByName('PcQuantity').AsFloat;
  347. CacheRecord.FPcTotalPrice := CacheRecord.FPcTotalPrice + Rec.ValueByName('PcTotalPrice').AsFloat;
  348. end;}
  349. { finally
  350. CacheRecord.SetBillsRecord(ANode);
  351. CacheRecord.Free;
  352. end;
  353. end;
  354. procedure CalculateCurNode(ANode: TsdIDTreeNode);
  355. begin
  356. if ANode.HasChildren then
  357. GatherChildValue(ANode)
  358. else
  359. GatherPhaseValue(ANode);
  360. end;
  361. procedure CalculateAllChildren(ANode: TsdIDTreeNode);
  362. var
  363. iChild: Integer;
  364. begin
  365. if ANode.HasChildren then
  366. for iChild := 0 to ANode.ChildCount - 1 do
  367. RecursiveCalculate(ANode.ChildNodes[iChild].ID);
  368. end;
  369. var
  370. stnNode: TsdIDTreeNode;
  371. begin
  372. stnNode := FBillsTree.FindNode(ABillsID);
  373. CalculateAllChildren(stnNode);
  374. CalculateCurNode(stnNode);
  375. end; }
  376. procedure TBillsData.InitBills;
  377. var
  378. Import: TBillsExcelImport;
  379. begin
  380. Import := TBillsExcelImport.Create(TProjectData(ProjectData));
  381. try
  382. Import.ImportFile(GetTemplateBillsFileName);
  383. finally
  384. Import.Free;
  385. end;
  386. end;
  387. function TBillsData.GetStageData: TStageData;
  388. begin
  389. Result := TProjectData(FProjectData).PhaseData.StageData;
  390. end;
  391. procedure TBillsData.LockedBaseData;
  392. var
  393. iIndex: Integer;
  394. Rec: TBillsRecord;
  395. begin
  396. sddBills.BeginUpdate;
  397. for iIndex := 0 to sddBills.RecordCount - 1 do
  398. begin
  399. Rec := TBillsRecord(sddBills.Records[iIndex]);
  400. Rec.SetBoolValue(Rec.LockedLevel, True);
  401. Rec.SetBoolValue(Rec.LockedInfo, True);
  402. Rec.SetBoolValue(Rec.LockedNewPrice, Rec.NewPrice.AsFloat <> 0);
  403. end;
  404. sddBills.EndUpdate;
  405. end;
  406. procedure TBillsData.sddBillsAfterAddRecord(ARecord: TsdDataRecord);
  407. begin
  408. ARecord.ValueByName('CreatePhaseID').AsInteger := TProjectData(FProjectData).PhaseIndex;
  409. end;
  410. function TBillsData.GetBuildLoadInterest(AIndex: Integer): Double;
  411. begin
  412. Result := GetGatherTotalPrice(34, AIndex);
  413. end;
  414. function TBillsData.GetFirstPart(AIndex: Integer): Double;
  415. begin
  416. Result := GetGatherTotalPrice(1, AIndex);
  417. end;
  418. function TBillsData.GetOtherFee(AIndex: Integer): Double;
  419. begin
  420. Result := GetGatherTotalPrice(15, AIndex);
  421. end;
  422. function TBillsData.GetOtherProjectFee(AIndex: Integer): Double;
  423. begin
  424. Result := GetGatherTotalPrice(9, AIndex);
  425. end;
  426. function TBillsData.GetRecyclingFee(AIndex: Integer): Double;
  427. begin
  428. Result := GetGatherTotalPrice(16, AIndex);
  429. end;
  430. function TBillsData.GetReservedFee(AIndex: Integer): Double;
  431. begin
  432. Result := GetGatherTotalPrice(7, AIndex);
  433. end;
  434. function TBillsData.GetSecondPart(AIndex: Integer): Double;
  435. begin
  436. Result := GetGatherTotalPrice(2, AIndex);
  437. end;
  438. function TBillsData.GetStageSettlement(AIndex: Integer): Double;
  439. begin
  440. // 全国
  441. // 第一部分+第二部分+第三部分+预备费+新增加费用项目(其他费用_广东)-回收金额
  442. Result := FirstPart[AIndex] + SecondPart[AIndex] + ThirdPart[AIndex]
  443. + ReservedFee[AIndex] + OtherFee[AIndex] - RecyclingFee[AIndex];
  444. // 广东
  445. // 全国的基础上+建设期贷款利息+公路功能以外的项目
  446. if _IsGuangDong then
  447. Result := Result + BuildLoadInterest[AIndex] + OtherProjectFee[AIndex];
  448. end;
  449. function TBillsData.GetThirdPart(AIndex: Integer): Double;
  450. begin
  451. Result := GetGatherTotalPrice(3, AIndex);
  452. end;
  453. function TBillsData.GetGatherTotalPrice(ABillsID, AIndex: Integer): Double;
  454. var
  455. Rec: TsdDataRecord;
  456. begin
  457. Result := 0;
  458. Rec := sddBills.FindKey('idxID', ABillsID);
  459. if Assigned(Rec) then
  460. begin
  461. case AIndex of
  462. 0: Result := Rec.ValueByName('TotalPrice').AsFloat;
  463. 1: Result := Rec.ValueByName('AddDealTotalPrice').AsFloat;
  464. 2: Result := Rec.ValueByName('AddQcTotalPrice').AsFloat;
  465. 3: Result := Rec.ValueByName('AddPcTotalPrice').AsFloat;
  466. 4: Result := Rec.ValueByName('AddGatherTotalPrice').AsFloat;
  467. end;
  468. end;
  469. end;
  470. procedure TBillsData.DisableEvents;
  471. begin
  472. sddBills.BeforeValueChange := nil;
  473. end;
  474. procedure TBillsData.EnableEvents;
  475. begin
  476. sddBills.BeforeValueChange := sddBillsBeforeValueChange;
  477. end;
  478. procedure TBillsData.UnLockedBaseData;
  479. var
  480. iIndex: Integer;
  481. begin
  482. for iIndex := 0 to sddBills.RecordCount - 1 do
  483. sddBills.Records[iIndex].ValueByName('LockedInfo').AsBoolean := False;
  484. end;
  485. procedure TBillsData.sddBillsBeforeDeleteRecord(ARecord: TsdDataRecord;
  486. var Allow: Boolean);
  487. begin
  488. with TProjectData(FProjectData) do
  489. begin
  490. if ProjProperties.PhaseCount > 0 then
  491. PhaseData.StageData.DeletePhaseRecord(ARecord.ValueByName('ID').AsInteger);
  492. end;
  493. end;
  494. procedure TBillsData.sddBillsBeforeValueChange(AValue: TsdValue;
  495. const NewValue: Variant; var Allow: Boolean);
  496. begin
  497. if (Pos('DgnQuantity', AValue.FieldName) > 0) and
  498. not (VarIsNull(NewValue) or (NewValue = 0)) then
  499. begin
  500. if AValue.Owner.ValueByName('B_Code').AsString <> '' then
  501. begin
  502. ErrorMessage('仅项目节可以输入设计数量!');
  503. Allow := False;
  504. end;
  505. end;
  506. end;
  507. function TBillsData.GetMaxBillsID: Integer;
  508. var
  509. Rec: TsdDataRecord;
  510. i: Integer;
  511. begin
  512. Result := 100;
  513. for i := 0 to sddBills.RecordCount - 1 do
  514. begin
  515. Rec := sddBills.Records[i];
  516. if Rec.ValueByName('ID').AsInteger > Result then
  517. Result := Rec.ValueByName('ID').AsInteger;
  518. end;
  519. end;
  520. procedure TBillsData.sddBillsGetRecordClass(
  521. var ARecordClass: TsdRecordClass);
  522. begin
  523. ARecordClass := TBillsRecord;
  524. end;
  525. end.