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 AddItemButton_Click(object sender, EventArgs e) { if (ItemNameEntryBox.Text == "The name of the item" || ItemLocationEntryBox.Text == "The location of purchase" || ItemCostEntryBox.Value == 0 || ItemMaxQuantityEntryBox.Value == 0) { return; } else if (ItemNameEntryBox.Text == "" || ItemLocationEntryBox.Text == "" || ItemQuantityEntryBox.Value.ToString() == "" || ItemCostEntryBox.Value.ToString() == "" || ItemMaxQuantityEntryBox.Value.ToString() == "") { return; } DataTypes.ListItem item = new DataTypes.ListItem(ItemNameEntryBox.Text, ItemLocationEntryBox.Text, (int)ItemQuantityEntryBox.Value, (int)ItemMaxQuantityEntryBox.Value, (float)ItemCostEntryBox.Value); currList.AddItem(item); SaveListButton.Visible = true; DeleteItemButton.Visible = true; EditList_ListBox.Items.Clear(); EditList_ListBox.Items.AddRange(currList.GetNameList().ToArray()); }
private void LoadListButton_Click(object sender, EventArgs e) { OpenFileDialog log = new OpenFileDialog(); string filePath = ""; if (log.ShowDialog() == System.Windows.Forms.DialogResult.OK) { filePath = log.FileName; //Order: Name, price, location, quantity, max quantity StreamReader reader = new StreamReader(filePath); DataTypes.ShoppingList list = new DataTypes.ShoppingList(); list.SetListName(reader.ReadLine()); while (!reader.EndOfStream) { DataTypes.ListItem item; string name = ""; string location = ""; double price = 0; int quantity = 0; int maxQuantity = 0; name = reader.ReadLine(); price = Convert.ToDouble(reader.ReadLine()); location = reader.ReadLine(); quantity = Convert.ToInt32(reader.ReadLine()); maxQuantity = Convert.ToInt32(reader.ReadLine()); item = new DataTypes.ListItem(name, location, quantity, maxQuantity, (float)price); list.AddItem(item); } reader.Close(); currList = list; EditList_ListBox.Items.Clear(); EditList_ListBox.Items.AddRange(currList.GetNameList().ToArray()); ListBoxLabel.Text = currList.GetListName(); #region Visibility toggles ItemNameLabel.Visible = true; ItemNameEntryBox.Visible = true; ItemLocationLabel.Visible = true; ItemLocationEntryBox.Visible = true; ItemCostLabel.Visible = true; ItemCostEntryBox.Visible = true; ItemQuantityLabel.Visible = true; ItemQuantityEntryBox.Visible = true; ItemMaxQuantityLabel.Visible = true; ItemMaxQuantityEntryBox.Visible = true; ListBoxLabel.Visible = true; EditList_ListBox.Visible = true; SaveItemButton.Visible = true; DeleteItemButton.Visible = true; LoadListButton.Visible = true; SaveListButton.Visible = true; AddItemButton.Visible = true; #endregion } }