ScExprsDM.pas 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. unit ScExprsDM;
  2. interface
  3. uses
  4. SysUtils, Classes, DBClient, Provider, DB, ADODB;
  5. type
  6. TDMExprs = class(TDataModule)
  7. atExprs: TADOTable;
  8. dspExprs: TDataSetProvider;
  9. cdsOrgExprs: TClientDataSet;
  10. cdsOrgExprsMajorID: TIntegerField;
  11. cdsOrgExprsMinorID: TIntegerField;
  12. cdsOrgExprsRecdID: TIntegerField;
  13. cdsOrgExprsExprs: TWideStringField;
  14. cdsOrgExprsFlag: TIntegerField;
  15. cdsOrgExprsExprsValue: TFloatField;
  16. cdsOrgExprsExprs2: TWideStringField;
  17. cdsOrgExprsExprs3: TWideStringField;
  18. cdsOrgExprsExprs4: TWideStringField;
  19. cdsOrgExprsExprs1: TWideStringField;
  20. cdsExprs: TClientDataSet;
  21. cdsExprsMajorID: TIntegerField;
  22. cdsExprsMinorID: TIntegerField;
  23. cdsExprsRecdID: TIntegerField;
  24. cdsExprsExprs: TWideStringField;
  25. cdsExprsFlag: TIntegerField;
  26. cdsExprsExprsValue: TFloatField;
  27. cdsExprsExprs1: TWideStringField;
  28. cdsExprsExprs2: TWideStringField;
  29. cdsExprsExprs3: TWideStringField;
  30. cdsExprsExprs4: TWideStringField;
  31. procedure cdsOrgExprsAfterOpen(DataSet: TDataSet);
  32. private
  33. procedure UpdateOldData;
  34. function GetConnection: TADOConnection;
  35. procedure SetConnection(const Value: TADOConnection);
  36. public
  37. procedure Save;
  38. procedure AddExprs(MajorID, MinorID, RecdID: Integer;
  39. const Expression: string; Value: Variant; Flag: Integer; AIndex: Integer = 0);
  40. procedure Delete(MajorID, RecdID: Integer); overload;
  41. procedure Delete(MajorID, MinorID, RecdID: Integer); overload;
  42. function GetExprs(MajorID, MinorID, RecdID: Integer; AIndex: Integer = 0): string;
  43. property Connection: TADOConnection read GetConnection write SetConnection;
  44. end;
  45. implementation
  46. {$R *.dfm}
  47. uses ConstVarUnit, Math;
  48. { TDMExprs }
  49. procedure TDMExprs.AddExprs(MajorID, MinorID, RecdID: Integer;
  50. const Expression: string; Value: Variant; Flag, AIndex: Integer);
  51. begin
  52. if cdsExprs.FindKey([MajorID, MinorID, RecdID]) then
  53. cdsExprs.Edit
  54. else
  55. cdsExprs.Insert;
  56. cdsExprsMajorID.Value := MajorID;
  57. cdsExprsMinorID.Value := MinorID;
  58. cdsExprsRecdID.Value := RecdID;
  59. case AIndex of
  60. 0: cdsExprsExprs.Value := Expression;
  61. 1: cdsExprsExprs1.Value := Expression;
  62. 2: cdsExprsExprs2.Value := Expression;
  63. 3: cdsExprsExprs3.Value := Expression;
  64. 4: cdsExprsExprs4.Value := Expression;
  65. end;
  66. cdsExprsFlag.Value := Flag;
  67. cdsExprsExprsValue.Value := Value;
  68. cdsExprs.Post;
  69. end;
  70. procedure TDMExprs.Delete(MajorID, RecdID: Integer);
  71. begin
  72. cdsOrgExprs.SetRange([MajorID, RecdID], [MajorID, RecdID]);
  73. cdsOrgExprs.First;
  74. while not cdsOrgExprs.Eof do cdsOrgExprs.Delete;
  75. cdsOrgExprs.CancelRange;
  76. end;
  77. procedure TDMExprs.Delete(MajorID, MinorID, RecdID: Integer);
  78. begin
  79. if cdsExprs.FindKey([MajorID, MinorID, RecdID]) then
  80. cdsExprs.Delete;
  81. end;
  82. function TDMExprs.GetConnection: TADOConnection;
  83. begin
  84. Result := atExprs.Connection;
  85. end;
  86. function TDMExprs.GetExprs(MajorID, MinorID, RecdID,
  87. AIndex: Integer): string;
  88. begin
  89. if cdsExprs.FindKey([MajorID, MinorID, RecdID]) then
  90. begin
  91. case AIndex of
  92. 0: Result := cdsExprsExprs.Value;
  93. 1: Result := cdsExprsExprs1.Value;
  94. 2: Result := cdsExprsExprs2.Value;
  95. 3: Result := cdsExprsExprs3.Value;
  96. 4: Result := cdsExprsExprs4.Value;
  97. else Result := '';
  98. end;
  99. end;
  100. end;
  101. procedure TDMExprs.Save;
  102. begin
  103. cdsOrgExprs.ApplyUpdates(0);
  104. end;
  105. procedure TDMExprs.SetConnection(const Value: TADOConnection);
  106. begin
  107. atExprs.Connection := Value;
  108. if Assigned(Value) then
  109. begin
  110. cdsOrgExprs.Active := True;
  111. cdsOrgExprs.IndexFieldNames := SMajorRecdID;
  112. end;
  113. end;
  114. procedure TDMExprs.cdsOrgExprsAfterOpen(DataSet: TDataSet);
  115. begin
  116. cdsExprs.CloneCursor(cdsOrgExprs, True);
  117. cdsExprs.IndexFieldNames := SMajorMinorRecdID;
  118. UpdateOldData;
  119. end;
  120. procedure TDMExprs.UpdateOldData;
  121. begin
  122. cdsExprs.First;
  123. while not cdsExprs.Eof do
  124. begin
  125. if (cdsExprsMajorID.AsInteger = Exprs_Qty_ID) and (cdsExprsMinorID.AsInteger = Exprs_DQty_ID) then
  126. begin
  127. cdsExprs.Edit;
  128. cdsExprsMinorID.AsInteger := Exprs_DQty_ID;
  129. cdsExprs.Post;
  130. end;
  131. if (cdsExprsMajorID.AsInteger = Exprs_Qty_ID) and (cdsExprsMinorID.AsInteger = Exprs_DQty2_ID) then
  132. begin
  133. cdsExprs.Edit;
  134. cdsExprsMinorID.AsInteger := Exprs_DQty2_ID;
  135. cdsExprs.Post;
  136. end;
  137. end;
  138. end;
  139. end.