VERSION 5.00
Object = "{3B7C8863-D78F-101B-B9B5-04021C009402}#1.2#0"; "richtx32.ocx"
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "msdatgrd.ocx"
Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomct2.ocx"
Begin VB.Form Form1 
   Caption         =   "Control"
   ClientHeight    =   9465
   ClientLeft      =   525
   ClientTop       =   1065
   ClientWidth     =   15480
   LinkTopic       =   "Form1"
   ScaleHeight     =   9465
   ScaleWidth      =   15480
   Begin VB.ComboBox Combo2 
      Height          =   315
      ItemData        =   "Form1.frx":0000
      Left            =   2880
      List            =   "Form1.frx":0010
      TabIndex        =   13
      Text            =   "BDGP"
      Top             =   480
      Width           =   1695
   End
   Begin VB.ComboBox Combo1 
      Height          =   315
      ItemData        =   "Form1.frx":002D
      Left            =   240
      List            =   "Form1.frx":0037
      TabIndex        =   12
      Text            =   "FACTURA"
      Top             =   960
      Width           =   2535
   End
   Begin RichTextLib.RichTextBox RichTextBox1 
      Height          =   255
      Left            =   12240
      TabIndex        =   11
      Top             =   720
      Visible         =   0   'False
      Width           =   975
      _ExtentX        =   1720
      _ExtentY        =   450
      _Version        =   393217
      TextRTF         =   $"Form1.frx":0059
   End
   Begin VB.CommandButton Command2 
      Caption         =   "VISUALIZAR"
      Height          =   855
      Left            =   9600
      TabIndex        =   10
      Top             =   480
      Width           =   2175
   End
   Begin MSComCtl2.DTPicker DTPicker1 
      Height          =   375
      Left            =   5640
      TabIndex        =   5
      Top             =   360
      Width           =   1455
      _ExtentX        =   2566
      _ExtentY        =   661
      _Version        =   393216
      Format          =   73072641
      CurrentDate     =   44169
   End
   Begin VB.TextBox Text1 
      Height          =   405
      Left            =   240
      TabIndex        =   3
      Top             =   480
      Width           =   2535
   End
   Begin RichTextLib.RichTextBox RichTextBox_Dis 
      Height          =   255
      Left            =   0
      TabIndex        =   2
      Top             =   0
      Visible         =   0   'False
      Width           =   615
      _ExtentX        =   1085
      _ExtentY        =   450
      _Version        =   393217
      TextRTF         =   $"Form1.frx":00E4
   End
   Begin MSDataGridLib.DataGrid DataGrid1 
      Height          =   3615
      Index           =   0
      Left            =   240
      TabIndex        =   1
      Top             =   1440
      Width           =   11535
      _ExtentX        =   20346
      _ExtentY        =   6376
      _Version        =   393216
      AllowUpdate     =   0   'False
      HeadLines       =   1
      RowHeight       =   15
      BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ColumnCount     =   2
      BeginProperty Column00 
         DataField       =   ""
         Caption         =   ""
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   3082
            SubFormatType   =   0
         EndProperty
      EndProperty
      BeginProperty Column01 
         DataField       =   ""
         Caption         =   ""
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   3082
            SubFormatType   =   0
         EndProperty
      EndProperty
      SplitCount      =   1
      BeginProperty Split0 
         MarqueeStyle    =   3
         BeginProperty Column00 
         EndProperty
         BeginProperty Column01 
         EndProperty
      EndProperty
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Buscar"
      Height          =   855
      Left            =   7080
      TabIndex        =   0
      Top             =   480
      Width           =   2055
   End
   Begin MSComCtl2.DTPicker DTPicker2 
      Height          =   375
      Left            =   5280
      TabIndex        =   7
      Top             =   960
      Width           =   1455
      _ExtentX        =   2566
      _ExtentY        =   661
      _Version        =   393216
      Format          =   73072641
      CurrentDate     =   44169
   End
   Begin MSDataGridLib.DataGrid DataGrid1 
      Height          =   3615
      Index           =   1
      Left            =   240
      TabIndex        =   9
      Top             =   5160
      Width           =   11535
      _ExtentX        =   20346
      _ExtentY        =   6376
      _Version        =   393216
      AllowUpdate     =   0   'False
      HeadLines       =   1
      RowHeight       =   15
      BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ColumnCount     =   2
      BeginProperty Column00 
         DataField       =   ""
         Caption         =   ""
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   3082
            SubFormatType   =   0
         EndProperty
      EndProperty
      BeginProperty Column01 
         DataField       =   ""
         Caption         =   ""
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   3082
            SubFormatType   =   0
         EndProperty
      EndProperty
      SplitCount      =   1
      BeginProperty Split0 
         MarqueeStyle    =   3
         BeginProperty Column00 
         EndProperty
         BeginProperty Column01 
         EndProperty
      EndProperty
   End
   Begin VB.Label Label3 
      Caption         =   "Desde"
      Height          =   255
      Left            =   4680
      TabIndex        =   8
      Top             =   960
      Width           =   495
   End
   Begin VB.Label Label2 
      Caption         =   "Desde"
      Height          =   255
      Left            =   4680
      TabIndex        =   6
      Top             =   480
      Width           =   495
   End
   Begin VB.Label Label1 
      Alignment       =   2  'Center
      BackColor       =   &H00C86F55&
      Caption         =   "TABLA"
      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
      Index           =   0
      Left            =   240
      TabIndex        =   4
      Top             =   120
      Width           =   7215
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'Call Exportar_DbGrid_Excel("Hoja1")


Private Sub Command1_Click()
Dim vFiltroDoc As String
Select Case Combo1.Text
    Case "FACTURA"
        vFiltroDoc = "A"
    Case "DOCUMENTO EN ESPERA"
        vFiltroDoc = "G"
End Select
V_Vista = "select TIPOFAC, NUMEROD, FECHAE, Descrip, TGRAVABLE+TEXENTO+MTOTAX AS TOTAL   from " & Combo2.Text & ".DBO.SAFACT where TIPOFAC IN('" & vFiltroDoc & "') AND NUMEROD+DESCRIP like '%" & Text1.Text & "%' AND " & _
"CONVERT(VARCHAR,FECHAE,112)>=" & Format(DTPicker1.Value, "YYYYMMDD") & " AND CONVERT(VARCHAR,FECHAE,112)<=" & Format(DTPicker2.Value, "YYYYMMDD") & " ORDER BY NUMEROD "
ActualizarRs3

If rs3.BOF = True Or rs3.EOF = True Then
Else
    ActualizarDetalle
End If
'''''''''''''''''formato
dbindEx = 0
Set DataGrid1(dbindEx).DataSource = rs3
vTabla = "SAFACT"
FormatoGrid
DataGrid1(0).Columns(4).NumberFormat = "#,##0.00"
DataGrid1(0).Columns(4).Alignment = dbgRight
'''''''''''''''''fin formato


End Sub

Sub ActualizarDetalle()
V_Vista = "select coditem, descrip1, precio, cantidad, totalitem from " & Combo2.Text & ".DBO.saitemfac where tipofac='" & rs3.Fields("tipofac").Value & "' and numerod='" & rs3.Fields("numerod").Value & "'"
ActualizarRs4
'''''''''''''''''formato
dbindEx = 1
Set DataGrid1(dbindEx).DataSource = rs4
vTabla = "SAITEMFAC"
FormatoGrid
DataGrid1(1).Columns(2).NumberFormat = "#,##0.00"
DataGrid1(1).Columns(2).Alignment = dbgRight
DataGrid1(1).Columns(3).NumberFormat = "#,##0.00"
DataGrid1(1).Columns(3).Alignment = dbgRight
DataGrid1(1).Columns(4).NumberFormat = "#,##0.00"
DataGrid1(1).Columns(4).Alignment = dbgRight
'''''''''''''''''fin formato
End Sub




Private Sub Command2_Click()
If rs3.State = 0 Then
    Exit Sub
End If
If rs3.BOF = True Or rs3.EOF = True Then
Else
    RichTextBox1.Text = " {SAFACT.TipoFac} = '" & rs3.Fields("tipofac").Value & "' and {SAFACT.NUMEROD} = '" & rs3.Fields("numerod").Value & "' and {SAITEMFAC.CodSucu} = '00000'"
    RichTextBox1.SaveFile App.Path & "\FILTRO.INI", 1
    If Combo1.Text = "FACTURA" Then
        Select Case Combo2.Text
            Case "BDGP"
                RichTextBox1.Text = App.Path & "\FACTURA.rpt@" & vbCrLf & _
                "@" & vbCrLf & _
                "FACTURAS REALIZADAS@"
                RichTextBox1.SaveFile App.Path & "\REPORTE.INI", 1
            Case "BDMI"
                RichTextBox1.Text = App.Path & "\FACTURA1.rpt@" & vbCrLf & _
                "@" & vbCrLf & _
                "FACTURAS REALIZADAS@"
                RichTextBox1.SaveFile App.Path & "\REPORTE.INI", 1
            Case "BDAR"
                RichTextBox1.Text = App.Path & "\FACTURA2.rpt@" & vbCrLf & _
                "@" & vbCrLf & _
                "FACTURAS REALIZADAS@"
                RichTextBox1.SaveFile App.Path & "\REPORTE.INI", 1
            Case "BDKDY"
                RichTextBox1.Text = App.Path & "\FACTURA3.rpt@" & vbCrLf & _
                "@" & vbCrLf & _
                "FACTURAS REALIZADAS@"
                RichTextBox1.SaveFile App.Path & "\REPORTE.INI", 1
                
        End Select
    Else
        Select Case Combo2.Text
            Case "BDGP"
                RichTextBox1.Text = App.Path & "\PEDIDO.rpt@" & vbCrLf & _
                "@" & vbCrLf & _
                "FACTURAS REALIZADAS@"
                RichTextBox1.SaveFile App.Path & "\REPORTE.INI", 1
            Case "BDMI"
                RichTextBox1.Text = App.Path & "\PEDIDO1.rpt@" & vbCrLf & _
                "@" & vbCrLf & _
                "FACTURAS REALIZADAS@"
                RichTextBox1.SaveFile App.Path & "\REPORTE.INI", 1
            Case "BDAR"
                RichTextBox1.Text = App.Path & "\PEDIDO2.rpt@" & vbCrLf & _
                "@" & vbCrLf & _
                "FACTURAS REALIZADAS@"
                RichTextBox1.SaveFile App.Path & "\REPORTE.INI", 1
            Case "BDKDY"
                RichTextBox1.Text = App.Path & "\PEDIDO3.rpt@" & vbCrLf & _
                "@" & vbCrLf & _
                "FACTURAS REALIZADAS@"
                RichTextBox1.SaveFile App.Path & "\REPORTE.INI", 1
                
        End Select
    
    End If
    MEN123 = Shell(App.Path & "\REPORTE.EXE", vbNormalFocus)
End If
End Sub

Private Sub DataGrid1_ColResize(Index As Integer, ByVal ColIndex As Integer, Cancel As Integer)
dbindEx = Index
GuardarFormatoGrid
End Sub



Private Sub DataGrid1_KeyUp(Index As Integer, KeyCode As Integer, Shift As Integer)
If Index = 0 Then
    ActualizarDetalle
End If
End Sub

Private Sub DataGrid1_RowColChange(Index As Integer, LastRow As Variant, ByVal LastCol As Integer)
If Index = 0 Then
    ActualizarDetalle
End If
End Sub

Sub GuardarFormatoGrid()
Dim I_G As Integer
Dim V_Star As Integer
RichTextBox_Dis.Text = ""
vTabla = DataGrid1(dbindEx).Tag
    For I_G = 0 To DataGrid1(dbindEx).Columns.Count - 1
        RichTextBox_Dis.Text = RichTextBox_Dis.Text & Format(DataGrid1(dbindEx).Columns(I_G).Width, "00000")
        RichTextBox_Dis.Text = RichTextBox_Dis.Text & "-"
    Next I_G

    RichTextBox_Dis.SaveFile App.Path & "\" & vTabla & ".TXT", 1
End Sub

Sub FormatoGrid()
On Error Resume Next
RichTextBox_Dis.LoadFile (App.Path & "\" & vTabla & ".TXT")
DataGrid1(dbindEx).Tag = vTabla
If Err.Number = 75 Then
    For I_G = 0 To DataGrid1(dbindEx).Columns.Count - 1
        RichTextBox_Dis.Text = RichTextBox_Dis.Text & Format(DataGrid1(dbindEx).Columns(I_G).Width, "00000")
        RichTextBox_Dis.Text = RichTextBox_Dis.Text & "-"
    Next I_G

    RichTextBox_Dis.SaveFile App.Path & "\" & vTabla & ".TXT", 1
Else
    For I_G = 0 To DataGrid1(dbindEx).Columns.Count - 1
        
            If I_G = 0 Then
                V_Star = 1
                DataGrid1(dbindEx).Columns(I_G).Width = Mid(RichTextBox_Dis.Text, V_Star, 5)
            Else
                V_Star = V_Star + 6
                DataGrid1(dbindEx).Columns(I_G).Width = Mid(RichTextBox_Dis.Text, V_Star, 5)
            End If
        
    Next I_G
End If
End Sub



Private Sub Form_Activate()
DTPicker1.Value = Date
DTPicker2.Value = Date

End Sub

Private Sub Form_Unload(Cancel As Integer)
End
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
    Command1 = True
End If
End Sub

