unit Unit6;

interface

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

type
  TForm6 = class(TForm)
    DBGrid1: TDBGrid;
    DataSource1: TDataSource;
    ADOTable1: TADOTable;
    ADOTable1DSDesigner: TAutoIncField;
    ADOTable1_: TIntegerField;
    ADOTable1_2: TIntegerField;
    ADOTable1_3: TWideStringField;
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Edit1: TEdit;
    GroupBox2: TGroupBox;
    Label2: TLabel;
    Edit2: TEdit;
    GroupBox3: TGroupBox;
    Label3: TLabel;
    Edit3: TEdit;
    GroupBox4: TGroupBox;
    DateTimePicker1: TDateTimePicker;
    Label4: TLabel;
    DataSource2: TDataSource;
    ADOTable2: TADOTable;
    DBGrid2: TDBGrid;
    ADOTable2_: TIntegerField;
    ADOTable2DSDesigner1_: TIntegerField;
    ADOTable2DSDesigner2_: TIntegerField;
    ADOTable2_2: TMemoField;
    Button1: TButton;
    Button2: TButton;
    ADOTable2DSDesigner3: TWideStringField;
    ADOTable2DSDesigner4: TDateTimeField;
    GroupBox5: TGroupBox;
    Button4: TButton;
    Button5: TButton;
    Label5: TLabel;
    Label6: TLabel;
    procedure Edit1Change(Sender: TObject);
    procedure Edit2Change(Sender: TObject);
    procedure Edit3Change(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
   

   
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form6: TForm6;

implementation

uses Unit9;

{$R *.dfm}

//Поиск- Сортировка

procedure TForm6.Edit1Change(Sender: TObject);
begin
if Length(Edit1.Text) > 0 then
begin
ADOTable1.Filtered:=false;
ADOTable1.Filter:='ФИО_Продовца LIKE ' + #39 + Edit1.Text + '%' + #39;
ADOTable1.Filtered:=true;
ADOTable1_2.Visible:=false;
end
else ADOTable1.Filtered:=false;
if Length(Edit1.Text) <= 0 then begin ADOTable1_2.Visible:=true; end;

end;


procedure TForm6.Edit2Change(Sender: TObject);
begin
if Length(Edit2.Text) > 0 then
begin
ADOTable1.Filtered:=false;
ADOTable1.Filter:='№_Продовца=' + #39 + Edit2.text + #39;
ADOTable1.Filtered:=true;
end
else ADOTable1.Filtered:=false;
end;

procedure TForm6.Edit3Change(Sender: TObject);
begin
if Length(Edit3.Text) > 0 then
begin
ADOTable1.Filtered:=false;
ADOTable1.Filter:='ФИО_Продовца LIKE ' + #39 + Edit3.Text + '%' + #39;
ADOTable1.Filtered:=true;
ADOTable1_.Visible:=false;
ADOTable1_3.Index:=0;
ADOTable1DSDesigner.Visible:=false;
ADOTable1_2.Index:=1;

end
else ADOTable1.Filtered:=false;
 begin if Length(Edit3.Text) = 0 then
      begin
      ADOTable1_.Visible:=true;
      ADOTable1DSDesigner.Visible:=true;
      ADOTable1DSDesigner.Index:=0;
      ADOTable1_.Index:=1;
      ADOTable1_2.Index:=2;
      ADOTable1_3.Index:=3;
      end
  end
end;

procedure TForm6.FormActivate(Sender: TObject);
begin
DBGrid2.Visible:=false;
end;



procedure TForm6.Button1Click(Sender: TObject);
begin
DBGrid2.Visible:=true;
DBGrid1.Visible:=false;
ADOTable2.Filtered:=true ;
ADOTable2.Filter:= 'Дата=' + #39 + DateToStr(DateTimePicker1.date) + #39;
end;

procedure TForm6.Button2Click(Sender: TObject);
begin
ADOTable2.Filtered:=False;
DBGrid2.Visible:=false;
DBGrid1.Visible:=true;
DBGrid1.SetFocus;
ADOTable1_2.Visible:=true;
end;

//Редактировать

procedure TForm6.Button5Click(Sender: TObject);
begin
if DBGrid1.ReadOnly = True then
  begin
  Button5.Caption:='ВЫКЛючить';
  DBGrid1.ReadOnly:= False;
  DBGrid1.SetFocus;
  end
else
  Begin
  DBGrid1.ReadOnly:=True;
  Button5.Caption:='ВКЛючить';
  DBGrid1.SetFocus;
  end
end;


//Удаление

procedure TForm6.Button4Click(Sender: TObject);
begin
if MessageDlg('Вы действительно хотите удалить запись?', mtConfirmation, [mbOk, mbCancel], 0) = mrCancel
then
begin
Button4.SetFocus;
end
else
ADOTable1.Delete;
end;


end.
