VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "Prices"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

'Klasa Prices
Implements DBTable
Private db As DBase
Private tNames As Collection
Private rec As Recordset
Private opened As Boolean
Private prec As Recordset
Private precOpened As Boolean

Private Sub DBTable_addTableValue(nm As String)
  Dim tbn As String
  On Local Error GoTo noname
  tbn = tNames(nm)
sbexit:
  Exit Sub
noname:
  tNames.Add nm, nm
  Resume sbexit
End Sub

Private Sub DBTable_createTable(datab As DBase)
  Dim inx As Indexer
  Set db = datab
  Set tNames = New Collection
  Set inx = db.makeTable("Prices")
  inx.createKey "Pricekey"
  inx.createInteger "Foodkey"
  inx.createInteger "StoreKey"
  inx.createSingle "Price"
  inx.makeIndex "Pricekey", True
  inx.makeIndex "Foodkey", False
  inx.makeIndex "Storekey", False
  inx.addTable
End Sub

Private Function DBTable_getKey(nm As String) As Integer
  'Pusta
End Function

Private Function DBTable_getValue() As String
  'Pusta
End Function

Private Function DBTable_hasMoreElements() As Boolean
  DBTable_hasMoreElements = Not rec.EOF
End Function

Private Sub DBTable_makeTable()
  'Pusta
End Sub

Private Sub DBTable_moveFirst()
rec.moveFirst
End Sub

Private Sub DBTable_openTable()
  If Not opened Then
    Set rec = db.openTable("Prices")
    opened = True
  End If
End Sub

Private Sub DBTable_setDB(datab As DAO.Database)
  Set db = datab
End Sub

Public Sub addRow(storekey As Integer, foodkey As Integer, price As Single)
  DBTable_openTable
  rec.AddNew
  rec![storekey] = storekey
  rec![foodkey] = foodkey
  rec![price] = price
  rec.Update
End Sub

Public Sub getPrices(nm As String)
  Dim qry As String
  If precOpened Then
    prec.Close
  End If
  qry = "SELECT Foods.Foodname, Stores.StoreName, Prices.Price " & _
  "FROM Stores INNER JOIN (Foods INNER JOIN Prices ON Foods.Foodkey = Prices.Foodkey) ON Stores.StoreKey = Prices.StoreKey " & _
  "Where (((Foods.Foodname) = '" & nm & "')) " & _
  "ORDER BY Prices.Price;"

  Set prec = db.openQuery(qry)
  precOpened = True
End Sub

Public Function hasMorePrices() As Boolean
  hasMorePrices = Not prec.EOF
End Function

Public Function getPriceString() As String
  getPriceString = prec![storename] + Chr$(9) + Str$(prec![price])
  prec.MoveNext
End Function
