unit frmseekborrow;

interface

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

type
  Tseekborrow = class(TForm)
    DBGrid1: TDBGrid;
    DBEdit1: TDBEdit;
    DBEdit2: TDBEdit;
    Label1: TLabel;
    Label2: TLabel;
    DataSource1: TDataSource;
    Button1: TButton;
    ComboBox1: TComboBox;
    ClientDataSet1: TClientDataSet;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  seekborrow: Tseekborrow;

implementation

uses service;

{$R *.dfm}

procedure Tseekborrow.FormClose(Sender: TObject; var Action: TCloseAction);
begin
frmService.Visible:=true;
end;

procedure Tseekborrow.FormShow(Sender: TObject);
begin
  with clientdataset1 do
    begin
      close;
      commandtext:='select * from records where libcard_id='+quotedstr(strName)+' order by records.no asc';
      open;
    end;
end;

procedure Tseekborrow.Button1Click(Sender: TObject);
var
  strBook_id,re_id:string;
  ret:integer;
begin
  ret := MessageBox(handle, '确实要删除该记录？',
               '删除记录', MB_YESNO+MB_ICONQUESTION	);
  if ret=IDYES then
    with clientdataset1 do
    begin
      if FieldValues['status']='预约' then
        begin
          strBook_id:= FieldValues['book_id'];
          re_id:= FieldValues['no'];
          close;
          commandtext:='delete from records where records.no='+re_id;
          execute;
          //修改图书信息表相关记录
          close;
          commandtext:='update booksinf set booking_num=booking_num-1 where book_id='+quotedstr(strBook_id);
          execute;
          close;
          commandtext:='select * from records where libcard_id='+quotedstr(strName);
          open;
        end
      else
        showmessage('没有权限删除该记录.');
    end;

end;

procedure Tseekborrow.ComboBox1Change(Sender: TObject);
begin
  with clientdataset1 do
  begin
  case combobox1.ItemIndex of
    0:
    if active then
      begin
      close;
      commandtext:='select * from records where libcard_id='+quotedstr(strName);
      open;
      end;
    1:
      begin
      close;
      commandtext:='select * from records where libcard_id='+quotedstr(strName)+' and status='+quotedstr('预约');
      open;
      end;
    2:
      begin
      close;
      commandtext:='select * from records where libcard_id='+quotedstr(strName)+' and status='+quotedstr('借书');
      open;
      end;
    3:
      begin
      close;
      commandtext:='select * from records where libcard_id='+quotedstr(strName)+' and status='+quotedstr('还书');
      open;
      end;
  end;
  end;
end;

end.
