Пример #1
0
        private void CreateList_Click(object sender, EventArgs e)
        {
            if (ListNameBox.Text == "Name of the list")
            {
                return;
            }

            newList.SetListName(ListNameBox.Text);

            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.Text    = ListNameBox.Text;
            ListBoxLabel.Visible = true;

            NewList_ListBox.Visible = true;

            ItemDetails.Text    = "Item details will appear here when clicked.";
            ItemDetails.Visible = true;

            AddItemButton.Visible = true;
        }
Пример #2
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());
            }
        }
Пример #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());
            }
        }