Exemplo n.º 1
0
        private void toolAplicar_Click(object sender, EventArgs e)
        {
            if (dgvCargaFaltas.Rows.Count == 0)
            {
                MessageBox.Show("No se puede aplicar verifique.", "Error");
                return;
            }

            int idEmpleado = 0;
            bool EsAlta = false, EsReingreso = false, EsBaja = false;

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

            fh = new Faltas.Core.FaltasHelper();
            fh.Command = cmd;

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

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

            Reingreso.Core.ReingresoHelper rh = new Reingreso.Core.ReingresoHelper();
            rh.Command = cmd;

            Bajas.Core.BajasHelper bh = new Bajas.Core.BajasHelper();
            bh.Command = cmd;

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

            List<Altas.Core.Altas> lstAlta;
            List<Reingreso.Core.Reingresos> lstReingreso;
            List<Bajas.Core.Bajas> lstBaja;

            foreach (DataGridViewRow fila in dgvCargaFaltas.Rows)
            {
                try
                {
                    cnx.Open();
                    idEmpleado = (int)emph.obtenerIdTrabajador(fila.Cells["noempleado"].Value.ToString(), idEmpresa);
                    cnx.Close();

                }
                catch (Exception error)
                {
                    MessageBox.Show("Error: Obtener ID del empleado. \r\n \r\n" + error.Message, "Error");
                    return;
                }

                int idperiodo = 0;
                try
                {
                    cnx.Open();
                    idperiodo = (int)emph.obtenerIdPeriodo(idEmpleado);
                    cnx.Close();
                }
                catch
                {
                    MessageBox.Show("Error: al obtener el Id del Periodo.", "Error");
                    cnx.Dispose();
                    return;
                }

                Altas.Core.Altas alta = new Altas.Core.Altas();
                alta.idempresa = GLOBALES.IDEMPRESA;
                alta.idtrabajador = idEmpleado;
                alta.periodoInicio = _inicioPeriodo.Date;
                alta.periodoFin = _finPeriodo.Date;

                Reingreso.Core.Reingresos reingreso = new Reingreso.Core.Reingresos();
                reingreso.idempresa = GLOBALES.IDEMPRESA;
                reingreso.idtrabajador = idEmpleado;
                reingreso.periodoinicio = _inicioPeriodo.Date;
                reingreso.periodofin = _finPeriodo.Date;

                Bajas.Core.Bajas baja = new Bajas.Core.Bajas();
                baja.idempresa = GLOBALES.IDEMPRESA;
                baja.idtrabajador = idEmpleado;
                baja.periodoinicio = _inicioPeriodo.Date;
                baja.periodofin = _finPeriodo.Date;

                lstAlta = new List<Altas.Core.Altas>();
                lstReingreso = new List<Reingreso.Core.Reingresos>();
                lstBaja = new List<Bajas.Core.Bajas>();

                Periodos.Core.Periodos p = new Periodos.Core.Periodos();
                p.idperiodo = idperiodo;

                int periodo = 0;
                try
                {
                    cnx.Open();
                    periodo = (int)ph.DiasDePago(p);

                    lstAlta = ah.obtenerAlta(alta);
                    lstReingreso = rh.obtenerReingreso(reingreso);
                    lstBaja = bh.obtenerBaja(baja);
                    cnx.Close();
                }
                catch
                {
                    MessageBox.Show("Error: al obtener los dias de pago.", "Error");
                    cnx.Dispose();
                    return;
                }

                if (lstAlta.Count != 0)
                    EsAlta = true;
                if (lstBaja.Count != 0)
                    EsBaja = true;
                if (lstReingreso.Count != 0)
                    EsReingreso = true;

                int falta = int.Parse(fila.Cells["faltas"].Value.ToString());
                DateTime fecha = DateTime.Parse(fila.Cells["fechainicio"].Value.ToString());

                if (falta > 15)
                    falta = 15;

                for (int i = 0; i < falta; i++)
                {
                    int existe = 0;
                    int existeFalta = 0;
                    int existeVacacion = 0;
                    try
                    {
                        cnx.Open();
                        existeFalta = (int)fh.existeFalta(idEmpleado, fecha.AddDays(i).Date);
                        cnx.Close();
                    }
                    catch
                    {
                        MessageBox.Show("Error: Al verificar existencia de falta.", "Error");
                        cnx.Dispose();
                        return;
                    }

                    if (existeFalta == 0)
                    {
                        Incidencias.Core.IncidenciasHelper ih = new Incidencias.Core.IncidenciasHelper();
                        ih.Command = cmd;

                        Vacaciones.Core.VacacionesHelper vh = new Vacaciones.Core.VacacionesHelper();
                        vh.Command = cmd;

                        bool FLAG_FALTAS = false;

                        if (EsAlta)
                        {
                            if (fecha.AddDays(i).Date < lstAlta[0].fechaingreso.Date)
                            {
                                MessageBox.Show("Error: Alta del empleado: " + fila.Cells["noempleado"].Value.ToString() + ", Fecha de Ingreso = " + lstAlta[0].fechaingreso.Date.ToShortDateString() + "\r\n Fecha de la falta es menor.", "Error");
                                FLAG_FALTAS = true;
                            }
                            else
                                FLAG_FALTAS = false;
                        }

                        if (EsReingreso)
                        {
                            if (fecha.AddDays(i).Date < lstReingreso[0].fechaingreso.Date)
                            {
                                MessageBox.Show("Error: Alta del empleado: " + fila.Cells["noempleado"].Value.ToString() + ", Fecha de Reingreso = " + lstReingreso[0].fechaingreso.Date.ToShortDateString() + "\r\n Fecha de la falta es menor.", "Error");
                                FLAG_FALTAS = true;
                            }
                            else
                                FLAG_FALTAS = false;
                        }

                        if (EsBaja)
                        {
                            if (fecha.AddDays(i).Date > lstBaja[0].fecha.Date)
                            {
                                MessageBox.Show("Error: Alta del empleado " + fila.Cells["noempleado"].Value.ToString() +
                                    ", Fecha de Reingreso = " + lstBaja[0].fecha.Date.ToShortDateString() +
                                    "\r\n Fecha de la falta es mayor.", "Error");
                                FLAG_FALTAS = true;
                            }
                            else
                                FLAG_FALTAS = false;
                        }

                        if (!FLAG_FALTAS)
                        {
                            try
                            {
                                cnx.Open();
                                existe = (int)ih.existeIncidenciaEnFalta(idEmpleado, fecha.AddDays(i).Date);
                                existeVacacion = (int)vh.existeVacacionEnFalta(idEmpleado, fecha.AddDays(i).Date);
                                cnx.Close();
                            }
                            catch
                            {
                                MessageBox.Show("Error: Al guardar la falta.", "Error");
                                cnx.Dispose();
                                return;
                            }

                            if (existe == 0 && existeVacacion == 0)
                                try
                                {
                                    Faltas.Core.Faltas f = new Faltas.Core.Faltas();
                                    f.idempresa = GLOBALES.IDEMPRESA;
                                    f.idtrabajador = idEmpleado;
                                    f.periodo = periodo;
                                    f.faltas = 1;
                                    f.fechainicio = DateTime.Parse(dgvCargaFaltas.Rows[0].Cells["fechainicio"].Value.ToString());
                                    f.fechafin = DateTime.Parse(dgvCargaFaltas.Rows[0].Cells["fechafin"].Value.ToString());
                                    f.fecha = fecha.AddDays(i).Date;

                                    cnx.Open();
                                    fh.insertaFalta(f);
                                    cnx.Close();
                                }
                                catch
                                {
                                    MessageBox.Show("Error: Al guardar la falta.", "Error");
                                    cnx.Dispose();
                                }
                            else
                                MessageBox.Show("La falta ingresada, se empalma con una incapacidad y/o dia de vacación del trabajador.", "Error");
                        }
                    }
                }
                EsAlta = false; EsReingreso = false; EsBaja = false;
            }
            MessageBox.Show("Faltas importadas", "Confirmación");
            cnx.Dispose();
            dgvCargaFaltas.Rows.Clear();
        }
Exemplo n.º 2
0
        private void ChecaFechaAltaReingreso()
        {
            DateTime inicio = DateTime.Now.Date, fin = DateTime.Now.Date;

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

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

            Reingreso.Core.ReingresoHelper rh = new Reingreso.Core.ReingresoHelper();
            rh.Command = cmd;

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

            List<CalculoNomina.Core.tmpPagoNomina> lstUltimaNomina = new List<CalculoNomina.Core.tmpPagoNomina>();

            try
            {
                cnx.Open();
                lstUltimaNomina = nh.obtenerUltimaNomina(GLOBALES.IDEMPRESA, false);
                cnx.Close();
            }
            catch (Exception error)
            {
                MessageBox.Show("Error: \r\n \r\n" + error.Message, "Error");
            }

            if (lstUltimaNomina.Count != 0)
            {
                if (Periodo == 7)
                {
                    inicio = lstUltimaNomina[0].fechafin.AddDays(1);
                    fin = lstUltimaNomina[0].fechafin.AddDays(7);
                }
                else
                {
                    inicio = lstUltimaNomina[0].fechafin.AddDays(1);
                    if (inicio.Day <= 15)
                        fin = lstUltimaNomina[0].fechafin.AddDays(15);
                    else
                        fin = new DateTime(inicio.Year, inicio.Month,
                            DateTime.DaysInMonth(inicio.Year, inicio.Month));
                }
            }

            Altas.Core.Altas a = new Altas.Core.Altas();
            a.idtrabajador = _idEmpleado;
            a.periodoInicio = inicio.Date;
            a.periodoFin = fin.Date;

            Reingreso.Core.Reingresos r = new Reingreso.Core.Reingresos();
            r.idtrabajador = _idEmpleado;
            r.periodoinicio = inicio.Date;
            r.periodofin = fin.Date;

            int existeAlta = 0;
            int existeReingreso = 0;

            try
            {
                cnx.Open();
                existeAlta = (int)ah.existeAlta(a);
                existeReingreso = (int)rh.existeReingreso(r);
                cnx.Close();
            }
            catch (Exception)
            {
                MessageBox.Show("Error: Al obtener la existencia de la alta.", "Error");
                cnx.Dispose();
            }

            DateTime fechaAlta = DateTime.Now.Date;
            DateTime fechaReingreso = DateTime.Now.Date;
            if (existeAlta != 0)
            {
                try
                {
                    cnx.Open();
                    fechaAlta = DateTime.Parse(ah.fechaAlta(a).ToString());
                    cnx.Close();
                }
                catch (Exception)
                {
                    MessageBox.Show("Error: Al obtener la fecha de alta.", "Error");
                    cnx.Dispose();
                }

                if (dtpFechaAplicacion.Value.Date < fechaAlta)
                    dtpFechaAplicacion.Value = fechaAlta;
            }

            if (existeReingreso != 0)
            {
                try
                {
                    cnx.Open();
                    fechaReingreso = DateTime.Parse(rh.fechaReingreso(r).ToString());
                    cnx.Close();
                }
                catch (Exception)
                {
                    MessageBox.Show("Error: Al obtener la fecha de alta.", "Error");
                    cnx.Dispose();
                }

                if (dtpFechaAplicacion.Value.Date < fechaReingreso)
                    dtpFechaAplicacion.Value = fechaReingreso;
            }
        }
Exemplo n.º 3
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            DateTime periodoInicio, periodoFin;
            bool EsAlta = false, EsReingreso = false, EsBaja = false;

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

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

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

            Reingreso.Core.ReingresoHelper rh = new Reingreso.Core.ReingresoHelper();
            rh.Command = cmd;

            Bajas.Core.BajasHelper bh = new Bajas.Core.BajasHelper();
            bh.Command = cmd;

            List<Altas.Core.Altas> lstAlta = new List<Altas.Core.Altas>();
            List<Reingreso.Core.Reingresos> lstReingreso = new List<Reingreso.Core.Reingresos>();
            List<Bajas.Core.Bajas> lstBaja = new List<Bajas.Core.Bajas>();

            Altas.Core.Altas alta = new Altas.Core.Altas();
            alta.idempresa = GLOBALES.IDEMPRESA;
            alta.idtrabajador = idTrabajador;
            alta.periodoInicio = _inicioPeriodo.Date;
            alta.periodoFin = _finPeriodo.Date;

            Reingreso.Core.Reingresos reingreso = new Reingreso.Core.Reingresos();
            reingreso.idempresa = GLOBALES.IDEMPRESA;
            reingreso.idtrabajador = idTrabajador;
            reingreso.periodoinicio = _inicioPeriodo.Date;
            reingreso.periodofin = _finPeriodo.Date;

            Bajas.Core.Bajas baja = new Bajas.Core.Bajas();
            baja.idempresa = GLOBALES.IDEMPRESA;
            baja.idtrabajador = idTrabajador;
            baja.periodoinicio = _inicioPeriodo.Date;
            baja.periodofin = _finPeriodo.Date;

            int idperiodo = 0;
            try
            {
                cnx.Open();
                idperiodo = (int)emph.obtenerIdPeriodo(idTrabajador);

                lstAlta = ah.obtenerAlta(alta);
                lstReingreso = rh.obtenerReingreso(reingreso);
                lstBaja = bh.obtenerBaja(baja);
                cnx.Close();
            }
            catch
            {
                MessageBox.Show("Error: al obtener el Id del Periodo.","Error");
                cnx.Dispose();
                return;
            }

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

            Periodos.Core.Periodos p = new Periodos.Core.Periodos();
            p.idperiodo = idperiodo;

            int periodo = 0;
            try
            {
                cnx.Open();
                periodo = (int)ph.DiasDePago(p);
                cnx.Close();
            }
            catch
            {
                MessageBox.Show("Error: al obtener los dias de pago.", "Error");
                cnx.Dispose();
                return;
            }

            if (periodo == 7)
            {
                DateTime dt = dtpFecha.Value.Date;
                while (dt.DayOfWeek != DayOfWeek.Monday) dt = dt.AddDays(-1);
                periodoInicio = dt;
                periodoFin = dt.AddDays(6);
            }
            else
            {
                if (dtpFecha.Value.Day <= 15)
                {
                    periodoInicio = new DateTime(dtpFecha.Value.Year, dtpFecha.Value.Month, 1);
                    periodoFin = new DateTime(dtpFecha.Value.Year, dtpFecha.Value.Month, 15);
                }
                else
                {
                    periodoInicio = new DateTime(dtpFecha.Value.Year, dtpFecha.Value.Month, 16);
                    periodoFin = new DateTime(dtpFecha.Value.Year, dtpFecha.Value.Month, DateTime.DaysInMonth(dtpFecha.Value.Year, dtpFecha.Value.Month));
                }
            }

            if (lstAlta.Count != 0)
                EsAlta = true;
            if (lstBaja.Count != 0)
                EsBaja = true;
            if (lstReingreso.Count != 0)
                EsReingreso = true;

            Faltas.Core.FaltasHelper fh = new Faltas.Core.FaltasHelper();
            fh.Command = cmd;

            List<Faltas.Core.Faltas> lstFaltas = new List<Faltas.Core.Faltas>();

            int faltas = int.Parse(txtFalta.Text);
            if (int.Parse(txtFalta.Text) > 15)
                faltas = 15;

            for (int i = 0; i < faltas; i++)
            {
                int existe = 0;
                int existeVacacion = 0;
                try
                {
                    cnx.Open();
                    existe = (int)fh.existeFalta(idTrabajador, dtpFecha.Value.AddDays(i).Date);
                    cnx.Close();
                }
                catch
                {
                    MessageBox.Show("Error: Al verificar existencia de falta.", "Error");
                    cnx.Dispose();
                    return;
                }

                if (existe != 0)
                {
                    MessageBox.Show("Ya existe una falta con esa fecha.", "Error");
                    //return;
                }
                else
                {
                    Incidencias.Core.IncidenciasHelper ih = new Incidencias.Core.IncidenciasHelper();
                    ih.Command = cmd;

                    Vacaciones.Core.VacacionesHelper vh = new Vacaciones.Core.VacacionesHelper();
                    vh.Command = cmd;

                    bool FLAG_FALTAS = false;

                    if (EsAlta)
                    {
                        if (dtpFecha.Value.AddDays(i).Date < lstAlta[0].fechaingreso.Date)
                        {
                            MessageBox.Show("Error: Alta del empleado, Fecha de Ingreso = " + lstAlta[0].fechaingreso.Date.ToShortDateString() + "\r\n Fecha de la falta es menor.", "Error");
                            FLAG_FALTAS = true;
                        }
                        else
                            FLAG_FALTAS = false;
                    }

                    if (EsReingreso)
                    {
                        if (dtpFecha.Value.AddDays(i).Date < lstReingreso[0].fechaingreso.Date)
                        {
                            MessageBox.Show("Error: Alta del empleado, Fecha de Reingreso = " + lstReingreso[0].fechaingreso.Date.ToShortDateString() + "\r\n Fecha de la falta es menor.", "Error");
                            FLAG_FALTAS = true;
                        }
                        else
                            FLAG_FALTAS = false;
                    }

                    if (EsBaja)
                    {
                        if (dtpFecha.Value.AddDays(i).Date > lstBaja[0].fecha.Date)
                        {
                            MessageBox.Show("Error: Alta del empleado, Fecha de Reingreso = " + lstBaja[0].fecha.Date.ToShortDateString() + "\r\n Fecha de la falta es mayor.", "Error");
                            FLAG_FALTAS = true;
                        }
                        else
                            FLAG_FALTAS = false;
                    }

                    if (!FLAG_FALTAS)
                    {
                        try
                        {
                            cnx.Open();
                            existe = (int)ih.existeIncidenciaEnFalta(idTrabajador, dtpFecha.Value.AddDays(i).Date);
                            existeVacacion = (int)vh.existeVacacionEnFalta(idTrabajador, dtpFecha.Value.AddDays(i).Date);
                            cnx.Close();
                        }
                        catch
                        {
                            MessageBox.Show("Error: Al guardar la falta.", "Error");
                            cnx.Dispose();
                            return;
                        }

                        if (existe == 0 && existeVacacion == 0)
                        {
                            Faltas.Core.Faltas falta = new Faltas.Core.Faltas();
                            falta.idtrabajador = idTrabajador;
                            falta.idempresa = GLOBALES.IDEMPRESA;
                            falta.faltas = 1;
                            falta.fechainicio = periodoInicio.Date;
                            falta.fechafin = periodoFin.Date;
                            falta.fecha = dtpFecha.Value.AddDays(i).Date;
                            falta.periodo = periodo;
                            lstFaltas.Add(falta);
                        }
                        else
                            MessageBox.Show("La falta ingresada, se empalma con una incapacidad y/o dia de vacación del trabajador.",
                                "Error");
                    }

                }
            }

            if (lstFaltas.Count != 0)
            {
                SqlBulkCopy bulk = new SqlBulkCopy(cnx);
                fh.bulkCommand = bulk;

                DataTable dtFalta = new DataTable();
                DataRow dtFilaFalta;
                dtFalta.Columns.Add("id", typeof(Int32));
                dtFalta.Columns.Add("idtrabajador", typeof(Int32));
                dtFalta.Columns.Add("idempresa", typeof(Int32));
                dtFalta.Columns.Add("periodo", typeof(Int32));
                dtFalta.Columns.Add("faltas", typeof(Int32));
                dtFalta.Columns.Add("fechainicio", typeof(DateTime));
                dtFalta.Columns.Add("fechafin", typeof(DateTime));
                dtFalta.Columns.Add("fecha", typeof(DateTime));

                for (int i = 0; i < lstFaltas.Count; i++)
                {
                    dtFilaFalta = dtFalta.NewRow();
                    dtFilaFalta["id"] = i + 1;
                    dtFilaFalta["idtrabajador"] = lstFaltas[i].idtrabajador;
                    dtFilaFalta["idempresa"] = lstFaltas[i].idempresa;
                    dtFilaFalta["periodo"] = lstFaltas[i].periodo;
                    dtFilaFalta["faltas"] = lstFaltas[i].faltas;
                    dtFilaFalta["fechainicio"] = lstFaltas[i].fechainicio;
                    dtFilaFalta["fechafin"] = lstFaltas[i].fechafin;
                    dtFilaFalta["fecha"] = lstFaltas[i].fecha;
                    dtFalta.Rows.Add(dtFilaFalta);
                }

                try
                {
                    cnx.Open();
                    fh.bulkFaltas(dtFalta, "tmpFaltas");
                    fh.stpFaltas();
                    cnx.Close();
                    cnx.Dispose();
                    muestraFaltas();
                }
                catch (Exception error)
                {
                    MessageBox.Show("Error: \r\n \r\n" + error.Message + "\r\n \r\n Error Bulk Faltas.", "Error");
                }
            }
        }
Exemplo n.º 4
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;
            }
        }
Exemplo n.º 5
0
        private void ListaEmpleados()
        {
            string cdn = ConfigurationManager.ConnectionStrings["cdnNomina"].ConnectionString;
            cnx = new SqlConnection(cdn);
            cmd = new SqlCommand();
            cmd.Connection = cnx;
            ah = new Altas.Core.AltasHelper();
            ch = new Catalogos.Core.CatalogosHelper();
            ah.Command = cmd;
            ch.Command = cmd;

            Altas.Core.Altas alta = new Altas.Core.Altas();
            alta.idempresa = GLOBALES.IDEMPRESA;

            try
            {
                cnx.Open();
                lstAltas = ah.obtenerAltas(alta);
                lstCatalogos = ch.obtenerCatalogos();
                cnx.Close();
                cnx.Dispose();

                var alt = from a in lstAltas join c in lstCatalogos on a.contrato equals c.id
                          join j in lstCatalogos on a.jornada equals j.id
                         select new
                         {
                             RegistroPatronal = a.registropatronal,
                             Nss = a.nss,
                             Rfc = a.rfc,
                             Curp = a.curp,
                             ApPaterno = a.paterno,
                             ApMaterno = a.materno,
                             Nombre = a.nombre,
                             Contrato = c.descripcion,
                             CValor = c.valor,
                             Jornada = j.descripcion,
                             JValor = j.valor,
                             Ingreso = a.fechaingreso,
                             Integrado = a.sdi,
                             CPostal = a.cp,
                             Nacimiento = a.fechanacimiento,
                             Estado = a.estado,
                             NoEstado = a.noestado,
                             Clinica = a.clinica,
                             Sexo = a.sexo
                         };
                dgvAltasSua.DataSource = alt.ToList();

                for (int i = 0; i < dgvAltasSua.Columns.Count; i++)
                {
                    dgvAltasSua.AutoResizeColumn(i);
                }

                dgvAltasSua.Columns["CValor"].Visible = false;
                dgvAltasSua.Columns["JValor"].Visible = false;
                dgvAltasSua.Columns["NoEstado"].Visible = false;
            }
            catch (Exception error)
            {
                MessageBox.Show("Error: \r\n \r\n " + error.Message, "Error");
            }

            DataGridViewCellStyle estilo = new DataGridViewCellStyle();
            estilo.Alignment = DataGridViewContentAlignment.MiddleRight;
            dgvAltasSua.Columns[9].DefaultCellStyle = estilo;
        }
Exemplo n.º 6
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;
            }

            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 ListaEmpleados(int operacion)
        {
            string cdn = ConfigurationManager.ConnectionStrings["cdnNomina"].ConnectionString;
            cnx = new SqlConnection(cdn);
            cmd = new SqlCommand();
            cmd.Connection = cnx;

            eh = new Empleados.Core.EmpleadosHelper();
            eh.Command = cmd;
            Empleados.Core.Empleados empleado = new Empleados.Core.Empleados();
            empleado.idempresa = GLOBALES.IDEMPRESA;
            empleado.estatus = GLOBALES.ACTIVO;

            switch (operacion)
            {
                #region ALTAS
                case 0: //ALTAS
                    ah = new Altas.Core.AltasHelper();
                    ah.Command = cmd;
                    Altas.Core.Altas alta = new Altas.Core.Altas();
                    alta.idempresa = GLOBALES.IDEMPRESA;
                    try
                    {
                        cnx.Open();
                        lstAltas = ah.obtenerAltas(alta);
                        cnx.Close();
                        cnx.Dispose();

                        var alt = from a in lstAltas
                                  select new
                                  {
                                      RegistroPatronal = a.registropatronal,
                                      Nss = a.nss,
                                      Curp = a.curp,
                                      ApPaterno = a.paterno,
                                      ApMaterno = a.materno,
                                      Nombre = a.nombre,
                                      Ingreso = a.fechaingreso,
                                      Integrado = a.sdi
                                  };
                        dgvDatos.DataSource = alt.ToList();
                    }
                    catch (Exception error)
                    {
                        MessageBox.Show("Error: \r\n \r\n " + error.Message, "Error");
                    }
                    break;
                #endregion

                #region MODIFICACIONES
                case 1: //MODIFICACIONES
                    mh = new Modificaciones.Core.ModificacionesHelper();
                    mh.Command = cmd;
                    Modificaciones.Core.Modificaciones modificacion = new Modificaciones.Core.Modificaciones();
                    modificacion.idempresa = GLOBALES.IDEMPRESA;
                    try
                    {
                        cnx.Open();
                        lstMod = mh.obtieneModificaciones(modificacion);
                        lstEmpleado = eh.obtenerEmpleados(empleado);
                        cnx.Close();
                        cnx.Dispose();

                        var mod = from m in lstMod
                                  join e in lstEmpleado on m.idtrabajador equals e.idtrabajador
                                  select new
                                  {
                                      RegistroPatronal = m.registropatronal,
                                      Nss = m.nss,
                                      Paterno = e.paterno,
                                      Materno = e.materno,
                                      Nombre = e.nombres,
                                      Curp = e.curp,
                                      Fecha = m.fecha,
                                      Integrado = m.sdi
                                  };
                        dgvDatos.DataSource = mod.ToList();
                    }
                    catch (Exception error)
                    {
                        MessageBox.Show("Error: \r\n \r\n " + error.Message, "Error");
                    }
                    break;
                #endregion

                #region BAJAS
                case 2://BAJAS
                    bh = new Bajas.Core.BajasHelper();
                    ch = new Catalogos.Core.CatalogosHelper();
                    bh.Command = cmd;
                    ch.Command = cmd;
                    Bajas.Core.Bajas baja = new Bajas.Core.Bajas();
                    Catalogos.Core.Catalogo catalogo = new Catalogos.Core.Catalogo();
                    baja.idempresa = GLOBALES.IDEMPRESA;
                    try
                    {
                        cnx.Open();
                        lstBaja = bh.obtenerBajas(baja);
                        lstEmpleado = eh.obtenerEmpleados(empleado);
                        lstCatalogo = ch.obtenerCatalogos();
                        cnx.Close();
                        cnx.Dispose();

                        var baj = from b in lstBaja
                                  join e in lstEmpleado on b.idtrabajador equals e.idtrabajador
                                  join c in lstCatalogo on b.motivo equals c.id
                                  select new
                                  {
                                      RegistroPatronal = b.registropatronal,
                                      Nss = b.nss,
                                      Paterno = e.paterno,
                                      Materno = e.materno,
                                      Nombre = e.nombres,
                                      Fecha = b.fecha,
                                      Motivo = c.valor
                                  };
                        dgvDatos.DataSource = baj.ToList();
                    }
                    catch (Exception error)
                    {
                        MessageBox.Show("Error: \r\n \r\n " + error.Message, "Error");
                    }
                    break;
                #endregion
            }
            for (int i = 0; i < dgvDatos.Columns.Count; i++)
            {
                dgvDatos.AutoResizeColumn(i);
            }
        }