Example #1
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            DateTime periodoInicio, periodoFin;
            bool EsAlta = false, EsReingreso = false, EsBaja = false;

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

            Empleados.Core.EmpleadosHelper emph = new Empleados.Core.EmpleadosHelper();
            emph.Command = cmd;

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

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

            Bajas.Core.BajasHelper bh = new Bajas.Core.BajasHelper();
            bh.Command = cmd;

            List<Altas.Core.Altas> lstAlta = new List<Altas.Core.Altas>();
            List<Reingreso.Core.Reingresos> lstReingreso = new List<Reingreso.Core.Reingresos>();
            List<Bajas.Core.Bajas> lstBaja = new List<Bajas.Core.Bajas>();

            Altas.Core.Altas alta = new Altas.Core.Altas();
            alta.idempresa = GLOBALES.IDEMPRESA;
            alta.idtrabajador = idTrabajador;
            alta.periodoInicio = _inicioPeriodo.Date;
            alta.periodoFin = _finPeriodo.Date;

            Reingreso.Core.Reingresos reingreso = new Reingreso.Core.Reingresos();
            reingreso.idempresa = GLOBALES.IDEMPRESA;
            reingreso.idtrabajador = idTrabajador;
            reingreso.periodoinicio = _inicioPeriodo.Date;
            reingreso.periodofin = _finPeriodo.Date;

            Bajas.Core.Bajas baja = new Bajas.Core.Bajas();
            baja.idempresa = GLOBALES.IDEMPRESA;
            baja.idtrabajador = idTrabajador;
            baja.periodoinicio = _inicioPeriodo.Date;
            baja.periodofin = _finPeriodo.Date;

            int idperiodo = 0;
            try
            {
                cnx.Open();
                idperiodo = (int)emph.obtenerIdPeriodo(idTrabajador);

                lstAlta = ah.obtenerAlta(alta);
                lstReingreso = rh.obtenerReingreso(reingreso);
                lstBaja = bh.obtenerBaja(baja);
                cnx.Close();
            }
            catch
            {
                MessageBox.Show("Error: al obtener el Id del Periodo.","Error");
                cnx.Dispose();
                return;
            }

            Periodos.Core.PeriodosHelper ph = new Periodos.Core.PeriodosHelper();
            ph.Command = cmd;

            Periodos.Core.Periodos p = new Periodos.Core.Periodos();
            p.idperiodo = idperiodo;

            int periodo = 0;
            try
            {
                cnx.Open();
                periodo = (int)ph.DiasDePago(p);
                cnx.Close();
            }
            catch
            {
                MessageBox.Show("Error: al obtener los dias de pago.", "Error");
                cnx.Dispose();
                return;
            }

            if (periodo == 7)
            {
                DateTime dt = dtpFecha.Value.Date;
                while (dt.DayOfWeek != DayOfWeek.Monday) dt = dt.AddDays(-1);
                periodoInicio = dt;
                periodoFin = dt.AddDays(6);
            }
            else
            {
                if (dtpFecha.Value.Day <= 15)
                {
                    periodoInicio = new DateTime(dtpFecha.Value.Year, dtpFecha.Value.Month, 1);
                    periodoFin = new DateTime(dtpFecha.Value.Year, dtpFecha.Value.Month, 15);
                }
                else
                {
                    periodoInicio = new DateTime(dtpFecha.Value.Year, dtpFecha.Value.Month, 16);
                    periodoFin = new DateTime(dtpFecha.Value.Year, dtpFecha.Value.Month, DateTime.DaysInMonth(dtpFecha.Value.Year, dtpFecha.Value.Month));
                }
            }

            if (lstAlta.Count != 0)
                EsAlta = true;
            if (lstBaja.Count != 0)
                EsBaja = true;
            if (lstReingreso.Count != 0)
                EsReingreso = true;

            Faltas.Core.FaltasHelper fh = new Faltas.Core.FaltasHelper();
            fh.Command = cmd;

            List<Faltas.Core.Faltas> lstFaltas = new List<Faltas.Core.Faltas>();

            int faltas = int.Parse(txtFalta.Text);
            if (int.Parse(txtFalta.Text) > 15)
                faltas = 15;

            for (int i = 0; i < faltas; i++)
            {
                int existe = 0;
                int existeVacacion = 0;
                try
                {
                    cnx.Open();
                    existe = (int)fh.existeFalta(idTrabajador, dtpFecha.Value.AddDays(i).Date);
                    cnx.Close();
                }
                catch
                {
                    MessageBox.Show("Error: Al verificar existencia de falta.", "Error");
                    cnx.Dispose();
                    return;
                }

                if (existe != 0)
                {
                    MessageBox.Show("Ya existe una falta con esa fecha.", "Error");
                    //return;
                }
                else
                {
                    Incidencias.Core.IncidenciasHelper ih = new Incidencias.Core.IncidenciasHelper();
                    ih.Command = cmd;

                    Vacaciones.Core.VacacionesHelper vh = new Vacaciones.Core.VacacionesHelper();
                    vh.Command = cmd;

                    bool FLAG_FALTAS = false;

                    if (EsAlta)
                    {
                        if (dtpFecha.Value.AddDays(i).Date < lstAlta[0].fechaingreso.Date)
                        {
                            MessageBox.Show("Error: Alta del empleado, Fecha de Ingreso = " + lstAlta[0].fechaingreso.Date.ToShortDateString() + "\r\n Fecha de la falta es menor.", "Error");
                            FLAG_FALTAS = true;
                        }
                        else
                            FLAG_FALTAS = false;
                    }

                    if (EsReingreso)
                    {
                        if (dtpFecha.Value.AddDays(i).Date < lstReingreso[0].fechaingreso.Date)
                        {
                            MessageBox.Show("Error: Alta del empleado, Fecha de Reingreso = " + lstReingreso[0].fechaingreso.Date.ToShortDateString() + "\r\n Fecha de la falta es menor.", "Error");
                            FLAG_FALTAS = true;
                        }
                        else
                            FLAG_FALTAS = false;
                    }

                    if (EsBaja)
                    {
                        if (dtpFecha.Value.AddDays(i).Date > lstBaja[0].fecha.Date)
                        {
                            MessageBox.Show("Error: Alta del empleado, Fecha de Reingreso = " + lstBaja[0].fecha.Date.ToShortDateString() + "\r\n Fecha de la falta es mayor.", "Error");
                            FLAG_FALTAS = true;
                        }
                        else
                            FLAG_FALTAS = false;
                    }

                    if (!FLAG_FALTAS)
                    {
                        try
                        {
                            cnx.Open();
                            existe = (int)ih.existeIncidenciaEnFalta(idTrabajador, dtpFecha.Value.AddDays(i).Date);
                            existeVacacion = (int)vh.existeVacacionEnFalta(idTrabajador, dtpFecha.Value.AddDays(i).Date);
                            cnx.Close();
                        }
                        catch
                        {
                            MessageBox.Show("Error: Al guardar la falta.", "Error");
                            cnx.Dispose();
                            return;
                        }

                        if (existe == 0 && existeVacacion == 0)
                        {
                            Faltas.Core.Faltas falta = new Faltas.Core.Faltas();
                            falta.idtrabajador = idTrabajador;
                            falta.idempresa = GLOBALES.IDEMPRESA;
                            falta.faltas = 1;
                            falta.fechainicio = periodoInicio.Date;
                            falta.fechafin = periodoFin.Date;
                            falta.fecha = dtpFecha.Value.AddDays(i).Date;
                            falta.periodo = periodo;
                            lstFaltas.Add(falta);
                        }
                        else
                            MessageBox.Show("La falta ingresada, se empalma con una incapacidad y/o dia de vacación del trabajador.",
                                "Error");
                    }

                }
            }

            if (lstFaltas.Count != 0)
            {
                SqlBulkCopy bulk = new SqlBulkCopy(cnx);
                fh.bulkCommand = bulk;

                DataTable dtFalta = new DataTable();
                DataRow dtFilaFalta;
                dtFalta.Columns.Add("id", typeof(Int32));
                dtFalta.Columns.Add("idtrabajador", typeof(Int32));
                dtFalta.Columns.Add("idempresa", typeof(Int32));
                dtFalta.Columns.Add("periodo", typeof(Int32));
                dtFalta.Columns.Add("faltas", typeof(Int32));
                dtFalta.Columns.Add("fechainicio", typeof(DateTime));
                dtFalta.Columns.Add("fechafin", typeof(DateTime));
                dtFalta.Columns.Add("fecha", typeof(DateTime));

                for (int i = 0; i < lstFaltas.Count; i++)
                {
                    dtFilaFalta = dtFalta.NewRow();
                    dtFilaFalta["id"] = i + 1;
                    dtFilaFalta["idtrabajador"] = lstFaltas[i].idtrabajador;
                    dtFilaFalta["idempresa"] = lstFaltas[i].idempresa;
                    dtFilaFalta["periodo"] = lstFaltas[i].periodo;
                    dtFilaFalta["faltas"] = lstFaltas[i].faltas;
                    dtFilaFalta["fechainicio"] = lstFaltas[i].fechainicio;
                    dtFilaFalta["fechafin"] = lstFaltas[i].fechafin;
                    dtFilaFalta["fecha"] = lstFaltas[i].fecha;
                    dtFalta.Rows.Add(dtFilaFalta);
                }

                try
                {
                    cnx.Open();
                    fh.bulkFaltas(dtFalta, "tmpFaltas");
                    fh.stpFaltas();
                    cnx.Close();
                    cnx.Dispose();
                    muestraFaltas();
                }
                catch (Exception error)
                {
                    MessageBox.Show("Error: \r\n \r\n" + error.Message + "\r\n \r\n Error Bulk Faltas.", "Error");
                }
            }
        }
        private void toolAplicar_Click(object sender, EventArgs e)
        {
            if (dgvCargaFaltas.Rows.Count == 0)
            {
                MessageBox.Show("No se puede aplicar verifique.", "Error");
                return;
            }

            int idEmpleado = 0;
            bool EsAlta = false, EsReingreso = false, EsBaja = false;

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

            fh = new Faltas.Core.FaltasHelper();
            fh.Command = cmd;

            emph = new Empleados.Core.EmpleadosHelper();
            emph.Command = cmd;

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

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

            Bajas.Core.BajasHelper bh = new Bajas.Core.BajasHelper();
            bh.Command = cmd;

            Periodos.Core.PeriodosHelper ph = new Periodos.Core.PeriodosHelper();
            ph.Command = cmd;

            List<Altas.Core.Altas> lstAlta;
            List<Reingreso.Core.Reingresos> lstReingreso;
            List<Bajas.Core.Bajas> lstBaja;

            foreach (DataGridViewRow fila in dgvCargaFaltas.Rows)
            {
                try
                {
                    cnx.Open();
                    idEmpleado = (int)emph.obtenerIdTrabajador(fila.Cells["noempleado"].Value.ToString(), idEmpresa);
                    cnx.Close();

                }
                catch (Exception error)
                {
                    MessageBox.Show("Error: Obtener ID del empleado. \r\n \r\n" + error.Message, "Error");
                    return;
                }

                int idperiodo = 0;
                try
                {
                    cnx.Open();
                    idperiodo = (int)emph.obtenerIdPeriodo(idEmpleado);
                    cnx.Close();
                }
                catch
                {
                    MessageBox.Show("Error: al obtener el Id del Periodo.", "Error");
                    cnx.Dispose();
                    return;
                }

                Altas.Core.Altas alta = new Altas.Core.Altas();
                alta.idempresa = GLOBALES.IDEMPRESA;
                alta.idtrabajador = idEmpleado;
                alta.periodoInicio = _inicioPeriodo.Date;
                alta.periodoFin = _finPeriodo.Date;

                Reingreso.Core.Reingresos reingreso = new Reingreso.Core.Reingresos();
                reingreso.idempresa = GLOBALES.IDEMPRESA;
                reingreso.idtrabajador = idEmpleado;
                reingreso.periodoinicio = _inicioPeriodo.Date;
                reingreso.periodofin = _finPeriodo.Date;

                Bajas.Core.Bajas baja = new Bajas.Core.Bajas();
                baja.idempresa = GLOBALES.IDEMPRESA;
                baja.idtrabajador = idEmpleado;
                baja.periodoinicio = _inicioPeriodo.Date;
                baja.periodofin = _finPeriodo.Date;

                lstAlta = new List<Altas.Core.Altas>();
                lstReingreso = new List<Reingreso.Core.Reingresos>();
                lstBaja = new List<Bajas.Core.Bajas>();

                Periodos.Core.Periodos p = new Periodos.Core.Periodos();
                p.idperiodo = idperiodo;

                int periodo = 0;
                try
                {
                    cnx.Open();
                    periodo = (int)ph.DiasDePago(p);

                    lstAlta = ah.obtenerAlta(alta);
                    lstReingreso = rh.obtenerReingreso(reingreso);
                    lstBaja = bh.obtenerBaja(baja);
                    cnx.Close();
                }
                catch
                {
                    MessageBox.Show("Error: al obtener los dias de pago.", "Error");
                    cnx.Dispose();
                    return;
                }

                if (lstAlta.Count != 0)
                    EsAlta = true;
                if (lstBaja.Count != 0)
                    EsBaja = true;
                if (lstReingreso.Count != 0)
                    EsReingreso = true;

                int falta = int.Parse(fila.Cells["faltas"].Value.ToString());
                DateTime fecha = DateTime.Parse(fila.Cells["fechainicio"].Value.ToString());

                if (falta > 15)
                    falta = 15;

                for (int i = 0; i < falta; i++)
                {
                    int existe = 0;
                    int existeFalta = 0;
                    int existeVacacion = 0;
                    try
                    {
                        cnx.Open();
                        existeFalta = (int)fh.existeFalta(idEmpleado, fecha.AddDays(i).Date);
                        cnx.Close();
                    }
                    catch
                    {
                        MessageBox.Show("Error: Al verificar existencia de falta.", "Error");
                        cnx.Dispose();
                        return;
                    }

                    if (existeFalta == 0)
                    {
                        Incidencias.Core.IncidenciasHelper ih = new Incidencias.Core.IncidenciasHelper();
                        ih.Command = cmd;

                        Vacaciones.Core.VacacionesHelper vh = new Vacaciones.Core.VacacionesHelper();
                        vh.Command = cmd;

                        bool FLAG_FALTAS = false;

                        if (EsAlta)
                        {
                            if (fecha.AddDays(i).Date < lstAlta[0].fechaingreso.Date)
                            {
                                MessageBox.Show("Error: Alta del empleado: " + fila.Cells["noempleado"].Value.ToString() + ", Fecha de Ingreso = " + lstAlta[0].fechaingreso.Date.ToShortDateString() + "\r\n Fecha de la falta es menor.", "Error");
                                FLAG_FALTAS = true;
                            }
                            else
                                FLAG_FALTAS = false;
                        }

                        if (EsReingreso)
                        {
                            if (fecha.AddDays(i).Date < lstReingreso[0].fechaingreso.Date)
                            {
                                MessageBox.Show("Error: Alta del empleado: " + fila.Cells["noempleado"].Value.ToString() + ", Fecha de Reingreso = " + lstReingreso[0].fechaingreso.Date.ToShortDateString() + "\r\n Fecha de la falta es menor.", "Error");
                                FLAG_FALTAS = true;
                            }
                            else
                                FLAG_FALTAS = false;
                        }

                        if (EsBaja)
                        {
                            if (fecha.AddDays(i).Date > lstBaja[0].fecha.Date)
                            {
                                MessageBox.Show("Error: Alta del empleado " + fila.Cells["noempleado"].Value.ToString() +
                                    ", Fecha de Reingreso = " + lstBaja[0].fecha.Date.ToShortDateString() +
                                    "\r\n Fecha de la falta es mayor.", "Error");
                                FLAG_FALTAS = true;
                            }
                            else
                                FLAG_FALTAS = false;
                        }

                        if (!FLAG_FALTAS)
                        {
                            try
                            {
                                cnx.Open();
                                existe = (int)ih.existeIncidenciaEnFalta(idEmpleado, fecha.AddDays(i).Date);
                                existeVacacion = (int)vh.existeVacacionEnFalta(idEmpleado, fecha.AddDays(i).Date);
                                cnx.Close();
                            }
                            catch
                            {
                                MessageBox.Show("Error: Al guardar la falta.", "Error");
                                cnx.Dispose();
                                return;
                            }

                            if (existe == 0 && existeVacacion == 0)
                                try
                                {
                                    Faltas.Core.Faltas f = new Faltas.Core.Faltas();
                                    f.idempresa = GLOBALES.IDEMPRESA;
                                    f.idtrabajador = idEmpleado;
                                    f.periodo = periodo;
                                    f.faltas = 1;
                                    f.fechainicio = DateTime.Parse(dgvCargaFaltas.Rows[0].Cells["fechainicio"].Value.ToString());
                                    f.fechafin = DateTime.Parse(dgvCargaFaltas.Rows[0].Cells["fechafin"].Value.ToString());
                                    f.fecha = fecha.AddDays(i).Date;

                                    cnx.Open();
                                    fh.insertaFalta(f);
                                    cnx.Close();
                                }
                                catch
                                {
                                    MessageBox.Show("Error: Al guardar la falta.", "Error");
                                    cnx.Dispose();
                                }
                            else
                                MessageBox.Show("La falta ingresada, se empalma con una incapacidad y/o dia de vacación del trabajador.", "Error");
                        }
                    }
                }
                EsAlta = false; EsReingreso = false; EsBaja = false;
            }
            MessageBox.Show("Faltas importadas", "Confirmación");
            cnx.Dispose();
            dgvCargaFaltas.Rows.Clear();
        }
        private void dgvFaltas_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (FLAGCARGA)
            {
                FLAGCARGA = false;
                return;
            }

            if (dgvFaltas.Columns[e.ColumnIndex].Name.ToString() == "")
                return;
            if (dgvFaltas.Rows[e.RowIndex].Cells[dgvFaltas.Columns[e.ColumnIndex].Name.ToString()].Value.ToString() == "" ||
                dgvFaltas.Rows[e.RowIndex].Cells[dgvFaltas.Columns[e.ColumnIndex].Name.ToString()].Value.ToString() == "0")
                return;

            try
            {
                int.Parse(dgvFaltas.Rows[e.RowIndex].Cells[dgvFaltas.Columns[e.ColumnIndex].Name.ToString()].Value.ToString());
            }
            catch
            {
                MessageBox.Show("Dato incorrecto. SOLO NUMEROS.", "Información");
                dgvFaltas.Rows[e.RowIndex].Cells[dgvFaltas.Columns[e.ColumnIndex].Name.ToString()].Value = "";
                return;
            }

            int existe = 0, existeVacacion = 0;
            int faltas = int.Parse(dgvFaltas.Rows[e.RowIndex].Cells[dgvFaltas.Columns[e.ColumnIndex].Name.ToString()].Value.ToString());
            DateTime fechaColumna = DateTime.Parse(dgvFaltas.Columns[e.ColumnIndex].Name.ToString());

            if (faltas > 1 || faltas < 0)
            {
                MessageBox.Show("Solo se admite el valor de 1 falta por dia.", "Información");
                dgvFaltas.Rows[e.RowIndex].Cells[dgvFaltas.Columns[e.ColumnIndex].Name.ToString()].Value = "";
                return;
            }

            cnx = new SqlConnection(cdn);
            cmd = new SqlCommand();
            cmd.Connection = cnx;
            Incidencias.Core.IncidenciasHelper ih = new Incidencias.Core.IncidenciasHelper();
            ih.Command = cmd;

            Vacaciones.Core.VacacionesHelper vh = new Vacaciones.Core.VacacionesHelper();
            vh.Command = cmd;

            try
            {
                cnx.Open();
                existe = (int)ih.existeIncidenciaEnFalta(int.Parse(dgvFaltas.Rows[e.RowIndex].Cells["idtrabajadorfalta"].Value.ToString()), fechaColumna.Date);
                existeVacacion = (int)vh.existeVacacionEnFalta(int.Parse(dgvFaltas.Rows[e.RowIndex].Cells["idtrabajadorfalta"].Value.ToString()), fechaColumna.Date);
                cnx.Close();
            }
            catch
            {
                MessageBox.Show("Error: \r\n \r\n No se pudo verificar la incapacidad, verifique.", "Error");
                dgvFaltas.Rows[e.RowIndex].Cells[dgvFaltas.Columns[e.ColumnIndex].Name.ToString()].Value = "";
                cnx.Dispose();
            }

            if (existe == 0 && existeVacacion == 0)
            {
                fh = new Faltas.Core.FaltasHelper();
                fh.Command = cmd;
                Faltas.Core.Faltas falta = new Faltas.Core.Faltas();
                falta.idtrabajador = int.Parse(dgvFaltas.Rows[e.RowIndex].Cells["idtrabajadorfalta"].Value.ToString());
                falta.idempresa = GLOBALES.IDEMPRESA;
                falta.periodo = _periodo;
                falta.faltas = int.Parse(dgvFaltas.Rows[e.RowIndex].Cells[dgvFaltas.Columns[e.ColumnIndex].Name.ToString()].Value.ToString());
                falta.fechainicio = periodoInicio.Date;
                falta.fechafin = periodoFin.Date;
                falta.fecha = DateTime.Parse(dgvFaltas.Columns[e.ColumnIndex].Name.ToString());

                try
                {
                    cnx.Open();
                    fh.insertaFalta(falta);
                    cnx.Close();
                    cnx.Dispose();
                }
                catch
                {
                    MessageBox.Show("Error: \r\n \r\n Se ingreso un valor incorrecto, verifique.", "Error");
                    dgvFaltas.Rows[e.RowIndex].Cells[dgvFaltas.Columns[e.ColumnIndex].Name.ToString()].Value = "";
                    cnx.Dispose();
                }
            }
            else
            {
                MessageBox.Show("La falta ingresada, se empalma con una incapacidad y/o dia de vacación del trabajador.", "Error");
                dgvFaltas.Rows[e.RowIndex].Cells[dgvFaltas.Columns[e.ColumnIndex].Name.ToString()].Value = "";
            }

            #region CODIGO COMENTADO
            //if (dgvFaltas.Columns[e.ColumnIndex].Name == "falta")
            //{
            //    if (int.Parse(dgvFaltas.Rows[e.RowIndex].Cells["falta"].Value.ToString()) > _periodo)
            //    {
            //        MessageBox.Show("La falta ingresada es mayor al periodo. Verifique", "Error");
            //        dgvFaltas.Rows[e.RowIndex].Cells["falta"].Value = 0;
            //        return;
            //    }

            //    if (dgvFaltas.Rows[e.RowIndex].Cells["falta"].Value.ToString() != "0")
            //    {
            //        if (dgvFaltas.Rows[e.RowIndex].Cells["incapacidad"].Value.ToString() != "0")
            //        {
            //            borraIncapacidad(e.ColumnIndex + 1, e.RowIndex);
            //            dgvFaltas.Rows[e.RowIndex].Cells["incapacidad"].Value = 0;
            //        }

            //        cnx = new SqlConnection(cdn);
            //        cmd = new SqlCommand();
            //        cmd.Connection = cnx;
            //        fh = new Faltas.Core.FaltasHelper();
            //        fh.Command = cmd;
            //        Faltas.Core.Faltas falta = new Faltas.Core.Faltas();
            //        falta.idtrabajador = int.Parse(dgvFaltas.Rows[e.RowIndex].Cells["idtrabajadorfalta"].Value.ToString());
            //        falta.idempresa = GLOBALES.IDEMPRESA;
            //        falta.periodo = _periodo;
            //        falta.faltas = int.Parse(dgvFaltas.Rows[e.RowIndex].Cells["falta"].Value.ToString());
            //        falta.fechainicio = dtpPeriodoInicio.Value.Date;
            //        falta.fechafin = dtpPeriodoFin.Value.Date;

            //        try
            //        {
            //            cnx.Open();
            //            fh.insertaFalta(falta);
            //            cnx.Close();
            //            cnx.Dispose();
            //        }
            //        catch (Exception error)
            //        {
            //            MessageBox.Show("Error: \r\n \r\n Se ingreso un valor incorrecto, verifique.", "Error");
            //            dgvFaltas.Rows[e.RowIndex].Cells["falta"].Value = 0;
            //            cnx.Dispose();
            //        }
            //    }
            //    else
            //    {
            //        borraFalta(e.ColumnIndex, e.RowIndex);
            //    }
            //}

            //if (dgvFaltas.Columns[e.ColumnIndex].Name == "incapacidad")
            //{
            //    if (int.Parse(dgvFaltas.Rows[e.RowIndex].Cells["incapacidad"].Value.ToString()) > _periodo)
            //    {
            //        MessageBox.Show("La incapacidad ingresada es mayor al periodo. Verifique", "Error");
            //        dgvFaltas.Rows[e.RowIndex].Cells["incapacidad"].Value = 0;
            //        return;
            //    }

            //    if (dgvFaltas.Rows[e.RowIndex].Cells["incapacidad"].Value.ToString() != "0")
            //    {
            //        if (dgvFaltas.Rows[e.RowIndex].Cells["falta"].Value.ToString() != "0")
            //        {
            //            borraFalta(e.ColumnIndex - 1, e.RowIndex);
            //            dgvFaltas.Rows[e.RowIndex].Cells["falta"].Value = 0;
            //        }

            //        cnx = new SqlConnection(cdn);
            //        cmd = new SqlCommand();
            //        cmd.Connection = cnx;
            //        ih = new Incapacidad.Core.IncapacidadHelper();
            //        ih.Command = cmd;
            //        Incapacidad.Core.Incapacidades incapacidad = new Incapacidad.Core.Incapacidades();
            //        incapacidad.idtrabajador = int.Parse(dgvFaltas.Rows[e.RowIndex].Cells["idtrabajadorfalta"].Value.ToString());
            //        incapacidad.idempresa = GLOBALES.IDEMPRESA;
            //        incapacidad.diasincapacidad = 0;
            //        incapacidad.diastomados = int.Parse(dgvFaltas.Rows[e.RowIndex].Cells["incapacidad"].Value.ToString());
            //        incapacidad.diasrestantes = 0;
            //        incapacidad.diasapagar = 0;
            //        incapacidad.tipo = 0;
            //        incapacidad.aplicada = 1;
            //        incapacidad.consecutiva = 1;
            //        incapacidad.fechainicio = dtpPeriodoInicio.Value.Date;
            //        incapacidad.fechafin = dtpPeriodoFin.Value.Date;

            //        try
            //        {
            //            cnx.Open();
            //            ih.insertaIncapacidad(incapacidad);
            //            cnx.Close();
            //            cnx.Dispose();
            //        }
            //        catch (Exception error)
            //        {
            //            MessageBox.Show("Error: \r\n \r\n Se ingreso un valor incorrecto, verifique.", "Error");
            //            dgvFaltas.Rows[e.RowIndex].Cells["incapacidad"].Value = 0;
            //            cnx.Dispose();
            //        }
            //    }
            //    else
            //    {
            //        borraIncapacidad(e.ColumnIndex, e.RowIndex);
            //    }
            //}
            #endregion
        }