VERSION 5.00
Object = "{0D452EE1-E08F-101A-852E-02608C4D0BB4}#2.0#0"; "FM20.DLL"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Begin VB.Form C_Generic 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Form1"
   ClientHeight    =   3600
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   5880
   ControlBox      =   0   'False
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   3600
   ScaleWidth      =   5880
   StartUpPosition =   1  'CenterOwner
   Begin Project1.CDate C_Date 
      Height          =   315
      Index           =   1000
      Left            =   120
      TabIndex        =   9
      Top             =   1860
      Width           =   1275
      _ExtentX        =   2249
      _ExtentY        =   556
   End
   Begin MSComctlLib.ImageCombo C_ImageCombo 
      Height          =   330
      Index           =   1000
      Left            =   120
      TabIndex        =   7
      Top             =   2520
      Visible         =   0   'False
      Width           =   1275
      _ExtentX        =   2249
      _ExtentY        =   582
      _Version        =   393216
      ForeColor       =   -2147483640
      BackColor       =   -2147483643
      Text            =   "ImageCombo1"
   End
   Begin MSFlexGridLib.MSFlexGrid C_Grid 
      Height          =   1035
      Index           =   1000
      Left            =   1560
      TabIndex        =   6
      Top             =   0
      Visible         =   0   'False
      Width           =   1695
      _ExtentX        =   2990
      _ExtentY        =   1826
      _Version        =   393216
      FixedCols       =   0
      AllowBigSelection=   0   'False
      ScrollTrack     =   -1  'True
      FocusRect       =   0
      SelectionMode   =   1
      AllowUserResizing=   1
      BorderStyle     =   0
   End
   Begin VB.PictureBox C_Picture 
      Height          =   255
      Index           =   1000
      Left            =   120
      ScaleHeight     =   195
      ScaleWidth      =   1215
      TabIndex        =   5
      Top             =   2220
      Visible         =   0   'False
      Width           =   1275
   End
   Begin VB.Frame C_Frame 
      Caption         =   "Frame1"
      Height          =   315
      Index           =   1000
      Left            =   120
      TabIndex        =   4
      Top             =   1500
      Visible         =   0   'False
      Width           =   1275
   End
   Begin VB.CommandButton C_Button 
      Caption         =   "Command1"
      Height          =   255
      Index           =   1000
      Left            =   120
      TabIndex        =   2
      Top             =   780
      Visible         =   0   'False
      Width           =   1275
   End
   Begin VB.TextBox C_Text 
      Height          =   285
      Index           =   1000
      Left            =   120
      TabIndex        =   1
      Text            =   "Text1"
      Top             =   420
      Visible         =   0   'False
      Width           =   1275
   End
   Begin VB.Label Lbl_Category 
      Height          =   315
      Left            =   3960
      TabIndex        =   8
      Top             =   480
      Visible         =   0   'False
      Width           =   1635
   End
   Begin MSForms.ComboBox C_Combobox 
      Height          =   315
      Index           =   1000
      Left            =   120
      TabIndex        =   3
      Top             =   1080
      Visible         =   0   'False
      Width           =   1275
      VariousPropertyBits=   679495707
      DisplayStyle    =   7
      Size            =   "2249;556"
      MatchEntry      =   0
      ShowDropButtonWhen=   2
      FontHeight      =   165
      FontCharSet     =   0
      FontPitchAndFamily=   2
   End
   Begin VB.Label C_Label 
      Caption         =   "Label1"
      Height          =   255
      Index           =   1000
      Left            =   180
      TabIndex        =   0
      Top             =   60
      Visible         =   0   'False
      Width           =   1155
   End
End
Attribute VB_Name = "C_Generic"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Public ms_Screen_Name As String

Private Enum Action_List
    Add = 1
    UPDATE = 2
    Delete = 3
    Preview = 4
    Refresh = 5
    Quit = 6
    search = 7
    CallFunction = 8
    GridPrint = 9
    ExportExcel = 10
End Enum

Private Enum Property_List
    Text_Caption = 1
    Left = 2
    Top = 3
    Width = 4
    Height = 5
    Enabled = 6
    Visible = 7
    Tag = 8
    TabIndex = 9
    BackColor = 10
    Appearance = 11
    BorderStyle = 12
    Picture = 13
    Cols = 14
    Rows = 15
    Number = 16
    action = 17
    ActionParameter = 18
    FillRequest = 19
    Total = 20
    Role = 21
    CallAfterFillRequest = 22
    Alignment = 23
End Enum

Private Enum Component_Type
    Form = 1
    Button = 2
    Label = 3
    Text = 4
    ComboBox = 5
    Date = 6
    Frame = 7
    Picture = 8
    MSGrid = 9
    Column = 10
    ImageCombo = 11
End Enum

Private Type Object_Definition
    ComponentName As String
    ComponentType As Component_Type
    ParentName As String
    Left As Long
    Top As Long
    Width As Long
    Height As Long
    Caption_Text As String
    Enabled As Boolean
    Visible As Boolean
    Tag As Variant
    TabIndex As Long
    BackColor As String
    Appearance As Integer
    BorderStyle As Integer
    Picture As Long
    Cols As Long
    Rows As Long
    Number As Long
    action As Integer
    ActionParameter As String
    FillRequest As String
    Total As String
    Role As String
    CallAfterFillRequest As String
    Alignment As String
End Type

Private mb_Created As Boolean
Private mb_CanQuit As Boolean
Private mt_ObjectList() As Object_Definition
Private mo_GenericFunctions As New C_GenericFunctions
Private mo_Fetch As Fetch
Public mo_Components As New Collection
Private mo_ComponentsIndex As New Collection
Private ml_RefreshIndex As Long
Private ml_FormIndex As Long

Public Grid As Object

Private Sub Load_Object()
Dim ll_Statement As Long
Dim li_Status As Integer
Dim ls_Req As String
Dim ll_ObjectCount As Long
Dim ls_PreviousComponent As String
Dim ls_Text As String
Dim ls_Value As String

    On Error GoTo Load_Object_Err

    ls_Req = "EXEC Screen_Definition_t_lst '" & gut_LangLogin.Code & "', '" & ms_Screen_Name & "'"

    If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_Req) Then
        li_Status = SQL_SUCCESS
    Else
        li_Status = SQL_ERROR
    End If

    ls_PreviousComponent = ""
    ll_ObjectCount = 0
    ReDim mt_ObjectList(0)

    Do While li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO
        li_Status = SQLFetch(ll_Statement)
        If li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO Then
            ls_Text = ODBCData(ll_Statement, 1)
            If ls_Text <> ls_PreviousComponent Then
                ll_ObjectCount = ll_ObjectCount + 1
                ReDim Preserve mt_ObjectList(ll_ObjectCount)
                ls_PreviousComponent = ls_Text
                mt_ObjectList(ll_ObjectCount).ComponentName = ls_Text
                mt_ObjectList(ll_ObjectCount).ComponentType = ODBCData(ll_Statement, 2)
                mt_ObjectList(ll_ObjectCount).ParentName = ODBCData(ll_Statement, 3)
                Initialize_Object ll_ObjectCount
                ls_Text = ODBCData(ll_Statement, 4)
                If ls_Text <> "" Then
                    mt_ObjectList(ll_ObjectCount).Caption_Text = ls_Text
                End If
            End If
            ls_Text = ODBCData(ll_Statement, 5)
            ls_Value = ODBCMemoGet(ll_Statement, 6)
            Select Case ls_Text
                Case Property_List.Text_Caption: mt_ObjectList(ll_ObjectCount).Caption_Text = ls_Value
                Case Property_List.Left: mt_ObjectList(ll_ObjectCount).Left = Val(ls_Value)
                Case Property_List.Top: mt_ObjectList(ll_ObjectCount).Top = Val(ls_Value)
                Case Property_List.Width: mt_ObjectList(ll_ObjectCount).Width = Val(ls_Value)
                Case Property_List.Height: mt_ObjectList(ll_ObjectCount).Height = Val(ls_Value)
                Case Property_List.Enabled: mt_ObjectList(ll_ObjectCount).Enabled = Val(ls_Value)
                Case Property_List.Visible: mt_ObjectList(ll_ObjectCount).Visible = Val(ls_Value)
                Case Property_List.Tag: mt_ObjectList(ll_ObjectCount).Tag = ls_Value
                Case Property_List.TabIndex: mt_ObjectList(ll_ObjectCount).TabIndex = Val(ls_Value)
                Case Property_List.BackColor: mt_ObjectList(ll_ObjectCount).BackColor = ls_Value
                Case Property_List.Appearance: mt_ObjectList(ll_ObjectCount).Appearance = Val(ls_Value)
                Case Property_List.BorderStyle: mt_ObjectList(ll_ObjectCount).BorderStyle = Val(ls_Value)
                Case Property_List.Picture: mt_ObjectList(ll_ObjectCount).Picture = Val(ls_Value)
                Case Property_List.Cols: mt_ObjectList(ll_ObjectCount).Cols = Val(ls_Value)
                Case Property_List.Rows: mt_ObjectList(ll_ObjectCount).Rows = Val(ls_Value)
                Case Property_List.Number: mt_ObjectList(ll_ObjectCount).Number = Val(ls_Value)
                Case Property_List.action: mt_ObjectList(ll_ObjectCount).action = Val(ls_Value)
                Case Property_List.ActionParameter: mt_ObjectList(ll_ObjectCount).ActionParameter = ls_Value
                Case Property_List.FillRequest: mt_ObjectList(ll_ObjectCount).FillRequest = ls_Value
                Case Property_List.Total: mt_ObjectList(ll_ObjectCount).Total = ls_Value
                Case Property_List.Role: mt_ObjectList(ll_ObjectCount).Role = ls_Value
                Case Property_List.CallAfterFillRequest: mt_ObjectList(ll_ObjectCount).CallAfterFillRequest = ls_Value
                Case Property_List.Alignment: mt_ObjectList(ll_ObjectCount).Alignment = ls_Value
            End Select
        End If
    Loop
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    
    Exit Sub

Load_Object_Err:
    StdError
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
End Sub

Private Sub Create_Object()
Dim i As Long
Dim ls_Text As String
Dim lo_Object As Object
Dim lb_Created As Boolean
Dim ls_text1 As String
Dim ls_Text2 As String

    mb_CanQuit = KO

    For i = 1 To UBound(mt_ObjectList)
    
        If mt_ObjectList(i).ComponentType <> Form Then
            lb_Created = OK
            Select Case mt_ObjectList(i).ComponentType
                Case Component_Type.Button:
                    Load C_Button(i)
                    mo_Components.Add C_Button(i), mt_ObjectList(i).ComponentName
                Case Component_Type.ComboBox
                    Load C_Combobox(i)
                    mo_Components.Add C_Combobox(i), mt_ObjectList(i).ComponentName
                Case Component_Type.Label
                    Load C_Label(i)
                    mo_Components.Add C_Label(i), mt_ObjectList(i).ComponentName
                Case Component_Type.Text
                    Load C_Text(i)
                    mo_Components.Add C_Text(i), mt_ObjectList(i).ComponentName
                Case Component_Type.Date
                    Load C_Date(i)
                    mo_Components.Add C_Date(i), mt_ObjectList(i).ComponentName
                Case Component_Type.Frame
                    Load C_Frame(i)
                    mo_Components.Add C_Frame(i), mt_ObjectList(i).ComponentName
                Case Component_Type.Picture
                    Load C_Picture(i)
                    mo_Components.Add C_Picture(i), mt_ObjectList(i).ComponentName
                Case Component_Type.MSGrid
                    Load C_Grid(i)
                    mo_Components.Add C_Grid(i), mt_ObjectList(i).ComponentName
                    Set Grid = C_Grid(i)
                    
                Case Component_Type.ImageCombo
                    Load C_ImageCombo(i)
                    mo_Components.Add C_ImageCombo(i), mt_ObjectList(i).ComponentName
                Case Else
                    lb_Created = KO
            End Select
            If lb_Created = OK Then mo_ComponentsIndex.Add i, mt_ObjectList(i).ComponentName
        Else
            mo_Components.Add Me, mt_ObjectList(i).ComponentName
            mo_ComponentsIndex.Add i, mt_ObjectList(i).ComponentName
            ml_FormIndex = i
        End If
    Next
    For i = 1 To UBound(mt_ObjectList)
        ls_Text = mt_ObjectList(i).ComponentName
        If mt_ObjectList(i).ComponentType = Column Then
            If mt_ObjectList(i).Width <> -1 Then mo_Components(mt_ObjectList(i).ParentName).ColWidth(mt_ObjectList(i).Number) = mt_ObjectList(i).Width
            If mt_ObjectList(i).Caption_Text <> "" Then mo_Components(mt_ObjectList(i).ParentName).TextMatrix(0, mt_ObjectList(i).Number) = mt_ObjectList(i).Caption_Text
            mo_Components(mt_ObjectList(i).ParentName).ColData(mt_ObjectList(i).Number) = i
            Select Case mt_ObjectList(i).Alignment
                Case "Right":
                    mo_Components(mt_ObjectList(i).ParentName).ColAlignment(mt_ObjectList(i).Number) = flexAlignRightCenter
                Case "Center":
                    mo_Components(mt_ObjectList(i).ParentName).ColAlignment(mt_ObjectList(i).Number) = flexAlignCenterCenter
                Case Else
                    mo_Components(mt_ObjectList(i).ParentName).ColAlignment(mt_ObjectList(i).Number) = flexAlignLeftCenter
            End Select
                
        Else
            If mt_ObjectList(i).Left <> -1 Then mo_Components(ls_Text).Left = mt_ObjectList(i).Left
            If mt_ObjectList(i).Top <> -1 Then mo_Components(ls_Text).Top = mt_ObjectList(i).Top
            If mt_ObjectList(i).Width <> -1 Then mo_Components(ls_Text).Width = mt_ObjectList(i).Width
            If mt_ObjectList(i).Height <> -1 Then mo_Components(ls_Text).Height = mt_ObjectList(i).Height
            Select Case mt_ObjectList(i).ComponentType
                Case Form, Frame
                    mo_Components(ls_Text).Caption = AnalyzeValue(mt_ObjectList(i).Caption_Text)
                Case Label
                    mo_Components(ls_Text).Caption = AnalyzeValue(mt_ObjectList(i).Caption_Text)
                    Select Case mt_ObjectList(i).Alignment
                        Case "Right"
                            mo_Components(ls_Text).Alignment = 1
                        Case "Center"
                            mo_Components(ls_Text).Alignment = 2
                        Case Else
                            mo_Components(ls_Text).Alignment = 0
                    End Select
                Case Text
                    mo_Components(ls_Text).Text = AnalyzeValue(mt_ObjectList(i).Caption_Text)
                    Select Case mt_ObjectList(i).Alignment
                        Case "Right"
                            mo_Components(ls_Text).Alignment = 1
                        Case "Center"
                            mo_Components(ls_Text).Alignment = 2
                        Case Else
                            mo_Components(ls_Text).Alignment = 0
                    End Select
                Case Button
                    mo_Components(ls_Text).Text = AnalyzeValue(mt_ObjectList(i).Caption_Text)
                Case ComboBox
                    Dim li_Position As Integer
                    If mt_ObjectList(i).Caption_Text <> "" Then
                    
                        li_Position = InStr(1, mt_ObjectList(i).Caption_Text, ";", vbTextCompare)
                        If li_Position <> 0 Then
                            ls_text1 = Mid(mt_ObjectList(i).Caption_Text, 1, li_Position - 1)
                        Else
                            ls_text1 = "0"
                        End If
                        ls_Text2 = Mid(mt_ObjectList(i).Caption_Text, li_Position + 1)
                        ls_text1 = AnalyzeValue(ls_text1)
                        ls_Text2 = AnalyzeValue(ls_Text2)
                        MCombo_AddItemCode mo_Components(ls_Text), ls_text1, ls_Text2
                    End If
                Case Date
                    mo_Components(ls_Text).SetDate = mt_ObjectList(i).Caption_Text
            End Select
            mo_Components(ls_Text).Enabled = mt_ObjectList(i).Enabled
            If mt_ObjectList(i).ComponentType <> Form Then mo_Components(ls_Text).Visible = mt_ObjectList(i).Visible
            If mt_ObjectList(i).ComponentType = ComboBox Or mt_ObjectList(i).ComponentType = ImageCombo Then
                mo_Components(ls_Text).Tag = UNLOADED
            Else
                mo_Components(ls_Text).Tag = mt_ObjectList(i).Tag
            End If
            If mt_ObjectList(i).ParentName <> "" Then
                Set mo_Components(ls_Text).Container = mo_Components(mt_ObjectList(i).ParentName)
            End If
            If mt_ObjectList(i).BackColor <> "" Then mo_Components(ls_Text).BackColor = Val(mt_ObjectList(i).BackColor)
            If mt_ObjectList(i).Appearance <> -1 Then mo_Components(ls_Text).Appearance = mt_ObjectList(i).Appearance
            If mt_ObjectList(i).BorderStyle <> -1 Then mo_Components(ls_Text).BorderStyle = mt_ObjectList(i).BorderStyle
            If mt_ObjectList(i).Picture <> -1 Then mo_Components(ls_Text).Picture = LoadResPicture(mt_ObjectList(i).Picture, 1)
            If mt_ObjectList(i).Cols <> -1 Then mo_Components(ls_Text).Cols = mt_ObjectList(i).Cols
            If mt_ObjectList(i).Rows <> -1 Then mo_Components(ls_Text).Rows = mt_ObjectList(i).Rows
        End If
        If mt_ObjectList(i).action = Action_List.Quit Then mb_CanQuit = OK
        If mt_ObjectList(i).action = Action_List.Refresh Then ml_RefreshIndex = i
        If mt_ObjectList(i).ComponentType = MSGrid Then
            mo_Components(ls_Text).Col = 0
            mo_Components(ls_Text).ColSel = mo_Components(ls_Text).Cols - 1
        End If
    Next

    For i = 1 To UBound(mt_ObjectList)
        If mt_ObjectList(i).ComponentType <> Form Then
            If mt_ObjectList(i).TabIndex <> -1 Then mo_Components(mt_ObjectList(i).ComponentName).TabIndex = mt_ObjectList(i).TabIndex
        End If
    Next

    mb_Created = OK

End Sub

Private Sub Initialize_Object(ll_ObjectCount As Long)
    
    mt_ObjectList(ll_ObjectCount).Caption_Text = ""
    mt_ObjectList(ll_ObjectCount).Left = -1
    mt_ObjectList(ll_ObjectCount).Top = -1
    mt_ObjectList(ll_ObjectCount).Width = -1
    mt_ObjectList(ll_ObjectCount).Height = -1
    mt_ObjectList(ll_ObjectCount).Enabled = OK
    mt_ObjectList(ll_ObjectCount).Visible = OK
    mt_ObjectList(ll_ObjectCount).TabIndex = -1
    mt_ObjectList(ll_ObjectCount).Tag = ""
    mt_ObjectList(ll_ObjectCount).BackColor = ""
    mt_ObjectList(ll_ObjectCount).Appearance = -1
    mt_ObjectList(ll_ObjectCount).BorderStyle = -1
    mt_ObjectList(ll_ObjectCount).Picture = -1
    mt_ObjectList(ll_ObjectCount).Cols = -1
    mt_ObjectList(ll_ObjectCount).Rows = -1
    mt_ObjectList(ll_ObjectCount).Number = -1
    mt_ObjectList(ll_ObjectCount).action = -1
    mt_ObjectList(ll_ObjectCount).ActionParameter = ""
    mt_ObjectList(ll_ObjectCount).FillRequest = ""
    mt_ObjectList(ll_ObjectCount).Total = ""
    mt_ObjectList(ll_ObjectCount).Role = ""
    mt_ObjectList(ll_ObjectCount).CallAfterFillRequest = ""
    mt_ObjectList(ll_ObjectCount).Alignment = ""
    
End Sub

Private Sub C_Combobox_Click(Index As Integer)
    If mb_Created = KO Then Exit Sub
    If C_Combobox(Index).Tag = UNLOADED Then Exit Sub
    MouseOff
    DoEvents
    Select Case mt_ObjectList(Index).action
        Case Action_List.CallFunction:
            CallByName mo_GenericFunctions, mt_ObjectList(Index).ActionParameter, VbMethod, mo_Components
        Case Action_List.Refresh
            Refresh_Screen mt_ObjectList(Index).ActionParameter
    End Select
    MouseOn
    DoEvents
End Sub

Private Sub C_Combobox_DropButtonClick(Index As Integer)
Dim lv_Code

    If C_Combobox(Index).Tag = UNLOADED Then
        MouseOff
        DoEvents
        lv_Code = MCombo_GetCode(C_Combobox(Index))
        C_Combobox(Index).Clear
        MCombo_Fill C_Combobox(Index), AnalyzeRequest(mt_ObjectList(Index).FillRequest)
        MCombo_CodeSelect(C_Combobox(Index)) = lv_Code
        C_Combobox(Index).Tag = Loaded
        MouseOn
        DoEvents
    End If

End Sub

Private Sub C_Combobox_KeyPress(Index As Integer, KeyAscii As msforms.ReturnInteger)
    C_Combobox_DropButtonClick Index
End Sub

Private Sub C_Grid_DblClick(Index As Integer)
    MouseOff
    Select Case mt_ObjectList(Index).action
        Case Action_List.Preview:
        
        Case Action_List.CallFunction:
            CallByName mo_GenericFunctions, mt_ObjectList(Index).ActionParameter, VbMethod, mo_Components
    End Select
    MouseOn
End Sub

Private Sub C_Grid_SelChange(Index As Integer)
    C_Grid(Index).RowSel = C_Grid(Index).Row
End Sub

Private Sub C_ImageCombo_Click(Index As Integer)
    If mb_Created = KO Then Exit Sub
    If C_ImageCombo(Index).Tag = UNLOADED Then Exit Sub
    MouseOff
    Select Case mt_ObjectList(Index).action
        Case Action_List.CallFunction:
            CallByName mo_GenericFunctions, mt_ObjectList(Index).ActionParameter, VbMethod, mo_Components
        Case Action_List.Refresh
            Refresh_Screen mt_ObjectList(Index).ActionParameter
    End Select
    MouseOn
End Sub

Private Sub C_ImageCombo_Dropdown(Index As Integer)
Dim ls_Req As String
Dim li_Status As Integer
Dim ll_Statement As Long
Dim lS_Code As String
Dim ls_Description As String
Dim ls_Category As String
Dim ls_CategoryCode As String
Dim ls_Contract As String * 1
Dim ls_Auto_Approved As String * 1
Dim li_CategoryNumber As Integer
Dim ls_CurrentCategory As String
Dim ls_CurrentKey As String
Dim i As Integer

    If C_ImageCombo(Index).Tag = UNLOADED Then
        MouseOff

        ls_CurrentCategory = ""
        li_CategoryNumber = 0

        On Error Resume Next
        
        ls_CurrentKey = ""
        ls_CurrentKey = C_ImageCombo(Index).SelectedItem.Key

        C_ImageCombo(Index).ComboItems.Clear

        On Error GoTo Cbo_SubCat_DropDown_Err
        
        ls_Req = mt_ObjectList(Index).FillRequest
        
        If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_Req) Then
            li_Status = SQL_SUCCESS
            
            Do While li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO
                li_Status = SQLFetch(ll_Statement)
                If li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO Then
                
                    'read the category code
                    ls_CategoryCode = ODBCData(ll_Statement, 1)
                    'read the category description
                    ls_Category = ODBCData(ll_Statement, 2)
                    'read the code
                    lS_Code = ODBCData(ll_Statement, 3)
                    'read the description
                    ls_Description = ODBCData(ll_Statement, 4)
                    'Read the type of subcategory (order or contract)
                    ls_Contract = ODBCData(ll_Statement, 5)
                    'Read auto approved of the sub category
                    ls_Auto_Approved = ODBCData(ll_Statement, 6)
                    
                    If ls_Category <> ls_CurrentCategory Then
                        li_CategoryNumber = li_CategoryNumber + 1
                        C_ImageCombo(Index).ComboItems.Add , ls_CategoryCode, ls_Category, , , 1
                        ls_CurrentCategory = ls_Category
                    End If
                    
                    C_ImageCombo(Index).ComboItems.Add , lS_Code, ls_Description, , , 3
                    C_ImageCombo(Index).ComboItems.Item(lS_Code).Tag = ls_Contract & ls_Auto_Approved & ls_Category
                    
                End If
            Loop
        
            li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
            
        End If
        
        If ls_CurrentKey <> "" Then
            For i = 1 To Cbo_SubCat.ComboItems.Count
                If C_ImageCombo(Index).ComboItems.Item(i).Key = ls_CurrentKey Then
                    C_ImageCombo(Index).ComboItems.Item(i).Selected = OK
                    Set C_ImageCombo(Index).SelectedItem = C_ImageCombo(Index).ComboItems.Item(i)
                End If
            Next
        End If
    
        C_ImageCombo(Index).Tag = Loaded
        MouseOn
    End If
    
    Exit Sub
    
Cbo_SubCat_DropDown_Err:
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    StdError
End Sub

Private Sub C_ImageCombo_KeyPress(Index As Integer, KeyAscii As Integer)
    C_ImageCombo_Dropdown Index
End Sub

Private Sub C_Picture_Click(Index As Integer)
Dim li_Position As Integer
    
    MouseOff
    Select Case mt_ObjectList(Index).action
        Case Action_List.Quit:  Unload Me
        Case Action_List.search:
        Case Action_List.CallFunction:
            CallByName mo_GenericFunctions, mt_ObjectList(Index).ActionParameter, VbMethod, mo_Components
        Case Action_List.GridPrint:
            Dim la_size()
            Dim la_pos()
            Dim i As Integer
            Dim ls_Grid As String
            Dim ls_TypePrint As String
            Dim li_Orientation As Integer
            Dim li_Tabulation As Integer
            Dim li_position1 As Integer
            Dim li_position2 As Integer
            Dim li_Row As Integer

            If Printers.Count = 0 Then
                SendMessage 135, "No printer is installed on your computer. Please, contact your system administrator.", gut_LangLogin.Code
                MouseOn
                Exit Sub
            End If
                
            li_Position = InStr(1, mt_ObjectList(Index).ActionParameter, ";", vbTextCompare)
            ls_TypePrint = Mid(mt_ObjectList(Index).ActionParameter, 1, li_Position - 1)
            li_position1 = InStr(li_Position + 1, mt_ObjectList(Index).ActionParameter, ";", vbTextCompare)
            ls_Grid = Mid(mt_ObjectList(Index).ActionParameter, li_Position + 1, li_position1 - li_Position - 1)
            li_position2 = InStr(li_position1 + 1, mt_ObjectList(Index).ActionParameter, ";", vbTextCompare)
            li_Orientation = Val(Mid(mt_ObjectList(Index).ActionParameter, li_position1 + 1, li_position2 - li_position1 - 1))
            li_Tabulation = Val(Mid(mt_ObjectList(Index).ActionParameter, li_position2 + 1))
            
            Set Grid = mo_Components(ls_Grid)
            
            ReDim la_size(Grid.Cols - 1)
            ReDim la_pos(Grid.Cols - 1)
            
            For i = 0 To UBound(mt_ObjectList)
                If mt_ObjectList(i).ComponentType = Component_Type.Column Then
                    If mt_ObjectList(i).ActionParameter = "" Or InStr(1, mt_ObjectList(i).ActionParameter, ";", vbTextCompare) = 1 Then
                        la_size(mt_ObjectList(i).Number) = 0
                    Else
                        la_size(mt_ObjectList(i).Number) = Val(Mid(mt_ObjectList(i).ActionParameter, 1, InStr(1, mt_ObjectList(i).ActionParameter, ";", vbTextCompare) - 1))
                    End If
                    la_pos(mt_ObjectList(i).Number) = mt_ObjectList(i).Number
                End If
            Next
            
            li_Row = Grid.Row
            
            If ls_TypePrint = "Page" Then
                PrintGrid2 li_Tabulation, la_size, la_pos
            Else
                PrintGrid li_Orientation, li_Tabulation, la_size
            End If
            
            Grid.Row = li_Row
            Grid.Col = 0
            Grid.ColSel = Grid.Cols - 1
            
        Case Action_List.ExportExcel
            Dim lo_appExcel As New CExcel
            Dim li_GridRow As Integer
            Dim li_GridCol As Integer
            Dim li_ExcelCol As Integer
            Dim ls_Text As String
            
                On Error GoTo Export_Excel_End
            
                Set Grid = mo_Components(mt_ObjectList(Index).ActionParameter)
            
                lo_appExcel.NewDocument ""
                With lo_appExcel.o_ExcelSheet1
                    For li_GridRow = 0 To Grid.Rows - 1
                        Grid.Row = li_GridRow
                        li_ExcelCol = 1
                        For li_GridCol = 0 To Grid.Cols - 1
                            Grid.Col = li_GridCol
                            ls_Text = mt_ObjectList(Grid.ColData(li_GridCol)).ActionParameter
                            li_Position = InStr(1, ls_Text, ";", vbTextCompare)
                            If Mid(ls_Text, li_Position + 1) = "Y" Then
                                .cells(li_GridRow + 1, li_ExcelCol).value = ConvertCodePageFromAnsi("'" & Grid.Text, gl_CodePage)
                                li_ExcelCol = li_ExcelCol + 1
                            End If
                        Next
                    Next
                End With
                Set lo_appExcel = Nothing
                
                SendMessage 129, "Press ALT+TAB to switch to the Excel application.", gut_LangLogin.Code
                
Export_Excel_End:
                
        Case Action_List.Refresh
            Refresh_Screen mt_ObjectList(Index).ActionParameter

    End Select
    MouseOn
    
End Sub

Private Sub Form_Click()
    If mb_CanQuit = KO Then Unload Me
End Sub

Private Sub Form_Load()

    C_Button(1000).Visible = KO
    C_Combobox(1000).Visible = KO
    C_Date(1000).Visible = KO
    C_Frame(1000).Visible = KO
    C_Grid(1000).Visible = KO
    C_Label(1000).Visible = KO
    C_Picture(1000).Visible = KO
    C_Text(1000).Visible = KO
    C_ImageCombo(1000).Visible = KO
    
    Set mo_Fetch = New Fetch
    mo_Fetch.EnvironmentIdentifier = gl_Environment
    mo_Fetch.DatabaseIdentifier = gl_Database

    MouseOff

    mb_Created = KO

    Load_Object

    Create_Object
    
    Check_Security

    If mt_ObjectList(ml_FormIndex).CallAfterFillRequest <> "" Then
        CallByName mo_GenericFunctions, mt_ObjectList(ml_FormIndex).CallAfterFillRequest, VbMethod, mo_Components
    End If

    Refresh_Screen mt_ObjectList(ml_RefreshIndex).ActionParameter

    If gl_CodePage <> 1252 And gl_CodePage <> 0 Then ChangeCharset Me
    
    MouseOn

End Sub

Private Sub Form_Unload(Cancel As Integer)
Dim i As Long

    For i = mo_Components.Count To 1 Step -1
        Unload mo_Components(i)
        mo_Components.Remove i
        mo_ComponentsIndex.Remove i
    Next
    
    Set mo_Components = Nothing
    Set Grid = Nothing
    
    ReDim mt_ObjectList(0)
    
End Sub

Private Function AnalyzeRequest(ls_Request As String) As String
Dim ls_request1 As String
Dim li_Position As Integer
Dim li_position1 As Integer
Dim li_position2 As Integer
Dim ls_Text As String
Dim ls_Component As String
Dim ls_InfoType As String
Dim ls_Info As String

    ls_request1 = ls_Request
    ls_request1 = Replace(ls_request1, "$Login_Name$", prg.LoginName)
    ls_request1 = Replace(ls_request1, "$Lang_Login$", gut_LangLogin.Code)
    ls_request1 = Replace(ls_request1, "$Lang_Work$", gut_LangWork.Code)
    li_Position = InStr(1, ls_request1, "$", vbTextCompare)
    If li_Position <> 0 Then li_position1 = InStr(li_Position + 1, ls_request1, "$", vbTextCompare)
    Do While li_Position <> 0 And li_position1 <> 0
        ls_Info = ""
        ls_Text = Mid(ls_request1, li_Position + 1, li_position1 - li_Position - 1)
        li_position2 = InStr(1, ls_Text, ":", vbTextCompare)
        If li_position2 = 0 Then
            ls_Component = ls_Text
            Select Case mt_ObjectList(mo_ComponentsIndex(ls_Component)).ComponentType
                Case Component_Type.Text
                    ls_Info = mo_Components(ls_Component).Text
                Case Component_Type.Label, Component_Type.Form, Component_Type.Frame
                    ls_Info = mo_Components(ls_Component).Caption
                Case Component_Type.Date
                    ls_Info = mo_Components(ls_Component).GetUSDate
            End Select
        Else
            ls_InfoType = Mid(ls_Text, li_position2 + 1)
            ls_Component = Mid(ls_Text, 1, li_position2 - 1)
            
            Select Case mt_ObjectList(mo_ComponentsIndex(ls_Component)).ComponentType
                Case Component_Type.ComboBox
                    If ls_InfoType = "Code" Then
                        ls_Info = MCombo_GetCode(mo_Components(ls_Component))
                    End If
                    If ls_InfoType = "Desc" Then
                        ls_Info = mo_Components(ls_Component).Text
                    End If
                Case Component_Type.ImageCombo
                    If ls_InfoType = "Code" Then
                        If Not mo_Components(ls_Component).SelectedItem Is Nothing Then
                            ls_Info = mo_Components(ls_Component).SelectedItem.Key
                        End If
                    End If
                    If ls_InfoType = "Desc" Then
                        ls_Info = mo_Components(ls_Component).Text
                    End If
            End Select
        End If
        
        ls_request1 = Replace(ls_request1, "$" & ls_Text & "$", ls_Info)
 
        li_Position = InStr(li_Position + Len(ls_Info), ls_request1, "$", vbTextCompare)
        If li_Position <> 0 Then li_position1 = InStr(li_Position + 1, ls_request1, "$", vbTextCompare)
    Loop
    
    AnalyzeRequest = ls_request1

End Function

Private Function AnalyzeValue(ls_Value As String) As String
Dim ls_Value1 As String

    ls_Value1 = ls_Value
    ls_Value1 = Replace(ls_Value1, "$Year$", Year(Now))
    ls_Value1 = Replace(ls_Value1, "$Month$", Format(Month(Now), "00"))
    ls_Value1 = Replace(ls_Value1, "$Day$", Format(Day(Now), "00"))
    ls_Value1 = Replace(ls_Value1, "$Date$", Format(Day(Now), "00") & "/" & Format(Month(Now), "00") & "/" & Year(Now))
    
    AnalyzeValue = ls_Value1

End Function

Public Sub Refresh_Screen(ls_Grid As String)
Dim ls_Req As String
Dim li_Count As Integer
Dim li_Status As Integer
Dim li_Count25 As Integer
Dim lb_Exit As Boolean
Dim i As Integer
Dim j As Integer
Dim li_NBcol As Integer
Dim lo_Grid As Object
Dim ll_NbRows As Long

    Set lo_Grid = mo_Components(ls_Grid)
    ls_Req = AnalyzeRequest(mt_ObjectList(lo_Grid.Index).FillRequest)
    
    On Error GoTo Refresh_Err

    'pic_next25.Visible = KO

    ' Columns header (invisible grid)
    lo_Grid.Rows = 2
    For li_Count = 0 To lo_Grid.Cols - 1
        lo_Grid.TextMatrix(1, li_Count) = ""
    Next li_Count
    
    ll_NbRows = 0
    li_Status = mo_Fetch.ExecuteQry(ls_Req, OK)

    If li_Status Then
        ml_TotCount = mo_Fetch.RowCount
    End If

    lb_Exit = KO

    li_NBcol = mo_Fetch.NbCol

    'if the serverCursor is true, we must make only one round
    'in the other case, we must read all the data
'    Do While (mb_ServerCursor = True And lb_Exit = False) Or (mb_ServerCursor = False And mi_NbRows <> ml_TotCount + 1)
    Do While lb_Exit = KO
        li_Count = mo_Fetch.FillMore
        If li_Count = 0 Then Exit Do
        For i = 1 To li_Count
            'Grid.Rows = mi_NbRows + 1
            If Not (Grid.Rows = 2 And i = 1) Then Grid.Rows = Grid.Rows + 1
            'Grid.Row = mi_NbRows
            For j = 1 To li_NBcol
                'Grid.col = j - 1
                Grid.TextMatrix(Grid.Rows - 1, j - 1) = mo_Fetch.GetData(i, j)
            Next
            ll_NbRows = ll_NbRows + 1
        Next
        'lb_Exit = True
    Loop

    If mt_ObjectList(lo_Grid.Index).Total <> "" Then
        mo_Components(mt_ObjectList(lo_Grid.Index).Total).Text = Str(ll_NbRows)
    End If

    Grid.Col = 0
    Grid.ColSel = Grid.Cols - 1
    
    If mt_ObjectList(lo_Grid.Index).CallAfterFillRequest <> "" Then
        CallByName mo_GenericFunctions, mt_ObjectList(lo_Grid.Index).CallAfterFillRequest, VbMethod, mo_Components
    End If

'we must make the "more 25" image visible or not
'If li_count = mo_Fetch.MaxRowCount And mi_NbRows <> ml_TotCount + 1 Then
'    pic_next25.Visible = OK
'Else
'    pic_next25.Visible = KO
'End If

    Exit Sub

Refresh_Err:
    'pic_next25.Visible = KO
    StdError
End Sub

Private Sub Check_Security()
Dim ls_Req As String
Dim li_Status As Integer
Dim ll_Statement As Long
Dim lo_list As New Collection
Dim ls_Action As String
Dim i As Integer
Dim j As Integer
Dim lb_Found As Boolean
    
    On Error GoTo Check_Security_Err

    ls_Req = AnalyzeRequest(mt_ObjectList(ml_FormIndex).FillRequest)
    
    If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_Req) Then
        li_Status = SQL_SUCCESS
        
        Do While li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO
            li_Status = SQLFetch(ll_Statement)
            If li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO Then
                ls_Action = ODBCData(ll_Statement, 1)
                
                lo_list.Add ls_Action
                
            End If
        Loop
    
        li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
        
    End If

    For i = 0 To UBound(mt_ObjectList) - 1
        If mt_ObjectList(i).Role <> "" Then
            lb_Found = KO
            For j = 1 To lo_list.Count
                If lo_list(j) = mt_ObjectList(i).Role Then
                    lb_Found = OK
                    Exit For
                End If
            Next
            If lb_Found = KO Then
                mo_Components(i).Visible = KO
                mt_ObjectList(i).Visible = KO
            End If
        End If
    Next

    Exit Sub
    
Check_Security_Err:
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    Exit Sub
End Sub
