private void toolGuardar_Click(object sender, EventArgs e)
        {
            cnx = new SqlConnection();
            cnx.ConnectionString = cdn;
            cmd = new SqlCommand();
            cmd.Connection = cnx;

            eh = new Empleados.Core.EmpleadosHelper();
            hh = new Historial.Core.HistorialHelper();
            mh = new Modificaciones.Core.ModificacionesHelper();
            eh.Command = cmd;
            hh.Command = cmd;
            mh.Command = cmd;

            Empleados.Core.Empleados empleado = new Empleados.Core.Empleados();
            empleado.idtrabajador = _idempleado;
            empleado.sdi = decimal.Parse(txtSDI.Text);
            empleado.sd = decimal.Parse(txtSD.Text);
            empleado.sueldo = decimal.Parse(txtSueldo.Text);

            Historial.Core.Historial historia = new Historial.Core.Historial();
            historia.idtrabajador = _idempleado;
            historia.idempresa = GLOBALES.IDEMPRESA;
            historia.tipomovimiento = GLOBALES.mMODIFICACIONSALARIO;
            historia.valor = decimal.Parse(txtSDI.Text);
            historia.fecha_imss = dtpFecha.Value;
            historia.fecha_sistema = DateTime.Now;
            historia.motivobaja = 0;

            if (departamento)
                historia.iddepartamento = int.Parse(cmbDepartamento.SelectedValue.ToString());
            else
                historia.iddepartamento = iddepto;

            if (puesto)
                historia.idpuesto = int.Parse(cmbPuesto.SelectedValue.ToString());
            else
                historia.idpuesto = idpuesto;

            Modificaciones.Core.Modificaciones mod = new Modificaciones.Core.Modificaciones();
            mod.idtrabajador = _idempleado;
            mod.idempresa = GLOBALES.IDEMPRESA;
            mod.registropatronal = rp;
            mod.nss = nss;
            mod.fecha = dtpFecha.Value;
            mod.sdi = decimal.Parse(txtSDI.Text);

            aplih = new Aplicaciones.Core.AplicacionesHelper();
            aplih.Command = cmd;
            Aplicaciones.Core.Aplicaciones aDepto = new Aplicaciones.Core.Aplicaciones();
            Aplicaciones.Core.Aplicaciones aPuesto = new Aplicaciones.Core.Aplicaciones();

            try {
                cnx.Open();
                eh.actualizaSueldo(empleado);
                hh.insertarHistorial(historia);
                mh.insertaModificacion(mod);

                if (departamento)
                {
                    Historial.Core.Historial historiaDepto = new Historial.Core.Historial();
                    historiaDepto.idtrabajador = _idempleado;
                    historiaDepto.idempresa = GLOBALES.IDEMPRESA;
                    historiaDepto.tipomovimiento = GLOBALES.mCAMBIODEPARTAMENTO;
                    historiaDepto.valor = decimal.Parse(txtSDI.Text);
                    historiaDepto.fecha_imss = dtpFecha.Value;
                    historiaDepto.fecha_sistema = DateTime.Now;
                    historiaDepto.motivobaja = 0;
                    historiaDepto.iddepartamento = int.Parse(cmbDepartamento.SelectedValue.ToString());
                    historiaDepto.idpuesto = idpuesto;
                    hh.insertarHistorial(historiaDepto);

                    aDepto = new Aplicaciones.Core.Aplicaciones();
                    aDepto.idtrabajador = _idempleado;
                    aDepto.idempresa = GLOBALES.IDEMPRESA;
                    aDepto.iddeptopuesto = int.Parse(cmbDepartamento.SelectedValue.ToString());
                    aDepto.deptopuesto = "D";
                    aDepto.fecha = dtpFecha.Value.Date;
                    aDepto.registro = DateTime.Now.Date;
                    aDepto.idusuario = GLOBALES.IDUSUARIO;
                    aDepto.periodoinicio = inicioPeriodo;
                    aDepto.periodofin = finPeriodo;
                    aplih.insertaAplicacion(aDepto);
                }

                if (puesto)
                {
                    Historial.Core.Historial historiaPuesto = new Historial.Core.Historial();
                    historiaPuesto.idtrabajador = _idempleado;
                    historiaPuesto.idempresa = GLOBALES.IDEMPRESA;
                    historiaPuesto.tipomovimiento = GLOBALES.mCAMBIOPUESTO;
                    historiaPuesto.valor = decimal.Parse(txtSDI.Text);
                    historiaPuesto.fecha_imss = dtpFecha.Value;
                    historiaPuesto.fecha_sistema = DateTime.Now;
                    historiaPuesto.motivobaja = 0;
                    historiaPuesto.iddepartamento = int.Parse(cmbDepartamento.SelectedValue.ToString());
                    historiaPuesto.idpuesto = int.Parse(cmbPuesto.SelectedValue.ToString());
                    hh.insertarHistorial(historiaPuesto);

                    aPuesto = new Aplicaciones.Core.Aplicaciones();
                    aPuesto.idtrabajador = _idempleado;
                    aPuesto.idempresa = GLOBALES.IDEMPRESA;
                    aPuesto.iddeptopuesto = int.Parse(cmbPuesto.SelectedValue.ToString());
                    aPuesto.deptopuesto = "P";
                    aPuesto.fecha = dtpFecha.Value.Date;
                    aPuesto.registro = DateTime.Now.Date;
                    aPuesto.idusuario = GLOBALES.IDUSUARIO;
                    aPuesto.periodoinicio = inicioPeriodo;
                    aPuesto.periodofin = finPeriodo;
                    aplih.insertaAplicacion(aPuesto);
                }

                cnx.Close();
                cnx.Dispose();

                MessageBox.Show("Incremento aplicado.", "ConfirmaciĆ³n");

                if (OnIncrementoSalarial != null)
                    OnIncrementoSalarial();
            }
            catch (Exception error) {
                MessageBox.Show("Error: \r\n \r\n " + error.Message, "Error");
            }
            this.Dispose();
        }
        private void ListaEmpleados()
        {
            string cdn = ConfigurationManager.ConnectionStrings["cdnNomina"].ConnectionString;
            cnx = new SqlConnection(cdn);
            cmd = new SqlCommand();
            cmd.Connection = cnx;
            mh = new Modificaciones.Core.ModificacionesHelper();
            eh = new Empleados.Core.EmpleadosHelper();
            mh.Command = cmd;
            eh.Command = cmd;

            Modificaciones.Core.Modificaciones mod = new Modificaciones.Core.Modificaciones();
            mod.idempresa = GLOBALES.IDEMPRESA;

            Empleados.Core.Empleados empleado = new Empleados.Core.Empleados();
            empleado.idempresa = GLOBALES.IDEMPRESA;
            empleado.estatus = GLOBALES.ACTIVO;

            try
            {
                cnx.Open();
                lstMod = mh.obtieneModificaciones(mod);
                lstEmpleados = eh.obtenerEmpleados(empleado);
                cnx.Close();
                cnx.Dispose();

                var modif = from m in lstMod
                         join t in lstEmpleados on m.idtrabajador equals t.idtrabajador
                         select new
                         {
                             RegistroPatronal = m.registropatronal,
                             Nss = m.nss,
                             Nombre = t.nombrecompleto,
                             Modificacion = m.fecha,
                             Integrado = m.sdi
                         };
                dgvModSua.DataSource = modif.ToList();

                for (int i = 0; i < dgvModSua.Columns.Count; i++)
                {
                    dgvModSua.AutoResizeColumn(i);
                }
            }
            catch (Exception error)
            {
                MessageBox.Show("Error: \r\n \r\n " + error.Message, "Error");
            }
        }
        private void ListaEmpleados(int operacion)
        {
            string cdn = ConfigurationManager.ConnectionStrings["cdnNomina"].ConnectionString;
            cnx = new SqlConnection(cdn);
            cmd = new SqlCommand();
            cmd.Connection = cnx;

            eh = new Empleados.Core.EmpleadosHelper();
            eh.Command = cmd;
            Empleados.Core.Empleados empleado = new Empleados.Core.Empleados();
            empleado.idempresa = GLOBALES.IDEMPRESA;
            empleado.estatus = GLOBALES.ACTIVO;

            switch (operacion)
            {
                #region ALTAS
                case 0: //ALTAS
                    ah = new Altas.Core.AltasHelper();
                    ah.Command = cmd;
                    Altas.Core.Altas alta = new Altas.Core.Altas();
                    alta.idempresa = GLOBALES.IDEMPRESA;
                    try
                    {
                        cnx.Open();
                        lstAltas = ah.obtenerAltas(alta);
                        cnx.Close();
                        cnx.Dispose();

                        var alt = from a in lstAltas
                                  select new
                                  {
                                      RegistroPatronal = a.registropatronal,
                                      Nss = a.nss,
                                      Curp = a.curp,
                                      ApPaterno = a.paterno,
                                      ApMaterno = a.materno,
                                      Nombre = a.nombre,
                                      Ingreso = a.fechaingreso,
                                      Integrado = a.sdi
                                  };
                        dgvDatos.DataSource = alt.ToList();
                    }
                    catch (Exception error)
                    {
                        MessageBox.Show("Error: \r\n \r\n " + error.Message, "Error");
                    }
                    break;
                #endregion

                #region MODIFICACIONES
                case 1: //MODIFICACIONES
                    mh = new Modificaciones.Core.ModificacionesHelper();
                    mh.Command = cmd;
                    Modificaciones.Core.Modificaciones modificacion = new Modificaciones.Core.Modificaciones();
                    modificacion.idempresa = GLOBALES.IDEMPRESA;
                    try
                    {
                        cnx.Open();
                        lstMod = mh.obtieneModificaciones(modificacion);
                        lstEmpleado = eh.obtenerEmpleados(empleado);
                        cnx.Close();
                        cnx.Dispose();

                        var mod = from m in lstMod
                                  join e in lstEmpleado on m.idtrabajador equals e.idtrabajador
                                  select new
                                  {
                                      RegistroPatronal = m.registropatronal,
                                      Nss = m.nss,
                                      Paterno = e.paterno,
                                      Materno = e.materno,
                                      Nombre = e.nombres,
                                      Curp = e.curp,
                                      Fecha = m.fecha,
                                      Integrado = m.sdi
                                  };
                        dgvDatos.DataSource = mod.ToList();
                    }
                    catch (Exception error)
                    {
                        MessageBox.Show("Error: \r\n \r\n " + error.Message, "Error");
                    }
                    break;
                #endregion

                #region BAJAS
                case 2://BAJAS
                    bh = new Bajas.Core.BajasHelper();
                    ch = new Catalogos.Core.CatalogosHelper();
                    bh.Command = cmd;
                    ch.Command = cmd;
                    Bajas.Core.Bajas baja = new Bajas.Core.Bajas();
                    Catalogos.Core.Catalogo catalogo = new Catalogos.Core.Catalogo();
                    baja.idempresa = GLOBALES.IDEMPRESA;
                    try
                    {
                        cnx.Open();
                        lstBaja = bh.obtenerBajas(baja);
                        lstEmpleado = eh.obtenerEmpleados(empleado);
                        lstCatalogo = ch.obtenerCatalogos();
                        cnx.Close();
                        cnx.Dispose();

                        var baj = from b in lstBaja
                                  join e in lstEmpleado on b.idtrabajador equals e.idtrabajador
                                  join c in lstCatalogo on b.motivo equals c.id
                                  select new
                                  {
                                      RegistroPatronal = b.registropatronal,
                                      Nss = b.nss,
                                      Paterno = e.paterno,
                                      Materno = e.materno,
                                      Nombre = e.nombres,
                                      Fecha = b.fecha,
                                      Motivo = c.valor
                                  };
                        dgvDatos.DataSource = baj.ToList();
                    }
                    catch (Exception error)
                    {
                        MessageBox.Show("Error: \r\n \r\n " + error.Message, "Error");
                    }
                    break;
                #endregion
            }
            for (int i = 0; i < dgvDatos.Columns.Count; i++)
            {
                dgvDatos.AutoResizeColumn(i);
            }
        }