Imports System.Data.SqlClient
Public Class AnularDevolucionVenta
    Inherits System.Windows.Forms.Form

    Private sentDevolucion As New SentDevolucion.Devolucion
    Private SentCobranzas As New SentCobranzas.Cobranzas

    Private codSucursal As Long
    Private dtDetalle As New DataTable("DETALLE")
    Private color1, color2 As String
    Friend WithEvents cmdAnular As System.Windows.Forms.Button
    Private dr As SqlDataReader
#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 WinPopup1 As WinPopup.WinPopup
    Friend WithEvents TxtMoneda4 As TxtMoneda.TxtMoneda
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox4 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
    Friend WithEvents TopLeftColor As LaMarvin.Windows.Forms.ColorPicker
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label20 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents BottomRightColor As LaMarvin.Windows.Forms.ColorPicker
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(AnularDevolucionVenta))
        Me.WinPopup1 = New WinPopup.WinPopup()
        Me.TxtMoneda4 = New TxtMoneda.TxtMoneda(Me.components)
        Me.TextBox1 = New System.Windows.Forms.TextBox()
        Me.TextBox4 = New System.Windows.Forms.TextBox()
        Me.TextBox3 = New System.Windows.Forms.TextBox()
        Me.TopLeftColor = New LaMarvin.Windows.Forms.ColorPicker()
        Me.Label5 = New System.Windows.Forms.Label()
        Me.Label4 = New System.Windows.Forms.Label()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.Label20 = New System.Windows.Forms.Label()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.BottomRightColor = New LaMarvin.Windows.Forms.ColorPicker()
        Me.cmdAnular = New System.Windows.Forms.Button()
        Me.SuspendLayout()
        '
        'WinPopup1
        '
        Me.WinPopup1.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.WinPopup1.BackColor = System.Drawing.SystemColors.ActiveCaption
        Me.WinPopup1.ImeMode = System.Windows.Forms.ImeMode.NoControl
        Me.WinPopup1.Location = New System.Drawing.Point(272, 61)
        Me.WinPopup1.Name = "WinPopup1"
        Me.WinPopup1.Size = New System.Drawing.Size(230, 100)
        Me.WinPopup1.TabIndex = 433
        Me.WinPopup1.Visible = False
        Me.WinPopup1.WinPopupAutoHide = False
        Me.WinPopup1.WinPopupAutoShow = False
        Me.WinPopup1.WinPopupGosth = False
        Me.WinPopup1.WinPopupGosthSpeed = 25
        '
        'TxtMoneda4
        '
        Me.TxtMoneda4.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.TxtMoneda4.Location = New System.Drawing.Point(112, 96)
        Me.TxtMoneda4.MaxLength = 9
        Me.TxtMoneda4.Name = "TxtMoneda4"
        Me.TxtMoneda4.ReadOnly = True
        Me.TxtMoneda4.Size = New System.Drawing.Size(80, 20)
        Me.TxtMoneda4.TabIndex = 438
        Me.TxtMoneda4.Text = "TxtMoneda4"
        Me.TxtMoneda4.TxtMonedaBase = "0"
        Me.TxtMoneda4.TxtMonedaDecimales = Nothing
        '
        'TextBox1
        '
        Me.TextBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.TextBox1.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper
        Me.TextBox1.Location = New System.Drawing.Point(112, 72)
        Me.TextBox1.MaxLength = 10
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.ReadOnly = True
        Me.TextBox1.Size = New System.Drawing.Size(80, 20)
        Me.TextBox1.TabIndex = 435
        Me.TextBox1.Text = "TEXTBOX1"
        '
        'TextBox4
        '
        Me.TextBox4.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.TextBox4.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper
        Me.TextBox4.Location = New System.Drawing.Point(112, 48)
        Me.TextBox4.MaxLength = 25
        Me.TextBox4.Name = "TextBox4"
        Me.TextBox4.Size = New System.Drawing.Size(160, 20)
        Me.TextBox4.TabIndex = 427
        Me.TextBox4.Text = "TEXTBOX4"
        '
        'TextBox3
        '
        Me.TextBox3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.TextBox3.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper
        Me.TextBox3.Location = New System.Drawing.Point(112, 24)
        Me.TextBox3.Name = "TextBox3"
        Me.TextBox3.Size = New System.Drawing.Size(80, 20)
        Me.TextBox3.TabIndex = 426
        Me.TextBox3.Text = "TEXTBOX3"
        '
        'TopLeftColor
        '
        Me.TopLeftColor.Color = System.Drawing.Color.SteelBlue
        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 = 429
        Me.TopLeftColor.Text = "ColorPicker1"
        Me.TopLeftColor.TextDisplayed = False
        '
        'Label5
        '
        Me.Label5.BackColor = System.Drawing.Color.Transparent
        Me.Label5.Location = New System.Drawing.Point(-16, 92)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(120, 23)
        Me.Label5.TabIndex = 437
        Me.Label5.Text = "Total Devolución"
        Me.Label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'Label4
        '
        Me.Label4.BackColor = System.Drawing.Color.Transparent
        Me.Label4.Location = New System.Drawing.Point(195, 69)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(432, 23)
        Me.Label4.TabIndex = 436
        Me.Label4.Text = "Label4"
        Me.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'Label1
        '
        Me.Label1.BackColor = System.Drawing.Color.Transparent
        Me.Label1.Location = New System.Drawing.Point(0, 68)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(104, 23)
        Me.Label1.TabIndex = 434
        Me.Label1.Text = "Cliente"
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'Label2
        '
        Me.Label2.BackColor = System.Drawing.Color.Transparent
        Me.Label2.Location = New System.Drawing.Point(-24, 21)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(128, 23)
        Me.Label2.TabIndex = 430
        Me.Label2.Text = "Tipo comprobante"
        Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'Label20
        '
        Me.Label20.BackColor = System.Drawing.Color.Transparent
        Me.Label20.Location = New System.Drawing.Point(195, 22)
        Me.Label20.Name = "Label20"
        Me.Label20.Size = New System.Drawing.Size(432, 23)
        Me.Label20.TabIndex = 432
        Me.Label20.Text = "Label20"
        Me.Label20.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'Label3
        '
        Me.Label3.BackColor = System.Drawing.Color.Transparent
        Me.Label3.Location = New System.Drawing.Point(24, 45)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(80, 23)
        Me.Label3.TabIndex = 431
        Me.Label3.Text = "Número"
        Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        '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.PapayaWhip
        Me.BottomRightColor.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold)
        Me.BottomRightColor.Location = New System.Drawing.Point(508, 149)
        Me.BottomRightColor.Name = "BottomRightColor"
        Me.BottomRightColor.Size = New System.Drawing.Size(12, 12)
        Me.BottomRightColor.TabIndex = 439
        Me.BottomRightColor.Text = "ColorPicker1"
        Me.BottomRightColor.TextDisplayed = False
        '
        '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.Image = CType(resources.GetObject("cmdAnular.Image"), System.Drawing.Image)
        Me.cmdAnular.Location = New System.Drawing.Point(373, 36)
        Me.cmdAnular.Name = "cmdAnular"
        Me.cmdAnular.Size = New System.Drawing.Size(135, 78)
        Me.cmdAnular.TabIndex = 440
        Me.cmdAnular.Text = "&Anular"
        Me.cmdAnular.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText
        Me.cmdAnular.UseVisualStyleBackColor = False
        '
        'AnularDevolucionVenta
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(520, 162)
        Me.Controls.Add(Me.WinPopup1)
        Me.Controls.Add(Me.cmdAnular)
        Me.Controls.Add(Me.BottomRightColor)
        Me.Controls.Add(Me.TxtMoneda4)
        Me.Controls.Add(Me.TextBox1)
        Me.Controls.Add(Me.TextBox4)
        Me.Controls.Add(Me.TextBox3)
        Me.Controls.Add(Me.TopLeftColor)
        Me.Controls.Add(Me.Label5)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label20)
        Me.Controls.Add(Me.Label3)
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.KeyPreview = True
        Me.Name = "AnularDevolucionVenta"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Anular Devolución  por Venta"
        Me.ResumeLayout(False)
        Me.PerformLayout()

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

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

        Limpiar()
        Configuraciones()
        TextBox3.Focus()

        AddHandler Me.KeyPress, AddressOf 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

    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 cmdAnular_Click(sender As Object, e As 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 funcion.Validar_Tabla("ESTADO", "DEVOLUCION", "CODDEVOLUCION", Val(TextBox4.Tag), EmpCodigo) = 1 Then
            Mensaje("Esta factura ya fue anulada")
            TextBox3.Focus()
            Exit Sub
        End If

        'If funcion.Maximo("CODCOBRANZA", "COBRANZAS WHERE CODCOMPROBANTE = " & Val(TextBox3.Tag) & " " & _
        '       "AND NUMCOMPROBANTE = '" & TextBox4.Text & "' ") > 0 Then
        '    Mensaje("Esta Devolución no se puede anular porque ya fue aplicada.")
        '    Exit Sub
        'End If

        Dim frmMen As New frmMensaje
        frmMen.lblMensaje.Text = "Desea anular el Comprobante"
        frmMen.ShowDialog()
        If frmMen.DialogResult = DialogResult.Yes Then
            If sentDevolucion.anular(TextBox4.Tag, codSucursal, dtDetalle, _
               TextBox3.Tag, EmpCodigo, TextBox4.Text, funcion.Validar_Tabla("CODMONEDA", "DEVOLUCION", "NUMDEVOLUCION", TextBox4.Text, EmpCodigo), _
               funcion.Descripcion_Tabla("'') AS NADA, ISNULL(COTIZACION1, 0", "DEVOLUCION", "NUMDEVOLUCION", TextBox4.Text, EmpCodigo), _
               funcion.Descripcion_Tabla("'') AS NADA, ISNULL(COTIZACION2, 0", "DEVOLUCION", "NUMDEVOLUCION", TextBox4.Text, EmpCodigo), _
               funcion.Descripcion_Tabla("'') AS NADA, CONVERT(VARCHAR(10),FECHADEVOLUCION,103", "DEVOLUCION", "NUMDEVOLUCION", TextBox4.Text, EmpCodigo), _
               TxtMoneda4.TxtMonedaBase, UsuCodigo) = True Then

                Mensaje("Comprobante anulado correctamente")
                Limpiar()
            Else
                Mensaje("El registro no se ha anulado")
            End If
        End If
        frmMen.Dispose()
        TextBox3.Focus()

    End Sub

    Public Sub CargarDetalle()
        dtDetalle = sentDevolucion.DsRecorrerDescripcionA(Val(TextBox4.Tag))
    End Sub

    'KeyPress
    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 Comprobante")

            If Not Campo_clave_tablas = "0" Then
                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("DEVOLUCION D INNER JOIN SUCURSAL S ON D.CODSUCURSAL = S.CODSUCURSAL", "CONVERT(VARCHAR(10),D.FECHADEVOLUCION,103)", "D.CODDEVOLUCION", "D.NUMDEVOLUCION", "Buscar Comprobante de Devolución", _
                         "D.ESTADO = 0 AND D.CODCOMPROBANTE = " & TextBox3.Tag & " AND D.CODEMPRESA = ", "", "", "S.DESSUCURSAL", "SUCURSAL")
            If Not Campo_clave_tablas = "0" Then
                TextBox4.Tag = Val(Campo_clave_tablas)
                TextBox4.Text = Campo_numero_tablas
            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(funcion.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(funcion.validacion_codigo_tabla_dependiente(cmdAnular, TextBox4, a, "CODDEVOLUCION", _
        "DEVOLUCION", "NUMDEVOLUCION", "ESTADO IN(0, 1) AND NUMDEVOLUCION", EmpCodigo))

        If Not TextBox4.Text = "" Then

            TextBox4.Tag = funcion.Validar_Tabla("CODDEVOLUCION", "DEVOLUCION", "NUMDEVOLUCION", TextBox4.Text, EmpCodigo)

            codSucursal = funcion.Validar_Tabla("CODSUCURSAL", "DEVOLUCION", "CODDEVOLUCION", Val(TextBox4.Tag), EmpCodigo)

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

            TxtMoneda4.Text = funcion.Validar_Tabla("TOTALDEVOLUCION", "DEVOLUCION", "CODDEVOLUCION", Val(TextBox4.Tag), EmpCodigo)
            TxtMoneda4.TextoSQL(TxtMoneda4.Text)

            CargarDetalle()
        Else
            Limpiar()
        End If
    End Sub

End Class
