Files
compabetoOG/EditarEmpleado.cs
T

115 lines
3.6 KiB
C#

using compabetov2.database;
using compabetov2.database.modelos;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace compabetov2
{
public partial class EditarEmpleado : Form
{
private Empleado empleado;
private personal ventanaPadre;
private string imagePath;
public EditarEmpleado(Empleado empleado, personal ventanaPadre)
{
InitializeComponent();
this.empleado = empleado;
this.ventanaPadre = ventanaPadre;
imagePath = Path.Combine(Application.StartupPath, "Resources", "usuarios", empleado.img);
llenarCampos();
}
private void llenarCampos()
{
txtNombre.Text = empleado.nombre;
txtApellido.Text = empleado.apellidos;
txtCalle.Text = empleado.calle;
txtColonia.Text = empleado.colonia;
txtCp.Text = empleado.cp;
txtNoExt.Text = empleado.no_ext;
txtNoInt.Text = empleado.no_int;
txtReferencia.Text = empleado.referencia;
txtTelefono.Text = empleado.telefono;
dtFechaCon.Text = empleado.fecha_contratacion;
dtFechaNac.Text = empleado.fecha_nac;
cbEstado.Text = empleado.estado;
lbImg.Text = $"Imagen: {Path.GetFileName(imagePath)}";
}
private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
}
private void btnCancelar_Click(object sender, EventArgs e)
{
}
private void button1_Click_1(object sender, EventArgs e)
{
Empleado empleadoNuevo = new Empleado(
empleado.idempleado,
txtNombre.Text,
txtApellido.Text,
txtCalle.Text,
dtFechaCon.Text,
cbEstado.Text,
txtColonia.Text,
txtCp.Text,
txtNoExt.Text,
txtNoInt.Text,
txtReferencia.Text,
dtFechaNac.Text,
txtTelefono.Text,
Path.GetFileName(imagePath));
if (service.actualizarEmpleado(empleadoNuevo))
{
if (!empleado.img.Equals(empleadoNuevo.img))
{
string destinationFolder = Path.Combine(Application.StartupPath, "Resources", "usuarios");
string destinationFile = Path.Combine(destinationFolder, Path.GetFileName(imagePath));
File.Copy(imagePath, destinationFile, true);
}
ventanaPadre.llenarPanel();
Close();
}
}
private void btnCancelar_Click_1(object sender, EventArgs e)
{
Close();
}
private void btnImg_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "Archivos de imagen (*.jpg, *.jpeg, *.png, *.bmp)|*.jpg;*.jpeg;*.png;*.bmp";
openFileDialog1.Title = "Seleccionar imagen";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
imagePath = openFileDialog1.FileName;
lbImg.Text = $"Imagen: {Path.GetFileName(imagePath)}";
}
}
}
}