private void RefreshButton_Click(object sender, EventArgs e) // Refresh Button { PictureBox[] pictures = { pictureBox1, pictureBox2, pictureBox3, pictureBox4, pictureBox5, pictureBox6, pictureBox7, pictureBox8, pictureBox9, pictureBox10, pictureBox11, pictureBox12, pictureBox13, pictureBox14,pictureBox15, pictureBox16 }; for (int index = 0; index < pictures.Length; index++) { VendItem locItem = new VendItem(); locItem.ItemInventory = 5; locItem.ItemPrice = VendMachList[index].ItemPrice; locItem.ItemName = VendMachList[index].ItemName; VendMachList[index] = locItem; pictures[index].Show(); } // Clears all the factors that change - clears labels, clears list of cart, clears current count of money accumulated label1.Text = ("$ 0.00"); listBox1.Items.Clear(); TotalPrice = 0.00m; ContPrice = 0.00m; label3.Text = (""); }
// Our method we'll use for the action of each item private void Choice(VendItem i, PictureBox p, int loc) { if (i.ItemInventory > 0) { VendItem locItem = new VendItem(); locItem.ItemInventory = i.ItemInventory - 1; locItem.ItemPrice = i.ItemPrice; locItem.ItemName = i.ItemName; VendMachList[loc] = locItem; TotalPrice = TotalPrice + i.ItemPrice; listBox1.Items.Add(i.ItemName); label1.Text = "$ " + TotalPrice.ToString(); } else { // If item is out of inventory ( ItemInv < 1 ) MessageBox.Show("Sorry we are all out of that item!"); // Hides empty stock p.Hide(); } }
// Read the VendMachItems.txt file private List <VendItem> ReadFile() { // Creates a list called ItemInfo populated of type VendItem List <VendItem> ItemInfo = new List <VendItem>(); try { StreamReader inputFile; string Line; VendItem entry = new VendItem(); char[] delim = { ',' }; inputFile = File.OpenText("VendMachItems.txt"); while (!inputFile.EndOfStream) { Line = inputFile.ReadLine(); string[] tokens = Line.Split(delim); entry.ItemName = tokens[0]; entry.ItemInventory = Convert.ToDouble(tokens[1]); entry.ItemPrice = Convert.ToDecimal(tokens[2]); ItemInfo.Add(entry); } } catch (Exception e) { MessageBox.Show(e.Message); } // Return the item's info return(ItemInfo); }