Public Class Form1
  Inherits System.Windows.Forms.Form
  Private db As DBase
  Private shops As Stores
  Private prc As Prices
  Private tips As ToolTip
#Region " Windows Form Designer generated code "

  Public Sub New()
    MyBase.New()

    'This call is required by the Windows Form Designer.
    InitializeComponent()

    'Add any initialization after the InitializeComponent() call
    init()
  End Sub

  'Form overrides dispose to clean up the component list.
  Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    If disposing Then
      If Not (components Is Nothing) Then
        components.Dispose()
      End If
    End If
    MyBase.Dispose(disposing)
  End Sub
  Friend WithEvents lsFoods As System.Windows.Forms.ListBox
  Friend WithEvents lsPrices As System.Windows.Forms.ListBox
  Friend WithEvents btLoad As System.Windows.Forms.Button

  'Required by the Windows Form Designer
  Private components As System.ComponentModel.Container

  'NOTE: The following procedure is required by the Windows Form Designer
  'It can be modified using the Windows Form Designer.  
  'Do not modify it using the code editor.
  <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    Me.btLoad = New System.Windows.Forms.Button()
    Me.lsPrices = New System.Windows.Forms.ListBox()
    Me.lsFoods = New System.Windows.Forms.ListBox()
    Me.SuspendLayout()
    '
    'btLoad
    '
    Me.btLoad.Location = New System.Drawing.Point(64, 232)
    Me.btLoad.Name = "btLoad"
    Me.btLoad.Size = New System.Drawing.Size(64, 24)
    Me.btLoad.TabIndex = 2
    Me.btLoad.Text = "Load"
    '
    'lsPrices
    '
    Me.lsPrices.Location = New System.Drawing.Point(192, 24)
    Me.lsPrices.Name = "lsPrices"
    Me.lsPrices.Size = New System.Drawing.Size(200, 199)
    Me.lsPrices.TabIndex = 1
    '
    'lsFoods
    '
    Me.lsFoods.Location = New System.Drawing.Point(24, 24)
    Me.lsFoods.Name = "lsFoods"
    Me.lsFoods.Size = New System.Drawing.Size(144, 199)
    Me.lsFoods.TabIndex = 0
    '
    'Form1
    '
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.ClientSize = New System.Drawing.Size(400, 273)
    Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btLoad, Me.lsPrices, Me.lsFoods})
    Me.Name = "Form1"
    Me.Text = "Facade demo"
    Me.ResumeLayout(False)

  End Sub

#End Region

  Private Sub init()
    db = New DBase("Groceries.mdb", "Access")
    shops = New Stores(db)
    prc = New Prices(db)
    loadFoodTable()
    tips = New ToolTip()
    tips.SetToolTip(btLoad, "Reload data from groceries.txt file")
  End Sub

  Private Sub btLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btLoad.Click
    lsFoods.Items.Clear()
    Me.Cursor.Current = Cursors.WaitCursor
    Dim dload As New DataLoader(db)
    dload.load("groceries.txt")
    loadFoodTable()
    Me.Cursor.Current = Cursors.Default
  End Sub
  '-----
  Private Sub loadFoodTable()
    Dim fods As New Foods(db)
    fods.openTable()
    While fods.hasMoreElements
      lsFoods.Items.Add(fods.getValue)
    End While
  End Sub
  '-----
  Private Sub lsFoods_SelectedIndexChanged( _
      ByVal sender As System.Object, _
      ByVal e As System.EventArgs) _
      Handles lsFoods.SelectedIndexChanged

    Dim food As String = lsFoods.Text
    Dim dtable As DataTable = prc.getPrices(food)
    Dim rw As DataRow
    lsPrices.Items.Clear()
    For Each rw In dtable.Rows
      lsPrices.Items.Add(rw("StoreName").ToString.Trim & _
      vbTab & rw("Price").ToString)
    Next
  End Sub
End Class
