data.pas
上传用户:fh681027
上传日期:2022-07-23
资源大小:1959k
文件大小:2k
源码类别:

Delphi控件源码

开发平台:

Delphi

  1. unit data;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  5.   DBTables, Db;
  6. type
  7.   TdmData = class(TDataModule)
  8.     spDelEmployee: TStoredProc;
  9.     EmpDS: TDataSource;
  10.     EmpUpdate: TUpdateSQL;
  11.     qryEmployee: TQuery;
  12.     qryEmployeeEMP_NO: TSmallintField;
  13.     qryEmployeeFIRST_NAME: TStringField;
  14.     qryEmployeeLAST_NAME: TStringField;
  15.     qryEmployeeDEPARTMENT: TStringField;
  16.     qryEmployeeJOB_TITLE: TStringField;
  17.     qryEmployeeSALARY: TFloatField;
  18.     AppDB: TDatabase;
  19.     qryDepartment: TQuery;
  20.     DepDS: TDataSource;
  21.     qryEmployeeDEPT_NO: TStringField;
  22.     qryJob: TQuery;
  23.     JobDS: TDataSource;
  24.     qryEmployeeJOB_CODE: TStringField;
  25.     qryEmployeeJOB_GRADE: TSmallintField;
  26.     qryEmployeeJOB_COUNTRY: TStringField;
  27.     procedure qryEmployeeUpdateRecord(DataSet: TDataSet;
  28.       UpdateKind: TUpdateKind; var UpdateAction: TUpdateAction);
  29.     procedure EmpDSUpdateData(Sender: TObject);
  30.   private
  31.     { Private declarations }
  32.   public
  33.     { Public declarations }
  34.   end;
  35. var
  36.   dmData: TdmData;
  37. implementation
  38. uses main;
  39. {$R *.DFM}
  40. procedure TdmData.qryEmployeeUpdateRecord(DataSet: TDataSet;
  41.   UpdateKind: TUpdateKind; var UpdateAction: TUpdateAction);
  42. begin
  43.   // when deleting the record, use the Stored Procedure
  44.   if UpdateKind = ukDelete then
  45.   begin
  46.     // assign emp_no value
  47.     with dmData do
  48.       spDelEmployee.Params[0].Value := qryEmployeeEMP_NO.OldValue;
  49.     try
  50.       // invoke stored proc that tries to delete employee
  51.       dmData.spDelEmployee.ExecProc;
  52.       UpdateAction := uaApplied; // success
  53.     except
  54.       UpdateAction := uaFail;
  55.     end;
  56.   end
  57.   else
  58.   try
  59.     // apply updates
  60.     dmData.EmpUpdate.Apply(UpdateKind);
  61.     UpdateAction := uaApplied;
  62.   except
  63.     UpdateAction := uaFail;
  64.   end;
  65. end;
  66. procedure TdmData.EmpDSUpdateData(Sender: TObject);
  67. begin
  68.   MainForm.btnApply.Enabled := True;
  69. end;
  70. end.