unit Unit4;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.ComCtrls, Vcl.ToolWin,
  Vcl.Grids, Vcl.DBGrids, Data.DB, Data.Win.ADODB, DBGridEhGrouping,
  ToolCtrlsEh, DBGridEhToolCtrls, DynVarsEh, EhLibVCL, GridsEh, DBAxisGridsEh,
  DBGridEh;

type
  TfUsers = class(TForm)
    pTop: TPanel;
    tbMain: TToolBar;
    tbAdd: TToolButton;
    tbEdit: TToolButton;
    tbDelete: TToolButton;
    dsUsers: TDataSource;
    DBGridEh1: TDBGridEh;
    procedure tbAddClick(Sender: TObject);
    procedure tbEditClick(Sender: TObject);
    procedure tbDeleteClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fUsers: TfUsers;

implementation

{$R *.dfm}

uses Unit1, Unit2, Unit5;

procedure TfUsers.tbAddClick(Sender: TObject);
begin
  DM.tUsers.Append;
  if fUsersEdit.ShowModal = mrOk then begin
    DM.tUsersrights.AsInteger := fUsersEdit.rgRigths.ItemIndex;
    if (fUsersEdit.Edit1.Text <> '') then
      DM.tUserspassword.AsString := fMain.md5(fUsersEdit.Edit1.Text);
    if DM.tUsers.Modified then
      DM.tUsers.Post;
   end;
   DM.tUsers.Cancel;
   DM.tUsers.Requery();
   DM.tUsers.Last;
end;

procedure TfUsers.tbDeleteClick(Sender: TObject);
begin
  if Application.MessageBox('Удалить запись?', 'Подтверждение', MB_ICONQUESTION+MB_YESNO) = idYes then
    DM.tUsers.Delete;
end;

procedure TfUsers.tbEditClick(Sender: TObject);
  var
    id:integer;
begin
  id := DM.tUsers.RecNo;
  DM.tUsers.Edit;
  fUsersEdit.rgRigths.ItemIndex := DM.tUsersrights.AsInteger;
  if fUsersEdit.ShowModal = mrOk then begin
    DM.tUsersrights.AsInteger := fUsersEdit.rgRigths.ItemIndex;
    if (fUsersEdit.Edit1.Text <> '') then
      DM.tUserspassword.AsString := fMain.md5(fUsersEdit.Edit1.Text);
    if DM.tUsers.Modified then
      DM.tUsers.Post;
  end;
  DM.tUsers.Cancel;
  DM.tUsers.Requery();
  DM.tUsers.MoveBy(id-1);
end;

end.
