VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.1#0"; "mscomctl.ocx"
Begin VB.Form ONSV_ItemPicker 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "BU_CODE"
   ClientHeight    =   4080
   ClientLeft      =   2760
   ClientTop       =   3750
   ClientWidth     =   5985
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   MousePointer    =   1  'Arrow
   ScaleHeight     =   4080
   ScaleWidth      =   5985
   ShowInTaskbar   =   0   'False
   Begin VB.TextBox txt_dataVersion 
      Height          =   330
      Left            =   5205
      TabIndex        =   15
      Top             =   1545
      Width           =   600
   End
   Begin VB.TextBox txt_firstRow 
      Height          =   330
      Left            =   1995
      Locked          =   -1  'True
      TabIndex        =   10
      Top             =   915
      Width           =   600
   End
   Begin VB.TextBox txt_Data_Year 
      Height          =   330
      Left            =   2700
      TabIndex        =   9
      Top             =   1545
      Width           =   1035
   End
   Begin Project1.ArmCombobox cbo_dataType 
      Height          =   345
      Left            =   2700
      TabIndex        =   7
      Top             =   1935
      Width           =   3105
      _ExtentX        =   5477
      _ExtentY        =   609
   End
   Begin MSComctlLib.ListView lv_items 
      Height          =   1215
      Left            =   2700
      TabIndex        =   2
      Top             =   90
      Width           =   3120
      _ExtentX        =   5503
      _ExtentY        =   2143
      View            =   3
      LabelWrap       =   0   'False
      HideSelection   =   0   'False
      HideColumnHeaders=   -1  'True
      GridLines       =   -1  'True
      _Version        =   393217
      ForeColor       =   -2147483640
      BackColor       =   -2147483643
      BorderStyle     =   1
      Appearance      =   1
      NumItems        =   1
      BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         Text            =   "Sheet name"
         Object.Width           =   4940
      EndProperty
   End
   Begin VB.CommandButton CancelButton 
      Cancel          =   -1  'True
      Caption         =   "Cancel"
      Height          =   375
      Left            =   3165
      TabIndex        =   1
      Top             =   3540
      Width           =   1215
   End
   Begin VB.CommandButton OKButton 
      Caption         =   "OK"
      Default         =   -1  'True
      Height          =   375
      Left            =   4590
      TabIndex        =   0
      Top             =   3540
      Width           =   1215
   End
   Begin Project1.ArmCombobox cbo_BU_Code 
      Height          =   345
      Left            =   2700
      TabIndex        =   8
      Top             =   2325
      Width           =   3105
      _ExtentX        =   5477
      _ExtentY        =   609
   End
   Begin Project1.ArmCombobox cbo_MG_Code 
      Height          =   345
      Left            =   2700
      TabIndex        =   12
      Top             =   2745
      Visible         =   0   'False
      Width           =   3105
      _ExtentX        =   5477
      _ExtentY        =   609
   End
   Begin VB.Label lbl_labels 
      Alignment       =   1  'Right Justify
      Caption         =   "Data version"
      Height          =   300
      Index           =   6
      Left            =   4035
      TabIndex        =   14
      Top             =   1575
      Width           =   1050
   End
   Begin VB.Label lbl_labels 
      Caption         =   "Material group"
      Height          =   300
      Index           =   4
      Left            =   165
      TabIndex        =   13
      Top             =   2767
      Visible         =   0   'False
      Width           =   2100
   End
   Begin VB.Label lbl_labels 
      Caption         =   "First valid row"
      Height          =   300
      Index           =   5
      Left            =   165
      TabIndex        =   11
      Top             =   945
      Width           =   1530
   End
   Begin VB.Label lbl_labels 
      Caption         =   "BU_CODE"
      Height          =   300
      Index           =   3
      Left            =   165
      TabIndex        =   6
      Top             =   2370
      Width           =   2100
   End
   Begin VB.Label lbl_labels 
      Caption         =   "Data type"
      Height          =   300
      Index           =   2
      Left            =   165
      TabIndex        =   5
      Top             =   1980
      Width           =   2100
   End
   Begin VB.Label lbl_labels 
      Caption         =   "Data year"
      Height          =   300
      Index           =   1
      Left            =   165
      TabIndex        =   4
      Top             =   1575
      Width           =   2100
   End
   Begin VB.Label lbl_labels 
      Caption         =   "Excell sheet"
      Height          =   300
      Index           =   0
      Left            =   165
      TabIndex        =   3
      Top             =   120
      Width           =   2100
   End
End
Attribute VB_Name = "ONSV_ItemPicker"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Const SEP = "ой"

Public Result As Boolean
Public Data_Year As String
Public BU_code As String
'Public MG_Code As String
Public Data_Type As String
Public Data_version As String
Public FirstRow As Long
Public XLSSheetName As String

Private ms_Language_Code As String

Private mo_Db As ARMSYSCOMLib.ArmDb

Public Property Set Db(ByRef ao_db As ArmDb)
    Set mo_Db = ao_db
End Property

Public Sub Load_A_Com()
    Result = False
    Data_Year = ""
    BU_code = ""
    Data_Type = ""
    ms_Language_Code = "E"
    FirstRow = 0
    XLSSheetName = ""
    Data_version = ""
    
    
    Dim lo_control As Object
    
    For Each lo_control In Controls
        Select Case UCase(TypeName(lo_control))
        Case "ARMCOMBOBOX"
          Set lo_control.ArmDb = mo_Db
          Call lo_control.Load_A_Com
        Case "ARMPICKER"
          Set lo_control.ArmDb = mo_Db
          Call lo_control.Load_A_Com
        Case "TOOLBARCONTROL"
          lo_control.Language = ms_Language_Code
'          Set lo_Control.ArmDb = mo_Db
          Call lo_control.Load_A_Com
        Case "ARMGRID"
          Set lo_control.ArmDb = mo_Db
          Call lo_control.Load_A_Com
        Case "ARMTREEVIEW"
          Set lo_control.ArmDb = mo_Db
          lo_control.Language = ms_Language_Code
          Call lo_control.Load_A_Com
        Case "ARMCHECKVIEW"
          Set lo_control.ArmDb = mo_Db
          Call lo_control.Load_A_Com
        Case "A_CALOCX"
          lo_control.Language = ms_Language_Code
          Call lo_control.reinit_cal
        Case "TOOLBR"
          Set lo_control.ArmDb = mo_Db
          Call lo_control.Load_A_Com
        End Select
    Next

    
    txt_Data_Year.Text = Year(Now)
    txt_firstRow.Enabled = False
    txt_firstRow.Text = ""
    
    cbo_dataType.FirstBlankItem = False
    cbo_dataType.AddItem (Array("BDG", "Budget"))
    cbo_dataType.AddItem (Array("FCT", "Forecast"))
    cbo_dataType.AddItem (Array("EST", "Estimate"))
    
    cbo_BU_Code.FirstBlankItem = False
    cbo_BU_Code.Enabled = False
    
    cbo_BU_Code.Request = "select BU_code, BU_desc from ONSV_BU order by Desc_Order"
    Call SetComboItemValue(cbo_BU_Code, "B001")
    
    cbo_MG_Code.FirstBlankItem = False
    cbo_MG_Code.Request = "select MG_Code, MG_Desc from [dbo].[ONSV_Material_Group] WHERE Language_code='E' ORDER BY Desc_Order"

End Sub

Public Property Let Title(ByVal as_caption As String)
    Me.Caption = as_caption
End Property

Public Function AddItem(ByVal as_Key As String, ByVal as_desc As String) As ListItem
    Set AddItem = lv_items.ListItems.Add(, as_Key, as_desc)
End Function

Private Sub CancelButton_Click()
    Result = False
    
    Unload Me
End Sub

'Private Sub lv_items_DblClick()
'    If Item_Check Then
'        Call Item_Save
'        Unload Me
'    End If
'End Sub

Public Sub lv_items_ItemClick(ByVal Item As MSComctlLib.ListItem)
    Dim lsa_data() As String
    lsa_data = Split(Item.Tag, SEP)
    txt_firstRow.Text = lsa_data(2)
    
    If lsa_data(0) <> "" Then
        txt_Data_Year.Text = lsa_data(0)
    End If
    
    If lsa_data(1) <> "" Then
        Call SetComboItemValue(cbo_dataType, lsa_data(1))
    End If
    
'    If InStr(1, Item.Text, "Metal", vbTextCompare) > 0 Then
'        Call SetComboItemValue(cbo_MG_Code, "M002")
'    ElseIf InStr(1, Item.Text, "Grid", vbTextCompare) > 0 Then
'        Call SetComboItemValue(cbo_MG_Code, "M003")
'    ElseIf InStr(1, Item.Text, "MF", vbTextCompare) > 0 Then
'        Call SetComboItemValue(cbo_MG_Code, "M001")
'    End If
    
    If lsa_data(3) <> "" Then
        txt_dataVersion.Text = lsa_data(3)
    End If
    
End Sub

Private Sub OKButton_Click()
    If Item_Check Then
        Call Item_Save
        Unload Me
    End If
End Sub

Private Sub Item_Save()
    Result = True
    
    FirstRow = txt_firstRow.Text
    XLSSheetName = lv_items.SelectedItem.Key
    
    BU_code = cbo_BU_Code.SelectedItem.Key
    Data_Type = cbo_dataType.SelectedItem.Key
'    MG_Code = cbo_MG_Code.SelectedItem.Key
    Data_Year = Trim(txt_Data_Year.Text)
    Data_version = Trim(txt_dataVersion.Text)
End Sub

Private Function Item_Check() As Boolean
    Item_Check = False
    
    If lv_items.SelectedItem Is Nothing Then
        MsgBox ("Select item please.")
        Exit Function
    End If
    
    If cbo_BU_Code.SelectedItem Is Nothing Then
        MsgBox ("Select BU_CODE please.")
        Exit Function
    End If
    
    If cbo_dataType.SelectedItem Is Nothing Then
        MsgBox ("Select Data type please.")
        Exit Function
    End If

'    If cbo_MG_Code.SelectedItem Is Nothing Then
'        MsgBox ("Select Material group please.")
'        Exit Function
'    End If

    If Not isNumeric(txt_Data_Year.Text) Then
        MsgBox ("Invalid value in Data Year.")
        Exit Function
    End If
    
    If Not isNumeric(txt_dataVersion.Text) Then
        MsgBox ("Invalid value in Data Version.")
        Exit Function
    End If
    
    Item_Check = True
End Function

Private Function SetComboItemValue(ByRef ao_cbo As ArmCombobox, ByVal as_Key As String) As Boolean
On Error GoTo ErrorHandler
    SetComboItemValue = True
    If Not ao_cbo.SearchItem(as_Key) Then
        Call ao_cbo.Load
        SetComboItemValue = ao_cbo.SearchItem(as_Key)
    End If
    Exit Function
ErrorHandler:
    SetComboItemValue = False
End Function
