Public Class frmRendimientoFiltro
    Private Rendimiento As New Rendimientos
    Dim Operaciones As New Operaciones
    Dim MontoACC As String = String.Empty
    Dim MontoLET As String = String.Empty
    Dim MontoCET As String = String.Empty
    Dim MontoPBUR As String = String.Empty
    Dim MontoVCN As String = String.Empty
    Dim MontoBON As String = String.Empty
    Dim MontoCINV As String = String.Empty
    Dim MontoEURB As String = String.Empty
    Dim MontoTIT As String = String.Empty
    Dim MontoDAP As String = String.Empty
    Dim MontoFUT As String = String.Empty
    Dim MontoOPC As String = String.Empty
    Dim MontoPPER As String = String.Empty
    Dim MontoPEMP As String = String.Empty
    Dim MontoREP As String = String.Empty
    Dim Lista As String = String.Empty
    Dim ListaEmpresa As String = String.Empty
    Dim ListaInstrumentos As String = String.Empty
    Dim ListaNacionalidad As String = String.Empty
    Dim ListaEstado As String = String.Empty
    Dim ListaVigencia As String = String.Empty
    Dim ListaTipoRenta As String = String.Empty

    Dim ListaAgrupada As String = String.Empty




    Private TipoFecha As String = "N"
    Private SoloFecha As Date = Date.Now.Date
    Private FechaInicial As Date = Date.Now.Date
    Private FechaFinal As Date = Date.Now.Date
    Private Portafolio As String = "Activo"
    Private chk_PortafolioSinRenta As String = "Activo"


    Private rdb_VerRendimiento As String = "Todos"

    Private NuevoCheckEmpresa As Boolean = True


    Private Sub lblTitulo_Click(sender As Object, e As EventArgs) Handles lblTitulo.Click

    End Sub

    Private Sub CheckBox6_CheckedChanged(sender As Object, e As EventArgs) Handles chkPortafolioSinRenta.CheckedChanged
        If chkPortafolioSinRenta.Checked Then
            chk_PortafolioSinRenta = "Activo"
        Else
            chk_PortafolioSinRenta = "Desactivo"
        End If
    End Sub


    Sub CargarDatos()
        Dim dt As New DataTable
        ActualizarListas()
        dt = Rendimiento.TraerRendimientos(TipoFecha, FechaInicial, FechaFinal, ListaEmpresa, ListaInstrumentos, ListaTipoRenta, ListaNacionalidad, ListaVigencia, ListaEstado, SoloFecha, Lista)
        CalcularCamposGenerales(dt)
        AgregarPorcentajeRendGeneral(dt)
        dgvRendimientos.DataSource = dt
        OcultarColumnas()
    End Sub



    Sub AgregarPorcentajeRendGeneral(ByRef dt As DataTable)



        For Each rows As DataRow In dt.Rows
            If Not dt.Columns("Rendimientos") Is Nothing Then
                rows("Rendimientos") = (Operaciones.ConvertirDecimal(rows("Rendimientos").ToString) * 100).ToString + " %"
            End If
            If Not dt.Columns("Peso") Is Nothing Then
                rows("Peso") = (Operaciones.ConvertirDecimal(rows("Peso").ToString) * 100).ToString + " %"
            End If

            If Not dt.Columns("RendimientoActual") Is Nothing Then
                rows("RendimientoActual") = (Operaciones.ConvertirDecimal(rows("RendimientoActual").ToString) * 100).ToString + " %"
            End If

        Next
    End Sub
    Sub CalcularCamposGenerales(ByRef dt As DataTable)
        Dim MontoInversion As Double = 0
        Dim Rendimiento As Double = 0
        Dim Peso As Double = 0
        Dim RendimientoSumaProducto As Double = 0
        Dim SumaProducto As Double = 0
        For Each rows As DataRow In dt.Rows
            MontoInversion += Operaciones.ConvertirDecimal(rows("Monto").ToString)
            Rendimiento += Operaciones.ConvertirDecimal(rows("Rendimientos").ToString)
            RendimientoSumaProducto = Operaciones.ConvertirDecimal(rows("Rendimientos").ToString)
            Peso = Operaciones.ConvertirDecimal(rows("Peso").ToString)
            SumaProducto += RendimientoSumaProducto * Peso
        Next
        txtPortTotal.Text = MontoInversion
        txtRendimientos.Text = (Rendimiento * 100).ToString + " %"
        txtRendSumaProducto.Text = (SumaProducto * 100).ToString + " %"

    End Sub

















    Private Sub frmRendimientoTotal_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        TipoRendimiento()

        AgregarCheckboxEmpresa()
        AgregarCheckboxInstrumento()

        CargarDatos()

    End Sub



    Sub AgregarCheckboxEmpresa()
        Dim diccionario As New Dictionary(Of String, String)
        diccionario = Rendimiento.Empresas
        For Each Empresa In diccionario
            Dim Empre As New CheckBox
            Dim Existe As Boolean = False
            Dim NombreEmpresa = Empresa.Value
            For Each item As CheckBox In flpEmpresa.Controls
                If item.Text.ToString = NombreEmpresa.ToString Then
                    Existe = True
                End If
            Next
            If Not Existe Then
                Empre.Name = Empresa.Key
                Empre.Checked = True
                Empre.Width = 250
                Empre.BackColor = ColorTranslator.FromHtml("#EAEAE8")
                Empre.Text = NombreEmpresa
                flpEmpresa.Controls.Add(Empre)
                AddHandler Empre.Click, AddressOf eventoEmpresa
                AddHandler Empre.CheckedChanged, AddressOf ColoreventoEmpresa
            End If
            Existe = False
        Next
        Dim Empres As New CheckBox
        Empres.Name = "TodosEmpresa"
        Empres.Checked = True
        Empres.Width = 250
        Empres.BackColor = ColorTranslator.FromHtml("#EAEAE8")
        Empres.Text = "Todos las Empresas"
        flpEmpresa.Controls.Add(Empres)
        AddHandler Empres.Click, AddressOf eventoEmpresa
        AddHandler Empres.CheckedChanged, AddressOf ColoreventoEmpresa
    End Sub






    Sub AgregarCheckboxInstrumento()
        Dim diccionario As New Dictionary(Of String, String)
        diccionario = Rendimiento.Instrumentos
        For Each Instrumento In diccionario
            Dim Ins As New CheckBox
            Dim Existe As Boolean = False
            Dim NombreInstrumento = Instrumento.Value
            For Each item As CheckBox In flpInstrumento.Controls
                If item.Text.ToString = NombreInstrumento.ToString Then
                    Existe = True
                End If
            Next
            If Not Existe Then
                Ins.Name = Instrumento.Key
                Ins.Checked = True
                Ins.Width = 250
                Ins.BackColor = ColorTranslator.FromHtml("#EAEAE8")
                Ins.Text = NombreInstrumento
                flpInstrumento.Controls.Add(Ins)
                AddHandler Ins.Click, AddressOf eventoInstrumento
                AddHandler Ins.CheckedChanged, AddressOf ColoreventoInstrumento
            End If
            Existe = False
        Next
        Dim Insi As New CheckBox
        Insi.Name = "TodosInstrumentos"
        Insi.Checked = True
        Insi.Width = 250
        Insi.BackColor = ColorTranslator.FromHtml("#EAEAE8")
        Insi.Text = "Todos los Instrumentos"
        flpInstrumento.Controls.Add(Insi)
        AddHandler Insi.Click, AddressOf eventoInstrumento
        AddHandler Insi.CheckedChanged, AddressOf ColoreventoInstrumento
    End Sub

    Sub eventoEmpresa(sender As Object, e As EventArgs)


        If sender.name = "TodosEmpresa" Then
            CambioCheckTodosEmpresa()

        Else
            TodosCheckEmpresa(sender, e)

        End If

    End Sub

    Sub eventoInstrumento(sender As Object, e As EventArgs)


        If sender.name = "TodosInstrumentos" Then
            CambioCheckTodosinstrumentos()

        Else
            TodosCheckInstrumentos(sender, e)

        End If

    End Sub

    Sub ColoreventoEmpresa(sender As Object, e As EventArgs)
        If (sender.checked) Then
            sender.BackColor = ColorTranslator.FromHtml("#EAEAE8")
        Else
            sender.BackColor = ColorTranslator.FromHtml("Transparent")
        End If

    End Sub
    Sub ColoreventoInstrumento(sender As Object, e As EventArgs)
        If (sender.checked) Then
            sender.BackColor = ColorTranslator.FromHtml("#EAEAE8")
        Else
            sender.BackColor = ColorTranslator.FromHtml("Transparent")
        End If
    End Sub

    Sub CambioCheckTodosEmpresa()
        Dim ContadorPrimario As Integer = Me.flpEmpresa.Controls.Count - 1
        Dim UltimoCheck As Boolean = True
        For Each xCheckBox In Me.flpEmpresa.Controls
            If TypeOf xCheckBox Is CheckBox Then
                Dim yCheckBox As New CheckBox
                yCheckBox = xCheckBox

                If xCheckBox.TabIndex = ContadorPrimario Then

                    If Not yCheckBox.Checked Then
                        UltimoCheck = False
                    End If
                End If
            End If
        Next
        If UltimoCheck Then
            For Each xCheckBox In Me.flpEmpresa.Controls
                If TypeOf xCheckBox Is CheckBox Then
                    Dim yCheckBox As New CheckBox
                    yCheckBox = xCheckBox
                    yCheckBox.Checked = True
                End If
            Next
        ElseIf Not UltimoCheck Then
            For Each xCheckBox In Me.flpEmpresa.Controls
                If TypeOf xCheckBox Is CheckBox Then
                    Dim yCheckBox As New CheckBox
                    yCheckBox = xCheckBox
                    yCheckBox.Checked = False
                End If
            Next
        End If
    End Sub

    Sub TodosCheckEmpresa(sender As Object, e As EventArgs)


        Dim ContadorPrimario As Integer = Me.flpEmpresa.Controls.Count - 1
        Dim TodosCheck As Boolean = True
        If Not sender.name = "TodosEmpresa" Then
            For Each xCheckBox In Me.flpEmpresa.Controls
                If TypeOf xCheckBox Is CheckBox Then
                    Dim yCheckBox As New CheckBox
                    yCheckBox = xCheckBox

                    If Not yCheckBox.TabIndex = ContadorPrimario Then
                        If Not yCheckBox.Checked Then
                            TodosCheck = False
                        End If
                    End If

                    If yCheckBox.TabIndex = ContadorPrimario Then


                        If Not TodosCheck Then

                            yCheckBox.Checked = False

                        Else

                            yCheckBox.Checked = True

                        End If
                    End If
                End If


            Next
        End If

    End Sub

    ''''''''Instrumentos ''''''''''
    Sub CambioCheckTodosinstrumentos()
        Dim ContadorPrimario As Integer = Me.flpInstrumento.Controls.Count - 1
        Dim UltimoCheck As Boolean = True
        For Each xCheckBox In Me.flpInstrumento.Controls
            If TypeOf xCheckBox Is CheckBox Then
                Dim yCheckBox As New CheckBox
                yCheckBox = xCheckBox

                If xCheckBox.TabIndex = ContadorPrimario Then

                    If Not yCheckBox.Checked Then
                        UltimoCheck = False
                    End If
                End If
            End If
        Next
        If UltimoCheck Then
            For Each xCheckBox In Me.flpInstrumento.Controls
                If TypeOf xCheckBox Is CheckBox Then
                    Dim yCheckBox As New CheckBox
                    yCheckBox = xCheckBox
                    yCheckBox.Checked = True
                End If
            Next
        ElseIf Not UltimoCheck Then
            For Each xCheckBox In Me.flpInstrumento.Controls
                If TypeOf xCheckBox Is CheckBox Then
                    Dim yCheckBox As New CheckBox
                    yCheckBox = xCheckBox
                    yCheckBox.Checked = False
                End If
            Next
        End If
    End Sub

    Sub TodosCheckInstrumentos(sender As Object, e As EventArgs)


        Dim ContadorPrimario As Integer = Me.flpInstrumento.Controls.Count - 1
        Dim TodosCheck As Boolean = True
        If Not sender.name = "TodosInstrumentos" Then
            For Each xCheckBox In Me.flpInstrumento.Controls
                If TypeOf xCheckBox Is CheckBox Then
                    Dim yCheckBox As New CheckBox
                    yCheckBox = xCheckBox

                    If Not yCheckBox.TabIndex = ContadorPrimario Then
                        If Not yCheckBox.Checked Then
                            TodosCheck = False
                        End If
                    End If

                    If yCheckBox.TabIndex = ContadorPrimario Then


                        If Not TodosCheck Then

                            yCheckBox.Checked = False

                        Else

                            yCheckBox.Checked = True

                        End If
                    End If
                End If


            Next
        End If

    End Sub











    Private Sub RadioButton3_CheckedChanged(sender As Object, e As EventArgs) Handles rdbAmbosRenta.CheckedChanged

    End Sub

    Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs)

    End Sub











    Private Sub rdbFecha_CheckedChanged(sender As Object, e As EventArgs) Handles rdbFecha.CheckedChanged
        If rdbFecha.Checked Then
            SoloFecha = dtpFecha.Value
            TipoFecha = "F"
        Else
            TipoFecha = "N"

        End If
    End Sub

    Private Sub rdbRangoFechas_CheckedChanged(sender As Object, e As EventArgs) Handles rdbRangoFechas.CheckedChanged
        If rdbRangoFechas.Checked Then
            TipoFecha = "FR"
            FechaInicial = dtpFechaInicial.Value
            FechaFinal = dtpFechaFinal.Value
        Else
            TipoFecha = "N"
        End If
    End Sub

    Private Sub rdbDeshabilitarFecha_CheckedChanged(sender As Object, e As EventArgs) Handles rdbDeshabilitarFecha.CheckedChanged
        If rdbDeshabilitarFecha.Checked Then
            TipoFecha = "N"
        End If
    End Sub

    Private Sub flpInstrumento_Paint(sender As Object, e As PaintEventArgs) Handles flpInstrumento.Paint

    End Sub

    Private Sub chkPortafolio_CheckedChanged(sender As Object, e As EventArgs) Handles chkPortafolio.CheckedChanged
        If chkPortafolio.Checked Then
            Portafolio = "Activo"
        Else
            Portafolio = "Desactivo"
        End If
    End Sub

    Private Sub chkPortafolioSinLiquidez_CheckedChanged(sender As Object, e As EventArgs) Handles chkPortafolioSinLiquidez.CheckedChanged

    End Sub

    Private Sub rdbVariable_CheckedChanged(sender As Object, e As EventArgs) Handles rdbVariable.CheckedChanged

    End Sub

    Private Sub rdbFija_CheckedChanged(sender As Object, e As EventArgs) Handles rdbFija.CheckedChanged

    End Sub

    Private Sub chkInternacional_CheckedChanged(sender As Object, e As EventArgs)

    End Sub

    Private Sub chkVigentes_CheckedChanged(sender As Object, e As EventArgs)

    End Sub

    Private Sub rdbPendientes_CheckedChanged(sender As Object, e As EventArgs) Handles rdbPendientes.CheckedChanged

    End Sub

    Private Sub rdbAprobado_CheckedChanged(sender As Object, e As EventArgs) Handles rdbAprobado.CheckedChanged

    End Sub

    Private Sub rdbRechazado_CheckedChanged(sender As Object, e As EventArgs) Handles rdbRechazado.CheckedChanged

    End Sub

    Private Sub rdbPAR_CheckedChanged(sender As Object, e As EventArgs) Handles rdbTodosEstado.CheckedChanged

    End Sub

    Private Sub rdbEmpresas_CheckedChanged(sender As Object, e As EventArgs)

    End Sub

    Private Sub rdbInstrumento_CheckedChanged(sender As Object, e As EventArgs)

    End Sub

    Private Sub rdbTiempo_CheckedChanged(sender As Object, e As EventArgs)

    End Sub

    Private Sub rdbTEI_CheckedChanged(sender As Object, e As EventArgs)

    End Sub

    Private Sub dgvRendimientos_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvRendimientos.CellContentClick

    End Sub

    Private Sub TbRendimientos_Click(sender As Object, e As EventArgs) Handles TbRendimientoGeneral.Click

    End Sub

    Private Sub TbcRendimiento_TabIndexChanged(sender As Object, e As EventArgs) Handles TbcRendimiento.TabIndexChanged

    End Sub

    Private Sub TbcRendimiento_SelectedIndexChanged(sender As Object, e As EventArgs) Handles TbcRendimiento.SelectedIndexChanged
        If rdbRendimientoGeneral.Checked Then

            If TbcRendimiento.SelectedIndex = 1 Then
                BloqueoPortafolio()
                CargarDatos()

            End If
        Else
            If TbcRendimiento.SelectedIndex = 1 Then
                BloqueoPortafolio()
                RendimientoMensual()

            End If

        End If
    End Sub




    Private Sub BloqueoPortafolio()
        If Portafolio = "Desactivo" Then
            lblPortTotal.Visible = False
            txtPortTotal.Visible = False
        Else
            lblPortTotal.Visible = True
            txtPortTotal.Visible = True


        End If




    End Sub

    Sub RendimientoMensual()
        Dim dt As New DataTable
        Dim TipoRendimiento As String = "Mensual"
        Dim Fecha1 As Date = dtpFechaInicialDiario.Value
        Dim Fecha2 As Date = dtpFechaFinalDiario.Value
        Dim Agrupado As String = String.Empty
        ActualizarListas()
        If String.IsNullOrEmpty(ListaAgrupada) Then
            Agrupado = "NO"
        Else
            Agrupado = "SI"
        End If

        dt = Rendimiento.CargarRendimientoDiario(Fecha1, Fecha2, TipoRendimiento, ListaEmpresa, ListaInstrumentos, ListaNacionalidad, ListaEstado,
        ListaVigencia, ListaTipoRenta, ListaAgrupada, Agrupado)
        AgregarPorcentajeRend(dt)
        dgvRendimientoMensual.DataSource = dt
    End Sub
    Sub AgregarPorcentajeRend(ByRef dt As DataTable)
        For Each rows As DataRow In dt.Rows
            rows("RendimientoTotal") = (Operaciones.ConvertirDecimal(rows("RendimientoTotal").ToString) * 100).ToString + " %"
        Next
    End Sub


    Sub AgregarPorcentajeRendDetalles(ByRef dt As DataTable)
        For Each rows As DataRow In dt.Rows

            If Not dt.Columns("Rendimiento") Is Nothing Then
                rows("Rendimiento") = (Operaciones.ConvertirDecimal(rows("Rendimiento").ToString) * 100).ToString + " %"
            End If
            If Not dt.Columns("RendimientoTotal") Is Nothing Then
                rows("RendimientoTotal") = (Operaciones.ConvertirDecimal(rows("RendimientoTotal").ToString) * 100).ToString + " %"
            End If
            If Not dt.Columns("Peso") Is Nothing Then
                rows("Peso") = (Operaciones.ConvertirDecimal(rows("Peso").ToString) * 100).ToString + " %"
            End If
            If Not dt.Columns("RendimientoPeso") Is Nothing Then
                rows("RendimientoPeso") = (Operaciones.ConvertirDecimal(rows("RendimientoPeso").ToString) * 100).ToString + " %"
            End If

            If Not dt.Columns("RendimientoGrupo") Is Nothing Then
                rows("RendimientoGrupo") = (Operaciones.ConvertirDecimal(rows("RendimientoGrupo").ToString) * 100).ToString + " %"
            End If

        Next
    End Sub


    Sub RendimientoDetalles()
        Dim dt As New DataTable
        Dim TipoRendimiento As String = "Detalles"
        ActualizarListas()






        Dim Fecha1 As Date = Date.Now.Date
        Dim Fecha2 As Date = Date.Now.Date
        Dim FechaAux As Date = Date.Now.Date
        Dim Agrupado As String = String.Empty
        Dim FechaInicial As Date = dtpFechaInicialDiario.Value
        Dim FechaFinal As Date = dtpFechaFinalDiario.Value


        If String.IsNullOrEmpty(ListaAgrupada) Then
            Agrupado = "NO"
        Else
            Agrupado = "SI"
        End If



        If rdbRendMensual.Checked Then



            If Not dgvRendimientoMensual.CurrentRow Is Nothing Then

                If String.IsNullOrEmpty(ListaAgrupada) Then
                    Agrupado = "NO"
                Else
                    Agrupado = "SI"
                End If
                If Not dgvRendimientoMensual.CurrentRow Is Nothing Then
                    FechaAux = dgvRendimientoMensual.CurrentRow.Cells("FechaUltima").Value
                    If FechaInicial.Month = FechaAux.Month And FechaInicial.Year = FechaAux.Year Then
                        Fecha1 = FechaInicial
                    Else
                        Fecha1 = CDate("1/" + FechaAux.Month.ToString + "/" + FechaAux.Year.ToString)

                    End If

                    If FechaFinal.Month = FechaAux.Month And FechaFinal.Year = FechaAux.Year Then
                        Fecha2 = FechaFinal
                    Else
                        Fecha2 = FechaAux
                    End If
                End If
                dt = Rendimiento.CargarRendimientoDiario(Fecha1, Fecha2, TipoRendimiento, ListaEmpresa, ListaInstrumentos, ListaNacionalidad, ListaEstado,
        ListaVigencia, ListaTipoRenta, ListaAgrupada, Agrupado)
                AgregarPorcentajeRendDetalles(dt)
                dgvRendimientoDetalles.DataSource = dt
            Else
                MsgBox("Error al Cargar Registros")
            End If
        Else


            If Not dgvRendimientoDiario.CurrentRow Is Nothing Then
                FechaAux = dgvRendimientoDiario.CurrentRow.Cells("FechaIterada").Value
                Fecha1 = FechaAux
                Fecha2 = FechaAux
                dt = Rendimiento.CargarRendimientoDiario(Fecha1, Fecha2, TipoRendimiento, ListaEmpresa, ListaInstrumentos, ListaNacionalidad, ListaEstado,
        ListaVigencia, ListaTipoRenta, ListaAgrupada, Agrupado)
                AgregarPorcentajeRendDetalles(dt)
                dgvRendimientoDetalles.DataSource = dt
            Else
                MsgBox("Error al Cargar Registros")
            End If
        End If



    End Sub



    Sub RendimientoDiario()
        Dim dt As New DataTable
        Dim TipoRendimiento As String = "Diario"
        Dim Fecha1 As Date = Date.Now.Date
        Dim Fecha2 As Date = Date.Now.Date
        Dim FechaAux As Date = Date.Now.Date
        Dim Agrupado As String = String.Empty
        Dim FechaInicial As Date = dtpFechaInicialDiario.Value
        Dim FechaFinal As Date = dtpFechaFinalDiario.Value

        If String.IsNullOrEmpty(ListaAgrupada) Then
            Agrupado = "NO"
        Else
            Agrupado = "SI"
        End If
        If Not dgvRendimientoMensual.CurrentRow Is Nothing Then
            FechaAux = dgvRendimientoMensual.CurrentRow.Cells("FechaUltima").Value
            If FechaInicial.Month = FechaAux.Month And FechaInicial.Year = FechaAux.Year Then
                Fecha1 = FechaInicial
            Else
                Fecha1 = CDate("1/" + FechaAux.Month.ToString + "/" + FechaAux.Year.ToString)

            End If

            If FechaFinal.Month = FechaAux.Month And FechaFinal.Year = FechaAux.Year Then
                Fecha2 = FechaFinal
            Else
                Fecha2 = FechaAux
            End If




            dt = Rendimiento.CargarRendimientoDiario(Fecha1, Fecha2, TipoRendimiento, ListaEmpresa, ListaInstrumentos, ListaNacionalidad, ListaEstado,
        ListaVigencia, ListaTipoRenta, ListaAgrupada, Agrupado)
            AgregarPorcentajeRend(dt)
            dgvRendimientoDiario.DataSource = dt
        Else
            MsgBox("Error al Cargar Registros")
        End If





    End Sub
    Private Sub dtpFechaInicial_ValueChanged(sender As Object, e As EventArgs) Handles dtpFechaInicial.ValueChanged
        FechaInicial = dtpFechaInicial.Value
        FechaFinal = dtpFechaFinal.Value
    End Sub

    Private Sub dtpFechaFinal_ValueChanged(sender As Object, e As EventArgs) Handles dtpFechaFinal.ValueChanged
        FechaInicial = dtpFechaInicial.Value
        FechaFinal = dtpFechaFinal.Value
    End Sub

    Private Sub dtpFecha_ValueChanged(sender As Object, e As EventArgs) Handles dtpFecha.ValueChanged
        SoloFecha = dtpFecha.Value
    End Sub

    Private Sub rdbInternacionales_CheckedChanged(sender As Object, e As EventArgs) Handles rdbInternacionales.CheckedChanged



    End Sub

    Private Sub rdbVigente_CheckedChanged(sender As Object, e As EventArgs) Handles rdbVigente.CheckedChanged

    End Sub

    Private Sub rdbVencido_CheckedChanged(sender As Object, e As EventArgs) Handles rdbVencido.CheckedChanged

    End Sub

    Private Sub rdbVencidoAmbos_CheckedChanged(sender As Object, e As EventArgs) Handles rdbVencidoAmbos.CheckedChanged

    End Sub

    Private Sub rdbAmbosPais_CheckedChanged(sender As Object, e As EventArgs) Handles rdbAmbosPais.CheckedChanged



    End Sub

    Private Sub rdbNacionales_CheckedChanged(sender As Object, e As EventArgs) Handles rdbNacionales.CheckedChanged

    End Sub

    Private Sub txtPortTotal_TextChanged(sender As Object, e As EventArgs) Handles txtPortTotal.TextChanged

    End Sub

    Private Sub txtRendimientos_TextChanged(sender As Object, e As EventArgs) Handles txtRendimientos.TextChanged

    End Sub

    Private Sub rdbRevision_CheckedChanged(sender As Object, e As EventArgs) Handles rdbRevision.CheckedChanged

    End Sub

    Private Sub rdbCancelada_CheckedChanged(sender As Object, e As EventArgs) Handles rdbCancelada.CheckedChanged

    End Sub


    Sub AgruparSeleccionado()
        Dim ListaAgrupada As String = String.Empty

        For Each check As CheckBox In grpAgrupamiento.Controls
            Dim Valor As String = String.Empty
            If check.Checked Then

                If check.Text = "Empresa" Then
                    Valor = "Empresa"

                ElseIf check.Text = "Instrumento" Then
                    Valor = "Instrumento"

                ElseIf check.Text = "Nacionalidad" Then
                    Valor = "Nacionalidad"

                ElseIf check.Text = "Estado" Then
                    Valor = "Estado"

                ElseIf check.Text = "Fecha" Then
                    Valor = "Fecha"


                ElseIf check.Text = "TipoRenta" Then
                    Valor = "TipoRenta"


                ElseIf check.Text = "Vigencia" Then
                    Valor = "Vigencia"


                End If


                If String.IsNullOrEmpty(ListaAgrupada) Then
                    ListaAgrupada = Valor
                Else
                    ListaAgrupada += "," + Valor
                End If
            End If
        Next
        Lista = ListaAgrupada

    End Sub

    Private Sub chkEmpresa_CheckedChanged(sender As Object, e As EventArgs) Handles chkEmpresa.CheckedChanged
        AgruparSeleccionado()
        CargarDatos()

    End Sub

    Private Sub chkInstrumento_CheckedChanged(sender As Object, e As EventArgs) Handles chkInstrumento.CheckedChanged
        AgruparSeleccionado()
        CargarDatos()

    End Sub

    Private Sub chkNacionalidad_CheckedChanged(sender As Object, e As EventArgs) Handles chkNacionalidad.CheckedChanged
        AgruparSeleccionado()
        CargarDatos()

    End Sub

    Private Sub chkEstado_CheckedChanged(sender As Object, e As EventArgs) Handles chkEstado.CheckedChanged
        AgruparSeleccionado()
        CargarDatos()

    End Sub

    Private Sub chkFecha_CheckedChanged(sender As Object, e As EventArgs) Handles chkFecha.CheckedChanged
        AgruparSeleccionado()
        CargarDatos()

    End Sub

    Private Sub chkVigencia_CheckedChanged(sender As Object, e As EventArgs) Handles chkVigencia.CheckedChanged
        AgruparSeleccionado()
        CargarDatos()

    End Sub

    Private Sub chkTipoRenta_CheckedChanged(sender As Object, e As EventArgs) Handles chkTipoRenta.CheckedChanged
        AgruparSeleccionado()
        CargarDatos()

    End Sub


    Sub TipoRendimiento()
        If rdbRendimientoGeneral.Checked Then
            grpFechas.Enabled = True
            grpVigente.Enabled = True
            grpMostrarTotales.Enabled = True
            TbRendimientoDiario.Parent = Nothing
            TbRendimientoGeneral.Parent = TbcRendimiento
        Else
            grpFechas.Enabled = False
            grpVigente.Enabled = False
            grpMostrarTotales.Enabled = False
            TbRendimientoGeneral.Parent = Nothing
            TbRendimientoDiario.Parent = TbcRendimiento

        End If
    End Sub

    Private Sub rdbRendimientoGeneral_CheckedChanged(sender As Object, e As EventArgs) Handles rdbRendimientoGeneral.CheckedChanged
        TipoRendimiento()
    End Sub

    Private Sub rdbRendimientoDiario_CheckedChanged(sender As Object, e As EventArgs) Handles rdbRendimientoDiario.CheckedChanged
        TipoRendimiento()
    End Sub





    Sub OcultarColumnasRendimientoGenerar()
        If Not dgvRendimientoDetalles.Columns("CodigoEmpresa") Is Nothing Then
            dgvRendimientoDetalles.Columns("CodigoEmpresa").Visible = False
        End If
        If Not dgvRendimientoDetalles.Columns("CodigoInstrumento") Is Nothing Then
            dgvRendimientoDetalles.Columns("CodigoInstrumento").Visible = False
        End If

        If Not dgvRendimientoDetalles.Columns("Pais") Is Nothing Then
            dgvRendimientoDetalles.Columns("Pais").Visible = False
        End If

    End Sub


    Sub ActualizarListas()

        EmpresaRendimientoDiario()
        InstrumentoRendimientoDiario()
        NacionalidadRendimientoDiario()
        EstadoRendimientoDiario()
        VigenciaRendimientoDiario()
        TipoRentaRendimientoDiario()
        AgruparRendimientoDiario()

    End Sub


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click



        RendimientoDetalles()
        OcultarColumnasRendimientoGenerar()
    End Sub

    Private Sub btnVer_Click(sender As Object, e As EventArgs) Handles btnVer.Click
        RendimientoDiario()
    End Sub







    Sub EmpresaRendimientoDiario()
        Dim ListaAgrupada As String = String.Empty

        For Each check As CheckBox In flpEmpresa.Controls
            Dim Valor As String = String.Empty
            If check.Checked Then
                If Not check.Name.ToString = "TodosEmpresa" Then
                    Valor = check.Name.ToString


                    If String.IsNullOrEmpty(ListaAgrupada) Then
                        ListaAgrupada = Valor
                    Else
                        ListaAgrupada += "," + Valor
                    End If
                End If
            End If
        Next
        ListaEmpresa = ListaAgrupada

    End Sub



    Sub InstrumentoRendimientoDiario()
        Dim ListaAgrupada As String = String.Empty

        For Each check As CheckBox In flpInstrumento.Controls
            Dim Valor As String = String.Empty
            If check.Checked Then
                If Not check.Name.ToString = "TodosInstrumentos" Then
                    Valor = check.Name.ToString


                    If String.IsNullOrEmpty(ListaAgrupada) Then
                        ListaAgrupada = Valor
                    Else
                        ListaAgrupada += "," + Valor
                    End If
                End If
            End If
        Next
        ListaInstrumentos = ListaAgrupada

    End Sub


    Sub NacionalidadRendimientoDiario()
        If rdbNacionales.Checked Then
            ListaNacionalidad = "Nacional"
        ElseIf rdbInternacionales.Checked Then
            ListaNacionalidad = "Internacional"

        ElseIf rdbAmbosPais.Checked Then
            ListaNacionalidad = "Todos"


        End If

    End Sub


    Sub EstadoRendimientoDiario()
        If rdbVigente.Checked Then
            ListaEstado = "A"
        ElseIf rdbVencido.Checked Then
            ListaEstado = "C"

        ElseIf rdbVencidoAmbos.Checked Then
            ListaEstado = "A,C"


        End If

    End Sub



    Sub VigenciaRendimientoDiario()
        If rdbPendientes.Checked Then
            ListaVigencia = "P"
        ElseIf rdbRevision.Checked Then
            ListaVigencia = "V"

        ElseIf rdbAprobado.Checked Then
            ListaVigencia = "A"




        ElseIf rdbCancelada.Checked Then
            ListaVigencia = "C"

        ElseIf rdbRechazado.Checked Then
            ListaVigencia = "R"



        ElseIf rdbTodosEstado.Checked Then
            ListaVigencia = "P,C,V,A,R"

        End If


    End Sub



    Sub TipoRentaRendimientoDiario()
        If rdbVariable.Checked Then
            ListaTipoRenta = "V"
        ElseIf rdbFija.Checked Then
            ListaTipoRenta = "F"
        ElseIf rdbAmbosRenta.Checked Then
            ListaTipoRenta = "V,F"



        End If

    End Sub



    Sub AgruparRendimientoDiario()
        Dim ListaAgrupada As String = String.Empty

        For Each check As CheckBox In grpAgruparRendDiario.Controls
            Dim Valor As String = String.Empty
            If check.Checked Then

                If check.Text = "Empresa" Then
                    Valor = "Empresa"

                ElseIf check.Text = "Instrumento" Then
                    Valor = "Instrumento"

                ElseIf check.Text = "Nacionalidad" Then
                    Valor = "Nacionalidad"

                ElseIf check.Text = "Estado" Then
                    Valor = "Estado"

                ElseIf check.Text = "Fecha" Then
                    Valor = "Fecha"


                ElseIf check.Text = "TipoRenta" Then
                    Valor = "TipoRenta"


                ElseIf check.Text = "Vigencia" Then
                    Valor = "Vigencia"


                End If


                If String.IsNullOrEmpty(ListaAgrupada) Then
                    ListaAgrupada = Valor
                Else
                    ListaAgrupada += "," + Valor
                End If
            End If
        Next
        Me.ListaAgrupada = ListaAgrupada

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles btnActualizar.Click
        ActualizarLimpiar()
    End Sub

    Private Sub TbRendimientoDiario_Click(sender As Object, e As EventArgs) Handles TbRendimientoDiario.Click

    End Sub
    Sub ActualizarLimpiar()
        dgvRendimientoDetalles.Columns.Clear()
        dgvRendimientoDiario.Columns.Clear()
        RendimientoMensual()
    End Sub



    Sub OcultarColumnas()

        If Not dgvRendimientos.Columns("CodigoEmpresa") Is Nothing Then
            dgvRendimientos.Columns("CodigoEmpresa").Visible = False
        End If


        If Not dgvRendimientos.Columns("CodigoInstrumento") Is Nothing Then
            dgvRendimientos.Columns("CodigoInstrumento").Visible = False
        End If


        If Not dgvRendimientos.Columns("CodigoPais") Is Nothing Then
            dgvRendimientos.Columns("CodigoPais").Visible = False
        End If

    End Sub

End Class