private void ChecaFechaAltaReingreso()
        {
            DateTime inicio = DateTime.Now.Date, fin = DateTime.Now.Date;

            cnx = new SqlConnection(cdn);
            cmd = new SqlCommand();
            cmd.Connection = cnx;

            Altas.Core.AltasHelper ah = new Altas.Core.AltasHelper();
            ah.Command = cmd;

            Reingreso.Core.ReingresoHelper rh = new Reingreso.Core.ReingresoHelper();
            rh.Command = cmd;

            CalculoNomina.Core.NominaHelper nh = new CalculoNomina.Core.NominaHelper();
            nh.Command = cmd;

            List<CalculoNomina.Core.tmpPagoNomina> lstUltimaNomina = new List<CalculoNomina.Core.tmpPagoNomina>();

            try
            {
                cnx.Open();
                lstUltimaNomina = nh.obtenerUltimaNomina(GLOBALES.IDEMPRESA, false);
                cnx.Close();
            }
            catch (Exception error)
            {
                MessageBox.Show("Error: \r\n \r\n" + error.Message, "Error");
            }

            if (lstUltimaNomina.Count != 0)
            {
                if (Periodo == 7)
                {
                    inicio = lstUltimaNomina[0].fechafin.AddDays(1);
                    fin = lstUltimaNomina[0].fechafin.AddDays(7);
                }
                else
                {
                    inicio = lstUltimaNomina[0].fechafin.AddDays(1);
                    if (inicio.Day <= 15)
                        fin = lstUltimaNomina[0].fechafin.AddDays(15);
                    else
                        fin = new DateTime(inicio.Year, inicio.Month,
                            DateTime.DaysInMonth(inicio.Year, inicio.Month));
                }
            }

            Altas.Core.Altas a = new Altas.Core.Altas();
            a.idtrabajador = _idEmpleado;
            a.periodoInicio = inicio.Date;
            a.periodoFin = fin.Date;

            Reingreso.Core.Reingresos r = new Reingreso.Core.Reingresos();
            r.idtrabajador = _idEmpleado;
            r.periodoinicio = inicio.Date;
            r.periodofin = fin.Date;

            int existeAlta = 0;
            int existeReingreso = 0;

            try
            {
                cnx.Open();
                existeAlta = (int)ah.existeAlta(a);
                existeReingreso = (int)rh.existeReingreso(r);
                cnx.Close();
            }
            catch (Exception)
            {
                MessageBox.Show("Error: Al obtener la existencia de la alta.", "Error");
                cnx.Dispose();
            }

            DateTime fechaAlta = DateTime.Now.Date;
            DateTime fechaReingreso = DateTime.Now.Date;
            if (existeAlta != 0)
            {
                try
                {
                    cnx.Open();
                    fechaAlta = DateTime.Parse(ah.fechaAlta(a).ToString());
                    cnx.Close();
                }
                catch (Exception)
                {
                    MessageBox.Show("Error: Al obtener la fecha de alta.", "Error");
                    cnx.Dispose();
                }

                if (dtpFechaAplicacion.Value.Date < fechaAlta)
                    dtpFechaAplicacion.Value = fechaAlta;
            }

            if (existeReingreso != 0)
            {
                try
                {
                    cnx.Open();
                    fechaReingreso = DateTime.Parse(rh.fechaReingreso(r).ToString());
                    cnx.Close();
                }
                catch (Exception)
                {
                    MessageBox.Show("Error: Al obtener la fecha de alta.", "Error");
                    cnx.Dispose();
                }

                if (dtpFechaAplicacion.Value.Date < fechaReingreso)
                    dtpFechaAplicacion.Value = fechaReingreso;
            }
        }
        private void obtenerPeriodoCalculo()
        {
            cnx = new SqlConnection(cdn);
            cmd = new SqlCommand();
            cmd.Connection = cnx;

            nh = new CalculoNomina.Core.NominaHelper();
            nh.Command = cmd;

            List<CalculoNomina.Core.tmpPagoNomina> lstUltimaNomina = new List<CalculoNomina.Core.tmpPagoNomina>();

            if (_tipoNomina != GLOBALES.EXTRAORDINARIO_NORMAL)
            {
                try
                {
                    cnx.Open();
                    lstUltimaNomina = nh.obtenerUltimaNomina(GLOBALES.IDEMPRESA, GLOBALES.NORMAL, _periodo);
                    cnx.Close();
                }
                catch (Exception error)
                {
                    MessageBox.Show("Error: \r\n \r\n" + error.Message, "Error");
                }

                if (lstUltimaNomina.Count != 0)
                {
                    if (_periodo == 7)
                    {
                        periodoInicio = lstUltimaNomina[0].fechafin.AddDays(1);
                        periodoFin = lstUltimaNomina[0].fechafin.AddDays(7);
                        periodoInicioPosterior = periodoFin.AddDays(1);
                        periodoFinPosterior = periodoFin.AddDays(7);

                        if (_obracivil)
                        {
                            try
                            {
                                lstUltimaNomina = new List<CalculoNomina.Core.tmpPagoNomina>();
                                cnx.Open();
                                lstUltimaNomina = nh.obtenerUltimaNomina(GLOBALES.IDEMPRESA, _obracivil);
                                cnx.Close();

                                if (lstUltimaNomina[0].guardada)
                                {
                                    periodoInicio = lstUltimaNomina[0].fechafin.AddDays(1);
                                    periodoFin = lstUltimaNomina[0].fechafin.AddDays(7);
                                    periodoInicioPosterior = periodoFin.AddDays(1);
                                    periodoFinPosterior = periodoFin.AddDays(7);
                                }
                                else
                                {
                                    periodoInicio = lstUltimaNomina[0].fechainicio;
                                    periodoFin = lstUltimaNomina[0].fechafin;
                                    periodoInicioPosterior = periodoFin.AddDays(1);
                                    periodoFinPosterior = periodoFin.AddDays(7);
                                }
                            }
                            catch (Exception error)
                            {
                                MessageBox.Show("Error: PreNomina de Obra Civil.\r\n \r\n" + error.Message, "Error");
                            }
                        }
                    }
                    else
                    {
                        periodoInicio = lstUltimaNomina[0].fechafin.AddDays(1);

                        if (periodoInicio.Day <= 15)
                            periodoFin = lstUltimaNomina[0].fechafin.AddDays(15);
                        else
                            periodoFin = new DateTime(periodoInicio.Year, periodoInicio.Month,
                                DateTime.DaysInMonth(periodoInicio.Year, periodoInicio.Month));

                        periodoInicioPosterior = periodoFin.AddDays(1);
                        if (periodoInicioPosterior.Day <= 15)
                            periodoFinPosterior = periodoFin.AddDays(15);
                        else
                            periodoFinPosterior = new DateTime(periodoInicioPosterior.Year, periodoInicioPosterior.Month,
                                DateTime.DaysInMonth(periodoInicioPosterior.Year, periodoInicioPosterior.Month));
                    }

                }
                else
                {
                    DateTime dt = DateTime.Now.Date;
                    if (_periodo == 7)
                    {
                        while (dt.DayOfWeek != DayOfWeek.Monday) dt = dt.AddDays(-1);
                        periodoInicio = dt;
                        periodoFin = dt.AddDays(6);
                        periodoInicioPosterior = periodoFin.AddDays(1);
                        periodoFinPosterior = periodoFin.AddDays(7);
                    }
                    else
                    {

                        if (dt.Day <= 15)
                        {
                            periodoInicio = new DateTime(dt.Year, dt.Month, 1);
                            periodoFin = new DateTime(dt.Year, dt.Month, 15);
                            periodoInicioPosterior = periodoFin.AddDays(1);
                            periodoFinPosterior = new DateTime(periodoInicioPosterior.Year, periodoInicioPosterior.Month,
                                DateTime.DaysInMonth(periodoInicioPosterior.Year, periodoInicioPosterior.Month) - 15);
                        }
                        else
                        {
                            periodoInicio = new DateTime(dt.Year, dt.Month, 16);
                            periodoFin = new DateTime(dt.Year, dt.Month, DateTime.DaysInMonth(dt.Year, dt.Month));
                            periodoInicioPosterior = periodoFin.AddDays(1);
                            periodoFinPosterior = periodoFin.AddDays(15);
                        }
                    }
                }
                this.Text = String.Format("Periodo de Pago: Del {0} al {1}.", periodoInicio.ToShortDateString(), periodoFin.ToShortDateString());
                toolPeriodo.Text = String.Format("Periodo de Pago: Del {0} al {1}.", periodoInicio.ToShortDateString(), periodoFin.ToShortDateString());
            }
            else
            {
                periodoInicio = DateTime.Now.Date;
                periodoFin = DateTime.Now.Date;

                this.Text = String.Format("Pago extraordinario: Del {0}.", periodoInicio.ToShortDateString());
                toolPeriodo.Text = String.Format("Pago extraordinario: Del {0}.", periodoInicio.ToShortDateString());
            }
        }