unit frmrecord;

interface

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

type
  Tfrm_Record = class(TForm)
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label10: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    DBText1: TDBText;
    DBText2: TDBText;
    DBText3: TDBText;
    DBText4: TDBText;
    DBText5: TDBText;
    DBText6: TDBText;
    lbSum: TDBText;
    DBText8: TDBText;
    DBText9: TDBText;
    DBText10: TDBText;
    Button1: TButton;
    Button3: TButton;
    Label11: TLabel;
    lbBorrow: TDBText;
    Label12: TLabel;
    lbBooking: TDBText;
    GroupBox1: TGroupBox;
    chBooking: TCheckBox;
    procedure Button1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frm_Record: Tfrm_Record;

implementation


{$R *.dfm}

procedure Tfrm_Record.Button1Click(Sender: TObject);
begin
  close;
end;

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

procedure Tfrm_Record.FormShow(Sender: TObject);
var
intRe:integer;
begin
with frmfindbook.clientdataset1 do
  begin
  intRe:=FieldValues['book_num']-FieldValues['borrow_num']-FieldValues['booking_num'];
  if intRe>0 then
    begin
     chBorrow.Enabled:=true;
     chBooking.Enabled:=false;
    end
  else if intRe>-FieldValues['book_num'] then
    begin
      chBorrow.Enabled:=false;
      chBooking.Enabled:=true;
    end
  else
    begin
      chBorrow.Enabled:=false;
      chBooking.Enabled:=false;
    end;
  end;
end;

procedure Tfrm_Record.Button3Click(Sender: TObject);
var
  strBookid,strBookname,strReadname:string;
begin
  if chBorrow.Checked or chBooking.Checked then
    begin
    strBookid:=frmFindBook.clientdataset1.fieldbyname('book_id').AsString;
    strBookname:=frmFindBook.clientdataset1.fieldbyname('book_name').AsString;
    with  frmFindBook.clientdataset2 do
    begin
      close;
      commandtext:='select libcard_id,reader_name from readers where libcard_id='+quotedstr(strName);
      open;
      strReadname:=fieldbyname('reader_name').AsString;
    end;
    with frmFindBook.clientdataset2 do
    begin
      close;
      commandtext:='insert into records (libcard_id,reader_name,book_id,book_name,borrow_date,status) Values ('+quotedstr(strName)+','+quotedstr(strReadname)+','+quotedstr(strBookid)+','+quotedstr(strBookname)+','+datetimetostr(date())+',''预约'')';
      execute;
      chBorrow.Checked:=false;
      chBooking.Checked:=false;
      showmessage('操作成功。');
    end;
    with frmFindBook.clientdataset1 do
    begin
{      edit;
      fieldbyname('booking_num').AsInteger:=fieldbyname('booking_num').AsInteger+1;
      post;
}    end;
    close;
    end
  else
    showmessage('该图书已被借出或预约，请选择其他书籍。');
    close;
end;

end.
