VERSION 5.00
Begin VB.UserControl cboPrd 
   ClientHeight    =   390
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   2715
   LockControls    =   -1  'True
   ScaleHeight     =   390
   ScaleWidth      =   2715
   Begin Project1.ArmCombobox cbo_short_code 
      Height          =   345
      Left            =   0
      TabIndex        =   1
      Top             =   0
      Width           =   2175
      _extentx        =   3836
      _extenty        =   609
   End
   Begin VB.CommandButton cmd_product 
      Caption         =   "..."
      Height          =   315
      Left            =   2160
      TabIndex        =   0
      Top             =   0
      Width           =   315
   End
End
Attribute VB_Name = "cboPrd"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

'Curseur & données
Private mo_ArmDb As Object
Private mb_Created As Boolean
Private mb_use_framework_connection As Boolean
Private ms_ConnectString As String
Private ms_UID As String

Private m_Language As String

Private ms_SelectedItemCode As String
Private ms_SelectedItemDesc As String
Private mi_SysClassifCode As Integer
Private mi_CPTCode As Integer
Private mb_CmdVisible As Boolean
Private ms_CT_Code As String                   '  Logistic market, use to filter the list of product


Public Event Change()

Public Property Set ArmDb(ByRef ao_local_connection As Object)
    If Not (ao_local_connection Is Nothing) Then
        
        Set mo_ArmDb = ao_local_connection
        mb_use_framework_connection = True
        
        Set cbo_short_code.ArmDb = mo_ArmDb
        'Connection
        
    End If
End Property

Public Property Get Font() As StdFont
  
  Set Font = cbo_short_code.Font

End Property

Property Let ConnectString(as_ConnectString As String)
    
    ms_UID = ConnectionStringValidation(as_ConnectString)
    If ms_UID = "" Then Exit Property
    
    ms_ConnectString = as_ConnectString
    cbo_short_code.ConnectString = ms_ConnectString
    
End Property

Property Let Language(ALng As String)
    m_Language = ALng
End Property

Property Let SysClassifCode(ai_SC_code As Integer)
    mi_SysClassifCode = ai_SC_code
    ReinitCmdProductVisible
End Property

Property Let CompetitorCode(ai_CPT_code As Integer)
    mi_CPTCode = ai_CPT_code
    ReinitCmdProductVisible
End Property

Property Let Enabled(ATag As Boolean)
    cbo_short_code.Enabled = ATag
    cmd_product.Enabled = ATag
End Property

Public Sub LetSelectedItem(as_Code As String, as_desc As String)
    ms_SelectedItemCode = as_Code
    ms_SelectedItemDesc = as_desc
    If ms_SelectedItemCode <> "" Then
        If cbo_short_code.Count > 0 Then
            cbo_short_code.SearchItem as_Code, 0, -1
        Else
            cbo_short_code.AddItem Array(as_Code, as_desc), True
        End If
    End If
End Sub

Public Property Get SelectedItemCode() As String
    SelectedItemCode = ms_SelectedItemCode
End Property

Public Property Get SelectedItemDesc() As String
    SelectedItemDesc = ms_SelectedItemDesc
End Property


Public Property Get CT_Code() As String
    CT_Code = ms_CT_Code
End Property

Public Property Let CT_Code(ByVal as_Value As String)
    ms_CT_Code = as_Value
End Property
    

Public Sub Clear()
    
    mb_CmdVisible = False
    
    ClearCombo
    
    UserControl_Resize
    
End Sub

Private Sub ClearCombo()
    
    ms_SelectedItemCode = ""
    ms_SelectedItemDesc = ""

    cbo_short_code.Clear
    
End Sub

Public Sub Load_A_COM()
    
    On Error GoTo Load_A_Com_Err
    
    VerifyInitialization mo_ArmDb, ms_ConnectString, m_Language, Me
    
    cbo_short_code.Load_A_COM
    
    cbo_short_code.FirstBlankItem = False
    
    ' Wrong, filters are initialized AFTER, and in all case the reinit function is called
    'cbo_short_code.Request = "exec cap_system_cbo2 " & mi_SysClassifCode & "," & mi_CPTCode & ",'" & m_Language & "'"
    
    mb_CmdVisible = False
    
    mi_SysClassifCode = 1
    mi_CPTCode = 0
    
fin:
    Exit Sub

Load_A_Com_Err:
    Call ASC_SendMessage(mo_ArmDb, m_Language, 891, "#An error occured during this manipulation, please contact your IT support")
    GoTo fin

End Sub

Public Sub Unload_A_COM()

   cbo_short_code.Unload_A_COM
   
   ASC_DisconnectFromDB mo_ArmDb, ms_UID, mb_Created

End Sub

Private Sub cbo_short_code_ComboItemSelected()

    ms_SelectedItemCode = GetCodeFromCombo(cbo_short_code)
    ms_SelectedItemDesc = GetTextFromCombo(cbo_short_code)

End Sub

Private Sub cmd_product_Click()
Dim lo_Form As PrdSeek
Dim ls_SelectedItemCode As String
Dim ls_SelectedItemDesc As String

    Set lo_Form = New PrdSeek
    Load lo_Form
    lo_Form.ConnectString = ms_ConnectString
    If mb_use_framework_connection = True Then Set lo_Form.ArmDb = mo_ArmDb
    lo_Form.Language = m_Language
    lo_Form.CT_Code = ms_CT_Code
    
    lo_Form.SysClassifCode = mi_SysClassifCode
    
    lo_Form.Load_A_COM
    CapMouseOn True
    
    lo_Form.show vbModal
    CapMouseOff True
    
    ls_SelectedItemCode = lo_Form.SelectedItemCode
    ls_SelectedItemDesc = lo_Form.SelectedItemDesc
   
    lo_Form.Unload_A_COM
    Unload lo_Form
    Set lo_Form = Nothing
    
    If ls_SelectedItemCode <> "" Then
        cbo_short_code.SearchItem ls_SelectedItemCode, 0, -1
        If cbo_short_code.SelectedItem Is Nothing Then
            cbo_short_code.AddItem Array(ls_SelectedItemCode, ls_SelectedItemDesc), True
        End If
        ms_SelectedItemCode = ls_SelectedItemCode
        ms_SelectedItemDesc = ls_SelectedItemDesc
        RaiseEvent Change
    End If

End Sub

Private Sub UserControl_Resize()
    cbo_short_code.Top = 0
    cbo_short_code.Left = 0
    cmd_product.Top = 0
    
    If mb_CmdVisible = True Then
   
        If UserControl.Width < cmd_product.Width Then
            UserControl.Width = cmd_product.Width
        End If
        
        cbo_short_code.Width = UserControl.Width - cmd_product.Width
        cmd_product.Left = cbo_short_code.Width
    Else
        cbo_short_code.Width = UserControl.Width
    End If
End Sub

Private Sub ReinitCmdProductVisible()
    
    ClearCombo
    
    Dim ls_Request As String
    Select Case mi_SysClassifCode
        Case 1  ' Ceilings
                If mi_CPTCode = 1 Then
                    ls_Request = "exec cap_system_cbo4 " & mi_SysClassifCode & "," & mi_CPTCode & ",'" & m_Language & "', '" & ms_CT_Code & "'"
    Else
                    ls_Request = "exec cap_system_cbo2 " & mi_SysClassifCode & "," & mi_CPTCode & ",'" & m_Language & "'"
    End If
        Case 2  ' Grids
            ls_Request = "exec cap_system_cbo3 " & mi_SysClassifCode & "," & mi_CPTCode & ",'" & m_Language & "'"
        Case 3  ' Accessories
            ls_Request = "exec cap_system_cbo2 " & mi_SysClassifCode & "," & mi_CPTCode & ",'" & m_Language & "'"
        Case 4 ' AS
        ls_Request = "exec cap_system_cbo5 " & mi_SysClassifCode & "," & mi_CPTCode & ",'" & m_Language & "'"
        Case 5 ' Wall
            ls_Request = "exec cap_system_cbo5 " & mi_SysClassifCode & "," & mi_CPTCode & ",'" & m_Language & "'"
    End Select
    cbo_short_code.Request = ls_Request
    
    Select Case mi_CPTCode
    Case 1
        Select Case mi_SysClassifCode
        Case 1
        mb_CmdVisible = True
        Case 2, 3, 4, 5
        mb_CmdVisible = False
        End Select
    Case Else
        mb_CmdVisible = False
    End Select
    
    UserControl_Resize
    cmd_product.Visible = mb_CmdVisible

End Sub

Public Sub SetFocus()
    
    On Error Resume Next

    cbo_short_code.SetFocus
    
End Sub

