Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Collections
Imports Funcion.Funcion

Public Class Acceso
    Inherits System.Windows.Forms.Form
    Dim sentFuncion As New Funcion.Funcion
    Dim veces As Integer = 1
    Dim codusu As New Funcion.Funcion
    Dim b As Integer
    Dim ImagenEncabezado = New System.Windows.Forms.PictureBox
    Dim btnMaximizar1 = New System.Windows.Forms.PictureBox
    Dim btnCerrar = New System.Windows.Forms.PictureBox
    Dim btnMinimizar = New System.Windows.Forms.PictureBox
    Dim btnMaximizar2 = New System.Windows.Forms.PictureBox
    Dim PanBtn = New System.Windows.Forms.Panel
    Dim lblNombre = New System.Windows.Forms.Label
    Dim PictureBox6 = New System.Windows.Forms.PictureBox
    Dim Linea1 = New System.Windows.Forms.Label
    Dim Linea2 = New System.Windows.Forms.Label
    Dim Linea3 = New System.Windows.Forms.Label
    'Dim TopLeftColor As New LaMarvin.Windows.Forms.ColorPicker
    ' Dim BottomRightColor As New LaMarvin.Windows.Forms.ColorPicker
    Dim dr As SqlDataReader
    '€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€
    'para guardar en la variable global quien esta logeado
    'Dim UsuCodigo As Long
    'Dim UsuDescripcion As String
    'Dim UsuNivel As Integer
    'Dim UsuPassword As String
    'Dim EmpCodigo As Long
    'Dim EmpDescripcion As String
    'Dim SucCodigo As Long
    'Dim SucDescripcion As String
    Dim color1, color2 As String 'para manejar los colores

    Dim total As String
    Dim servidor As String
    Dim base As String
    Dim aux As String

    Dim longitud As Integer
    Dim i As Integer

#Region " Código generado por el Diseñador de Windows Forms "

    Public Sub New()
        MyBase.New()

        'El Diseñador de Windows Forms requiere esta llamada.
        InitializeComponent()
        Skin()

        'Agregar cualquier inicialización después de la llamada a InitializeComponent()

    End Sub

    'Form reemplaza a Dispose para limpiar la lista de componentes.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Requerido por el Diseñador de Windows Forms
    Private components As System.ComponentModel.IContainer

    'NOTA: el Diseñador de Windows Forms requiere el siguiente procedimiento
    'Puede modificarse utilizando el Diseñador de Windows Forms. 
    'No lo modifique con el editor de código.
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
    Friend WithEvents btnAceptar As System.Windows.Forms.Button
    Friend WithEvents btnCancelar As System.Windows.Forms.Button
    Friend WithEvents Timer1 As System.Windows.Forms.Timer
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents cbNombreEmpresa As vbWindowsUI.FlatComboBox
    Friend WithEvents PrintDocument1 As System.Drawing.Printing.PrintDocument
    Friend WithEvents cbSucursal As vbWindowsUI.FlatComboBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Acceso))
        Me.Label1 = New System.Windows.Forms.Label()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.TextBox1 = New System.Windows.Forms.TextBox()
        Me.TextBox2 = New System.Windows.Forms.TextBox()
        Me.btnAceptar = New System.Windows.Forms.Button()
        Me.btnCancelar = New System.Windows.Forms.Button()
        Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
        Me.Label3 = New System.Windows.Forms.Label()
        Me.Label4 = New System.Windows.Forms.Label()
        Me.cbNombreEmpresa = New vbWindowsUI.FlatComboBox()
        Me.cbSucursal = New vbWindowsUI.FlatComboBox()
        Me.PrintDocument1 = New System.Drawing.Printing.PrintDocument()
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.BackColor = System.Drawing.Color.White
        Me.Label1.Location = New System.Drawing.Point(16, 57)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(100, 23)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "&Sucursal"
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'Label2
        '
        Me.Label2.BackColor = System.Drawing.Color.White
        Me.Label2.Location = New System.Drawing.Point(16, 80)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(100, 23)
        Me.Label2.TabIndex = 1
        Me.Label2.Text = "Usuario"
        Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'TextBox1
        '
        Me.TextBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.TextBox1.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper
        Me.TextBox1.Location = New System.Drawing.Point(128, 81)
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(176, 20)
        Me.TextBox1.TabIndex = 2
        Me.TextBox1.Text = "TEXTBOX1"
        '
        'TextBox2
        '
        Me.TextBox2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.TextBox2.Location = New System.Drawing.Point(128, 105)
        Me.TextBox2.Name = "TextBox2"
        Me.TextBox2.PasswordChar = Global.Microsoft.VisualBasic.ChrW(42)
        Me.TextBox2.Size = New System.Drawing.Size(176, 20)
        Me.TextBox2.TabIndex = 3
        Me.TextBox2.Text = "TEXTBOX2"
        '
        'btnAceptar
        '
        Me.btnAceptar.BackColor = System.Drawing.Color.Transparent
        Me.btnAceptar.FlatStyle = System.Windows.Forms.FlatStyle.Popup
        Me.btnAceptar.Image = CType(resources.GetObject("btnAceptar.Image"), System.Drawing.Image)
        Me.btnAceptar.ImageAlign = System.Drawing.ContentAlignment.TopCenter
        Me.btnAceptar.Location = New System.Drawing.Point(114, 131)
        Me.btnAceptar.Name = "btnAceptar"
        Me.btnAceptar.Size = New System.Drawing.Size(63, 54)
        Me.btnAceptar.TabIndex = 4
        Me.btnAceptar.TextAlign = System.Drawing.ContentAlignment.BottomCenter
        Me.btnAceptar.UseVisualStyleBackColor = False
        '
        'btnCancelar
        '
        Me.btnCancelar.BackColor = System.Drawing.Color.Transparent
        Me.btnCancelar.FlatStyle = System.Windows.Forms.FlatStyle.Popup
        Me.btnCancelar.Image = CType(resources.GetObject("btnCancelar.Image"), System.Drawing.Image)
        Me.btnCancelar.ImageAlign = System.Drawing.ContentAlignment.TopCenter
        Me.btnCancelar.Location = New System.Drawing.Point(189, 131)
        Me.btnCancelar.Name = "btnCancelar"
        Me.btnCancelar.Size = New System.Drawing.Size(63, 54)
        Me.btnCancelar.TabIndex = 5
        Me.btnCancelar.TextAlign = System.Drawing.ContentAlignment.BottomCenter
        Me.btnCancelar.UseVisualStyleBackColor = False
        '
        'Timer1
        '
        Me.Timer1.Enabled = True
        Me.Timer1.Interval = 500
        '
        'Label3
        '
        Me.Label3.BackColor = System.Drawing.Color.White
        Me.Label3.Location = New System.Drawing.Point(16, 33)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(100, 23)
        Me.Label3.TabIndex = 6
        Me.Label3.Text = "&Empresa"
        Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'Label4
        '
        Me.Label4.BackColor = System.Drawing.Color.White
        Me.Label4.Location = New System.Drawing.Point(16, 103)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(100, 23)
        Me.Label4.TabIndex = 7
        Me.Label4.Text = "Contraseña"
        Me.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'cbNombreEmpresa
        '
        Me.cbNombreEmpresa.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cbNombreEmpresa.Location = New System.Drawing.Point(128, 33)
        Me.cbNombreEmpresa.Name = "cbNombreEmpresa"
        Me.cbNombreEmpresa.Size = New System.Drawing.Size(176, 21)
        Me.cbNombreEmpresa.TabIndex = 0
        '
        'cbSucursal
        '
        Me.cbSucursal.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cbSucursal.Location = New System.Drawing.Point(128, 57)
        Me.cbSucursal.Name = "cbSucursal"
        Me.cbSucursal.Size = New System.Drawing.Size(176, 21)
        Me.cbSucursal.TabIndex = 1
        '
        'Acceso
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.SystemColors.Control
        Me.BackgroundImage = CType(resources.GetObject("$this.BackgroundImage"), System.Drawing.Image)
        Me.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch
        Me.ClientSize = New System.Drawing.Size(332, 197)
        Me.ControlBox = False
        Me.Controls.Add(Me.cbSucursal)
        Me.Controls.Add(Me.cbNombreEmpresa)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.btnCancelar)
        Me.Controls.Add(Me.btnAceptar)
        Me.Controls.Add(Me.TextBox2)
        Me.Controls.Add(Me.TextBox1)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.Name = "Acceso"
        Me.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Acceso"
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region

#Region " Skin "
    Public Sub Skin()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Madre))
        Me.PanBtn.SuspendLayout()
        Me.SuspendLayout()
        '
        'ImagenEncabezado
        '
        Me.ImagenEncabezado.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.ImagenEncabezado.Cursor = System.Windows.Forms.Cursors.Default
        Me.ImagenEncabezado.Image = CType(resources.GetObject("ImagenEncabezado.Image"), System.Drawing.Image)
        Me.ImagenEncabezado.Location = New System.Drawing.Point(0, 0)
        Me.ImagenEncabezado.Name = "ImagenEncabezado"
        Me.ImagenEncabezado.Size = New System.Drawing.Size(Me.Size.Width, 19)
        Me.ImagenEncabezado.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage
        Me.ImagenEncabezado.TabIndex = 5
        Me.ImagenEncabezado.TabStop = False
        '
        'btnMaximizar1
        '
        Me.btnMaximizar1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.btnMaximizar1.Cursor = System.Windows.Forms.Cursors.Default
        Me.btnMaximizar1.Image = CType(resources.GetObject("btnMaximizar1.Image"), System.Drawing.Image)
        Me.btnMaximizar1.Location = New System.Drawing.Point(18, 0)
        Me.btnMaximizar1.Name = "btnMaximizar1"
        Me.btnMaximizar1.Size = New System.Drawing.Size(19, 19)
        Me.btnMaximizar1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize
        Me.btnMaximizar1.TabIndex = 13
        Me.btnMaximizar1.TabStop = False
        '
        'btnCerrar
        '
        Me.btnCerrar.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.btnCerrar.Cursor = System.Windows.Forms.Cursors.Default
        Me.btnCerrar.Image = CType(resources.GetObject("btnCerrar.Image"), System.Drawing.Image)
        Me.btnCerrar.Location = New System.Drawing.Point(35, 0)
        Me.btnCerrar.Name = "btnCerrar"
        Me.btnCerrar.Size = New System.Drawing.Size(20, 19)
        Me.btnCerrar.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize
        Me.btnCerrar.TabIndex = 12
        Me.btnCerrar.TabStop = False
        '
        'btnMinimizar
        '
        Me.btnMinimizar.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.btnMinimizar.Cursor = System.Windows.Forms.Cursors.Arrow
        Me.btnMinimizar.Image = CType(resources.GetObject("btnMinimizar.Image"), System.Drawing.Image)
        Me.btnMinimizar.Location = New System.Drawing.Point(0, 0)
        Me.btnMinimizar.Name = "btnMinimizar"
        Me.btnMinimizar.Size = New System.Drawing.Size(19, 19)
        Me.btnMinimizar.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize
        Me.btnMinimizar.TabIndex = 10
        Me.btnMinimizar.TabStop = False
        '
        'btnMaximizar2
        '
        Me.btnMaximizar2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.btnMaximizar2.Cursor = System.Windows.Forms.Cursors.Default
        Me.btnMaximizar2.Image = CType(resources.GetObject("btnMaximizar2.Image"), System.Drawing.Image)
        Me.btnMaximizar2.Location = New System.Drawing.Point(18, 0)
        Me.btnMaximizar2.Name = "btnMaximizar2"
        Me.btnMaximizar2.Size = New System.Drawing.Size(19, 19)
        Me.btnMaximizar2.TabIndex = 9
        Me.btnMaximizar2.TabStop = False
        Me.btnMaximizar2.Visible = False
        '
        'PanBtn
        '
        Me.PanBtn.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.PanBtn.Controls.Add(Me.btnMaximizar1)
        Me.PanBtn.Controls.Add(Me.btnCerrar)
        Me.PanBtn.Controls.Add(Me.btnMinimizar)
        Me.PanBtn.Controls.Add(Me.btnMaximizar2)
        Me.PanBtn.Cursor = System.Windows.Forms.Cursors.Default
        Me.PanBtn.Location = New System.Drawing.Point(Me.Size.Width - 55, 0)
        Me.PanBtn.Name = "PanBtn"
        Me.PanBtn.Size = New System.Drawing.Size(55, 20)
        Me.PanBtn.TabIndex = 14
        '
        'lblNombre
        '
        Me.lblNombre.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblNombre.ForeColor = System.Drawing.Color.White
        Me.lblNombre.Image = CType(resources.GetObject("lblNombre.Image"), System.Drawing.Image)
        Me.lblNombre.Location = New System.Drawing.Point(20, 0)
        Me.lblNombre.Name = "lblNombre"
        Me.lblNombre.Size = New System.Drawing.Size(200, 16)
        Me.lblNombre.TabIndex = 16
        Me.lblNombre.Text = "Acceso a Stock"
        '
        'PictureBox6
        '
        Me.PictureBox6.BackColor = System.Drawing.Color.Transparent
        Me.PictureBox6.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.PictureBox6.Cursor = System.Windows.Forms.Cursors.Default
        Me.PictureBox6.Image = CType(resources.GetObject("PictureBox6.Image"), System.Drawing.Image)
        Me.PictureBox6.Location = New System.Drawing.Point(0, 0)
        Me.PictureBox6.Name = "PictureBox6"
        Me.PictureBox6.Size = New System.Drawing.Size(19, 19)
        Me.PictureBox6.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage
        Me.PictureBox6.TabIndex = 15
        Me.PictureBox6.TabStop = False
        '
        'Linea1
        '
        Me.Linea1.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.Linea1.BackColor = System.Drawing.Color.FromArgb(CType(64, Byte), CType(64, Byte), CType(64, Byte))
        Me.Linea1.Cursor = System.Windows.Forms.Cursors.Default
        Me.Linea1.Location = New System.Drawing.Point(0, 0)
        Me.Linea1.Name = "Linea1"
        Me.Linea1.Size = New System.Drawing.Size(2, Me.Size.Height)
        Me.Linea1.TabIndex = 272

        '
        'Linea2
        '
        Me.Linea2.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.Linea2.BackColor = System.Drawing.Color.FromArgb(CType(64, Byte), CType(64, Byte), CType(64, Byte))
        Me.Linea2.Cursor = System.Windows.Forms.Cursors.SizeWE
        Me.Linea2.Location = New System.Drawing.Point(Me.Size.Width - 2, 0)
        Me.Linea2.Name = "Linea2"
        Me.Linea2.Size = New System.Drawing.Size(2, Me.Size.Height)
        Me.Linea2.TabIndex = 273
        '
        'Linea3
        '
        Me.Linea3.Anchor = CType(((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.Linea3.BackColor = System.Drawing.Color.FromArgb(CType(64, Byte), CType(64, Byte), CType(64, Byte))
        Me.Linea3.Cursor = System.Windows.Forms.Cursors.SizeNS
        Me.Linea3.Location = New System.Drawing.Point(0, Me.Size.Height - 2)
        Me.Linea3.Name = "Linea3"
        Me.Linea3.Size = New System.Drawing.Size(Me.Size.Width, 2)
        Me.Linea3.TabIndex = 274
        '
        'TopLeftColor
        '
        'Me.TopLeftColor.Color = System.Drawing.Color.Ivory
        'Me.TopLeftColor.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(238, Byte))
        'Me.TopLeftColor.ForeColor = System.Drawing.Color.Cyan
        'Me.TopLeftColor.Location = New System.Drawing.Point(0, 19)
        'Me.TopLeftColor.Name = "TopLeftColor"
        'Me.TopLeftColor.Size = New System.Drawing.Size(12, 12)
        'Me.TopLeftColor.TabIndex = 277
        'Me.TopLeftColor.Text = "ColorPicker1"
        'Me.TopLeftColor.TextDisplayed = False
        '
        'BottomRightColor
        '
        'Me.BottomRightColor.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        'Me.BottomRightColor.Color = System.Drawing.Color.DarkSeaGreen
        'Me.BottomRightColor.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(238, Byte))
        'Me.BottomRightColor.Location = New System.Drawing.Point(Me.Size.Width - 13, Me.Size.Height - 13)
        'Me.BottomRightColor.Name = "BottomRightColor"
        'Me.BottomRightColor.Size = New System.Drawing.Size(12, 12)
        'Me.BottomRightColor.TabIndex = 278
        'Me.BottomRightColor.Text = "ColorPicker1"
        'Me.BottomRightColor.TextDisplayed = False

        '
        'Madre
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.Color.FromArgb(CType(230, Byte), CType(230, Byte), CType(230, Byte))
        Me.ClientSize = New System.Drawing.Size(Me.Size.Width, Me.Size.Height)
        Me.Controls.Add(Me.Linea3)
        Me.Controls.Add(Me.Linea2)
        Me.Controls.Add(Me.Linea1)
        'Me.Controls.Add(Me.TopLeftColor)
        'Me.Controls.Add(Me.BottomRightColor)
        Me.Controls.Add(Me.lblNombre)
        Me.Controls.Add(Me.ImagenEncabezado)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
        Me.Text = "Acceso"
        Me.ResumeLayout(False)
    End Sub
#End Region

    Private Sub Evento_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        Dim KeyAscii As Short = Asc(e.KeyChar)
        If KeyAscii = 42 Then
            TextBox2.Focus()
        End If
        If KeyAscii = 0 Then
            e.Handled = True
        End If
    End Sub

    Private Sub AsignarEventos(ByVal elControl As Control)
        Dim ctrl As Control
        For Each ctrl In elControl.Controls
            AddHandler ctrl.KeyPress, AddressOf Me.Salir
            AddHandler ctrl.KeyPress, AddressOf Me.Evento_KeyPress
            AddHandler ctrl.KeyDown, AddressOf Me.Acceso_KeyDown

            AsignarEventos(ctrl)
        Next
    End Sub

    Private Sub Salir(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
        Dim KeyAscii As Short = Asc(e.KeyChar)
        If KeyAscii = 27 Then
            End     'End para que salga del programa u no entre
        End If
    End Sub

    Private Sub Acceso_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        b = 0
        limpiar()
        CargarEmpresa()
        'Pedro Silva 25062012. Utilizo el nombre de la empresa para consultar su sucursal y ponerle
        ' como valor por default en el combo sucursal
        If Not cbNombreEmpresa.SelectedValue = Nothing Then
            CargarSucursal(cbNombreEmpresa.SelectedValue)
        End If
        Configuraciones()
        TextBox1.Text = ""
        TextBox2.Text = ""
        btnAceptar.Focus()
        ''
        ''
        '2005-04-15 Gerke para que funcione las teclas de acceso directo
        AsignarEventos(Me)

        cbNombreEmpresa.SelectedValue = 1
        CargarSucursal(cbNombreEmpresa.SelectedValue)
        TextBox1.Focus()
    End Sub

    Public Sub CargarEmpresa()
        cbNombreEmpresa.DataBindings.Clear()
        Try
            cbNombreEmpresa.DataSource = sentFuncion.Empresa()

            cbNombreEmpresa.DisplayMember = "Table.NOMBRE"
            cbNombreEmpresa.ValueMember = "Table.CODIGO"
        Catch ex As Exception
            cbNombreEmpresa.DataSource = Nothing
            limpiar()

            MsgBox("No se pudo realizar la Conexión." & vbCrLf & "Verifique el Servidor.", MsgBoxStyle.Critical + MsgBoxStyle.OKOnly + MsgBoxStyle.SystemModal, _
            "Acceso")

            btnAceptar.Focus()
        End Try
    End Sub

    Public Sub CargarSucursal(ByVal empresa As Long)
        cbSucursal.DataBindings.Clear()
        cbSucursal.DataSource = sentFuncion.Sucursal(empresa)
        cbSucursal.DisplayMember = "Table.Nombre"
        cbSucursal.ValueMember = "Table.Codigo"
        If cbSucursal.Items.Count = 1 Then
            TextBox1.Focus()
        Else
            cbSucursal.Focus()
        End If

    End Sub

    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        Dim KeyAscii As Short = Asc(e.KeyChar)
        Dim cadena As Object
        'cadena = "0123456789/" & Chr(8) & Chr(13) & Chr(42) 'chr(8) = delete, es decir admitimos borrar
        cadena = StringCadena
        If InStr(cadena, Chr(KeyAscii)) = 0 Then
            KeyAscii = 0
        Else
            If KeyAscii = 13 Then
                TextBox2.Focus()
            End If
        End If
        If KeyAscii = 0 Then
            e.Handled = True
        End If
    End Sub

    Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
        Dim KeyAscii As Short = Asc(e.KeyChar)
        Dim cadena As Object
        'cadena = "0123456789/" & Chr(8) & Chr(13) & Chr(42) 'chr(8) = delete, es decir admitimos borrar
        cadena = StringCadena
        If InStr(cadena, Chr(KeyAscii)) = 0 Then
            KeyAscii = 0
        Else
            If KeyAscii = 13 Then
                btnAceptar.Focus()
                btnAceptar.PerformClick() 'Pedro Silva 27062012 Me ahorro un evento al hacer clic directamente desde aca
            End If
        End If
        If KeyAscii = 0 Then
            e.Handled = True
        End If
    End Sub

    Private Sub btnCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
        End
    End Sub

    Public Sub limpiar()
        TextBox1.Text = ""
        TextBox2.Text = ""
        cbNombreEmpresa.Text = ""
        cbSucursal.Text = ""
    End Sub

    Private Sub btnAceptar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAceptar.Click
        If cbNombreEmpresa.SelectedIndex = -1 Then
            MsgBox("Debe seleccionar la empresa")
            Exit Sub
        End If

        If cbSucursal.SelectedIndex = -1 Then
            MsgBox("Debe seleccionar una sucursal")
            Exit Sub
        End If


        If veces <= 3 Then      'Si son menos de 3 intentos
            dr = codusu.usuario(TextBox1.Text, TextBox2.Text, cbNombreEmpresa.SelectedValue)

            Try
                'Para cualquier error   
                dr.Read()

                If Not TextBox2.Text = dr("password") Then
                    dr.Close()
                End If

                UsuCodigo = dr("codigo")
                UsuDescripcion = dr("usuario")
                UsuDescripcion = UsuDescripcion.Trim
                UsuNivel = dr("nivel")
                UsuPassword = dr("password")
                EmpCodigo = dr("empresa")
                SucCodigoPertenece = dr("codsucursalpertenece").ToString
                If SucCodigoPertenece = "" Then
                    SucCodigoPertenece = "NULL" 'Pedro Silva 28062012 Significa que el usuario tiene acceso full
                    'para consultar los informes de todos las sucursales
                    SucDescripcion = cbSucursal.Text
                Else
                    SucDescripcion = sentFuncion.UsuarioSucursal(EmpCodigo, SucCodigoPertenece)
                    'SucDescripcion = sentFuncion.Descripcion_Tabla("DESSUCURSAL", "SUCURSAL", "CODSUCURSAL", SucCodigoPertenece, EmpCodigo)
                End If
                EmpDescripcion = cbNombreEmpresa.Text
                EmpDescripcion = EmpDescripcion.Trim
                SucCodigo = cbSucursal.SelectedValue
                'SucDescripcion = SucDescripcion.Trim
                Entrar = 1

            Catch
                MsgBox("Verifique su clave, vuelva a intentarlo", MsgBoxStyle.Information, "Error")
                UsuCodigo = 0
                Entrar = 0
            Finally
                If UsuCodigo <> 0 Then
                    'validamos q la fecha del servidor sea igual a la fecha de la maquina
                    b = 1
                    AccesoGuardar() 'guarda los datos actuales del usurio en OndaNet.XML
                    Me.Close()
                Else
                    veces = veces + 1
                    Call limpiar()
                End If
                dr.Close()
                codusu.usuario(TextBox1.Text, TextBox2.Text, cbNombreEmpresa.SelectedValue).Close()
                TextBox1.Focus()
            End Try
        Else
            veces = veces + 1
            Call limpiar()
        End If

        If veces <= 3 Then
            TextBox1.Focus()
        Else
            End
        End If
    End Sub

    Private Sub Acceso_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
        btnAceptar.Focus()
    End Sub

    Private Sub Acceso_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        'If b = 1 Then
        Timer1.Enabled = False
        'MDI.ShowDialog()
        'End If
    End Sub

    'Protected Overrides Sub OnPaintBackground(ByVal e As System.Windows.Forms.PaintEventArgs)
    '    Dim B As Brush
    '    Try
    '        B = New Drawing2D.LinearGradientBrush(Me.ClientRectangle, Me.TopLeftColor.Color, Me.BottomRightColor.Color, Drawing2D.LinearGradientMode.ForwardDiagonal)
    '        e.Graphics.FillRectangle(B, Me.ClientRectangle)
    '    Catch
    '    Finally
    '        If Not B Is Nothing Then
    '            B.Dispose()
    '        End If
    '    End Try
    'End Sub

    Private Sub Acceso_BackColorChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.BackColorChanged
        Me.Refresh()
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        'Try
        'TopLeftColor.Color.FromName(color1)
        'BottomRightColor.Color.FromName(color2)
        'Catch
        'Finally
        'End Try
        Me.Refresh()
    End Sub

    Public Sub Configuraciones()
        ' Use reflection to find the location of the config file. 
        Dim Asm As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly
        Dim strConfigLoc As String = Asm.Location

        ' The config file is located in the application's bin directory, so
        ' you need to remove the file name.
        Dim strTemp As String
        strTemp = strConfigLoc
        strTemp = System.IO.Path.GetDirectoryName(strConfigLoc)

        ' Declare a FileInfo object for the config file.
        Dim FileInfo As System.IO.FileInfo = New System.IO.FileInfo(strTemp & "\OndaNet.xml")

        ' Load the config file into the XML DOM.
        Dim XmlDocument As New System.Xml.XmlDocument
        XmlDocument.Load(FileInfo.FullName)

        ' Find the right node and change it to the new value.
        Dim Node As System.Xml.XmlNode
        For Each Node In XmlDocument.Item("configuration").Item("Usuario")
            ' Skip any comments.
            If Node.Name = "add" Then
                If Node.Attributes.GetNamedItem("key").Value = "AccesoEstado" Then
                    If Node.Attributes.GetNamedItem("value").Value = "1" Then
                        Me.WindowState = FormWindowState.Maximized
                    Else
                        Me.WindowState = FormWindowState.Normal
                    End If

                End If
                Dim a As String
                'If Node.Attributes.GetNamedItem("key").Value = "AccesoColor1" Then
                '    TopLeftColor.Color = System.Drawing.Color.FromName(Node.Attributes.GetNamedItem("value").Value.ToString)
                'End If
                'If Node.Attributes.GetNamedItem("key").Value = "AccesoColor2" Then
                '    BottomRightColor.Color = System.Drawing.Color.FromName(Node.Attributes.GetNamedItem("value").Value.ToString)
                'End If
            End If
        Next Node
    End Sub

    Public Sub AccesoGuardar()
        'color1 = TopLeftColor.Color.Name.ToString
        'color2 = BottomRightColor.Color.Name.ToString
        Dim Asm As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly
        Dim strConfigLoc As String = Asm.Location
        Dim strTemp As String
        strTemp = strConfigLoc
        strTemp = System.IO.Path.GetDirectoryName(strConfigLoc)
        Dim FileInfo As System.IO.FileInfo = New System.IO.FileInfo(strTemp & "\OndaNet.xml")
        Dim XmlDocument As New System.Xml.XmlDocument
        XmlDocument.Load(FileInfo.FullName)
        Dim Node As System.Xml.XmlNode
        For Each Node In XmlDocument.Item("configuration").Item("Usuario")
            If Node.Name = "add" Then
                If Node.Attributes.GetNamedItem("key").Value = "UsuCodigo" Then
                    Node.Attributes.GetNamedItem("value").Value = CType(UsuCodigo, String)
                End If
                If Node.Attributes.GetNamedItem("key").Value = "UsuDescripcion" Then
                    Node.Attributes.GetNamedItem("value").Value = CType(UsuDescripcion, String)
                End If
                If Node.Attributes.GetNamedItem("key").Value = "UsuNivel" Then
                    Node.Attributes.GetNamedItem("value").Value = CType(UsuNivel, String)
                End If
                If Node.Attributes.GetNamedItem("key").Value = "EmpCodigo" Then
                    Node.Attributes.GetNamedItem("value").Value = CType(EmpCodigo, String)
                End If
                If Node.Attributes.GetNamedItem("key").Value = "EmpDescripcion" Then
                    Node.Attributes.GetNamedItem("value").Value = CType(EmpDescripcion, String)
                End If
                If Node.Attributes.GetNamedItem("key").Value = "SucCodigo" Then
                    Node.Attributes.GetNamedItem("value").Value = CType(SucCodigo, String)
                End If
                If Node.Attributes.GetNamedItem("key").Value = "SucDescripcion" Then
                    Node.Attributes.GetNamedItem("value").Value = CType(SucDescripcion, String)
                End If
                If Node.Attributes.GetNamedItem("key").Value = "AccesoColor1" Then
                    Node.Attributes.GetNamedItem("value").Value = CType(color1, String)
                End If
                If Node.Attributes.GetNamedItem("key").Value = "AccesoColor2" Then
                    Node.Attributes.GetNamedItem("value").Value = CType(color2, String)
                End If
            End If
        Next Node
        XmlDocument.Save(FileInfo.FullName)
    End Sub

    Private Sub cbNombreEmpresa_SelectionChangeCommitted(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbNombreEmpresa.SelectionChangeCommitted
        'cuando se elige una empresa
        CargarSucursal(cbNombreEmpresa.SelectedValue)
    End Sub

    Private Sub CambiaServidor()
        'Pide el nombre del Servidor y lo cambia en el Total
        servidor = InputBox("Ingrese el Nombre del Servidor", "Acceso", "")

        If Not servidor = "" Then
            i = total.IndexOf(";")

            total = total.Remove(0, i)
            total = "workstation id=" & servidor & total

            i = total.IndexOf("data source=")
            longitud = total.IndexOf(";", i)

            aux = total.Substring(i, longitud - i)
            total = total.Replace(aux, "data source=" & servidor)
        End If
    End Sub

    Private Sub CambiaBase()
        'Pide el nombre de la Base y lo cambia en el Total
        base = InputBox("Ingrese el Nombre de la Base de Datos", "Acceso", "")

        If Not base = "" Then
            i = total.IndexOf("catalog=")
            longitud = total.Length

            aux = total.Substring(i, longitud - i)
            total = total.Replace(aux, "catalog=" & base)
        End If
    End Sub

    Private Sub Acceso_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        If (e.Control = True And e.Alt = True And e.KeyCode = Keys.S) Or _
        (e.Control = True And e.Alt = True And e.KeyCode = Keys.B) Then
            If total = "" Then
                Dim BD As New BD.ABD
                BD.Leer()

                total = BD.Conect
            End If
        End If

        'Ctrl + Alt + S
        If e.Control = True And e.Alt = True And e.KeyCode = Keys.S Then
            CambiaServidor()

            e.Handled = True
        End If

        'Ctrl + Alt + B
        If e.Control = True And e.Alt = True And e.KeyCode = Keys.B Then
            CambiaBase()

            e.Handled = True
        End If

        'Ctrl + Alt + G
        If e.Control = True And e.Alt = True And e.KeyCode = Keys.G Then
            Grabar()

            e.Handled = True
        End If

        If e.Alt = True Then
            If e.KeyCode = Keys.E Then
                cbNombreEmpresa.Focus()

                e.Handled = True
            End If
        End If

        If e.Alt = True Then
            If e.KeyCode = Keys.S Then
                cbSucursal.Focus()

                e.Handled = True
            End If
        End If
    End Sub

    Public Sub Grabar()
        If Not total = "" Then
            Dim Asm As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly
            Dim strConfigLoc As String = Asm.Location
            Dim strTemp As String
            strTemp = strConfigLoc
            strTemp = System.IO.Path.GetDirectoryName(strConfigLoc)
            Dim FileInfo As System.IO.FileInfo = New System.IO.FileInfo(strTemp & "\Total.xml")
            Dim XmlDocument As New System.Xml.XmlDocument
            XmlDocument.Load(FileInfo.FullName)
            Dim Node As System.Xml.XmlNode
            For Each Node In XmlDocument.Item("configuration").Item("Usuario")
                ' Skip any comments.
                If Node.Name = "add" Then
                    If Node.Attributes.GetNamedItem("key").Value = "Conect" Then
                        Node.Attributes.GetNamedItem("value").Value = total
                    End If
                End If
            Next Node
            XmlDocument.Save(FileInfo.FullName)

            limpiar()
            CargarEmpresa()
        End If
    End Sub

    Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
        If e.KeyCode = Keys.Up Then
            cbSucursal.Focus()
        ElseIf e.KeyCode = Keys.Down Then
            TextBox2.Focus()
        End If
    End Sub

    Private Sub TextBox2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox2.KeyDown
        If e.KeyCode = Keys.Up Then
            TextBox1.Focus()
        ElseIf e.KeyCode = Keys.Down Then
            cbNombreEmpresa.Focus()
        End If
    End Sub

    Private Sub cbNombreEmpresa_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles cbNombreEmpresa.KeyPress
        Dim keyAscii As Short = Asc(e.KeyChar)

        If keyAscii = 13 Then
            CargarSucursal(cbNombreEmpresa.SelectedValue)
            cbSucursal.Focus()
        End If
    End Sub

    Private Sub cbSucursal_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles cbSucursal.KeyPress
        Dim keyAscii As Short = Asc(e.KeyChar)

        If keyAscii = 13 Then
            TextBox1.Focus()
        End If
    End Sub
End Class