Public Class Anular
    Inherits System.Windows.Forms.Form
    Private sentFuncion As New funcion.Funcion
    Private sentVentas As New sentVentas.Ventas
    Private codSucursal As Long

    Private dtDetalle As DataTable
    Private dtCobranza As DataTable

    Private color1, color2 As String

    Private sucursal As Long
    Private moneda As Long

#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 TextBox4 As System.Windows.Forms.TextBox
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
    Friend WithEvents Label20 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents cmdAnular As System.Windows.Forms.Button
    Friend WithEvents TopLeftColor As LaMarvin.Windows.Forms.ColorPicker
    Friend WithEvents BottomRightColor As LaMarvin.Windows.Forms.ColorPicker
    Friend WithEvents TxtMoneda4 As TxtMoneda.TxtMoneda
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Me.TextBox4 = New System.Windows.Forms.TextBox
        Me.Label2 = New System.Windows.Forms.Label
        Me.TextBox3 = New System.Windows.Forms.TextBox
        Me.Label20 = New System.Windows.Forms.Label
        Me.Label3 = New System.Windows.Forms.Label
        Me.cmdAnular = New System.Windows.Forms.Button
        Me.Label1 = New System.Windows.Forms.Label
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.Label4 = New System.Windows.Forms.Label
        Me.Label5 = New System.Windows.Forms.Label
        Me.TopLeftColor = New LaMarvin.Windows.Forms.ColorPicker
        Me.BottomRightColor = New LaMarvin.Windows.Forms.ColorPicker
        Me.TxtMoneda4 = New TxtMoneda.TxtMoneda(Me.components)
        Me.SuspendLayout()
        '
        'TextBox4
        '
        Me.TextBox4.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.TextBox4.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper
        Me.TextBox4.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.TextBox4.Location = New System.Drawing.Point(152, 40)
        Me.TextBox4.MaxLength = 20
        Me.TextBox4.Name = "TextBox4"
        Me.TextBox4.Size = New System.Drawing.Size(192, 26)
        Me.TextBox4.TabIndex = 1
        Me.TextBox4.Text = "TEXTBOX4"
        '
        'Label2
        '
        Me.Label2.BackColor = System.Drawing.Color.Transparent
        Me.Label2.Location = New System.Drawing.Point(24, 16)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(120, 23)
        Me.Label2.TabIndex = 38
        Me.Label2.Text = "Comprobante"
        Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'TextBox3
        '
        Me.TextBox3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.TextBox3.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper
        Me.TextBox3.Location = New System.Drawing.Point(152, 16)
        Me.TextBox3.Name = "TextBox3"
        Me.TextBox3.Size = New System.Drawing.Size(80, 20)
        Me.TextBox3.TabIndex = 0
        Me.TextBox3.Text = "TEXTBOX3"
        '
        'Label20
        '
        Me.Label20.BackColor = System.Drawing.Color.Transparent
        Me.Label20.Location = New System.Drawing.Point(248, 16)
        Me.Label20.Name = "Label20"
        Me.Label20.Size = New System.Drawing.Size(376, 23)
        Me.Label20.TabIndex = 41
        Me.Label20.Text = "Label20"
        Me.Label20.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'Label3
        '
        Me.Label3.BackColor = System.Drawing.Color.Transparent
        Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label3.Location = New System.Drawing.Point(24, 40)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(120, 23)
        Me.Label3.TabIndex = 40
        Me.Label3.Text = "Número"
        Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'cmdAnular
        '
        Me.cmdAnular.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.cmdAnular.BackColor = System.Drawing.Color.Transparent
        Me.cmdAnular.FlatStyle = System.Windows.Forms.FlatStyle.Popup
        Me.cmdAnular.Location = New System.Drawing.Point(18, 168)
        Me.cmdAnular.Name = "cmdAnular"
        Me.cmdAnular.Size = New System.Drawing.Size(580, 32)
        Me.cmdAnular.TabIndex = 2
        Me.cmdAnular.Text = "&Anular"
        '
        'Label1
        '
        Me.Label1.BackColor = System.Drawing.Color.Transparent
        Me.Label1.Location = New System.Drawing.Point(24, 72)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(120, 23)
        Me.Label1.TabIndex = 408
        Me.Label1.Text = "Cliente"
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'TextBox1
        '
        Me.TextBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.TextBox1.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper
        Me.TextBox1.Location = New System.Drawing.Point(152, 72)
        Me.TextBox1.MaxLength = 10
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.ReadOnly = True
        Me.TextBox1.Size = New System.Drawing.Size(192, 20)
        Me.TextBox1.TabIndex = 409
        Me.TextBox1.Text = "TEXTBOX1"
        '
        'Label4
        '
        Me.Label4.BackColor = System.Drawing.Color.Transparent
        Me.Label4.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label4.Location = New System.Drawing.Point(24, 104)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(568, 23)
        Me.Label4.TabIndex = 410
        Me.Label4.Text = "Label4"
        Me.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'Label5
        '
        Me.Label5.BackColor = System.Drawing.Color.Transparent
        Me.Label5.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label5.Location = New System.Drawing.Point(24, 136)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(120, 23)
        Me.Label5.TabIndex = 411
        Me.Label5.Text = "Total Factura"
        Me.Label5.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'TopLeftColor
        '
        Me.TopLeftColor.Color = System.Drawing.SystemColors.Control
        Me.TopLeftColor.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold)
        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 = 4
        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.SystemColors.Control
        Me.BottomRightColor.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold)
        Me.BottomRightColor.Location = New System.Drawing.Point(605, 195)
        Me.BottomRightColor.Name = "BottomRightColor"
        Me.BottomRightColor.Size = New System.Drawing.Size(12, 12)
        Me.BottomRightColor.TabIndex = 3
        Me.BottomRightColor.Text = "ColorPicker1"
        Me.BottomRightColor.TextDisplayed = False
        '
        'TxtMoneda4
        '
        Me.TxtMoneda4.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.TxtMoneda4.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.TxtMoneda4.Location = New System.Drawing.Point(152, 136)
        Me.TxtMoneda4.MaxLength = 9
        Me.TxtMoneda4.Name = "TxtMoneda4"
        Me.TxtMoneda4.ReadOnly = True
        Me.TxtMoneda4.Size = New System.Drawing.Size(192, 26)
        Me.TxtMoneda4.TabIndex = 412
        Me.TxtMoneda4.Text = "TxtMoneda4"
        Me.TxtMoneda4.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        Me.TxtMoneda4.TxtMonedaBase = "0"
        Me.TxtMoneda4.TxtMonedaDecimales = Nothing
        '
        'Anular
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(616, 206)
        Me.Controls.Add(Me.TxtMoneda4)
        Me.Controls.Add(Me.cmdAnular)
        Me.Controls.Add(Me.BottomRightColor)
        Me.Controls.Add(Me.TopLeftColor)
        Me.Controls.Add(Me.Label5)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.TextBox1)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.TextBox4)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.TextBox3)
        Me.Controls.Add(Me.Label20)
        Me.Controls.Add(Me.Label3)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow
        Me.KeyPreview = True
        Me.Name = "Anular"
        Me.ShowInTaskbar = False
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Anular"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub ColorChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TopLeftColor.ColorChanged, BottomRightColor.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 Caja_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
        Me.Refresh()
    End Sub

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

        Texto()
        Limpiar()
        Configuraciones()

        TextBox3.Focus()
    End Sub

    Private Sub Texto()
        dtDetalle = New DataTable("DETALLE")
        dtCobranza = New DataTable("COBRANZA")

        Label3.Font = New Font("Microsoft Sans Serif", 12, FontStyle.Bold)
        TextBox4.Font = New Font("Microsoft Sans Serif", 12, FontStyle.Bold)
        TextBox4.ForeColor = Color.IndianRed

        Label4.Font = New Font("Microsoft Sans Serif", 12, FontStyle.Bold)
        Label5.Font = New Font("Microsoft Sans Serif", 12, FontStyle.Bold)
        TxtMoneda4.Font = New Font("Microsoft Sans Serif", 12, FontStyle.Bold)

        AddHandler Me.KeyPress, AddressOf Me.Salir
    End Sub

    Private Sub Limpiar()
        TextBox3.Tag = 0
        TextBox3.Text = ""
        Label20.Text = ""

        TextBox4.Text = ""

        TextBox1.Tag = 0
        TextBox1.Text = ""
        Label4.Text = ""

        TxtMoneda4.Text = ""
        TxtMoneda4.TxtMonedaDecimales = CANDECIMALESIMPORTE

        codSucursal = 0
    End Sub

    Public 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 btAceptar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAnular.Click
        Anular()
    End Sub

    Private Sub Anular()
        If TextBox3.Text = "" Then
            Mensaje("Ingrese un Comprobante")
            TextBox3.Focus()
            Exit Sub
        End If

        If TextBox4.Text = "" Then
            Mensaje("Ingrese un Número")
            TextBox4.Focus()
            Exit Sub
        End If

        If sentFuncion.Validar_Tabla("ESTADO", "VENTAS", "CODVENTA", Val(TextBox4.Tag), EmpCodigo) = 1 Then
            Mensaje("Esta factura ya está anulada")
            TextBox3.Focus()
            Exit Sub
        End If

        If sentFuncion.Maximo("CODVENTA", "FACTURAAFECTADA WHERE CODVENTA = " & Val(TextBox4.Tag) & " ") > 0 Then
            Mensaje("Esta venta no se puede anular porque ya tiene cobros aplicados")
            TextBox3.Focus()
            Exit Sub
        End If

        If sentFuncion.Maximo("CODVENTA", "MOVIASIENTOMOVI WHERE CODVENTA = " & Val(TextBox4.Tag) & " ") > 0 Then
            Mensaje("Esta venta no se puede anular porque ya fue generado el asiento correspondiente")
            TextBox3.Focus()
            Exit Sub
        End If

        'If sentFuncion.Maximo("CODVENTA", "CAJAFACTURASCOBRADAS WHERE CODVENTA = " & Val(TextBox4.Tag) & " ") > 0 Then
        '    Mensaje("Esta venta no se puede anular porque ya fue ingresada en Caja")
        '    TextBox3.Focus()
        '    Exit Sub
        'End If

        If sentFuncion.Maximo("CODVENTA", "VENTAS WHERE CODVENTA = " & Val(TextBox4.Tag) & " And CODCONVENTAS Is NOT NULL ") > 0 Then
            Mensaje("Esta venta no se puede anular porque ya fue generado en el Libro de Ventas")
            TextBox3.Focus()
            Exit Sub
        End If

        Sucursal = funcion.Validar_Tabla("CODSUCURSAL", "VENTAS", "CODVENTA", TextBox4.Tag, EmpCodigo)

        If MsgBox("¿Está seguro de anular este comprobante?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Anular") = MsgBoxResult.Yes Then
            If sentVentas.anular(TextBox4.Tag, sucursal, dtDetalle, dtCobranza, TextBox3.Tag, _
            EmpCodigo, TextBox4.Text, Moneda, "", "", "", Label4.Text, TxtMoneda4.TxtMonedaBase, UsuCodigo) = True Then
                Mensaje("Comprobante anulado correctamente")
                Limpiar()
            Else
                Mensaje("Comprobante no ha sido anulado")
            End If
        End If

        TextBox3.Focus()
    End Sub

    Public Sub CargarDetalle()
        dtDetalle = sentVentas.DsRecorrerDetalle(Val(TextBox4.Tag))
    End Sub

    Public Sub CargaFacturaCobrar()
        dtCobranza = sentVentas.DsRecorrerCuotas(Val(TextBox4.Tag))
    End Sub

    'KeyPres
    Private Sub TextBox3_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox3.KeyPress
        Dim KeyAscii As Short = Asc(e.KeyChar)

        If KeyAscii = 13 Then
            TextBox4.Focus()
        End If

        If KeyAscii = 42 Then
            Buscar_Tabla("TIPOCOMPROBANTE", "DESCOMPROBANTE", "CODCOMPROBANTE", "NUMTIPOCOMPRO", "Buscar Tipo de Comprobante", "", "", "")

            If campo_clave_tablas = "0" Then
                TextBox3.Tag = 0
                TextBox3.Text = ""
                Label20.Text = ""
            Else
                TextBox3.Tag = campo_clave_tablas
                TextBox3.Text = Campo_numero_tablas
                Label20.Text = Campo_descripcion_tablas
            End If

            e.Handled = True
        End If

        If KeyAscii = 0 Then
            e.Handled = True
        End If
    End Sub

    Private Sub TextBox4_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox4.KeyPress
        Dim KeyAscii As Short = Asc(e.KeyChar)

        If KeyAscii = 13 Then
            cmdAnular.Focus()
        End If

        If KeyAscii = 42 Then
            Buscar_Tabla("VENTAS V INNER JOIN TIPOCOMPROBANTE T ON V.CODCOMPROBANTE = T.CODCOMPROBANTE " & _
            "INNER JOIN CLIENTES CL ON V.CODCLIENTE = CL.CODCLIENTE", _
            "RTRIM(T.NUMTIPOCOMPRO) + ' ' + RTRIM(V.NUMVENTA) + ' - ' + LTRIM(RTRIM(CL.APELLIDO) + ' ' + RTRIM(CL.NOMBRE))", _
            "V.CODVENTA", "RTRIM(V.NUMVENTATIMBRADO)", "Buscar Venta", _
            "V.ESTADO = 0 AND V.CODCOMPROBANTE = " & TextBox3.Tag & " AND V.CODEMPRESA =", "", "", "CONVERT(VARCHAR(10), V.FECHAVENTA, 103)", _
            "Fecha")

            If campo_clave_tablas = "0" Then
                TextBox4.Text = ""
            Else
                TextBox4.Text = funcion.Descripcion_Tabla("NUMVENTA", "VENTAS", "CODVENTA", Campo_clave_tablas, EmpCodigo)
            End If
            e.Handled = True
        End If

        If KeyAscii = 0 Then
            e.Handled = True
        End If
    End Sub

    'KeyDown
    Private Sub TextBox3_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox3.KeyDown
        Select Case e.KeyCode
            Case Keys.Up
                TextBox4.Focus()
            Case Keys.Down
                TextBox4.Focus()
        End Select
    End Sub

    Private Sub TextBox4_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox4.KeyDown
        Select Case e.KeyCode
            Case Keys.Up
                TextBox3.Focus()
            Case Keys.Down
                TextBox3.Focus()
        End Select
    End Sub

    'Validated
    Private Sub TextBox3_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox3.Validated
        Mensaje(sentFuncion.validacion_codigo_tabla_dependiente(cmdAnular, TextBox3, Label20, "CODCOMPROBANTE", "TIPOCOMPROBANTE", _
        "DESCOMPROBANTE", "NUMTIPOCOMPRO", EmpCodigo))
    End Sub

    Private Sub TextBox4_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox4.Validated
        Dim a As New Label
        Mensaje(sentFuncion.validacion_codigo_tabla_dependiente(cmdAnular, TextBox4, a, "CODVENTA", _
        "VENTAS", "NUMVENTA", "ESTADO = 0 AND NUMVENTA", EmpCodigo))

        If Not TextBox4.Text = "" Then
            codSucursal = sentFuncion.Validar_Tabla("CODSUCURSAL", "VENTAS", "CODVENTA", Val(TextBox4.Tag), EmpCodigo)

            TextBox1.Tag = sentFuncion.Validar_Tabla("CODCLIENTE", "VENTAS", "CODVENTA", Val(TextBox4.Tag), EmpCodigo)
            TextBox1.Text = sentFuncion.Descripcion_Tabla("NUMCLIENTE", "CLIENTES", "CODCLIENTE", Val(TextBox1.Tag), EmpCodigo)
            Label4.Text = sentFuncion.Descripcion_Tabla("LTRIM(RTRIM(APELLIDO)+' '+RTRIM(NOMBRE))", "CLIENTES", "CODCLIENTE", Val(TextBox1.Tag), EmpCodigo)

            TxtMoneda4.Text = sentFuncion.Descripcion_Tabla("''), " & _
            "(TOTALEXENTA + TOTALGRAVADA + TOTALIVA - TOTALDESCUENTO", "VENTAS", "CODVENTA", Val(TextBox4.Tag), EmpCodigo)

            Moneda = funcion.Validar_Tabla("CODMONEDA", "VENTAS", "CODVENTA", TextBox4.Tag, EmpCodigo)
            If funcion.Descripcion_Tabla("DECIMALES", "MONEDA", "CODMONEDA", moneda, EmpCodigo) = 0 Then
                TxtMoneda4.TxtMonedaDecimales = 0
            Else
                TxtMoneda4.TxtMonedaDecimales = CANDECIMALESIMPORTE
            End If

            TxtMoneda4.TextoSQL(TxtMoneda4.Text)

            CargarDetalle()
            CargaFacturaCobrar()
        Else
            Limpiar()
        End If
    End Sub
End Class