//update the Item private void button2_Click(object sender, RoutedEventArgs e) { //Get the selected item string product_Code = listBox.Items.GetItemAt(1).ToString(); product_Code = product_Code.Remove(0, 15); Inventory item = Inventory.GetWithCode(product_Code); //update the item quantity int newValue; if (Int32.TryParse(textBox.Text, out newValue)) { item.ModifyItemStock(newValue); } //update the listbox listBox.Items.Clear(); listBox.Items.Add("Product : " + item.Product); listBox.Items.Add("Product Code : " + item.Product_Code); listBox.Items.Add("On Hand : " + item.On_Hand); listBox.Items.Add("On Order : " + item.On_Order); listBox.Items.Add("Reorder Level : " + item.Reorder_Level); listBox.Items.Add("Reorder Quantity : " + item.Reorder_Quantity); }
//Update the selected product private void Update_Product_button_Click(object sender, RoutedEventArgs e) { //Check all of the text/combo box fields string product_Code = Product_Code_Textbox.Text.ToString(); string product_Name = Product_Name_textBox.Text.ToString(); double list_price, unit_price; bool listPrice, unitPrice, reorderLevel, reorderQuant, onHand; int reorder_level, reorder_quant, on_Hand; CheckTextBoxes(out list_price, out listPrice, out unit_price, out unitPrice, out reorder_level, out reorderLevel, out reorder_quant, out reorderQuant, out on_Hand, out onHand); if (listPrice && unitPrice && reorderLevel && reorderQuant && onHand && product_Code.Length > 1 && product_Name.Length > 1) { Product product = (Product)listBox.SelectedItem; Inventory inventory = Inventory.GetWithCode(product.Product_Code); string category = category_comboBox.Text.ToString(); Product.ChangeProductCategory(product.Product_Id, category); Product.UpdateListPrice(product.Product_Id, list_price); Inventory.setFiltersToOrder(product.Product_Id, reorder_level, reorder_quant); inventory.ModifyItemStock(on_Hand); //Re-enable the textboxes that can't be updated in case a new product is to be added Product_Code_Textbox.IsEnabled = true; Product_Name_textBox.IsEnabled = true; Unit_Price_textBox.IsEnabled = true; //reset/update all fields listBox.ItemsSource = Product.GetAll(); Disc_Product_button.IsEnabled = false; Update_Product_button.IsEnabled = false; Add_Product_button.IsEnabled = true; Location_comboBox.IsEnabled = true; ResetBoxesToBlank(); } }
private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e) { if ((Product)comboBox1.SelectedItem != null) { Product product = (Product)comboBox1.SelectedItem; if (Inventory.GetWithCode(product.Product_Code) != null) { Inventory item = Inventory.GetWithCode(product.Product_Code); listBox.Items.Clear(); listBox.Items.Add("Product : " + item.Product); listBox.Items.Add("Product Code : " + item.Product_Code); listBox.Items.Add("On Hand : " + item.On_Hand); listBox.Items.Add("On Order : " + item.On_Order); listBox.Items.Add("Reorder Level : " + item.Reorder_Level); listBox.Items.Add("Reorder Quantity : " + item.Reorder_Quantity); textBox.IsEnabled = true; button2.IsEnabled = true; } else /*should probably output an error*/ } { } else /*should probably output an error*/ } {
private void listBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if ((Product)listBox.SelectedItem != null) { Product product = (Product)listBox.SelectedItem; if (Inventory.GetWithCode(product.Product_Code) != null) { Inventory inventory = Inventory.GetWithCode(product.Product_Code); //Set all textbox values to the corresponding values of that product so it can be updated Product_Code_Textbox.Text = product.Product_Code; Product_Name_textBox.Text = product.Product_Name; List_Price_textBox.Text = product.List_Price.ToString(); Unit_Price_textBox.Text = product.Unit_Cost.ToString(); ReorderLevel_textBox.Text = inventory.Reorder_Level.ToString(); ReorderQuantity_textBox.Text = inventory.Reorder_Quantity.ToString(); OnHand_textBox.Text = inventory.On_Hand.ToString(); Location_textBox.Text = inventory.Product_Location; //Disable the textBoxes that can't be modified Product_Code_Textbox.IsEnabled = false; Product_Name_textBox.IsEnabled = false; Unit_Price_textBox.IsEnabled = false; //Find which category the item has and set the combobox to show it int index = 0; for (int i = 0; i < categories.Count; i++) { if (categories[i].Category_Text == product.Category) { index = i; } } category_comboBox.SelectedIndex = index; /*---Not sure that this is possible--- * --Regardless, I'm out of time to try-- * * //Because the combobox is filled with empty locations, * //we need to add the location this item is at befeore searching for it * Category currLocation = Category.Get(inventory.Product_Location); * Location_comboBox.Items.Add(currLocation); * for(int i = 0; i < locations.Count; i++) * { * if(locations[i].Product_Location == inventory.Product_Location) * { * index = i; * } * }*/ Location_comboBox.Text = inventory.Product_Location; Location_comboBox.IsEnabled = false; //Enable/disable the necessary buttons //-Discontinue and Update need to be clickable //-Add can not be clickable Disc_Product_button.IsEnabled = true; Update_Product_button.IsEnabled = true; Add_Product_button.IsEnabled = false; } } }