VERSION 5.00
Object = "{0ECD9B60-23AA-11D0-B351-00A0C9055D8E}#6.0#0"; "MSHFLXGD.OCX"
Begin VB.Form Form_TicketUsuario 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Ticket Usuario"
   ClientHeight    =   5685
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   7575
   Icon            =   "Form_TicketUsuario.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   5685
   ScaleWidth      =   7575
   Begin VB.Frame Frame3 
      Caption         =   "Seleccionar"
      ForeColor       =   &H00FF0000&
      Height          =   735
      Left            =   120
      TabIndex        =   7
      Top             =   600
      Width           =   7335
      Begin VB.OptionButton Option1 
         Caption         =   "Ticket Confirmados"
         Height          =   375
         Index           =   2
         Left            =   5280
         TabIndex        =   10
         Top             =   240
         Width           =   1695
      End
      Begin VB.OptionButton Option1 
         Caption         =   "Ticket Cerrados"
         Height          =   375
         Index           =   1
         Left            =   2760
         TabIndex        =   9
         Top             =   240
         Width           =   1575
      End
      Begin VB.OptionButton Option1 
         Caption         =   "Ticket Abiertos"
         Height          =   375
         Index           =   0
         Left            =   360
         TabIndex        =   8
         Top             =   240
         Width           =   1815
      End
   End
   Begin VB.Frame Frame2 
      Height          =   735
      Left            =   2520
      TabIndex        =   3
      Top             =   4800
      Width           =   4935
      Begin VB.CommandButton cmd_salir 
         Caption         =   "Salir"
         Height          =   375
         Left            =   3360
         TabIndex        =   6
         Top             =   240
         Width           =   1335
      End
      Begin VB.CommandButton cmd_confirmar 
         Caption         =   "Confirmar"
         Height          =   375
         Left            =   1800
         TabIndex        =   5
         Top             =   240
         Width           =   1335
      End
      Begin VB.CommandButton cmd_consulta 
         Caption         =   "Consulta"
         Height          =   375
         Left            =   240
         TabIndex        =   4
         Top             =   240
         Width           =   1335
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "Ticket del Usuario"
      ForeColor       =   &H00FF0000&
      Height          =   3255
      Left            =   120
      TabIndex        =   0
      Top             =   1440
      Width           =   7335
      Begin MSHierarchicalFlexGridLib.MSHFlexGrid grid_ticket 
         Height          =   2895
         Left            =   120
         TabIndex        =   1
         Top             =   240
         Width           =   7095
         _ExtentX        =   12515
         _ExtentY        =   5106
         _Version        =   393216
         FocusRect       =   0
         FillStyle       =   1
         SelectionMode   =   1
         _NumberOfBands  =   1
         _Band(0).Cols   =   2
      End
   End
   Begin VB.Label lbl_usuario 
      Caption         =   "LUIS RIVEROS"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   13.5
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   240
      TabIndex        =   2
      Top             =   120
      Width           =   8295
   End
End
Attribute VB_Name = "Form_TicketUsuario"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub cmd_confirmar_Click()
    confirmar
End Sub

Private Sub cmd_consulta_Click()
    If grid_ticket.Rows = 2 And grid_ticket.TextMatrix(1, 1) = "" Then
        Exit Sub
    End If
    form_consultar.generar_consulta (grid_ticket.TextMatrix(grid_ticket.Row, 1))
    'Load form_consultar
    form_consultar.Visible = False
    form_consultar.imprimir_consulta
    form_consultar.Visible = False
    'Unload form_consultaR
End Sub

Private Sub cmd_Salir_Click()
    Unload Me
End Sub

Private Sub Form_Load()
    lbl_usuario.Caption = "USUARIO: " & Nom_com_usu_ses
    Option1(0).Value = True
End Sub

Private Sub llena_ticket()
Dim i As Integer
Dim var_sql As String
Dim objRS As ADODB.Recordset
Set objRS = New ADODB.Recordset
'var_sql = "select numero_ticket as ticket,estado_actual as estado," _
'        & "date_format(fecha,'%Y-%m-%d') as fecha," _
'        & "date_format(fecha,'%H-%i-%s') as hora,asignado as confirmado" _
'        & " from spte_solicitud ss,spte_ticket st" _
'        & " Where st.folio_solicitud = ss.Folio And ss.login_usuario = '" _
'        & Nom_usu_ses & "'"
        
var_sql = "select ta.*,usuario_confirmo as confirmo from (select t.* from" _
        & " (select st.folio_solicitud,numero_ticket as ticket,estado_actual as estado,date_format(fecha,'%Y-%m-%d')" _
        & " as fecha,date_format(fecha,'%H-%i-%s') as hora,asignado" _
        & " from spte_solicitud ss,spte_ticket st Where st.folio_solicitud = ss.Folio" _
        & " And ss.login_usuario = '" & Nom_usu_ses & "') as t" _
        & " left join spte_asignacion  as sa on t.ticket = sa.ticket) as ta left join" _
        & " spte_respuesta as sr on ta.ticket = sr.ticket"
        
        
If Option1(0).Value = True Then
    var_sql = var_sql & " where ta.estado <> 'Cerrado'"
End If

If Option1(1).Value = True Then
    var_sql = var_sql & " where ta.estado = 'Cerrado' and usuario_confirmo = 'NO'"
End If

If Option1(2).Value = True Then
    var_sql = var_sql & " where ta.estado = 'Cerrado' and usuario_confirmo = 'SI'"
End If
        
objRS.Open var_sql, conn
If Not objRS.EOF Then
    Call Rec2Grid(objRS, grid_ticket, True)
    grid_ticket.ColSel = 7
    grid_ticket.ColWidth(1) = 0
    For i = 1 To grid_ticket.Rows - 1
        If grid_ticket.TextMatrix(i, 7) = "Null" Then
            grid_ticket.TextMatrix(i, 7) = "NO"
        End If
    Next i
Else
    MsgBox "Ud. no tiene ticket solicitados"
End If
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 confirmar()
    Dim R As Integer
    Dim var_sql As String
    If grid_ticket.Rows = 2 And grid_ticket.TextMatrix(1, 1) = "" Then
        Exit Sub
    End If
    If grid_ticket.TextMatrix(grid_ticket.Row, 3) = "Cerrado" And _
       grid_ticket.TextMatrix(grid_ticket.Row, 6) = "SI" And _
       grid_ticket.TextMatrix(grid_ticket.Row, 7) = "NO" Then
                       
            R = MsgBox("¿Esta seguro de que desea marcar el ticket como confirmado?", _
            vbQuestion + vbYesNo, "Mensaje de confirmación")
            If R = 6 Then
                var_sql = "update spte_respuesta set usuario_confirmo = 'SI'" _
                & " Where ticket = " & grid_ticket.TextMatrix(grid_ticket.Row, 2)
                conn.Execute var_sql
                grid_ticket.TextMatrix(grid_ticket.Row, 7) = "SI"
            End If
    Else
        MsgBox "Para poder confirmar el ticket, el estado debe ser cerrado", vbInformation
    End If
End Sub

Private Sub grid_ticket_dblClick()
    confirmar
End Sub

Private Sub Option1_Click(Index As Integer)
    limpiar
    llena_ticket
End Sub

Private Sub limpiar()
    Dim i As Integer
    grid_ticket.Rows = 2
    For i = 0 To grid_ticket.Cols - 1
        grid_ticket.TextMatrix(1, i) = ""
    Next i
End Sub
