예제 #1
0
        /// <summary>
        ///     Adds a new order line to the database.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (orderIdInput.Text.Equals("") || productIdInput.Text.Equals("") || quantityInput.Text.Equals(""))
                {
                    MessageBox.Show("Please input all text boxes.");
                    orderIdInput.Focus();
                    return;
                }
                else if ((!Regex.IsMatch(orderIdInput.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.");
                    orderIdInput.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());
            }

            OrderLineObject orderLine;
            OrderObject     order   = businessLogicLayer.CheckOrdersByID(int.Parse(orderIdInput.Text));
            ProductObject   product = businessLogicLayer.CheckProductsByID(int.Parse(productIdInput.Text));

            try
            {
                if (!int.Parse(orderIdInput.Text).Equals(order.order_id))
                {
                    MessageBox.Show("The Order ID provided does not exist.");
                    orderIdInput.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
                {
                    orderLine = businessLogicLayer.InsertNewOrderLine(int.Parse(orderIdInput.Text), int.Parse(productIdInput.Text), int.Parse(quantityInput.Text));
                    MessageBox.Show("The provided Order 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());
            }
        }
예제 #2
0
        /// <summary>
        ///     Deletes an order from the database.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DeleteButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (orderIdInput.Text.Equals(""))
                {
                    MessageBox.Show("Please input the text box.");
                    orderIdInput.Focus();
                    return;
                }
                else if (!Regex.IsMatch(orderIdInput.Text, "^[0-9]*$"))
                {
                    MessageBox.Show("Please input only numerical characters into the text box.");
                    orderIdInput.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 order1 = businessLogicLayer.CheckOrdersByID(int.Parse(orderIdInput.Text));
            OrderObject order2 = businessLogicLayer.CheckOrderIsAllocated(int.Parse(orderIdInput.Text));

            try
            {
                if (!int.Parse(orderIdInput.Text).Equals(order1.order_id))
                {
                    MessageBox.Show("The Order ID provided does not exist.");
                    orderIdInput.Focus();
                    return;
                }
                else if (order2.status.Equals("allocated"))
                {
                    MessageBox.Show("The Order provided is currently allocated and so cannot be deleted. \n\nPlease contact an administrator if the order still needs to be deleted.");
                    orderIdInput.Focus();
                    return;
                }
                else if (order2.status.Equals("picked"))
                {
                    MessageBox.Show("The Order provided has already been picked and so cannot be deleted. \n\nPlease contact an administrator if the order still needs to be deleted.");
                    orderIdInput.Focus();
                    return;
                }
                else if (order2.status.Equals("dispatched"))
                {
                    MessageBox.Show("The Order provided has already been dispatched and so cannot be deleted. \n\nPlease contact an administrator if the order still needs to be deleted.");
                    orderIdInput.Focus();
                    return;
                }
                else
                {
                    order = businessLogicLayer.DeleteCurrentOrder(int.Parse(orderIdInput.Text));
                    MessageBox.Show("The provided Order has been deleted from 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());
            }
        }
예제 #3
0
        /// <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());
            }
        }