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 = "{00025600-0000-0000-C000-000000000046}#5.2#0"; "crystl32.ocx"
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form FImportarToma 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Importacion de Toma de Inventario"
   ClientHeight    =   5985
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   5160
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   5985
   ScaleWidth      =   5160
   Begin Crystal.CrystalReport CrystalReport1 
      Left            =   4200
      Top             =   840
      _ExtentX        =   741
      _ExtentY        =   741
      _Version        =   348160
      PrintFileLinesPerPage=   60
   End
   Begin VB.Frame Frame1 
      Caption         =   "Archivos Importados"
      Height          =   3255
      Left            =   120
      TabIndex        =   8
      Top             =   2640
      Width           =   4935
      Begin Crystal.CrystalReport CRPDT 
         Left            =   2160
         Top             =   2760
         _ExtentX        =   741
         _ExtentY        =   741
         _Version        =   348160
         WindowState     =   2
         PrintFileLinesPerPage=   60
         WindowShowSearchBtn=   -1  'True
         WindowShowPrintSetupBtn=   -1  'True
      End
      Begin VB.CommandButton cmdimprimir 
         Caption         =   "Imprimir"
         Height          =   735
         Left            =   3480
         Picture         =   "FImportarToma.frx":0000
         Style           =   1  'Graphical
         TabIndex        =   10
         Top             =   2400
         Width           =   1335
      End
      Begin VB.ListBox lstimportados 
         Height          =   1815
         Left            =   120
         TabIndex        =   9
         Top             =   480
         Width           =   4695
      End
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Command1"
      Height          =   255
      Left            =   0
      TabIndex        =   7
      Top             =   480
      Visible         =   0   'False
      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        =   5
      Top             =   1920
      Width           =   1935
   End
   Begin VB.CommandButton cmdBuscar 
      Height          =   375
      Left            =   2280
      MouseIcon       =   "FImportarToma.frx":030A
      MousePointer    =   99  'Custom
      Picture         =   "FImportarToma.frx":045C
      Style           =   1  'Graphical
      TabIndex        =   4
      ToolTipText     =   "Buscar Documento"
      Top             =   1800
      Width           =   375
   End
   Begin MSComDlg.CommonDialog cd1 
      Left            =   0
      Top             =   0
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin VB.CommandButton cmdCancelar 
      Caption         =   "&Salir"
      Height          =   735
      Left            =   3960
      Picture         =   "FImportarToma.frx":098E
      Style           =   1  'Graphical
      TabIndex        =   1
      Top             =   1680
      Width           =   1095
   End
   Begin VB.CommandButton cmdEjecutar 
      Caption         =   "&Ejecutar"
      Height          =   735
      Left            =   2880
      Picture         =   "FImportarToma.frx":0C98
      Style           =   1  'Graphical
      TabIndex        =   0
      Top             =   1680
      Width           =   1095
   End
   Begin MSComCtl2.Animation Animation1 
      Height          =   615
      Left            =   1080
      TabIndex        =   2
      Top             =   240
      Width           =   3045
      _ExtentX        =   5371
      _ExtentY        =   1085
      _Version        =   393216
      FullWidth       =   203
      FullHeight      =   41
   End
   Begin MSComctlLib.ProgressBar Pb1 
      Height          =   255
      Left            =   120
      TabIndex        =   11
      Top             =   1320
      Width           =   4815
      _ExtentX        =   8493
      _ExtentY        =   450
      _Version        =   393216
      Appearance      =   1
      Scrolling       =   1
   End
   Begin VB.Line Line1 
      X1              =   120
      X2              =   5040
      Y1              =   2520
      Y2              =   2520
   End
   Begin VB.Label Label1 
      Caption         =   "Archivo a Importar"
      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        =   6
      Top             =   1680
      Width           =   1695
   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            =   240
      TabIndex        =   3
      Top             =   960
      Width           =   1575
   End
   Begin VB.Image Image2 
      Height          =   480
      Left            =   360
      Picture         =   "FImportarToma.frx":0FA2
      Top             =   360
      Width           =   480
   End
   Begin VB.Image Image1 
      Height          =   660
      Left            =   4440
      Picture         =   "FImportarToma.frx":12AC
      Stretch         =   -1  'True
      Top             =   240
      Width           =   555
   End
End
Attribute VB_Name = "FImportarToma"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private MrsArchivosImport 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

Private Sub cmdBuscar_Click()
    
    cd1.DialogTitle = "Seleccionar Tabla dbf a Importar "
    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()
    Unload Me
End Sub

Private Sub cmdEjecutar_Click()
On Error GoTo TrataError

  If GVDATO(txtArchivo.Text) = Empty Then
      MsgBox "Seleccione el Archivo a Importar", 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 importación", vbYesNo + vbQuestion, "Advertencia") = vbNo Then
     Mcon.Close
     Exit Sub
  Else
     Screen.MousePointer = 11
     Animation1.Open GstrReportesVta & "Proceso.avi"
     Animation1.Visible = True
     Animation1.Play
     cmdCancelar.Enabled = False
  End If
  
 
  Set RS_TOMA = New ADODB.Recordset
  strSQL = "SELECT * FROM " & Mid(txtArchivo.Text, 1, Len(txtArchivo.Text) - 4) ' FLINVE"
   
  RS_TOMA.Open strSQL, Mcon, adOpenStatic

  Pb1.Max = RS_TOMA.RecordCount
  Pb1.Value = 0
   
  If Trim(cd1.FileName) = Empty Then
     cd1.FileName = GstrRutaPDT
  End If
   
  While Not RS_TOMA.EOF
     ' aca viene el proceso de insercion
       
       lblArticulo.Caption = "Artículo : " & RS_TOMA(1)
       lblArticulo.Refresh
       objTOMAINVT.GrabarTomaInventario GstrSiteProce, RS_TOMA(1), RS_TOMA(2), cd1.FileName
       RS_TOMA.MoveNext
       Pb1.Value = Pb1.Value + 1
       
  Wend
  
  '**************************************************
  'Hay que Grabar el Archivo Importado en el Temporal
    
   objTOMAINVT.GrabarArchivoImportado cd1.FileName
         
  '**************************************************
    
    Animation1.AutoPlay = False
    Animation1.Stop
    Animation1.Visible = False
    
    cmdCancelar.Enabled = True
    Pb1.Value = 0
    lblArticulo.Caption = Empty
    Screen.MousePointer = 0
    Me.Hide
    MsgBox "Importación realizada con éxito", 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 cmdimprimir_Click()
  
On Error GoTo errhandler
  
  If lstimportados.ListIndex = -1 Then
     MsgBox "Debe seleccionar el Archivo que desea Imprimir ", vbDefaultButton1 + vbExclamation, "Advertencia"
     Exit Sub
  End If
  
  CRPDT.ReportFileName = GstrReportesInv & "rpt_ListadoPDT.rpt"
  CRPDT.Formulas(1) = "formarchivo= stringvar strarchivo; strarchivo:='" & lstimportados.List(lstimportados.ListIndex) & "'"
  CRPDT.Formulas(2) = "formdecStock=" & GintDecStock
  CRPDT.Formulas(3) = "formScreen= stringvar Screen; Screen:='XX.XXXX'"
  CRPDT.Formulas(4) = "formUsuario=stringvar Usuario; Usuario:='" & GCUSERID & "'"
  
  CRPDT.StoredProcParam(0) = lstimportados.List(lstimportados.ListIndex)
  CRPDT.Action = 1
Exit Sub

errhandler:
    
   MsgBox Err.Description, vbExclamation + vbDefaultButton1, "Mensaje"
   
End Sub

Private Sub Command1_Click()

Dim RSTEM As ADODB.Recordset
Set RSTEM = New ADODB.Recordset

Dim con As ADODB.Connection
Set con = New ADODB.Connection
con.Open "FILEDSN=conexionsies"

Dim strSQL As String

RSTEM.Open " SELECT INVTIDSKU,DESCR FROM IN_INVENTORY WHERE CLASSID NOT IN ('01','21') ", con, adOpenStatic

While Not RSTEM.EOF
    strSQL = "insert into TBSKUS(sku,DESC) values('" & Trim(RSTEM(0)) & "','" & Trim(RSTEM(1)) & "')"
    Mcon.Execute strSQL
    RSTEM.MoveNext
Wend

con.Close
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 MrsArchivosImport = objTOMAINVT.ObtenerArchivosImportados
      
     If Not MrsArchivosImport.EOF Then
        MrsArchivosImport.MoveFirst
        Do While Not MrsArchivosImport.EOF
           lstimportados.AddItem Trim(MrsArchivosImport!filenamepdt)
           MrsArchivosImport.MoveNext
        Loop
     End If
            
     '----------------------------------
        
     Me.Top = 1200
     Me.Left = (Screen.Width - Me.Width) / 2
    
     KeyPreview = True
    
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If KeyCode = vbKeyF2 Then
        cmdBuscar_Click
    End If
End Sub

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

Public Sub salir_formulario()
    Unload Me
End Sub

