/// <summary> /// Adds a new receipt line to the database. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddButton_Click(object sender, RoutedEventArgs e) { try { if (receiptIdInput.Text.Equals("") || productIdInput.Text.Equals("") || quantityInput.Text.Equals("")) { MessageBox.Show("Please input all text boxes."); receiptIdInput.Focus(); return; } else if ((!Regex.IsMatch(receiptIdInput.Text, "^[0-9]*$")) || (!Regex.IsMatch(productIdInput.Text, "^[0-9]*$")) || (!Regex.IsMatch(quantityInput.Text, "^[0-9]*$"))) { MessageBox.Show("Please input only numerical characters into all text boxes."); receiptIdInput.Focus(); return; } } catch (Exception ex) { MessageBox.Show("An error has occurred, please contact your administrator." + "\n\n" + "The error message is: " + "\n\n" + ex.ToString()); } ReceiptLineObject receiptLine; ReceiptObject receipt = businessLogicLayer.CheckReceiptsByID(int.Parse(receiptIdInput.Text)); ProductObject product = businessLogicLayer.CheckProductsByID(int.Parse(productIdInput.Text)); try { if (!int.Parse(receiptIdInput.Text).Equals(receipt.receipt_id)) { MessageBox.Show("The Receipt ID provided does not exist."); receiptIdInput.Focus(); return; } else if (!int.Parse(productIdInput.Text).Equals(product.product_id)) { MessageBox.Show("The Product ID provided does not exist."); productIdInput.Focus(); return; } else { receiptLine = businessLogicLayer.InsertNewReceiptLine(int.Parse(receiptIdInput.Text), int.Parse(productIdInput.Text), int.Parse(quantityInput.Text)); MessageBox.Show("The provided Receipt Line has been added to the system."); return; } } catch (Exception ex) { MessageBox.Show("An error has occurred, please contact your administrator." + "\n\n" + "The error message is: " + "\n\n" + ex.ToString()); } }