Ejemplo n.º 1
0
        private void dtpSeleccionaFecha_ValueChanged(object sender, EventArgs e)
        {
            cnx = new SqlConnection(cdn);
            cmd = new SqlCommand();
            cmd.Connection = cnx;

            int existe = 0;

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

            if (_tipoNomina != GLOBALES.EXTRAORDINARIO_NORMAL)
            {
                if (_periodo == 7)
                {
                    DateTime dt = dtpSeleccionaFecha.Value.Date;
                    while (dt.DayOfWeek != DayOfWeek.Monday) dt = dt.AddDays(-1);

                    dtpPeriodoInicio.Value = dt;
                    dtpPeriodoFin.Value = dt.AddDays(6);

                    periodoInicio = dtpPeriodoInicio.Value.Date;
                    periodoFin = dtpPeriodoFin.Value.Date;
                }
                else
                {
                    if (dtpSeleccionaFecha.Value.Day <= 15)
                    {
                        dtpPeriodoInicio.Value = new DateTime(dtpSeleccionaFecha.Value.Year, dtpSeleccionaFecha.Value.Month, 1);
                        dtpPeriodoFin.Value = new DateTime(dtpSeleccionaFecha.Value.Year, dtpSeleccionaFecha.Value.Month, 15);
                    }
                    else
                    {
                        dtpPeriodoInicio.Value = new DateTime(dtpSeleccionaFecha.Value.Year, dtpSeleccionaFecha.Value.Month, 16);
                        dtpPeriodoFin.Value = new DateTime(dtpSeleccionaFecha.Value.Year, dtpSeleccionaFecha.Value.Month, DateTime.DaysInMonth(dtpSeleccionaFecha.Value.Year, dtpSeleccionaFecha.Value.Month));
                    }
                    periodoInicio = dtpPeriodoInicio.Value.Date;
                    periodoFin = dtpPeriodoFin.Value.Date;
                }

                try
                {
                    cnx.Open();
                    existe = (int)nh.existeNomina(GLOBALES.IDEMPRESA, periodoInicio.Date, periodoFin.Date, _periodo);
                    cnx.Close();
                    if (existe != 0)
                    {
                        MessageBox.Show("NOMINA CALCULADA \r\n \r\n " +
                                            "El periodo seleccionado se encuenta: \r\n " +
                                            "Calculado y Autorizado.", "Información");
                        btnAceptar.Enabled = false;
                    }
                    else
                    {
                        btnAceptar.Enabled = true;
                    }
                }
                catch (Exception error)
                {
                    MessageBox.Show("Error: \r\n \r\n" + error.Message, "Error");
                }
            }
            else
            {
                periodoInicio = dtpSeleccionaFecha.Value.Date;
                periodoFin = dtpSeleccionaFecha.Value.Date;
                btnAceptar.Enabled = true;
            }
        }
Ejemplo n.º 2
0
        void cp_OnNuevoPeriodo(DateTime inicio, DateTime fin)
        {
            periodoInicio = inicio;
            periodoFin = fin;
            borraGridFaltas();
            disenoGridFaltas();
            cargaEmpleadosFaltas();

            if (_tipoNomina != GLOBALES.EXTRAORDINARIO_NORMAL)
            {
                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
            {
                cnx = new SqlConnection(cdn);
                cmd = new SqlCommand();
                cmd.Connection = cnx;
                nh = new CalculoNomina.Core.NominaHelper();
                nh.Command = cmd;

                int existeNominaExtraordinaria = 0;
                try
                {
                    cnx.Open();
                    existeNominaExtraordinaria = (int)nh.existeNomina(GLOBALES.IDEMPRESA, periodoInicio, periodoFin, _periodo);
                    cnx.Close();
                    cnx.Dispose();
                }
                catch (Exception)
                {
                    MessageBox.Show("Error: Al obtener la existencia de la nomina extraordinaria.\r\n \r\n SE CERRARÁ LA VENTANA.", "Error");
                    cnx.Dispose();
                    this.Dispose();
                }

                if (existeNominaExtraordinaria == 0)
                {
                    this.Text = String.Format("Pago extraordinario: Del {0}.", periodoInicio.ToShortDateString());
                    toolPeriodo.Text = String.Format("Pago extraordinario: Del {0}.", periodoInicio.ToShortDateString());
                    movimientosEspeciales();
                }
                else
                {
                    MessageBox.Show("La fecha seleccionada ya ha sido calculada. \r\n \r\n SE CERRARÁ LA VENTANA.", "Información");
                    this.Dispose();
                }

            }
        }