unit MainUnit;

interface

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

type
  TMainForm = class(TForm)
    DBGrid1: TDBGrid;
    MainMenu1: TMainMenu;
    N1: TMenuItem;
    CloseMenu: TMenuItem;
    N3: TMenuItem;
    TownBookMenuItem: TMenuItem;
    Help1: TMenuItem;
    AboutMenuItem: TMenuItem;
    ImageList1: TImageList;
    ToolBar1: TToolBar;
    NewButton: TToolButton;
    EditButton: TToolButton;
    DelButton: TToolButton;
    ToolButton4: TToolButton;
    ToolButton5: TToolButton;
    N4: TMenuItem;
    N5: TMenuItem;
    N6: TMenuItem;
    N7: TMenuItem;
    ToolButton6: TToolButton;
    N2: TMenuItem;
    N8: TMenuItem;
    N9: TMenuItem;
    ToolBar2: TToolBar;
    Label1: TLabel;
    FindTelephoneEdit: TEdit;
    Label2: TLabel;
    FindEdit: TEdit;
    FindButton: TToolButton;
    DBGrid2: TDBGrid;
    Splitter1: TSplitter;
    procedure CloseMenuClick(Sender: TObject);
    procedure TownBookMenuItemClick(Sender: TObject);
    procedure AboutMenuItemClick(Sender: TObject);
    procedure NewButtonClick(Sender: TObject);
    procedure EditButtonClick(Sender: TObject);
    procedure DelButtonClick(Sender: TObject);
    procedure FindTelephoneEditChange(Sender: TObject);
    procedure N8Click(Sender: TObject);
    procedure N9Click(Sender: TObject);
    procedure FindButtonClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  MainForm: TMainForm;

implementation

uses DataModuleUnit, TownBookUnit, AboutUnit, EditFormUnit, FindResultUnit;

{$R *.dfm}

procedure TMainForm.CloseMenuClick(Sender: TObject);
begin
 Close;
end;

procedure TMainForm.TownBookMenuItemClick(Sender: TObject);
begin
 TownBookForm.ShowModal;
end;

procedure TMainForm.AboutMenuItemClick(Sender: TObject);
begin
 AboutForm.ShowModal;
end;

procedure TMainForm.NewButtonClick(Sender: TObject);
begin
 DataModule1.BookTable.Insert;
 EditRecordForm.ShowModal;
end;

procedure TMainForm.EditButtonClick(Sender: TObject);
begin
 EditRecordForm.ShowModal;
end;

procedure TMainForm.DelButtonClick(Sender: TObject);
begin
 if Application.MessageBox(PChar('Ты действительно хочешь удалить '+DataModule1.BookTableDSDesigner.AsString), 'Внимание!!!', MB_OKCANCEL)=id_OK then
  DataModule1.BookTable.Delete;
end;

procedure TMainForm.FindTelephoneEditChange(Sender: TObject);
begin
 if Length(FindEdit.Text)>0 then
  DataModule1.BookTable.Filtered:=true
 else
  DataModule1.BookTable.Filtered:=false;

 DataModule1.BookTable.Filter:='Фамилия>'''+FindEdit.Text+'''';
end;

procedure TMainForm.N8Click(Sender: TObject);
begin
 DataModule1.BookTable.Sort:='Фамилия ASC';
end;

procedure TMainForm.N9Click(Sender: TObject);
begin
 DataModule1.BookTable.Sort:='Город ASC';
end;

procedure TMainForm.FindButtonClick(Sender: TObject);
begin
 DataModule1.FindQuery.Active:=false;
 DataModule1.FindQuery.Parameters.ParamByName('Telephone').Value:=FindTelephoneEdit.Text;
 DataModule1.FindQuery.Active:=true;

 FindResultForm.ShowModal;
 DataModule1.BookTable.Refresh;
 DataModule1.TelephonTable.Refresh;
end;

end.
