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 toolGuardar_Click(object sender, EventArgs e) { //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; } if (_idEmpleado == 0) { MessageBox.Show("No se puede guardar no ha seleccionado al Empleado", "Error"); return; } //bool alta_reingreso = ChecaFechaAltaReingreso(); //if (dtpFechaAplicacion.Value.Date > dtpFinPeriodo.Value.Date) //{ // MessageBox.Show("La fecha de aplicacion es mayor al periodo.", "Error"); // return; //} //if (dtpFechaAplicacion.Value.Date < dtpInicioPeriodo.Value.Date) //{ // MessageBox.Show("La fecha de aplicacion es menor al periodo.", "Error"); // return; //} cnx = new SqlConnection(); cnx.ConnectionString = cdn; cmd = new SqlCommand(); cmd.Connection = cnx; ih = new Infonavit.Core.InfonavitHelper(); ih.Command = cmd; PeriodoFechaAplicacion(); Infonavit.Core.Infonavit i = new Infonavit.Core.Infonavit(); i.idtrabajador = _idEmpleado; i.idempresa = GLOBALES.IDEMPRESA; i.credito = txtNumeroCredito.Text; i.descuento = Descuento; i.activo = chkInactivo.Checked == true ? false : true; i.descripcion = txtDescripcion.Text; i.dias = (int)(periodoFin.Date - dtpFechaAplicacion.Value.Date).TotalDays + 1; i.fecha = dtpFechaAplicacion.Value.Date; i.inicio = periodoInicio.Date; i.fin = periodoFin.Date; i.registro = DateTime.Now; i.idusuario = GLOBALES.IDUSUARIO; i.estatus = int.Parse(cmbEstatusInfonavit.SelectedValue.ToString()); if (rbtnPesos.Checked) if (Periodo == 7) i.valordescuento = (decimal.Parse(txtValor.Text) / decimal.Parse((30.4).ToString())) * Periodo; else i.valordescuento = decimal.Parse(txtValor.Text) / 2; if (rbtnVsmdf.Checked) i.valordescuento = decimal.Parse(txtValor.Text); if (rbtnPorcentaje.Checked) i.valordescuento = decimal.Parse(txtValor.Text); Conceptos.Core.ConceptosHelper ch = new Conceptos.Core.ConceptosHelper(); ch.Command = cmd; Conceptos.Core.ConceptoTrabajador ctInfonavit = new Conceptos.Core.ConceptoTrabajador(); ctInfonavit.idempleado = _idEmpleado; Conceptos.Core.ConceptoTrabajador ctSeguroInfonavit = new Conceptos.Core.ConceptoTrabajador(); ctSeguroInfonavit.idempleado = _idEmpleado; try { cnx.Open(); ctInfonavit.idconcepto = (int)ch.obtenerIdConcepto(9, GLOBALES.IDEMPRESA, Periodo); ctSeguroInfonavit.idconcepto = (int)ch.obtenerIdConcepto(21, GLOBALES.IDEMPRESA, Periodo); cnx.Close(); } catch { MessageBox.Show("Error: Al obtener el ID del Concepto Infonavit.", "Error"); cnx.Dispose(); return; } switch (_tipoOperacion) { case 0: try { int existeCredito = 0; cnx.Open(); existeCredito = int.Parse(ih.existeInfonavit(_idEmpleado, txtNumeroCredito.Text.Trim()).ToString()); if (existeCredito != 0) { MessageBox.Show("El número de credito que desea ingresar ya existe.\r\n" + "Si es una modificación del crédito use la opción \"Modificación\""); this.Dispose(); } else { ih.insertaInfonavit(i); ch.insertaConceptoTrabajador(ctInfonavit); ch.insertaConceptoTrabajador(ctSeguroInfonavit); } cnx.Close(); cnx.Dispose(); } catch (Exception error) { MessageBox.Show("Error al ingresar los datos. \r\n \r\n Error: " + error.Message); this.Dispose(); } break; case 2: try { cnx.Open(); if (_modificar == 0) { i.idinfonavit = IdInfonavit; ih.actualizaInfonavit(i); } else if (_modificar == 1) { ih.insertaInfonavit(i); ih.actualizaEstatusInfonavit(IdInfonavit, DateTime.Now, GLOBALES.IDUSUARIO); } cnx.Close(); cnx.Dispose(); } catch (Exception error) { MessageBox.Show("Error al actualizar los datos. \r\n \r\n Error: " + error.Message); this.Dispose(); } break; } if (OnNuevoInfonavit != null) OnNuevoInfonavit(_tipoOperacion); this.Dispose(); }