VERSION 5.00
Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form FExportarToma 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Exportación de Datos"
   ClientHeight    =   4905
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   5175
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   ScaleHeight     =   4905
   ScaleWidth      =   5175
   Begin MSComDlg.CommonDialog cd1 
      Left            =   120
      Top             =   2040
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin VB.Frame Frame1 
      Caption         =   "Archivos PDT"
      Height          =   2295
      Left            =   120
      TabIndex        =   7
      Top             =   2520
      Width           =   4935
      Begin VB.ListBox lstexportados 
         Height          =   1815
         Left            =   120
         TabIndex        =   8
         Top             =   360
         Width           =   4695
      End
   End
   Begin VB.CommandButton cmdEjecutar 
      Caption         =   "&Ejecutar"
      Height          =   735
      Left            =   2880
      Picture         =   "FExportarToma.frx":0000
      Style           =   1  'Graphical
      TabIndex        =   6
      Top             =   1680
      Width           =   1095
   End
   Begin VB.CommandButton cmdCancelar 
      Caption         =   "&Salir"
      Height          =   735
      Left            =   3960
      Picture         =   "FExportarToma.frx":030A
      Style           =   1  'Graphical
      TabIndex        =   5
      Top             =   1680
      Width           =   1095
   End
   Begin VB.CommandButton cmdBuscar 
      Height          =   375
      Left            =   2280
      MouseIcon       =   "FExportarToma.frx":0614
      MousePointer    =   99  'Custom
      Picture         =   "FExportarToma.frx":0766
      Style           =   1  'Graphical
      TabIndex        =   3
      ToolTipText     =   "Buscar Documento"
      Top             =   2040
      Width           =   375
   End
   Begin VB.TextBox txtArchivo 
      BackColor       =   &H80000004&
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   285
      Left            =   120
      Locked          =   -1  'True
      TabIndex        =   2
      Top             =   2040
      Width           =   1935
   End
   Begin MSComCtl2.Animation Animation1 
      Height          =   615
      Left            =   840
      TabIndex        =   0
      Top             =   360
      Width           =   3045
      _ExtentX        =   5371
      _ExtentY        =   1085
      _Version        =   393216
      FullWidth       =   203
      FullHeight      =   41
   End
   Begin MSComctlLib.ProgressBar Pb1 
      Height          =   255
      Left            =   120
      TabIndex        =   1
      Top             =   1080
      Width           =   4935
      _ExtentX        =   8705
      _ExtentY        =   450
      _Version        =   393216
      Appearance      =   1
      Scrolling       =   1
   End
   Begin VB.Label lblArticulo 
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   120
      TabIndex        =   9
      Top             =   1440
      Width           =   2655
   End
   Begin VB.Label Label1 
      Caption         =   "Archivo Destino"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   120
      TabIndex        =   4
      Top             =   1800
      Width           =   1695
   End
   Begin VB.Image Image2 
      Height          =   480
      Left            =   4080
      Picture         =   "FExportarToma.frx":0C98
      Top             =   360
      Width           =   480
   End
   Begin VB.Image Image1 
      Height          =   660
      Left            =   120
      Picture         =   "FExportarToma.frx":0FA2
      Stretch         =   -1  'True
      Top             =   240
      Width           =   555
   End
End
Attribute VB_Name = "FExportarToma"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private MrsArchivosExport As ADODB.Recordset
Private MstrDirectorio As String
Private Mcon As ADODB.Connection
Private Mcmd As ADODB.Command
Private objTOMAINVT As DB_INV_TOMADEINVENTARIO.C_inventario

Public Sub salir_formulario()
    Unload Me
End Sub

Private Sub cmdBuscar_Click()

    cd1.DialogTitle = "Seleccionar Tabla dbf para Exportar "
    cd1.InitDir = "c:\"
    cd1.Filter = "*.dbf|*.dbf"
    cd1.ShowOpen
    txtArchivo.Text = cd1.FileTitle
    MstrDirectorio = Mid(cd1.FileName, 1, Len(cd1.FileName) - Len(txtArchivo.Text))
    
End Sub

Private Sub cmdCancelar_Click()
    salir_formulario
End Sub
Private Sub cmdEjecutar_Click()

On Error GoTo TrataError

  If GVDATO(txtArchivo.Text) = Empty Then
      MsgBox "Seleccione el Archivo Destino", vbExclamation, "Importación"
      Exit Sub
  End If

  Dim RS_TOMA As ADODB.Recordset
  Dim strSQL As String

 'Se Tiene que crear la Conexión al Momento de Seleccionar el Archivo
  
  If GintRutaPDTActiva = 1 Then
     Mcon.ConnectionString = GstrRutaPDT + "SourceDB=" + MstrDirectorio
     Mcon.Open
  Else
     Mcon.ConnectionString = GstrRutaPDT
     Mcon.Open
  End If

 '*******************************************************************
 
  If MsgBox("Seguro que desea realizar la Exportación", vbYesNo + vbQuestion, "Advertencia") = vbNo Then
     Mcon.Close
     Exit Sub
  Else
  
     ' Hay que Verificar que el Archivo no hay sido Procesado Antes
      
     If Not objTOMAINVT.VerificarArchivosExportados(cd1.FileName).EOF Then
        If MsgBox("Ya se realizó una exportación a este archivo, Desea Continuar ", vbQuestion + vbYesNo, "Advertencia") = vbNo Then
           Mcon.Close
           Exit Sub
        End If
     End If
     
     Screen.MousePointer = 11
     Animation1.Open GstrReportesVta & "Proceso.avi"
     Animation1.Visible = True
     Animation1.Play
     cmdCancelar.Enabled = False
  End If
         
  'Inicia el Proceso de Grabado  **************************************
     Set RS_TOMA = New ADODB.Recordset
         
     If Trim(UCase(Mid(txtArchivo.Text, 1, Len(txtArchivo.Text) - 4))) = "FLINVE" Then
        Set RS_TOMA = objTOMAINVT.ObtenerDatosTomaInventario(1)
        Pb1.Max = RS_TOMA.RecordCount
        Pb1.Value = 0
          While Not RS_TOMA.EOF
            lblArticulo.Caption = "Artículo : " & RS_TOMA!INVTIDSKU
            lblArticulo.Refresh
            strSQL = "insert into FLINVE(lote,sku,CANT) VALUES('0001','" & RS_TOMA!INVTIDSKU & "',0)"
            'strSQL = "insert into TBSKUS(sku,DESC) values('" & Trim(RSTEM(0)) & "','" & Trim(RSTEM(1)) & "')"
            Mcon.Execute strSQL
            RS_TOMA.MoveNext
            Pb1.Value = Pb1.Value + 1
          Wend
        objTOMAINVT.GrabarArchivoExportado cd1.FileName
     Else
        If Trim(UCase(Mid(txtArchivo.Text, 1, Len(txtArchivo.Text) - 4))) = "TBBARR" Then
           Set RS_TOMA = objTOMAINVT.ObtenerDatosTomaInventario(2)
           Pb1.Max = RS_TOMA.RecordCount
           Pb1.Value = 0
             While Not RS_TOMA.EOF
              lblArticulo.Caption = "Artículo : " & RS_TOMA!INVTIDBARR
              lblArticulo.Refresh
              strSQL = "insert into TBBARR(BARR,sku) VALUES('" & RS_TOMA!INVTIDBARR & "','" & RS_TOMA!INVTIDSKU & "')"
              Mcon.Execute strSQL
              RS_TOMA.MoveNext
              Pb1.Value = Pb1.Value + 1
             Wend
                      
           objTOMAINVT.GrabarArchivoExportado cd1.FileName
        Else
           If Trim(UCase(Mid(txtArchivo.Text, 1, Len(txtArchivo.Text) - 4))) = "TBSKUS" Then
              Set RS_TOMA = objTOMAINVT.ObtenerDatosTomaInventario(3)
              Pb1.Max = RS_TOMA.RecordCount
              Pb1.Value = 0
                While Not RS_TOMA.EOF
                  lblArticulo.Caption = "Artículo : " & RS_TOMA!INVTIDSKU
                  lblArticulo.Refresh
                  strSQL = "insert into TBSKUS(sku,DESC) VALUES('" & RS_TOMA!INVTIDSKU & "','" & RS_TOMA!DESCR & "')"
                  Mcon.Execute strSQL
                  RS_TOMA.MoveNext
                  Pb1.Value = Pb1.Value + 1
                Wend
                            
               objTOMAINVT.GrabarArchivoExportado cd1.FileName
           End If
        End If
     End If
      
     Set RS_TOMA = Nothing
      
     Animation1.AutoPlay = False
     Animation1.Stop
     Animation1.Visible = False
    
     cmdCancelar.Enabled = True
     Pb1.Value = 0
     lblArticulo.Caption = Empty
     Screen.MousePointer = 0
     Me.Hide
     MsgBox "Exportación realizada con éxito, " & CStr(Pb1.Max) & " registros exportados ", vbInformation, "Importación"
     Unload Me
Exit Sub

TrataError:
    Animation1.AutoPlay = False
    Animation1.Stop
    Animation1.Visible = False
    
    Mcon.Close
    cmdCancelar.Enabled = False
    Pb1.Value = 0
    lblArticulo.Caption = Empty
    
    Screen.MousePointer = 0
    MsgBox MensajedeError(Err.Number, Err.Description), vbDefaultButton1 + vbCritical, "Error"
    
End Sub

Private Sub Form_Load()
  
    Set Mcon = New ADODB.Connection
    Set objTOMAINVT = New DB_INV_TOMADEINVENTARIO.C_inventario
   
    'Mcon.ConnectionString = "FILEDSN=TOMAINVT"
    'Mcon.Open
     
    'Set Mcmd = New ADODB.Command
    'Mcmd.ActiveConnection = Mcon
        
    'Hay que Cargar en el lstimportados
     
     Set MrsArchivosExport = objTOMAINVT.ObtenerArchivosExportados
      
     If Not MrsArchivosExport.EOF Then
        MrsArchivosExport.MoveFirst
        Do While Not MrsArchivosExport.EOF
           lstexportados.AddItem Trim(MrsArchivosExport!filenamepdt)
           MrsArchivosExport.MoveNext
        Loop
     End If
            
     '----------------------------------
        
     Me.Top = 1200
     Me.Left = (Screen.Width - Me.Width) / 2
    
     KeyPreview = True

End Sub

Private Sub Form_Unload(Cancel As Integer)
     
     Set Mcon = Nothing
     Set MrsArchivosExport = Nothing
     
End Sub

