Files
compabetoOG/Empleados/AgregarEmpleado.cs
T
2024-01-22 02:36:18 -07:00

131 lines
4.3 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.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace compabetov2
{
public partial class AgregarEmpleado : Form
{
private personal ventanaPersonal;
private string imagenPath = "";
public AgregarEmpleado(personal ventanaPersonal)
{
InitializeComponent();
this.ventanaPersonal = ventanaPersonal;
}
private void label1_Click(object sender, EventArgs e)
{
}
private void flowLayoutPanel2_Paint(object sender, PaintEventArgs e)
{
}
private void btnAgregar_Click(object sender, EventArgs e)
{
string nombre = txtNombre.Text;
string apellidos = txtApellido.Text;
string calle = txtCalle.Text;
string fechaCon = dtFechaCon.Text;
string estado = cbEstado.Text;
string colonia = txtColonia.Text;
string cp = txtCp.Text;
string noExt = txtNoExt.Text;
string noInt = txtNoInt.Text;
string referencia = txtReferencia.Text;
string fechaNac = dtFechaNac.Text;
string telefono = txtTelefono.Text;
Empleado empleado = new Empleado(-1, nombre,apellidos,calle,fechaCon,estado,colonia
,cp,noExt,noInt,referencia,fechaNac,telefono);
if (service.insertarEmpleado(empleado))
{
ventanaPersonal.llenarPanel();
MessageBox.Show($"Empleado {nombre} agreado", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void AgregarEmpleado_Load(object sender, EventArgs e)
{
}
private void flowLayoutPanel2_Paint_1(object sender, PaintEventArgs e)
{
}
private void openFileDialog1_FileOk(object sender, CancelEventArgs 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)
{
imagenPath = openFileDialog1.FileName;
lbImg.Text = $"Imagen: {Path.GetFileName(imagenPath)}";
string destinationFolder = Path.Combine(Application.StartupPath, "Resources", "usuarios");
//string destinationFile = Path.Combine(destinationFolder, Path.GetFileName(sourceFile));
//File.Copy(sourceFile, destinationFile, true);
}
}
private void label1_Click_1(object sender, EventArgs e)
{
}
private void btnAgregar_Click_1(object sender, EventArgs e)
{
string nombre = txtNombre.Text;
string apellidos = txtApellido.Text;
string calle = txtCalle.Text;
string fechaCon = dtFechaCon.Text;
string estado = cbEstado.Text;
string colonia = txtColonia.Text;
string cp = txtCp.Text;
string noExt = txtNoExt.Text;
string noInt = txtNoInt.Text;
string referencia = txtReferencia.Text;
string fechaNac = dtFechaNac.Text;
string telefono = txtTelefono.Text;
Empleado empleado = new Empleado(-1, nombre, apellidos, calle, fechaCon, estado, colonia
, cp, noExt, noInt, referencia, fechaNac, telefono, Path.GetFileName(imagenPath));
if (service.insertarEmpleado(empleado))
{
if (!imagenPath.Equals("")) {
string destinationFolder = Path.Combine(Application.StartupPath, "Resources", "usuarios");
string destinationFile = Path.Combine(destinationFolder, Path.GetFileName(imagenPath));
File.Copy(imagenPath, destinationFile, true);
}
ventanaPersonal.llenarPanel();
Close();
}
}
}
}