Beispiel #1
0
        private void BtnGuardar_Click(object sender, RoutedEventArgs e)
        {
            switch (opcion)
            {
            case 1:

                try
                {
                    user = new Common.Usuario(txtNombre.Text, txtprimerAp.Text, txtSegundoApellido.Text, txtCi.Text, int.Parse(txtTelefono.Text), txtDireccion.Text, txtEmail.Text, DateTime.Parse(dtfecha.ToString()), txtRol.Text, txtNombreUsuario.Text, txtPassword.Password);
                    brl  = new UsuarioBRL(user);
                    brl.Insert();

                    MessageBox.Show("Proveedor insertado con exito...");
                    FillDataGrid();
                    DesHabilitar();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("error al insert  " + ex.Message);
                }
                break;

            case 2:
                try
                {
                    user.Nombre          = txtNombre.Text;
                    user.NombreUsuario   = txtNombreUsuario.Text;
                    user.PrimerApellido  = txtprimerAp.Text;
                    user.SegundoApellido = txtSegundoApellido.Text;
                    user.Ci            = txtCi.Text;
                    user.Telefono      = int.Parse(txtTelefono.Text);
                    user.Direccion     = txtDireccion.Text;
                    user.Rol           = txtRol.Text;
                    user.Password      = txtPassword.Password;
                    user.FechaRegistro = DateTime.Parse(dtfecha.ToString());
                    user.Email         = txtEmail.Text;
                    brl = new UsuarioBRL(user);
                    brl.Update();



                    MessageBox.Show(" Proveedor Modificado con exito...");
                    FillDataGrid();

                    DesHabilitar();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error al modificar " + ex.Message);
                }
                break;
            }
        }
        private void btnGuardar_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (pathFotografia != string.Empty)
                {
                    switch (opcion)
                    {
                    case 0:
                        empleado = new Common.Empleado(txtNombres.Text, txtPrimerApellido.Text, txtSegundoApellido.Text, txtCI.Text, cbxSexo.Text, DateTime.Now, txtTelefono.Text, 1, puntoUbicacion.Latitude, puntoUbicacion.Longitude, txtFechaNacimiento.SelectedDate.Value, Sesion.idSesion);
                        // string usua = nombreUsuario(txtNombres.Text, txtPrimerApellido.Text);
                        //string clave = contraseña(txtNombres.Text, txtPrimerApellido.Text);
                        // MessageBox.Show("Usuario: " + usua + " Password: "******"Usuario: " + txtUsuario.Text + " Password: "******"idEmpleado", "Empleado");

                        //se copia la imagen
                        File.Copy(pathFotografia, Config.pathFotoUsuario + id + ".jpg");
                        MessageBox.Show("Correcto");
                        break;

                    case 1:     //Modificacion
                        usuario.Nombres         = txtNombres.Text;
                        usuario.PrimerApellido  = txtPrimerApellido.Text;
                        usuario.SegundoApellido = txtSegundoApellido.Text;
                        usuario.Ci       = txtCI.Text;
                        usuario.Sexo     = cbxSexo.Text;
                        usuario.Telefono = txtTelefono.Text;
                        usuario.Latitud  = puntoUbicacion.Latitude;
                        usuario.Longitud = puntoUbicacion.Longitude;

                        //IMAGEN
                        if (pathFotografia != pathFotoUsuarioServer)
                        {
                            GC.Collect();
                            GC.WaitForPendingFinalizers();
                            if (usuario.Foto == 1)
                            {
                                File.Delete(pathFotoUsuarioServer);
                                File.Copy(pathFotografia, Config.pathFotoUsuario + usuario.IdUsuario + ".jpg");
                            }
                            else
                            {
                                File.Copy(pathFotografia, Config.pathFotoUsuario + usuario.IdUsuario + ".jpg");
                            }
                            //File.Delete(pathFotoEmpleadoServer);
                            //File.Copy(pathFotografia, Config.pathFotoEmpleado + empleado.IdEmpleado + ".jpg");
                        }

                        brl = new UsuarioBRL(usuario);
                        brl.Update();
                        MessageBox.Show("El registro se modifico con exito");

                        this.Close();
                        break;
                    }
                }
                else
                {
                    MessageBox.Show("Es necesario registrar una fotografia");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #3
0
        private void BtnGuardarUsuario_Click(object sender, RoutedEventArgs e)
        {
            txtcorreoAg.IsEnabled = true;
            switch (operacion)
            {
            case 1:
                if (txtnombresAg.Text == "" && txtnombresAg.Text.Length < 3 && txtprimerapellidoAg.Text == "" && txtprimerapellidoAg.Text.Length < 3 && txtsegundoApellidoAg.Text.Length < 3 && txtsegundoApellidoAg.Text == "" && txtcorreoAg.Text == "")
                {
                    MessageBox.Show("Debe Llenar los campos para poder agregar un registro");
                }
                else
                {
                    txtnombresAg.Text        = txtnombresAg.Text.Trim();
                    txtprimerapellidoAg.Text = txtprimerapellidoAg.Text.Trim();


                    string rol = "";
                    if (rbtAdmin.IsChecked == true)
                    {
                        rol = rol + "Administrador";
                    }
                    else if (rbtEditor.IsChecked == true)
                    {
                        rol = rol + "Editor";
                    }
                    else if (rbtVend.IsChecked == true)
                    {
                        rol = rol + "Vendedor";
                    }



                    string sexo = "";
                    if (rbtHombre.IsChecked == true)
                    {
                        sexo = sexo + "1";
                    }
                    else
                    if (rbtMujer.IsChecked == true)
                    {
                        sexo = sexo + "2";
                    }
                    //Ususario
                    Random rdno        = new Random();
                    string caracteres1 = "abcdefghijklmnopqrstuvwxyzaawe1234567890";
                    int    longitud1   = caracteres1.Length;
                    char   letra1;
                    int    longituddat     = 3;
                    string datosaleatorios = string.Empty;
                    for (int i = 0; i < longituddat; i++)
                    {
                        letra1           = caracteres1[rdno.Next(longitud1)];
                        datosaleatorios += letra1.ToString();
                    }
                    string datosRan = datosaleatorios;
                    string usuario1 = txtnombresAg.Text;
                    string usuario2 = txtprimerapellidoAg.Text;
                    if (usuario1.Length > 2 && usuario2.Length > 2)
                    {
                        userName = usuario1.Substring(0, 3) + usuario2.Substring(0, 3) + datosRan;
                    }
                    else
                    {
                        MessageBox.Show("Ingrese correctamente los datos");
                    }

                    //Contrasenia
                    Random rdn        = new Random();
                    string caracteres = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
                    int    longitud   = caracteres.Length;
                    char   letra;
                    int    longitudContrasenia  = 6;
                    string contraseniaAleatoria = string.Empty;
                    for (int i = 0; i < longitudContrasenia; i++)
                    {
                        letra = caracteres[rdn.Next(longitud)];
                        contraseniaAleatoria += letra.ToString();
                    }
                    string contrasenia = contraseniaAleatoria;

                    if (txtcorreoAg.Text.Contains("gmail.com"))
                    {
                        txtcorreoAg.Text = txtcorreoAg.Text.Trim();
                        #region enviar correo
                        System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
                        msg.To.Add(txtcorreoAg.Text);
                        msg.Subject         = "Registrado para usar el sistema cubestore";
                        msg.SubjectEncoding = System.Text.Encoding.UTF8;

                        msg.Body         = "Hola que tal Bienvenido a cubestore " + txtnombresAg.Text + " " + txtprimerapellidoAg + "\n";
                        msg.Body         = "Sus credenciales para ingreso son:\n" + "Usuario:  " + userName + "\nContrseña:  " + contrasenia;
                        msg.BodyEncoding = System.Text.Encoding.UTF8;
                        msg.IsBodyHtml   = true;
                        msg.From         = new System.Net.Mail.MailAddress("*****@*****.**");

                        System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
                        client.Credentials = new System.Net.NetworkCredential("*****@*****.**", "Cristofer246");
                        client.Port        = 587;
                        client.EnableSsl   = true;
                        client.Host        = "smtp.gmail.com";
                        #endregion

                        try
                        {
                            DateTime fecha = DateTime.Now;
                            usuario = new Usuario(txtnombresAg.Text.Trim(), txtprimerapellidoAg.Text.Trim(), txtsegundoApellidoAg.Text.Trim(), byte.Parse(sexo), userName, contrasenia, rol, txtcorreoAg.Text, fecha);
                            brl     = new UsuarioBRL(usuario);
                            brl.Insert();
                            client.Send(msg);
                            MessageBox.Show("Usuario Agregado Exitosamente");
                            LimpiarCamposAg();
                            DesHabilitar();
                            txtcorreoAg.IsEnabled = false;
                            LoadDataGrid();
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("Error al enviar el correo intente nuevamente");
                        }
                    }
                    else
                    {
                        MessageBox.Show("El correo debe estar en un formato correcto");
                    }
                }
                break;

            case 2:
                if (txtnombresAg.Text == "")
                {
                    MessageBox.Show("Seleccione un registro de la lista para modificarlo");
                }
                else
                {
                    try
                    {
                        txtcorreoAg.IsEnabled = false;
                        //Modificar
                        //categoria = new Categoria(txtnombreCategoria.Text);
                        usuario.Nombres         = txtnombresAg.Text.Trim();
                        usuario.PrimerApellido  = txtprimerapellidoAg.Text.Trim();
                        usuario.SegundoApellido = txtsegundoApellidoAg.Text.Trim();
                        usuario.Correo          = txtcorreoAg.Text.Trim();
                        brl = new UsuarioBRL(usuario);
                        brl.Update();
                        MessageBox.Show("Registro Modificado Exitosamente");
                        LimpiarCamposAg();
                        DesHabilitar();
                        LoadDataGrid();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Ocurrio un error comuniquese con el administrador de sistemas");
                    }
                }
                break;
            }
        }