unit Employees;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls, Buttons, Mask, DBCtrls, ExtCtrls, Grids,
  DBGrids, DB, DBTables, System.ComponentModel;

type
  TForm1 = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    TabSheet3: TTabSheet;
    Label1: TLabel;
    Label2: TLabel;
    BitBtn1: TBitBtn;
    DataSource1: TDataSource;
    Table1: TTable;
    DBGrid1: TDBGrid;
    DBNavigator1: TDBNavigator;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    DBEdit2: TDBEdit;
    DBEdit3: TDBEdit;
    DBEdit4: TDBEdit;
    DBEdit5: TDBEdit;
    DBEdit6: TDBEdit;
    DBEdit7: TDBEdit;
    DBMemo1: TDBMemo;
    DBRadioGroup1: TDBRadioGroup;
    DBRadioGroup2: TDBRadioGroup;
    DBGrid3: TDBGrid;
    DBGrid2: TDBGrid;
    DataSource2: TDataSource;
    Table2: TTable;
    DBEdit9: TDBEdit;
    DBEdit10: TDBEdit;
    DBEdit11: TDBEdit;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    BitBtn2: TBitBtn;
    BitBtn3: TBitBtn;
    BitBtn4: TBitBtn;
    BitBtn5: TBitBtn;
    BitBtn6: TBitBtn;
    BitBtn7: TBitBtn;
    BitBtn8: TBitBtn;
    BitBtn9: TBitBtn;
    DataSource3: TDataSource;
    Query1: TQuery;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    Label17: TLabel;
    ComboBox1: TComboBox;
    Label18: TLabel;
    Edit1: TEdit;
    BitBtn11: TBitBtn;
    Label19: TLabel;
    ComboBox2: TComboBox;
    Label20: TLabel;
    Edit2: TEdit;
    BitBtn12: TBitBtn;
    BitBtn10: TBitBtn;
    DBEdit1: TDBEdit;
    DBEdit8: TDBEdit;
    Table1Zgh: TStringField;
    Table1Xm: TStringField;
    Table1Xb: TStringField;
    Table1Csrq: TDateField;
    Table1Hf: TBooleanField;
    Table1Zc: TStringField;
    Table1Zw: TStringField;
    Table1Jbgz: TFloatField;
    Table1Bmh: TStringField;
    Table1Bz: TMemoField;
    Table2Bmh: TStringField;
    Table2Bmmc: TStringField;
    Table2Fzr: TStringField;
    Table2Dhhm: TStringField;
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure BitBtn3Click(Sender: TObject);
    procedure BitBtn4Click(Sender: TObject);
    procedure BitBtn5Click(Sender: TObject);
    procedure BitBtn6Click(Sender: TObject);
    procedure BitBtn9Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure BitBtn7Click(Sender: TObject);
    procedure BitBtn8Click(Sender: TObject);
    procedure BitBtn10Click(Sender: TObject);
    procedure BitBtn11Click(Sender: TObject);
    procedure BitBtn12Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
Close;
end;

procedure TForm1.BitBtn2Click(Sender: TObject);
begin
Table2.First;
end;

procedure TForm1.BitBtn3Click(Sender: TObject);
begin
Table2.Prior;
end;

procedure TForm1.BitBtn4Click(Sender: TObject);
begin
Table2.Next;
end;

procedure TForm1.BitBtn5Click(Sender: TObject);
begin
Table2.Last;
end;

procedure TForm1.BitBtn6Click(Sender: TObject);
begin
BitBtn2.Enabled:=false;
BitBtn3.Enabled:=false;
BitBtn4.Enabled:=false;
BitBtn5.Enabled:=false;
BitBtn6.Enabled:=false;
BitBtn7.Enabled:=false;
BitBtn8.Enabled:=false;
BitBtn9.Enabled:=True;
BitBtn10.Enabled:=True;
Table2.Append;
end;

procedure TForm1.BitBtn9Click(Sender: TObject);
begin
BitBtn2.Enabled:=True;
BitBtn3.Enabled:=True;
BitBtn4.Enabled:=True;
BitBtn5.Enabled:=True;
BitBtn6.Enabled:=True;
BitBtn7.Enabled:=True;
BitBtn8.Enabled:=True;
BitBtn9.Enabled:=False;
BitBtn10.Enabled:=False;
Table2.Post;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
BitBtn9.Enabled:=False;
BitBtn10.Enabled:=false;
DBEdit8.Text:='';
end;

procedure TForm1.BitBtn7Click(Sender: TObject);
begin
BitBtn2.Enabled:=false;
BitBtn3.Enabled:=false;
BitBtn4.Enabled:=false;
BitBtn5.Enabled:=false;
BitBtn6.Enabled:=false;
BitBtn7.Enabled:=false;
BitBtn8.Enabled:=false;
BitBtn9.Enabled:=True;
BitBtn10.Enabled:=True;
Table2.Edit;
end;

procedure TForm1.BitBtn8Click(Sender: TObject);
begin
if Table2.IsEmpty then
   MessageDlg( '当前无数据，请确认!',mtError,[mbOk],0)
else
   Begin
   if MessageDlg('确认删除当前记录吗？',
      mtConfirmation,[mbOK,mbCancel],0)=mrOK then
      Begin
      Table2.Delete;
      Showmessage('该记录已被删除');
      Table2.First;
      end;
   end;
end;

procedure TForm1.BitBtn10Click(Sender: TObject);
begin
Table2.Cancel;
BitBtn2.Enabled:=True;
BitBtn3.Enabled:=True;
BitBtn4.Enabled:=True;
BitBtn5.Enabled:=True;
BitBtn6.Enabled:=True;
BitBtn7.Enabled:=True;
BitBtn8.Enabled:=True;
BitBtn9.Enabled:=False;
BitBtn10.Enabled:=False;
end;

procedure TForm1.BitBtn11Click(Sender: TObject);
Var
  StrSQL: string;
begin
Query1.Close;
Query1.SQL.Clear;
 case ComboBox1.ItemIndex of
   -1,10: strSQL:='Select * from Employees.db';
   0,1,2,4,5,6,8: strSQL:='Select * from Employees where '+
                      ComboBox1.Text+'='+''''+Edit1.Text+'''';
   7: strSQL:='Select * from Employees where '+
          ComboBox1.Text+'='+Edit1.Text;
 else
    strSQL:='Select * from Employees where '+ComboBox1.Text+'='
            +chr(35)+Edit1.Text+chr(35);
 end;
Query1.SQL.Add(strSQL);
QUERY1.Prepare;
Query1.Open;
if Query1.RecordCount=0  then
     ShowMessage('指定记录没有找到');
DBGrid3.DataSource:=DataSource3;
Edit1.Text:='';
end;

procedure TForm1.BitBtn12Click(Sender: TObject);
Var
  StrSQL: string;
begin
Query1.Close;
Query1.SQL.Clear;
case ComboBox2.ItemIndex of
    -1,4 :strSQL:='Select * from Department.db'
else
    strSQL:='Select * from Department.db where '+
             ComboBox2.Text+'='+''''+Edit2.Text+'''';
end;
Query1.SQL.Add(strSQL);
QUERY1.Prepare;
Query1.Open;
if Query1.RecordCount=0  then
     ShowMessage('指定记录没有找到');
DBGrid3.DataSource:=DataSource3;
Edit2.Text:='';
end;

end.
