예제 #1
0
        public static bool RemoveItemFromInventory(Item item)
        {
            bool result = items.Remove(item);

            InvoFileTools.SaveCurrentFile();
            return(result);
        }
예제 #2
0
        private void saveChangesBtn_Click(object sender, EventArgs e)
        {
            ListBox      listBox       = (ListBox)GetControl("inventoryListBox");
            Item         item          = (Item)listBox.SelectedItem;
            DialogResult confirmResult = MessageBox.Show("Are you sure to edit this item?", "Confirm edit", MessageBoxButtons.YesNo);

            if (confirmResult == DialogResult.Yes)
            {
                foreach (Control control in editItemPanel.Controls[0].Controls)
                {
                    if (control.Name == "editNameTextBox")
                    {
                        item.Name = control.Text;
                    }
                    if (control.Name == "editPriceTextBox")
                    {
                        item.Price = Convert.ToDecimal(control.Text);
                    }
                    if (control.Name == "editQuantityTextBox")
                    {
                        item.Quantity = Convert.ToInt32(control.Text);
                    }
                }

                InvoFileTools.SaveCurrentFile();
                GetControl("showInventoryPanel").Show();
                GetControl("editItemPanel").Hide();
                FillListBox();
            }
        }
예제 #3
0
 //returns false if item already exists. True if succesful
 static public bool AddItemToInventory(Item item)
 {
     //Check if item already exists first
     foreach (Item i in items)
     {
         if (i.Name == item.Name)
         {
             return(false);
         }
     }
     items.Add(item);
     InvoFileTools.SaveCurrentFile();
     return(true);
 }
예제 #4
0
        public static bool LoadInventoryFromFile(string fileName)
        {
            InvoFile invoFile = InvoFileTools.LoadFile(fileName);

            if (invoFile == null)
            {
                return(false);
            }
            for (int i = 0; i < invoFile.items.Length; i++)
            {
                Item item = new Item(invoFile.items[i].name, invoFile.items[i].price, invoFile.items[i].quantity);
                items.Add(item);
            }
            return(true);
        }
예제 #5
0
        private void createNewFileBtn_Click(object sender, EventArgs e)
        {
            InvoFileTools.SaveNewFile(GetControl("fileToName").Text);
            //Close create window
            Form.ActiveForm.Close();

            //Should be main window
            foreach (Control control in Form.ActiveForm.Controls)
            {
                if (control.GetType() == typeof(Panel))
                {
                    control.Hide();
                }
            }
            Inventory.UnloadInventory();
            GetControl("panel1").Show();
        }