Exemplo n.º 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;
            }
        }
        private void workerImporta_DoWork(object sender, DoWorkEventArgs e)
        {
            int contador = dgvCargaEmpleados.Rows.Count;
            int progreso = 0;

            cnx = new SqlConnection(cdn);
            cmd = new SqlCommand();
            cmd.Connection = cnx;

            foreach (DataGridViewRow fila in dgvCargaEmpleados.Rows)
            {

                workerImporta.ReportProgress((progreso * 100) / contador);
                progreso++;

                dh = new Departamento.Core.DeptoHelper();
                dh.Command = cmd;

                puestoh = new Puestos.Core.PuestosHelper();
                puestoh.Command = cmd;

                ph = new Periodos.Core.PeriodosHelper();
                ph.Command = cmd;

                try
                {
                    cnx.Open();
                    idDepto = (int)dh.obtenerIdDepartamento(fila.Cells["departamento"].Value.ToString(), GLOBALES.IDEMPRESA);
                    idPuesto = (int)puestoh.obtenerIdPuesto(fila.Cells["puesto"].Value.ToString(), GLOBALES.IDEMPRESA);
                    idPeriodo = (int)ph.obtenerIdPeriodo(fila.Cells["periodo"].Value.ToString(), GLOBALES.IDEMPRESA);
                    cnx.Close();
                }
                catch
                {
                    MessageBox.Show("Error: Al obtener los datos del Departamento, Puesto y/o Periodo.", "Error");
                    cnx.Dispose();
                    return;
                }

                Empleados.Core.Empleados empleado = new Empleados.Core.Empleados();
                empleado.noempleado = fila.Cells["noempleado"].Value.ToString();
                empleado.nombres = fila.Cells["nombre"].Value.ToString();
                empleado.paterno = fila.Cells["paterno"].Value.ToString();
                empleado.materno = fila.Cells["materno"].Value.ToString();
                empleado.nombrecompleto = String.Format("{0} {1} {2}", empleado.paterno, empleado.materno, empleado.nombres);
                empleado.idempresa = GLOBALES.IDEMPRESA;
                empleado.idperiodo = idPeriodo;
                empleado.idsalario = 1;
                empleado.iddepartamento = idDepto;
                empleado.idpuesto = idPuesto;
                empleado.fechaingreso = DateTime.Parse(fila.Cells["fechaingreso"].Value.ToString());
                empleado.antiguedad = 0;
                empleado.fechaantiguedad = DateTime.Parse(fila.Cells["fechaingreso"].Value.ToString());
                empleado.antiguedadmod = 0;
                empleado.fechanacimiento = ObtieneFecha(fila.Cells["curp"].Value.ToString());
                empleado.edad = ObtieneEdad(empleado.fechanacimiento);
                empleado.rfc = ObtenerRfc(empleado.paterno, empleado.materno, empleado.nombres, empleado.fechanacimiento);
                empleado.curp = fila.Cells["curp"].Value.ToString();
                empleado.nss = fila.Cells["nss"].Value.ToString();
                empleado.digitoverificador = int.Parse(fila.Cells["dv"].Value.ToString());
                empleado.tiposalario = 19;
                empleado.sdi = decimal.Parse(fila.Cells["sdi"].Value.ToString());
                empleado.sd = ObtieneSD(decimal.Parse(fila.Cells["sdi"].Value.ToString()));
                empleado.sueldo = ObtieneSueldo(empleado.sd);
                empleado.estatus = 1;
                empleado.idusuario = GLOBALES.IDUSUARIO;
                empleado.cuenta = "0000000000";
                empleado.clabe = "000000000000000000";
                empleado.idbancario = "0000";
                empleado.metodopago = "TRANSFERENCIA";
                empleado.tiporegimen = 60;

                //Empleados.Core.EmpleadosEstatus ee = new Empleados.Core.EmpleadosEstatus();
                //ee.estatus = GLOBALES.ACTIVO;
                //ee.idempresa = GLOBALES.IDEMPRESA;

                cnx = new SqlConnection(cdn);
                cmd = new SqlCommand();
                cmd.Connection = cnx;

                emph = new Empleados.Core.EmpleadosHelper();
                emph.Command = cmd;

                Empleados.Core.Empleados nss = new Empleados.Core.Empleados();
                nss.nss = empleado.nss;
                nss.digitoverificador = empleado.digitoverificador;
                int existeEmpleado = 0;
                try
                {
                    cnx.Open();
                    existeEmpleado = (int)emph.existeEmpleado(nss);
                    cnx.Close();
                }
                catch (Exception)
                {
                    MessageBox.Show("Error: Al obtener la existencia del empleado.", "Error");
                    cnx.Dispose();
                    return;
                }

                if (existeEmpleado == 0)
                {
                    try
                    {
                        cnx.Open();
                        emph.insertaEmpleado(empleado);
                        //ee.idtrabajador = (int)emph.obtenerIdTrabajador(empleado);
                        //emph.insertaEmpleadoEstatus(ee);
                        cnx.Close();
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Error: Al ingresar al empleado. No. empleado: " + fila.Cells["noempleado"].Value.ToString(), "Error");
                        cnx.Dispose();
                        return;
                    }

                    int idEmpleado = 0;
                    try
                    {
                        cnx.Open();
                        idEmpleado = (int)emph.obtenerIdTrabajador(fila.Cells["noempleado"].Value.ToString(), GLOBALES.IDEMPRESA);
                        cnx.Close();
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Error: Al obtener el ID del empleado. No. empleado: " + fila.Cells["noempleado"].Value.ToString(), "Error");
                        cnx.Dispose();
                        return;
                    }

                    //cnx = new SqlConnection(cdn);
                    //cmd = new SqlCommand();
                    //cmd.Connection = cnx;

                    //hh = new Historial.Core.HistorialHelper();
                    //hh.Command = cmd;

                    //Historial.Core.Historial historial = new Historial.Core.Historial();
                    //historial.idtrabajador = idEmpleado;
                    //historial.tipomovimiento = GLOBALES.mALTA;
                    //historial.valor = empleado.sdi;
                    //historial.fecha_imss = DateTime.Parse(fila.Cells["fechaingreso"].Value.ToString());
                    //historial.fecha_sistema = DateTime.Now.Date;
                    //historial.idempresa = GLOBALES.IDEMPRESA;
                    //historial.motivobaja = 0;

                    //try
                    //{
                    //    cnx.Open();
                    //    hh.insertarHistorial(historial);
                    //    cnx.Close();
                    //}
                    //catch (Exception)
                    //{
                    //    MessageBox.Show("Error: Al ingresar historial del trabajador. No. empleado: " + fila.Cells["noempleado"].Value.ToString(), "Error");
                    //    cnx.Dispose();
                    //    return;
                    //}

                    //cnx = new SqlConnection(cdn);
                    //cmd = new SqlCommand();
                    //cmd.Connection = cnx;

                    //eh = new Empresas.Core.EmpresasHelper();
                    //eh.Command = cmd;

                    //Empresas.Core.Empresas empresa = new Empresas.Core.Empresas();
                    //empresa.idempresa = GLOBALES.IDEMPRESA;

                    //try
                    //{
                    //    cnx.Open();
                    //    registroPatronal = eh.obtenerRegistroPatronal(empresa).ToString();
                    //    cnx.Close();
                    //}
                    //catch (Exception)
                    //{
                    //    MessageBox.Show("Error: Al obtener el registro patronal. NoEmpleado: " + fila.Cells["noempleado"].Value.ToString() + ".", "Error");
                    //    cnx.Dispose();
                    //    return;
                    //}

                    //Altas.Core.Altas alta = new Altas.Core.Altas();
                    //alta.idtrabajador = idEmpleado;
                    //alta.idempresa = GLOBALES.IDEMPRESA;
                    //alta.registropatronal = registroPatronal;
                    //alta.nss = empleado.nss + empleado.digitoverificador.ToString();
                    //alta.rfc = empleado.rfc;
                    //alta.curp = empleado.curp;
                    //alta.paterno = empleado.paterno;
                    //alta.materno = empleado.materno;
                    //alta.nombre = empleado.nombres;
                    //alta.contrato = 4;
                    //alta.jornada = 12;
                    //alta.fechaingreso = empleado.fechaingreso;
                    //alta.diasproporcionales = ObtenerDiasProporcionales(empleado.fechaingreso);
                    //alta.sdi = empleado.sdi;
                    //alta.cp = "0";
                    //alta.fechanacimiento = empleado.fechanacimiento;
                    //alta.estado = ObtenerEstado(empleado.curp);
                    //alta.noestado = ObtenerIdEstado(alta.estado);
                    //alta.clinica = "0";
                    //alta.sexo = ObtenerSexo(empleado.curp);
                    //alta.periodoInicio = periodoInicio;
                    //alta.periodoFin = periodoFin;

                    //cnx = new SqlConnection(cdn);
                    //cmd = new SqlCommand();
                    //cmd.Connection = cnx;

                    //ah = new Altas.Core.AltasHelper();
                    //ah.Command = cmd;

                    //try
                    //{
                    //    cnx.Open();
                    //    ah.insertaAlta(alta);
                    //    cnx.Close();
                    //}
                    //catch (Exception)
                    //{
                    //    MessageBox.Show("Error: Al ingresar alta del trabajador. No. empleado: " + fila.Cells["noempleado"].Value.ToString(), "Error");
                    //    cnx.Dispose();
                    //    return;
                    //}
                }
            }
            cnx.Dispose();
        }
Exemplo n.º 3
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;
            }
        }