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 LoadTextButton_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(); parent.currList = list; parent.FullListBox.Items.Clear(); parent.FullListBox.Items.AddRange(parent.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 } }
private void LoadXL_Button_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(); //Excel stuff Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application(); Workbook xlWorkbook = xlApp.Workbooks.Open(filePath); _Worksheet xlWorksheet = xlWorkbook.Sheets[1]; Range xlRange = xlWorksheet.UsedRange; list.SetListName("Loaded Excel List"); int rowCount = xlRange.Rows.Count; for (int i = 1; i <= rowCount; i++) { DataTypes.ListItem item; string name = ""; string location = ""; double price = 0; int quantity = 0; int maxQuantity = 0; if (xlRange.Cells[i, 1] != null && xlRange.Cells[i, 1].Value2 != null) { name = Convert.ToString(xlRange.Cells[i, 1].Value2); } if (xlRange.Cells[i, 2] != null && xlRange.Cells[i, 2].Value2 != null) { price = Convert.ToDouble(xlRange.Cells[i, 2].Value2); } if (xlRange.Cells[i, 3] != null && xlRange.Cells[i, 3].Value2 != null) { location = Convert.ToString(xlRange.Cells[i, 3].Value2); } if (xlRange.Cells[i, 4] != null && xlRange.Cells[i, 4].Value2 != null) { quantity = Convert.ToInt32(xlRange.Cells[i, 4].Value2); } if (xlRange.Cells[i, 5] != null && xlRange.Cells[i, 5].Value2 != null) { maxQuantity = Convert.ToInt32(xlRange.Cells[i, 5].Value2); } item = new DataTypes.ListItem(name, location, quantity, maxQuantity, (float)price); list.AddItem(item); } //reader.Close(); parent.currList = list; parent.FullListBox.Items.Clear(); parent.FullListBox.Items.AddRange(parent.currList.GetNameList().ToArray()); } }