private void btnOrder_Click(object sender, EventArgs e) { Double.TryParse(txtPrice.Text.Trim(), out var price); string pickupAddress = boxWhichLocation.Text; bool successInsert = false; bool successUpdate = false; //ensure combo box options are valid, if not display error to user bool success = CheckUserOrder(); //if both combobox options have selected a valid option, then try to insert into orders and update game stock if (success) { var od = new OrderDatabase(); var pd = new ProductDatabase(); successInsert = od.InsertIntoOrders(CustomerID, GameID, Title, price, pickupAddress); successUpdate = pd.UpdateGameStockAfterOrder(GameID, QuantityInStock, QuantitySold, true); } //if database has been updated successfully then let user know and update their viewed data if (successInsert && successUpdate) { UserControls.ShowUserInfo(); MessageBox.Show( $"{txtName.Text} has ordered {Title} for pickup at {boxWhichLocation.Text}. You will get receive an email at {txtEmail.Text} when it's ready for pickup."); Close(); } }
//if admin chooses an order, then update as picked up in database, and reload admins viewed data private void btnPickedUp_Click(object sender, EventArgs e) { try { string[] orderArr = boxOrderPickups.Text.Split('~'); Int32.TryParse(orderArr[0].Trim(), out int orderId); string title = orderArr[1].Trim(); bool success = false; //if a product was selected then send to database if (boxOrderPickups.SelectedIndex != 0) { var od = new OrderDatabase(); success = od.SetOrderAsPickedUp(orderId); } else { MessageBox.Show("You must choose an order to set it as picked up."); } //if updated in database successfully, then update admins data and inform him of success if (success) { UserControls.ShowUserInfo(); MessageBox.Show($"#{orderId}: {title} has been picked up successfully."); Close(); } } catch { MessageBox.Show("You must choose a product to be picked up."); } }
//if the order is cancelled by the user then remove the order from the database and update the stock quantities accordingly private void btnCancel_Click(object sender, EventArgs e) { try { string[] boxArr = boxWhichOrder.Text.Split('-'); string[] orderArr = boxArr[0].Split('#'); int orderId = Convert.ToInt32(orderArr[1].Trim()); bool successUpdate = false; bool successDelete = false; //if a valid option has been selected from the combo box if (boxWhichOrder.SelectedIndex != 0) { var od = new OrderDatabase(); var pd = new ProductDatabase(); successDelete = od.DeleteUserOrder(orderId); //remove the users order successUpdate = pd.UpdateGameStockAfterOrder(GameID, QuantityInStock, QuantitySold, false); //add back to stock and remove from sold } else { MessageBox.Show("You must select an order to cancel it."); } //if database operations are successful then let the user know and update their data information viewed if (successUpdate && successDelete) { UserControls.ShowUserInfo(); //refresh inventory also if they are an admin if (AccessLevel == 1) { AdminControls.AdminSetup(); } MessageBox.Show( $"Order #{orderId} has been cancelled for pickup."); Close(); } else { MessageBox.Show("There was an issue while attempting to cancel this order."); } } catch { MessageBox.Show("You must choose a product to be cancelled."); } }