VERSION 5.00
Object = "{0ECD9B60-23AA-11D0-B351-00A0C9055D8E}#6.0#0"; "MSHFLXGD.OCX"
Begin VB.Form Form_cajas_mantencion 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Mantencion de cajas"
   ClientHeight    =   5925
   ClientLeft      =   45
   ClientTop       =   375
   ClientWidth     =   6285
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   5925
   ScaleWidth      =   6285
   Begin VB.Frame Frame1 
      Caption         =   "Rango de folios de cajas"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   4575
      Left            =   120
      TabIndex        =   1
      Top             =   1200
      Width           =   6015
      Begin VB.Frame Frame_cajas 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00C00000&
         Height          =   2055
         Left            =   1440
         TabIndex        =   6
         Top             =   1200
         Visible         =   0   'False
         Width           =   3135
         Begin VB.TextBox txt_folio_inicial 
            Height          =   285
            Left            =   1200
            TabIndex        =   10
            Top             =   480
            Width           =   1575
         End
         Begin VB.TextBox txt_folio_final 
            Height          =   285
            Left            =   1200
            TabIndex        =   9
            Top             =   960
            Width           =   1575
         End
         Begin VB.CommandButton cmd_aceptar 
            Caption         =   "Aceptar"
            Height          =   375
            Left            =   240
            TabIndex        =   8
            Top             =   1440
            Width           =   1095
         End
         Begin VB.CommandButton cmd_cancelar 
            Caption         =   "Cancelar"
            Height          =   375
            Left            =   1680
            TabIndex        =   7
            Top             =   1440
            Width           =   1095
         End
         Begin VB.Label Label3 
            Caption         =   "Folio inicial"
            Height          =   255
            Left            =   120
            TabIndex        =   12
            Top             =   480
            Width           =   855
         End
         Begin VB.Label Label4 
            Caption         =   "Folio final"
            Height          =   255
            Left            =   120
            TabIndex        =   11
            Top             =   960
            Width           =   855
         End
      End
      Begin VB.CommandButton cmd_insertar 
         Caption         =   "Insertar"
         Height          =   375
         Left            =   240
         TabIndex        =   5
         Top             =   3960
         Width           =   1215
      End
      Begin VB.CommandButton cmd_modificar 
         Caption         =   "Modificar"
         Height          =   375
         Left            =   1680
         TabIndex        =   4
         Top             =   3960
         Width           =   1215
      End
      Begin VB.CommandButton cmd_eliminar 
         Caption         =   "Eliminar"
         Height          =   375
         Left            =   3120
         TabIndex        =   3
         Top             =   3960
         Width           =   1215
      End
      Begin VB.CommandButton Command5 
         Caption         =   "Salir"
         Height          =   375
         Left            =   4560
         TabIndex        =   2
         Top             =   3960
         Width           =   1215
      End
      Begin MSHierarchicalFlexGridLib.MSHFlexGrid grid_cajas 
         Height          =   3375
         Left            =   240
         TabIndex        =   16
         Top             =   360
         Width           =   5505
         _ExtentX        =   9710
         _ExtentY        =   5953
         _Version        =   393216
         FocusRect       =   0
         FillStyle       =   1
         SelectionMode   =   1
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         _NumberOfBands  =   1
         _Band(0).Cols   =   2
      End
   End
   Begin VB.Frame Frame2 
      Caption         =   "Cajas"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   855
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   6015
      Begin VB.ComboBox cb_cajas 
         Height          =   315
         Left            =   1560
         TabIndex        =   14
         Text            =   "Caja 1"
         Top             =   360
         Width           =   1575
      End
      Begin VB.CommandButton Command1 
         Caption         =   "Ver"
         Height          =   375
         Left            =   3360
         TabIndex        =   13
         Top             =   240
         Width           =   1095
      End
      Begin VB.Label Label1 
         Caption         =   "Seleccione caja:"
         Height          =   255
         Left            =   240
         TabIndex        =   15
         Top             =   360
         Width           =   1335
      End
   End
End
Attribute VB_Name = "Form_cajas_mantencion"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub cmd_Aceptar_Click()
    Dim Mensaje As String
    Dim Folio As Long
    Dim folio_inicial As Long
    Dim folio_final As Long
    
    folio_inicial = Val(grid_cajas.TextMatrix(grid_cajas.Row, 2))
    folio_final = Val(grid_cajas.TextMatrix(grid_cajas.Row, 3))
    Folio = Mid(cb_cajas, 6)
    
    If Frame_cajas.Caption = "Ingresar Caja" Then
        var_sql = "insert into fnza_cajas_folios(folio,folio_inicial,folio_final,activo)" _
                & " values(" & Folio & "," & txt_folio_inicial.Text & "," & txt_folio_final.Text & ",'NO')"
        Mensaje = "La caja ha sido agregada satisfactoriamente"
    Else
        var_sql = "update fnza_cajas_folios set folio_inicial = " & txt_folio_inicial.Text & ",folio_final = " & txt_folio_final.Text & " where" _
                & " folio = " & Folio & " and folio_inicial >= " & folio_inicial & " and folio_final <= " & folio_final
        Mensaje = "La caja ha sido modificada satisfactoriamente"
    End If
        
    conn.Execute var_sql
    
    Frame_cajas.Visible = False
    
    Command1_Click
    MsgBox Mensaje, vbInformation
    
    
End Sub

Private Sub cmd_Cancelar_Click()
    Frame_cajas.Visible = False
End Sub

Private Sub cmd_eliminar_Click()
    Dim Folio As Long
    Dim folio_inicial As Long
    Dim folio_final As Long
    Folio = Mid(cb_cajas, 6)
    folio_inicial = grid_cajas.TextMatrix(grid_cajas.Row, 2)
    folio_final = grid_cajas.TextMatrix(grid_cajas.Row, 3)
    
    var_sql = "delete from fnza_cajas_folios where" _
            & " folio = " & Folio & " and folio_inicial >= " & folio_inicial & " and folio_final <= " & folio_final
    conn.Execute var_sql
    Command1_Click
    
    MsgBox "La caja a sido eliminada satisfactoriamente", vbInformation

End Sub

Private Sub cmd_insertar_Click()
    txt_folio_inicial.Text = ""
    txt_folio_final.Text = ""
    Frame_cajas.Caption = "Ingresar Caja"
    Frame_cajas.Visible = True
End Sub

Private Sub cmd_modificar_Click()
    Dim Folio As Long
    Dim folio_inicial As Long
    Dim folio_final As Long
    Folio = Mid(cb_cajas, 6)
    txt_folio_inicial = grid_cajas.TextMatrix(grid_cajas.Row, 2)
    txt_folio_final = grid_cajas.TextMatrix(grid_cajas.Row, 3)
    
    Frame_cajas.Caption = "Modificar Caja"
    Frame_cajas.Visible = True
End Sub

Private Sub Command1_Click()
    Dim i As Integer
    Dim j As Integer
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    Dim var_sql As String
    var_sql = "SELECT concat('Caja ',caja) as caja,folio_inicial,folio_final,activo,cf.folio FROM fnza_cajas as c,fnza_cajas_folios cf where c.folio = cf.folio and caja = " & Mid(cb_cajas, 6)
    objRS.Open var_sql, conn
    grid_cajas.Clear
    grid_cajas.Rows = 2
    If objRS.RecordCount > 0 Then
    Call Rec2Grid(objRS, grid_cajas, True)
    grid_cajas.ColWidth(5) = 0
    
    For j = 1 To grid_cajas.Rows - 1
        For i = 1 To grid_cajas.Cols - 1
            If grid_cajas.TextMatrix(j, 4) = "SI" Then
                grid_cajas.Row = j
                grid_cajas.Col = i
                grid_cajas.CellBackColor = vbGreen
                'grid_cajas.CellAlignment = flexAlignCenterCenter
            End If
        Next i
    Next j
    End If
    objRS.Close
    
End Sub

Private Sub Command5_Click()
    Unload Me
End Sub

Private Sub Form_Load()
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    Dim var_sql As String
    grid_cajas.Cols = 4
    var_sql = "SELECT distinct caja FROM fnza_cajas order by caja"
    objRS.Open var_sql, conn
    While Not objRS.EOF
        cb_cajas.AddItem "Caja " & objRS("caja")
        objRS.MoveNext
    Wend
    objRS.Close
End Sub

Private Sub Rec2Grid(ByRef REC As ADODB.Recordset, ByRef grid As Object, Optional ByVal Numeracion As Boolean = True)
    grid.ClearStructure
    If REC.RecordCount > 0 Then
        grid.Cols = REC.Fields.count + 1
        grid.Rows = REC.RecordCount + 1
        grid.FixedCols = 1
        grid.FixedRows = 1
        grid.TextMatrix(0, 0) = "Nš"
        grid.ColWidth(0) = IIf(Numeracion, TextWidth(grid.TextMatrix(0, 0)) + 100, 0)
        For i = 1 To REC.Fields.count
            grid.TextMatrix(0, i) = UCase(REC.Fields(i - 1).Name)
            grid.ColWidth(i) = TextWidth(grid.TextMatrix(0, i)) + 100
        Next i
        REC.MoveFirst
        For i = 1 To REC.RecordCount
            grid.TextMatrix(i, 0) = i
            grid.ColWidth(0) = IIf(Numeracion, IIf(TextWidth(grid.TextMatrix(i, 0)) + 100 > grid.ColWidth(0), TextWidth(grid.TextMatrix(i, 0)) + 100, grid.ColWidth(0)), 0)
            For j = 1 To REC.Fields.count
                grid.TextMatrix(i, j) = IIf(IsNull(REC(j - 1)), "Null", REC(j - 1))
                grid.ColWidth(j) = IIf(TextWidth(grid.TextMatrix(i, j)) + 100 > grid.ColWidth(j), TextWidth(grid.TextMatrix(i, j)) + 100, grid.ColWidth(j))
            Next j
            REC.MoveNext
        Next i
    Else
        grid.Cols = 2
        grid.Rows = 2
    End If
End Sub

Private Sub grid_cajas_DblClick()
    Dim Folio As Long
    Dim folio_inicial As Long
    Dim folio_final As Long
    Dim var_sql As String
    Dim activo As String
    
    Folio = grid_cajas.TextMatrix(grid_cajas.Row, 5)
    folio_inicial = grid_cajas.TextMatrix(grid_cajas.Row, 2)
    folio_final = grid_cajas.TextMatrix(grid_cajas.Row, 3)
    activo = grid_cajas.TextMatrix(grid_cajas.Row, 4)
    
    If activo = "SI" Then
        var_sql = "update fnza_cajas_folios set activo = 'NO' where folio = " & Folio _
                & " and folio_inicial >= " & folio_inicial & " and folio_final <= " & folio_final
    Else
        var_sql = "update fnza_cajas_folios set activo = 'SI' where folio = " & Folio _
                & " and folio_inicial >= " & folio_inicial & " and folio_final <= " & folio_final
    End If
    
'    var_sql = "update fnza_cajas_folios set activo = 'NO' where folio = " & Folio
'    conn.Execute var_sql
'
'    var_sql = "update fnza_cajas_folios set activo = 'SI' where folio = " & Folio _
'            & " and folio_inicial >= " & folio_inicial & " and folio_final <= " & folio_final
    conn.Execute var_sql
          
    Command1_Click
    
    MsgBox "La caja " & cb_cajas.Text & " con rango de folios de " & folio_inicial & " hasta " & folio_final & " a sido activada"
End Sub
