private void btnAceptar_Click(object sender, EventArgs e) { string rp; //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; } control = GLOBALES.VALIDAR(this, typeof(MaskedTextBox)); if (!control.Equals("")) { MessageBox.Show("Falta el campo: " + control, "Información"); return; } cnx = new SqlConnection(cdn); cmd = new SqlCommand(); cmd.Connection = cnx; Empleados.Core.EmpleadosHelper empleadoh = new Empleados.Core.EmpleadosHelper(); Historial.Core.HistorialHelper hh = new Historial.Core.HistorialHelper(); Reingreso.Core.ReingresoHelper rh = new Reingreso.Core.ReingresoHelper(); Empresas.Core.EmpresasHelper eh = new Empresas.Core.EmpresasHelper(); Infonavit.Core.InfonavitHelper ih = new Infonavit.Core.InfonavitHelper(); empleadoh.Command = cmd; hh.Command = cmd; rh.Command = cmd; eh.Command = cmd; ih.Command = cmd; Empleados.Core.Empleados empleado = new Empleados.Core.Empleados(); Empleados.Core.EmpleadosEstatus ee = new Empleados.Core.EmpleadosEstatus(); Historial.Core.Historial historia = new Historial.Core.Historial(); Reingreso.Core.Reingresos reingreso = new Reingreso.Core.Reingresos(); Empresas.Core.Empresas empresa = new Empresas.Core.Empresas(); empleado.idtrabajador = _idempleado; empleado.idempresa = lstEmpleado[0].idempresa; empleado.fechaingreso = dtpFechaReingreso.Value; empleado.fechaantiguedad = dtpFechaAntiguedad.Value; empleado.antiguedad = int.Parse(txtAntiguedad.Text); empleado.antiguedadmod = int.Parse(txtAntiguedadMod.Text); empleado.iddepartamento = int.Parse(cmbDepartamento.SelectedValue.ToString()); empleado.idpuesto = int.Parse(cmbPuesto.SelectedValue.ToString()); empleado.idperiodo = int.Parse(cmbPeriodo.SelectedValue.ToString()); empleado.sueldo = decimal.Parse(txtSueldo.Text); empleado.sd = decimal.Parse(txtSalarioDiario.Text); empleado.sdi = decimal.Parse(txtSDI.Text); empleado.idusuario = GLOBALES.IDUSUARIO; empleado.estatus = GLOBALES.ACTIVO; empleado.cuenta = mtxtCuentaBancaria.Text; empleado.clabe = mtxtCuentaClabe.Text; empleado.idbancario = mtxtIdBancario.Text; empleado.metodopago = cmbMetodoPago.Text; if (chkObraCivil.Checked) empleado.obracivil = true; else empleado.obracivil = false; ee.idtrabajador = _idempleado; ee.idempresa = GLOBALES.IDEMPRESA; ee.estatus = GLOBALES.REINGRESO; historia.idtrabajador = _idempleado; historia.idempresa = lstEmpleado[0].idempresa; historia.valor = decimal.Parse(txtSDI.Text); historia.fecha_imss = dtpFechaReingreso.Value; historia.fecha_sistema = DateTime.Now; historia.motivobaja = 0; historia.tipomovimiento = GLOBALES.mREINGRESO; historia.iddepartamento = int.Parse(cmbDepartamento.SelectedValue.ToString()); historia.idpuesto = int.Parse(cmbPuesto.SelectedValue.ToString()); empresa.idempresa = lstEmpleado[0].idempresa; reingreso.idtrabajador = _idempleado; reingreso.idempresa = lstEmpleado[0].idempresa; reingreso.fechaingreso = dtpFechaReingreso.Value; reingreso.sdi = decimal.Parse(txtSDI.Text); reingreso.registro = DateTime.Now; Periodos.Core.PeriodosHelper pdh = new Periodos.Core.PeriodosHelper(); pdh.Command = cmd; Periodos.Core.Periodos p = new Periodos.Core.Periodos(); p.idperiodo = int.Parse(cmbPeriodo.SelectedValue.ToString()); int diasPago = 0; try { cnx.Open(); diasPago = (int)pdh.DiasDePago(p); cnx.Close(); } catch { MessageBox.Show("Error: Al obtener los dias de pago.", "Error"); } DateTime dt = dtpFechaReingreso.Value.Date; DateTime periodoInicio, periodoFin; int diasProporcionales = 0; if (diasPago == 7) { while (dt.DayOfWeek != DayOfWeek.Monday) dt = dt.AddDays(-1); periodoInicio = dt; periodoFin = dt.AddDays(6); diasProporcionales = (int)(periodoFin.Date - dtpFechaReingreso.Value.Date).TotalDays + 1; } else { if (dt.Day <= 15) { periodoInicio = new DateTime(dt.Year, dt.Month, 1); periodoFin = new DateTime(dt.Year, dt.Month, 15); diasProporcionales = (int)(periodoFin.Date - dtpFechaReingreso.Value.Date).TotalDays + 1; } else { int diasMes = DateTime.DaysInMonth(dt.Year, dt.Month); int diasNoLaborados = 0; periodoInicio = new DateTime(dt.Year, dt.Month, 16); periodoFin = new DateTime(dt.Year, dt.Month, DateTime.DaysInMonth(dt.Year, dt.Month)); diasNoLaborados = (int)(dtpFechaReingreso.Value.Date - periodoInicio).TotalDays; switch (diasMes) { case 28: diasProporcionales = 15 - diasNoLaborados; break; case 29: diasProporcionales = 15 - diasNoLaborados; break; case 30: diasProporcionales = (diasMes - 15) - diasNoLaborados; break; case 31: diasProporcionales = (diasMes - 16) - diasNoLaborados; break; } } } CalculoNomina.Core.NominaHelper nh = new CalculoNomina.Core.NominaHelper(); nh.Command = cmd; List<CalculoNomina.Core.tmpPagoNomina> lstFechas = new List<CalculoNomina.Core.tmpPagoNomina>(); bool verificaFechas = false; try { cnx.Open(); lstFechas = nh.obtenerUltimaNominaTrabajador(GLOBALES.IDEMPRESA, GLOBALES.NORMAL, diasPago, _idempleado); cnx.Close(); } catch (Exception) { MessageBox.Show("Error: Al obtener la fecha de la ultima nómina calculada", "Error"); } if (lstFechas.Count != 0) { if (dtpFechaReingreso.Value.Date <= lstFechas[0].fechainicio.Date || dtpFechaReingreso.Value.Date <= lstFechas[0].fechafin.Date) verificaFechas = false; else verificaFechas = true; if (!verificaFechas) { MessageBox.Show("La fecha de ingreso es invalida. Fecha menor al ultimo periodo calculado, verifique.", "Error"); return; } } try { cnx.Open(); empleadoh.reingreso(empleado); empleadoh.bajaEmpleado(ee); rp = (string)eh.obtenerRegistroPatronal(empresa); reingreso.registropatronal = rp; reingreso.nss = lstEmpleado[0].nss + lstEmpleado[0].digitoverificador; reingreso.diasproporcionales = diasProporcionales; reingreso.periodoinicio = periodoInicio; reingreso.periodofin = periodoFin; rh.insertaReingreso(reingreso); hh.insertarHistorial(historia); cnx.Close(); MessageBox.Show("Empleado reingresado con éxito.", "Información"); if (OnReingreso != null) OnReingreso(GLOBALES.NUEVO); } catch (Exception error) { MessageBox.Show("Error: \r\n \r\n " + error.Message, "Error"); } int existeInfonavit = 0; try { cnx.Open(); existeInfonavit = (int)ih.existeInfonavit(_idempleado); cnx.Close(); } catch (Exception) { MessageBox.Show("Error: Al obtener la existencia del Infonavit.\r\n AVISO: INGRESAR O MODIFICAR MANUALMENTE EL CREDITO DE INFONAVIT", "Error"); cnx.Dispose(); } List<Infonavit.Core.Infonavit> lstInfonavit = new List<Infonavit.Core.Infonavit>(); if (existeInfonavit != 0) { try { cnx.Open(); lstInfonavit = ih.obtenerInfonavitTrabajador(_idempleado); cnx.Close(); } catch (Exception) { MessageBox.Show("Error: Al obtener la información de infonavit.\r\n AVISO: INGRESAR O MODIFICAR MANUALMENTE EL CREDITO DE INFONAVIT", "Error"); cnx.Dispose(); } try { cnx.Open(); ih.actualizaEstatusInfonavit(lstInfonavit[0].idinfonavit, _idempleado); cnx.Close(); MessageBox.Show("Trabajador cuenta con Infonavit. Crédito: " + lstInfonavit[0].credito, "Información"); } catch (Exception) { MessageBox.Show("Error: Al obtener al activar el crédito de infonavit.\r\n AVISO: INGRESAR O MODIFICAR MANUALMENTE EL CREDITO DE INFONAVIT", "Error"); cnx.Dispose(); } } this.Dispose(); }
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 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 ListaEmpleados() { string cdn = ConfigurationManager.ConnectionStrings["cdnNomina"].ConnectionString; cnx = new SqlConnection(cdn); cmd = new SqlCommand(); cmd.Connection = cnx; rh = new Reingreso.Core.ReingresoHelper(); eh = new Empleados.Core.EmpleadosHelper(); rh.Command = cmd; eh.Command = cmd; Reingreso.Core.Reingresos reingreso = new Reingreso.Core.Reingresos(); reingreso.idempresa = GLOBALES.IDEMPRESA; Empleados.Core.Empleados empleado = new Empleados.Core.Empleados(); empleado.idempresa = GLOBALES.IDEMPRESA; empleado.estatus = GLOBALES.ACTIVO; try { cnx.Open(); lstReingreso = rh.obtenerReingresos(reingreso); lstEmpleados = eh.obtenerEmpleados(empleado); cnx.Close(); cnx.Dispose(); var rein = from r in lstReingreso join t in lstEmpleados on r.idtrabajador equals t.idtrabajador select new { RegistroPatronal = r.registropatronal, Nss = r.nss, Nombre = t.nombrecompleto, Reingreso = r.fechaingreso, Integrado = r.sdi }; dgvReingresoSua.DataSource = rein.ToList(); for (int i = 0; i < dgvReingresoSua.Columns.Count; i++) { dgvReingresoSua.AutoResizeColumn(i); } } catch (Exception error) { MessageBox.Show("Error: \r\n \r\n " + error.Message, "Error"); } }
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"); } } }