예제 #1
0
        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());
            }
        }
예제 #2
0
        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());
        }
예제 #3
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
            }
        }
예제 #4
0
        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());
            }
        }