Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 15th, 2012  |  syntax: None  |  size: 5.55 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Public Class Cashier
  2.     Dim Buttons(x) As Button ' Button array
  3.     Dim Foods(x) As String ' Food array
  4.     Dim Prices(x) As Double ' Price array
  5.     Dim FoodID(x) As Integer ' FoodID array
  6.     Dim x As Integer ' Used to get the array size
  7.     Dim btn As Button ' Used to generate the buttons
  8.     Dim y As Integer = 0 ' Counter to add foods into the array
  9.     Dim i As Integer = 0 ' Loop couhter
  10.     Dim temp_string As String
  11.     Dim price As String
  12.     Dim total As Double
  13.     Dim display_food As String
  14.  
  15.  
  16.     Private Sub Cashier_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  17.  
  18.         'TODO: This line of code loads data into the 'TuckshopDataSet.Tuckshop' table. You can move, or remove it, as needed.
  19.         Me.TuckshopTableAdapter.Fill(Me.TuckshopDataSet.Tuckshop)
  20.         'TODO: This line of code loads data into the 'TuckshopDataSet.Foods' table. You can move, or remove it, as needed.
  21.         Me.FoodsTableAdapter.Fill(Me.TuckshopDataSet.Foods)
  22.         txtPrice.Text = "$0"
  23.         x = TuckshopDataSet.Foods.Count() ' Gets the length of the foods column
  24.         ReDim Preserve Buttons(x) ' Sets the array size for the buttons
  25.         ReDim Preserve Foods(x) ' Sets the array size for the foods
  26.         ReDim Preserve Prices(x) ' Sets the array size for the prices
  27.         ReDim Preserve FoodID(x) ' Sets the array size for the prices
  28.         While y < x
  29.             Foods(y) = TuckshopDataSet.Tuckshop(y)(1) ' Make the index of the array the index of the column
  30.             Prices(y) = TuckshopDataSet.Tuckshop(y)(2) ' Make the index of the array the index of the column
  31.             FoodID(y) = TuckshopDataSet.Tuckshop(y)(0) ' Make the index of the array the index of the column
  32.             y += 1 ' Incrememnt y
  33.         End While
  34.  
  35.  
  36.         Dim Panel1 As New System.Windows.Forms.Panel ' Declares the panel
  37.         Panel1.Parent = GroupBox ' Makes the form the parents of the panel
  38.         Panel1.AutoScroll = True ' Sets autoscrolling on
  39.         Panel1.Location = New System.Drawing.Point(5, 20) ' Creates the panel at the co-ordinates (x,y)
  40.         Panel1.Name = "Panel1" ' Gives the panel a name
  41.         Panel1.Size = New System.Drawing.Size(400, 400) ' Sets the dimensions of the panel
  42.         Panel1.TabIndex = 2 ' Sets the tab index
  43.  
  44.         Const length As Integer = 75 ' Length for buttons
  45.         Const width As Integer = 75 ' Width for buttons
  46.  
  47.  
  48.         ' First button: needed to be created first to base co-ordinates of the rest of the buttons
  49.         btn = New Button ' Sets btn to a new button
  50.         btn.Parent = Panel1 ' Makes the panel the parent of the button
  51.         btn.Size = New Size(length, width) ' Sets the length and width of the button
  52.         btn.Text = CType(Foods(0) & vbNewLine & "$" & Prices(0), String) ' Makes the text of the button the food
  53.         btn.Visible = True ' Makes the button visible
  54.         btn.Location = New Point(Panel1.Left)
  55.         AddHandler btn.Click, AddressOf btn_Click ' This is how button clicks are handled (see: btn_click sub)
  56.         Buttons(i) = btn ' Makes the first button in the array to 0
  57.         i += 1 ' Increments i
  58.  
  59.         While i < x ' While i is does not equal the button array size
  60.             btn = New Button ' Creates a new button
  61.             btn.Parent = Panel1 ' Makes the panel the parents of the button
  62.             btn.Size = New Size(length, width) ' Sets the length and width of the button
  63.             btn.Visible = True ' Makes the button visible
  64.             AddHandler btn.Click, AddressOf btn_Click ' Handles button clicks
  65.             Buttons(i) = btn ' Puts the button in the array given its index
  66.             btn.Text = CType(Foods(i) & vbNewLine & "$" & Prices(i), String) ' Displays the food on the button
  67.             btn.Location = New Point(Buttons(i - 1).Right, Buttons(i - 1).Top) ' Sets the location to the previous button's right co-ordinate
  68.             If Buttons(i).Right > Panel1.Right Then ' If the button is outside the panel
  69.                 Buttons(i).Location = New Point(Panel1.Left, Buttons(i).Top + btn.Height) ' Make the location of the button the next row
  70.             End If
  71.             i += 1 ' Increments i
  72.         End While
  73.  
  74.     End Sub
  75.  
  76.     Private Sub btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
  77.         Dim dollar_pos As Integer
  78.         ' lstItems.Items.Add((CType(sender.text, String)))
  79.         temp_string = CType(sender.text, String)
  80.         dollar_pos = temp_string.IndexOf("$")
  81.         display_food = temp_string.Insert((dollar_pos - 1), "   ")
  82.         lstItems.Items.Add(display_food)
  83.         price = Mid$(temp_string, dollar_pos + 2)
  84.         price = FormatNumber(price, 2)
  85.         total += price
  86.         txtPrice.Text = total
  87.  
  88.  
  89.     End Sub
  90.  
  91.     Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
  92.         Dim dollar_pos As Integer
  93.         temp_string = lstItems.SelectedItem()
  94.         dollar_pos = temp_string.IndexOf("$")
  95.         price = Mid$(temp_string, dollar_pos + 2)
  96.         price = FormatNumber(price, 2)
  97.         total -= price
  98.         txtPrice.Text = total
  99.         lstItems.Items.RemoveAt(lstItems.SelectedIndex)
  100.        
  101.     End Sub
  102.  
  103.     Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
  104.         lstItems.Items.Clear()
  105.         total = 0
  106.         txtPrice.Text = total
  107.     End Sub
  108.  
  109.     Private Sub btnCharge_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCharge.Click
  110.         ' need help here
  111.     End Sub
  112. End Class