private bool ValidaGravar()
 {
     try
     {
         if (string.IsNullOrEmpty(TxtNome.Text))
         {
             MessageBox.Show("Favor preencher o campo de Nome!", "Campo faltando",
                             MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             TxtNome.Focus();
             return(false);
         }
         if (string.IsNullOrEmpty(txtCpf.Text))
         {
             MessageBox.Show("Favor preencher o campo de CPF!", "Campo faltando",
                             MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             txtCpf.Focus();
             return(false);
         }
         if (ValidadorCpf.ValidaCpf(txtCpf.Text) == false)
         {
             MessageBox.Show("CPF Inválido : " + txtCpf.Text, "Campo faltando",
                             MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             txtCpf.Focus();
             return(false);
         }
         if (string.IsNullOrEmpty(txtEmail.Text))
         {
             MessageBox.Show("Favor preencher o campo de E-mail!", "Campo faltando",
                             MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             txtEmail.Focus();
             return(false);
         }
         if (CmbPerfil.SelectedIndex == -1)
         {
             MessageBox.Show("Favor selecionar um perfil!", "Campo faltando",
                             MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             CmbPerfil.Focus();
             return(false);
         }
         if (txtSenha.Text != txtConfirma.Text)
         {
             MessageBox.Show("As senhas não são iguais!", "Campo faltando",
                             MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             txtSenha.Focus();
             return(false);
         }
         return(true);
     }
     catch (Exception e)
     {
         MessageBox.Show("Erro - ValidaGravar " + e.Message, "Erro!", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return(false);
     }
 }
 private void LimpiarCampos()
 {
     HfIdUsuario.Value = TxtNombre.Text = TxtUsuario.Text = string.Empty;
     TxtContrasena.Attributes.Add("value", string.Empty);
     lblPersonalizado.Visible = false;
     CmbTipo.ClearSelection();
     CmbPerfil.ClearSelection();
     LimpiarPermisos();// false);
     //Deselecciona las filas seleccionadas
     foreach (GridDataItem item in RadGrid2.MasterTableView.Items)
     {
         item.Selected = false;
     }
 }
        private void CargarCmbPerfil()
        {
            DataTable dt      = new DataTable();
            string    mensaje = string.Empty;

            dt = perfiles.PerfilConsultar(ref mensaje);
            if (!mensaje.Equals(string.Empty))
            {
                (this.Master as Principal).AlertError(mensaje);
            }

            CmbPerfil.DataSource = dt == null ? new DataTable() : dt;
            CmbPerfil.DataBind();
        }
        private void CargarCmbPerfil()
        {
            DataTable dt      = new DataTable();
            string    mensaje = string.Empty;

            dt = perfiles.PerfilConsultar(lblCadena.Text, ref mensaje);
            if (!mensaje.Equals(string.Empty))
            {
                AlertError(mensaje);
            }

            CmbPerfil.DataSource = dt == null ? new DataTable() : dt;
            CmbPerfil.DataBind();
        }
Example #5
0
 private bool ValidaGravar()
 {
     try
     {
         if (string.IsNullOrEmpty(TxtNome.Text))
         {
             MessageBox.Show("Favor preencher o campo de Nome!", "Campo faltando",
                             MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             TxtNome.Focus();
             return(false);
         }
         if (string.IsNullOrEmpty(txtCpf.Text))
         {
             MessageBox.Show("Favor preencher o campo de CPF!", "Campo faltando",
                             MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             txtCpf.Focus();
             return(false);
         }
         if (ValidadorCpf.ValidaCpf(txtCpf.Text) == false)
         {
             MessageBox.Show("CPF Inválido : " + txtCpf.Text, "Campo faltando",
                             MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             txtCpf.Focus();
             return(false);
         }
         if (this.user.PkUsuario == 0 && this.VerificaCpfExist())
         {
             MessageBox.Show("Já existe um usuário com este CPF:" + txtCpf.Text, "Campo faltando",
                             MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             txtCpf.Focus();
             return(false);
         }
         if (string.IsNullOrEmpty(txtEmail.Text))
         {
             MessageBox.Show("Favor preencher o campo de E-mail!", "Campo faltando",
                             MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             txtEmail.Focus();
             return(false);
         }
         if (CmbPerfil.SelectedIndex == -1)
         {
             MessageBox.Show("Favor selecionar um perfil!", "Campo faltando",
                             MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             CmbPerfil.Focus();
             return(false);
         }
         if ((string.IsNullOrEmpty(txtSenha.Text) && string.IsNullOrEmpty(txtConfirma.Text)))
         {
             MessageBox.Show("Favor preencher o campo de senha e confirmar senha!", "Campo faltando",
                             MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             txtSenha.Focus();
             return(false);
         }
         if (txtSenha.Text != txtConfirma.Text)
         {
             MessageBox.Show("Os campos de senha e confirma senha estão diferentes!", "Campo faltando",
                             MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             txtSenha.Focus();
             return(false);
         }
         return(true);
     }
     catch (Exception e)
     {
         MessageBox.Show("Erro - ValidaGravar " + e.Message, "Erro!", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return(false);
     }
 }
        protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
        {
            string mensaje = string.Empty;

            GuardarItemsSeleccionados(RadGrid1);
            if (e.CommandName.Equals("Nuevo"))
            {
                LimpiarCampos();
                MostrarModal();
            }
            else if (e.CommandName.Equals("Editar"))
            {
                DataTable dt = new DataTable();
                LimpiarCampos();
                foreach (GridDataItem item in RadGrid1.SelectedItems)
                {
                    HfIdUsuario.Value = item["IdUsuario"].Text.Trim();
                    TxtUsuario.Text   = item["Usuario"].Text.Trim();
                    TxtNombre.Text    = item["Nombre"].Text.Trim();
                    CmbTipo.FindItemByValue(item["IdTipoUsuario"].Text.Trim()).Selected = true;
                    CmbPerfil.FindItemByValue(item["IdPerfil"].Text.Trim()).Selected    = true;
                    //Se valida para saber si mostrar etiqueta de personalizado
                    if (item["Perfil"].Text.Contains("Personalizado"))
                    {
                        lblPersonalizado.Visible = true;
                    }
                    else
                    {
                        lblPersonalizado.Visible = false;
                    }

                    CargarPermisosUsuario();
                }
                MostrarModal();
            }
            else if (e.CommandName.Equals("Eliminar"))
            {
                foreach (GridDataItem item in RadGrid1.SelectedItems)
                {
                    HfIdUsuario.Value = item["IdUsuario"].Text.Trim();
                }

                usuarios.UsuarioEliminar(Convert.ToInt32(Session["IdUsuario"]), Convert.ToInt32(HfIdUsuario.Value), ref mensaje);
                if (mensaje.Equals(ControlExcepciones.Ok))
                {
                    (this.Master as Principal).AlertSuccess("El usuario se eliminó.");
                    RadGrid1.Rebind();
                }
                else
                {
                    (this.Master as Principal).AlertError(mensaje);
                }
            }
            else if (e.CommandName.Equals(RadGrid.ExportToExcelCommandName))
            {
                ConfigureExport(RadGrid1);
            }
            else if (e.CommandName == RadGrid.ExportToPdfCommandName)
            {
                RadGrid1.MasterTableView.GetColumn("Nombre").HeaderStyle.Width              = 300;
                RadGrid1.MasterTableView.GetColumn("Usuario").HeaderStyle.Width             =
                    RadGrid1.MasterTableView.GetColumn("Perfil").HeaderStyle.Width          =
                        RadGrid1.MasterTableView.GetColumn("TipoUsuario").HeaderStyle.Width = 90;
                ConfigureExport(RadGrid1);
            }
        }