public void GenerarNuevaContrasena(string email)
        {
            Random obj      = new Random();
            string posibles = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
            int    longitud = posibles.Length;

            char letra;

            int longitudnuevacadena = 5;

            string nuevacadena = "";

            for (int i = 0; i < longitudnuevacadena; i++)

            {
                letra = posibles[obj.Next(longitud)];

                nuevacadena += letra.ToString();
            }

            SqlConnection cn  = DataBase.Conexion();
            SqlCommand    cmd = new SqlCommand("NuevaContra", cn);

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("@correo", email);
            cmd.Parameters.AddWithValue("@contrasena", enc.EncryptKey(nuevacadena));
            try
            {
                // cn.Open();
                int filasAfectadas = cmd.ExecuteNonQuery();
                if (filasAfectadas != 0)
                {
                    EnviarCorreoContrasena(nuevacadena, email);
                }
            }
            catch
            {
            }
        }
        private void bt_modificar_Click(object sender, EventArgs e)
        {
            actualizarImagen(Convert.ToInt32(lb_numeroID.Text), pictureBox1);

            try
            {
                if (ValidarCampos())
                {
                    //MODIGICAR EMPLEADO, SOLO ES NECESARIO CAMBIAR EL COMANDO PARA USARLO EN OTRA TABLA Y LISTO
                    //Escribimos los campos que queremos modificar
                    string actualizar = "Nombre= '" + txtNombre.Text + "', Direccion = '" + txtDireccion.Text + "', Email = '" + txtEmail.Text + "', Telefono = '" + txtTelefono.Text + "', Sexo = '" + cb_sexo.Text + "', DUI = '" + txtDUI.Text + "', NIT = '" + txtNIT.Text + "', Sueldo = '" + txtSueldo.Text + "', Usuario = '" + txtUser.Text + "', Contraseña = '" + enc.EncryptKey(tb_contraseña.Text) + "', Cargo = '" + cb_cargo.Text + "', Activo = '" + obtenerEstado() + "'";
                    //le pasamos los parametros de nuestro metodo Actualizar que se encuentra en la clase DataBase
                    if (db.Actualizar("Empleado", actualizar, "IdEmpleado =" + lb_numeroID.Text))
                    {
                        MessageBox.Show("Empleado actualizado", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.Close();
                        emp.Show();
                    }
                    else
                    {
                        MessageBox.Show("No se pudo modificar el empleado", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                }
            }
            catch (Exception)
            {
                MessageBox.Show("No se pudo modificar el empleado, seleccione Cancelar y vuelva a intentarlo", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #3
0
 private void bt_modificar_Click(object sender, EventArgs e)
 {
     try
     {
         if (ValidarCampos())
         {
             if (txtSueldo.Text == "")
             {
                 txtSueldo.Text = 0.00.ToString();
                 if (db.SiExiste("Empleado", "DUI", txtDUI.Text) == false)
                 {
                     MessageBox.Show("Ya existe un empleado con el mismo DUI, por favor ingrese un empleado diferente", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
                 else
                 {
                     //AGREGAR EMPLEADO, SOLO ES NECESARIO CAMBIAR EL COMANDO PARA USARLOS EN OTRA TABLA Y LISTO
                     string agregar = "insert into Empleado values( '" + txtNombre.Text + "', '" + txtDireccion.Text + "', '" + txtEmail.Text + "', '" + txtTelefono.Text + "','" + cb_sexo.Text + "','" + txtDUI.Text + "','" + txtNIT.Text + "','" + txtSueldo.Text + "', '" + txtUser.Text + "','" + enc.EncryptKey(tb_contraseña.Text) + "', '" + cb_cargo.Text + "', '" + obtenerEstado() + "')";
                     //llamamos a la clase DataBase con el metodo Insertar y le pasamos el parametro
                     if (db.Insertar(agregar))
                     {
                         insertarImagen(traerIDventa(), pictureBox1);
                         MessageBox.Show("Empleado agregado", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);
                         this.Close();
                         emp.Show();
                     }
                     else
                     {
                         MessageBox.Show("No se pudo agregar el empleado", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Error);
                     }
                 }
             }
             else
             {
                 //AGREGAR EMPLEADO, SOLO ES NECESARIO CAMBIAR EL COMANDO PARA USARLO EN OTRA TABLA Y LISTO
                 string agregar = "insert into Empleado values( '" + txtNombre.Text + "', '" + txtDireccion.Text + "', '" + txtEmail.Text + "', '" + txtTelefono.Text + "','" + cb_sexo.Text + "','" + txtDUI.Text + "','" + txtNIT.Text + "','" + txtSueldo.Text + "', '" + txtUser.Text + "','" + enc.EncryptKey(tb_contraseña.Text) + "', '" + cb_cargo.Text + "', '" + obtenerEstado() + "')";
                 //llamamos a la clase DataBase con el metodo Insertar y le pasamos el parametro
                 if (db.Insertar(agregar))
                 {
                     insertarImagen(traerIDventa(), pictureBox1);
                     MessageBox.Show("Empleado agregado", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     this.Close();
                     emp.Show();
                 }
                 else
                 {
                     MessageBox.Show("No se pudo agregar el empleado", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
         }
         else
         {
         }
     }
     catch (Exception)
     {
         MessageBox.Show("No se pudo agregar el empleado, seleccione Cancelar y vuelva a intentarlo", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }