unit CadPerfilUsuario;

interface

uses
  Windows, system.UItypes, IB_Access, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ModeloCadastro, IB_Components, DB,
  Buttons, IB_Controls,UCBase,UserPermis_U, Mask, ImgList, AppEvnts,
  ExtCtrls, StdCtrls, Grids, IB_Grid, ComCtrls, jpeg, IB_EditButton,
  System.ImageList;

type
  TfrmCadPerfilUsuario = class(TFrModeloCadastro)
    edtNome: TIB_Edit;
    btnAcesso: TBitBtn;
    procedure FormCreate(Sender: TObject);
    procedure BtGravarClick(Sender: TObject);
    procedure btnAcessoClick(Sender: TObject);
    procedure btnEditar2Click(Sender: TObject);
    procedure BtCancelarClick(Sender: TObject);
    procedure BtInserirClick(Sender: TObject);
  private
    procedure SetWindowProfile;
    procedure ActionBtPermissProfileDefault;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmCadPerfilUsuario: TfrmCadPerfilUsuario;

implementation

uses Principal;

{$R *.dfm}

procedure TfrmCadPerfilUsuario.FormCreate(Sender: TObject);
begin
   Gera_Codigo  := True;
   Chave_Tabela := 'COD_USUARIO';
  inherited;
end;

procedure TfrmCadPerfilUsuario.BtGravarClick(Sender: TObject);
begin
   TbPrincipal.FieldByName('UCTYPEREC').Value := 'P';

  inherited;
   btnAcesso.Visible := True ;
end;

procedure TfrmCadPerfilUsuario.SetWindowProfile;
begin
  with frmPrincipal.UserControl1.UserSettings.Rights do
  begin
    UserPermis.Caption              := WindowCaption;
    UserPermis.LbDescricao.Caption  := LabelProfile;
    UserPermis.lbUser.Left          := UserPermis.LbDescricao.Left + UserPermis.LbDescricao.Width + 5;
    UserPermis.PageMenu.Caption     := PageMenu;
    UserPermis.PageAction.Caption   := PageActions;
    UserPermis.PageControls.Caption := PageControls; // By Vicente Barros Leonel
    UserPermis.BtLibera.Caption     := BtUnlock;
    UserPermis.BtBloqueia.Caption   := BtLock;
    UserPermis.BtGrava.Caption      := BtSave;
    UserPermis.BtCancel.Caption     := BtCancel;
    UserPermis.Position             := frmPrincipal.UserControl1.UserSettings.WindowsPosition;
  end;
end;


procedure TfrmCadPerfilUsuario.ActionBtPermissProfileDefault;
var
  TempCampos, TempCamposEX: String;
begin
  UserPermis.FTempIdUser := TbPrincipal.FieldByName('COD_USUARIO').AsInteger;
  with frmPrincipal.UserControl1  do
  begin
    TempCampos   := Format(' %s as IdUser, %s as Modulo, %s as ObjName, %s as UCKey ',
      [TableRights.FieldUserID,
      TableRights.FieldModule,
      TableRights.FieldComponentName,
      TableRights.FieldKey]);
    TempCamposEX := Format('%s, %s as FormName ', [TempCampos, TableRights.FieldFormName]);

    UserPermis.DSPermiss := DataConnector.UCGetSQLDataset(Format('Select %s from %s tab Where tab.%s = %s and tab.%s = %s',
      [TempCampos,
      TableRights.TableName,
      TableRights.FieldUserID,
      TbPrincipal.FieldByName('COD_USUARIO').AsString,
      TableRights.FieldModule,
      QuotedStr(ApplicationID)]));

    UserPermis.DSPermiss.Open;

    UserPermis.DSPermissEX := DataConnector.UCGetSQLDataset(Format('Select %s from %s tab1 Where tab1.%s = %s and tab1.%s = %s',
      [TempCamposEX,
      TableRights.TableName + 'EX',
      TableRights.FieldUserID,
      TbPrincipal.FieldByName('COD_USUARIO').AsString,
      TableRights.FieldModule,
      QuotedStr(ApplicationID)]));

    UserPermis.DSPermissEX.Open;
    UserPermis.DSPerfil := TDataset.Create(UserPermis);

    UserPermis.ShowModal;

    TbPrincipal.Close;
    TbPrincipal.Open;

    TbPrincipal.Locate('COD_USUARIO', UserPermis.FTempIdUser, []);

    //FreeAndNil(UserPermis);
  end;
end;


procedure TfrmCadPerfilUsuario.btnAcessoClick(Sender: TObject);
begin
  if TbPrincipal.IsEmpty then
    Exit;
  UserPermis              := TUserPermis.Create(self);
  UserPermis.FUserControl := frmPrincipal.UserControl1;
  SetWindowProfile;
  UserPermis.lbUser.Caption := TbPrincipal.FieldByName('nome').AsString;
  ActionBtPermissProfileDefault;

end;

procedure TfrmCadPerfilUsuario.btnEditar2Click(Sender: TObject);
begin
  inherited;
   btnAcesso.Visible := False;
end;

procedure TfrmCadPerfilUsuario.BtCancelarClick(Sender: TObject);
begin
  inherited;
   btnAcesso.Visible := True ;
end;

procedure TfrmCadPerfilUsuario.BtInserirClick(Sender: TObject);
begin
  inherited;
btnAcesso.Visible := False;
end;

end.
