Exemple #1
0
 public WinNuevoEmpleado(Common.Empleado empleado)
 {
     InitializeComponent();
     this.empleado = empleado;
     LoadDataEmpleado();
     tbkTItulo.Text = "Modificacion de Datos del Empleado";
     opcion         = 1;
 }
        private void dtgData_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (dtgData.Items.Count > 0 && dtgData.SelectedItem != null)
            {
                if (busquedaEmpleado == 1)
                {
                    try
                    {
                        usuario = null;
                        DataRowView dataRow = (DataRowView)dtgData.SelectedItem;
                        short       id      = short.Parse(dataRow.Row.ItemArray[0].ToString());
                        brlUsuario = new UsuarioBRL();
                        usuario    = brlUsuario.Get(id);

                        LoadDatosUsuario();
                    }
                    catch (Exception err)
                    {
                        MessageBox.Show("Error al insertar el cliente" + err);
                        throw err;
                    }
                }
                else
                {
                    try
                    {
                        empleado = null;
                        DataRowView dataRow = (DataRowView)dtgData.SelectedItem;
                        short       id      = short.Parse(dataRow.Row.ItemArray[0].ToString());
                        brlEmpleado = new EmpleadoBRL();
                        empleado    = brlEmpleado.Get(id);

                        LoadDatosEmpleado();
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
            }
            else
            {
                ClearDataEmpleado();
            }
        }
Exemple #3
0
        private void btnGuardar_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (pathFotografia != string.Empty)
                {
                    switch (opcion)
                    {
                    case 0:     //insertamos
                        empleado    = new Common.Empleado(txtNombres.Text, txtPrimerApellido.Text, txtSegundoApellido.Text, txtCI.Text, cbxSexo.Text, DateTime.Now, txtTelefono.Text, 0, puntoUbicacion.Latitude, puntoUbicacion.Longitude, txtFechaNacimiento.SelectedDate.Value, Sesion.idSesion);
                        brlEmpleado = new EmpleadoBRL(empleado);
                        brlEmpleado.Insert();

                        //capturamos la imagen

                        short id = MethodsBRL.GetMaxIDTable("idEmpleado", "Empleado");

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

                    case 1:    //modificacion
                        //asignacion de valores
                        empleado.Nombres         = txtNombres.Text;
                        empleado.PrimerApellido  = txtPrimerApellido.Text;
                        empleado.SegundoApellido = txtSegundoApellido.Text;
                        empleado.Ci              = txtCI.Text;
                        empleado.Sexo            = cbxSexo.Text;
                        empleado.Telefono        = txtTelefono.Text;
                        empleado.Latitud         = puntoUbicacion.Latitude;
                        empleado.Longitud        = puntoUbicacion.Longitude;
                        empleado.FechaNacimiento = txtFechaNacimiento.SelectedDate.Value;

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

                        brlEmpleado = new EmpleadoBRL(empleado);
                        brlEmpleado.Update();
                        MessageBox.Show("El registro se modifico con exito");

                        this.Close();
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    MessageBox.Show("Es necesario elegir una fotografia del empleado");
                }
            }
            catch (Exception err)
            {
                MessageBox.Show("Error al insertar el cliente" + err);
                throw err;
            }
        }
        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;
            }
        }