Beispiel #1
0
        private void guardar(int tipoGuardar)
        {
            int existe = 0;
            //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;
            }

            if (txtNSS.Text.Length != 11)
            {
                MessageBox.Show("El campo NSS es mayor o meno a 11 dígitos.", "Error");
                return;
            }

            int idtrabajador;

            cnx = new SqlConnection();
            cnx.ConnectionString = cdn;
            cmd = new SqlCommand();
            cmd.Connection = cnx;
            eh = new Empleados.Core.EmpleadosHelper();
            eh.Command = cmd;

            CalculoNomina.Core.NominaHelper nh = new CalculoNomina.Core.NominaHelper();
            nh.Command = cmd;

            Empleados.Core.Empleados existeEmpleado = new Empleados.Core.Empleados();
            existeEmpleado.nss = txtNSS.Text.Trim().Substring(0, 10);
            existeEmpleado.digitoverificador = int.Parse(txtNSS.Text.Trim().Substring(10, 1));
            existeEmpleado.idempresa = GLOBALES.IDEMPRESA;

            int existeNss;
            try
            {
                cnx.Open();
                existeNss = (int)eh.existeEmpleado(existeEmpleado);
                cnx.Close();
            }
            catch
            {
                MessageBox.Show("Error al validar existencia de empleado.", "Error");
                return;
            }

            Empleados.Core.Empleados em = new Empleados.Core.Empleados();
            em.nombres = txtNombre.Text;
            em.paterno = txtApPaterno.Text;
            em.materno = txtApMaterno.Text;
            em.noempleado = mtxtNoEmpleado.Text;
            em.nombrecompleto = txtApPaterno.Text + (string.IsNullOrEmpty(txtApMaterno.Text) ? "" : " " + txtApMaterno.Text) + " " + txtNombre.Text;
            em.fechaingreso = dtpFechaIngreso.Value;
            em.antiguedad = int.Parse(txtAntiguedad.Text);
            em.fechaantiguedad = dtpFechaAntiguedad.Value;
            em.fechanacimiento = dtpFechaNacimiento.Value;
            em.antiguedadmod = int.Parse(txtAntiguedadMod.Text);
            em.edad = int.Parse(txtEdad.Text);
            em.idempresa = GLOBALES.IDEMPRESA;
            em.rfc = txtRFC.Text;
            em.curp = txtCURP.Text;
            em.nss = txtNSS.Text.Trim().Substring(0, 10);
            em.digitoverificador = int.Parse(txtNSS.Text.Trim().Substring(10, 1));

            em.idperiodo = int.Parse(cmbPeriodo.SelectedValue.ToString());
            em.idsalario = int.Parse(cmbZona.SelectedValue.ToString());
            em.tiposalario = int.Parse(cmbTipoSalario.SelectedValue.ToString());
            em.tiporegimen = int.Parse(cmbTipoRegimen.SelectedValue.ToString());

            em.sdi = decimal.Parse(txtSDI.Text);
            em.sd = decimal.Parse(txtSD.Text);
            em.sueldo = decimal.Parse(txtSueldo.Text);

            em.cuenta = mtxtCuentaBancaria.Text;
            em.clabe = mtxtCuentaClabe.Text;
            em.idbancario = mtxtIdBancario.Text;
            em.metodopago = cmbMetodoPago.Text;
            //em.metodopago = int.Parse(cmbMetodoPago.SelectedValue.ToString());

            if (chkObraCivil.Checked)
                em.obracivil = true;
            else
                em.obracivil = false;

            //hh = new Historial.Core.HistorialHelper();
            //hh.Command = cmd;
            //Historial.Core.Historial h = new Historial.Core.Historial();
            //h.idempresa = GLOBALES.IDEMPRESA;
            //h.tipomovimiento = GLOBALES.mALTA;
            //h.valor = decimal.Parse(txtSDI.Text);
            //h.fecha_imss = dtpFechaIngreso.Value;
            //h.fecha_sistema = DateTime.Now;
            //h.motivobaja = 0;
            //h.iddepartamento = int.Parse(cmbDepartamento.SelectedValue.ToString());
            //h.idpuesto = int.Parse(cmbPuesto.SelectedValue.ToString());

            ih = new Imagen.Core.ImagenesHelper();
            ih.Command = cmd;

            Imagen.Core.Imagenes img = null;

            //Empresas.Core.EmpresasHelper empresash = new Empresas.Core.EmpresasHelper();
            //empresash.Command = cmd;
            //Empresas.Core.Empresas empresa = new Empresas.Core.Empresas();
            //empresa.idempresa = GLOBALES.IDEMPRESA;

            try
            {
                if (ImagenAsignada == true)
                {
                    img = new Imagen.Core.Imagenes();
                    img.imagen = GLOBALES.IMAGEN_BYTES(bmp);
                    img.tipopersona = GLOBALES.pEMPLEADO;
                }
            }
            catch (Exception error)
            {
                MessageBox.Show("Error: " + error.Message, "Error");
            }

            switch (_tipoOperacion)
            {
                case 0:
                    try
                    {
                        //Empleados.Core.EmpleadosEstatus ee = new Empleados.Core.EmpleadosEstatus();
                        //ee.estatus = GLOBALES.ACTIVO;
                        //ee.idempresa = GLOBALES.IDEMPRESA;

                        em.estatus = GLOBALES.ACTIVO;
                        em.idusuario = GLOBALES.IDUSUARIO;
                        em.iddepartamento = int.Parse(cmbDepartamento.SelectedValue.ToString());
                        em.idpuesto = int.Parse(cmbPuesto.SelectedValue.ToString());

                        if (existeNss != 0)
                        {
                            MessageBox.Show("El empleado que desea ingresar ya existe actualmente. \r\n \r\n Es necesario realizar un reingreso.", "Error");
                            return;
                        }

                        cnx.Open();
                        eh.insertaEmpleado(em);
                        idtrabajador = (int)eh.obtenerIdTrabajador(em);

                        //h.idtrabajador = idtrabajador;
                        //hh.insertarHistorial(h);

                        //ee.idtrabajador = idtrabajador;
                        //eh.insertaEmpleadoEstatus(ee);

                        //a.idtrabajador = idtrabajador;
                        //a.registropatronal = empresash.obtenerRegistroPatronal(empresa).ToString();
                        //ah.insertaAlta(a);

                        if (ImagenAsignada == true)
                        {
                            img.idpersona = idtrabajador;
                            ih.insertaImagen(img);
                        }

                        cnx.Close();
                        cnx.Dispose();
                    }
                    catch (Exception error)
                    {
                        MessageBox.Show("Error al ingresar el empleado. \r\n \r\n Error: " + error.Message);
                    }
                    break;
                case 2:
                    try
                    {
                        em.idtrabajador = _idempleado;
                        em.iddepartamento = idDepto;
                        em.idpuesto = idPuesto;

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

                        Altas.Core.AltasHelper ah = new Altas.Core.AltasHelper();
                        ah.Command = cmd;
                        Altas.Core.Altas a = new Altas.Core.Altas();
                        a.idempresa = GLOBALES.IDEMPRESA;
                        a.contrato = 4;
                        a.jornada = 12;
                        a.nss = txtNSS.Text;
                        a.rfc = txtRFC.Text;
                        a.curp = txtCURP.Text;
                        a.paterno = txtApPaterno.Text;
                        a.materno = txtApMaterno.Text;
                        a.nombre = txtNombre.Text;
                        a.fechaingreso = dtpFechaIngreso.Value;
                        a.diasproporcionales = diasProporcionales;
                        a.sdi = decimal.Parse(txtSDI.Text);
                        a.fechanacimiento = dtpFechaNacimiento.Value;
                        a.estado = cmbEstado.Text;
                        a.noestado = int.Parse(cmbEstado.SelectedValue.ToString());
                        a.sexo = ObtieneSexo();
                        a.periodoInicio = periodoInicio;
                        a.periodoFin = periodoFin;

                        cnx.Open();
                        eh.actualizaEmpleado(em);

                        a.idtrabajador = _idempleado;
                        ah.actualizaAlta(a);

                        if (ImagenAsignada == true)
                        {
                            img.idpersona = _idempleado;
                            img.tipopersona = GLOBALES.pEMPLEADO;
                            existe = (int)ih.ExisteImagen(img);
                            if (existe != 0)
                                ih.actualizaImagen(img);
                            else
                                ih.insertaImagen(img);
                        }
                        cnx.Close();
                        cnx.Dispose();
                    }
                    catch (Exception error)
                    {
                        MessageBox.Show("Error al actualizar el empleado. \r\n \r\n Error: " + error.Message);
                    }
                    break;
            }

            switch (tipoGuardar)
            {
                case 0:
                    GLOBALES.LIMPIAR(this, typeof(TextBox));
                    GLOBALES.LIMPIAR(this, typeof(MaskedTextBox));
                    GLOBALES.REFRESCAR(this, typeof(ComboBox));
                    break;
                case 1:
                    if (OnNuevoEmpleado != null)
                        OnNuevoEmpleado(_tipoOperacion);
                    this.Dispose();
                    break;
            }
        }
Beispiel #2
0
        private void guardar(int tipoGuardar)
        {
            //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;
            eh             = new Empleados.Core.EmpleadosHelper();
            eh.Command     = cmd;

            Empleados.Core.Empleados em = new Empleados.Core.Empleados();
            em.nombres           = txtNombre.Text;
            em.paterno           = txtApMaterno.Text;
            em.materno           = txtApMaterno.Text;
            em.nombrecompleto    = txtApPaterno.Text + (string.IsNullOrEmpty(txtApMaterno.Text) ? "" : " " + txtApMaterno.Text) + " " + txtNombre.Text;
            em.fechanacimiento   = dtpFechaNacimiento.Value;
            em.edad              = int.Parse(txtEdad.Text);
            em.idempresa         = GLOBALES.IDEMPRESA;
            em.fechaingreso      = dtpFechaIngreso.Value;
            em.localforaneo      = cmbLocalForaneo.SelectedValue.ToString();
            em.sua               = cmbSua.SelectedValue.ToString();
            em.rfc               = txtRFC.Text;
            em.curp              = txtCURP.Text;
            em.nss               = txtNSS.Text;
            em.digitoverificador = int.Parse(txtDigito.Text);

            switch (_tipoOperacion)
            {
            case 0:
                try
                {
                    em.antiguedad  = 0;
                    em.idcliente   = int.Parse(cmbCliente.SelectedValue.ToString());
                    em.idperiodo   = int.Parse(cmbPeriodo.SelectedValue.ToString());
                    em.tiposalario = cmbTipoSalario.SelectedValue.ToString();
                    em.sdi         = decimal.Parse(txtSDI.Text);
                    em.sd          = decimal.Parse(txtSD.Text);
                    em.sueldo      = decimal.Parse(txtSueldo.Text);
                    em.idinfonavit = 0;
                    em.estatus     = 0;
                    em.idse        = 0;
                    em.modsalario  = 0;
                    em.idplaza     = GLOBALES.IDPLAZA;

                    cnx.Open();
                    eh.insertaEmpleado(em);
                    cnx.Close();
                    cnx.Dispose();
                }
                catch (Exception error)
                {
                    MessageBox.Show("Error al ingresar el empleado. \r\n \r\n Error: " + error.Message);
                }
                break;

            case 2:
                try
                {
                    em.idempresa = _idempleado;
                    cnx.Open();
                    eh.actualizaEmpleado(em);
                    cnx.Close();
                    cnx.Dispose();
                }
                catch (Exception error)
                {
                    MessageBox.Show("Error al actualizar el empleado. \r\n \r\n Error: " + error.Message);
                }
                break;
            }

            switch (tipoGuardar)
            {
            case 0:
                GLOBALES.LIMPIAR(this, typeof(TextBox));
                GLOBALES.LIMPIAR(this, typeof(MaskedTextBox));
                GLOBALES.REFRESCAR(this, typeof(ComboBox));
                break;

            case 1:
                if (OnNuevoEmpleado != null)
                {
                    OnNuevoEmpleado(_tipoOperacion);
                }
                this.Dispose();
                break;
            }
        }