private void dgvComplementos_CellClick(object sender, DataGridViewCellEventArgs e) { int fila = 0; cnx = new MySqlConnection(); cnx.ConnectionString = cdn; cmd = new MySqlCommand(); cmd.Connection = cnx; Complementos.Core.ComplementoHelper ch = new Complementos.Core.ComplementoHelper(); ch.Command = cmd; fila = dgvComplementos.CurrentCell.RowIndex; Complementos.Core.Complemento c = new Complementos.Core.Complemento(); c.idtrabajador = int.Parse(dgvComplementos.Rows[fila].Cells[0].Value.ToString()); try { cnx.Open(); int existe = (int)ch.existeComplemento(c); cnx.Close(); cnx.Dispose(); if (!existe.Equals(0)) { toolNuevo.Enabled = false; } else { toolNuevo.Enabled = true; } } catch (Exception error) { MessageBox.Show("Error: \r\n \r\n" + error.Message, "Error"); } }
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 muestraVacaciones() { cnx = new SqlConnection(cdn); cmd = new SqlCommand(); cmd.Connection = cnx; Vacaciones.Core.VacacionesHelper vh = new Vacaciones.Core.VacacionesHelper(); vh.Command = cmd; Complementos.Core.ComplementoHelper comh = new Complementos.Core.ComplementoHelper(); comh.Command = cmd; Vacaciones.Core.VacacionesPrima v = new Vacaciones.Core.VacacionesPrima(); v.idtrabajador = idTrabajador; Complementos.Core.Complemento comp = new Complementos.Core.Complemento(); comp.idtrabajador = idTrabajador; List<Vacaciones.Core.VacacionesPrima> lstVacacionesPrima = new List<Vacaciones.Core.VacacionesPrima>(); try { cnx.Open(); lstVacacionesPrima = vh.obtenerVacacionesPrimaTrabajador(v); txtObservaciones.Text = comh.obtenerObservacionesTrabajador(comp).ToString(); cnx.Close(); cnx.Dispose(); } catch (Exception error) { MessageBox.Show("Error: Al obtener las Vacaciones. (Función Muestra Vacaciones.) \r\n \r\n" + error.Message, "Error"); } lstvVacaciones.Clear(); lstvVacaciones.View = View.Details; lstvVacaciones.GridLines = true; lstvVacaciones.Columns.Add("ID", 30, HorizontalAlignment.Right); lstvVacaciones.Columns.Add("Periodo Inicio", 80, HorizontalAlignment.Right); lstvVacaciones.Columns.Add("Periodo Fin", 80, HorizontalAlignment.Right); for (int i = 0; i < lstVacacionesPrima.Count; i++) { lstvVacaciones.Items.Add(lstVacacionesPrima[i].id.ToString()); lstvVacaciones.Items[i].SubItems.Add(lstVacacionesPrima[i].periodoinicio.ToShortDateString()); lstvVacaciones.Items[i].SubItems.Add(lstVacacionesPrima[i].periodofin.ToShortDateString()); } }
private void btnGuardarObservaciones_Click(object sender, EventArgs e) { cnx = new SqlConnection(cdn); cmd = new SqlCommand(); cmd.Connection = cnx; Complementos.Core.ComplementoHelper ch = new Complementos.Core.ComplementoHelper(); ch.Command = cmd; Complementos.Core.Complemento c = new Complementos.Core.Complemento(); c.idtrabajador = idTrabajador; c.observaciones = txtObservaciones.Text; try { cnx.Open(); ch.actualizaObservacionesTrabajador(c); cnx.Close(); cnx.Dispose(); } catch { MessageBox.Show("Error: Al actualizar las observaciones.", "Error"); cnx.Dispose(); return; } }
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; } control = GLOBALES.VALIDAR(this, typeof(MaskedTextBox)); if (!control.Equals("")) { MessageBox.Show("Falta el campo: " + control, "Información"); return; } cnx = new MySqlConnection(); cnx.ConnectionString = cdn; cmd = new MySqlCommand(); cmd.Connection = cnx; ch = new Complementos.Core.ComplementoHelper(); dh = new Direccion.Core.DireccionesHelper(); ch.Command = cmd; dh.Command = cmd; Direccion.Core.Direcciones d = new Direccion.Core.Direcciones(); d.idpersona = _idEmpleado; d.calle = txtCalle.Text; d.exterior = txtExterior.Text; d.interior = txtInterior.Text; d.cp = txtCP.Text; d.colonia = txtColonia.Text; d.ciudad = txtMunicipio.Text; d.estado = txtEstado.Text; d.pais = txtPais.Text; d.tipodireccion = 2; d.tipopersona = 2; Complementos.Core.Complemento c = new Complementos.Core.Complemento(); c.idtrabajador = _idEmpleado; c.contrato = cmbContrato.SelectedValue.ToString(); c.jornada = cmbJornada.SelectedValue.ToString(); c.iddepartamento = int.Parse(cmbDepartamento.SelectedValue.ToString()); c.idpuesto = int.Parse(cmbPuesto.SelectedValue.ToString()); c.estadocivil = cmbEstadoCivil.SelectedValue.ToString(); c.sexo = cmbSexo.SelectedValue.ToString(); c.escolaridad = cmbEscolaridad.SelectedValue.ToString(); c.horario = txtHorario.Text; c.nocontrol = txtNoControl.Text; c.clinica = txtClinica.Text; c.nacionalidad = txtNacionalidad.Text; c.funciones = txtFunciones.Text; switch (_tipoOperacion) { case 0: try { cnx.Open(); dh.insertaDireccion(d); ch.insertaComplemento(c); 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 { d.iddireccion = idDireccion; c.id = idComplemento; cnx.Open(); ch.actualizaComplemento(c); dh.actualizaDireccion(d); cnx.Close(); cnx.Dispose(); } catch (Exception error) { MessageBox.Show("Error al actualizar los datos. \r\n \r\n Error: " + error.Message); this.Dispose(); } break; } }
private void frmComplementos_Load(object sender, EventArgs e) { CargaComboBox(); if (_tipoOperacion == GLOBALES.CONSULTAR || _tipoOperacion == GLOBALES.MODIFICAR) { cnx = new MySqlConnection(); cnx.ConnectionString = cdn; cmd = new MySqlCommand(); cmd.Connection = cnx; ch = new Complementos.Core.ComplementoHelper(); dh = new Direccion.Core.DireccionesHelper(); ch.Command = cmd; dh.Command = cmd; List <Complementos.Core.Complemento> lstComplemento; List <Direccion.Core.Direcciones> lstDireccion; Complementos.Core.Complemento c = new Complementos.Core.Complemento(); c.idtrabajador = _idEmpleado; Direccion.Core.Direcciones d = new Direccion.Core.Direcciones(); d.idpersona = _idEmpleado; d.tipopersona = 2; try { cnx.Open(); lstComplemento = ch.obtenerComplemento(c); lstDireccion = dh.obtenerDireccion(d); cnx.Close(); cnx.Dispose(); for (int i = 0; i < lstComplemento.Count; i++) { idComplemento = lstComplemento[i].id; cmbContrato.SelectedValue = lstComplemento[i].contrato; cmbJornada.SelectedValue = lstComplemento[i].jornada; cmbDepartamento.SelectedValue = lstComplemento[i].iddepartamento; cmbPuesto.SelectedValue = lstComplemento[i].idpuesto; cmbEstadoCivil.SelectedValue = lstComplemento[i].estadocivil; cmbSexo.SelectedValue = lstComplemento[i].sexo; cmbEscolaridad.SelectedValue = lstComplemento[i].escolaridad; txtHorario.Text = lstComplemento[i].horario; txtNoControl.Text = lstComplemento[i].nocontrol; txtClinica.Text = lstComplemento[i].clinica; txtNacionalidad.Text = lstComplemento[i].nacionalidad; txtFunciones.Text = lstComplemento[i].funciones; } for (int j = 0; j < lstDireccion.Count; j++) { idDireccion = lstDireccion[j].iddireccion; txtCalle.Text = lstDireccion[j].calle; txtExterior.Text = lstDireccion[j].exterior; txtInterior.Text = lstDireccion[j].interior; txtColonia.Text = lstDireccion[j].colonia; txtCP.Text = lstDireccion[j].cp; txtMunicipio.Text = lstDireccion[j].ciudad; txtEstado.Text = lstDireccion[j].estado; txtPais.Text = lstDireccion[j].pais; } } catch (Exception error) { MessageBox.Show("Error: \r\n \r\n " + error.Message, "Error"); } if (_tipoOperacion == GLOBALES.CONSULTAR) { toolTitulo.Text = "Consulta del Complemento"; GLOBALES.INHABILITAR(this, typeof(TextBox)); GLOBALES.INHABILITAR(this, typeof(MaskedTextBox)); GLOBALES.INHABILITAR(this, typeof(ComboBox)); } else { toolTitulo.Text = "Edición del Complemento"; } } }
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; } control = GLOBALES.VALIDAR(this, typeof(MaskedTextBox)); if (!control.Equals("")) { MessageBox.Show("Falta el campo: " + control, "Información"); return; } cnx = new SqlConnection(); cnx.ConnectionString = cdn; cmd = new SqlCommand(); cmd.Connection = cnx; ch = new Complementos.Core.ComplementoHelper(); dh = new Direccion.Core.DireccionesHelper(); ah = new Altas.Core.AltasHelper(); ch.Command = cmd; dh.Command = cmd; ah.Command = cmd; Direccion.Core.Direcciones d = new Direccion.Core.Direcciones(); d.idpersona = _idEmpleado; d.calle = txtCalle.Text; d.exterior = txtExterior.Text; d.interior = txtInterior.Text; d.cp = txtCP.Text; d.colonia = txtColonia.Text; d.ciudad = txtMunicipio.Text; d.estado = txtEstado.Text; d.pais = txtPais.Text; d.tipodireccion = GLOBALES.dPERSONAL; d.tipopersona = GLOBALES.pEMPLEADO; Complementos.Core.Complemento c = new Complementos.Core.Complemento(); c.idtrabajador = _idEmpleado; c.contrato = int.Parse(cmbContrato.SelectedValue.ToString()); c.jornada = int.Parse(cmbJornada.SelectedValue.ToString()); c.estadocivil = int.Parse(cmbEstadoCivil.SelectedValue.ToString()); c.sexo = int.Parse(cmbSexo.SelectedValue.ToString()); c.escolaridad = int.Parse(cmbEscolaridad.SelectedValue.ToString()); c.clinica = txtClinica.Text; c.nacionalidad = txtNacionalidad.Text; c.tempresa1 = mTelEmpresa.Text; c.tempresa2 = mTelEmpresa2.Text; c.tempresa3 = mTelEmpresa3.Text; c.extension = txtExtension.Text; c.cempresa = mCelEmpresa.Text; c.cpersonal = mTelPersonal.Text; c.email = txtCorreo.Text; c.observaciones = txtObservaciones.Text; Altas.Core.Altas a = new Altas.Core.Altas(); a.idtrabajador = _idEmpleado; a.jornada = int.Parse(cmbJornada.SelectedValue.ToString()); a.contrato = int.Parse(cmbContrato.SelectedValue.ToString()); a.cp = txtCP.Text; a.clinica = txtClinica.Text; switch (_tipoOperacion) { case 0: try { cnx.Open(); dh.insertaDireccion(d); ch.insertaComplemento(c); ah.actualizaAltaComplemento(a); 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 { d.iddireccion = idDireccion; c.id = idComplemento; cnx.Open(); ch.actualizaComplemento(c); dh.actualizaDireccion(d); ah.actualizaAltaComplemento(a); cnx.Close(); cnx.Dispose(); } catch (Exception error) { MessageBox.Show("Error al actualizar los datos. \r\n \r\n Error: " + error.Message); this.Dispose(); } break; } this.Dispose(); }
private void frmComplementos_Load(object sender, EventArgs e) { CargaComboBox(); if (_tipoOperacion == GLOBALES.CONSULTAR || _tipoOperacion == GLOBALES.MODIFICAR) { cnx = new SqlConnection(); cnx.ConnectionString = cdn; cmd = new SqlCommand(); cmd.Connection = cnx; ch = new Complementos.Core.ComplementoHelper(); dh = new Direccion.Core.DireccionesHelper(); ch.Command = cmd; dh.Command = cmd; List<Complementos.Core.Complemento> lstComplemento; List<Direccion.Core.Direcciones> lstDireccion; Complementos.Core.Complemento c = new Complementos.Core.Complemento(); c.idtrabajador = _idEmpleado; Direccion.Core.Direcciones d = new Direccion.Core.Direcciones(); d.idpersona = _idEmpleado; d.tipopersona = GLOBALES.pEMPLEADO; try { cnx.Open(); lstComplemento = ch.obtenerComplemento(c); lstDireccion = dh.obtenerDireccion(d); cnx.Close(); cnx.Dispose(); for (int i = 0; i < lstComplemento.Count; i++) { idComplemento = lstComplemento[i].id; cmbContrato.SelectedValue = lstComplemento[i].contrato; cmbJornada.SelectedValue = lstComplemento[i].jornada; cmbEstadoCivil.SelectedValue = lstComplemento[i].estadocivil; cmbSexo.SelectedValue = lstComplemento[i].sexo; cmbEscolaridad.SelectedValue = lstComplemento[i].escolaridad; txtClinica.Text = lstComplemento[i].clinica; txtNacionalidad.Text = lstComplemento[i].nacionalidad; mTelEmpresa.Text = lstComplemento[i].tempresa1; mTelEmpresa2.Text = lstComplemento[i].tempresa2; mTelEmpresa3.Text = lstComplemento[i].tempresa3; txtExtension.Text = lstComplemento[i].extension; mCelEmpresa.Text = lstComplemento[i].cempresa; mTelPersonal.Text = lstComplemento[i].cpersonal; txtCorreo.Text = lstComplemento[i].email; txtObservaciones.Text = lstComplemento[i].observaciones; } for (int j = 0; j < lstDireccion.Count; j++) { idDireccion = lstDireccion[j].iddireccion; txtCalle.Text = lstDireccion[j].calle; txtExterior.Text = lstDireccion[j].exterior; txtInterior.Text = lstDireccion[j].interior; txtColonia.Text = lstDireccion[j].colonia; txtCP.Text = lstDireccion[j].cp; txtMunicipio.Text = lstDireccion[j].ciudad; txtEstado.Text = lstDireccion[j].estado; txtPais.Text = lstDireccion[j].pais; } } catch (Exception error) { MessageBox.Show("Error: \r\n \r\n " + error.Message, "Error"); } if (_tipoOperacion == GLOBALES.CONSULTAR) { toolTitulo.Text = "Consulta del Complemento"; GLOBALES.INHABILITAR(this, typeof(TextBox)); GLOBALES.INHABILITAR(this, typeof(MaskedTextBox)); GLOBALES.INHABILITAR(this, typeof(ComboBox)); toolGuardar.Enabled = false; } else toolTitulo.Text = "Edición del Complemento"; } else { lblEmpleado.Text = _nombreEmpleado; } }