/// <summary> /// Add new Stock to the database. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddButton_Click(object sender, RoutedEventArgs e) { try { if (accountIdInput.Text.Equals("") || productIdInput.Text.Equals("") || warehouseIdInput.Text.Equals("") || quantityInput.Text.Equals("")) { MessageBox.Show("Please input all text boxes."); accountIdInput.Focus(); return; } else if ((!Regex.IsMatch(accountIdInput.Text, "^[0-9]*$")) || (!Regex.IsMatch(productIdInput.Text, "^[0-9]*$")) || (!Regex.IsMatch(warehouseIdInput.Text, "^[0-9]*$")) || (!Regex.IsMatch(quantityInput.Text, "^[0-9]*$"))) { MessageBox.Show("Please input only numerical characters into all text boxes."); accountIdInput.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()); } StockObject stock; AccountObject account = businessLogicLayer.CheckAccountsByID(int.Parse(accountIdInput.Text)); ProductObject product = businessLogicLayer.CheckProductsByID(int.Parse(productIdInput.Text)); WarehouseObject warehouse = businessLogicLayer.CheckWarehousesByID(int.Parse(warehouseIdInput.Text)); LocationObject location = businessLogicLayer.FindFreeLocation(int.Parse(warehouseIdInput.Text)); int stockLocation = location.location_id; try { if (!int.Parse(accountIdInput.Text).Equals(account.account_id)) { MessageBox.Show("The Account ID provided does not exist."); accountIdInput.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 if (!int.Parse(warehouseIdInput.Text).Equals(warehouse.warehouse_id)) { MessageBox.Show("The Warehouse ID provided does not exist."); warehouseIdInput.Focus(); return; } else if (stockLocation.Equals(0)) { MessageBox.Show("There are no more locations free in warehouse: " + warehouseIdInput.Text); warehouseIdInput.Focus(); return; } else { stock = businessLogicLayer.InsertNewStock(int.Parse(accountIdInput.Text), int.Parse(productIdInput.Text), int.Parse(warehouseIdInput.Text), stockLocation, int.Parse(quantityInput.Text)); location = businessLogicLayer.MarkLocationAllocated(stockLocation); MessageBox.Show("The Stock provided has been added to the system. \n\nA location has been found for the Stock and is now set as allocated. \n\nThe Stock (Pallet) is now ready to be put away, please see the location code as to where."); return; } } catch (Exception ex) { MessageBox.Show("An error has occurred, please contact your administrator." + "\n\n" + "The error message is: " + "\n\n" + ex.ToString()); } }
/// <summary> /// Edits a receipt in the database. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void EditButton_Click(object sender, RoutedEventArgs e) { string dateTimeFormat = "dd-MM-yyyy HH:mm"; DateTime CurrentTime = DateTime.Now; try { if (currentReceiptReferenceInput.Text.Equals("") || currentAccountIdInput.Text.Equals("") || currentWarehouseIdInput.Text.Equals("") || newReceiptReferenceInput.Text.Equals("") || newAccountIdInput.Text.Equals("") || newWarehouseIdInput.Text.Equals("")) { MessageBox.Show("Please input all text boxes."); currentReceiptReferenceInput.Focus(); return; } else if ((!Regex.IsMatch(currentAccountIdInput.Text, "^[0-9]*$")) || (!Regex.IsMatch(currentWarehouseIdInput.Text, "^[0-9]*$")) || (!Regex.IsMatch(newAccountIdInput.Text, "^[0-9]*$")) || (!Regex.IsMatch(newWarehouseIdInput.Text, "^[0-9]*$"))) { MessageBox.Show("Please input only numerical characters into the Account ID and Warehouse ID text boxes."); currentAccountIdInput.Focus(); return; } // https://stackoverflow.com/questions/31817105/regex-for-date-pattern/31817136 else if ((!DateTime.TryParseExact(currentExpectedDateInput.Text, dateTimeFormat, null, DateTimeStyles.None, out CurrentTime)) || (!DateTime.TryParseExact(newExpectedDateInput.Text, dateTimeFormat, null, DateTimeStyles.None, out CurrentTime))) { MessageBox.Show("Please input valid dates and times using the datetime pickers."); currentExpectedDateInput.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()); } ReceiptObject receipt; ReceiptObject receiptAllCurrent = businessLogicLayer.CheckReceiptsAll(currentReceiptReferenceInput.Text.ToLower(), int.Parse(currentAccountIdInput.Text), int.Parse(currentWarehouseIdInput.Text), DateTime.Parse(currentExpectedDateInput.Text)); ReceiptObject receiptCurrent = businessLogicLayer.CheckReceiptsByRefAndAccountID(currentReceiptReferenceInput.Text.ToLower(), int.Parse(currentAccountIdInput.Text)); ReceiptObject receiptNew = businessLogicLayer.CheckReceiptsByRefAndAccountID(newReceiptReferenceInput.Text.ToLower(), int.Parse(newAccountIdInput.Text)); AccountObject account = businessLogicLayer.CheckAccountsByID(int.Parse(newAccountIdInput.Text)); WarehouseObject warehouse = businessLogicLayer.CheckWarehousesByID(int.Parse(newWarehouseIdInput.Text)); try { if (!(currentReceiptReferenceInput.Text.ToLower().Equals(receiptAllCurrent.receipt_reference) && int.Parse(currentAccountIdInput.Text).Equals(receiptAllCurrent.account_id) && int.Parse(currentWarehouseIdInput.Text).Equals(receiptAllCurrent.warehouse_id) && DateTime.Parse(currentExpectedDateInput.Text).Equals(receiptAllCurrent.expected_date))) { MessageBox.Show("The Current Receipt provided does not exist."); currentReceiptReferenceInput.Focus(); return; } else if (!int.Parse(newAccountIdInput.Text).Equals(account.account_id)) { MessageBox.Show("The New Account ID provided does not exist."); newAccountIdInput.Focus(); return; } else if (!int.Parse(newWarehouseIdInput.Text).Equals(warehouse.warehouse_id)) { MessageBox.Show("The New Warehouse ID provided does not exist."); newWarehouseIdInput.Focus(); return; } else if (newReceiptReferenceInput.Text.ToLower().Equals(receiptNew.receipt_reference) && !newReceiptReferenceInput.Text.ToLower().Equals(receiptCurrent.receipt_reference) || int.Parse(newAccountIdInput.Text).Equals(receiptNew.account_id) && !int.Parse(newAccountIdInput.Text).Equals(receiptCurrent.account_id)) { MessageBox.Show("The Receipt Reference: " + newReceiptReferenceInput.Text + " already exists for Account: " + newAccountIdInput.Text); newReceiptReferenceInput.Focus(); return; } else if (receiptedDateInput.Value.HasValue.Equals(false)) { receipt = businessLogicLayer.EditCurrentReceiptNoRecDate(newReceiptReferenceInput.Text.ToLower(), int.Parse(newAccountIdInput.Text), int.Parse(newWarehouseIdInput.Text), DateTime.Parse(newExpectedDateInput.Text), currentReceiptReferenceInput.Text.ToLower(), int.Parse(currentAccountIdInput.Text), int.Parse(currentWarehouseIdInput.Text), DateTime.Parse(currentExpectedDateInput.Text)); MessageBox.Show(currentReceiptReferenceInput.Text + " has been updated without a Receipted Date."); return; } else { receipt = businessLogicLayer.EditCurrentReceipt(newReceiptReferenceInput.Text.ToLower(), int.Parse(newAccountIdInput.Text), int.Parse(newWarehouseIdInput.Text), DateTime.Parse(newExpectedDateInput.Text), DateTime.Parse(receiptedDateInput.Text), currentReceiptReferenceInput.Text.ToLower(), int.Parse(currentAccountIdInput.Text), int.Parse(currentWarehouseIdInput.Text), DateTime.Parse(currentExpectedDateInput.Text)); MessageBox.Show(currentReceiptReferenceInput.Text + " has been updated with a Receipt Date."); return; } } catch (Exception ex) { MessageBox.Show("An error has occurred, please contact your administrator." + "\n\n" + "The error message is: " + "\n\n" + ex.ToString()); } }
/// <summary> /// Adds a new receipt to the database. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddButton_Click(object sender, RoutedEventArgs e) { string dateTimeFormat = "dd-MM-yyyy HH:mm"; DateTime CurrentTime = DateTime.Now; try { if (receiptReferenceInput.Text.Equals("") || accountIdInput.Text.Equals("") || warehouseIdInput.Text.Equals("")) { MessageBox.Show("Please input all text boxes."); receiptReferenceInput.Focus(); return; } else if ((!Regex.IsMatch(accountIdInput.Text, "^[0-9]*$")) || (!Regex.IsMatch(warehouseIdInput.Text, "^[0-9]*$"))) { MessageBox.Show("Please input only numerical characters into the Account ID and Warehouse ID text boxes."); accountIdInput.Focus(); return; } // https://stackoverflow.com/questions/31817105/regex-for-date-pattern/31817136 else if (!DateTime.TryParseExact(expectedDateInput.Text, dateTimeFormat, null, DateTimeStyles.None, out CurrentTime)) { MessageBox.Show("Please input a valid date and time using the datetime picker."); expectedDateInput.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()); } ReceiptObject receipt = businessLogicLayer.CheckReceiptsByRefAndAccountID(receiptReferenceInput.Text.ToLower(), int.Parse(accountIdInput.Text)); AccountObject account = businessLogicLayer.CheckAccountsByID(int.Parse(accountIdInput.Text)); WarehouseObject warehouse = businessLogicLayer.CheckWarehousesByID(int.Parse(warehouseIdInput.Text)); try { if (!int.Parse(accountIdInput.Text).Equals(account.account_id)) { MessageBox.Show("The Account ID provided does not exist."); accountIdInput.Focus(); return; } else if (!int.Parse(warehouseIdInput.Text).Equals(warehouse.warehouse_id)) { MessageBox.Show("The Warehouse ID provided does not exist."); warehouseIdInput.Focus(); return; } else if (receiptReferenceInput.Text.ToLower().Equals(receipt.receipt_reference) && int.Parse(accountIdInput.Text).Equals(receipt.account_id)) { MessageBox.Show("The Receipt Reference: " + receiptReferenceInput.Text + " already exists for Account: " + accountIdInput.Text); receiptReferenceInput.Focus(); return; } else { receipt = businessLogicLayer.InsertNewReceipt(receiptReferenceInput.Text.ToLower(), int.Parse(accountIdInput.Text), int.Parse(warehouseIdInput.Text), DateTime.Parse(expectedDateInput.Text)); MessageBox.Show(receiptReferenceInput.Text + " 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()); } }
/// <summary> /// Edits an order in the database. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void EditButton_Click(object sender, RoutedEventArgs e) { string dateTimeFormat = "dd-MM-yyyy HH:mm"; DateTime CurrentTime = DateTime.Now; try { if (currentOrderIDInput.Text.Equals("") || currentOrderReferenceInput.Text.Equals("") || currentAccountIDInput.Text.Equals("") || newOrderReferenceInput.Text.Equals("") || newAccountIdInput.Text.Equals("") || newWarehouseIdInput.Text.Equals("") || newStatusInput.Text.Equals("") || newFirstNameInput.Text.Equals("") || newLastNameInput.Text.Equals("") || newAddressLine1Input.Text.Equals("") || newAddressLine2Input.Equals("") || newCityInput.Text.Equals("") || newPostcodeInput.Text.Equals("")) { MessageBox.Show("Please input all text boxes."); currentOrderIDInput.Focus(); return; } else if ((!Regex.IsMatch(currentOrderIDInput.Text, "^[0-9]*$")) || (!Regex.IsMatch(currentAccountIDInput.Text, "^[0-9]*$")) || (!Regex.IsMatch(newAccountIdInput.Text, "^[0-9]*$")) || (!Regex.IsMatch(newWarehouseIdInput.Text, "^[0-9]*$"))) { MessageBox.Show("Please input only numerical characters into the Current Order ID, Current Account ID, New Account ID and New Warehouse ID text boxes."); currentOrderIDInput.Focus(); return; } else if (!(newStatusInput.Text.ToLower().Equals("created") || newStatusInput.Text.ToLower().Equals("allocated") || newStatusInput.Text.ToLower().Equals("picked") || newStatusInput.Text.ToLower().Equals("dispatched"))) { MessageBox.Show("Please input only 'created', 'allocated', 'picked' or 'dispatched' into the New Status text box."); newStatusInput.Focus(); return; } // https://stackoverflow.com/questions/31817105/regex-for-date-pattern/31817136 else if (!DateTime.TryParseExact(newDispatchDateInput.Text, dateTimeFormat, null, DateTimeStyles.None, out CurrentTime)) { MessageBox.Show("Please input a valid date and time using the datetime picker."); newDispatchDateInput.Focus(); return; } else if ((!Regex.IsMatch(newFirstNameInput.Text, @"^[a-zA-Z]+$")) || (!Regex.IsMatch(newLastNameInput.Text, @"^[a-zA-Z]+$")) || (!Regex.IsMatch(newCityInput.Text, @"^[a-zA-Z]+$"))) { MessageBox.Show("Please input only alphabetical characters for the New First Name, New Last Name and New City text boxes"); newFirstNameInput.Focus(); return; } // https://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom#Validation else if (!Regex.IsMatch(newPostcodeInput.Text, "^(([A-Z]{1,2}[0-9][A-Z0-9]?|ASCN|STHL|TDCU|BBND|[BFS]IQQ|PCRN|TKCA) ?[0-9][A-Z]{2}|BFPO ?[0-9]{1,4}|(KY[0-9]|MSR|VG|AI)[ -]?[0-9]{4}|[A-Z]{2} ?[0-9]{2}|GE ?CX|GIR ?0A{2}|SAN ?TA1)$")) { MessageBox.Show("Please input a valid UK Postcode (must be in capitals)."); newPostcodeInput.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()); } OrderObject order; OrderObject orderCurrentByID = businessLogicLayer.CheckOrdersByID(int.Parse(currentOrderIDInput.Text)); OrderObject orderCurrentByIDAndRefAndAccID = businessLogicLayer.CheckOrdersByIDAndRefAndAccID(int.Parse(currentOrderIDInput.Text), currentOrderReferenceInput.Text.ToLower(), int.Parse(currentAccountIDInput.Text)); OrderObject orderCurrent = businessLogicLayer.CheckOrdersByRefAndAccountID(currentOrderReferenceInput.Text.ToLower(), int.Parse(currentAccountIDInput.Text)); OrderObject orderNew = businessLogicLayer.CheckOrdersByRefAndAccountID(newOrderReferenceInput.Text.ToLower(), int.Parse(newAccountIdInput.Text)); AccountObject account = businessLogicLayer.CheckAccountsByID(int.Parse(newAccountIdInput.Text)); WarehouseObject warehouse = businessLogicLayer.CheckWarehousesByID(int.Parse(newWarehouseIdInput.Text)); try { if (!int.Parse(currentOrderIDInput.Text).Equals(orderCurrentByID.order_id)) { MessageBox.Show("The Current Order ID provided does not exist."); currentOrderIDInput.Focus(); return; } else if (!(int.Parse(currentOrderIDInput.Text).Equals(orderCurrentByIDAndRefAndAccID.order_id) && currentOrderReferenceInput.Text.Equals(orderCurrentByIDAndRefAndAccID.order_reference) && int.Parse(currentAccountIDInput.Text).Equals(orderCurrentByIDAndRefAndAccID.account_id))) { MessageBox.Show("The Current Order provided does not exist."); currentOrderIDInput.Focus(); return; } else if (!int.Parse(newAccountIdInput.Text).Equals(account.account_id)) { MessageBox.Show("The New Account ID provided does not exist."); newAccountIdInput.Focus(); return; } else if (!int.Parse(newWarehouseIdInput.Text).Equals(warehouse.warehouse_id)) { MessageBox.Show("The new Warehouse ID provided does not exist."); newWarehouseIdInput.Focus(); return; } else if (newOrderReferenceInput.Text.ToLower().Equals(orderNew.order_reference) && !newOrderReferenceInput.Text.ToLower().Equals(orderCurrent.order_reference) || int.Parse(newAccountIdInput.Text).Equals(orderNew.account_id) && !int.Parse(newAccountIdInput.Text).Equals(orderCurrent.account_id)) { MessageBox.Show("The Order Reference: " + newOrderReferenceInput.Text + " already exists for Account: " + newAccountIdInput.Text); newOrderReferenceInput.Focus(); return; } else { order = businessLogicLayer.EditCurrentOrder(newOrderReferenceInput.Text.ToLower(), int.Parse(newAccountIdInput.Text), int.Parse(newWarehouseIdInput.Text), newStatusInput.Text.ToLower(), DateTime.Parse(newDispatchDateInput.Text), newFirstNameInput.Text.ToLower(), newLastNameInput.Text.ToLower(), newAddressLine1Input.Text.ToLower(), newAddressLine2Input.Text.ToLower(), newCityInput.Text.ToLower(), newPostcodeInput.Text.ToLower(), int.Parse(currentOrderIDInput.Text)); MessageBox.Show("The provided order has been updated."); return; } } catch (Exception ex) { MessageBox.Show("An error has occurred, please contact your administrator." + "\n\n" + "The error message is: " + "\n\n" + ex.ToString()); } }
/// <summary> /// Adds a new Order to the database. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddButton_Click(object sender, RoutedEventArgs e) { string dateTimeFormat = "dd-MM-yyyy HH:mm"; DateTime CurrentTime = DateTime.Now; try { if (orderReferenceInput.Text.Equals("") || accountIdInput.Text.Equals("") || warehouseIdInput.Text.Equals("") || firstNameInput.Text.Equals("") || lastNameInput.Text.Equals("") || addressLine1Input.Text.Equals("") || addressLine2Input.Text.Equals("") || cityInput.Equals("") || postcodeInput.Text.Equals("")) { MessageBox.Show("Please input all text boxes."); orderReferenceInput.Focus(); return; } else if ((!Regex.IsMatch(accountIdInput.Text, "^[0-9]*$")) || (!Regex.IsMatch(warehouseIdInput.Text, "^[0-9]*$"))) { MessageBox.Show("Please input only numerical characters into the Account ID and Warehouse ID text boxes."); accountIdInput.Focus(); return; } // https://stackoverflow.com/questions/31817105/regex-for-date-pattern/31817136 else if (!DateTime.TryParseExact(dispatchDateInput.Text, dateTimeFormat, null, DateTimeStyles.None, out CurrentTime)) { MessageBox.Show("Please input a valid date and time using the datetime picker."); dispatchDateInput.Focus(); return; } // https://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom#Validation else if (!Regex.IsMatch(postcodeInput.Text, "^(([A-Z]{1,2}[0-9][A-Z0-9]?|ASCN|STHL|TDCU|BBND|[BFS]IQQ|PCRN|TKCA) ?[0-9][A-Z]{2}|BFPO ?[0-9]{1,4}|(KY[0-9]|MSR|VG|AI)[ -]?[0-9]{4}|[A-Z]{2} ?[0-9]{2}|GE ?CX|GIR ?0A{2}|SAN ?TA1)$")) { MessageBox.Show("Please input a valid UK Postcode (In Capitals)."); postcodeInput.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()); } OrderObject order = businessLogicLayer.CheckOrdersByRefAndAccountID(orderReferenceInput.Text.ToLower(), int.Parse(accountIdInput.Text)); AccountObject account = businessLogicLayer.CheckAccountsByID(int.Parse(accountIdInput.Text)); WarehouseObject warehouse = businessLogicLayer.CheckWarehousesByID(int.Parse(warehouseIdInput.Text)); try { if (!int.Parse(accountIdInput.Text).Equals(account.account_id)) { MessageBox.Show("The Account ID provided does not exist."); accountIdInput.Focus(); return; } else if (!int.Parse(warehouseIdInput.Text).Equals(warehouse.warehouse_id)) { MessageBox.Show("The Warehouse ID provided does not exist."); warehouseIdInput.Focus(); return; } else if (orderReferenceInput.Text.ToLower().Equals(order.order_reference) && int.Parse(accountIdInput.Text).Equals(order.account_id)) { MessageBox.Show("The Order Reference: " + orderReferenceInput.Text + " already exists for Account: " + accountIdInput.Text); orderReferenceInput.Focus(); return; } else { order = businessLogicLayer.InsertNewOrder(orderReferenceInput.Text.ToLower(), int.Parse(accountIdInput.Text), int.Parse(warehouseIdInput.Text), DateTime.Parse(dispatchDateInput.Text), firstNameInput.Text.ToLower(), lastNameInput.Text.ToLower(), addressLine1Input.Text.ToLower(), addressLine2Input.Text.ToLower(), cityInput.Text.ToLower(), postcodeInput.Text.ToLower()); MessageBox.Show(orderReferenceInput.Text + " 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()); } }
/// <summary> /// Edits a stock in the database. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void EditButton_Click(object sender, RoutedEventArgs e) { try { if (currentStockIdInput.Text.Equals("") || currentLocationIdInput.Text.Equals("") || newAccountIdInput.Text.Equals("") || newProductIdInput.Text.Equals("") || newWarehouseIdInput.Text.Equals("") || newLocationIdInput.Equals("") || newQuantityInput.Text.Equals("") || newAllocatedQuantityInput.Text.Equals("") || newAvailabilityStatusInput.Text.Equals("")) { MessageBox.Show("Please input all text boxes."); currentStockIdInput.Focus(); return; } else if ((!Regex.IsMatch(currentStockIdInput.Text, "^[0-9]*$")) || (!Regex.IsMatch(currentLocationIdInput.Text, "^[0-9]*$")) || (!Regex.IsMatch(newAccountIdInput.Text, "^[0-9]*$")) || (!Regex.IsMatch(newProductIdInput.Text, "^[0-9]*$")) || (!Regex.IsMatch(newWarehouseIdInput.Text, "^[0-9]*$")) || (!Regex.IsMatch(newLocationIdInput.Text, "^[0-9]*$")) || (!Regex.IsMatch(newQuantityInput.Text, "^[0-9]*$")) || (!Regex.IsMatch(newAllocatedQuantityInput.Text, "^[0-9]*$"))) { MessageBox.Show("Please input only numerical characters into all text boxes apart from the current and new 'Availability Status Input'."); currentStockIdInput.Focus(); return; } else if (!(newAvailabilityStatusInput.Text.ToLower().Equals("true") || newAvailabilityStatusInput.Text.ToLower().Equals("false"))) { MessageBox.Show("Please input only 'True' or 'False' into the current and new Availability Status Input text boxes."); newAvailabilityStatusInput.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()); } StockObject stock; StockObject stockCurrentId = businessLogicLayer.CheckStockByID(int.Parse(currentStockIdInput.Text)); StockObject stockCurrentIdAndWarehouseAndLocation = businessLogicLayer.CheckStockByIDAndWarehouseAndLocation(int.Parse(currentStockIdInput.Text), int.Parse(currentWarehouseIdInput.Text), int.Parse(currentLocationIdInput.Text)); StockObject stockCurrentWarehouseAndLocation = businessLogicLayer.CheckStockByWarehouseAndLocation(int.Parse(currentWarehouseIdInput.Text), int.Parse(currentLocationIdInput.Text)); StockObject stockNewWarehouseAndLocation = businessLogicLayer.CheckStockByWarehouseAndLocation(int.Parse(newWarehouseIdInput.Text), int.Parse(newLocationIdInput.Text)); LocationObject locationNewLocationByWarehouse = businessLogicLayer.CheckLocationByIDAndWarehouse(int.Parse(newLocationIdInput.Text), int.Parse(newWarehouseIdInput.Text)); AccountObject accountId = businessLogicLayer.CheckAccountsByID(int.Parse(newAccountIdInput.Text)); ProductObject productId = businessLogicLayer.CheckProductsByID(int.Parse(newProductIdInput.Text)); WarehouseObject warehouseId = businessLogicLayer.CheckWarehousesByID(int.Parse(newWarehouseIdInput.Text)); LocationObject locationId = businessLogicLayer.CheckLocationsByID(int.Parse(newLocationIdInput.Text)); LocationObject locationUnallocated; LocationObject locationAllocated; try { if (!int.Parse(currentStockIdInput.Text).Equals(stockCurrentId.stock_id)) { MessageBox.Show("The current Stock ID provided does not exist."); currentStockIdInput.Focus(); return; } else if (!int.Parse(currentStockIdInput.Text).Equals(stockCurrentIdAndWarehouseAndLocation.stock_id) && !int.Parse(currentWarehouseIdInput.Text).Equals(stockCurrentIdAndWarehouseAndLocation.warehouse_id) && !int.Parse(currentLocationIdInput.Text).Equals(stockCurrentIdAndWarehouseAndLocation.location_id)) { MessageBox.Show("The current Stock provided does not exist in that Warehouse & Location."); currentStockIdInput.Focus(); return; } else if (!int.Parse(newAccountIdInput.Text).Equals(accountId.account_id)) { MessageBox.Show("The new Account ID provided does not exist."); newAccountIdInput.Focus(); return; } else if (!int.Parse(newProductIdInput.Text).Equals(productId.product_id)) { MessageBox.Show("The new product ID provided does not exist."); newProductIdInput.Focus(); return; } else if (!int.Parse(newWarehouseIdInput.Text).Equals(warehouseId.warehouse_id)) { MessageBox.Show("The new Warehouse ID provided does not exist."); newWarehouseIdInput.Focus(); return; } else if (!int.Parse(newLocationIdInput.Text).Equals(locationId.location_id)) { MessageBox.Show("The new Location ID provided does not exist."); newLocationIdInput.Focus(); return; } else if (int.Parse(newQuantityInput.Text) < int.Parse(newAllocatedQuantityInput.Text)) { MessageBox.Show("The new Allocated Quantity cannot be greater than the new Quantity."); newQuantityInput.Focus(); return; } else if (!int.Parse(newLocationIdInput.Text).Equals(locationNewLocationByWarehouse.location_id)) { MessageBox.Show("The new Location ID provided does not exist in that warehouse."); currentStockIdInput.Focus(); return; } else if (int.Parse(newWarehouseIdInput.Text).Equals(stockNewWarehouseAndLocation.warehouse_id) && !int.Parse(newWarehouseIdInput.Text).Equals(stockCurrentWarehouseAndLocation.warehouse_id) || int.Parse(newLocationIdInput.Text).Equals(stockNewWarehouseAndLocation.location_id) && !int.Parse(newLocationIdInput.Text).Equals(stockCurrentWarehouseAndLocation.location_id)) { MessageBox.Show("Stock already exists in that Warehouse and Location."); newWarehouseIdInput.Focus(); return; } else { stock = businessLogicLayer.EditCurrentStock(int.Parse(newAccountIdInput.Text), int.Parse(newProductIdInput.Text), int.Parse(newWarehouseIdInput.Text), int.Parse(newLocationIdInput.Text), int.Parse(newQuantityInput.Text), int.Parse(newAllocatedQuantityInput.Text), bool.Parse(newAvailabilityStatusInput.Text.ToLower()), int.Parse(currentStockIdInput.Text)); locationUnallocated = businessLogicLayer.MarkLocationUnallocated(int.Parse(currentLocationIdInput.Text)); locationAllocated = businessLogicLayer.MarkLocationAllocated(int.Parse(newLocationIdInput.Text)); MessageBox.Show("The Stock provided has been updated. \n\nThe current Location has been marked unallocated. \n\nThe new Location has been marked allocated"); return; } } catch (Exception ex) { MessageBox.Show("An error has occurred, please contact your administrator." + "\n\n" + "The error message is: " + "\n\n" + ex.ToString()); } }