Imports System.Runtime.InteropServices

Public Class FrmMain
    Dim sw, sh As Integer
#Region "Mov. Pantalla"
    <DllImport("user32.Dll", EntryPoint:="ReleaseCapture")>
    Private Shared Sub ReleaseCapture()
    End Sub

    <DllImport("user32.Dll", EntryPoint:="SendMessage")>
    Private Shared Sub SendMessage(hWnd As IntPtr, wMsg As Integer, wParam As Integer, lParam As Integer)
    End Sub
    Private Sub PanelBarraTitulo_MouseMove(sender As Object, e As MouseEventArgs) Handles PanelBarraTitulo.MouseMove
        ReleaseCapture()
        SendMessage(Me.Handle, &H112&, &HF012&, 0)
    End Sub

    Private Sub lblEmpresa_MouseMove(sender As Object, e As MouseEventArgs) Handles lblEmpresa.MouseMove
        ReleaseCapture()
        SendMessage(Me.Handle, &H112&, &HF012&, 0)
    End Sub

    Private Sub PictureBox2_MouseMove_1(sender As Object, e As MouseEventArgs) Handles PictureBox2.MouseMove
        ReleaseCapture()
        SendMessage(Me.Handle, &H112&, &HF012&, 0)
    End Sub

    Private Sub PanelLogo_MouseMove(sender As Object, e As MouseEventArgs) Handles PanelLogo.MouseMove
        ReleaseCapture()
        SendMessage(Me.Handle, &H112&, &HF012&, 0)
    End Sub


    Private Sub OcultaPaneles()
        PanelIT.Visible = False
    End Sub
    Private Sub MostrarPanel(SubMenu As Panel)
        If SubMenu.Visible = False Then
            OcultaPaneles()
            SubMenu.Visible = True
        Else
            SubMenu.Visible = False
        End If
    End Sub
    Private Sub PictureBox2_MouseMove(sender As Object, e As MouseEventArgs)
        ReleaseCapture()
        SendMessage(Me.Handle, &H112&, &HF012&, 0)
    End Sub
    Private Sub btnMinimizar_Click(sender As Object, e As EventArgs) Handles btnMinimizar.Click
        Me.WindowState = FormWindowState.Minimized
    End Sub
    Private Sub btnCerrar_Click(sender As Object, e As EventArgs) Handles btnCerrar.Click
        VerificaAlertas
    End Sub
#End Region

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        OcultaPaneles()
    End Sub

    Private Sub BtnSalir_Click(sender As Object, e As EventArgs) Handles BtnSalir.Click
        VerificaAlertas()
    End Sub
    Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles btnOcultaMenu.Click
        OcultarMNU()
    End Sub

    Private Sub PictureBox3_Click(sender As Object, e As EventArgs) Handles btnMostrarMenu.Click
        MostrarMNU()
    End Sub
    Sub OcultarMNU()
        tmOcultarMenu.Enabled = True
        Me.btnMostrarMenu.Visible = True
        Me.lblEmpresa.Visible = False
        Me.btnCerrar.Visible = False
        Me.btnMinimizar.Visible = False
        Me.btnOcultaMenu.Visible = False
        LblLetras.Visible = True
        PictureBox2.Visible = False

        lblNivel.Visible = False
        lblUsuario.Visible = False
        lblMail.Visible = False
        lblServidor.Visible = False

        BtnInvoices.Text = ""
        BtnInvoicesHisto.Text = ""
        BtnCobranza.Text = ""
        BtnIT.Text = ""
        BtnClientes.Text = ""
        BtnSalir.Text = ""
        sw = Me.Size.Width
        sh = Me.Size.Height
        Me.Size = New Size(59, sh)
        OcultaPaneles()
    End Sub
    Sub MostrarMNU()
        Me.Size = New Size(sw, sh)
        OcultaPaneles()
        tmMostrarMenu.Enabled = True
        Me.btnMostrarMenu.Visible = False
        Me.lblEmpresa.Visible = True
        Me.btnCerrar.Visible = True
        Me.btnMinimizar.Visible = True
        Me.btnOcultaMenu.Visible = True
        LblLetras.Visible = False
        PictureBox2.Visible = True

        lblNivel.Visible = True
        lblUsuario.Visible = True
        lblMail.Visible = True
        lblServidor.Visible = True

        BtnInvoices.Text = "  Invoices && Remisiones"
        BtnInvoicesHisto.Text = "  Historial Inv. && Rem."
        BtnCobranza.Text = "  Cobranza"
        BtnIT.Text = "  IT && Control Accesos"
        BtnClientes.Text = "Clientes"
        BtnSalir.Text = "  Cerrar Sistema"
    End Sub
    Private Sub tmOcultarMenu_Tick(sender As Object, e As EventArgs) Handles tmOcultarMenu.Tick
        If PanelMenu.Width <= 75 Then
            Me.tmOcultarMenu.Enabled = False
        Else
            PanelMenu.Width = PanelMenu.Width - 20
            PanelLogo.Width = PanelLogo.Width - 20
            PanelBarraTitulo.Width = PanelBarraTitulo.Width - 20
        End If
    End Sub

    Private Sub tmMostrarMenu_Tick(sender As Object, e As EventArgs) Handles tmMostrarMenu.Tick
        If PanelMenu.Width >= 279 Then
            Me.tmMostrarMenu.Enabled = False
        Else
            PanelMenu.Width = PanelMenu.Width + 20
            PanelLogo.Width = PanelLogo.Width + 20
            PanelBarraTitulo.Width = PanelBarraTitulo.Width + 20
        End If
    End Sub

    Private Sub BtnClientes_Click(sender As Object, e As EventArgs) Handles BtnClientes.Click
        If CheckForm(frmClientes) = True Then
            frmClientes.BringToFront()
            frmClientes.WindowState = FormWindowState.Normal
            OcultaPaneles()
        Else
            BtnClientes.BackColor = Color.FromArgb(245, 97, 27)
            OcultaPaneles()
            frmClientes.Show()
        End If
    End Sub

    Private Sub BtnITUsuarios_Click_1(sender As Object, e As EventArgs) Handles BtnITUsuarios.Click
        GlobalVariables.VarOpcion = "Usuarios"
        frmAcceso.ShowDialog()

        If GlobalVariables.VarClaveOK = True Then
            If CheckForm(frmUsuarios) = True Then
                frmUsuarios.BringToFront()
                frmUsuarios.WindowState = FormWindowState.Normal
                OcultaPaneles()
            Else
                BtnITUsuarios.BackColor = Color.FromArgb(245, 97, 27)
                OcultaPaneles()
                frmUsuarios.ShowDialog()
            End If
            Exit Sub
        Else
            MsgBox("Password incorrecto o usuario no autorizado.", MsgBoxStyle.Information, "System Message")
            Exit Sub
        End If
    End Sub

    Private Sub BtnInvoices_Click(sender As Object, e As EventArgs) Handles BtnInvoices.Click
        GlobalVariables.VarFromHistoInv = False

        If CheckForm(FrmInvoices) = True Then
            FrmInvoices.BringToFront()
            FrmInvoices.WindowState = FormWindowState.Normal
            OcultaPaneles()
        Else
            BtnInvoices.BackColor = Color.FromArgb(245, 97, 27)
            OcultaPaneles()
            FrmInvoices.Show()
        End If
    End Sub

    Private Sub BtnInvoicesHisto_Click(sender As Object, e As EventArgs) Handles BtnInvoicesHisto.Click
        If CheckForm(FrmInvoicesHisto) = True Then
            FrmInvoicesHisto.BringToFront()
            FrmInvoicesHisto.WindowState = FormWindowState.Normal
            OcultaPaneles()
        Else
            BtnInvoicesHisto.BackColor = Color.FromArgb(245, 97, 27)
            OcultaPaneles()
            FrmInvoicesHisto.Show()
        End If
    End Sub

    Private Sub BtnCobranza_Click(sender As Object, e As EventArgs) Handles BtnCobranza.Click
        If CheckForm(FrmCobranza) = True Then
            FrmCobranza.BringToFront()
            FrmCobranza.WindowState = FormWindowState.Normal
            OcultaPaneles()
        Else
            BtnCobranza.BackColor = Color.FromArgb(245, 97, 27)
            OcultaPaneles()
            FrmCobranza.Show()
        End If
    End Sub

    Private Sub BtnIT_Click_1(sender As Object, e As EventArgs) Handles BtnIT.Click
        If PanelMenu.Width = 59 Then
            MostrarMNU()
            MostrarPanel(PanelIT)
        Else
            MostrarPanel(PanelIT)
        End If
    End Sub

    Private Sub BtnITConfig_Click(sender As Object, e As EventArgs) Handles BtnITConfig.Click
        GlobalVariables.varConfig = False
        OcultaPaneles()
        frmAccesoConfig.ShowDialog()
    End Sub

    Private Sub BtnITControlAcc_Click(sender As Object, e As EventArgs) Handles BtnITControlAcc.Click
        GlobalVariables.VarOpcion = "Control Accesos"
        frmAcceso.ShowDialog()

        If GlobalVariables.VarClaveOK = True Then
            If CheckForm(frmUsuarios) = True Then
                frmControlACC.BringToFront()
                frmControlACC.WindowState = FormWindowState.Normal
                OcultaPaneles()
            Else
                BtnITControlAcc.BackColor = Color.FromArgb(245, 97, 27)
                OcultaPaneles()
                frmControlACC.ShowDialog()
            End If
            Exit Sub
        Else
            MsgBox("Password incorrecto o usuario no autorizado.", MsgBoxStyle.Information, "System Message")
            Exit Sub
        End If
    End Sub

    Sub VerificaAlertas()
        If GlobalVariables.EditoCliente = True Then
            MsgBox("Atención! Captura de Cliente en proceso... Guardar o Cancelar el registro para continuar.", MsgBoxStyle.Information, "Mensaje del Sistema")
            Exit Sub
        End If

        If GlobalVariables.EditoInvoice = True Then
            MsgBox("Atención! Captura de Invoice/Remisión en proceso... Guardar o Cancelar el registro para continuar.", MsgBoxStyle.Information, "Mensaje del Sistema")
            Exit Sub
        End If

        Application.Exit()
    End Sub

End Class