private void buttonIngresar_Click(object sender, EventArgs e) { string usuario = txtUsuario.Text; string password = txtPassword.Text; try { Controlador ctrl = new Controlador(); string respuesta = ctrl.ctrlLogin(usuario, password); if (respuesta.Length > 0) { MessageBox.Show(respuesta, "Avizo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { frmPrincipal frm = new frmPrincipal(); frm.Visible = true; this.Visible = false; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Avizo", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void button1_Click(object sender, EventArgs e) { Usuarios usuario = new Usuarios(); usuario.Usuario = txtUsuario.Text; usuario.Password = txtPassword.Text; usuario.ConPassword = txtConPassword.Text; usuario.Nombre = txtNombre.Text; try { Controlador control = new Controlador(); string respuesta = control.ctrlRegistro(usuario); if (respuesta.Length > 0) { MessageBox.Show(respuesta, "Avizo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Usuario Registrado", "Avizo", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnActualizar_Click(object sender, EventArgs e) { int id = int.Parse(txtId.Text); String nombre = txtNombreUsuario.Text; int id_tipo = int.Parse(txtIdTipo.Text); String usuario = txtTipoUsuario.Text; String password = Controlador.generarSHA1(txtPass.Text); String conPassword = Controlador.generarSHA1(txtConfirPass.Text); if (string.IsNullOrEmpty(txtId.Text) || string.IsNullOrEmpty(txtNombreUsuario.Text) || string.IsNullOrEmpty(txtIdTipo.Text) || string.IsNullOrEmpty(txtTipoUsuario.Text) || string.IsNullOrEmpty(txtPass.Text) || string.IsNullOrEmpty(txtConfirPass.Text)) { MessageBox.Show("Para actulizar, todos los campos deber ser llenados"); } else { if (password == conPassword) { string sql = "UPDATE usuarios SET usuario='" + usuario + "', password='******', nombre='" + nombre + "', id_tipo='" + id_tipo + "' WHERE id='" + id + "'"; MySqlConnection conexion = Conexion.getConexion(); conexion.Open(); try { MySqlCommand comando = new MySqlCommand(sql, conexion); comando.ExecuteNonQuery(); MessageBox.Show("Registro actualizado"); limpiar(); } catch (MySqlException ex) { MessageBox.Show("Error al actualizar: " + ex.Message); } finally { conexion.Close(); } } else { MessageBox.Show("Para actulizar, las contrasenas deben coincidir"); } } }