Exemple #1
0
 //    //BUSCAR CON NOMBRE DE CARGO
 //    public CARGO buscarConNombreCargo(String nombreCargo)
 //    {
 //        return entityContext.CARGOes.Where(e => e.NOMCARGO == nombreCargo).First();
 //    }
 //INSERTAR CARGO
 public void insertarUsuario(USUARIO usuario)
 {
     using (TransactionScope transaction = new TransactionScope())
     {
         entityContext.USUARIOs.Add(usuario);
         entityContext.SaveChanges();
         transaction.Complete();
     }
 }
Exemple #2
0
 //ACTUALIZAR
 public void actualizarUsuario(int indice, USUARIO usuario)
 {
     using (TransactionScope transaction = new TransactionScope())
     {
         var objUsuario = entityContext.USUARIOs.Where(qq => qq.IDUSUARIO == indice).Single();
         usuario.IDUSUARIO = indice;
         entityContext.Entry(objUsuario).CurrentValues.SetValues(usuario);
         entityContext.SaveChanges();
         transaction.Complete();
     }
 }
        private void btnCancelar_Click(object sender, EventArgs e)
        {
            String strError = "";
            Boolean bolError = false;

            Regex Val = new Regex(@"^[a-zA-Z0-9_]*$");
            if (!Val.IsMatch(txtNombreUsuario.Text))
            {
                strError += "El nombre de Usuario debe tener solo letras y números, sin espacios\n";
                bolError = true;
            }
            if (txtNombreUsuario.Text == "")
            {
                strError += "El nombre es obligatorio\n";
                bolError = true;
            }
            if (cmbEmpleados.SelectedIndex == -1)
            {
                strError += "Empleado es obligatrio\n";
                bolError = true;
            }
            Regex ValContraseña = new Regex(@"(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{6,12})$");
            if (!ValContraseña.IsMatch(mskTextBox.Text) && cambioContraseña)
            {
                strError += "La contraseña debe tener al menos 6 caracteres y un número\n";
                bolError = true;
            }
            if (cmbEstado.SelectedIndex == -1)
            {
                strError += "El Estado es obligatorio\n";
                bolError = true;
            }
            if (cmbPerfil.SelectedIndex == -1)
            {
                strError += "El Perfil es obligatorio\n";
                bolError = true;
            }

            if (!bolError)
            {
                if (MessageBox.Show("¿Actualizar el usuario?", "Guardar usuario", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    USUARIO usuario = new USUARIO();
                    usuario.NOMBREUSUARIO = txtNombreUsuario.Text;
                    usuario.IDEMP = Convert.ToInt32(cmbEmpleados.SelectedValue);
                    usuario.CONTRASENAUSUARIO = ComputeHash(mskTextBox.Text);
                    usuario.IDPERFIL = (new clsPerfilBLL()).buscarConId(Convert.ToInt32((Object)cmbPerfil.SelectedValue)).IDPERFIL;
                    usuario.ESTUSUARIO = ((string)cmbEstado.SelectedItem == "ACTIVO") ? true : false;
                    (new clsUsuarioBLL()).actualizarUsuario(Int32.Parse(dgvUsuarios.Rows[dgvUsuarios.SelectedRows[0].Index].Cells[0].Value.ToString()), usuario);

                    MessageBox.Show("El usuario ha sido actualizado satisfactoriamente");
                    cargarUsuariosDataGridView();
                    habilitarControles(false);
                    mskTextBox.Enabled = false;
                    limpiarInfo();
                }
            }
            else
            {
                MessageBox.Show(strError);
            }
        }
 public List<MENU_PERFIL> obtenerTodosLosMenuPerfilesDeUsuario(USUARIO user)
 {
     PERFIL perfil = (new clsPerfilBLL()).buscarConId(Convert.ToInt32(user.IDPERFIL));
     List<MENU_PERFIL> lstMenuPerfils = entityContext.MENU_PERFIL.Where(e => e.IDPERFIL == perfil.IDPERFIL).ToList();
     return lstMenuPerfils;
 }
        private void button2_Click(object sender, EventArgs e)
        {
            String strError = "";
            Boolean bolError = false;

            Regex Val = new Regex(@"^[a-zA-Z0-9_]*$");
            if (!Val.IsMatch(txtNombreUsuario.Text))
            {
                strError += "El nombre de Usuario debe tener solo letras y números, sin espacios\n";
                bolError = true;
            }
            if (txtNombreUsuario.Text == "")
            {
                strError += "El nombre es obligatorio\n";
                bolError = true;
            }
            if (cmbEmpleados.SelectedIndex == -1)
            {
                strError += "Empleado es obligatrio\n";
                bolError = true;
            }
            Regex ValContraseña = new Regex(@"(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{6,12})$");
            if (!ValContraseña.IsMatch(mskTextBox.Text))
            {
                strError += "La contraseña debe tener al menos 6 caracteres y un número\n";
                bolError = true;
            }
            if(mskTextBox.Text == "")
            {
                strError += "La contraseña es obligatoria\n";
                bolError = true;
            }
            if (cmbPerfil.SelectedIndex == -1)
            {
                strError += "El Perfil es obligatorio\n";
                bolError = true;
            }

            if (!bolError)
            {
                if (MessageBox.Show("¿Guardar el usuario?", "Guardar usuario", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    USUARIO usuario = new USUARIO();
                    usuario.NOMBREUSUARIO = txtNombreUsuario.Text;
                    usuario.IDEMP = Convert.ToInt32(cmbEmpleados.SelectedValue);
                    usuario.CONTRASENAUSUARIO = ComputeHash(mskTextBox.Text);
                    usuario.IDPERFIL = (new clsPerfilBLL()).buscarConId(Convert.ToInt32((Object)cmbPerfil.SelectedValue)).IDPERFIL;
                    usuario.ESTUSUARIO = true;

                    (new clsUsuarioBLL()).insertarUsuario(usuario);

                    MessageBox.Show("El usuarios ha sido registrado satisfactoriamente");
                    cargarUsuariosDataGridView();
                }
            }
            else
            {
                MessageBox.Show(strError);
            }
        }