private void Registrar()
        {
            string Identidad_Empleado = textboxIdentidadAgregar.Text;
            string Nombre_Empleado    = textboxNombreAgregar.Text;
            string Apellido_Empleado  = textboxApellidoAgregar.Text;
            string Usuario            = textboxUsuarioAgregar.Text;
            string Telefono           = textboxTelefonoAgregar.Text;
            string Celular            = textboxCelularAgregar.Text;
            string Contraseña         = Encriptacion.Encrypt(labelContraseñaTemporal.Text);
            int    Intentos           = 0;
            bool   IsExist            = false;

            SqlCommand    sql    = new SqlCommand("select * from Empleados Where Usuario = '" + Usuario + "' or Identidad_Empleado='" + Identidad_Empleado + "'", Conexion.Obtenerconexion());
            SqlDataReader reader = sql.ExecuteReader();

            if (reader.Read())
            {
                Identidad_Empleado = reader.GetString(1);
                Usuario            = reader.GetString(7);
                IsExist            = true;
            }
            Conexion.Obtenerconexion().Close();
            if (IsExist == true)
            {
                if (Identidad_Empleado.Equals(textboxIdentidadAgregar.Text) || Usuario.Equals(textboxUsuarioAgregar.Text))
                {
                    MessageBox.Show("Identidad de Empleado o Usuario ya existente", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                if (comboboxPuestoAgregar.Text == "Gerente")
                {
                    int Codigo_Puesto = 1;
                    int Cod_Estado    = 6;
                    if (textboxTelefonoAgregar.Text == "")
                    {
                        SqlCommand insert = new SqlCommand("Insert into Empleados(Identidad_Empleado, Nombre_Empleado, Apellido_Empleado, Celular, Usuario, Contraseña, Codigo_Puesto, Codigo_Estado, Intentos)Values('" + Identidad_Empleado + "', '" + Nombre_Empleado + "', '" + Apellido_Empleado + "', '" + Celular + "','" + Usuario + "', '" + Contraseña + "', '" + Codigo_Puesto + "', '" + Cod_Estado + "', '" + Intentos + "')", Conexion.Obtenerconexion());
                        insert.ExecuteNonQuery();
                        MessageBox.Show("Usuario Creado con Exito.", "Cuenta Creada", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        PreguntasdeSeguridad seguridad = new PreguntasdeSeguridad();
                        InicioSesion         inicio    = new InicioSesion();
                        seguridad.lblUsuario.Text = textboxUsuarioAgregar.Text;
                        this.Hide();
                        inicio.Show();
                    }
                    else if (textboxCelularAgregar.Text == "")
                    {
                        SqlCommand insert = new SqlCommand("Insert into Empleados(Identidad_Empleado, Nombre_Empleado, Apellido_Empleado, , Telefono, Usuario, Contraseña, Codigo_Puesto, Codigo_Estado, Intentos)Values('" + Identidad_Empleado + "', '" + Nombre_Empleado + "', '" + Apellido_Empleado + "', '" + Telefono + "','" + Usuario + "', '" + Contraseña + "', '" + Codigo_Puesto + "', '" + Cod_Estado + "', '" + Intentos + "')", Conexion.Obtenerconexion());
                        insert.ExecuteNonQuery();
                        MessageBox.Show("Usuario Creado con Exito.", "Cuenta Creada", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        PreguntasdeSeguridad seguridad = new PreguntasdeSeguridad();
                        InicioSesion         inicio    = new InicioSesion();
                        seguridad.lblUsuario.Text = textboxUsuarioAgregar.Text;
                        this.Hide();
                        inicio.Show();
                    }
                    else
                    {
                        SqlCommand insert = new SqlCommand("Insert into Empleados(Identidad_Empleado, Nombre_Empleado, Apellido_Empleado, , Telefono, Celular, Usuario, Contraseña, Codigo_Puesto, Codigo_Estado, Intentos)Values('" + Identidad_Empleado + "', '" + Nombre_Empleado + "', '" + Apellido_Empleado + "', '" + Telefono + "', '" + Celular + "','" + Usuario + "', '" + Contraseña + "', '" + Codigo_Puesto + "', '" + Cod_Estado + "', '" + Intentos + "')", Conexion.Obtenerconexion());
                        insert.ExecuteNonQuery();
                        MessageBox.Show("Usuario Creado con Exito.", "Cuenta Creada", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        PreguntasdeSeguridad seguridad = new PreguntasdeSeguridad();
                        InicioSesion         inicio    = new InicioSesion();
                        seguridad.lblUsuario.Text = textboxUsuarioAgregar.Text;
                        this.Hide();
                        inicio.Show();
                    }
                }
                if (comboboxPuestoAgregar.Text == "Cajero")
                {
                    int Codigo_Puesto = 2;
                    int Cod_Estado    = 6;
                    if (textboxTelefonoAgregar.Text == "")
                    {
                        SqlCommand insert = new SqlCommand("Insert into Empleados(Identidad_Empleado, Nombre_Empleado, Apellido_Empleado, Celular, Usuario, Contraseña, Codigo_Puesto, Codigo_Estado, Intentos)Values('" + Identidad_Empleado + "', '" + Nombre_Empleado + "', '" + Apellido_Empleado + "', '" + Celular + "','" + Usuario + "', '" + Contraseña + "', '" + Codigo_Puesto + "', '" + Cod_Estado + "', '" + Intentos + "')", Conexion.Obtenerconexion());
                        insert.ExecuteNonQuery();
                        MessageBox.Show("Usuario Creado con Exito.", "Cuenta Creada", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        PreguntasdeSeguridad seguridad = new PreguntasdeSeguridad();
                        InicioSesion         inicio    = new InicioSesion();
                        seguridad.lblUsuario.Text = textboxUsuarioAgregar.Text;
                        this.Hide();
                        inicio.Show();
                    }
                    else if (textboxCelularAgregar.Text == "")
                    {
                        SqlCommand insert = new SqlCommand("Insert into Empleados(Identidad_Empleado, Nombre_Empleado, Apellido_Empleado, Telefono, Usuario, Contraseña, Codigo_Puesto, Codigo_Estado, Intentos)Values('" + Identidad_Empleado + "', '" + Nombre_Empleado + "', '" + Apellido_Empleado + "', '" + Telefono + "','" + Usuario + "', '" + Contraseña + "', '" + Codigo_Puesto + "', '" + Cod_Estado + "', '" + Intentos + "')", Conexion.Obtenerconexion());
                        insert.ExecuteNonQuery();
                        MessageBox.Show("Usuario Creado con Exito.", "Cuenta Creada", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        PreguntasdeSeguridad seguridad = new PreguntasdeSeguridad();
                        InicioSesion         inicio    = new InicioSesion();
                        seguridad.lblUsuario.Text = textboxUsuarioAgregar.Text;
                        this.Hide();
                        inicio.Show();
                    }
                    else
                    {
                        SqlCommand insert = new SqlCommand("Insert into Empleados(Identidad_Empleado, Nombre_Empleado, Apellido_Empleado, Telefono, Celular, Usuario, Contraseña, Codigo_Puesto, Codigo_Estado, Intentos)Values('" + Identidad_Empleado + "', '" + Nombre_Empleado + "', '" + Apellido_Empleado + "', '" + Telefono + "', '" + Celular + "','" + Usuario + "', '" + Contraseña + "', '" + Codigo_Puesto + "', '" + Cod_Estado + "', '" + Intentos + "')", Conexion.Obtenerconexion());
                        insert.ExecuteNonQuery();
                        MessageBox.Show("Usuario Creado con Exito.", "Cuenta Creada", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        PreguntasdeSeguridad seguridad = new PreguntasdeSeguridad();
                        InicioSesion         inicio    = new InicioSesion();
                        seguridad.lblUsuario.Text = textboxUsuarioAgregar.Text;
                        this.Hide();
                        inicio.Show();
                    }
                }
            }
        }
示例#2
0
        private void IniciarSesion()
        {
            string Codigo_Usuario = "";
            string ID             = "";
            string Usuario        = txtUsuario.Text;
            string Password       = "";
            string Codigo_Estado  = "";
            bool   IsExist        = false;
            int    cont           = 0;

            SqlCommand    cmd = new SqlCommand("select * from Empleados where Usuario ='" + Usuario + "'", Conexion.Obtenerconexion());
            SqlDataReader sdr = cmd.ExecuteReader();

            if (sdr.Read())
            {
                Usuario  = sdr.GetString(6);
                Password = sdr.GetString(7);
                IsExist  = true;
            }
            Conexion.Obtenerconexion().Close();
            if (IsExist)
            {
                if (Usuario.Equals(txtUsuario.Text))
                {
                    SqlCommand sql = new SqlCommand("select Codigo_Estado from Empleados where Usuario ='" + Usuario + "'", Conexion.Obtenerconexion());
                    sql.Parameters.AddWithValue("@Usuario", Codigo_Estado);
                    SqlDataReader reader = sql.ExecuteReader();
                    if (reader.Read())
                    {
                        Codigo_Estado = reader["Codigo_Estado"].ToString();
                    }
                    Conexion.Obtenerconexion().Close();

                    if (Encriptacion.Decrypt(Password).Equals(txtContraseña.Text))
                    {
                        if (Codigo_Estado == "6")
                        {
                            bool       IfExist = false;
                            SqlCommand cd      = new SqlCommand("Select Codigo_Usuario From Empleados Where Codigo_Estado = '" + 6 + "'", Conexion.Obtenerconexion());
                            cd.Parameters.AddWithValue("@Codigo_Estado", Codigo_Usuario);
                            SqlDataReader sq = cd.ExecuteReader();
                            if (sq.Read())
                            {
                                Codigo_Usuario = sq["Codigo_Usuario"].ToString();
                            }
                            ID = Codigo_Usuario;

                            SqlCommand    command    = new SqlCommand("Select * From Respuestas Where Codigo_Usuario = '" + ID + "'", Conexion.Obtenerconexion());
                            SqlDataReader dataReader = command.ExecuteReader();
                            if (dataReader.Read())
                            {
                                Codigo_Usuario = dataReader.GetString(0);
                                IfExist        = true;
                            }
                            if (IfExist)
                            {
                                MessageBox.Show("Su cuenta es nueva. Debe establecer las Preguntas de Seguridad y una nueva contraseña", "Primer Login", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                NuevaContraseña nueva = new NuevaContraseña();
                                nueva.User = Usuario;
                                this.Hide();
                                nueva.Show();
                            }
                            else
                            {
                                MessageBox.Show("Su cuenta es nueva. Debe establecer las Preguntas de Seguridad y una nueva contraseña", "Primer Login", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                PreguntasdeSeguridad seguridad = new PreguntasdeSeguridad();
                                seguridad.lblUsuario.Text = Usuario;
                                this.Hide();
                                seguridad.Show();
                            }
                        }
                        else if (Codigo_Estado == "5")
                        {
                            MessageBox.Show("Su Usuario se encuentra bloqueado", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            RecuperacionContraseña recuperacion = new RecuperacionContraseña();
                            this.Hide();
                            recuperacion.Show();
                        }
                        else if (Codigo_Estado == "2")
                        {
                            MessageBox.Show("Su Usuario esta inactivo. Contacte al Administrador.", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        else if (Codigo_Estado == "1")
                        {
                            MenuPrincipal menu = new MenuPrincipal();
                            menu.lblUsuario.Text = Usuario;
                            this.Hide();
                            menu.Show();
                        }
                    }
                    else
                    {
                        int Intentos = 0;
                        MessageBox.Show("¡Usuario o contraseña incorrecto! Intente nuevamente.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        SqlCommand    command = new SqlCommand("select * from Empleados where Usuario ='" + Usuario + "'", Conexion.Obtenerconexion());
                        SqlDataReader rd      = command.ExecuteReader();
                        if (rd.Read())
                        {
                            Intentos = rd.GetInt32(10);
                            IsExist  = true;
                        }

                        cont++;
                        Intentos = Intentos + cont;
                        cont     = 0;

                        if (Intentos > 2)
                        {
                            SqlCommand update = new SqlCommand(@"Update Empleados Set  Intentos='" + Intentos + "', Codigo_Estado='" + 5 + "' Where Usuario='" + Usuario + "'", Conexion.Obtenerconexion());
                            update.ExecuteNonQuery();
                        }
                        else
                        {
                            SqlCommand update = new SqlCommand(@"Update Empleados Set  Intentos='" + Intentos + "'Where Usuario='" + Usuario + "'", Conexion.Obtenerconexion());
                            update.ExecuteNonQuery();
                        }
                    }
                }
                else
                {
                    MessageBox.Show("¡Usuario incorrecto! Intente nuevamente.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("¡Ingrese su Usuario o Contraseña!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }