unit bore;

interface

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

type
  Tfrmbore = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    DBGrid1: TDBGrid;
    Edit1: TEdit;
    Label1: TLabel;
    Button1: TButton;
    DBNavigator1: TDBNavigator;
    GroupBox1: TGroupBox;
    Label4: TLabel;
    Label5: TLabel;
    DBText3: TDBText;
    DBText4: TDBText;
    Label9: TLabel;
    Label10: TLabel;
    DBText5: TDBText;
    DBText6: TDBText;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    DBText7: TDBText;
    DBText8: TDBText;
    DBText9: TDBText;
    DBText10: TDBText;
    GroupBox2: TGroupBox;
    Label7: TLabel;
    Label6: TLabel;
    Label2: TLabel;
    DBText1: TDBText;
    Label3: TLabel;
    DBText2: TDBText;
    ADOQuery1: TADOQuery;
    DataSource1: TDataSource;
    ADOQuery2: TADOQuery;
    DataSource2: TDataSource;
    Label8: TLabel;
    DBText11: TDBText;
    DBText12: TDBText;
    DBText13: TDBText;
    Label15: TLabel;
    DBText14: TDBText;
    Label16: TLabel;
    DBText15: TDBText;
    Label17: TLabel;
    DBText16: TDBText;
    ComboBox1: TComboBox;
    GroupBox3: TGroupBox;
    Button2: TButton;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Button1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure DBNavigator1Click(Sender: TObject; Button: TNavigateBtn);
    procedure Button2Click(Sender: TObject);
    procedure TabSheet2Show(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmbore: Tfrmbore;

implementation

uses admin;

{$R *.dfm}

procedure Tfrmbore.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  frmAdmin.Visible :=true;
  ADOQuery1.Close;
  ADOQuery2.Close;
end;

procedure Tfrmbore.Button1Click(Sender: TObject);
begin
  with ADOQuery1 do
    begin
      close;
      sql.Clear;
      if edit1.Text='' then
        sql.Add('select * from records')
      else
        sql.Add('select * from records where libcard_id='+quotedstr(edit1.Text));
      open;
    end;
end;

procedure Tfrmbore.FormShow(Sender: TObject);
begin
  with ADOQuery1 do
    begin
      close;
      sql.Clear;
        sql.Add('select * from records') ;
      open;
    end;
  with ADOQuery2 do
    begin
      close;
      sql.Clear;
        sql.Add('select * from booksinf');
      open;
    end;
  pagecontrol1.ActivePage:= tabsheet1;
end;

procedure Tfrmbore.DBNavigator1Click(Sender: TObject;
  Button: TNavigateBtn);
begin
adoquery2.Locate('book_id;book_name', VarArrayOf([adoquery1.FieldValues['book_id'],adoquery1.FieldValues['book_name']]), [loPartialKey]);

end;

procedure Tfrmbore.Button2Click(Sender: TObject);
var
  ret:integer;
  strStatus:string;
begin
  strStatus:=adoquery1.FieldValues['status'];
  if combobox1.ItemIndex<>-1 then
    begin
      ret := MessageBox(handle, '确实要执行更改操作？',
               '办理借还书手续', MB_YESNO+MB_ICONQUESTION	);
      if ret=IDYES then
      begin
        with adoquery1 do
          begin
            edit;
            fieldvalues['status']:=combobox1.Text;  //修改借书记录状态
            post;
          case combobox1.ItemIndex of
          0:
            begin
              adoquery2.Edit;
              adoquery2.fieldvalues['booking_num']:=adoquery2.fieldvalues['booking_num']-1;   //更新图书信息表
              adoquery2.fieldvalues['borrow_num']:=adoquery2.fieldvalues['borrow_num']+1;
              adoquery2.post;
              edit;
              fieldvalues['borrow_date']:=date;
              post;
            end;
          1:
            begin
              edit;
              fieldvalues['conborrow_date']:=date;
              post;
            end;
          2:
            begin
              adoquery2.edit;
              adoquery2.fieldvalues['borrow_num']:=adoquery2.fieldvalues['borrow_num']-1;
              adoquery2.post;
              edit;
              fieldvalues['return_date']:=date;
              post;
            end;
          end;
       end;
     end;
  end;
end;

procedure Tfrmbore.TabSheet2Show(Sender: TObject);
begin
if adoquery2.Active then
  adoquery2.Locate('book_id', adoquery1.FieldValues['book_id'], [loPartialKey]);
end;

procedure Tfrmbore.ComboBox1Change(Sender: TObject);
begin
  with adoquery1 do
  begin
    case combobox1.ItemIndex of
      0:
      if fieldvalues['status']<>'预约' then
        combobox1.ItemIndex:=-1;
      1:
      if fieldvalues['status']<>'借书' then
        combobox1.ItemIndex:=-1;
      2:
      if (fieldvalues['status']<>'借书')and(fieldvalues['status']<>'续借') then
        combobox1.ItemIndex:=-1;
    end;
  end;
end;

end.
