public static UsuarioGeneral IniciarSesionGeneral(string nombre, string contra)
        {
            MySqlCommand comando = new MySqlCommand(String.Format("CALL InicioSesion('{0}','{1}')", nombre, contra), ConectorMySQL.Conectar());

            try
            {
                MySqlDataReader leer = comando.ExecuteReader();
                UsuarioGeneral  p    = new UsuarioGeneral();
                while (leer.Read())
                {
                    p.ID         = leer.GetInt32(0);
                    p.Nombre     = leer.GetString(1);
                    p.Contraseña = leer.GetString(2);
                    p.Tipo       = leer.GetString(3);
                }
                return(p);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                ConectorMySQL.Desconectar();
            }
        }
        public static List <UsuarioGeneral> leerTodo() // mostrar
        {
            List <UsuarioGeneral> lista   = new List <UsuarioGeneral>();
            MySqlCommand          comando = new MySqlCommand(String.Format("CALL verUsuarios()"), ConectorMySQL.Conectar());

            try
            {
                MySqlDataReader leer = comando.ExecuteReader();

                while (leer.Read())
                {
                    UsuarioGeneral p = new UsuarioGeneral();
                    p.ID         = leer.GetInt32(0);
                    p.Nombre     = leer.GetString(1);
                    p.Contraseña = leer.GetString(2);
                    p.Tipo       = leer.GetString(3);
                    lista.Add(p);
                }
                return(lista);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                ConectorMySQL.Desconectar();
            }
        }
        public static List <UsuarioGeneral> leerPordescripcion(string nombre) // buscar
        {
            List <UsuarioGeneral> listaBuscar = new List <UsuarioGeneral>();
            MySqlCommand          comando     = new MySqlCommand(String.Format("call UBuscarNombre('{0}')", nombre), ConectorMySQL.Conectar());

            try
            {
                MySqlDataReader leer = comando.ExecuteReader();

                while (leer.Read())
                {
                    UsuarioGeneral p = new UsuarioGeneral();
                    p.ID         = leer.GetInt32(0);
                    p.Nombre     = leer.GetString(1);
                    p.Contraseña = leer.GetString(2);
                    p.Tipo       = leer.GetString(3);
                    listaBuscar.Add(p);
                }
                return(listaBuscar);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                ConectorMySQL.Desconectar();
            }
        }
        public static UsuarioGeneral obtenerproducto(int id)
        {
            UsuarioGeneral s       = new UsuarioGeneral();
            MySqlCommand   comando = new MySqlCommand(String.Format("call UBuscarId('{0}')", id), ConectorMySQL.Conectar());

            try
            {
                MySqlDataReader leer = comando.ExecuteReader();

                while (leer.Read())
                {
                    s.ID         = leer.GetInt32(0);
                    s.Nombre     = leer.GetString(1);
                    s.Contraseña = leer.GetString(2);
                    s.Tipo       = leer.GetString(3);
                }
                return(s);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                ConectorMySQL.Desconectar();
            }
        }
예제 #5
0
        private void btnModificarUsuariosGen_Click(object sender, EventArgs e)
        {
            if (tablaUsuariosGenerales.SelectedRows.Count == 1)
            {
                int id = Convert.ToInt32(tablaUsuariosGenerales.CurrentRow.Cells[0].Value);

                usuarioseleccionado = Clases_DAO.UsuariosDAO.obtenerproducto(id);


                FormModificarUsuariosGen frmModiusuario = new FormModificarUsuariosGen();

                if (usuarioseleccionado != null) //si se selecciona un producto se vaya al txt
                {
                    usuarioactual = usuarioseleccionado;

                    frmModiusuario.id = id;
                    frmModiusuario.txtBoxNombreModif.Text = Convert.ToString(usuarioactual.Nombre);
                    frmModiusuario.txtBoxContraModif.Text = Convert.ToString(usuarioactual.Contraseña);
                }
                frmModiusuario.Show();
            }
            else
            {
                MessageBox.Show("Debes seleccionar una fila");
            }
        }
예제 #6
0
        private void btnLoguear_Click(object sender, EventArgs e)
        {
            UsuarioGeneral usuario = new UsuarioGeneral();

            lblErrorUsuario.Visible = false;
            lblErrorContra.Visible  = false;

            if (txtUsuario.Text != "Usuario" && txtContra.Text != "Contraseña")
            {
                lblErrorUsuario.Visible = false;
                lblErrorContra.Visible  = false;
                usuario = UsuariosDAO.IniciarSesionGeneral(txtUsuario.Text, txtContra.Text);
                if (usuario.Nombre != null)
                {
                    this.Hide();
                    Form1 inicio = new Form1();
                    Program.tipoUsuario   = usuario.Tipo;
                    Program.nombreUsuario = usuario.Nombre;
                    inicio.Show();
                }
                else
                {
                    lblErrorLogin.Text    = "Usuario o contraseña inválidas, intente de nuevo";
                    lblErrorLogin.Visible = true;
                    txtContra.Text        = "";
                    txtContra_Leave(null, e);
                    txtUsuario.Focus();
                }
            }
            else if (txtUsuario.Text == "Usuario" && txtContra.Text == "Contraseña")
            {
                lblErrorUsuario.Text    = "Hace falta ingresar el usuario";
                lblErrorUsuario.Visible = true;
                lblErrorContra.Text     = "Hace falta ingresar la contraseña";
                lblErrorContra.Visible  = true;
            }
            else if (txtUsuario.Text == "Usuario")
            {
                lblErrorUsuario.Text    = "Hace falta ingresar el usuario";
                lblErrorUsuario.Visible = true;
            }
            else if (txtContra.Text == "Contraseña")
            {
                lblErrorContra.Text    = "Hace falta ingresar la contraseña";
                lblErrorContra.Visible = true;
            }
        }
        public static int crear(UsuarioGeneral add) // agregar
        {
            int          retorno = 0;
            MySqlCommand comando = new MySqlCommand(String.Format("CALL nuevoUsuario('{0}','{1}')",
                                                                  add.Nombre, add.Contraseña), ConectorMySQL.Conectar());

            try
            {
                retorno = comando.ExecuteNonQuery();
                return(retorno);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                ConectorMySQL.Desconectar();
            }
        }
예제 #8
0
        private void botonConfirmarRegisUsuariosGen_Click(object sender, EventArgs e)
        {
            int retorno = 0;

            if (txtBoxNombreRegis.Text != "" && txtContraRegis.Text != "")
            {
                UsuarioGeneral agregar = new UsuarioGeneral();
                agregar.Nombre     = txtBoxNombreRegis.Text;
                agregar.Contraseña = txtContraRegis.Text;
                retorno            = Clases_DAO.UsuariosDAO.crear(agregar);
            }

            if (retorno > 0)
            {
                MessageBox.Show("Agregado con éxito");
                MainMenuUsuarios.tablaUsuariosGenerales.DataSource = Clases_DAO.UsuariosDAO.leerTodo();
                this.Close();
            }
            else
            {
                MessageBox.Show("Error, hacen falta campos por llenar");
            }
        }