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(); }