private void retrieveAllOfOneBtn_Click(object sender, EventArgs e) { //The "Retrieve All of One Item" button retrieves all of a user-selected Item from the Warehouse. MySqlCommand cmd = new MySqlCommand(); DBQueries queries = new DBQueries(); //If an invalid Item Name is selected, alert user and return to orderViewForm. if (orderView.SelectedCells[0].Value == null) { MessageBox.Show("Invalid Item Name selected, please select an Item Name and try again."); return; } string itemName = orderView.SelectedCells[0].Value.ToString(); //If an invalid Item Name is selected, alert user and return to orderViewForm. if (orderView.Columns[orderView.CurrentCell.ColumnIndex].Name == orderView.Columns["Container ID:"].Name || orderView.Columns[orderView.CurrentCell.ColumnIndex].Name == orderView.Columns["Item Quantity:"].Name || itemName == "") { MessageBox.Show("Invalid Item Name selected, please select an Item Name and try again."); return; } //Get necessary Customer Info from database int itemID = queries.getItemID(connection, itemName); int contID = queries.getSingleContainerID(connection, itemID); int custID = customer.getID(); //Retrieve all of specified Item from warehouse queries.retrieveAllOfOneItem(connection, itemID, custID, contID); //Refresh the DGV, displaying the newly updated Invoice with Item removed. custContList = queries.getCustStorageOrder(connection, custID); orderView.Rows.Clear(); for (int i = 0; i < custContList.Count(); i++) { itemList = custContList[i].getItemList(); orderView.Rows.Add(custContList[i].getID().ToString(), "", ""); for (int j = 0; j < itemList.Count(); j++) { orderView.Rows.Add("", itemList[j].getName(), itemList[j].getQuantity()); } } //Alert user that Item has been retrieved successfully. MessageBox.Show("Item: " + itemName + " has been successfully retrieved."); }
private void retrieveXBtn_Click(object sender, EventArgs e) { //The "Retrieve X Of One Item" button retrieves a specified quantity of a specific Item that the user has selected. MySqlCommand cmd = new MySqlCommand(); DBQueries queries = new DBQueries(); //If an invalid Item Name is selected, alert user and return to orderViewForm. if (orderView.SelectedCells[0].Value == null) { MessageBox.Show("Invalid Item Name selected, please select an Item Name and try again."); return; } string itemName = orderView.SelectedCells[0].Value.ToString(); //If an invalid Item Name is selected, alert user and return to orderViewForm. if (orderView.Columns[orderView.CurrentCell.ColumnIndex].Name == orderView.Columns["Container ID:"].Name || orderView.Columns[orderView.CurrentCell.ColumnIndex].Name == orderView.Columns["Item Quantity:"].Name || itemName == "") { MessageBox.Show("Invalid Item Name selected, please select an Item Name and try again."); return; } //Get necessary info from database int curItemQuantity = queries.getItemQuantity(connection, itemName); int itemID = queries.getItemID(connection, itemName); string value = ""; int numOfItems; //Prompt user to enter the quantity of Items they wish to retrieve. if (Dialog.InputBox("Enter the number of Items you would like to retrieve:", "Number of Items:", ref value) == DialogResult.OK) { numOfItems = int.Parse(value); int newQty = curItemQuantity - numOfItems; //If the user-entered quantity is larger than that remaining in the warehouse, alert user and return to orderViewForm if (newQty < 0) { MessageBox.Show("Not enough quantity remaining to retrieve " + numOfItems + " of Item: " + itemName + ", please enter a quantity less than " + curItemQuantity); return; } //Update quantity in the database. queries.retrieveXOfOneItem(connection, newQty, itemID); custContList = queries.getCustStorageOrder(connection, customer.getID()); //Refresh the DGV, displaying the newly updated Invoice with Item quantity updated. orderView.Rows.Clear(); for (int i = 0; i < custContList.Count(); i++) { itemList = custContList[i].getItemList(); orderView.Rows.Add(custContList[i].getID().ToString(), "", ""); for (int j = 0; j < itemList.Count(); j++) { orderView.Rows.Add("", itemList[j].getName(), itemList[j].getQuantity()); } } //Alert the user that the quantity they have requested has been retrieved. MessageBox.Show("Quantity: " + numOfItems.ToString() + " of Item: " + itemName + " successfully retrieved."); } }