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 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 toolGuardar_Click(object sender, EventArgs e) { int existe = 0; if (_idEmpleado == 0) { MessageBox.Show("No ha seleccionado al Empleado.", "Información"); return; } //SE VALIDA SI TODOS LOS CAMPOS HAN SIDO LLENADOS. string control = GLOBALES.VALIDAR(this, typeof(TextBox)); if (!control.Equals("")) { MessageBox.Show("Falta el campo: " + control, "Información"); return; } cnx = new SqlConnection(cdn); cmd = new SqlCommand(); bulk = new SqlBulkCopy(cnx); cmd.Connection = cnx; Faltas.Core.FaltasHelper fh = new Faltas.Core.FaltasHelper(); fh.Command = cmd; DateTime finIncapacidad = dtpFechaInicio.Value.AddDays(double.Parse(txtDiasIncapacidad.Text) - 1); int a = 0; int existeFalta = 0; bool FLAGFALTAS = false; Incidencias.Core.IncidenciasHelper incidenciah = new Incidencias.Core.IncidenciasHelper(); incidenciah.Command = cmd; DateTime fii, ffi; bool FLAG_FINICIO = false, FLAG_FFIN = false; List<Incidencias.Core.Incidencias> datoFechas = new List<Incidencias.Core.Incidencias>(); try { cnx.Open(); datoFechas = incidenciah.finIncapacidad(_idEmpleado); cnx.Close(); } catch { MessageBox.Show("Error: Al obtener la ultima fecha de incapacidad.", "Error"); cnx.Dispose(); return; } if (datoFechas.Count != 0) { fii = dtpFechaInicio.Value.Date; ffi = dtpFechaInicio.Value.AddDays(int.Parse(txtDiasIncapacidad.Text) - 1); for (int i = 0; i < datoFechas.Count; i++) { if (fii.Date <= datoFechas[i].finincapacidad.Date) { FLAG_FINICIO = true; } if (ffi.Date >= datoFechas[i].inicioincapacidad.Date) { FLAG_FFIN = true; } } //ffi = DateTime.Parse(datoFecha.ToString()); if (FLAG_FINICIO && FLAG_FFIN) { MessageBox.Show("Las fechas de la incapacidad se empalman con una ya existente.", "Información"); return; } else if (FLAG_FINICIO) { MessageBox.Show("Las fechas de la incapacidad se empalman con una ya existente.", "Información"); return; } } while (dtpFechaInicio.Value.AddDays(a).Date <= finIncapacidad.Date) { try { cnx.Open(); existeFalta = (int)fh.existeFalta(_idEmpleado, dtpFechaInicio.Value.AddDays(a).Date); cnx.Close(); } catch { MessageBox.Show("Error: Al obtener la existencia de faltas.", "Error"); cnx.Dispose(); return; } if (existeFalta != 0) { try { cnx.Open(); fh.eliminaFalta(_idEmpleado, dtpFechaInicio.Value.AddDays(a).Date); FLAGFALTAS = true; cnx.Close(); } catch { MessageBox.Show("Error: Al eliminar la falta existente.", "Error"); cnx.Dispose(); return; } } a++; } if (FLAGFALTAS) MessageBox.Show("Se encontraron faltas al momento de ingresar la incapacidad. \r\n \r\n Estas se quitaron.", "Confirmación"); ih = new Incidencias.Core.IncidenciasHelper(); ih.Command = cmd; ih.bulkCommand = bulk; Incidencias.Core.Incidencias incidencia = new Incidencias.Core.Incidencias(); incidencia.certificado = txtCertificado.Text.Trim(); List<Incidencias.Core.Incidencias> lstIncidencias; try { cnx.Open(); existe = int.Parse(ih.existeCertificado(incidencia).ToString()); cnx.Close(); } catch (Exception error) { MessageBox.Show("Error al consultar el certificado. \r\n \r\n Descripcion: " + error.Message, "Error"); } if (existe == 0) { PeriodoFechaAplicacion(); DateTime fechaInicioIncapacidad = dtpFechaInicio.Value.Date; DateTime fechaFinIncapacidad = dtpFechaInicio.Value.AddDays(double.Parse(txtDiasIncapacidad.Text) - 1).Date; //DateTime fechaFinPeriodo = dtpFinPeriodo.Value.Date; DateTime fechaFinPeriodo = periodoFin.Date; int diasRestantes = int.Parse(txtDiasIncapacidad.Text); int dias = 0; bool FLAG = false; lstIncidencias = new List<Incidencias.Core.Incidencias>(); int i = 1; while (diasRestantes != 0) { if (fechaFinIncapacidad <= fechaFinPeriodo) { Incidencias.Core.Incidencias incidencia2 = new Incidencias.Core.Incidencias(); incidencia2.id = i; incidencia2.idtrabajador = _idEmpleado; incidencia2.idempresa = GLOBALES.IDEMPRESA; incidencia2.certificado = txtCertificado.Text.Trim(); incidencia2.inicioincapacidad = dtpFechaInicio.Value; incidencia2.finincapacidad = dtpFechaInicio.Value.AddDays(double.Parse(txtDiasIncapacidad.Text) - 1); incidencia2.periodoinicio = periodoInicio.Date; incidencia2.periodofin = periodoFin.Date; incidencia2.idcontrol = int.Parse(cmbTipoCaso.SelectedValue.ToString()); incidencia2.idincapacidad = int.Parse(cmbTipoIncapacidad.SelectedValue.ToString()); dias = diasRestantes; incidencia2.dias = dias; incidencia2.fechainicio = fechaInicioIncapacidad.Date; incidencia2.fechafin = fechaFinIncapacidad.Date; lstIncidencias.Add(incidencia2); } else { Incidencias.Core.Incidencias incidencia2 = new Incidencias.Core.Incidencias(); incidencia2.id = i; incidencia2.idtrabajador = _idEmpleado; incidencia2.idempresa = GLOBALES.IDEMPRESA; incidencia2.certificado = txtCertificado.Text.Trim(); incidencia2.inicioincapacidad = dtpFechaInicio.Value; incidencia2.finincapacidad = dtpFechaInicio.Value.AddDays(double.Parse(txtDiasIncapacidad.Text) - 1); incidencia2.periodoinicio = periodoInicio.Date; incidencia2.periodofin = periodoFin.Date; incidencia2.idcontrol = int.Parse(cmbTipoCaso.SelectedValue.ToString()); incidencia2.idincapacidad = int.Parse(cmbTipoIncapacidad.SelectedValue.ToString()); if (!FLAG) { dias = (int)(fechaFinPeriodo - fechaInicioIncapacidad).TotalDays + 1; incidencia2.dias = dias; incidencia2.fechainicio = fechaInicioIncapacidad.Date; incidencia2.fechafin = fechaFinPeriodo.Date; fechaInicioIncapacidad = fechaFinPeriodo.AddDays(1); if (periodo == 7) fechaFinPeriodo = fechaFinPeriodo.AddDays(periodo); else { if (fechaInicioIncapacidad.Day <= 15) { fechaFinPeriodo = fechaFinPeriodo.AddDays(periodo); } else { fechaFinPeriodo = new DateTime(fechaFinPeriodo.Year, fechaFinPeriodo.Month, DateTime.DaysInMonth(fechaFinPeriodo.Year, fechaFinPeriodo.Month)); } } FLAG = true; } else { if (diasRestantes > periodo) { dias = (int)(fechaFinPeriodo - fechaInicioIncapacidad).TotalDays + 1; incidencia2.dias = dias; incidencia2.fechainicio = fechaInicioIncapacidad.Date; incidencia2.fechafin = fechaFinPeriodo.Date; fechaInicioIncapacidad = fechaFinPeriodo.AddDays(1); if (periodo == 7) fechaFinPeriodo = fechaFinPeriodo.AddDays(periodo); else { if (fechaInicioIncapacidad.Day <= 15) { fechaFinPeriodo = fechaFinPeriodo.AddDays(periodo); } else { fechaFinPeriodo = new DateTime(fechaFinPeriodo.Year, fechaFinPeriodo.Month, DateTime.DaysInMonth(fechaFinPeriodo.Year, fechaFinPeriodo.Month)); } } } } lstIncidencias.Add(incidencia2); } diasRestantes = diasRestantes - dias; i++; } } else { MessageBox.Show("El certificado que intenta guardar ya existe.", "Error"); return; } switch (_tipoForma) { case 0://ALTA EN BASE DE DATOS DataTable dt = new DataTable(); DataRow dtFila; dt.Columns.Add("id", typeof(Int32)); dt.Columns.Add("idtrabajador", typeof(Int32)); dt.Columns.Add("idempresa", typeof(Int32)); dt.Columns.Add("dias", typeof(Int32)); dt.Columns.Add("certificado", typeof(String)); dt.Columns.Add("inicioincapacidad", typeof(DateTime)); dt.Columns.Add("finincapacidad", typeof(DateTime)); dt.Columns.Add("fechainicio", typeof(DateTime)); dt.Columns.Add("fechafin", typeof(DateTime)); dt.Columns.Add("periodoinicio", typeof(DateTime)); dt.Columns.Add("periodofin", typeof(DateTime)); dt.Columns.Add("idcontrol", typeof(Int32)); dt.Columns.Add("idincapacidad", typeof(Int32)); for (int i = 0; i < lstIncidencias.Count; i++) { dtFila = dt.NewRow(); dtFila["id"] = lstIncidencias[i].id; dtFila["idtrabajador"] = lstIncidencias[i].idtrabajador; dtFila["idempresa"] = lstIncidencias[i].idempresa; dtFila["dias"] = lstIncidencias[i].dias; dtFila["certificado"] = lstIncidencias[i].certificado; dtFila["inicioincapacidad"] = lstIncidencias[i].inicioincapacidad; dtFila["finincapacidad"] = lstIncidencias[i].finincapacidad; dtFila["fechainicio"] = lstIncidencias[i].fechainicio; dtFila["fechafin"] = lstIncidencias[i].fechafin; dtFila["periodoinicio"] = lstIncidencias[i].periodoinicio; dtFila["periodofin"] = lstIncidencias[i].periodofin; dtFila["idcontrol"] = lstIncidencias[i].idcontrol; dtFila["idincapacidad"] = lstIncidencias[i].idincapacidad; dt.Rows.Add(dtFila); } try { cnx.Open(); ih.bulkIncidencia(dt, "tmpIncidencias"); ih.stpIncidencia(dtpInicioPeriodo.Value.Date, dtpFinPeriodo.Value.Date); cnx.Close(); cnx.Dispose(); if (OnIncapacidad != null) OnIncapacidad(); } catch (Exception error) { MessageBox.Show("Error al ingresar la incapacidad. \r\n \r\n Descripcion: " + error.Message, "Error"); } this.Dispose(); break; //case 1://ALTA EN DATAGRIDVIEW // try // { // cnx.Open(); // lstEmpleado = eh.obtenerEmpleado(empleado); // cnx.Close(); // cnx.Dispose(); // if (OnIncapacidad != null) // OnIncapacidad(lstEmpleado[0].noempleado, // lstEmpleado[0].nombres, // lstEmpleado[0].paterno, // lstEmpleado[0].materno, // int.Parse(txtDiasIncapacidad.Text), // dtpFechaInicio.Value, // dtpInicioPeriodo.Value, // dtpFinPeriodo.Value); // } // catch (Exception error) // { // MessageBox.Show("Error al ingresar la incapacidad. \r\n \r\n Descripcion: " + error.Message, "Error"); // } // break; } }
private void btnGuardarVP_Click(object sender, EventArgs e) { cnx = new SqlConnection(cdn); cmd = new SqlCommand(); cmd.Connection = cnx; Empleados.Core.EmpleadosHelper emph = new Empleados.Core.EmpleadosHelper(); emph.Command = cmd; Vacaciones.Core.VacacionesHelper vh = new Vacaciones.Core.VacacionesHelper(); vh.Command = cmd; Complementos.Core.ComplementoHelper ch = new Complementos.Core.ComplementoHelper(); ch.Command = cmd; Empleados.Core.Empleados empleado = new Empleados.Core.Empleados(); empleado.idtrabajador = idTrabajador; Complementos.Core.Complemento c = new Complementos.Core.Complemento(); c.idtrabajador = idTrabajador; c.observaciones = txtObservaciones.Text; List<Empleados.Core.Empleados> lstEmpleado = new List<Empleados.Core.Empleados>(); try { cnx.Open(); lstEmpleado = emph.obtenerEmpleado(empleado); cnx.Close(); } catch { MessageBox.Show("Error: Al obtener la antigüedad del empleado.", "Error"); cnx.Dispose(); return; } Vacaciones.Core.DiasDerecho dd = new Vacaciones.Core.DiasDerecho(); dd.anio = lstEmpleado[0].antiguedadmod; int dias = 0; try { cnx.Open(); dias = (int)vh.diasDerecho(dd); cnx.Close(); } catch { MessageBox.Show("Error: Al obtener los dias por derecho del empleado.", "Error"); cnx.Dispose(); return; } int existePrima = 0; int existeVacacion = 0; if (cmbConceptoVacaciones.SelectedIndex == 0) // PRIMA VACACIONAL Y VACACIONES { Vacaciones.Core.VacacionesPrima vp = new Vacaciones.Core.VacacionesPrima(); vp.idtrabajador = idTrabajador; vp.periodoinicio = _inicioPeriodo; vp.periodofin = _finPeriodo; vp.vacacionesprima = "P"; try { cnx.Open(); existePrima = (int)vh.existeVacacionesPrima(vp); cnx.Close(); } catch { MessageBox.Show("Error: Al obtener la existencia de prima vacacional del empleado.", "Error"); cnx.Dispose(); return; } vp = new Vacaciones.Core.VacacionesPrima(); vp.idtrabajador = idTrabajador; vp.periodoinicio = _inicioPeriodo; vp.periodofin = _finPeriodo; vp.vacacionesprima = "V"; try { cnx.Open(); existeVacacion = (int)vh.existeVacacionesPrima(vp); cnx.Close(); } catch { MessageBox.Show("Error: Al obtener la existencia de vacaciones del empleado.", "Error"); cnx.Dispose(); return; } //VALIDACION DE EXISTENCIA DE PRIMA VACACIONAL Y VACACIONES if (existePrima != 0 || existeVacacion != 0) { MessageBox.Show("Error: Los datos a ingresar ya existen y/o existe la Prima Vacaciona o Vacaciones.", "Error"); cnx.Dispose(); return; } else { Faltas.Core.FaltasHelper fh = new Faltas.Core.FaltasHelper(); fh.Command = cmd; Faltas.Core.Faltas falta = new Faltas.Core.Faltas(); falta.idempresa = GLOBALES.IDEMPRESA; falta.idtrabajador = idTrabajador; falta.fechainicio = _inicioPeriodo.Date; falta.fechafin = _finPeriodo.Date; int existeFaltas = 0; try { cnx.Open(); existeFaltas = (int)fh.existeFalta(falta); cnx.Close(); } catch (Exception error) { MessageBox.Show("Error: Al obtener las faltas del trabajador. \r\n" + error.Message, "Error"); cnx.Dispose(); return; } int diasPagoReales = int.Parse(txtDiasPagoPV.Text) + existeFaltas; if (diasPagoReales > _periodo) { diasPagoReales = _periodo - existeFaltas; MessageBox.Show("Existen faltas del trabajador, se ajustaron las vacaciones a: " + diasPagoReales.ToString() + " dia(s).", "Información"); } else { diasPagoReales = int.Parse(txtDiasPagoPV.Text); } vp = new Vacaciones.Core.VacacionesPrima(); vp.idtrabajador = idTrabajador; vp.idempresa = GLOBALES.IDEMPRESA; vp.periodoinicio = _inicioPeriodo; vp.periodofin = _finPeriodo; vp.diasderecho = dias; vp.diaspago = diasPagoReales; vp.diaspendientes = dias - diasPagoReales; vp.fechapago = DateTime.Now.Date; vp.fechainicio = DateTime.Now.Date; vp.fechafin = DateTime.Now.Date; vp.vacacionesprima = "P"; try { cnx.Open(); vh.insertaVacacion(vp); cnx.Close(); } catch { MessageBox.Show("Error: Al ingresar el registro de prima vacacional.", "Error"); cnx.Dispose(); return; } diasPagoReales = int.Parse(txtDiasPagoV.Text) + existeFaltas; if (diasPagoReales > _periodo) { diasPagoReales = _periodo - existeFaltas; MessageBox.Show("Existen faltas del trabajador, se ajustaron las vacaciones a: " + diasPagoReales.ToString() + " dia(s).", "Información"); } else { diasPagoReales = int.Parse(txtDiasPagoV.Text); } vp = new Vacaciones.Core.VacacionesPrima(); vp.idtrabajador = idTrabajador; vp.idempresa = GLOBALES.IDEMPRESA; vp.periodoinicio = _inicioPeriodo; vp.periodofin = _finPeriodo; vp.diasderecho = dias; vp.diaspago = diasPagoReales; vp.diaspendientes = dias - diasPagoReales; vp.fechapago = DateTime.Now.Date; vp.fechainicio = dtpFechaInicioVacaciones.Value.Date; vp.fechafin = dtpFechaInicioVacaciones.Value.AddDays(diasPagoReales - 1); vp.vacacionesprima = "V"; try { cnx.Open(); vh.insertaVacacion(vp); cnx.Close(); cnx.Dispose(); muestraVacaciones(); } catch { MessageBox.Show("Error: Al ingresar el registro de prima vacacional.", "Error"); cnx.Dispose(); return; } } } else // SOLO PRIMA VACACIONAL { Vacaciones.Core.VacacionesPrima vp = new Vacaciones.Core.VacacionesPrima(); vp.idtrabajador = idTrabajador; vp.periodoinicio = _inicioPeriodo; vp.periodofin = _finPeriodo; vp.vacacionesprima = "P"; try { cnx.Open(); existePrima = (int)vh.existeVacacionesPrima(vp); cnx.Close(); } catch { MessageBox.Show("Error: Al obtener la existencia de vacaciones del empleado.", "Error"); cnx.Dispose(); return; } //VALIDACION DE EXISTENCIA DE PRIMA VACACIONAL if (existePrima != 0) { MessageBox.Show("Error: Los datos a ingresar ya existen.", "Error"); cnx.Dispose(); return; } else { Faltas.Core.FaltasHelper fh = new Faltas.Core.FaltasHelper(); fh.Command = cmd; Faltas.Core.Faltas falta = new Faltas.Core.Faltas(); falta.idempresa = GLOBALES.IDEMPRESA; falta.idtrabajador = idTrabajador; falta.fechainicio = _inicioPeriodo.Date; falta.fechafin = _finPeriodo.Date; int existeFaltas = 0; try { cnx.Open(); existeFaltas = (int)fh.existeFalta(falta); cnx.Close(); } catch (Exception error) { MessageBox.Show("Error: Al obtener las faltas del trabajador. \r\n" + error.Message, "Error"); cnx.Dispose(); return; } int diasPagoReales = int.Parse(txtDiasPagoPV.Text) + existeFaltas; if (diasPagoReales > _periodo) { diasPagoReales = _periodo - existeFaltas; MessageBox.Show("Existen faltas del trabajador, se ajustaron las vacaciones a: " + diasPagoReales.ToString() + " dia(s).", "Información"); } else { diasPagoReales = int.Parse(txtDiasPagoPV.Text); } vp = new Vacaciones.Core.VacacionesPrima(); vp.idtrabajador = idTrabajador; vp.idempresa = GLOBALES.IDEMPRESA; vp.periodoinicio = _inicioPeriodo; vp.periodofin = _finPeriodo; vp.diasderecho = dias; vp.diaspago = diasPagoReales; vp.diaspendientes = dias - diasPagoReales; vp.fechapago = DateTime.Now.Date; vp.fechainicio = DateTime.Now.Date; vp.fechafin = DateTime.Now.Date; vp.vacacionesprima = "P"; try { cnx.Open(); vh.insertaVacacion(vp); cnx.Close(); cnx.Dispose(); muestraVacaciones(); } catch { MessageBox.Show("Error: Al ingresar el registro de prima vacacional.", "Error"); cnx.Dispose(); return; } } } }
private void workVacaciones_DoWork(object sender, DoWorkEventArgs e) { int idEmpleado = 0; cnx = new SqlConnection(cdn); cmd = new SqlCommand(); cmd.Connection = cnx; List<Vacaciones.Core.VacacionesPrima> lstMovimientos = new List<Vacaciones.Core.VacacionesPrima>(); vh = new Vacaciones.Core.VacacionesHelper(); vh.Command = cmd; emph = new Empleados.Core.EmpleadosHelper(); emph.Command = cmd; ph = new Periodos.Core.PeriodosHelper(); ph.Command = cmd; foreach (DataGridViewRow fila in dgvCargaVacaciones.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 concepto. \r\n \r\n" + error.Message, "Error"); cnx.Dispose(); this.Dispose(); } Empleados.Core.Empleados empleado = new Empleados.Core.Empleados(); empleado.idtrabajador = idEmpleado; List<Empleados.Core.Empleados> lstEmpleado = new List<Empleados.Core.Empleados>(); try { cnx.Open(); lstEmpleado = emph.obtenerEmpleado(empleado); cnx.Close(); } catch { MessageBox.Show("Error: Al obtener la antigüedad del empleado.", "Error"); cnx.Dispose(); this.Dispose(); } Vacaciones.Core.DiasDerecho dd = new Vacaciones.Core.DiasDerecho(); dd.anio = lstEmpleado[0].antiguedadmod; int dias = 0; try { cnx.Open(); dias = (int)vh.diasDerecho(dd); cnx.Close(); } catch { MessageBox.Show("Error: Al obtener los dias por derecho del empleado.", "Error"); cnx.Dispose(); return; } Faltas.Core.FaltasHelper fh = new Faltas.Core.FaltasHelper(); fh.Command = cmd; Faltas.Core.Faltas falta = new Faltas.Core.Faltas(); falta.idempresa = GLOBALES.IDEMPRESA; falta.idtrabajador = idEmpleado; falta.fechainicio = DateTime.Parse(dgvCargaVacaciones.Rows[0].Cells["inicio"].Value.ToString()); falta.fechafin = DateTime.Parse(dgvCargaVacaciones.Rows[0].Cells["fin"].Value.ToString()); int existeFaltas = 0; try { cnx.Open(); existeFaltas = (int)fh.existeFalta(falta); cnx.Close(); } catch (Exception error) { MessageBox.Show("Error: Al obtener las faltas del trabajador. \r\n" + error.Message, "Error"); cnx.Dispose(); return; } int idperiodo = 0; try { cnx.Open(); idperiodo = (int)emph.obtenerIdPeriodo(idEmpleado); cnx.Close(); } catch (Exception error) { MessageBox.Show("Error: Al obtener el id del periodo. \r\n" + error.Message, "Error"); cnx.Dispose(); return; } Periodos.Core.Periodos p = new Periodos.Core.Periodos(); p.idperiodo = idperiodo; int diasPeriodo = 0; try { cnx.Open(); diasPeriodo = (int)ph.DiasDePago(p); cnx.Close(); } catch (Exception error) { MessageBox.Show("Error: Al obtener los dias del periodo. \r\n" + error.Message, "Error"); cnx.Dispose(); return; } int diasPagoReales = int.Parse(fila.Cells["diaspago"].Value.ToString()) + existeFaltas; if (diasPagoReales >= diasPeriodo) { diasPagoReales = diasPeriodo - existeFaltas; MessageBox.Show("Existen faltas del trabajador, se ajustarán las vacaciones.", "Información"); } else { diasPagoReales = int.Parse(fila.Cells["diaspago"].Value.ToString()); } Vacaciones.Core.VacacionesPrima vp = new Vacaciones.Core.VacacionesPrima(); vp.idtrabajador = idEmpleado; vp.idempresa = GLOBALES.IDEMPRESA; vp.periodoinicio = DateTime.Parse(dgvCargaVacaciones.Rows[0].Cells["inicio"].Value.ToString()); vp.periodofin = DateTime.Parse(dgvCargaVacaciones.Rows[0].Cells["fin"].Value.ToString()); vp.diasderecho = dias; vp.fechapago = DateTime.Now.Date; vp.vacacionesprima = fila.Cells["concepto"].Value.ToString() == "Prima Vacacional" ? "P" : "V"; if (fila.Cells["concepto"].Value.ToString() == "Prima Vacacional") { vp.diaspago = diasPagoReales; vp.diaspendientes = dias - diasPagoReales; vp.fechainicio = DateTime.Now.Date; vp.fechafin = DateTime.Now.Date; } else { vp.diaspago = diasPagoReales; vp.diaspendientes = dias - diasPagoReales; vp.fechainicio = DateTime.Parse(fila.Cells["fechaaplicacion"].Value.ToString()); vp.fechafin = DateTime.Parse(fila.Cells["fechaaplicacion"].Value.ToString()).AddDays(diasPagoReales - 1); } lstMovimientos.Add(vp); } bulk = new SqlBulkCopy(cnx); vh.bulkCommand = bulk; DataTable dt = new DataTable(); DataRow dtFila; dt.Columns.Add("id", typeof(Int32)); dt.Columns.Add("idtrabajador", typeof(Int32)); dt.Columns.Add("idempresa", typeof(Int32)); dt.Columns.Add("periodoinicio", typeof(DateTime)); dt.Columns.Add("periodofin", typeof(DateTime)); dt.Columns.Add("diasderecho", typeof(Int32)); dt.Columns.Add("diaspago", typeof(Int32)); dt.Columns.Add("diaspendientes", typeof(Int32)); dt.Columns.Add("fechapago", typeof(DateTime)); dt.Columns.Add("vacacionesprima", typeof(String)); dt.Columns.Add("fechainicio", typeof(DateTime)); dt.Columns.Add("fechafin", typeof(DateTime)); int index = 1; for (int i = 0; i < lstMovimientos.Count; i++) { dtFila = dt.NewRow(); dtFila["id"] = i + 1; dtFila["idtrabajador"] = lstMovimientos[i].idtrabajador; dtFila["idempresa"] = lstMovimientos[i].idempresa; dtFila["periodoinicio"] = lstMovimientos[i].periodoinicio; dtFila["periodofin"] = lstMovimientos[i].periodofin; dtFila["diasderecho"] = lstMovimientos[i].diasderecho; dtFila["diaspago"] = lstMovimientos[i].diaspago; dtFila["diaspendientes"] = lstMovimientos[i].diaspendientes; dtFila["fechapago"] = lstMovimientos[i].fechapago; dtFila["vacacionesprima"] = lstMovimientos[i].vacacionesprima; dtFila["fechainicio"] = lstMovimientos[i].fechainicio; dtFila["fechafin"] = lstMovimientos[i].fechafin; dt.Rows.Add(dtFila); index++; } try { cnx.Open(); vh.bulkVacaciones(dt, "tmpVacacionesPrima"); vh.stpVacaciones(); cnx.Close(); cnx.Dispose(); } catch (Exception error) { MessageBox.Show("Error (DataTable): \r\n \r\n" + error.Message, "Error"); } }