/// <summary>
        ///     Adds a new Product 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("") || titleInput.Text.Equals("") || skuInput.Text.Equals(""))
                {
                    MessageBox.Show("Please input all text boxes.");
                    accountIdInput.Focus();
                    return;
                }
                else if (!Regex.IsMatch(accountIdInput.Text, "^[0-9]*$"))
                {
                    MessageBox.Show("Please input only numerical characters into the Account ID text box.");
                    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());
            }

            ProductObject product = businessLogicLayer.CheckProductsByIDAndSku(int.Parse(accountIdInput.Text), skuInput.Text.ToLower());
            AccountObject account = businessLogicLayer.CheckAccountsByID(int.Parse(accountIdInput.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(accountIdInput.Text).Equals(product.account_id) && skuInput.Text.ToLower().Equals(product.sku))
                {
                    MessageBox.Show("The Account provided already has a SKU with that name.");
                    accountIdInput.Focus();
                    return;
                }
                else
                {
                    product = businessLogicLayer.InsertNewProduct(int.Parse(accountIdInput.Text), titleInput.Text.ToLower(), skuInput.Text.ToLower());
                    MessageBox.Show(titleInput.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());
            }
        }
Example #2
0
        /// <summary>
        ///     Edits a product in the database.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void EditButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (currentAccountIdInput.Text.Equals("") || currentTitleInput.Text.Equals("") || currentSkuInput.Text.Equals("") ||
                    newAccountIdInput.Text.Equals("") || newTitleInput.Text.Equals("") || newSkuInput.Text.Equals(""))
                {
                    MessageBox.Show("Please input all text boxes.");
                    currentAccountIdInput.Focus();
                    return;
                }
                else if ((!Regex.IsMatch(currentAccountIdInput.Text, "^[0-9]*$")) || (!Regex.IsMatch(newAccountIdInput.Text, "^[0-9]*$")))
                {
                    MessageBox.Show("Please input only numerical characters into the Account ID text box.");
                    currentAccountIdInput.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());
            }

            ProductObject product;
            ProductObject productAll     = businessLogicLayer.CheckProductsAll(int.Parse(currentAccountIdInput.Text), currentTitleInput.Text.ToLower(), currentSkuInput.Text.ToLower());
            ProductObject productCurrent = businessLogicLayer.CheckProductsByIDAndSku(int.Parse(currentAccountIdInput.Text), currentSkuInput.Text.ToLower());
            ProductObject productNew     = businessLogicLayer.CheckProductsByIDAndSku(int.Parse(newAccountIdInput.Text), newSkuInput.Text.ToLower());
            AccountObject account        = businessLogicLayer.CheckAccountsByID(int.Parse(newAccountIdInput.Text));

            try
            {
                if (!(int.Parse(currentAccountIdInput.Text).Equals(productAll.account_id) && currentTitleInput.Text.ToLower().Equals(productAll.title) &&
                      currentSkuInput.Text.ToLower().Equals(productAll.sku)))
                {
                    MessageBox.Show("The 'current' product provided does not exist.");
                    currentAccountIdInput.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(newAccountIdInput.Text).Equals(productNew.account_id) && !int.Parse(newAccountIdInput.Text).Equals(productCurrent.account_id) ||
                         newSkuInput.Text.ToLower().Equals(productNew.sku) && !newSkuInput.Text.ToLower().Equals(productCurrent.sku))
                {
                    MessageBox.Show("An Account with that SKU already exists.");
                    newAccountIdInput.Focus();
                    return;
                }
                else
                {
                    product = businessLogicLayer.EditCurrentProduct(int.Parse(newAccountIdInput.Text), newTitleInput.Text.ToLower(), newSkuInput.Text.ToLower(),
                                                                    int.Parse(currentAccountIdInput.Text), currentTitleInput.Text.ToLower(), currentSkuInput.Text.ToLower());
                    MessageBox.Show(currentTitleInput.Text + " 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());
            }
        }