Imports System.Windows.Forms

Public Class frmPrincipal
    Private _MenuMini As Boolean = False

    Private Sub ShowNewForm(ByVal sender As Object, ByVal e As EventArgs) Handles NewToolStripButton.Click
        ' Cree una nueva instancia del formulario secundario.
        Dim ChildForm As New System.Windows.Forms.Form
        ' Conviértalo en un elemento secundario de este formulario MDI antes de mostrarlo.




        m_ChildFormNumber += 1
        ChildForm.Text = "Ventana " & m_ChildFormNumber

        ChildForm.Show()
    End Sub

    Private Sub OpenFile(ByVal sender As Object, ByVal e As EventArgs) Handles OpenToolStripButton.Click
        Dim OpenFileDialog As New OpenFileDialog
        OpenFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
        OpenFileDialog.Filter = "Archivos de texto (*.txt)|*.txt|Todos los archivos (*.*)|*.*"
        If (OpenFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
            Dim FileName As String = OpenFileDialog.FileName
            ' TODO: agregue código aquí para abrir el archivo.
        End If
    End Sub

    Private Sub SaveAsToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim SaveFileDialog As New SaveFileDialog
        SaveFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
        SaveFileDialog.Filter = "Archivos de texto (*.txt)|*.txt|Todos los archivos (*.*)|*.*"

        If (SaveFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
            Dim FileName As String = SaveFileDialog.FileName
            ' TODO: agregue código aquí para guardar el contenido actual del formulario en un archivo.
        End If
    End Sub


    Private Sub ExitToolsStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
        Me.Close()
    End Sub

    Private Sub CutToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
        ' Utilice My.Computer.Clipboard para insertar el texto o las imágenes seleccionadas en el Portapapeles
    End Sub

    Private Sub CopyToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
        ' Utilice My.Computer.Clipboard para insertar el texto o las imágenes seleccionadas en el Portapapeles
    End Sub

    Private Sub PasteToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
        'Utilice My.Computer.Clipboard.GetText() o My.Computer.Clipboard.GetData para recuperar la información del Portapapeles.
    End Sub

    Private Sub ToolBarToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
        'Me.ToolStrip.Visible = Me.ToolBarToolStripMenuItem.Checked
    End Sub

    Private Sub StatusBarToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
        'Me.StatusStrip.Visible = Me.StatusBarToolStripMenuItem.Checked
    End Sub

    Private Sub CascadeToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
        Me.LayoutMdi(MdiLayout.Cascade)
    End Sub

    Private Sub TileVerticalToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
        Me.LayoutMdi(MdiLayout.TileVertical)
    End Sub

    Private Sub TileHorizontalToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
        Me.LayoutMdi(MdiLayout.TileHorizontal)
    End Sub

    Private Sub ArrangeIconsToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
        Me.LayoutMdi(MdiLayout.ArrangeIcons)
    End Sub

    Private Sub CloseAllToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
        ' Cierre todos los formularios secundarios del principal.
        For Each ChildForm As Form In Me.MdiChildren
            ChildForm.Close()
        Next
    End Sub

    Private m_ChildFormNumber As Integer

    Private Sub btnPropuestaDeInversion_Click(sender As Object, e As EventArgs)
        frmPIN_Temporal.MdiParent = Me
        frmPIN_Temporal.WindowState = FormWindowState.Normal
        'frmPIN.Dock = DockStyle.Fill
        frmPIN_Temporal.Show()
        frmPIN_Temporal.Focus()
    End Sub

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

        Me.ToolStrip.Visible = False
        Listas()
        Me.mnuPrincipal.Renderer = New MenuPrincipalRender()
        ''inicio()

    End Sub

    Private Sub btnInicio_Click(sender As Object, e As EventArgs)
        inicio()
    End Sub
    Private Sub inicio()




        frmPortafolio.WindowState = FormWindowState.Normal
        'frmPortafolio.FormBorderStyle = FormBorderStyle.None
        frmPortafolio.Dock = DockStyle.Fill
        frmPortafolio.Show()
        Me.Focus()
    End Sub

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

        frmINV.WindowState = FormWindowState.Normal
        frmINV.ShowDialog()
        Me.Focus()
    End Sub

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

        frmDISP.WindowState = FormWindowState.Normal
        frmDISP.Show()
        Me.Focus()
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs)
        frmINV.ShowDialog()

    End Sub

    Private Sub mnuInicio_Click(sender As Object, e As EventArgs) Handles mnuInicio.Click
        inicio()
    End Sub

    Private Sub mnuPropuestas_Click(sender As Object, e As EventArgs) Handles mnuPropuestas.Click





        frmProgreso.Show()

        frmPIN.WindowState = FormWindowState.Normal
        frmPIN.ShowDialog()
        Me.Focus()

    End Sub

    Private Sub mnuInversiones_Click(sender As Object, e As EventArgs) Handles mnuInversiones.Click
        frmProgreso.Show()

        frmINV.WindowState = FormWindowState.Normal
        frmINV.ShowDialog()
        Me.Focus()
    End Sub

    Private Sub mnuDisponibilidades_Click(sender As Object, e As EventArgs) Handles mnuDisponibilidades.Click


        frmDISP.WindowState = FormWindowState.Normal
        frmDISP.Show()
        Me.Focus()
    End Sub

    Private Sub mnuPrincipal_ItemClicked(sender As Object, e As ToolStripItemClickedEventArgs)

    End Sub

    Private Sub mnuPrincipal_ItemClicked_1(sender As Object, e As ToolStripItemClickedEventArgs) Handles mnuPrincipal.ItemClicked

    End Sub

    Private Sub mnuCalificadoras_Click(sender As Object, e As EventArgs) Handles mnuCalificadoras.Click



        frmCalificadoras.WindowState = FormWindowState.Normal
        frmCalificadoras.Show()

    End Sub

    Private Sub mnuEmisores_Click(sender As Object, e As EventArgs) Handles mnuEmisores.Click



        frmEmisores.WindowState = FormWindowState.Normal
        frmEmisores.Show()

    End Sub

    Private Sub mnuEmpresas_Click(sender As Object, e As EventArgs) Handles mnuEmpresas.Click

        frmEmpresas.WindowState = FormWindowState.Normal
        frmEmpresas.Show()

    End Sub

    Private Sub mnuInstrumentos_Click(sender As Object, e As EventArgs) Handles mnuInstrumentos.Click


        frmInstrumentos.WindowState = FormWindowState.Normal
        frmInstrumentos.Show()

    End Sub

    Private Sub mnuIngresosDashboards_Click(sender As Object, e As EventArgs) Handles mnuIngresosDashboards.Click

        frmIngresosDashBoards.WindowState = FormWindowState.Maximized
        frmIngresosDashBoards.Show()

    End Sub

    Private Sub mnuIngresosConsulta_Click(sender As Object, e As EventArgs) Handles mnuIngresosConsulta.Click



        frmIngresosConsulta.WindowState = FormWindowState.Normal
        frmIngresosConsulta.Show()

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If _MenuMini Then
            MenuNormal()
        Else
            MenuMini()
        End If
    End Sub
    Private Sub MenuMini()
        Me.PanelMenu.Width = 60
        Me.picLogo.Width = 60
        Me.mnuPrincipal.Width = 60
        Me.lblInversionesTXT.Visible = False

        Dim mnuItems As ToolStripMenuItem
        For Each mnuItems In mnuPrincipal.Items
            mnuItems.Width = 40
            mnuItems.DisplayStyle = ToolStripItemDisplayStyle.Image
        Next
        _MenuMini = True
    End Sub
    Private Sub MenuNormal()
        Me.PanelMenu.Width = 254
        Me.picLogo.Width = 250
        Me.mnuPrincipal.Width = 250
        Me.lblInversionesTXT.Visible = True

        Dim mnuItems As ToolStripMenuItem
        For Each mnuItems In mnuPrincipal.Items
            mnuItems.Width = 250
            mnuItems.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText
        Next
        _MenuMini = False
    End Sub

    Private Sub BancosToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles mnuBancos.Click



        frmBancos.WindowState = FormWindowState.Normal
        frmBancos.Focus()
        Me.Focus()
    End Sub

    Private Sub CuentasBancariasToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles mnuCuentasBancarias.Click

        frmCuentasBancarias.WindowState = FormWindowState.Normal
        frmCuentasBancarias.Focus()
        Me.Focus()
    End Sub

    Private Sub mnuPaises_Click(sender As Object, e As EventArgs) Handles mnuPaises.Click

        frmPaises.WindowState = FormWindowState.Normal
        frmPaises.Focus()
        Me.Focus()

    End Sub

    Private Sub mnuFormasDePago_Click(sender As Object, e As EventArgs) Handles mnuFormasDePago.Click

        frmFormasDePago.WindowState = FormWindowState.Normal
        frmFormasDePago.Focus()
        Me.Focus()
    End Sub

    Private Sub mnuUsuarios_Click(sender As Object, e As EventArgs) Handles mnuUsuarios.Click

        frmUSR0.WindowState = FormWindowState.Normal
        frmUSR0.Focus()
        Me.Focus()
    End Sub

    Private Sub mnuDepartamentos_Click(sender As Object, e As EventArgs) Handles mnuDepartamentos.Click


        frmDEP0.WindowState = FormWindowState.Normal
        frmDEP0.Focus()
        Me.Focus()
    End Sub

    Private Sub mnuTipoCuentaBancaria_Click(sender As Object, e As EventArgs) Handles mnuTipoCuentaBancaria.Click


        frmTipoCuentaBancaria.WindowState = FormWindowState.Normal
        frmTipoCuentaBancaria.Focus()
        Me.Focus()
    End Sub

    Private Sub mnuRendimientos_Click(sender As Object, e As EventArgs) Handles mnuRendimientos.Click
        Dim MenuRendimientos As New frmMenuRendimientos
        MenuRendimientos.Show()
    End Sub


    Sub Listas()
        Fuente()
        DefinirTam()
        ListaEmpresas()
        ListaInstrumentos()
        ListaPaises()
        GraficaInstrumentos()
        GraficaMontoInstrumentos()
        GraficaRendimientoInstrumentos()
        RendimientoMonto()
    End Sub

    Sub Fuente()
        lblTitulo.ForeColor = Drawing.Color.FromArgb(15, 151, 208)
        lblRendimiento.ForeColor = Drawing.Color.FromArgb(15, 151, 208)
        lblIngreso.ForeColor = Drawing.Color.FromArgb(15, 151, 208)
        lblPortafolio.ForeColor = Drawing.Color.FromArgb(15, 151, 208)



        lblMontoIngresos.ForeColor = Drawing.Color.FromArgb(237, 51, 50)
        lblIngresostexto.ForeColor = Drawing.Color.FromArgb(15, 151, 208)
        lblMontoRendimiento.ForeColor = Drawing.Color.FromArgb(237, 51, 50)
        lblRendimientotexto.ForeColor = Drawing.Color.FromArgb(15, 151, 208)
    End Sub

    Sub ListaEmpresas()
        Dim General As New DAOGeneral
        Dim Empresas As DataTable = General.ListaEmpresas
        For Each row As DataRow In Empresas.Rows
            Dim Boton As New Button
            Boton.Text = CStr(row("Descripcion"))
            Boton.Name = CStr(row("Codigo"))
            Boton.Width = flpEmpresas.Width - 20
            'Boton.FlatStyle = FlatStyle.Flat
            Boton.ForeColor = Drawing.Color.FromArgb(40, 47, 59)
            Boton.BackColor = Drawing.Color.FromArgb(15, 151, 208)
            Boton.Height = 30
            Boton.TextAlign = ContentAlignment.MiddleLeft
            Boton.Font = New Font(Boton.Font.Name, 10)
            Boton.Margin = New Padding(0)
            flpEmpresas.Controls.Add(Boton)
        Next






    End Sub

    Sub ListaInstrumentos()
        Dim General As New DAOGeneral
        Dim Instrumentos As DataTable = General.ListaInstrumentos
        For Each row As DataRow In Instrumentos.Rows
            Dim Boton As New Button
            Boton.Text = CStr(row("Descripcion"))
            Boton.Name = CStr(row("Codigo"))
            Boton.Width = flpEmpresas.Width - 20
            'Boton.FlatStyle = FlatStyle.Flat
            Boton.ForeColor = Drawing.Color.FromArgb(40, 47, 59)
            Boton.BackColor = Drawing.Color.FromArgb(15, 151, 208)
            Boton.Height = 30
            Boton.TextAlign = ContentAlignment.MiddleLeft
            Boton.Font = New Font(Boton.Font.Name, 10)
            Boton.Margin = New Padding(0)
            flpInstrumentos.Controls.Add(Boton)
        Next
    End Sub


    Sub ListaPaises()
        Dim General As New DAOGeneral
        Dim Paises As DataTable = General.ListaPaisesRelevanteInversion
        For Each row As DataRow In Paises.Rows
            Dim Boton As New Button
            Boton.Text = CStr(row("Descripcion"))
            Boton.Name = CStr(row("Codigo"))
            Boton.Width = flpEmpresas.Width - 20
            'Boton.FlatStyle = FlatStyle.Flat
            Boton.ForeColor = Drawing.Color.FromArgb(40, 47, 59)
            Boton.BackColor = Drawing.Color.FromArgb(15, 151, 208)
            Boton.Height = 30
            Boton.TextAlign = ContentAlignment.MiddleLeft
            Boton.Font = New Font(Boton.Font.Name, 10)
            Boton.Margin = New Padding(0)
            flpPaises.Controls.Add(Boton)
        Next
    End Sub



    Sub DefinirTam()
        Dim TamEmpresa As Double = lblEmpresa.Width * 3


        pnlEmpresa.Width = TamEmpresa
        pnlInstrumento.Width = TamEmpresa
        pnlPais.Width = TamEmpresa


        pnlEmpresa.Height = 300
        pnlInstrumento.Height = 300
        pnlPais.Height = 300

        flpEmpresas.Width = TamEmpresa - 5
        flpInstrumentos.Width = TamEmpresa - 5
        flpPaises.Width = TamEmpresa - 5

        flpEmpresas.Height = 295
        flpInstrumentos.Height = 295
        flpPaises.Height = 295



    End Sub

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

    End Sub

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

    End Sub

    Sub GraficaInstrumentos()
        Dim general As New DAOGeneral
        Dim dt As DataTable = general.InstrumentosGrafica



        charPastel.Series(0).Points.Clear()
        charPastel.Series(0).IsValueShownAsLabel = False
        charPastel.Series(0).LabelForeColor = Color.Transparent
        'charPastel.Series(0).LabelAngle = -45

        'charPastel.Series(0).Font = New Font(charPastel.Series(0).Font.Name, 5)

        'charPastel.ChartAreas(0).Area3DStyle.Enable3D = True

        charPastel.Series(0).XValueMember = "Instrumento"
        charPastel.Series(0).YValueMembers = "Cantidad"

        charPastel.DataSource = dt
    End Sub

    Sub GraficaMontoInstrumentos()
        Dim general As New DAOGeneral

        Dim dt As DataTable = general.MontosInstrumentosGrafica
        charbarras.Series(0).Points.Clear()
        'charbarras.ChartAreas(0).Area3DStyle.Enable3D = True


        charbarras.Series(0).XValueMember = "Instrumento"
        charbarras.Series(0).YValueMembers = "Suma"
        charbarras.DataSource = dt
    End Sub


    Sub GraficaRendimientoInstrumentos()
        Dim general As New DAOGeneral

        Dim dt As DataTable = general.RendimientosInstrumentoGrafica
        charlineal.Series(0).Points.Clear()



        charlineal.Series(0).XValueMember = "Instrumento"
        charlineal.Series(0).YValueMembers = "Suma"
        charlineal.DataSource = dt
    End Sub




    Sub RendimientoMonto()
        Dim general As New DAOGeneral
        Dim Monto As String = "0.00"
        Dim Cantidad As Integer = 0
        Dim Rendimiento As String = "0.00 "
        Dim dt As DataTable = general.RendimientoMontoGraficas
        For Each rows As DataRow In dt.Rows
            If Not String.IsNullOrEmpty(rows("Rendimiento").ToString) Then
                Rendimiento = rows("Rendimiento").ToString
            End If

            If Not String.IsNullOrEmpty(rows("Monto").ToString) Then
                Monto = rows("Monto").ToString
            End If

            If Not String.IsNullOrEmpty(rows("Cantidad").ToString) Then
                Cantidad = rows("Cantidad")
            End If
        Next

        lblMontoIngresos.Text = "$ " + Monto
        If Cantidad = 0 Then
            lblMontoRendimiento.Text = "0 %"
        Else

            lblMontoRendimiento.Text = FormatNumber((((CDec(Rendimiento) / Cantidad)) * 100), 6).ToString + " %"
        End If
    End Sub

    Private Sub ToolStrip_ItemClicked(sender As Object, e As ToolStripItemClickedEventArgs) Handles ToolStrip.ItemClicked

    End Sub

    Sub EventEmpresa()
        If lblEmpresa.ForeColor.Name = Drawing.Color.FromArgb(237, 168, 59).Name Then
            lblEmpresa.ForeColor = Color.WhiteSmoke
            lblInstrumento.ForeColor = Drawing.Color.FromArgb(237, 168, 59)
            lblPais.ForeColor = Drawing.Color.FromArgb(237, 168, 59)



            pnlEmpresa.Visible = True
            pnlInstrumento.Visible = False
            pnlPais.Visible = False

        Else

            lblEmpresa.ForeColor = Drawing.Color.FromArgb(237, 168, 59)
            pnlEmpresa.Visible = False

        End If

    End Sub


    Sub EventInstrumento()
        If lblInstrumento.ForeColor.Name = Drawing.Color.FromArgb(237, 168, 59).Name Then
            lblInstrumento.ForeColor = Color.WhiteSmoke
            lblEmpresa.ForeColor = Drawing.Color.FromArgb(237, 168, 59)
            lblPais.ForeColor = Drawing.Color.FromArgb(237, 168, 59)



            pnlInstrumento.Visible = True
            pnlEmpresa.Visible = False
            pnlPais.Visible = False

        Else

            lblInstrumento.ForeColor = Drawing.Color.FromArgb(237, 168, 59)
            pnlInstrumento.Visible = False

        End If

    End Sub


    Sub EventPais()
        If lblPais.ForeColor.Name = Drawing.Color.FromArgb(237, 168, 59).Name Then
            lblPais.ForeColor = Color.WhiteSmoke
            lblInstrumento.ForeColor = Drawing.Color.FromArgb(237, 168, 59)
            lblEmpresa.ForeColor = Drawing.Color.FromArgb(237, 168, 59)



            pnlPais.Visible = True
            pnlInstrumento.Visible = False
            pnlEmpresa.Visible = False

        Else

            lblPais.ForeColor = Drawing.Color.FromArgb(237, 168, 59)
            pnlPais.Visible = False

        End If

    End Sub



    Private Sub lblEmpresa_MouseHover(sender As Object, e As EventArgs) Handles lblEmpresa.MouseHover

    End Sub

    Private Sub lblEmpresa_MouseLeave(sender As Object, e As EventArgs) Handles lblEmpresa.MouseLeave

    End Sub

    Private Sub lblEmpresa_MouseEnter(sender As Object, e As EventArgs) Handles lblEmpresa.MouseEnter

    End Sub

    Private Sub pnlEmpresa_MouseEnter(sender As Object, e As EventArgs) Handles pnlEmpresa.MouseEnter

    End Sub

    Private Sub lblEmpresa_Click(sender As Object, e As EventArgs) Handles lblEmpresa.Click
        EventEmpresa()
    End Sub

    Private Sub lblInstrumento_Click(sender As Object, e As EventArgs) Handles lblInstrumento.Click
        EventInstrumento()
    End Sub

    Private Sub lblPais_Click(sender As Object, e As EventArgs) Handles lblPais.Click
        EventPais()
    End Sub

    Private Sub pnlHijo_Paint(sender As Object, e As PaintEventArgs) Handles pnlHijo.Paint

    End Sub

    Private Sub mnuConfiguracion_Click(sender As Object, e As EventArgs) Handles mnuConfiguracion.Click

    End Sub

    Private Sub lblMontoRendimiento_Click(sender As Object, e As EventArgs) Handles lblMontoRendimiento.Click

    End Sub

    Private Sub FToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles FToolStripMenuItem.Click
        frmMenuCostos.Show()
    End Sub

    Private Sub ArbitrajeToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ArbitrajeToolStripMenuItem.Click
        frmColaTitulos.Show()
    End Sub
End Class
