unit reader_record;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, DBCtrls, DB,Mask, ExtCtrls;

type
  Tfrm_reader_record = class(TForm)
    Panel1: TPanel;
    GroupBox3: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    DBEdit1: TDBEdit;
    DBEdit2: TDBEdit;
    DBEdit3: TDBEdit;
    DBEdit5: TDBEdit;
    DBEdit6: TDBEdit;
    DBEdit7: TDBEdit;
    DBEdit8: TDBEdit;
    DBEdit9: TDBEdit;
    DBEdit10: TDBEdit;
    DBComboBox1: TDBComboBox;
    DBComboBox2: TDBComboBox;
    btnSave: TButton;
    btnCancel: TButton;
    Label12: TLabel;
    procedure btnSaveClick(Sender: TObject);
    procedure btnCancelClick(Sender: TObject);
    procedure DBEdit1Enter(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frm_reader_record: Tfrm_reader_record;

implementation

uses readerinf;

{$R *.dfm}

procedure Tfrm_reader_record.btnSaveClick(Sender: TObject);
begin
   With admin_readerinf.ADOQuery1 do begin
     if (State = dsEdit) or (state=dsInsert) then
        if DBEdit1.Text<>'' then
          Post  //提交数据到数据库
        else
          Cancel;
   end;
  self.Close;
end;

procedure Tfrm_reader_record.btnCancelClick(Sender: TObject);
begin
   With admin_readerinf.ADOQuery1 do begin
     if (State=dsEdit)or(State=dsInsert) then
        Cancel;  //放弃所做的修改
   end;
  self.Close;
end;

procedure Tfrm_reader_record.DBEdit1Enter(Sender: TObject);
begin
  //由于 DBEdit1绑定的是主索引字段，不允许修改，只允许在
  //添加新记录时输入新值
  if admin_readerinf.ADOQuery1.state<>dsInsert	then
    DBEdit1.ReadOnly:=true
  else
    DBEdit1.ReadOnly:=false ;
end;

procedure Tfrm_reader_record.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  admin_readerinf.Enabled:=True;    //允许对admin_readerinf窗体操作
end;

end.
