unit readerinf;

interface

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

type
  Tadmin_readerinf = class(TForm)
    DBGrid1: TDBGrid;
    btnExit: TButton;
    ComboBox1: TComboBox;
    ComboBox2: TComboBox;
    btnSeek: TButton;
    GroupBox1: TGroupBox;
    Edit1: TEdit;
    GroupBox2: TGroupBox;
    DataSource1: TDataSource;
    ADOQuery1: TADOQuery;
    ADODataSet1: TADODataSet;
    btnAppend: TButton;
    btnDelete: TButton;
    btnModify: TButton;
    procedure btnExitClick(Sender: TObject);
    procedure ComboBox2Change(Sender: TObject);
    procedure btnSeekClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure ADOQuery1BeforeDelete(DataSet: TDataSet);
    procedure btnAppendClick(Sender: TObject);
    procedure btnDeleteClick(Sender: TObject);
    procedure btnModifyClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  admin_readerinf: Tadmin_readerinf;
  slTemp:tstringlist;

implementation

uses admin, reader_record;

{$R *.dfm}

procedure Tadmin_readerinf.btnExitClick(Sender: TObject);
begin
  close;
end;

procedure Tadmin_readerinf.ComboBox2Change(Sender: TObject);
begin
if combobox2.itemindex=0 then
  begin
    combobox1.Visible:=false;
    edit1.Visible:=false;
  end
else
  begin
    combobox1.Visible:=true;
    edit1.Visible:=true;
  end;

end;

procedure Tadmin_readerinf.btnSeekClick(Sender: TObject);
var
strSql:string;
begin
  if combobox2.ItemIndex>0 then
    begin
     try
      case  combobox2.ItemIndex of
      1,2,3,5,6,7,8,10:
       strSql:='select * from readers where '+slTemp[combobox2.ItemIndex]+combobox1.Text+quotedstr(edit1.Text);
      4,9:
       strSql:='select * from readers where '+slTemp[combobox2.ItemIndex]+combobox1.Text+quotedstr(edit1.Text);
      end;
       with  ADOQuery1 do
        begin
          close;
          sql.Clear;
          sql.Add(strSql);
          Open;
       end;
     except
       showmessage('SQL语句错误：'+strSql);
        with  ADOQuery1 do
        begin
          close;
          sql.Clear;
          sql.Add('select * from booksinf');
          Open;
        end;

     end

    end
  else
    begin
      with  ADOQuery1 do
      begin
        close;
        sql.Clear;
        sql.Add('select * from readers');
        Open;
      end;
    end;
end;

procedure Tadmin_readerinf.FormShow(Sender: TObject);
begin
   with  ADOQuery1 do
   begin
        close;
        sql.Clear;
        sql.Add('select * from readers');
        Open;
   end;
  slTemp:=tstringlist.Create;
  slTemp.commatext:=('*,libcard_id,reader_name,sex,birth_date,dept,phone,address,status,card_date,mem');
end;

procedure Tadmin_readerinf.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  frmadmin.Visible :=true;
  ADOQuery1.Close;
  slTemp.Free;
end;

procedure Tadmin_readerinf.ADOQuery1BeforeDelete(DataSet: TDataSet);
begin
  with ADODataSet1 do
  begin
    close;
    commandtext:='select * from records where libcard_id='+quotedstr(ADOQuery1.FieldValues['libcard_id'])+' and (status=''借书'' or status=''续借'')';
    open;
    if not isempty then
      begin
        showmessage('该读者有借书未还，不能删除该记录。');
        abort;
      end;
  end;
end;

procedure Tadmin_readerinf.btnAppendClick(Sender: TObject);
begin
    ADOQuery1.Append;
    frm_reader_record.visible:=true;  //打开记录编辑窗体
    self.Enabled:=false;            //禁止对当前窗体操作
end;

procedure Tadmin_readerinf.btnDeleteClick(Sender: TObject);
var
  intYesNo:integer;
begin
  intYesNo:=MessageDlg('确定要删除当前记录？',mtWarning,[mbYes,mbNo],0);
  if intYesNo=IDYES then
    ADOQuery1.Delete;
end;

procedure Tadmin_readerinf.btnModifyClick(Sender: TObject);
begin
    frm_reader_record.visible:=true;  //打开记录编辑窗体修改记录
    self.Enabled:=false;            //禁止对当前窗体操作
end;

end.
