public void InsertarUsuario(Modelos.Usuario us) { try { Con.Conectar(); string sql = "INSERT INTO Usuarios VALUES(@doc, @nom, @dir, @tel, @mail, @est)"; SqlCommand sc = new SqlCommand(sql, Con.Conex()); sc.Parameters.AddWithValue("@doc", us.UsuDocumento); sc.Parameters.AddWithValue("@nom", us.UsuNombre); sc.Parameters.AddWithValue("@dir", us.UsuDireccion); sc.Parameters.AddWithValue("@tel", us.UsuTelefono); sc.Parameters.AddWithValue("@mail", us.UsuCorreo); sc.Parameters.AddWithValue("@est", us.UsuEstado); int result = sc.ExecuteNonQuery(); if (result == 1) { Console.WriteLine("Usuario agragado!"); } else { Console.WriteLine("El usuario no pudo ser agregado"); } } catch (Exception e) { Console.WriteLine(e.Message); } finally { Con.Desconectar(); } }
public void ActualizarUsuario(Modelos.Usuario us) { try { Con.Conectar(); string sql = "UPDATE Usuarios SET UsuNombre = @nom, UsuDireccion = @dir, UsuTelefono = @tel, UsuCorreo = @mail, UsuEstado = @est WHERE usuDocumento = @doc"; SqlCommand sc = new SqlCommand(sql, Con.Conex()); sc.Parameters.AddWithValue("@doc", us.UsuDocumento); sc.Parameters.AddWithValue("@nom", us.UsuNombre); sc.Parameters.AddWithValue("@dir", us.UsuDireccion); sc.Parameters.AddWithValue("@tel", us.UsuTelefono); sc.Parameters.AddWithValue("@mail", us.UsuCorreo); sc.Parameters.AddWithValue("@est", us.UsuEstado); int result = sc.ExecuteNonQuery(); if (result == 1) { Console.WriteLine("Usuario actualizado!"); } else { Console.WriteLine("El usuario no pudo ser actualizado"); } } catch (Exception e) { Console.WriteLine(e.Message); } finally { Con.Desconectar(); } }
private void Bteditar_Click_1(object sender, EventArgs e) { if (dgvUsuario.SelectedRows.Count == 1) { DataGridViewRow renglon = dgvUsuario.SelectedRows[0]; Modelos.Usuario elUsuario = new Modelos.Usuario(); elUsuario.IDUsuario = Int32.Parse(renglon.Cells["IDUsuario"].Value.ToString()); elUsuario.Correo = renglon.Cells["Correo"].Value.ToString(); elUsuario.Contraseña = renglon.Cells["Contrasena"].Value.ToString(); elUsuario.Activo = Boolean.Parse(renglon.Cells["Activo"].Value.ToString()); elUsuario.Premium = Boolean.Parse(renglon.Cells["Premium"].Value.ToString()); elUsuario.FechaHoraRegistro = DateTime.Parse(renglon.Cells["FechaHoraRegistro"].Value.ToString()); Vistas.AgregaEditaUsuario edita = new Vistas.AgregaEditaUsuario(elUsuario); edita.ShowDialog(); if (elUsuario.IDUsuario != 0) // Edito { ActualizaGridUsuario(); } } else { MessageBox.Show("No hay registro seleccionado en el Grid"); } }
public async Task <int> Registro(Modelos.Usuario entidad) { _context.Usuario.Add(entidad); var salida = await _context.SaveChangesAsync(); return(salida); }
public Rol(Modelos.Usuario usuario) { InitializeComponent(); Decoracion.Reorganizar(this); this.usuario = usuario; Titulo.Text = "Usuario: " + this.usuario.getUsername(); this.loadRoles(); }
private void Btagregar_Click_1(object sender, EventArgs e) { Modelos.Usuario nuevoUsuario = new Modelos.Usuario(); Vistas.AgregaEditaUsuario ventanaNuevoUsuario = new Vistas.AgregaEditaUsuario(nuevoUsuario); ventanaNuevoUsuario.ShowDialog(); if (nuevoUsuario.IDUsuario != 0) { ActualizaGridUsuario(); } }
private void btnRegistrar_Click(object sender, EventArgs e) { if (this.operacion == "actualizar") { this.oficial.carrera = ((KeyValuePair<string, string>)this.txtCarrera.SelectedItem).Key; this.oficial.codigo = this.txtCodigo.Text; this.oficial.ci = this.txtCI.Text; this.oficial.grado = this.txtGrado.Text; this.oficial.nombre = this.txtNombre.Text; this.oficial.apellidoPaterno = this.txtApellidoPaterno.Text; this.oficial.apellidoMaterno = this.txtApellidoMaterno.Text; this.oficial.telefono = this.txtTelefono.Text; this.oficial.direccion = this.txtDireccion.Text; string tabla = "oficiales"; Dictionary<string, string[]> datos = new Dictionary<string, string[]>(); datos.Add("carrera", new string[] { "=", this.oficial.carrera, "," }); datos.Add("codigo", new string[] { "=", string.Format("'{0}'", this.oficial.codigo), "," }); datos.Add("grado", new string[] { "=", string.Format("'{0}'", this.oficial.grado), "," }); datos.Add("ci", new string[] { "=", string.Format("'{0}'", this.oficial.ci), "," }); datos.Add("nombre", new string[] { "=", string.Format("'{0}'", this.oficial.nombre), "," }); datos.Add("apellidoPaterno", new string[] { "=", string.Format("'{0}'", this.oficial.apellidoPaterno), "," }); datos.Add("apellidoMaterno", new string[] { "=", string.Format("'{0}'", this.oficial.apellidoMaterno), "," }); datos.Add("telefono", new string[] { "=", string.Format("'{0}'", this.oficial.telefono), "," }); datos.Add("direccion", new string[] { "=", string.Format("'{0}'", this.oficial.direccion), "" }); Dictionary<string, string[]> llaves = new Dictionary<string, string[]>(); llaves.Add("ID", new string[] { "=", this.oficial.ID, "" }); if (controller.actualizar(tabla, datos, llaves)) { this.Close(); } return; } Modelos.IModelo estudianteOficial = new Modelos.EstudianteOficial(this.txtGrado.Text, this.txtNombre.Text, this.txtApellidoPaterno.Text, this.txtApellidoMaterno.Text, this.txtCodigo.Text, this.txtDireccion.Text, this.txtTelefono.Text, ((KeyValuePair<string, string>)this.txtCarrera.SelectedItem).Key, this.txtCI.Text); Modelos.IModelo cuenta = new Modelos.Usuario( this.txtNombre.Text, this.txtApellidoPaterno.Text, this.txtApellidoMaterno.Text, this.txtCodigo.Text, this.txtCodigo.Text, "Oficial"); if (controller.registrar(estudianteOficial) && usuario.registrar(cuenta)) { this.Close(); } }
//Boton de logueo private void button1_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(this.username) || String.IsNullOrEmpty(this.password)) { MessageBox.Show("El Usuario o la Contrasena no pueden estar vacios", "Error"); return; } if (this.usuarioBloqueado == this.username) { MessageBox.Show("Usuario: " + this.username + " inhabilitado por multiples intentos fallidos", "Error"); return; } //consulta a la DB Modelos.Usuario usuario = DB_Ofertas.login(this.username, this.password); if (usuario != null && usuario.habilitado) { //pantalla de seleccion de rol Rol r = new Rol(usuario); r.Show(); this.Hide(); } else if (usuario != null && !usuario.habilitado) { MessageBox.Show("El usuario se encuentra deshabilitado", "Error"); } else { if (this.intentos <= 3) { this.intentos++; } if (this.intentos > 3) { this.usuarioBloqueado = this.username; MessageBox.Show("Se ha inhabilitado el usuario: " + this.username + " por superar la cantidad de intentos", "Error"); return; } else { MessageBox.Show("Usuario o contrasena invalida, intentos restantes: " + (3 - this.intentos) + "", "Error"); return; } } }
protected void BtnActualizar_Click(object sender, EventArgs e) { Modelos.Usuario us = new Modelos.Usuario(); us.UsuDocumento = ListaUsuarios.SelectedValue; us.UsuNombre = NombreBusqueda.Text; us.UsuDireccion = DireccionBusqueda.Text; us.UsuCorreo = CorreoBusqueda.Text; us.UsuTelefono = TelefonoBusqueda.Text; us.UsuEstado = EstadoBusqueda.Text; Cu.ActualizarUsuario(us); NombreBusqueda.Text = ""; DireccionBusqueda.Text = ""; CorreoBusqueda.Text = ""; TelefonoBusqueda.Text = ""; EstadoBusqueda.Text = ""; listar(); }
public static Modelos.Usuario obtenerUsuarioGuest() { miconexion.Open(); SqlCommand cmd = new SqlCommand("select * from USUARIO where Nombre_Empleado = 'Guest'", miconexion); SqlDataReader reader = cmd.ExecuteReader(); Modelos.Usuario nuevo_usuario = new Modelos.Usuario(); while (reader.Read()) { nuevo_usuario.Id_Usuario = (int)reader["Id_Usuario"]; nuevo_usuario.Nombre_Empleado = (string)reader["Nombre_Empleado"]; nuevo_usuario.FK_TipoUsuario = (int)reader["FK_TipoUsuario"]; nuevo_usuario.Num_Empleado = (string)reader["Num_Empleado"]; } miconexion.Close(); return(nuevo_usuario); }
public async Task <int> EditarUsuario(Modelos.Usuario entidad) { var usr = await _context.Usuario.FindAsync(entidad.IdUsuario); if (usr == null) { return(0); } usr.Username = entidad.Username != null ? entidad.Username : usr.Username; usr.Password = entidad.Password != null ? entidad.Password : usr.Password; usr.PasswordSalt = entidad.PasswordSalt != null ? entidad.PasswordSalt : usr.PasswordSalt; usr.Actualizado = DateTime.UtcNow; var salida = await _context.SaveChangesAsync(); return(salida); }
protected void BtnIngresar_Click(object sender, EventArgs e) { Controladores.UsuarioControlador Cu = new Controladores.UsuarioControlador(); Modelos.Usuario us = new Modelos.Usuario(); us.UsuDocumento = Documento.Text; us.UsuNombre = Nombre.Text; us.UsuDireccion = Direccion.Text; us.UsuTelefono = Telefono.Text; us.UsuCorreo = Correo.Text; us.UsuEstado = Estado.Text; Cu.InsertarUsuario(us); Documento.Text = ""; Nombre.Text = ""; Direccion.Text = ""; Telefono.Text = ""; Correo.Text = ""; Estado.Text = ""; Mostrartabla(""); Documento.Focus(); }
public static Modelos.Usuario obtenerUsuario(string usuario, string password) { miconexion.Open(); SqlCommand cmd = new SqlCommand("select * from USUARIO where username = '******' and password = '******'", miconexion); SqlDataReader reader = cmd.ExecuteReader(); Modelos.Usuario nuevo_usuario = new Modelos.Usuario(); while (reader.Read()) { nuevo_usuario.Id_Usuario = (int)reader["Id_Usuario"]; nuevo_usuario.Nombre_Empleado = (string)reader["Nombre_Empleado"]; nuevo_usuario.Username = (string)reader["username"]; nuevo_usuario.Password = (string)reader["password"]; nuevo_usuario.FK_AreaInt = (int)reader["FK_AreaInt"]; nuevo_usuario.FK_TipoUsuario = (int)reader["FK_TipoUsuario"]; nuevo_usuario.Num_Empleado = (string)reader["Num_Empleado"]; } miconexion.Close(); return(nuevo_usuario); }
private void btnRegistrar_Click(object sender, EventArgs e) { if (this.txtPrivilegio.Text == "") { MessageBox.Show("Ingrese el Privilegio"); return; } if (this.txtNombre.Text == "") { MessageBox.Show("Ingrese el nombre"); return; } if (this.txtUsuario.Text == "") { MessageBox.Show("Ingrese el nombre de usuario"); return; } if (this.txtPassword.Text == "") { MessageBox.Show("Ingrese el password del usuario"); return; } Modelos.IModelo oficial = new Modelos.Usuario( this.txtNombre.Text, this.txtApellidoPaterno.Text, this.txtApellidoMaterno.Text, this.txtUsuario.Text, this.txtPassword.Text, this.txtPrivilegio.Text); if (controller.registrar(oficial)) { this.Close(); } }
public AgregaEditaUsuario(Modelos.Usuario parametro) { InitializeComponent(); elUsuario = parametro; CargaDatos(); }
public Usuarios(Modelos.Usuario parametro) { InitializeComponent(); elUsuario = parametro; }
public Contato Usuario(Modelos.Usuario usuario) { _usuario = usuario; return(this); }