unit Unit4;

interface

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

type
  TForm4 = class(TForm)
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    ADOTable1: TADOTable;
    GroupBox1: TGroupBox;
    Label1: TLabel;
    GroupBox2: TGroupBox;
    Label2: TLabel;
    Edit2: TEdit;
    GroupBox3: TGroupBox;
    DateTimePicker1: TDateTimePicker;
    Label3: TLabel;
    Button1: TButton;
    Button2: TButton;
    Label5: TLabel;
    Edit1: TEdit;
    GroupBox4: TGroupBox;
    Button3: TButton;
    Label6: TLabel;
    GroupBox5: TGroupBox;
    Label7: TLabel;
    Button4: TButton;
    GroupBox6: TGroupBox;
    Button5: TButton;
    Label8: TLabel;
    ADOTable1DSDesigner: TAutoIncField;
    ADOTable1_: TWideStringField;
    ADOTable1_2: TWideStringField;
    ADOTable1_3: TIntegerField;
    ADOTable1DSDesigner2: TIntegerField;
    ADOTable1_4: TDateTimeField;

   
    procedure Edit1Change(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Edit2Change(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
   

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

var
  Form4: TForm4;

implementation

uses Unit5;

{$R *.dfm}

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

procedure TForm4.Edit1Change(Sender: TObject);
begin
if Length(Edit1.Text) > 0 then
begin
ADOTable1.Filtered:=false;
ADOTable1.Filter:='Вид_Товара LIKE ' + #39 + Edit1.Text + '%' + #39;
ADOTable1.Filtered:=true;
end
else ADOTable1.Filtered:=false;
end;

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

procedure TForm4.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 TForm4.Button1Click(Sender: TObject);
begin
ADOTable1.Filtered:=true ;
ADOTable1.Filter:= 'Дата_покупки=' + #39 + DateToStr(DateTimePicker1.date) + #39;

end;

procedure TForm4.Button2Click(Sender: TObject);
begin
ADOTable1.Filtered:=False;
DateTimePicker1.SetFocus;
end;


//Вкл-Выкл режим редактирования

procedure TForm4.Button3Click(Sender: TObject);
begin
if DBGrid1.ReadOnly = True then
  begin
  Button3.Caption:='Выключить режим редактирования';
  Label8.Visible:=True;
  Label8.Caption:='ВКЛЮЧЕНО!!!';
  Label8.Font.Color:= clRed;
  DBGrid1.ReadOnly:= False;
  end
else
  Begin
  DBGrid1.ReadOnly:=True;
  Button3.Caption:='Включить режим редактирования';
  Label8.Visible:=False;

  end
end;

//Удаление

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

//Добавление

procedure TForm4.Button5Click(Sender: TObject);
begin
Form5.ShowModal;
end;






end.
