VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomctl.ocx"
Begin VB.UserControl CapCustOf 
   ClientHeight    =   4515
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   14025
   ScaleHeight     =   4515
   ScaleWidth      =   14025
   Begin VB.TextBox txt_Desc 
      Enabled         =   0   'False
      Height          =   375
      Left            =   5085
      TabIndex        =   2
      Top             =   825
      Width           =   5985
   End
   Begin Project1.ToolBr pbItem 
      Align           =   1  'Align Top
      Height          =   600
      Left            =   0
      TabIndex        =   0
      Top             =   0
      Width           =   14025
      _ExtentX        =   24739
      _ExtentY        =   1058
   End
   Begin MSComctlLib.ListView lv_Customers 
      Height          =   3015
      Left            =   30
      TabIndex        =   1
      Top             =   1305
      Width           =   11070
      _ExtentX        =   19526
      _ExtentY        =   5318
      View            =   3
      LabelEdit       =   1
      LabelWrap       =   -1  'True
      HideSelection   =   -1  'True
      Checkboxes      =   -1  'True
      FullRowSelect   =   -1  'True
      _Version        =   393217
      ForeColor       =   -2147483640
      BackColor       =   -2147483643
      BorderStyle     =   1
      Appearance      =   1
      NumItems        =   6
      BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         Object.Tag             =   "c1"
         Text            =   "#Installed"
         Object.Width           =   1411
      EndProperty
      BeginProperty ColumnHeader(2) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   1
         Object.Tag             =   "c2"
         Text            =   "#Name"
         Object.Width           =   4410
      EndProperty
      BeginProperty ColumnHeader(3) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   2
         Object.Tag             =   "c3"
         Text            =   "#SA"
         Object.Width           =   882
      EndProperty
      BeginProperty ColumnHeader(4) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   3
         Object.Tag             =   "c4"
         Text            =   "#Activity"
         Object.Width           =   3528
      EndProperty
      BeginProperty ColumnHeader(5) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   4
         Object.Tag             =   "c5"
         Text            =   "#Zip"
         Object.Width           =   2540
      EndProperty
      BeginProperty ColumnHeader(6) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   5
         Object.Tag             =   "c6"
         Text            =   "#Phone"
         Object.Width           =   2540
      EndProperty
   End
   Begin VB.Label lbl_Desc 
      Alignment       =   1  'Right Justify
      Caption         =   "#Project Name"
      Height          =   255
      Left            =   2250
      TabIndex        =   3
      Tag             =   "lbl_Desc"
      Top             =   900
      Width           =   2655
   End
End
Attribute VB_Name = "CapCustOf"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

'******** Curseur de connexion
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 mb_DoCheck As Boolean

Private m_Language As String

Public mt_CstValues As Type_CstValues          ' Structure which contains constants value

Private ms_SP As String                 ' Sales Project ID
Private mi_Conc As Integer

Private p_CountRec As Integer
Private mb_Validated As Boolean


Public Event quit()

Public Property Set ArmDb(ByRef ao_local_connection As Object)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "CustOf:ArmDb_Set"
    #End If
    CapMouseOff
    
    If Not (ao_local_connection Is Nothing) Then
        Set mo_ArmDb = ao_local_connection
        mb_use_framework_connection = True
        Set pbitem.ArmDb = mo_ArmDb
    End If

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "CustOf:ArmDb_Set"
    #End If
    CapMouseOn
End Property

Property Let ConnectString(as_ConnectString As String)
    
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "CustOf:ConnectString_Let", "as_ConnectString=" & as_ConnectString
    #End If
    CapMouseOff
    
    ms_UID = ConnectionStringValidation(as_ConnectString)
    If ms_UID = "" Then GoTo Trace_End
    
    ms_ConnectString = as_ConnectString
    pbitem.ConnectString = ms_ConnectString
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "CustOf:ConnectString_Let"
    #End If
    CapMouseOn
End Property

Property Let Language(ALng As String)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "CustOf:Language_Let", "ALng=" & ALng
    #End If
    CapMouseOff
    
    m_Language = ALng
    pbitem.Language = m_Language
    
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "CustOf:Language_Let"
    #End If
    CapMouseOn
End Property

Public Property Get Validated() As Boolean
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "CustOf:Validated_Get"
    #End If
    CapMouseOff
    
    Validated = mb_Validated
    
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "CustOf:Validated_Get", "Result=" & Validated
    #End If
    CapMouseOn
End Property

Property Get CountRec() As Integer
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "CustOf:CountRec_Get"
    #End If
    CapMouseOff
    
    CountRec = p_CountRec
    
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "CustOf:CountRec_Get", "Result=" & CountRec
    #End If
    CapMouseOn
End Property

Private Sub ShowLink(AActionType As String)
Dim TheLinkForm As LinkForm

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "CustOf:ShowLink", "AActionType=" & AActionType
    #End If
    
    Set TheLinkForm = New LinkForm
    
    Set TheLinkForm.mt_CstValues = mt_CstValues
    TheLinkForm.ConnectString = ms_ConnectString
    If mb_use_framework_connection = True Then
        Set TheLinkForm.ArmDb = mo_ArmDb
    End If
    
    TheLinkForm.Language = m_Language
    TheLinkForm.project = ms_SP
    
    TheLinkForm.Customer = ""
    
    TheLinkForm.SQLActionType = AActionType
    
    TheLinkForm.Load_A_Com
    
    CapMouseOn True
    TheLinkForm.show vbModal
    CapMouseOff True
    
    Set TheLinkForm = Nothing
    
    LoadListView
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "CustOf:ShowLink"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "CustOf:ShowLink"
    CapMouseOn
End Sub

Property Let iConc(AiConc As Integer)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "CustOf:iConc_Let", "AiConc=" & AiConc
    #End If
    CapMouseOff
    
    mi_Conc = AiConc
    
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "CustOf:iConc_Let"
    #End If
    CapMouseOn
End Property

Public Property Get project() As String
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "CustOf:Project_Get"
    #End If
    CapMouseOff
    
    project = ms_SP
    
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "CustOf:Project_Get", "Result=" & project
    #End If
    CapMouseOn
End Property


Public Property Let project(ByVal as_ProjectKey As String)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "CustOf:Project_Let", "as_ProjectKey=" & as_ProjectKey
    #End If
    CapMouseOff
    
    ms_SP = as_ProjectKey
    
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "CustOf:Project_Let"
    #End If
    CapMouseOn
End Property

Public Sub Display()
Dim ll_Cursor As Long

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "CustOf:Display"
    #End If
    
    LoadListView
    
    Dim TheRequest As String
    TheRequest = "exec sales_project_t_sel4 " & "'" & ms_SP & "', 'E'"
    ll_Cursor = mo_ArmDb.OpenSQL(TheRequest, -1, 0)
    If ll_Cursor = 0 Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError mo_ArmDb, "PrdValOf:Display", "Request=" & TheRequest
        GoTo Trace_End
    End If
    txt_desc = mo_ArmDb.GetFields(ll_Cursor, "SP_desc")

Trace_End:
    mo_ArmDb.Close ll_Cursor
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "CustOf:Display"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    mo_ArmDb.Close ll_Cursor
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "CustOf:Display"
    CapMouseOn
End Sub

Private Function Check() As Boolean
Dim ll_Count As Long
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "CustOf:Check"
    #End If
    
    If Not mb_DoCheck Then
        Check = True
        GoTo Trace_End
    End If

    ll_Count = lv_Customers.ListItems.Count

    While ll_Count > 0
        If lv_Customers.ListItems.Item(ll_Count).Checked Then
            Check = True
            GoTo Trace_End
        End If
        ll_Count = ll_Count - 1
    Wend
    Call ASC_SendMessage(mo_ArmDb, m_Language, 205, "#You must choose at least one customer")
        
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "CustOf:Check", "Result=" & Check
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "CustOf:Check"
    CapMouseOn
End Function

Private Sub LoadListView()
Dim ln_Node As ListItem
Dim ls_LRcode As String
Dim ls_Req As String
Dim ls_LRdesc As String
Dim ll_Cursor As Long

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "CustOf:LoadListView"
    #End If
    
    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End
    
    ls_Req = "exec cap_projectcompany_t_lst2 " & "'" & ms_SP & "', '" & m_Language & "'"
    ll_Cursor = mo_ArmDb.OpenSQL(ls_Req, -1, 0)
    If ll_Cursor = 0 Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError mo_ArmDb, "CustOf:LoadListView", "Request=" & ls_Req
        GoTo Trace_End
    End If
    
    p_CountRec = mo_ArmDb.RowCount(ll_Cursor)
    
    lv_Customers.ListItems.Clear
    mo_ArmDb.First ll_Cursor
    Do Until mo_ArmDb.EOF(ll_Cursor)
        Set ln_Node = lv_Customers.ListItems.Add
        ln_Node.Text = ""
        ln_Node.Tag = mo_ArmDb.GetFields(ll_Cursor, "CCU_capkey")
        txt_desc = mo_ArmDb.GetFields(ll_Cursor, "SP_desc")
' task 299.5 change from X to I
        ln_Node.Checked = IIf(mo_ArmDb.GetFields(ll_Cursor, "PC_InstallatorFlag") = "I", 1, 0)
        ln_Node.SubItems(1) = mo_ArmDb.GetFields(ll_Cursor, "CCU_desc")
        ln_Node.SubItems(2) = mo_ArmDb.GetFields(ll_Cursor, "CCU_SAFlag")
        ln_Node.SubItems(3) = mo_ArmDb.GetFields(ll_Cursor, "CCT_desc")
        ln_Node.SubItems(4) = mo_ArmDb.GetFields(ll_Cursor, "CCU_Zip")
        ln_Node.SubItems(5) = mo_ArmDb.GetFields(ll_Cursor, "CCU_Tel")
        mo_ArmDb.Next ll_Cursor
    Loop
    
Trace_End:
    mo_ArmDb.Close ll_Cursor
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "CustOf:LoadListView"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    mo_ArmDb.Close ll_Cursor
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "CustOf:LoadListView"
    CapMouseOn
End Sub

Public Function Save() As Boolean
Dim i As Long
Dim ll_ListCount As Long
Dim lb_Success As Boolean
Dim ls_Flag As String
Dim ls_Request As String
Dim lb_Result As Boolean
Dim ls_Result As String

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "CustOf:Save"
    #End If
    
    Save = False
    
    ll_ListCount = lv_Customers.ListItems.Count
    
    ' X = false
    ' I = instal
    ' N = n/a
    ls_Flag = "X"

    If Not mb_DoCheck Then
        ls_Flag = "N"
        For i = 1 To ll_ListCount
            If lv_Customers.ListItems.Item(i).Checked Then
                ls_Flag = "X"
                Exit For
            End If
        Next
    End If
    
    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End
    
    For i = 1 To ll_ListCount
        ErrorOFF
        If Not (Trim$(ms_SP) <> "") And (Trim$(lv_Customers.ListItems.Item(i).Tag) <> "") Then
            ErrorON
        End If
        
        ls_Request = "Exec Cap_ProjectCompany_upd "
        
        ls_Request = ls_Request & "  '" & ms_SP & "'"
        ls_Request = ls_Request & ", '" & lv_Customers.ListItems.Item(i).Tag & "'"
        ls_Request = ls_Request & ", '" & IIf(lv_Customers.ListItems.Item(i).Checked, "I", ls_Flag) & "'"
        
        'Execution
        If ErrorFound Then GoTo Trace_End
        
        lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_Result)
        If lb_Result = False Then GoTo Trace_End
    Next
        
    ' Update the dropped company to set as not installed
    ls_Request = "exec Cap_ProjectCompany_UpdDropped '" & ms_SP & "'"
    If Not ASC_RecordExec(mo_ArmDb, ls_Request, ls_Result) Then GoTo Trace_End
        
    Save = True
        
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "CustOf:Save"
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "CustOf:Save"
    CapMouseOn
End Function

Public Sub Load_A_Com()

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "CustOf:Load_A_Com"
    #End If
    
    VerifyInitialization mo_ArmDb, ms_ConnectString, m_Language, Me
    
    pbitem.Load_A_Com
    pbitem.DrivenByCapture = True
    pbitem.ClearAllIcons
    pbitem.PictureDisplayed = "P_Valid=1 P_Undo=2 P_Add=4 P_Quit=-1"
    
    
    Call LoadLabels(mo_ArmDb, UserControl.Controls, "Cap_Customer_Validation", m_Language)
    
    Call RAZ
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "CustOf:Load_A_Com"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "CustOf:Load_A_Com"
    CapMouseOn
End Sub

Public Sub Unload_A_Com()

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "CustOf:Unload_A_Com"
    #End If
    
    pbitem.Unload_A_Com
    
    Set mt_CstValues = Nothing

    ASC_DisconnectFromDB mo_ArmDb, ms_UID, mb_Created
    Set mo_ArmDb = Nothing

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "CustOf:Unload_A_Com"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "CustOf:Unload_A_Com"
    CapMouseOn
End Sub

Private Sub lv_Customers_ItemCheck(ByVal Item As MSComctlLib.ListItem)
Dim i As Integer
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "CustOf:lv_Customers_ItemCheck"
    #End If
    
    Dim ll_Idx As Long, ll_Count As Long
    ll_Count = lv_Customers.ListItems.Count
    For ll_Idx = 1 To ll_Count
        If (lv_Customers.ListItems.Item(ll_Idx).Index <> Item.Index) Then
            lv_Customers.ListItems.Item(ll_Idx).Checked = False
        End If
    Next

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "CustOf:lv_Customers_ItemCheck"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "CustOf:lv_Customers_ItemCheck"
    CapMouseOn
End Sub

Private Sub pbItem_action(ByVal as_ActionType As String)
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "CustOf:pbItem_action", "as_ActionType=" & as_ActionType
    #End If
    
    mb_Validated = False

   Select Case as_ActionType
        Case "Exit"
            RaiseEvent quit

        Case "Undo"
            LoadListView
            
        Case "Valid"
            If Check Then
                mb_Validated = True
                RaiseEvent quit
            End If
        Case "Add"
            ShowLink "Add"
        
        Case Else
            mb_Validated = False
            RaiseEvent quit
    End Select

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "CustOf:pbItem_action"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "CustOf:pbItem_action"
    CapMouseOn
End Sub

Public Property Let DoCheck(ByVal ab_DoCheck As Boolean)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "CustOf:DoCheck_Let", "ab_DoCheck =" & ab_DoCheck
    #End If
    CapMouseOff
    
    mb_DoCheck = ab_DoCheck
    
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "CustOf:DoCheck_Let"
    #End If
    CapMouseOn
End Property

Public Property Get DoCheck() As Boolean
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "CustOf:DoCheck_Get"
    #End If
    CapMouseOff
    
    DoCheck = mb_DoCheck
    
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "CustOf:DoCheck_Get", "Result =" & mb_DoCheck
    #End If
    CapMouseOn
End Property

Public Sub RAZ()
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "CustOf:RAZ"
    #End If
    CapMouseOff
    
    mb_Validated = False
    
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "CustOf:RAZ"
    #End If
    CapMouseOn
End Sub


Public Sub Refresh()
    pbitem.Refresh
End Sub

