using compabetov2.database.modelos; using compabetov2.database; 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.Empleados { public partial class EditarEmpleado1 : Form { private Empleado empleado; private personal ventanaPadre; private string imagePath; public EditarEmpleado1(Empleado empleado, personal ventanaPadre) { InitializeComponent(); this.empleado = empleado; this.ventanaPadre = ventanaPadre; imagePath = Path.Combine(Application.StartupPath, "Resources", "usuarios", empleado.img); llenarCampos(); txtCp.KeyPress += new KeyPressEventHandler(PermitirSoloNumeros); // Suscribir al evento KeyPress para el TextBox txtNoExt txtNoExt.KeyPress += new KeyPressEventHandler(PermitirSoloNumeros); // Suscribir al evento KeyPress para el TextBox txtNoInt txtNoInt.KeyPress += new KeyPressEventHandler(PermitirSoloNumeros); // Suscribir al evento KeyPress para el TextBox txtNombre txtNombre.KeyPress += new KeyPressEventHandler(PermitirSoloLetras); // Suscribir al evento KeyPress para el TextBox txtApellido txtApellido.KeyPress += new KeyPressEventHandler(PermitirSoloLetras); } 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 label1_Click(object sender, EventArgs e) { } private void button1_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)}"; } } private void pictureBox2_Click(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 EditarEmpleado1_Load(object sender, EventArgs e) { } private void pictureBox1_Click(object sender, EventArgs e) { this.Close(); } private void PermitirSoloNumeros(object sender, KeyPressEventArgs e) { // Verificar si la tecla presionada no es un número o la tecla de retroceso if (!char.IsDigit(e.KeyChar) && e.KeyChar != 8) { e.Handled = true; // Ignorar la tecla presionada // Mostrar un mensaje indicando que solo se permiten números MessageBox.Show("Por favor, ingrese solo números.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void PermitirSoloLetras(object sender, KeyPressEventArgs e) { // Verificar si la tecla presionada no es una letra o la tecla de retroceso if (!char.IsLetter(e.KeyChar) && e.KeyChar != 8 && e.KeyChar != 32) { e.Handled = true; // Ignorar la tecla presionada // Mostrar un mensaje indicando que solo se permiten letras MessageBox.Show("Por favor, ingrese solo letras.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void pictureBox3_Click(object sender, EventArgs e) { } } }