- Public Class Cashier
- Dim Buttons(x) As Button ' Button array
- Dim Foods(x) As String ' Food array
- Dim Prices(x) As Double ' Price array
- Dim FoodID(x) As Integer ' FoodID array
- Dim x As Integer ' Used to get the array size
- Dim btn As Button ' Used to generate the buttons
- Dim y As Integer = 0 ' Counter to add foods into the array
- Dim i As Integer = 0 ' Loop couhter
- Dim temp_string As String
- Dim price As String
- Dim total As Double
- Dim display_food As String
- Private Sub Cashier_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- 'TODO: This line of code loads data into the 'TuckshopDataSet.Tuckshop' table. You can move, or remove it, as needed.
- Me.TuckshopTableAdapter.Fill(Me.TuckshopDataSet.Tuckshop)
- 'TODO: This line of code loads data into the 'TuckshopDataSet.Foods' table. You can move, or remove it, as needed.
- Me.FoodsTableAdapter.Fill(Me.TuckshopDataSet.Foods)
- txtPrice.Text = "$0"
- x = TuckshopDataSet.Foods.Count() ' Gets the length of the foods column
- ReDim Preserve Buttons(x) ' Sets the array size for the buttons
- ReDim Preserve Foods(x) ' Sets the array size for the foods
- ReDim Preserve Prices(x) ' Sets the array size for the prices
- ReDim Preserve FoodID(x) ' Sets the array size for the prices
- While y < x
- Foods(y) = TuckshopDataSet.Tuckshop(y)(1) ' Make the index of the array the index of the column
- Prices(y) = TuckshopDataSet.Tuckshop(y)(2) ' Make the index of the array the index of the column
- FoodID(y) = TuckshopDataSet.Tuckshop(y)(0) ' Make the index of the array the index of the column
- y += 1 ' Incrememnt y
- End While
- Dim Panel1 As New System.Windows.Forms.Panel ' Declares the panel
- Panel1.Parent = GroupBox ' Makes the form the parents of the panel
- Panel1.AutoScroll = True ' Sets autoscrolling on
- Panel1.Location = New System.Drawing.Point(5, 20) ' Creates the panel at the co-ordinates (x,y)
- Panel1.Name = "Panel1" ' Gives the panel a name
- Panel1.Size = New System.Drawing.Size(400, 400) ' Sets the dimensions of the panel
- Panel1.TabIndex = 2 ' Sets the tab index
- Const length As Integer = 75 ' Length for buttons
- Const width As Integer = 75 ' Width for buttons
- ' First button: needed to be created first to base co-ordinates of the rest of the buttons
- btn = New Button ' Sets btn to a new button
- btn.Parent = Panel1 ' Makes the panel the parent of the button
- btn.Size = New Size(length, width) ' Sets the length and width of the button
- btn.Text = CType(Foods(0) & vbNewLine & "$" & Prices(0), String) ' Makes the text of the button the food
- btn.Visible = True ' Makes the button visible
- btn.Location = New Point(Panel1.Left)
- AddHandler btn.Click, AddressOf btn_Click ' This is how button clicks are handled (see: btn_click sub)
- Buttons(i) = btn ' Makes the first button in the array to 0
- i += 1 ' Increments i
- While i < x ' While i is does not equal the button array size
- btn = New Button ' Creates a new button
- btn.Parent = Panel1 ' Makes the panel the parents of the button
- btn.Size = New Size(length, width) ' Sets the length and width of the button
- btn.Visible = True ' Makes the button visible
- AddHandler btn.Click, AddressOf btn_Click ' Handles button clicks
- Buttons(i) = btn ' Puts the button in the array given its index
- btn.Text = CType(Foods(i) & vbNewLine & "$" & Prices(i), String) ' Displays the food on the button
- btn.Location = New Point(Buttons(i - 1).Right, Buttons(i - 1).Top) ' Sets the location to the previous button's right co-ordinate
- If Buttons(i).Right > Panel1.Right Then ' If the button is outside the panel
- Buttons(i).Location = New Point(Panel1.Left, Buttons(i).Top + btn.Height) ' Make the location of the button the next row
- End If
- i += 1 ' Increments i
- End While
- End Sub
- Private Sub btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
- Dim dollar_pos As Integer
- ' lstItems.Items.Add((CType(sender.text, String)))
- temp_string = CType(sender.text, String)
- dollar_pos = temp_string.IndexOf("$")
- display_food = temp_string.Insert((dollar_pos - 1), " ")
- lstItems.Items.Add(display_food)
- price = Mid$(temp_string, dollar_pos + 2)
- price = FormatNumber(price, 2)
- total += price
- txtPrice.Text = total
- End Sub
- Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
- Dim dollar_pos As Integer
- temp_string = lstItems.SelectedItem()
- dollar_pos = temp_string.IndexOf("$")
- price = Mid$(temp_string, dollar_pos + 2)
- price = FormatNumber(price, 2)
- total -= price
- txtPrice.Text = total
- lstItems.Items.RemoveAt(lstItems.SelectedIndex)
- End Sub
- Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
- lstItems.Items.Clear()
- total = 0
- txtPrice.Text = total
- End Sub
- Private Sub btnCharge_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCharge.Click
- ' need help here
- End Sub
- End Class