/// <summary> /// Inserta un nuevo usuario en la tabla Usuarios /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnGuardar_Click(object sender, EventArgs e) { if (this.txtNombre.Text == string.Empty) { MessageBox.Show("Debe ingresar el Nombre"); return; } if (this.txtUsuario.Text == string.Empty) { MessageBox.Show("Debe ingresar el Nombre de usuario"); return; } if (this.txtContra.Text == string.Empty) { MessageBox.Show("Debe ingresar una contraseña para el usuario"); return; } if (this.cboRol.SelectedIndex == -1) { MessageBox.Show("Debe escoger un Rol"); return; } if (this.email_bien_escrito(this.txtUsuario.Text)) { Entidades.UsuarioEnt usuario = new Entidades.UsuarioEnt(); usuario.Nombre = this.txtNombre.Text; usuario.NombreUsuario = this.txtUsuario.Text; usuario.Contrasenia = this.txtContra.Text; Entidades.RolesEnt rol = this.cboRol.SelectedItem as Entidades.RolesEnt; usuario.rol = rol; Logica.Class.Usuario.insertarUsuario(usuario); this.refrescar(); } else { MessageBox.Show("Debe ingresar un correo valido. Ej: [email protected]"); return; } }
/// <summary> /// Obtiene los roles que existen en la tabla Roles /// </summary> /// <returns></returns> public static List <Entidades.RolesEnt> ObtenerListaRoles() { List <Entidades.RolesEnt> listaRol = new List <Entidades.RolesEnt>(); SqlConnection conn = new SqlConnection(Conexion.cadena); string sql = "SP_ObtenerRoles"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.CommandType = System.Data.CommandType.StoredProcedure; try { conn.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { Entidades.RolesEnt rol = new Entidades.RolesEnt(); rol.idRol = (int)reader["ID_ROL"]; rol.Descrip = reader["DESCRIP"].ToString(); listaRol.Add(rol); } } catch { throw; } finally { conn.Close(); } return(listaRol); }