BillsDm.pas 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  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. sddBills.FieldByName('OrgQuantity').ValidChars := sddBills.FieldByName('Quantity').ValidChars + ArithmeticCharSet;
  110. sddBills.FieldByName('OrgTotalPrice').ValidChars := sddBills.FieldByName('OrgQuantity').ValidChars;
  111. sddBills.FieldByName('MisQuantity').ValidChars := sddBills.FieldByName('OrgQuantity').ValidChars;
  112. sddBills.FieldByName('MisTotalPrice').ValidChars := sddBills.FieldByName('OrgQuantity').ValidChars;
  113. sddBills.FieldByName('OthQuantity').ValidChars := sddBills.FieldByName('OrgQuantity').ValidChars;
  114. sddBills.FieldByName('OthTotalPrice').ValidChars := sddBills.FieldByName('OrgQuantity').ValidChars;
  115. end;
  116. procedure TBillsData.Save;
  117. procedure ResolveCode(ARec: TsdDataRecord);
  118. var
  119. sgs: TStrings;
  120. i: Integer;
  121. sXiangCode, sMuCode, sJieCode, sXiMuCode: string;
  122. begin
  123. sgs := TStringList.Create;
  124. try
  125. sgs.Delimiter := '-';
  126. sgs.DelimitedText := ARec.ValueByName('Code').AsString;
  127. case sgs.Count of
  128. 1: sXiangCode := '';
  129. 2: sXiangCode := ChinessNum(StrToIntDef(sgs[1], 0));
  130. 3: sMuCode := sgs[2];
  131. 4: sJieCode := sgs[3];
  132. else
  133. begin
  134. for i := 4 to sgs.Count - 1 do
  135. if sXiMuCode = '' then
  136. sXiMuCode := sgs[i]
  137. else
  138. sXiMuCode := sXiMuCode + '-' + sgs[i];
  139. end;
  140. end;
  141. finally
  142. if (ARec.ValueByName('XiangCode').AsString <> sXiangCode) then
  143. ARec.ValueByName('XiangCode').AsString := sXiangCode;
  144. if (ARec.ValueByName('MuCode').AsString <> sMuCode) then
  145. ARec.ValueByName('MuCode').AsString := sMuCode;
  146. if (ARec.ValueByName('JieCode').AsString <> sJieCode) then
  147. ARec.ValueByName('JieCode').AsString := sJieCode;
  148. if (ARec.ValueByName('XiMuCode').AsString <> sXiMuCode) then
  149. ARec.ValueByName('XiMuCode').AsString := sXiMuCode;
  150. sgs.Free;
  151. end;
  152. end;
  153. procedure SaveReportsRela;
  154. var
  155. iIndex: Integer;
  156. stnNode: TsdIDTreeNode;
  157. iLeafXmjParentID: Integer;
  158. sIndexCode: string;
  159. begin
  160. sddBills.BeginUpdate;
  161. try
  162. with TProjectData(FProjectData).BillsCompileData do
  163. for iIndex := 0 to BillsCompileTree.Count - 1 do
  164. begin
  165. stnNode := BillsCompileTree.Items[iIndex];
  166. // 分项清单排序
  167. if (stnNode.Rec.ValueByName('SerialNo').AsString = '') or
  168. (stnNode.MajorIndex <> stnNode.Rec.ValueByName('SerialNo').AsInteger) then
  169. stnNode.Rec.ValueByName('SerialNo').AsInteger := stnNode.MajorIndex;
  170. // 叶子节点
  171. if (stnNode.Rec.ValueByName('IsLeaf').asBoolean <> not stnNode.HasChildren) then
  172. stnNode.Rec.ValueByName('IsLeaf').AsBoolean := not stnNode.HasChildren;
  173. // 最底项目节父节点ID
  174. if (stnNode.Rec.ValueByName('B_Code').AsString <> '') then
  175. iLeafXmjParentID := GetLeafXmjParentID(stnNode.ID)
  176. else
  177. iLeafXmjParentID := -1;
  178. if (stnNode.Rec.ValueByName('LeafXmjParentID').AsInteger <> iLeafXmjParentID) then
  179. stnNode.Rec.ValueByName('LeafXmjParentID').AsInteger := iLeafXmjParentID;
  180. // 分解项目节编号为项、目、节、细目
  181. if stnNode.Rec.ValueByName('Code').AsString <> '' then
  182. ResolveCode(stnNode.Rec);
  183. // 工程量清单排序Code
  184. if (stnNode.Rec.ValueByName('B_Code').AsString <> '') then
  185. begin
  186. sIndexCode := B_CodeToIndexCode(stnNode.Rec.ValueByName('B_Code').AsString);
  187. if (stnNode.Rec.ValueByName('IndexCode').AsString <> sIndexCode) then
  188. stnNode.Rec.ValueByName('IndexCode').AsString := sIndexCode;
  189. end;
  190. end;
  191. finally
  192. sddBills.EndUpdate;
  193. end;
  194. end;
  195. begin
  196. if TProjectData(FProjectData).BillsCompileData.Active then
  197. SaveReportsRela; // 保存 SerialNo, IsLeaf, LeafXmjParentID, 分解Code
  198. sddBills.Save;
  199. end;
  200. {procedure TBillsData.Calculate(ABillsID: Integer);
  201. var
  202. stnNode: TsdIDTreeNode;
  203. iChild: Integer;
  204. begin
  205. stnNode := FBillsTree.FindNode(ABillsID);
  206. if stnNode.HasChildren then
  207. begin
  208. for iChild := 0 to stnNode.ChildCount - 1 do
  209. Calculate(stnNode.ChildNodes[iChild].ID);
  210. end
  211. else
  212. begin
  213. CalculateOrg(ABillsID);
  214. CalculateDeal(ABillsID);
  215. CalculateQuantityChange(ABillsID);
  216. CalculatePriceChange(ABillsID);
  217. end;
  218. end;
  219. procedure TBillsData.CalculateDeal(ABillsID: Integer);
  220. var
  221. iIndex: Integer;
  222. fQuantity, fTotalPrice: Double;
  223. Rec: TsdDataRecord;
  224. begin
  225. fQuantity := 0;
  226. fTotalPrice := 0;
  227. with TProjectData(FProjectData) do
  228. for iIndex := 0 to PhaseCount - 1 do
  229. begin
  230. Rec := PhaseData[iIndex].PhaseRecord(ABillsID);
  231. if not Assigned(Rec) then Continue;
  232. fQuantity := fQuantity + Rec.ValueByName('DealQuantity').AsFloat;
  233. fTotalPrice := fTotalPrice + Rec.ValueByName('DealTotalPrice').AsFloat;
  234. end;
  235. with FBillsTree.FindNode(ABillsID).Rec do
  236. UpdateRecordDeal(ABillsID, fQuantity - ValueByName('AddDealQuantity').AsFloat,
  237. fTotalPrice - ValueByName('AddDealTotalPrice').AsFloat);
  238. end;
  239. procedure TBillsData.CalculatePriceChange(ABillsID: Integer);
  240. var
  241. iIndex: Integer;
  242. fQuantity, fTotalPrice: Double;
  243. Rec: TsdDataRecord;
  244. begin
  245. fQuantity := 0;
  246. fTotalPrice := 0;
  247. with TProjectData(FProjectData) do
  248. for iIndex := 0 to PhaseCount - 1 do
  249. begin
  250. Rec := PhaseData[iIndex].PhaseRecord(ABillsID);
  251. if not Assigned(Rec) then Continue;
  252. fQuantity := fQuantity + Rec.ValueByName('PcQuantity').AsFloat;
  253. fTotalPrice := fTotalPrice + Rec.ValueByName('PcTotalPrice').AsFloat;
  254. end;
  255. with FBillsTree.FindNode(ABillsID).Rec do
  256. UpdateRecordPc(ABillsID, fQuantity - ValueByName('AddPcQuantity').AsFloat,
  257. fTotalPrice - ValueByName('AddPcTotalPrice').AsFloat);
  258. end;
  259. procedure TBillsData.CalculateQuantityChange(ABillsID: Integer);
  260. var
  261. iIndex: Integer;
  262. fQuantity, fTotalPrice: Double;
  263. Rec: TsdDataRecord;
  264. begin
  265. fQuantity := 0;
  266. fTotalPrice := 0;
  267. with TProjectData(FProjectData) do
  268. for iIndex := 0 to PhaseCount - 1 do
  269. begin
  270. Rec := PhaseData[iIndex].PhaseRecord(ABillsID);
  271. if not Assigned(Rec) then Continue;
  272. fQuantity := fQuantity + Rec.ValueByName('QcQuantity').AsFloat;
  273. fTotalPrice := fTotalPrice + Rec.ValueByName('QcTotalPrice').AsFloat;
  274. end;
  275. with FBillsTree.FindNode(ABillsID).Rec do
  276. UpdateRecordQc(ABillsID, fQuantity - ValueByName('AddQcQuantity').AsFloat,
  277. fTotalPrice - ValueByName('AddQcTotalPrice').AsFloat);
  278. end; }
  279. {
  280. procedure TBillsData.RecursiveCalculate(ABillsID: Integer);
  281. procedure GatherChildValue(ANode: TsdIDTreeNode);
  282. var
  283. CacheRecord: TCacheRecord;
  284. iChild: Integer;
  285. begin
  286. CacheRecord := TCacheRecord.Create;
  287. try
  288. for iChild := 0 to ANode.ChildCount - 1 do
  289. with ANode.ChildNodes[iChild].Rec do
  290. begin
  291. CacheRecord.FTotalPrice := CacheRecord.FTotalPrice + ValueByName('TotalPrice').AsFloat;
  292. CacheRecord.FDealQuantity := CacheRecord.FDealQuantity + ValueByName('AddDealQuantity').AsFloat;
  293. CacheRecord.FDealTotalPrice := CacheRecord.FDealTotalPrice + ValueByName('AddDealTotalPrice').AsFloat;
  294. CacheRecord.FQcQuantity := CacheRecord.FQcQuantity + ValueByName('AddQcQuantity').AsFloat;
  295. CacheRecord.FQcTotalPrice := CacheRecord.FQcTotalPrice + ValueByName('AddQcTotalPrice').AsFloat;
  296. CacheRecord.FPcQuantity := CacheRecord.FPcQuantity + ValueByName('AddPcQuantity').AsFloat;
  297. CacheRecord.FPcTotalPrice := CacheRecord.FPcTotalPrice + ValueByName('AddPcTotalPrice').AsFloat;
  298. end;
  299. finally
  300. CacheRecord.SetBillsRecord(ANode);
  301. CacheRecord.Free;
  302. end;
  303. end;
  304. procedure CalculateLeafNode(ANode: TsdIDTreeNode; ACacheRecord: TCacheRecord);
  305. begin
  306. with ANode.Rec do
  307. begin
  308. if ValueByName('QtyFlag').AsInteger = 1 then
  309. ValueByName('Quantity').AsFloat := EvaluateExprs(ValueByName('QtyFormula').AsString);
  310. if ValueByName('QtyFlag').AsInteger < 2 then
  311. ACacheRecord.FTotalPrice := ValueByName('Quantity').AsFloat * ValueByName('Price').AsFloat
  312. else
  313. begin
  314. FFormulaCalc.SetRecordText(ValueByName('QtyFormula').AsString);
  315. ACacheRecord.FTotalPrice := FFormulaCalc.Value;
  316. end;
  317. end;
  318. end;
  319. procedure GatherPhaseValue(ANode: TsdIDTreeNode);
  320. var
  321. CacheRecord: TCacheRecord;
  322. iIndex: Integer;
  323. Rec: TsdDataRecord;
  324. begin
  325. CacheRecord := TCacheRecord.Create;
  326. try
  327. CalculateLeafNode(ANode, CacheRecord);
  328. {with TProjectData(FProjectData) do
  329. for iIndex := 0 to PhaseCount - 1 do
  330. begin
  331. PhaseData[iIndex].ReCalculate(ANode.ID);
  332. Rec := PhaseData[iIndex].PhaseRecord(ANode.ID);
  333. if not Assigned(Rec) then Continue;
  334. CacheRecord.FDealQuantity := CacheRecord.FDealQuantity + Rec.ValueByName('DealQuantity').AsFloat;
  335. CacheRecord.FDealTotalPrice := CacheRecord.FDealTotalPrice + Rec.ValueByName('DealTotalPrice').AsFloat;
  336. CacheRecord.FQcQuantity := CacheRecord.FQcQuantity + Rec.ValueByName('QcQuantity').AsFloat;
  337. CacheRecord.FQcTotalPrice := CacheRecord.FQcTotalPrice + Rec.ValueByName('QcTotalPrice').AsFloat;
  338. CacheRecord.FPcQuantity := CacheRecord.FPcQuantity + Rec.ValueByName('PcQuantity').AsFloat;
  339. CacheRecord.FPcTotalPrice := CacheRecord.FPcTotalPrice + Rec.ValueByName('PcTotalPrice').AsFloat;
  340. end;}
  341. { finally
  342. CacheRecord.SetBillsRecord(ANode);
  343. CacheRecord.Free;
  344. end;
  345. end;
  346. procedure CalculateCurNode(ANode: TsdIDTreeNode);
  347. begin
  348. if ANode.HasChildren then
  349. GatherChildValue(ANode)
  350. else
  351. GatherPhaseValue(ANode);
  352. end;
  353. procedure CalculateAllChildren(ANode: TsdIDTreeNode);
  354. var
  355. iChild: Integer;
  356. begin
  357. if ANode.HasChildren then
  358. for iChild := 0 to ANode.ChildCount - 1 do
  359. RecursiveCalculate(ANode.ChildNodes[iChild].ID);
  360. end;
  361. var
  362. stnNode: TsdIDTreeNode;
  363. begin
  364. stnNode := FBillsTree.FindNode(ABillsID);
  365. CalculateAllChildren(stnNode);
  366. CalculateCurNode(stnNode);
  367. end; }
  368. procedure TBillsData.InitBills;
  369. var
  370. Import: TBillsExcelImport;
  371. begin
  372. Import := TBillsExcelImport.Create(TProjectData(ProjectData));
  373. try
  374. Import.ImportFile(GetTemplateBillsFileName);
  375. finally
  376. Import.Free;
  377. end;
  378. end;
  379. function TBillsData.GetStageData: TStageData;
  380. begin
  381. Result := TProjectData(FProjectData).PhaseData.StageData;
  382. end;
  383. procedure TBillsData.LockedBaseData;
  384. var
  385. iIndex: Integer;
  386. begin
  387. sddBills.BeginUpdate;
  388. for iIndex := 0 to sddBills.RecordCount - 1 do
  389. begin
  390. if not sddBills.Records[iIndex].ValueByName('LockedLevel').AsBoolean then
  391. sddBills.Records[iIndex].ValueByName('LockedLevel').AsBoolean := True;
  392. if not sddBills.Records[iIndex].ValueByName('LockedInfo').AsBoolean then
  393. sddBills.Records[iIndex].ValueByName('LockedInfo').AsBoolean := True;
  394. if sddBills.Records[iIndex].ValueByName('NewPrice').AsFloat <> 0 then
  395. sddBills.Records[iIndex].ValueByName('LockedNewPrice').AsBoolean := True;
  396. end;
  397. sddBills.EndUpdate;
  398. end;
  399. procedure TBillsData.sddBillsAfterAddRecord(ARecord: TsdDataRecord);
  400. begin
  401. ARecord.ValueByName('CreatePhaseID').AsInteger := TProjectData(FProjectData).PhaseIndex;
  402. end;
  403. function TBillsData.GetBuildLoadInterest(AIndex: Integer): Double;
  404. begin
  405. Result := GetGatherTotalPrice(34, AIndex);
  406. end;
  407. function TBillsData.GetFirstPart(AIndex: Integer): Double;
  408. begin
  409. Result := GetGatherTotalPrice(1, AIndex);
  410. end;
  411. function TBillsData.GetOtherFee(AIndex: Integer): Double;
  412. begin
  413. Result := GetGatherTotalPrice(15, AIndex);
  414. end;
  415. function TBillsData.GetOtherProjectFee(AIndex: Integer): Double;
  416. begin
  417. Result := GetGatherTotalPrice(9, AIndex);
  418. end;
  419. function TBillsData.GetRecyclingFee(AIndex: Integer): Double;
  420. begin
  421. Result := GetGatherTotalPrice(16, AIndex);
  422. end;
  423. function TBillsData.GetReservedFee(AIndex: Integer): Double;
  424. begin
  425. Result := GetGatherTotalPrice(7, AIndex);
  426. end;
  427. function TBillsData.GetSecondPart(AIndex: Integer): Double;
  428. begin
  429. Result := GetGatherTotalPrice(2, AIndex);
  430. end;
  431. function TBillsData.GetStageSettlement(AIndex: Integer): Double;
  432. begin
  433. // 全国
  434. // 第一部分+第二部分+第三部分+预备费+新增加费用项目(其他费用_广东)-回收金额
  435. Result := FirstPart[AIndex] + SecondPart[AIndex] + ThirdPart[AIndex]
  436. + ReservedFee[AIndex] + OtherFee[AIndex] - RecyclingFee[AIndex];
  437. // 广东
  438. // 全国的基础上+建设期贷款利息+公路功能以外的项目
  439. if _IsGuangDong then
  440. Result := Result + BuildLoadInterest[AIndex] + OtherProjectFee[AIndex];
  441. end;
  442. function TBillsData.GetThirdPart(AIndex: Integer): Double;
  443. begin
  444. Result := GetGatherTotalPrice(3, AIndex);
  445. end;
  446. function TBillsData.GetGatherTotalPrice(ABillsID, AIndex: Integer): Double;
  447. var
  448. Rec: TsdDataRecord;
  449. begin
  450. Result := 0;
  451. Rec := sddBills.FindKey('idxID', ABillsID);
  452. if Assigned(Rec) then
  453. begin
  454. case AIndex of
  455. 0: Result := Rec.ValueByName('TotalPrice').AsFloat;
  456. 1: Result := Rec.ValueByName('AddDealTotalPrice').AsFloat;
  457. 2: Result := Rec.ValueByName('AddQcTotalPrice').AsFloat;
  458. 3: Result := Rec.ValueByName('AddPcTotalPrice').AsFloat;
  459. 4: Result := Rec.ValueByName('AddGatherTotalPrice').AsFloat;
  460. end;
  461. end;
  462. end;
  463. procedure TBillsData.DisableEvents;
  464. begin
  465. sddBills.BeforeValueChange := nil;
  466. sddBills.AfterValueChanged := nil;
  467. end;
  468. procedure TBillsData.EnableEvents;
  469. begin
  470. {sddBills.BeforeValueChange := sddBillsBeforeValueChange;
  471. sddBills.AfterValueChanged := sddBillsAfterValueChanged;}
  472. end;
  473. procedure TBillsData.UnLockedBaseData;
  474. var
  475. iIndex: Integer;
  476. begin
  477. for iIndex := 0 to sddBills.RecordCount - 1 do
  478. sddBills.Records[iIndex].ValueByName('LockedInfo').AsBoolean := False;
  479. end;
  480. procedure TBillsData.sddBillsBeforeDeleteRecord(ARecord: TsdDataRecord;
  481. var Allow: Boolean);
  482. begin
  483. with TProjectData(FProjectData) do
  484. begin
  485. if ProjProperties.PhaseCount > 0 then
  486. PhaseData.StageData.DeletePhaseRecord(ARecord.ValueByName('ID').AsInteger);
  487. end;
  488. end;
  489. procedure TBillsData.sddBillsBeforeValueChange(AValue: TsdValue;
  490. const NewValue: Variant; var Allow: Boolean);
  491. begin
  492. if (Pos('DgnQuantity', AValue.FieldName) > 0) and
  493. not (VarIsNull(NewValue) or (NewValue = 0)) then
  494. begin
  495. if AValue.Owner.ValueByName('B_Code').AsString <> '' then
  496. begin
  497. ErrorMessage('仅项目节可以输入设计数量!');
  498. Allow := False;
  499. end;
  500. end;
  501. end;
  502. function TBillsData.GetMaxBillsID: Integer;
  503. var
  504. Rec: TsdDataRecord;
  505. i: Integer;
  506. begin
  507. Result := 100;
  508. for i := 0 to sddBills.RecordCount - 1 do
  509. begin
  510. Rec := sddBills.Records[i];
  511. if Rec.ValueByName('ID').AsInteger > Result then
  512. Result := Rec.ValueByName('ID').AsInteger;
  513. end;
  514. end;
  515. procedure TBillsData.sddBillsGetRecordClass(
  516. var ARecordClass: TsdRecordClass);
  517. begin
  518. ARecordClass := TBillsRecord;
  519. end;
  520. end.