Beispiel #1
0
        private void frmInfonavit_Load(object sender, EventArgs e)
        {
            cargaCombo();
            if (_tipoOperacion == GLOBALES.CONSULTAR || _tipoOperacion == GLOBALES.MODIFICAR)
            {
                cnx = new SqlConnection();
                cnx.ConnectionString = cdn;
                cmd = new SqlCommand();
                cmd.Connection = cnx;
                ih = new Infonavit.Core.InfonavitHelper();
                ih.Command = cmd;

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

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

                List<Infonavit.Core.Infonavit> lstInfonavit;
                List<Departamento.Core.Depto> lstDepartamento = new List<Departamento.Core.Depto>();
                List<Empleados.Core.Empleados> lstEmpleado = new List<Empleados.Core.Empleados>();

                Empleados.Core.Empleados empleado = new Empleados.Core.Empleados();
                empleado.idtrabajador = _idEmpleado;

                Departamento.Core.Depto dpto = new Departamento.Core.Depto();
                dpto.idempresa = GLOBALES.IDEMPRESA;

                Infonavit.Core.Infonavit i = new Infonavit.Core.Infonavit();
                i.idtrabajador = _idEmpleado;
                i.activo = _estatusInfonavit;

                try
                {
                    cnx.Open();
                    Periodo = (int)eh.obtenerDiasPeriodo(_idEmpleado);
                    lstEmpleado = eh.obtenerEmpleado(empleado);
                    lstDepartamento = dh.obtenerDepartamentos(dpto);
                    cnx.Close();
                }
                catch (Exception error)
                {
                    MessageBox.Show("Error al obtener los dias del periodo. \r\n \r\n La ventana se cerrará. \r\n \r\n" + error.Message, "Error");
                    cnx.Dispose();
                    this.Dispose();
                }

                var dato = from emp in lstEmpleado
                           join d in lstDepartamento on emp.iddepartamento equals d.id
                           select new
                           {
                               emp.noempleado,
                               emp.nombrecompleto,
                               d.descripcion
                           };
                foreach (var inf in dato)
                {
                    mtxtNoEmpleado.Text = inf.noempleado;
                    txtDepartamento.Text = inf.descripcion;
                }

                try
                {
                    cnx.Open();
                    lstInfonavit = ih.obtenerInfonavit(i);
                    Periodo = (int)eh.obtenerDiasPeriodo(_idEmpleado);
                    cnx.Close();
                    cnx.Dispose();

                    for (int j = 0; j < lstInfonavit.Count; j++)
                    {
                        IdInfonavit = int.Parse(lstInfonavit[j].idinfonavit.ToString());
                        txtNumeroCredito.Text = lstInfonavit[j].credito;
                        txtValor.Text = lstInfonavit[j].valordescuento.ToString();
                        if (lstInfonavit[j].activo)
                            chkInactivo.Checked = false;
                        else
                            chkInactivo.Checked = true;
                        txtDescripcion.Text = lstInfonavit[j].descripcion;
                        dtpFechaAplicacion.Value = lstInfonavit[j].fecha;
                        cmbEstatusInfonavit.SelectedValue = lstInfonavit[j].estatus;
                        //dtpInicioPeriodo.Value = lstInfonavit[j].inicio.AddDays(1);
                        //dtpFinPeriodo.Value = lstInfonavit[j].fin;

                        switch (lstInfonavit[j].descuento)
                        {
                                //Porcentaje
                            case 1:
                                rbtnPorcentaje.Checked = true;
                                break;
                            case 2:
                                rbtnPesos.Checked = true;
                                if (Periodo == 7)
                                    txtValor.Text = ((lstInfonavit[j].valordescuento * decimal.Parse((30.4).ToString())) / Periodo).ToString();
                                else
                                    txtValor.Text = (lstInfonavit[j].valordescuento * 2).ToString();
                                break;
                            case 3:
                                rbtnVsmdf.Checked = true;
                                txtValor.Text = lstInfonavit[j].valordescuento.ToString();
                                break;
                        }
                    }
                }
                catch (Exception error)
                {
                    MessageBox.Show("Error: \r\n \r\n " + error.Message, "Error");
                }

                if (_tipoOperacion == GLOBALES.CONSULTAR)
                {
                    toolVentana.Text = "Consulta del Crédito";
                    GLOBALES.INHABILITAR(this, typeof(TextBox));
                    GLOBALES.INHABILITAR(this, typeof(RadioButton));
                    GLOBALES.INHABILITAR(this, typeof(CheckBox));
                    GLOBALES.INHABILITAR(this, typeof(DateTimePicker));
                    GLOBALES.INHABILITAR(this, typeof(MaskedTextBox));
                    GLOBALES.INHABILITAR(this, typeof(ComboBox));
                    toolGuardar.Enabled = false;
                    toolBuscar.Enabled = false;
                }
                else
                {
                    toolVentana.Text = "Edición del Crédito";
                    lblEmpleado.Text = _nombreEmpleado;
                    toolBuscar.Enabled = false;
                    //obtenerPeriodoActual();
                }

                if (_modificar == 1)
                {
                    //dtpInicioPeriodo.Enabled = true;
                }
            }
        }
        private void ListaEmpleados()
        {
            string cdn = ConfigurationManager.ConnectionStrings["cdnNomina"].ConnectionString;
            cnx = new SqlConnection(cdn);
            cmd = new SqlCommand();
            cmd.Connection = cnx;
            ih = new Infonavit.Core.InfonavitHelper();
            eh = new Empleados.Core.EmpleadosHelper();
            ih.Command = cmd;
            eh.Command = cmd;

            Infonavit.Core.suaInfonavit sua = new Infonavit.Core.suaInfonavit();
            sua.idempresa = GLOBALES.IDEMPRESA;

            Empleados.Core.Empleados empleado = new Empleados.Core.Empleados();
            empleado.idempresa = GLOBALES.IDEMPRESA;
            empleado.estatus = GLOBALES.ACTIVO;

            try
            {
                cnx.Open();
                lstInf = ih.obtenerInfonavit(sua);
                lstEmpleados = eh.obtenerEmpleados(empleado);
                cnx.Close();
                cnx.Dispose();

                var inf = from i in lstInf
                            join t in lstEmpleados on i.idtrabajador equals t.idtrabajador
                            select new
                            {
                                RegistroPatronal = i.registropatronal,
                                Nss = i.nss,
                                Nombre = t.nombrecompleto,
                                Credito = i.credito,
                                Modificacion = i.modificacion,
                                Descuento = i.descuento,
                                Fecha = i.fecha,
                                Valor = i.valor
                            };
                dgvInfSua.DataSource = inf.ToList();

                for (int i = 0; i < dgvInfSua.Columns.Count; i++)
                {
                    dgvInfSua.AutoResizeColumn(i);
                }
            }
            catch (Exception error)
            {
                MessageBox.Show("Error: \r\n \r\n " + error.Message, "Error");
            }
        }