private void BuyListButton_Click(object sender, EventArgs e) { DataTypes.ShoppingList list = new DataTypes.ShoppingList(); for (int i = 0; i < currList.GetList().Count; i++) { if (currList.GetList()[i].itemQuantity < currList.GetList()[i].itemMaxQuantity) { list.AddItem(currList.GetList()[i]); } } buyList = list; BuyListBox.Items.Clear(); BuyListBox.Items.AddRange(buyList.GetNameList().ToArray()); if (buyList.GetList().Count == 0) { return; } string specialPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); string fileName = "BuyList.txt"; string filePath = specialPath + @"\" + fileName; listPath = filePath; //Order: Name, price, location, quantity, max quantity StreamWriter writer = new StreamWriter(filePath); buyList.GetList().Sort((x, y) => x.purchaseLocation.CompareTo(y.purchaseLocation)); for (int i = 0; i < buyList.GetList().Count; i++) { int qty = buyList.GetList()[i].itemMaxQuantity - buyList.GetList()[i].itemQuantity; int spaceCount = 20 - buyList.GetList()[i].itemName.Length; writer.Write(buyList.GetList()[i].itemName); for (int j = 0; j < spaceCount; j++) { writer.Write(" "); } spaceCount = 9 - buyList.GetList()[i].itemCost.ToString().Length; for (int j = 0; j < spaceCount; j++) { writer.Write(" "); } writer.Write(buyList.GetList()[i].itemCost); writer.WriteLine(" x" + qty + " " + buyList.GetList()[i].purchaseLocation); } writer.WriteLine(""); writer.WriteLine("Estimated cost pre-tax: " + buyList.Truncate(buyList.GetTotalCost(), 2)); writer.Close(); }
private void BuyListBox_SelectedIndexChanged(object sender, EventArgs e) { if (buyList.GetList().Count == 0 || BuyListBox.SelectedIndex == -1) { return; } BuyListItemDetails.Text = "Item Price: " + buyList.GetList()[BuyListBox.SelectedIndex].itemCost + "\n" + "Item Purchase Location: " + buyList.GetList()[BuyListBox.SelectedIndex].purchaseLocation + "\n" + "Item Quantity: " + buyList.GetList()[BuyListBox.SelectedIndex].itemQuantity + "\n" + "Max Quantity: " + buyList.GetList()[BuyListBox.SelectedIndex].itemMaxQuantity + "\n"; }
private void SaveItemButton_Click(object sender, EventArgs e) { currList.GetList()[EditList_ListBox.SelectedIndex].itemName = ItemNameEntryBox.Text; currList.GetList()[EditList_ListBox.SelectedIndex].purchaseLocation = ItemLocationEntryBox.Text; currList.GetList()[EditList_ListBox.SelectedIndex].itemCost = (float)ItemCostEntryBox.Value; currList.GetList()[EditList_ListBox.SelectedIndex].itemQuantity = (int)ItemQuantityEntryBox.Value; currList.GetList()[EditList_ListBox.SelectedIndex].itemMaxQuantity = (int)ItemMaxQuantityEntryBox.Value; }