Ejemplo n.º 1
0
        private void btnAgregar_Click(object sender, EventArgs e)
        {
            int existe = 0;
            cnx = new SqlConnection();
            cnx.ConnectionString = cdn;
            cmd = new SqlCommand();
            cmd.Connection = cnx;
            Conceptos.Core.ConceptosHelper ch = new Conceptos.Core.ConceptosHelper();
            ch.Command = cmd;
            Conceptos.Core.ConceptoTrabajador ct = new Conceptos.Core.ConceptoTrabajador();
            ct.idempleado = _idEmpleado;
            ct.idconcepto = int.Parse(cmbConcepto.SelectedValue.ToString());

            try
            {
                cnx.Open();
                existe = (int)ch.existeConceptoTrabajador(ct);
                if (existe.Equals(0))
                {
                    ch.insertaConceptoTrabajador(ct);
                }
                cnx.Close();
                cnx.Dispose();

                if (!existe.Equals(0))
                {
                    MessageBox.Show("Concepto ya esta relacionado con el trabajador.", "Información");
                }

                if (OnConcepto != null)
                    OnConcepto(_idEmpleado);
            }
            catch (Exception error)
            {
                MessageBox.Show("Error: \r\n \r\n" + error.Message, "Error");
            }
        }
Ejemplo n.º 2
0
        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();
        }