Example #1
0
        private void SaveListButton_Click(object sender, EventArgs e)
        {
            if (currList.GetList().Count == 0)
            {
                return;
            }

            string specialPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            string fileName    = currList.GetListName() + ".txt";
            string filePath    = specialPath + @"\" + fileName;
            //Order: Name, price, location, quantity, max quantity
            StreamWriter writer = new StreamWriter(filePath);

            writer.WriteLine(currList.GetListName());

            for (int i = 0; i < currList.GetList().Count; i++)
            {
                //writer.WriteLine("#");
                writer.WriteLine(currList.GetList()[i].itemName);
                writer.WriteLine(currList.GetList()[i].itemCost);
                writer.WriteLine(currList.GetList()[i].purchaseLocation);
                writer.WriteLine(currList.GetList()[i].itemQuantity);
                writer.WriteLine(currList.GetList()[i].itemMaxQuantity);
            }

            writer.Close();
        }
Example #2
0
        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
            }
        }