Public Class AccesoCajero
    Inherits System.Windows.Forms.Form
    Private veces As Integer = 1
    Private Acceso As Boolean
    Private Password As String

    Private color1, color2 As String
    Friend WithEvents btnCancelar As System.Windows.Forms.Button
    Friend WithEvents btnAceptar As System.Windows.Forms.Button
    Friend WithEvents TopLeftColor As LaMarvin.Windows.Forms.ColorPicker

#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()

        '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 Label4 As System.Windows.Forms.Label
    Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents BottomRightColor As LaMarvin.Windows.Forms.ColorPicker
    Friend WithEvents Label5 As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(AccesoCajero))
        Me.Label4 = New System.Windows.Forms.Label()
        Me.TextBox2 = New System.Windows.Forms.TextBox()
        Me.TextBox1 = New System.Windows.Forms.TextBox()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.BottomRightColor = New LaMarvin.Windows.Forms.ColorPicker()
        Me.Label5 = New System.Windows.Forms.Label()
        Me.TopLeftColor = New LaMarvin.Windows.Forms.ColorPicker()
        Me.btnCancelar = New System.Windows.Forms.Button()
        Me.btnAceptar = New System.Windows.Forms.Button()
        Me.SuspendLayout()
        '
        'Label4
        '
        Me.Label4.BackColor = System.Drawing.Color.Transparent
        Me.Label4.Location = New System.Drawing.Point(5, 29)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(120, 23)
        Me.Label4.TabIndex = 13
        Me.Label4.Text = "Contraseña"
        Me.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'TextBox2
        '
        Me.TextBox2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.TextBox2.Location = New System.Drawing.Point(141, 29)
        Me.TextBox2.MaxLength = 20
        Me.TextBox2.Name = "TextBox2"
        Me.TextBox2.PasswordChar = Global.Microsoft.VisualBasic.ChrW(42)
        Me.TextBox2.Size = New System.Drawing.Size(128, 20)
        Me.TextBox2.TabIndex = 10
        Me.TextBox2.Text = "********************"
        '
        'TextBox1
        '
        Me.TextBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.TextBox1.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper
        Me.TextBox1.Location = New System.Drawing.Point(141, 5)
        Me.TextBox1.MaxLength = 5
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(128, 20)
        Me.TextBox1.TabIndex = 9
        Me.TextBox1.Text = "TEXTBOX1"
        '
        'Label2
        '
        Me.Label2.BackColor = System.Drawing.Color.Transparent
        Me.Label2.Location = New System.Drawing.Point(5, 5)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(120, 23)
        Me.Label2.TabIndex = 8
        Me.Label2.Text = "Cajero"
        Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'Label1
        '
        Me.Label1.BackColor = System.Drawing.Color.Transparent
        Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.Location = New System.Drawing.Point(12, 60)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(254, 20)
        Me.Label1.TabIndex = 14
        Me.Label1.Text = "Cajero"
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        '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.SystemColors.Control
        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.ForeColor = System.Drawing.Color.Cyan
        Me.BottomRightColor.Location = New System.Drawing.Point(357, 109)
        Me.BottomRightColor.Name = "BottomRightColor"
        Me.BottomRightColor.Size = New System.Drawing.Size(12, 12)
        Me.BottomRightColor.TabIndex = 18
        Me.BottomRightColor.Text = "ColorPicker1"
        Me.BottomRightColor.TextDisplayed = False
        Me.BottomRightColor.Visible = False
        '
        'Label5
        '
        Me.Label5.BackColor = System.Drawing.Color.Transparent
        Me.Label5.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label5.Location = New System.Drawing.Point(12, 84)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(254, 20)
        Me.Label5.TabIndex = 20
        Me.Label5.Text = "Caja"
        Me.Label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'TopLeftColor
        '
        Me.TopLeftColor.Color = System.Drawing.SystemColors.Control
        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, 0)
        Me.TopLeftColor.Name = "TopLeftColor"
        Me.TopLeftColor.Size = New System.Drawing.Size(12, 12)
        Me.TopLeftColor.TabIndex = 17
        Me.TopLeftColor.Text = "ColorPicker1"
        Me.TopLeftColor.TextDisplayed = False
        Me.TopLeftColor.Visible = False
        '
        'btnCancelar
        '
        Me.btnCancelar.Anchor = System.Windows.Forms.AnchorStyles.Bottom
        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.Location = New System.Drawing.Point(299, 62)
        Me.btnCancelar.Name = "btnCancelar"
        Me.btnCancelar.Size = New System.Drawing.Size(59, 51)
        Me.btnCancelar.TabIndex = 22
        Me.btnCancelar.UseVisualStyleBackColor = False
        '
        'btnAceptar
        '
        Me.btnAceptar.Anchor = System.Windows.Forms.AnchorStyles.Bottom
        Me.btnAceptar.BackColor = System.Drawing.Color.Transparent
        Me.btnAceptar.FlatStyle = System.Windows.Forms.FlatStyle.Popup
        Me.btnAceptar.ForeColor = System.Drawing.SystemColors.AppWorkspace
        Me.btnAceptar.Image = CType(resources.GetObject("btnAceptar.Image"), System.Drawing.Image)
        Me.btnAceptar.Location = New System.Drawing.Point(299, 5)
        Me.btnAceptar.Name = "btnAceptar"
        Me.btnAceptar.Size = New System.Drawing.Size(59, 51)
        Me.btnAceptar.TabIndex = 21
        Me.btnAceptar.UseVisualStyleBackColor = False
        '
        'AccesoCajero
        '
        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.ClientSize = New System.Drawing.Size(369, 121)
        Me.ControlBox = False
        Me.Controls.Add(Me.btnCancelar)
        Me.Controls.Add(Me.btnAceptar)
        Me.Controls.Add(Me.Label5)
        Me.Controls.Add(Me.BottomRightColor)
        Me.Controls.Add(Me.TopLeftColor)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.TextBox2)
        Me.Controls.Add(Me.TextBox1)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.KeyPreview = True
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "AccesoCajero"
        Me.ShowInTaskbar = False
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Cajero"
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region

    Private Sub ColorChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles BottomRightColor.ColorChanged, TopLeftColor.ColorChanged
        Me.Refresh()
        color1 = TopLeftColor.Color.Name.ToString
        color2 = BottomRightColor.Color.Name.ToString
    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 Configuraciones()
        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 = Me.Name.ToString Then
                '    If Node.Attributes.GetNamedItem("value").Value = "1" Then
                '        Me.WindowState = FormWindowState.Maximized
                '    Else
                '        Me.WindowState = FormWindowState.Normal
                '    End If
                'End If
                'If Node.Attributes.GetNamedItem("key").Value = Me.Name.ToString & "Color1" Then
                '    TopLeftColor.Color = System.Drawing.Color.FromName(Node.Attributes.GetNamedItem("value").Value.ToString)
                'End If
                'If Node.Attributes.GetNamedItem("key").Value = Me.Name.ToString & "Color2" Then
                '    BottomRightColor.Color = System.Drawing.Color.FromName(Node.Attributes.GetNamedItem("value").Value.ToString)
                'End If
            End If
        Next Node
    End Sub

    Private Sub _Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        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 = Me.Name.ToString Then
                '    If Me.WindowState = FormWindowState.Maximized Then
                '        Node.Attributes.GetNamedItem("value").Value = CType("1", String)
                '    Else
                '        Node.Attributes.GetNamedItem("value").Value = CType("0", String)
                '    End If
                'End If
                If Node.Attributes.GetNamedItem("key").Value = Me.Name.ToString & "Color1" Then
                    Node.Attributes.GetNamedItem("value").Value = CType(color1, String)
                End If
                If Node.Attributes.GetNamedItem("key").Value = Me.Name.ToString & "Color2" Then
                    Node.Attributes.GetNamedItem("value").Value = CType(color2, String)
                End If
            End If
        Next Node
        XmlDocument.Save(FileInfo.FullName)
    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
            Close()
        End If
    End Sub

    Private Sub AccesoCajero_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
        Me.Tag = Acceso
    End Sub

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

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

    Public Sub limpiar()
        TextBox1.Text = ""
        TextBox2.Text = ""
        Label1.Text = ""
        Label5.Text = ""

        TextBox1.Focus()
    End Sub

    Private Sub AccesoCajero_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        limpiar()
        Configuraciones()
        AsignarEventos(Me)

        Me.Refresh()
    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 = StringCadena
        If InStr(cadena, Chr(KeyAscii)) = 0 Then
            KeyAscii = 0
        End If
        If KeyAscii = 13 Then
            TextBox2.Focus()
        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 = StringCadena
        If InStr(cadena, Chr(KeyAscii)) = 0 Then
            KeyAscii = 0
        End If
        If KeyAscii = 13 Then
            btnAceptar.Focus()
        End If
        If KeyAscii = 0 Then
            e.Handled = True
        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
            TextBox2.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
            TextBox1.Focus()
        End If
    End Sub

    Private Sub TextBox1_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Validated
        If TextBox1.Text.Trim <> "" Then
            If funcion.Validar_Tabla_cod_string("NUMCOBRADOR", "COBRADOR", "NUMCOBRADOR", TextBox1.Text.Trim, EmpCodigo) Then
                TextBox1.Tag = funcion.Validar_Tabla("USUARIO", "COBRADOR", "NUMCOBRADOR", TextBox1.Text.Trim, EmpCodigo)
                Label1.Text = funcion.Descripcion_Tabla("DESCOBRADOR", "COBRADOR", "NUMCOBRADOR", TextBox1.Text.Trim, EmpCodigo)

                CodCobrador = funcion.Validar_Tabla("CODCOBRADOR", "COBRADOR", "NUMCOBRADOR", TextBox1.Text.Trim, EmpCodigo)
                NumCobrador = TextBox1.Text.Trim
                DesCobrador = Label1.Text.Trim

                NumCaja = funcion.Validar_Tabla("NUMCAJA", "CAJA", "CODCOBRADOR", CodCobrador, EmpCodigo & " AND CODSUCURSAL = " & SucCodigo & " ")
                NumeroCaja = funcion.Descripcion_Tabla("NUMEROCAJA", "CAJA", "NUMCAJA", NumCaja, EmpCodigo)

                If NumCaja = 0 Then
                    Label5.Text = "- Numero de caja no Asignada -"
                Else
                    Label5.Text = "Caja Nº " & NumeroCaja
                End If
            Else
                TextBox1.Tag = 0
                Label1.Text = Label2.Text & " no Existe"
                Label5.Text = ""
            End If
        Else
            TextBox1.Tag = 0
            Label1.Text = ""
            Label5.Text = ""
        End If
    End Sub

    Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.GotFocus
        SeleccionaTexto(TextBox1)
    End Sub

    Private Sub TextBox2_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox2.GotFocus
        SeleccionaTexto(TextBox2)
    End Sub

    Private Sub SeleccionaTexto(ByRef textbox As Windows.Forms.TextBox)
        textbox.SelectionStart = 0
        textbox.SelectionLength = Len(textbox.Text)
        textbox.Focus()
    End Sub

    Private Sub AccesoCajero_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        If e.Control = True And e.KeyCode = Keys.E Then
            Me.Tag = True

        End If
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

    End Sub

    Private Sub btnAceptar_Click(sender As Object, e As EventArgs) Handles btnAceptar.Click

        If TextBox2.Text = funcion.Descripcion_Tabla("PASSUSUARIO", "USUARIO", "CODUSUARIO", TextBox1.Tag, EmpCodigo) Then
            UsuCodigo = TextBox1.Tag
            UsuDescripcion = funcion.Descripcion_Tabla("DESUSUARIO", "USUARIO", "CODUSUARIO", TextBox1.Tag, EmpCodigo)
            UsuNivel = funcion.Descripcion_Tabla("NIVELCUENTA", "USUARIO", "CODUSUARIO", TextBox1.Tag, EmpCodigo)
            UsuPassword = TextBox2.Text

            If NumCaja = 0 Then
                If UsuNivel = 1 Then
                    Dim aux As String
                    aux = InputBox("Ingrese el Numero de Caja con el que desea ingresar...", "Caja")
                    NumCaja = funcion.Validar_Tabla("NUMCAJA", "CAJA", "NUMEROCAJA", aux, EmpCodigo)
                    NumeroCaja = funcion.Descripcion_Tabla("NUMEROCAJA", "CAJA", "NUMEROCAJA", aux, EmpCodigo)
                End If
                If NumCaja = 0 Then
                    MsgBox("Numero de Caja no existe", MsgBoxStyle.Information, "Caja")
                Else
                    Acceso = True
                    Close()
                    Exit Sub
                End If
            Else
                Acceso = True
                Close()
                Exit Sub
            End If
        Else
            MsgBox("Password incorrecto!      ", MsgBoxStyle.OkOnly + MsgBoxStyle.Exclamation + MsgBoxStyle.DefaultButton1 + MsgBoxStyle.ApplicationModal + MsgBoxStyle.MsgBoxSetForeground)
        End If

        If TextBox1.Tag <> 0 Then
            TextBox2.SelectionStart = 0
            TextBox2.SelectionLength = Len(TextBox2.Text)
            TextBox2.Focus()
        Else
            TextBox1.SelectionStart = 0
            TextBox1.SelectionLength = Len(TextBox1.Text)
            TextBox1.Focus()
        End If

        If veces = 3 Then
            Acceso = False
            Close()
        End If

        veces = veces + 1

    End Sub

  
    Private Sub btnCancelar_Click(sender As Object, e As EventArgs) Handles btnCancelar.Click
        Acceso = False
        Close()
    End Sub

    Private Sub Label5_Click(sender As Object, e As EventArgs) Handles Label5.Click

    End Sub
End Class
