123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- unit ScExprsDM;
- interface
- uses
- SysUtils, Classes, DBClient, Provider, DB, ADODB;
- type
- TDMExprs = class(TDataModule)
- atExprs: TADOTable;
- dspExprs: TDataSetProvider;
- cdsOrgExprs: TClientDataSet;
- cdsOrgExprsMajorID: TIntegerField;
- cdsOrgExprsMinorID: TIntegerField;
- cdsOrgExprsRecdID: TIntegerField;
- cdsOrgExprsExprs: TWideStringField;
- cdsOrgExprsFlag: TIntegerField;
- cdsOrgExprsExprsValue: TFloatField;
- cdsOrgExprsExprs2: TWideStringField;
- cdsOrgExprsExprs3: TWideStringField;
- cdsOrgExprsExprs4: TWideStringField;
- cdsOrgExprsExprs1: TWideStringField;
- cdsExprs: TClientDataSet;
- cdsExprsMajorID: TIntegerField;
- cdsExprsMinorID: TIntegerField;
- cdsExprsRecdID: TIntegerField;
- cdsExprsExprs: TWideStringField;
- cdsExprsFlag: TIntegerField;
- cdsExprsExprsValue: TFloatField;
- cdsExprsExprs1: TWideStringField;
- cdsExprsExprs2: TWideStringField;
- cdsExprsExprs3: TWideStringField;
- cdsExprsExprs4: TWideStringField;
- procedure cdsOrgExprsAfterOpen(DataSet: TDataSet);
- private
- procedure UpdateOldData;
- function GetConnection: TADOConnection;
- procedure SetConnection(const Value: TADOConnection);
- public
- procedure Save;
- procedure AddExprs(MajorID, MinorID, RecdID: Integer;
- const Expression: string; Value: Variant; Flag: Integer; AIndex: Integer = 0);
- procedure Delete(MajorID, RecdID: Integer); overload;
- procedure Delete(MajorID, MinorID, RecdID: Integer); overload;
- function GetExprs(MajorID, MinorID, RecdID: Integer; AIndex: Integer = 0): string;
- property Connection: TADOConnection read GetConnection write SetConnection;
- end;
- implementation
- {$R *.dfm}
- uses ConstVarUnit, Math;
- { TDMExprs }
- procedure TDMExprs.AddExprs(MajorID, MinorID, RecdID: Integer;
- const Expression: string; Value: Variant; Flag, AIndex: Integer);
- begin
- if cdsExprs.FindKey([MajorID, MinorID, RecdID]) then
- cdsExprs.Edit
- else
- cdsExprs.Insert;
- cdsExprsMajorID.Value := MajorID;
- cdsExprsMinorID.Value := MinorID;
- cdsExprsRecdID.Value := RecdID;
- case AIndex of
- 0: cdsExprsExprs.Value := Expression;
- 1: cdsExprsExprs1.Value := Expression;
- 2: cdsExprsExprs2.Value := Expression;
- 3: cdsExprsExprs3.Value := Expression;
- 4: cdsExprsExprs4.Value := Expression;
- end;
- cdsExprsFlag.Value := Flag;
- cdsExprsExprsValue.Value := Value;
- cdsExprs.Post;
- end;
- procedure TDMExprs.Delete(MajorID, RecdID: Integer);
- begin
- cdsOrgExprs.SetRange([MajorID, RecdID], [MajorID, RecdID]);
- cdsOrgExprs.First;
- while not cdsOrgExprs.Eof do cdsOrgExprs.Delete;
- cdsOrgExprs.CancelRange;
- end;
- procedure TDMExprs.Delete(MajorID, MinorID, RecdID: Integer);
- begin
- if cdsExprs.FindKey([MajorID, MinorID, RecdID]) then
- cdsExprs.Delete;
- end;
- function TDMExprs.GetConnection: TADOConnection;
- begin
- Result := atExprs.Connection;
- end;
- function TDMExprs.GetExprs(MajorID, MinorID, RecdID,
- AIndex: Integer): string;
- begin
- if cdsExprs.FindKey([MajorID, MinorID, RecdID]) then
- begin
- case AIndex of
- 0: Result := cdsExprsExprs.Value;
- 1: Result := cdsExprsExprs1.Value;
- 2: Result := cdsExprsExprs2.Value;
- 3: Result := cdsExprsExprs3.Value;
- 4: Result := cdsExprsExprs4.Value;
- else Result := '';
- end;
- end;
- end;
- procedure TDMExprs.Save;
- begin
- cdsOrgExprs.ApplyUpdates(0);
- end;
- procedure TDMExprs.SetConnection(const Value: TADOConnection);
- begin
- atExprs.Connection := Value;
- if Assigned(Value) then
- begin
- cdsOrgExprs.Active := True;
- cdsOrgExprs.IndexFieldNames := SMajorRecdID;
- end;
- end;
- procedure TDMExprs.cdsOrgExprsAfterOpen(DataSet: TDataSet);
- begin
- cdsExprs.CloneCursor(cdsOrgExprs, True);
- cdsExprs.IndexFieldNames := SMajorMinorRecdID;
- UpdateOldData;
- end;
- procedure TDMExprs.UpdateOldData;
- begin
- cdsExprs.First;
- while not cdsExprs.Eof do
- begin
- if (cdsExprsMajorID.AsInteger = Exprs_Qty_ID) and (cdsExprsMinorID.AsInteger = Exprs_DQty_ID) then
- begin
- cdsExprs.Edit;
- cdsExprsMinorID.AsInteger := Exprs_DQty_ID;
- cdsExprs.Post;
- end;
- if (cdsExprsMajorID.AsInteger = Exprs_Qty_ID) and (cdsExprsMinorID.AsInteger = Exprs_DQty2_ID) then
- begin
- cdsExprs.Edit;
- cdsExprsMinorID.AsInteger := Exprs_DQty2_ID;
- cdsExprs.Post;
- end;
- end;
- end;
- end.
|