StdBillsLibDM.pas 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715
  1. unit StdBillsLibDM;
  2. interface
  3. uses
  4. SysUtils, Classes, DBClient, Provider, DB, ADODB, ScBillsTree,
  5. ZjIDTree, ZjLists, ScProjectManager, DataBase;
  6. type
  7. TDMStdBillsLib = class(TDataModule)
  8. acnBillsLib: TADOConnection;
  9. atBillsLib: TADOTable;
  10. dspBillsLib: TDataSetProvider;
  11. cdsBillsLib: TClientDataSet;
  12. cdsBillsLibID: TIntegerField;
  13. cdsBillsLibParentID: TIntegerField;
  14. cdsBillsLibNextID: TIntegerField;
  15. cdsBillsLibCode: TWideStringField;
  16. cdsBillsLibB_Code: TWideStringField;
  17. cdsBillsLibName: TWideStringField;
  18. cdsBillsLibUnit: TWideStringField;
  19. cdsBillsLibStaticID: TIntegerField;
  20. cdsBillsLibExpr: TWideStringField;
  21. cdsBillsLibView: TClientDataSet;
  22. cdsBillsLibViewID: TIntegerField;
  23. cdsBillsLibViewParentID: TIntegerField;
  24. cdsBillsLibViewNextID: TIntegerField;
  25. cdsBillsLibViewCode: TWideStringField;
  26. cdsBillsLibViewB_Code: TWideStringField;
  27. cdsBillsLibViewName: TWideStringField;
  28. cdsBillsLibViewUnit: TWideStringField;
  29. cdsBillsLibViewStaticID: TIntegerField;
  30. cdsBillsLibViewExpr: TWideStringField;
  31. atDrawingQuantity: TADOTable;
  32. dspDrawingQuantity: TDataSetProvider;
  33. cdsDrawingQuantity: TClientDataSet;
  34. cdsDrawingQuantityID: TIntegerField;
  35. cdsDrawingQuantityName: TWideStringField;
  36. cdsDrawingQuantityUnits: TWideStringField;
  37. cdsDrawingQuantityDesignQuantity: TFloatField;
  38. cdsDrawingQuantityDesignQuantity2: TFloatField;
  39. cdsDrawingQuantityMemoStr: TWideStringField;
  40. cdsDrawingQuantityBillsID: TIntegerField;
  41. dspCustomStep: TDataSetProvider;
  42. cdsCustomStep: TClientDataSet;
  43. atCustomStep: TADOTable;
  44. cdsDrawQView: TClientDataSet;
  45. cdsDrawQViewID: TIntegerField;
  46. cdsDrawQViewName: TWideStringField;
  47. cdsDrawQViewUnits: TWideStringField;
  48. cdsDrawQViewDesignQuantity: TFloatField;
  49. cdsDrawQViewDesignQuantity2: TFloatField;
  50. cdsDrawQViewMemoStr: TWideStringField;
  51. cdsDrawQViewBillsID: TIntegerField;
  52. dsBillsDQ: TDataSource;
  53. cdsStaticID: TClientDataSet;
  54. cdsStaticIDName: TWideStringField;
  55. cdsStaticIDStaticID: TIntegerField;
  56. cdsStaticIDID: TIntegerField;
  57. cdsDQSetRange: TClientDataSet;
  58. cdsDQSetRangeID: TIntegerField;
  59. cdsDQSetRangeName: TWideStringField;
  60. cdsDQSetRangeUnits: TWideStringField;
  61. cdsDQSetRangeDesignQuantity: TFloatField;
  62. cdsDQSetRangeDesignQuantity2: TFloatField;
  63. cdsDQSetRangeMemoStr: TWideStringField;
  64. cdsDQSetRangeBillsID: TIntegerField;
  65. cdsCustomStepID: TIntegerField;
  66. cdsCustomStepFmtName: TWideStringField;
  67. cdsCustomStepStartValue: TFloatField;
  68. cdsCustomStepStepValue: TFloatField;
  69. cdsCustomStepView: TClientDataSet;
  70. cdsCustomStepBillsCode: TWideStringField;
  71. cdsCustomStepIsCode: TBooleanField;
  72. cdsCustomStepDisName: TWideStringField;
  73. cdsCustomStepUnits: TWideStringField;
  74. cdsCustomStepViewFmtName: TWideStringField;
  75. cdsCustomStepViewStartValue: TFloatField;
  76. cdsCustomStepViewStepValue: TFloatField;
  77. cdsCustomStepViewBillsCode: TWideStringField;
  78. cdsCustomStepViewIsCode: TBooleanField;
  79. cdsCustomStepViewDisName: TWideStringField;
  80. cdsCustomStepViewUnits: TWideStringField;
  81. cdsCustomStepViewCustomValue: TFloatField;
  82. cdsCustomStepOldValue: TFloatField;
  83. cdsCustomStepViewOldValue: TFloatField;
  84. cdsCustomStepStartCodeID: TIntegerField;
  85. cdsCustomStepViewStartCodeID: TIntegerField;
  86. cdsCustomStepViewCustomBillsCode: TWideStringField;
  87. atBillsQty: TADOTable;
  88. dspBillsQty: TDataSetProvider;
  89. cdsBillsQty: TClientDataSet;
  90. cdsBillsQtyView: TClientDataSet;
  91. acnBillsQty: TADOConnection;
  92. cdsBillsQtyID: TIntegerField;
  93. cdsBillsQtyParentID: TIntegerField;
  94. cdsBillsQtyNextID: TIntegerField;
  95. cdsBillsQtyCode: TWideStringField;
  96. cdsBillsQtyB_Code: TWideStringField;
  97. cdsBillsQtyName: TWideStringField;
  98. cdsBillsQtyUnit: TWideStringField;
  99. cdsBillsQtyStaticID: TIntegerField;
  100. cdsBillsQtyViewID: TIntegerField;
  101. cdsBillsQtyViewParentID: TIntegerField;
  102. cdsBillsQtyViewNextID: TIntegerField;
  103. cdsBillsQtyViewCode: TWideStringField;
  104. cdsBillsQtyViewB_Code: TWideStringField;
  105. cdsBillsQtyViewName: TWideStringField;
  106. cdsBillsQtyViewUnit: TWideStringField;
  107. cdsBillsQtyViewStaticID: TIntegerField;
  108. cdsBillsQtyExpr: TWideStringField;
  109. cdsBillsQtyViewExpr: TWideStringField;
  110. acCustomStep: TADOConnection;
  111. atBQDrawingQty: TADOTable;
  112. dspBQDrawingQty: TDataSetProvider;
  113. cdsBQDrawingQty: TClientDataSet;
  114. cdsBQDrawingQtyView: TClientDataSet;
  115. dsBillsQty: TDataSource;
  116. cdsBQDrawingQtyID: TIntegerField;
  117. cdsBQDrawingQtyName: TWideStringField;
  118. cdsBQDrawingQtyUnits: TWideStringField;
  119. cdsBQDrawingQtyDesignQuantity: TFloatField;
  120. cdsBQDrawingQtyDesignQuantity2: TFloatField;
  121. cdsBQDrawingQtyMemoStr: TWideStringField;
  122. cdsBQDrawingQtyBillsID: TIntegerField;
  123. cdsBQDrawingQtyViewID: TIntegerField;
  124. cdsBQDrawingQtyViewName: TWideStringField;
  125. cdsBQDrawingQtyViewUnits: TWideStringField;
  126. cdsBQDrawingQtyViewDesignQuantity: TFloatField;
  127. cdsBQDrawingQtyViewDesignQuantity2: TFloatField;
  128. cdsBQDrawingQtyViewMemoStr: TWideStringField;
  129. cdsBQDrawingQtyViewBillsID: TIntegerField;
  130. cdsFastSearch: TClientDataSet;
  131. cdsBQFastSearch: TClientDataSet;
  132. cdsBQFastSearchID: TIntegerField;
  133. cdsBQFastSearchParentID: TIntegerField;
  134. cdsBQFastSearchNextID: TIntegerField;
  135. cdsBQFastSearchCode: TWideStringField;
  136. cdsBQFastSearchB_Code: TWideStringField;
  137. cdsBQFastSearchName: TWideStringField;
  138. cdsBQFastSearchUnit: TWideStringField;
  139. cdsBQFastSearchStaticID: TIntegerField;
  140. cdsBQFastSearchExpr: TWideStringField;
  141. cdsFastSearchID: TIntegerField;
  142. cdsFastSearchParentID: TIntegerField;
  143. cdsFastSearchNextID: TIntegerField;
  144. cdsFastSearchCode: TWideStringField;
  145. cdsFastSearchB_Code: TWideStringField;
  146. cdsFastSearchName: TWideStringField;
  147. cdsFastSearchUnit: TWideStringField;
  148. cdsFastSearchStaticID: TIntegerField;
  149. cdsFastSearchExpr: TWideStringField;
  150. cdsCustomStepFmtName2: TWideStringField;
  151. cdsCustomStepViewFmtName2: TWideStringField;
  152. cdsCustomStepSubArea: TBooleanField;
  153. cdsCustomStepViewSubArea: TBooleanField;
  154. procedure cdsBillsLibAfterOpen(DataSet: TDataSet);
  155. procedure cdsDrawingQuantityAfterOpen(DataSet: TDataSet);
  156. procedure DataModuleCreate(Sender: TObject);
  157. procedure DataModuleDestroy(Sender: TObject);
  158. procedure cdsCustomStepViewCustomValueChange(Sender: TField);
  159. procedure cdsCustomStepViewAfterPost(DataSet: TDataSet);
  160. procedure cdsCustomStepViewBeforeInsert(DataSet: TDataSet);
  161. procedure cdsCustomStepViewBeforeDelete(DataSet: TDataSet);
  162. procedure cdsBillsLibViewBeforeInsert(DataSet: TDataSet);
  163. procedure cdsBillsLibAfterClose(DataSet: TDataSet);
  164. procedure cdsBillsQtyAfterOpen(DataSet: TDataSet);
  165. procedure cdsBQDrawingQtyAfterOpen(DataSet: TDataSet);
  166. procedure cdsBillsLibViewAfterPost(DataSet: TDataSet);
  167. procedure cdsBillsLibViewCodeChange(Sender: TField);
  168. procedure cdsBillsLibViewAfterInsert(DataSet: TDataSet);
  169. procedure cdsBillsQtyViewAfterPost(DataSet: TDataSet);
  170. procedure cdsBillsQtyViewAfterInsert(DataSet: TDataSet);
  171. procedure cdsDrawQViewNewRecord(DataSet: TDataSet);
  172. procedure cdsBQDrawingQtyViewNewRecord(DataSet: TDataSet);
  173. private
  174. FActive: Boolean;
  175. FMaxBillsID: Integer;
  176. FStdBillsCtrl: TObject;
  177. FCustomStepFlag: Boolean;
  178. FAdding: Boolean;
  179. FCdsStaticID: TClientDataSet;
  180. FCdsModifyBills: TClientDataSet;
  181. FStdBillNode: TStdBillNode;
  182. FStdBillsTree: TStdBillsTree;
  183. FBillsQtyTree: TStdBillsTree;
  184. FBillsData: TDMDataBase;
  185. FProjectMgr: TProjectManager;
  186. procedure Initialize(aType: Integer; AIsAll: Boolean);
  187. procedure Finalize(aType: Integer; AIsAll: Boolean);
  188. procedure CreateCDS;
  189. procedure DestroyCDs;
  190. procedure DoInitDBRecord;
  191. {compare code}
  192. function CompareDiagitCode(AsCode, ACode: string): Integer;
  193. function IsStaticIDExist(ALibNode: TZjIDTreeNode): Boolean;
  194. {add drawingquantity}
  195. procedure AddRelaDrawQ(ADestID, ASrcID: Integer);
  196. {add bills items}
  197. function AddNewItem(AStdNode: TStdBillNode): TScBillsItem;
  198. {calculate code and name by customstep}
  199. function CalculateCode(var aCustomValue: Double; var ACode, ADisName, AUnits: string; AIncrease: Boolean = False): Boolean;
  200. procedure RecodeCurBills(aCustomValue: Double; const ACode, ADisName, AUnits: string; AIsCode, AIncrease: Boolean);
  201. procedure EditCustomStepOldValue(const ACode: string; const Value: Double);
  202. procedure EditCustomStepViewOldValue(const Value: Double);
  203. {locate customstep by code}
  204. function LocateCustomStepByCode(aID: Integer; const ACode, AOldCode: string): Boolean;
  205. {add qty item}
  206. function CanAddQtyItem(var aNode: TScBillsItem): Boolean;
  207. procedure AddQtyRelaDrawQ(ADestID, ASrcID: Integer);
  208. function AddNewQtyItems(aNode: TScBillsItem; aQtyNode: TStdBillNode): TScBillsItem;
  209. function GetNewID(DataSet: TClientDataSet): Integer;
  210. public
  211. constructor Create(AProjMgr: TProjectManager);
  212. { close }
  213. procedure CloseLib(aFileFlag: Integer);
  214. {open new std lib}
  215. procedure LoadNewStdLib(const ALibName: string);
  216. procedure LoadBillsQtyLib(const ALibName: string);
  217. procedure LoadCustomStep(const aLibName: string);
  218. {add items to cur project}
  219. function AddItems(ASelList: TIntegerSList): Boolean;
  220. procedure AddItem;
  221. {add billsQty items}
  222. function AddBillsQtyItems(aSelList: TIntegerSList): Boolean;
  223. procedure AddBillsQtyItem;
  224. function IsCodeStepItem(AB_Code: string; var AUnits: string): Boolean;
  225. {refresh customstep}
  226. procedure RefreshCustomStep;
  227. {only be used in before post}
  228. procedure AutoIncreaseBillsCode;
  229. {find code in std lib}
  230. function FindLibCode(const ACode: string; var AName, AUnits: string; AIsCode: Boolean): Boolean;
  231. function FindRecord(aNode: TZjIDTreeNode; const aCode, aName: string): Boolean;
  232. // Added by GiLi 2012-3-20 11:00:46
  233. // 定位至标准清单
  234. procedure LocateCurBillsToStdBills;
  235. procedure Save;
  236. property StdBillsCtrl: TObject read FStdBillsCtrl write FStdBillsCtrl;
  237. property StdBillsTree: TStdBillsTree read FStdBillsTree write FStdBillsTree;
  238. property BillsQtyTree: TStdBillsTree read FBillsQtyTree write FBillsQtyTree;
  239. // 这两个属性是为了和SmartCost定义保持一致,方便代码Copy. chenshilong, 2011-07-20
  240. property StdTree: TStdTree read FStdBillsTree write FStdBillsTree;
  241. property BQStdTree: TStdTree read FBillsQtyTree write FBillsQtyTree;
  242. procedure CloneActive(IsActive: Boolean);
  243. end;
  244. implementation
  245. {$R *.dfm}
  246. uses
  247. Windows,
  248. Controls,
  249. ConstVarUnit,
  250. ConstMethodUnit,
  251. ScStdBillsCtrl,
  252. Math;
  253. procedure TDMStdBillsLib.cdsBillsLibAfterOpen(DataSet: TDataSet);
  254. begin
  255. cdsBillsLibView.CloneCursor(cdsBillsLib, True);
  256. cdsStaticID.CloneCursor(cdsBillsLib, True);
  257. cdsStaticID.IndexFieldNames := SID;
  258. cdsStaticID.Filter := 'StaticID>0';
  259. cdsStaticID.Filtered := True;
  260. FStdBillsTree.DataSet := cdsBillsLibView;
  261. FStdBillsTree.Selected.Expand;
  262. cdsFastSearch.CloneCursor(cdsBillsLib, True);
  263. cdsFastSearch.IndexFieldNames := 'Code';
  264. cdsFastSearch.Filter := 'Code is not null';
  265. cdsFastSearch.Filtered := True;
  266. end;
  267. procedure TDMStdBillsLib.cdsDrawingQuantityAfterOpen(DataSet: TDataSet);
  268. begin
  269. cdsDrawQView.CloneCursor(cdsDrawingQuantity, True);
  270. cdsDrawQView.MasterSource := dsBillsDQ;
  271. cdsDrawQView.MasterFields := SID;
  272. cdsDrawQView.IndexFieldNames := Format('%s;%s', [sBillsID, SID]);
  273. cdsDQSetRange.CloneCursor(cdsDrawingQuantity, True);
  274. cdsDQSetRange.IndexFieldNames := sBillsID;
  275. end;
  276. procedure TDMStdBillsLib.LoadNewStdLib(const ALibName: string);
  277. begin
  278. cdsDrawQView.DisableControls;
  279. cdsBillsLibView.DisableControls;
  280. try
  281. acnBillsLib.Connected := False;
  282. acnBillsLib.ConnectionString := Format(SAdoConnectStr, [ALibName, 'Admin', '']);
  283. acnBillsLib.Connected := True;
  284. IncProgressUI(10);
  285. {refresh bills}
  286. cdsBillsLib.Close;
  287. cdsBillsLib.Open;
  288. IncProgressUI(40);
  289. {refresh drawingQuantity}
  290. cdsDrawingQuantity.Close;
  291. cdsDrawingQuantity.Open;
  292. cdsDrawingQuantity.IndexFieldNames := 'ID';
  293. IncProgressUI(100);
  294. {refresh custom step}
  295. { cdsCustomStep.Close;
  296. cdsCustomStep.Open;
  297. IncProgressUI(100); }
  298. FActive := True;
  299. finally
  300. cdsDrawQView.EnableControls;
  301. cdsBillsLibView.EnableControls;
  302. end;
  303. end;
  304. procedure TDMStdBillsLib.DataModuleCreate(Sender: TObject);
  305. begin
  306. FStdBillsTree := TStdBillsTree.Create;
  307. FStdBillsTree.KeyFieldName := 'ID';
  308. FStdBillsTree.ParentFieldName := 'ParentID';
  309. FStdBillsTree.NextSiblingFieldName := 'NextID';
  310. FStdBillsTree.AutoCreateKeyID := True;
  311. {如果太早设置BillsTree.dataset,则定位会错乱,应该写在AfterOpen之后}
  312. // FStdBillsTree.DataSet := cdsBillsLibView;
  313. FBillsQtyTree := TStdBillsTree.Create;
  314. FBillsQtyTree.KeyFieldName := 'ID';
  315. FBillsQtyTree.ParentFieldName := 'ParentID';
  316. FBillsQtyTree.NextSiblingFieldName := 'NextID';
  317. FBillsQtyTree.AutoCreateKeyID := True;
  318. cdsCustomStepView.Open;
  319. end;
  320. procedure TDMStdBillsLib.DataModuleDestroy(Sender: TObject);
  321. begin
  322. FStdBillsTree.Free;
  323. FBillsQtyTree.Free;
  324. end;
  325. function TDMStdBillsLib.AddNewItem(AStdNode: TStdBillNode): TScBillsItem;
  326. {比较节点前后关系, 小于返回小于0, 等于返回0, 大于返回大于0}
  327. function CompareNodesDifference(ASNode: TStdBillNode; ANode: TScBillsItem): Integer;
  328. function TranslateChineseToALB(AWord: WideString): Integer;
  329. const
  330. chaArr: array [0..9] of WideString = ('十', '一', '二', '三', '四',
  331. '五', '六', '七', '八', '九');
  332. function ChnToNum(ANum: WideString): Integer;
  333. var
  334. J: Integer;
  335. begin
  336. Result := -1;
  337. for J := 0 to 9 do
  338. begin
  339. if SameText(ANum, chaArr[J]) then
  340. begin
  341. Result := J;
  342. if Result = 0 then Result := 10;
  343. Break;
  344. end;
  345. end;
  346. end;
  347. var
  348. I, len, icha: Integer;
  349. begin
  350. Result := 0;
  351. len := Length(AWord);
  352. for I := 1 to Len do
  353. begin
  354. icha := ChnToNum(AWord[I]);
  355. if icha = 10 then
  356. begin
  357. if Result = 0 then Result := 10
  358. else Result := Result * 10;
  359. end
  360. else
  361. begin
  362. if Result = 0 then Result := icha
  363. else Result := Result + icha;
  364. end;
  365. end;
  366. end;
  367. function CompareNodeCode(const ASCode, ACode: string; var AResult: Integer): Boolean;
  368. var
  369. l1, l2: Integer;
  370. begin
  371. if SameText(ASCode, ACode) then
  372. begin
  373. Result := False;
  374. Exit;
  375. end;
  376. Result := True;
  377. l1 := -1;
  378. l2 := -1;
  379. if not SameText(ASCode, '') and not SameText(ACode, '') then
  380. begin
  381. if Length(ASCode) - Length(WideString(ASCode)) > 0 then
  382. l1 := TranslateChineseToALB(ASCode);
  383. if Length(ACode) - Length(WideString(ACode)) > 0 then
  384. l2 := TranslateChineseToALB(ACode);
  385. if (l1 = -1) and (l2 = -1) then
  386. AResult := CompareDiagitCode(ASCode, ACode)
  387. else AResult := l1 - l2;
  388. end
  389. else Result := False;
  390. end;
  391. function CompareNodeBCode(const ASBCode, ABCode: string; var AResult: Integer): Boolean;
  392. begin
  393. if SameText(ASBCode, ABCode) then
  394. begin
  395. Result := False;
  396. Exit;
  397. end;
  398. Result := True;
  399. if not SameText(ASBCode, '') and not SameText(ABCode, '') then
  400. AResult := CompareDiagitCode(ASBCode, ABCode)
  401. else Result := False;
  402. end;
  403. function CompareNodeName(const ASName, AName: string; var AResult: Integer): Boolean;
  404. begin
  405. if (pos('…', ASName) <> 0) or (pos('…', AName) <> 0) then
  406. AResult := CompareText(ASName, AName) * -1
  407. else AResult := CompareText(ASName, AName);
  408. end;
  409. begin
  410. if CompareNodeCode(ASNode.Code, ANode.SBillCode, Result) then Exit;
  411. if CompareNodeBCode(ASNode.BCode, ANode.SBillBCode, Result) then Exit;
  412. CompareNodeName(ASNode.Name, ANode.SBillName, Result);
  413. end;
  414. procedure EditPropertyInDB(ANode: TScBillsItem; ASNode: TStdBillNode);
  415. var
  416. sLibNodeStaticExpr: string;
  417. begin
  418. ANode.SBillCode := ASNode.Code;
  419. ANode.SBillBCode := ASNode.BCode;
  420. ANode.SBillName := ASNode.Name;
  421. ANode.Units := ASNode.Units;
  422. { if not SameText(ASNode.Exprs, '') then
  423. begin
  424. // sLibNodeStaticExpr := ASNode.Exprs;
  425. // sLibNodeStaticExpr := ExprsGraph.PretreatExprs(sLibNodeStaticExpr);
  426. // 表达式计算图,用来进行表达式的运算管理等
  427. // ExprsGraph.SetExpression(ANode.ID, Copy(sLibNodeStaticExpr, 2, MaxInt));
  428. // sLibNodeStaticExpr := ExprsGraph.ConvertExprsForSave(sLibNodeStaticExpr);
  429. // FProject.Exprs.AddExprs(1, 3, ANode.ID, sLibNodeStaticExpr, Evaluate(sLibNodeStaticExpr), 0);
  430. // ANode.IsCalcExprs := True;
  431. end; }
  432. end;
  433. {取最顶层节点}
  434. function GetAnsctorNode(ASNode: TStdBillNode; AList: TList): TScBillsItem;
  435. var
  436. vNode: TStdBillNode;
  437. vItem: TScBillsItem;
  438. iPreID: Integer;
  439. begin
  440. vNode := ASNode.TopestAncestor(AList);
  441. vItem := TScBillsItem(FBillsData.BillsTree.FirstNode);
  442. while Assigned(vItem) do
  443. begin
  444. if SameText(vNode.Code, vItem.SBillCode) and SameText(vNode.Name, vItem.SBillName) then Break;
  445. vItem := TScBillsItem(vItem.NextSibling);
  446. end;
  447. if Assigned(vItem) then Result := vItem
  448. else
  449. begin
  450. FStdBillNode := vNode;
  451. with FBillsData do
  452. begin
  453. // 有固定ID的黑体字项,也要求能找到自己的正确位置。
  454. if vNode.StaticID <> -1 then
  455. begin
  456. iPreID := PreBlackFontItemID(vNode.StaticID);
  457. Result := BillsTree.AddBillsItem(vNode.StaticID, -1, BillsTree[iPreID].NextSiblingID);
  458. end
  459. // 因某种情况没有设置固定ID的黑体字项(如老版本标准项目表),要求也能正确添加不会报错,用于兼容
  460. else
  461. begin
  462. Result := BillsTree.AddBillsItem(FMaxBillsID, -1, -1);
  463. Inc(FMaxBillsID);
  464. end;
  465. EditPropertyInDB(Result, vNode);
  466. AddRelaDrawQ(Result.ID, vNode.ID);
  467. end;
  468. end;
  469. end;
  470. {往清单中添加指定节点}
  471. function AddCurStdNodeToBills(AParentNode: TScBillsItem; ASNode: TStdBillNode): TScBillsItem;
  472. var
  473. I, iResult: Integer;
  474. blFlag: Boolean;
  475. vItem: TScBillsItem;
  476. begin
  477. blFlag := False;
  478. FStdBillNode := ASNode;
  479. for I := 0 to AParentNode.ChildCount - 1 do
  480. begin
  481. vItem := TScBillsItem(AParentNode.ChildNodes[I]);
  482. iResult := CompareNodesDifference(ASNode, vItem);
  483. if iResult < 0 then
  484. begin
  485. with FBillsData do
  486. begin
  487. if ASNode.StaticID = -1 then
  488. begin
  489. Result := TScBillsItem(BillsTree.AddBillsItem(FMaxBillsID, AParentNode.ID, vItem.ID));
  490. Inc(FMaxBillsID);
  491. end
  492. else
  493. Result := TScBillsItem(BillsTree.AddBillsItem(ASNode.StaticID, AParentNode.ID, vItem.ID));
  494. // ModifyParentIsLeaf(AParentNode.ID);
  495. EditPropertyInDB(Result, ASNode);
  496. AddRelaDrawQ(Result.ID, ASNode.ID);
  497. blFlag := True;
  498. Break;
  499. end;
  500. end
  501. else if iResult = 0 then
  502. begin
  503. Result := vItem;
  504. //AddRelaDrawQ(Result.ID, ASNode.ID);
  505. blFlag := True;
  506. Break;
  507. end;
  508. end;
  509. if not blFlag then
  510. begin
  511. if ASNode.StaticID = -1 then
  512. begin
  513. Result := TScBillsItem(FBillsData.BillsTree.AddBillsItem(FMaxBillsID, AParentNode.ID, -1));
  514. Inc(FMaxBillsID);
  515. end
  516. else
  517. Result := TScBillsItem(FBillsData.BillsTree.AddBillsItem(ASNode.StaticID, AParentNode.ID, -1));
  518. // ModifyParentIsLeaf(AParentNode.ID);
  519. EditPropertyInDB(Result, ASNode);
  520. AddRelaDrawQ(Result.ID, ASNode.ID);
  521. end;
  522. end;
  523. {在清单树中检查并返回父节点,如果没有,则创建父节点}
  524. function CheckAndThenGetParent(ASNode: TStdBillNode): TScBillsItem;
  525. var
  526. ansctor: TScBillsItem;
  527. lstNode: TList;
  528. vNode: TStdBillNode;
  529. I: Integer;
  530. begin
  531. lstNode := TList.Create;
  532. try
  533. ansctor := GetAnsctorNode(ASNode, lstNode);
  534. if not Assigned(ansctor) then
  535. begin
  536. FStdBillNode := ASNode;
  537. if ASNode.StaticID <> -1 then
  538. ansctor := TScBillsItem(FBillsData.BillsTree.AddBillsItem(ASNode.StaticID, -1, -1))
  539. else
  540. begin
  541. ansctor := TScBillsItem(FBillsData.BillsTree.AddBillsItem(FMaxBillsID, -1, -1));
  542. Inc(FMaxBillsID);
  543. end;
  544. EditPropertyInDB(ansctor, ASNode);
  545. AddRelaDrawQ(Result.ID, ASNode.ID);
  546. end;
  547. Result := ansctor;
  548. for I := lstNode.Count - 2 downto 0 do
  549. begin
  550. vNode := TStdBillNode(lstNode[I]);
  551. Result := AddCurStdNodeToBills(Result, vNode);
  552. end;
  553. finally
  554. lstNode.Free;
  555. end;
  556. end;
  557. var
  558. vItem: TScBillsItem;
  559. begin
  560. vItem := CheckAndThenGetParent(AStdNode);
  561. Result := vItem;
  562. if not Assigned(AStdNode.Parent) and Assigned(vItem) and
  563. (CompareNodesDifference(AStdNode, vItem) = 0) then Exit;
  564. if Assigned(vItem) then Result := AddCurStdNodeToBills(vItem, AStdNode);
  565. end;
  566. function TDMStdBillsLib.AddItems(ASelList: TIntegerSList): Boolean;
  567. var
  568. I: Integer;
  569. Node: TStdBillNode;
  570. vNode: TZjIDTreeNode;
  571. begin
  572. Result := False;
  573. if not Assigned(FProjectMgr.ActiveProject) then Exit;
  574. if not cdsBillsLib.Active then Exit;
  575. FBillsData := FProjectMgr.ActiveProject.BillsData;
  576. FMaxBillsID := FBillsData.GetMaxBillsID;
  577. Initialize(1, True);
  578. FAdding := True;
  579. try
  580. vNode := nil;
  581. for I := 0 to FStdBillsTree.Count - 1 do
  582. begin
  583. Node := TStdBillNode(FStdBillsTree.Items[I]);
  584. if (ASelList[I] <> 0) and not IsStaticIDExist(Node) then
  585. begin
  586. vNode := AddNewItem(Node);
  587. // TStdBillsCtrl(FStdBillsCtrl).IncStep := 1;
  588. end;
  589. end;
  590. Result := True;
  591. finally
  592. Finalize(1, True);
  593. FAdding := False;
  594. if Assigned(vNode) then
  595. vNode.LocateDBRecord;
  596. end;
  597. end;
  598. procedure TDMStdBillsLib.AddItem;
  599. var
  600. vNode: TZjIDTreeNode;
  601. begin
  602. if not Assigned(FProjectMgr.ActiveProject) then Exit;
  603. FBillsData := FProjectMgr.ActiveProject.BillsData;
  604. FMaxBillsID := FBillsData.GetMaxBillsID;
  605. Initialize(1, False);
  606. FAdding := True;
  607. try
  608. if IsStaticIDExist(FStdBillsTree.Selected) then Exit;
  609. vNode := AddNewItem(TStdBillNode(FStdBillsTree.Selected));
  610. // 双击定位
  611. if Assigned(vNode) then
  612. vNode.LocateDBRecord;
  613. finally
  614. Finalize(1, False);
  615. FAdding := False;
  616. end;
  617. end;
  618. constructor TDMStdBillsLib.Create(AProjMgr: TProjectManager);
  619. begin
  620. inherited Create(nil);
  621. FProjectMgr := AProjMgr;
  622. end;
  623. procedure TDMStdBillsLib.Finalize(aType: Integer; AIsAll: Boolean);
  624. begin
  625. with FBillsData do
  626. begin
  627. if AIsAll then
  628. begin
  629. {endUpdate}
  630. TStdBillsCtrl(FStdBillsCtrl).EndUpdateUI(aType);
  631. EnabledUITreeEvt(True, False);
  632. EnabledUIDrawQtyEvt(True);
  633. end;
  634. BillsTree.InternalEvent := nil;
  635. EndHandler;
  636. DestroyCDs;
  637. end;
  638. end;
  639. procedure TDMStdBillsLib.Initialize(aType: Integer; AIsAll: Boolean);
  640. begin
  641. with FBillsData do
  642. begin
  643. if AIsAll then
  644. begin
  645. {beginUpdate}
  646. TStdBillsCtrl(FStdBillsCtrl).BeginUpdateUI(aType);
  647. EnabledUITreeEvt(False, False);
  648. EnabledUIDrawQtyEvt(False);
  649. end;
  650. BillsTree.InternalEvent := DoInitDBRecord;
  651. {Events}
  652. BeginHandler;
  653. CreateCDS;
  654. end;
  655. end;
  656. procedure TDMStdBillsLib.DoInitDBRecord;
  657. begin
  658. with FBillsData.BillsTree do
  659. begin
  660. DataSet.FieldByName('Code').AsString := FStdBillNode.Code;
  661. DataSet.FieldByName('B_Code').AsString := FStdBillNode.BCode;
  662. DataSet.FieldByName('Name').AsString := FStdBillNode.Name;
  663. DataSet.FieldByName('Units').AsString := FStdBillNode.Units;
  664. // DataSet.FieldByName('IsLeaf').AsBoolean := True;
  665. end;
  666. end;
  667. function TDMStdBillsLib.IsStaticIDExist(ALibNode: TZjIDTreeNode): Boolean;
  668. var
  669. CheckID: Integer;
  670. CheckName, sHintName: string;
  671. begin
  672. Result := False;
  673. if ALibNode.ID >= 100 then Exit;
  674. if cdsStaticID.FindKey([ALibNode.ID]) then
  675. begin
  676. CheckName := cdsStaticIDName.AsString;
  677. CheckID := cdsStaticIDStaticID.AsInteger;
  678. with FBillsData do
  679. begin
  680. // ID号相同名称不同视作ID被占用。
  681. // ID号相同名称也相同表示清单已存在。
  682. if FCdsStaticID.FindKey([CheckID]) then
  683. begin
  684. Result := True;
  685. BillsTree[CheckID].LocateDBRecord;
  686. if FCdsStaticID.FieldByName('Name').AsString <> CheckName then
  687. begin
  688. if FCdsStaticID.FieldByName('Code').AsString <> '' then
  689. sHintName := FCdsStaticID.FieldByName('Code').AsString +
  690. FCdsStaticID.FieldByName('Name').AsString
  691. else
  692. sHintName := FCdsStaticID.FieldByName('Name').AsString;
  693. MessageHint(0, Format('固定ID(%d)已被清单“%s”占用,添加失败,可先将其删除然后再添加。', [CheckID, sHintName]));
  694. end;
  695. end;
  696. end;
  697. end;
  698. end;
  699. procedure TDMStdBillsLib.CreateCDS;
  700. begin
  701. with FBillsData do
  702. begin
  703. FCdsStaticID := TClientDataSet.Create(nil);
  704. FCdsStaticID.CloneCursor(cdsBills, True);
  705. FCdsStaticID.IndexFieldNames := SID;
  706. FCdsStaticID.Filter := 'ID>0 and ID<100';
  707. FCdsStaticID.Filtered := True;
  708. FCdsModifyBills := TClientDataSet.Create(nil);
  709. FCdsModifyBills.CloneCursor(cdsBills, True);
  710. FCdsModifyBills.IndexFieldNames := SID;
  711. end;
  712. end;
  713. procedure TDMStdBillsLib.DestroyCDs;
  714. begin
  715. FCdsStaticID.Free;
  716. FCdsModifyBills.Free;
  717. end;
  718. procedure TDMStdBillsLib.AddRelaDrawQ(ADestID, ASrcID: Integer);
  719. var
  720. iMaxDQID, iSerinalNo: Integer;
  721. begin
  722. iSerinalNo := 1;
  723. iMaxDQID := FBillsData.GetMaxDrawingQuangtiyID;
  724. cdsDQSetRange.SetRange([ASrcID], [ASrcID]);
  725. while not cdsDQSetRange.Eof do
  726. begin
  727. FBillsData.cdsDrawingQuantity.Insert;
  728. FBillsData.cdsDrawingQuantityID.Value := iMaxDQID;
  729. FBillsData.cdsDrawingQuantitySerinalNo.Value := iSerinalNo;
  730. FBillsData.cdsDrawingQuantityBillsID.Value := ADestID;
  731. FBillsData.cdsDrawingQuantityName.Value := cdsDQSetRangeName.Value;
  732. FBillsData.cdsDrawingQuantityUnits.Value := cdsDQSetRangeUnits.Value;
  733. FBillsData.cdsDrawingQuantityDQuantity1.Value := cdsDQSetRangeDesignQuantity.Value;
  734. FBillsData.cdsDrawingQuantityMemoContext.Value := cdsDQSetRangeMemoStr.Value;
  735. FBillsData.cdsDrawingQuantity.Post;
  736. Inc(iMaxDQID);
  737. Inc(iSerinalNo);
  738. cdsDQSetRange.Next;
  739. end;
  740. cdsDQSetRange.CancelRange;
  741. end;
  742. function TDMStdBillsLib.CalculateCode(var aCustomValue: Double; var ACode, ADisName, AUnits: string;
  743. AIncrease: Boolean): Boolean;
  744. var
  745. iSuffix: Integer;
  746. dCustomValue: Double;
  747. begin
  748. dCustomValue := cdsCustomStepViewCustomValue.Value;
  749. if AIncrease then
  750. begin
  751. dCustomValue := cdsCustomStepViewOldValue.Value + cdsCustomStepViewStepValue.Value;
  752. end;
  753. aCustomValue := dCustomValue;
  754. iSuffix := Ceil((dCustomValue - cdsCustomStepViewStartValue.Value) / cdsCustomStepViewStepValue.Value);
  755. if iSuffix >= 0 then
  756. begin
  757. if AIncrease and (cdsCustomStepViewStartCodeID.Value > 0) then
  758. dCustomValue := cdsCustomStepViewStartValue.Value + (iSuffix - 1) * cdsCustomStepViewStepValue.Value
  759. else
  760. dCustomValue := cdsCustomStepViewStartValue.Value + iSuffix * cdsCustomStepViewStepValue.Value;
  761. if dCustomValue <= cdsCustomStepViewStartValue.AsFloat then
  762. ADisName := Format(cdsCustomStepViewFmtName.AsString, [FloatToStr(dCustomValue)])
  763. else if cdsCustomStepViewSubArea.AsBoolean then
  764. ADisName := Format(cdsCustomStepViewFmtName2.AsString,
  765. [FloatToStr(dCustomValue - cdsCustomStepViewStepValue.AsFloat), FloatToStr(dCustomValue)])
  766. else
  767. ADisName := Format(cdsCustomStepViewFmtName2.AsString, [FloatToStr(dCustomValue)]);
  768. if cdsCustomStepViewStartCodeID.Value > 0 then
  769. begin
  770. if AIncrease then
  771. iSuffix := iSuffix + cdsCustomStepViewStartCodeID.Value - 2
  772. else
  773. iSuffix := iSuffix + cdsCustomStepViewStartCodeID.Value - 1;
  774. end;
  775. ACode := Format('%s-%d', [cdsCustomStepViewBillsCode.AsString, iSuffix + 1]);
  776. AUnits := cdsCustomStepViewUnits.AsString;
  777. if AIncrease and (cdsCustomStepViewStartCodeID.Value > 0) then
  778. dCustomValue := dCustomValue + cdsCustomStepViewStepValue.Value;
  779. EditCustomStepViewOldValue(dCustomValue);
  780. if cdsCustomStepViewCustomBillsCode.Value = '' then
  781. EditCustomStepOldValue(cdsCustomStepViewBillsCode.Value, dCustomValue)
  782. else
  783. EditCustomStepOldValue(cdsCustomStepViewCustomBillsCode.Value, dCustomValue);
  784. end
  785. else
  786. begin
  787. ADisName := '';
  788. ACode := '';
  789. AUnits := '';
  790. end;
  791. Result := cdsCustomStepViewIsCode.Value;
  792. end;
  793. procedure TDMStdBillsLib.RecodeCurBills(aCustomValue: Double; const ACode, ADisName, AUnits: string;
  794. AIsCode, AIncrease: Boolean);
  795. begin
  796. if (ACode = '') and (ADisName = '') then Exit;
  797. with FBillsData do
  798. begin
  799. if not AIncrease then
  800. cdsOrgBills.Edit;
  801. if AIsCode then
  802. cdsOrgBillsCode.Value := ACode
  803. else
  804. cdsOrgBillsB_Code.Value := ACode;
  805. cdsOrgBillsName.Value := ADisName;
  806. cdsOrgBillsUnits.Value := AUnits;
  807. cdsOrgBillsCustomValue.Value := aCustomValue;
  808. if not AIncrease then
  809. cdsOrgBills.Post
  810. else
  811. begin
  812. cdsOrgBillsCode.Tag := 0;
  813. cdsOrgBillsB_Code.Tag := 0;
  814. end;
  815. end;
  816. end;
  817. procedure TDMStdBillsLib.cdsCustomStepViewCustomValueChange(
  818. Sender: TField);
  819. begin
  820. Sender.Tag := 1;
  821. end;
  822. procedure TDMStdBillsLib.RefreshCustomStep;
  823. var
  824. iID, iParentID: Integer;
  825. strCode, strOldCode: string;
  826. begin
  827. if not cdsCustomStep.Active then Exit;
  828. FBillsData := FProjectMgr.ActiveProject.BillsData;
  829. cdsCustomStepView.EmptyDataSet;
  830. with FBillsData do
  831. begin
  832. iID := cdsOrgBillsID.AsInteger;
  833. iParentID := cdsOrgBillsParentID.AsInteger;
  834. if iParentID <> -1 then
  835. begin
  836. if cdsBills.FindKey([iParentID]) then
  837. begin
  838. strCode := cdsBillsCode.AsString;
  839. if strCode = '' then
  840. strCode := cdsBillsB_Code.AsString;
  841. end
  842. else strCode := '';
  843. //while strCode <> '' do
  844. if strCode <> '' then
  845. begin
  846. if LocateCustomStepByCode(iID, strCode, '') then Exit;
  847. strOldCode := strCode;
  848. strCode := GetPreCode(strCode);
  849. strCode := Format('%s-X', [strCode]);
  850. {search -X}
  851. LocateCustomStepByCode(iID, strCode, strOldCode);
  852. end;
  853. end;
  854. end;
  855. end;
  856. function TDMStdBillsLib.FindLibCode(const ACode: string; var AName,
  857. AUnits: string; AIsCode: Boolean): Boolean;
  858. begin
  859. Result := False;
  860. if not FActive then Exit;
  861. AName := '';
  862. AUnits := '';
  863. if AIsCode then
  864. begin
  865. if cdsBillsLib.Locate(sCode, ACode, []) then
  866. Result := True;
  867. end
  868. else
  869. begin
  870. if cdsBillsLib.Locate(sB_Code, ACode, []) then
  871. Result := True;
  872. end;
  873. if Result then
  874. begin
  875. AName := cdsBillsLibName.Value;
  876. AUnits := cdsBillsLibUnit.Value;
  877. end;
  878. end;
  879. procedure TDMStdBillsLib.AutoIncreaseBillsCode;
  880. var
  881. bIsCode: Boolean;
  882. strCode, strDisName, strUnits: string;
  883. dCustomValue: Double;
  884. begin
  885. if not Assigned(FProjectMgr.ActiveProject) then Exit;
  886. if cdsCustomStepView.RecordCount = 0 then Exit;
  887. FBillsData := FProjectMgr.ActiveProject.BillsData;
  888. bIsCode := CalculateCode(dCustomValue, strCode, strDisName, strUnits, True);
  889. RecodeCurBills(dCustomValue, strCode, strDisName, strUnits, bIsCode, True);
  890. end;
  891. procedure TDMStdBillsLib.cdsCustomStepViewAfterPost(DataSet: TDataSet);
  892. var
  893. bIsCode: Boolean;
  894. strCode, strDisName, strUnits: string;
  895. dCustomValue: Double;
  896. begin
  897. if FCustomStepFlag then Exit;
  898. if cdsCustomStepViewCustomValue.Tag = 1 then
  899. begin
  900. FBillsData := FProjectMgr.ActiveProject.BillsData;
  901. bIsCode := CalculateCode(dCustomValue, strCode, strDisName, strUnits);
  902. RecodeCurBills(dCustomValue, strCode, strDisName, strUnits, bIsCode, False);
  903. cdsCustomStepViewCustomValue.Tag := 0;
  904. end;
  905. end;
  906. procedure TDMStdBillsLib.EditCustomStepOldValue(const ACode: string; const Value: Double);
  907. begin
  908. if cdsCustomStep.Locate(sBillsCode, ACode, []) then
  909. begin
  910. cdsCustomStep.Edit;
  911. cdsCustomStepOldValue.Value := Value;
  912. cdsCustomStep.Post;
  913. end;
  914. end;
  915. procedure TDMStdBillsLib.EditCustomStepViewOldValue(const Value: Double);
  916. begin
  917. FCustomStepFlag := True;
  918. cdsCustomStepView.Edit;
  919. cdsCustomStepViewOldValue.Value := Value;
  920. cdsCustomStepView.Post;
  921. FCustomStepFlag := False;
  922. end;
  923. procedure TDMStdBillsLib.cdsCustomStepViewBeforeInsert(DataSet: TDataSet);
  924. begin
  925. if not FCustomStepFlag then raise Exception.Create('不能添加记录!');
  926. end;
  927. procedure TDMStdBillsLib.cdsCustomStepViewBeforeDelete(DataSet: TDataSet);
  928. begin
  929. if not FCustomStepFlag then raise Exception.Create('不能删除记录!');
  930. end;
  931. procedure TDMStdBillsLib.cdsBillsLibViewBeforeInsert(DataSet: TDataSet);
  932. begin
  933. raise Exception.Create('不能添加记录!');
  934. end;
  935. procedure TDMStdBillsLib.cdsBillsLibAfterClose(DataSet: TDataSet);
  936. begin
  937. FStdBillsTree.DataSet := nil;
  938. end;
  939. function TDMStdBillsLib.LocateCustomStepByCode(aID: Integer; const ACode, AOldCode: string): Boolean;
  940. begin
  941. if cdsCustomStep.Locate(sBillsCode, ACode, []) then
  942. begin
  943. FCustomStepFlag := True;
  944. cdsCustomStepView.Append;
  945. if AOldCode = '' then
  946. begin
  947. cdsCustomStepViewBillsCode.Value := cdsCustomStepBillsCode.Value;
  948. cdsCustomStepViewCustomBillsCode.Value := AOldCode;
  949. end
  950. else
  951. begin
  952. cdsCustomStepViewBillsCode.Value := AOldCode;
  953. cdsCustomStepViewCustomBillsCode.Value := ACode;
  954. end;
  955. cdsCustomStepViewFmtName.Value := cdsCustomStepFmtName.AsString;
  956. cdsCustomStepViewFmtName2.Value := cdsCustomStepFmtName2.AsString;
  957. cdsCustomStepViewStartValue.Value := cdsCustomStepStartValue.Value;
  958. cdsCustomStepViewStepValue.Value := cdsCustomStepStepValue.Value;
  959. cdsCustomStepViewDisName.Value := cdsCustomStepDisName.AsString;
  960. cdsCustomStepViewUnits.Value := cdsCustomStepUnits.AsString;
  961. cdsCustomStepViewStartCodeID.Value := cdsCustomStepStartCodeID.Value;
  962. cdsCustomStepViewSubArea.Value := cdsCustomStepSubArea.Value;
  963. if (cdsCustomStepOldValue.Value <> 0) and (not FAdding) then
  964. cdsCustomStepViewOldValue.Value := cdsCustomStepOldValue.Value
  965. else
  966. cdsCustomStepViewOldValue.Value := cdsCustomStepStartValue.Value;
  967. if FBillsData.cdsBills.FindKey([aID]) then
  968. begin
  969. if FBillsData.cdsBillsCustomValue.AsFloat <> 0 then
  970. cdsCustomStepViewCustomValue.Value := FBillsData.cdsBillsCustomValue.AsFloat
  971. else
  972. begin
  973. cdsCustomStepViewCustomValue.Value := cdsCustomStepViewOldValue.AsFloat;
  974. FBillsData.cdsBills.Edit;
  975. FBillsData.cdsBillsCustomValue.Value := cdsCustomStepViewOldValue.AsFloat;
  976. FBillsData.cdsBills.Post;
  977. end;
  978. end;
  979. cdsCustomStepView.Post;
  980. FCustomStepFlag := False;
  981. Result := True;
  982. end
  983. else Result := False;
  984. end;
  985. procedure TDMStdBillsLib.cdsBillsQtyAfterOpen(DataSet: TDataSet);
  986. begin
  987. cdsBillsQtyView.CloneCursor(cdsBillsQty, True);
  988. FBillsQtyTree.DataSet := cdsBillsQtyView;
  989. FBillsQtyTree.Selected.Expand;
  990. cdsBQFastSearch.CloneCursor(cdsBillsQty, True);
  991. cdsBQFastSearch.IndexFieldNames := 'B_Code';
  992. cdsBQFastSearch.Filter := 'B_Code is not null';
  993. cdsBQFastSearch.Filtered := True;
  994. end;
  995. procedure TDMStdBillsLib.LoadBillsQtyLib(const ALibName: string);
  996. begin
  997. cdsBillsQtyView.DisableControls;
  998. try
  999. acnBillsQty.Connected := False;
  1000. acnBillsQty.ConnectionString := Format(SAdoConnectStr, [ALibName, 'Admin', '']);
  1001. acnBillsQty.Connected := True;
  1002. IncProgressUI(20);
  1003. {refresh billsQty}
  1004. cdsBillsQty.Close;
  1005. cdsBillsQty.Open;
  1006. IncProgressUI(40);
  1007. cdsBQDrawingQty.Close;
  1008. cdsBQDrawingQty.Open;
  1009. cdsBQDrawingQty.IndexFieldNames := 'ID';
  1010. IncProgressUI(40);
  1011. finally
  1012. cdsBillsQtyView.EnableControls;
  1013. end;
  1014. end;
  1015. procedure TDMStdBillsLib.AddBillsQtyItem;
  1016. var
  1017. selNode: TScBillsItem;
  1018. begin
  1019. if not Assigned(FProjectMgr.ActiveProject) then Exit;
  1020. FBillsData := FProjectMgr.ActiveProject.BillsData;
  1021. selNode := TScBillsItem(FBillsData.BillsTree.Selected);
  1022. if not CanAddQtyItem(selNode) or not Assigned(selNode) then Exit;
  1023. FMaxBillsID := FBillsData.GetMaxBillsID;
  1024. Initialize(2, False);
  1025. try
  1026. selNode := AddNewQtyItems(selNode, TStdBillNode(FBillsQtyTree.Selected));
  1027. if Assigned(selNode) then
  1028. selNode.LocateDBRecord;
  1029. finally
  1030. Finalize(2, False);
  1031. end;
  1032. end;
  1033. function TDMStdBillsLib.AddBillsQtyItems(aSelList: TIntegerSList): Boolean;
  1034. var
  1035. I: Integer;
  1036. sbnNode: TStdBillNode;
  1037. sbiNewNode: TScBillsItem;
  1038. selNode: TScBillsItem;
  1039. begin
  1040. Result := False;
  1041. if not Assigned(FProjectMgr.ActiveProject) then Exit;
  1042. if not cdsBillsQty.Active then Exit;
  1043. FBillsData := FProjectMgr.ActiveProject.BillsData;
  1044. selNode := TScBillsItem(FBillsData.BillsTree.Selected);
  1045. if not CanAddQtyItem(selNode) or not Assigned(selNode) then Exit;
  1046. FMaxBillsID := FBillsData.GetMaxBillsID;
  1047. Initialize(2, True);
  1048. try
  1049. sbiNewNode := nil;
  1050. for I := 0 to FBillsQtyTree.Count - 1 do
  1051. begin
  1052. if aSelList[I] <> 0 then
  1053. begin
  1054. sbnNode := TStdBillNode(FBillsQtyTree.Items[I]);
  1055. if sbnNode.Code = '' then
  1056. sbiNewNode := AddNewQtyItems(selNode, sbnNode);
  1057. end;
  1058. end;
  1059. Result := True;
  1060. if Assigned(sbiNewNode) then
  1061. sbiNewNode.LocateDBRecord;
  1062. finally
  1063. Finalize(2, True);
  1064. end;
  1065. end;
  1066. function TDMStdBillsLib.CanAddQtyItem(var aNode: TScBillsItem): Boolean;
  1067. begin
  1068. if ((aNode.SBillCode <> '')
  1069. and
  1070. aNode.HasChildren
  1071. and
  1072. (TScBillsItem(aNode.FirstChild).SBillCode <> ''))
  1073. or
  1074. not aNode.IsInheritFrom(1)
  1075. then
  1076. Result := False
  1077. else
  1078. begin
  1079. Result := True;
  1080. while aNode.SBillCode = '' do
  1081. aNode := TScBillsItem(aNode.Parent);
  1082. end;
  1083. end;
  1084. function TDMStdBillsLib.AddNewQtyItems(aNode: TScBillsItem;
  1085. aQtyNode: TStdBillNode): TScBillsItem;
  1086. var
  1087. I: Integer;
  1088. iNextID: Integer;
  1089. iCompareValue: Integer;
  1090. bFlag: Boolean;
  1091. sbnParent: TStdBillNode;
  1092. sbiNewItem, sbiChildItem: TScBillsItem;
  1093. begin
  1094. sbiNewItem := aNode;
  1095. sbnParent := TStdBillNode(aQtyNode.Parent);
  1096. if sbnParent.BCode <> '' then
  1097. sbiNewItem := AddNewQtyItems(sbiNewItem, sbnParent);
  1098. bFlag := True;
  1099. iNextID := -1;
  1100. FStdBillNode := aQtyNode;
  1101. for I := 0 to sbiNewItem.ChildCount - 1 do
  1102. begin
  1103. sbiChildItem := TScBillsItem(sbiNewItem.ChildNodes[I]);
  1104. if Pos(aQtyNode.BCode + '-', sbiChildItem.SBillBCode) = 1 then
  1105. begin
  1106. Result := sbiNewItem;
  1107. bFlag := False;
  1108. Break;
  1109. end;
  1110. iCompareValue := CompareDiagitCode(sbiChildItem.SBillBCode, aQtyNode.BCode);
  1111. if iCompareValue = 0 then
  1112. begin
  1113. Result := sbiChildItem;
  1114. bFlag := False;
  1115. Break;;
  1116. end
  1117. else if iCompareValue > 0 then
  1118. begin
  1119. iNextID := sbiChildItem.ID;
  1120. Break;
  1121. end;
  1122. end;
  1123. if bFlag then
  1124. begin
  1125. Result := FBillsData.BillsTree.AddBillsItem(FMaxBillsID, sbiNewItem.ID, iNextID);
  1126. Result.SBillBCode := aQtyNode.BCode;
  1127. Result.SBillName := aQtyNode.Name;
  1128. AddQtyRelaDrawQ(FMaxBillsID, aQtyNode.ID);
  1129. Inc(FMaxBillsID);
  1130. end;
  1131. end;
  1132. function TDMStdBillsLib.CompareDiagitCode(AsCode, ACode: string): Integer;
  1133. var
  1134. s1, s2: string;
  1135. p1, p2: Integer;
  1136. v1, v2, e1, e2: Integer;
  1137. begin
  1138. p1 := pos('-', AsCode);
  1139. p2 := pos('-', ACode);
  1140. while (p1 <> 0) and (p2 <> 0) do
  1141. begin
  1142. s1 := copy(AsCode, 1, p1 - 1);
  1143. s2 := copy(ACode, 1, p2 - 1);
  1144. if SameText(s1, s2) then
  1145. begin
  1146. AsCode := copy(AsCode, p1 + 1, Length(AsCode));
  1147. ACode := copy(ACode, p2 + 1, Length(ACode));
  1148. p1 := pos('-', AsCode);
  1149. p2 := pos('-', ACode);
  1150. end
  1151. else
  1152. begin
  1153. Val(s1, v1, e1);
  1154. Val(s2, v2, e2);
  1155. if (e1 = 0) and (e2 = 0) then
  1156. Result := v1 - v2
  1157. else Result := CompareText(s1, s2);
  1158. Exit;
  1159. end;
  1160. end;
  1161. if (p1 = 0) and (p2 = 0) then
  1162. begin
  1163. Val(AsCode, v1, e1);
  1164. Val(ACode, v2, e2);
  1165. if (e1 = 0) and (e2 = 0) then
  1166. Result := v1 - v2
  1167. else Result := CompareText(AsCode, ACode);
  1168. end
  1169. else if p1 <> 0 then
  1170. begin
  1171. s1 := copy(AsCode, 1, p1 - 1);
  1172. Val(s1, v1, e1);
  1173. Val(ACode, v2, e2);
  1174. if (e1 = 0) and (e2 = 0) then
  1175. begin
  1176. Result := v1 - v2;
  1177. if Result = 0 then
  1178. Result := Length(AsCode) - Length(ACode);
  1179. end
  1180. else Result := CompareText(s1, ACode);
  1181. end
  1182. else
  1183. begin
  1184. s2 := copy(ACode, 1, p2 - 1);
  1185. Val(AsCode, v1, e1);
  1186. Val(s2, v2, e2);
  1187. if (e1 = 0) and (e2 = 0) then
  1188. begin
  1189. Result := v1 - v2;
  1190. if Result = 0 then
  1191. Result := Length(AsCode) - Length(ACode);
  1192. end
  1193. else Result := CompareText(AsCode, s2);
  1194. end;
  1195. end;
  1196. procedure TDMStdBillsLib.CloseLib(aFileFlag: Integer);
  1197. begin
  1198. if aFileFlag = 1 then
  1199. begin
  1200. acnBillsLib.Close;
  1201. cdsBillsLib.Active := False;
  1202. end
  1203. else
  1204. begin
  1205. acnBillsQty.Close;
  1206. cdsBillsQty.Active := False;
  1207. end;
  1208. end;
  1209. function TDMStdBillsLib.FindRecord(aNode: TZjIDTreeNode; const aCode, aName: string): Boolean;
  1210. begin
  1211. Result := False;
  1212. if aNode = nil then Exit;
  1213. if (aCode <> '') and (aName <> '') then
  1214. begin
  1215. if ((Pos(aCode, TStdBillNode(aNode).Code) = 1)
  1216. or
  1217. (Pos(aCode, TStdBillNode(aNode).BCode) = 1))
  1218. and
  1219. (Pos(aName, TStdBillNode(aNode).Name) <> 0)
  1220. then
  1221. Result := True;
  1222. end
  1223. else if (aCode <> '') and (aName = '') then
  1224. begin
  1225. if (Pos(aCode, TStdBillNode(aNode).Code) = 1)
  1226. or
  1227. (Pos(aCode, TStdBillNode(aNode).BCode) = 1)
  1228. then
  1229. Result := True;
  1230. end
  1231. else if (aCode = '') and (aName <> '') then
  1232. begin
  1233. if Pos(aName, TStdBillNode(aNode).Name) <> 0 then
  1234. Result := True;
  1235. end
  1236. else
  1237. Exit;
  1238. if Result then
  1239. begin
  1240. aNode.LocateDBRecord;
  1241. Exit;
  1242. end;
  1243. Result := FindRecord(aNode.NextNode, aCode, aName);
  1244. end;
  1245. procedure TDMStdBillsLib.LoadCustomStep(const aLibName: string);
  1246. begin
  1247. cdsCustomStepView.DisableControls;
  1248. try
  1249. acCustomStep.Connected := False;
  1250. acCustomStep.ConnectionString := Format(SAdoConnectStr, [ALibName, 'Admin', '']);
  1251. acCustomStep.Connected := True;
  1252. {refresh billsQty}
  1253. cdsCustomStep.Close;
  1254. cdsCustomStep.Open;
  1255. finally
  1256. cdsCustomStepView.EnableControls;
  1257. end;
  1258. end;
  1259. procedure TDMStdBillsLib.cdsBQDrawingQtyAfterOpen(DataSet: TDataSet);
  1260. begin
  1261. //cdsBQDrawingQty.IndexFieldNames := sBillsID;
  1262. cdsBQDrawingQtyView.CloneCursor(cdsBQDrawingQty, True);
  1263. cdsBQDrawingQtyView.MasterSource := dsBillsQty;
  1264. cdsBQDrawingQtyView.MasterFields := SID;
  1265. cdsBQDrawingQtyView.IndexFieldNames := sBillsID;
  1266. end;
  1267. procedure TDMStdBillsLib.AddQtyRelaDrawQ(ADestID, ASrcID: Integer);
  1268. var
  1269. iMaxDQID, iSerinalNo: Integer;
  1270. begin
  1271. iSerinalNo := 1;
  1272. iMaxDQID := FBillsData.GetMaxDrawingQuangtiyID;
  1273. cdsBQDrawingQty.Filter := Format('BillsID = %d', [ASrcID]);
  1274. cdsBQDrawingQty.Filtered := True;
  1275. while not cdsBQDrawingQty.Eof do
  1276. begin
  1277. FBillsData.cdsDrawingQuantity.Insert;
  1278. FBillsData.cdsDrawingQuantityID.Value := iMaxDQID;
  1279. FBillsData.cdsDrawingQuantitySerinalNo.Value := iSerinalNo;
  1280. FBillsData.cdsDrawingQuantityBillsID.Value := ADestID;
  1281. FBillsData.cdsDrawingQuantityName.Value := cdsBQDrawingQtyName.Value;
  1282. FBillsData.cdsDrawingQuantityUnits.Value := cdsBQDrawingQtyUnits.Value;
  1283. FBillsData.cdsDrawingQuantityDQuantity1.Value := cdsBQDrawingQtyDesignQuantity.Value;
  1284. FBillsData.cdsDrawingQuantityMemoContext.Value := cdsBQDrawingQtyMemoStr.Value;
  1285. FBillsData.cdsDrawingQuantity.Post;
  1286. Inc(iMaxDQID);
  1287. Inc(iSerinalNo);
  1288. cdsBQDrawingQty.Next;
  1289. end;
  1290. cdsBQDrawingQty.Filtered := False;
  1291. end;
  1292. function TDMStdBillsLib.IsCodeStepItem(AB_Code: string;
  1293. var AUnits: string): Boolean;
  1294. begin
  1295. Result := False;
  1296. cdsCustomStep.First;
  1297. while not cdsCustomStep.Eof do
  1298. begin
  1299. if Pos(cdsCustomStepBillsCode.AsString, AB_Code) = 1 then
  1300. begin
  1301. AUnits := cdsCustomStepUnits.AsString;
  1302. Result := True;
  1303. Break;
  1304. end;
  1305. cdsCustomStep.Next;
  1306. end;
  1307. end;
  1308. // Added by GiLi 2012-3-20 14:48:28
  1309. // 反向定位标准清单
  1310. procedure TDMStdBillsLib.LocateCurBillsToStdBills;
  1311. var
  1312. AID, AStdID, AStdParentID, vNodeLevel, PrevLevel: Integer;
  1313. ACode, ABillsCode: string;
  1314. vNode, vTempNode: TScBillsItem;
  1315. vStdNode, vTmpStdNode: TZjIDTreeNode;
  1316. // 递归查找该项目节编号下的清单编号的节点(定位条件 项目节编号、清单编号)
  1317. function FindNodeByBCode(ANode: TZjIDTreeNode): TZjIDTreeNode;
  1318. var
  1319. ACurStdBCode: string;
  1320. begin
  1321. Result := nil;
  1322. if ANode = nil then
  1323. Exit;
  1324. ACurStdBCode := TStdBillNode(ANode).BCode;
  1325. if SameText(Trim(ABillsCode), ACurStdBCode) then
  1326. begin
  1327. Result := ANode;
  1328. Exit;
  1329. end;
  1330. if Result = nil then
  1331. Result := FindNodeByBCode(ANode.FirstChild);
  1332. if Result = nil then
  1333. Result := FindNodeByBCode(ANode.NextSibling);
  1334. end;
  1335. begin
  1336. if not Assigned(FProjectMgr.ActiveProject) then Exit;
  1337. if not cdsBillsLibView.Active then Exit;
  1338. if not FBillsData.cdsOrgBills.Active then
  1339. begin
  1340. raise Exception.Create('标准清单未打开,无法定位!');
  1341. Exit;
  1342. end;
  1343. FBillsData := FProjectMgr.ActiveProject.BillsData;
  1344. ACode := FBillsData.cdsOrgBillsCode.AsString;
  1345. ABillsCode := FBillsData.cdsOrgBillsB_Code.AsString;
  1346. AID := FBillsData.cdsOrgBillsID.AsInteger;
  1347. AStdParentID := FBillsData.cdsOrgBillsParentID.AsInteger;
  1348. vNodeLevel := 0;
  1349. PrevLevel := 0;
  1350. // 如果清单编号不为空,那么直接查找编号,找不到给出提示
  1351. if Trim(ACode) <> '' then
  1352. begin
  1353. if not cdsBillsLibView.Locate('Code', ACode, []) then
  1354. begin
  1355. if mrYes <> MessageQuest(0, '标准清单中不存在编号为' + ACode + '的项!' + #13#10 + '您是否要进行模糊定位? Y/N', '询问', MB_YESNO) then
  1356. Exit;
  1357. vNode := FBillsData.BillsTree.FindNode(AID);
  1358. while (not cdsBillsLibView.Locate('Code', ACode, []))
  1359. and (vNode <> nil)
  1360. do
  1361. begin
  1362. vNode := TScBillsItem(vNode.Parent);
  1363. ACode := vNode.Code;
  1364. end;
  1365. if vNode = nil then
  1366. begin
  1367. cdsBillsLibView.First;
  1368. end;
  1369. end;
  1370. Exit;
  1371. end;
  1372. // 如果当前项的编号是空,那么找当前节点下的妈妈,取妈妈的Code
  1373. if Trim(ACode) = '' then
  1374. begin
  1375. vNode := FBillsData.BillsTree.FindNode(AID);
  1376. vTempNode := vNode;
  1377. // 求同层下,排第几个
  1378. while vTempNode <> nil do
  1379. begin
  1380. Inc(PrevLevel);
  1381. vTempNode := TScBillsItem(vTempNode.PrevSibling);
  1382. end;
  1383. // 找妈妈,并记录层数
  1384. while (vNode <> nil) and (Trim(ACode) = '') do
  1385. begin
  1386. ACode := vNode.Code;
  1387. // 记录层数
  1388. Inc(vNodeLevel);
  1389. vNode := TScBillsItem(vNode.Parent);
  1390. end;
  1391. end;
  1392. if Trim(ACode) = '' then
  1393. begin
  1394. MessageHint(0, '标准清单中不存在该项!', '提示', 0);
  1395. Exit;
  1396. end;
  1397. // 先定位到有项目节编号的标准清单项的妈妈下
  1398. if not cdsBillsLibView.Locate('Code', ACode, []) then
  1399. begin
  1400. MessageHint(0, '标准清单中不存在该项!', '提示', 0);
  1401. Exit;
  1402. end;
  1403. AStdID := cdsBillsLibViewID.AsInteger;
  1404. vStdNode := FStdBillsTree.FindNode(AStdID);
  1405. vTmpStdNode := vStdNode; // 递归之前记录位置
  1406. if Assigned(vStdNode) then
  1407. vStdNode := FindNodeByBCode(vStdNode.FirstChild);
  1408. if Assigned(vStdNode) then
  1409. begin
  1410. vStdNode.LocateDBRecord;
  1411. Exit;
  1412. end
  1413. else
  1414. begin
  1415. if mrYes <> MessageQuest(0, '标准清单中不存在该项!' + #13#10 + '您是否要进行模糊定位? Y/N', '询问', MB_YESNO) then
  1416. Exit;
  1417. end;
  1418. vStdNode := vTmpStdNode;
  1419. // 找到层
  1420. while vNodeLevel > 1 do
  1421. begin
  1422. if not Assigned(vStdNode) then
  1423. begin
  1424. MessageHint(0, '标准清单中不存在该项的相似清单!', '提示', 0);
  1425. Exit;
  1426. end;
  1427. vStdNode := vStdNode.FirstChild;
  1428. Dec(vNodeLevel);
  1429. end;
  1430. // 确定层下的位置
  1431. while PrevLevel > 1 do
  1432. begin
  1433. if not Assigned(vStdNode.NextSibling) then
  1434. begin
  1435. vStdNode.LocateDBRecord;
  1436. //MessageHint(0, '标准清单中不存在该项!', '提示', 0);
  1437. Exit;
  1438. end;
  1439. vStdNode := vStdNode.NextSibling;
  1440. Dec(PrevLevel);
  1441. end;
  1442. if Assigned(vStdNode) then
  1443. vStdNode.LocateDBRecord;
  1444. //else
  1445. // MessageHint(0, '标准清单中不存在该项!', '提示', 0);
  1446. {
  1447. AID := FBillsData.cdsOrgBillsID.AsInteger;
  1448. vNode := FStdBillsTree.FindNode(AID);
  1449. if Assigned(vNode) then
  1450. begin
  1451. vNode.LocateDBRecord;
  1452. end;
  1453. }
  1454. end;
  1455. procedure TDMStdBillsLib.CloneActive(IsActive: Boolean);
  1456. begin
  1457. if Assigned(FCdsStaticID) and Assigned(FCdsModifyBills) then
  1458. begin
  1459. FCdsStaticID.Active := IsActive;
  1460. FCdsModifyBills.Active := IsActive;
  1461. end;
  1462. end;
  1463. procedure TDMStdBillsLib.Save;
  1464. begin
  1465. if acnBillsLib.Connected then
  1466. begin
  1467. cdsBillsLib.ApplyUpdates(0);
  1468. cdsDrawingQuantity.ApplyUpdates(0);
  1469. end;
  1470. if acnBillsQty.Connected then
  1471. begin
  1472. cdsBillsQty.ApplyUpdates(0);
  1473. cdsBQDrawingQty.ApplyUpdates(0);
  1474. end;
  1475. end;
  1476. procedure TDMStdBillsLib.cdsBillsLibViewAfterPost(DataSet: TDataSet);
  1477. var
  1478. Node: TStdBillNode;
  1479. begin
  1480. if (cdsBillsLibViewCode.Tag = 1) or (cdsBillsLibViewB_Code.Tag = 1) or
  1481. (cdsBillsLibViewName.Tag = 1) or (cdsBillsLibViewUnit.Tag = 1) then
  1482. begin
  1483. Node := TStdBillNode(FStdBillsTree.FindNode(cdsBillsLibViewID.AsInteger));
  1484. Node.Code := cdsBillsLibViewCode.AsString;
  1485. Node.BCode := cdsBillsLibViewB_Code.AsString;
  1486. Node.Name := cdsBillsLibViewName.AsString;
  1487. Node.Units := cdsBillsLibViewUnit.AsString;
  1488. if cdsBillsLibViewStaticID.IsNull then
  1489. Node.StaticID := -1
  1490. else
  1491. Node.StaticID := cdsBillsLibViewStaticID.AsInteger;
  1492. end;
  1493. cdsBillsLibViewCode.Tag := 0;
  1494. cdsBillsLibViewB_Code.Tag := 0;
  1495. cdsBillsLibViewName.Tag := 0;
  1496. cdsBillsLibViewUnit.Tag := 0;
  1497. end;
  1498. procedure TDMStdBillsLib.cdsBillsLibViewCodeChange(Sender: TField);
  1499. begin
  1500. Sender.Tag := 1;
  1501. end;
  1502. procedure TDMStdBillsLib.cdsBillsLibViewAfterInsert(DataSet: TDataSet);
  1503. var
  1504. Node: TStdBillNode;
  1505. begin
  1506. Node := TStdBillNode(FStdBillsTree.FindNode(cdsBillsQtyViewID.AsInteger));
  1507. if cdsBillsLibViewStaticID.IsNull then
  1508. Node.StaticID := -1
  1509. else
  1510. Node.StaticID := cdsBillsLibViewStaticID.AsInteger;
  1511. end;
  1512. procedure TDMStdBillsLib.cdsBillsQtyViewAfterPost(DataSet: TDataSet);
  1513. var
  1514. Node: TStdBillNode;
  1515. begin
  1516. if (cdsBillsQtyViewCode.Tag = 1) or (cdsBillsQtyViewB_Code.Tag = 1) or
  1517. (cdsBillsQtyViewName.Tag = 1) or (cdsBillsQtyViewUnit.Tag = 1) then
  1518. begin
  1519. Node := TStdBillNode(FBillsQtyTree.FindNode(cdsBillsQtyViewID.AsInteger));
  1520. Node.Code := cdsBillsQtyViewCode.AsString;
  1521. Node.BCode := cdsBillsQtyViewB_Code.AsString;
  1522. Node.Name := cdsBillsQtyViewName.AsString;
  1523. Node.Units := cdsBillsQtyViewUnit.AsString;
  1524. if cdsBillsQtyViewStaticID.IsNull then
  1525. Node.StaticID := -1
  1526. else
  1527. Node.StaticID := cdsBillsQtyViewStaticID.AsInteger;
  1528. end;
  1529. cdsBillsQtyViewCode.Tag := 0;
  1530. cdsBillsQtyViewB_Code.Tag := 0;
  1531. cdsBillsQtyViewName.Tag := 0;
  1532. cdsBillsQtyViewUnit.Tag := 0;
  1533. end;
  1534. procedure TDMStdBillsLib.cdsBillsQtyViewAfterInsert(DataSet: TDataSet);
  1535. var
  1536. Node: TStdBillNode;
  1537. begin
  1538. Node := TStdBillNode(FBillsQtyTree.FindNode(cdsBillsQtyViewID.AsInteger));
  1539. if cdsBillsQtyViewStaticID.IsNull then
  1540. Node.StaticID := -1
  1541. else
  1542. Node.StaticID := cdsBillsQtyViewStaticID.AsInteger;
  1543. end;
  1544. function TDMStdBillsLib.GetNewID(DataSet: TClientDataSet): Integer;
  1545. begin
  1546. DataSet.Last;
  1547. Result := DataSet.FieldByName('ID').AsInteger + 1;
  1548. end;
  1549. procedure TDMStdBillsLib.cdsDrawQViewNewRecord(DataSet: TDataSet);
  1550. begin
  1551. cdsDrawQViewID.AsInteger := GetNewID(cdsDrawingQuantity);
  1552. end;
  1553. procedure TDMStdBillsLib.cdsBQDrawingQtyViewNewRecord(DataSet: TDataSet);
  1554. begin
  1555. cdsBQDrawingQtyViewID.AsInteger := GetNewID(cdsBQDrawingQty);
  1556. end;
  1557. end.