示例#1
0
        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;
            }
        }