VERSION 5.00
Begin VB.Form FCambiarNumDoc 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Cambiar Número de Factura"
   ClientHeight    =   2550
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   4680
   Icon            =   "FCambiarNumDoc.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   2550
   ScaleWidth      =   4680
   Begin VB.CommandButton Cmd_salir 
      Caption         =   "Cancelar"
      Height          =   375
      Left            =   2400
      TabIndex        =   5
      Top             =   1320
      Width           =   1935
   End
   Begin VB.CommandButton Cmd_Aceptar 
      Caption         =   "Aceptar"
      Height          =   375
      Left            =   240
      TabIndex        =   4
      Top             =   1320
      Width           =   1935
   End
   Begin VB.TextBox Txt_Num2 
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   1920
      TabIndex        =   3
      Top             =   840
      Width           =   2535
   End
   Begin VB.TextBox Txt_Num1 
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   1920
      TabIndex        =   2
      Top             =   360
      Width           =   2535
   End
   Begin VB.Label Label6 
      Caption         =   "Ej.: Para la Factura: 017-0000614, digitar: 170000614"
      Height          =   255
      Left            =   240
      TabIndex        =   9
      Top             =   1800
      Width           =   3975
   End
   Begin VB.Label Label5 
      Caption         =   "Ej.: Para la Factura: 004-0025357, digitar: 1040025357"
      Height          =   255
      Left            =   240
      TabIndex        =   8
      Top             =   2040
      Width           =   3975
   End
   Begin VB.Label Label4 
      Caption         =   "Ej.: Para la Factura: 010-0135741, digitar: 1100135740"
      Height          =   255
      Left            =   240
      TabIndex        =   7
      Top             =   2280
      Width           =   3975
   End
   Begin VB.Label Label3 
      Alignment       =   2  'Center
      Caption         =   "Nota: Revisar antes y después de un cambio de número."
      ForeColor       =   &H000000C0&
      Height          =   255
      Left            =   120
      TabIndex        =   6
      Top             =   0
      Width           =   4575
   End
   Begin VB.Label Label2 
      Caption         =   "Número Nuevo:"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   240
      TabIndex        =   1
      Top             =   840
      Width           =   1695
   End
   Begin VB.Label Label1 
      Caption         =   "Número Actual:"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   240
      TabIndex        =   0
      Top             =   360
      Width           =   1695
   End
End
Attribute VB_Name = "FCambiarNumDoc"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Cmd_Aceptar_Click()
On Error GoTo trataerror
    Dim cmd As ADODB.Command
    Dim strsql As String
    Dim con As ADODB.Connection
    Dim rs1 As ADODB.Recordset
    Dim rs2 As ADODB.Recordset

     If IsNumeric(Txt_Num1.Text) And Len(Txt_Num1.Text) > 8 And IsNumeric(Txt_Num2) And Len(Txt_Num2.Text) > 8 Then
        '-------------------------------------------------------------
        strsql = "SELECT * FROM OP_SALES (NOLOCK) WHERE DOCTYPEID = '01' AND SITEID = '76' AND NBRDOCUMENT=" & Val(Txt_Num1.Text) & ""
        Set rs1 = New ADODB.Recordset
        rs1.CursorLocation = adUseClient
        
        Set con = New ADODB.Connection
        con.ConnectionString = "FILEDSN=conexionsies"
        con.Open
        rs1.Open strsql, con, adOpenDynamic, adLockBatchOptimistic
        
        If rs1.RecordCount = 0 Or rs1.EOF Then
            MsgBox "Número de Factura Actual No Existe, por favor verificar.", vbInformation, "Nro no Existe"
            Exit Sub
        End If
        '-------------------------------------------------------------
        strsql = "SELECT * FROM OP_SALES (NOLOCK) WHERE DOCTYPEID = '01' AND SITEID = '76' AND NBRDOCUMENT=" & Val(Txt_Num2.Text) & ""
        Set rs2 = New ADODB.Recordset
        rs2.CursorLocation = adUseClient
        
        rs2.Open strsql, con, adOpenDynamic, adLockBatchOptimistic
        
        If rs2.RecordCount > 0 Then
            MsgBox "Número de Factura nuevo Ya Existe, por favor verificar.", vbInformation, "Nro ya Existe"
            Exit Sub
        End If
        '-------------------------------------------------------------
        strsql = "UPDATE OP_SALES SET NBRDOCUMENT=" & Val(Txt_Num2.Text) & " WHERE DOCTYPEID = '01' AND SITEID = '76' AND NBRDOCUMENT=" & Val(Txt_Num1.Text) & ""
        Set cmd = New ADODB.Command
        
        cmd.CommandText = strsql
        cmd.ActiveConnection = "FILEDSN=conexionsies"
        cmd.Execute
        
        MsgBox "Número de factura modificado, por favor verificar.", vbInformation, "Nro Modificado"
     Else
        MsgBox "Número ingresado es incorrecto", vbExclamation, "Número incorrecto"
     End If
     
Exit Sub
    
trataerror:
    If Not cmd Is Nothing Then
        Set cmd = Nothing
    End If
    If Not rs1 Is Nothing Then
        Set rs1 = Nothing
    End If
    If Not rs2 Is Nothing Then
        Set rs2 = Nothing
    End If
    MsgBox "No se pudo cambiar, es posible que ya esté registrado.", vbExclamation, "Error en Actualización"

End Sub

Private Sub cmd_salir_Click()
    Unload Me
End Sub

Public Sub salir_formulario()
    Salir
End Sub

Private Sub Salir()
    Unload Me
End Sub


