Пример #1
0
        public bool ValidateUserInformation()
        {
            // BEGIN USER INPUT DATA VALIDATION.....
            // Verify that PERSONAL information was not left blank
            if ((this.txtFirstName.Text == "") || (this.txtLastName.Text == "") || (this.txtPhoneNumber.Text == "") ||
                (this.txtEmailAddress.Text == "") || (this.txtUsername.Text == "") || (this.txtUserPassword.Text == "") ||
                (this.txtManagerPassword.Text == ""))
            {   // If any personal information was blank, display error and break code
                ApplicationObjects.DisplayInvalidInput("Please make sure that you have filled out all of the personal fields and try again.");
                return(false);
            }

            // Variable used in TryParse functions
            long number;

            // Validate numeric input for phone number
            if ((!long.TryParse((txtPhoneNumber.Text), out number)) || (txtPhoneNumber.Text.Length != 10))
            {   // If phone number input was not numeric, display error and break code
                ApplicationObjects.DisplayInvalidInput("Invalid phone number entered.  Please enter 10 digits (no dashes) & try again.");
                return(false);
            }

            // validate email address format
            if (!ApplicationObjects.EmailIsValid(txtEmailAddress.Text))
            {   // If email address was not in specified format, display error and break code
                ApplicationObjects.DisplayInvalidInput("Invalid e-mail address entered.  Please try again.");
                return(false);
            }

            // validate user name
            if (!(txtUsername.Text.Length >= 4))
            {
                ApplicationObjects.DisplayInvalidInput("Invalid username entered.  Your username must be four characters or longer.");
                return(false);
            }

            // validate password
            if (!(txtUserPassword.Text.Length >= 4))
            {
                ApplicationObjects.DisplayInvalidInput("Invalid password entered.  Your password must be four characters or longer.");
                return(false);
            }
            // .....END USER INPUT DATA VALIDATION

            return(true);
        }
Пример #2
0
        private void btnOrderSearch_Click(object sender, EventArgs e)
        {
            List <Order> ordersList = new List <Order>();

            if ((cbSearchFields.SelectedItem == null) || (tbx_Search.Text == ""))
            {
                ApplicationObjects.DisplayInvalidInput("Please make sure that you have entered search criteria.");
            }
            else if (cbSearchFields.SelectedItem.ToString() == "Inventory Item Id")
            {
                try
                {
                    // Generate a list of IOrders that match the Inventory Item ID entered by the user
                    ordersList = ApplicationObjects.GetOrderByInventoryItemId(new Guid(tbx_Search.Text));
                }
                catch (Exception)
                {   // Catch if a non-Guid was entered
                    ApplicationObjects.DisplayInvalidInput("Search failed!  You may have entered an invalid ID.  Please check your item ID and try again");
                    return;
                }
            }
            else if (cbSearchFields.SelectedItem.ToString() == "Order Id")
            {
                try
                {
                    // Generate a list of Orders that match the Order ID entered by the user
                    ordersList.Add(ApplicationObjects.GetOrder(new Guid(tbx_Search.Text)));
                }
                catch (Exception)
                {   // Catch if a non-Guid was entered
                    ApplicationObjects.DisplayInvalidInput("Search failed!  You may have entered an invalid ID.  Please check your item ID and try again");
                    return;
                }
            }
            else if (cbSearchFields.SelectedItem.ToString() == "Order Status")
            {
                // Convert user input into enum, before passing to search method
                OrderStatus orderStatus = BusinessLayer.Translators.Order.ConvertStringToOrderStatus(tbx_Search.Text);

                if (orderStatus == OrderStatus.None)
                {
                    ApplicationObjects.DisplayInvalidInput("You may have entered an invalid order status type.  Please try again");
                    return;
                }

                // Generate a list of Orders that match the Order ID entered by the user
                ordersList = ApplicationObjects.GetOrderByOrderStatus(orderStatus);
            }

            orderTable.Rows.Clear();
            if (ordersList.Count > 0)
            {
                foreach (Order order in ordersList)
                {
                    DataRow newRow = orderTable.NewRow();
                    newRow["Order Id"]        = order.OrderId.ToString();
                    newRow["First Name"]      = order.Person.FirstName;
                    newRow["Last Name"]       = order.Person.LastName;
                    newRow["Entry Date"]      = order.OrderEntryDate.ToString();
                    newRow["Fulfilled Date"]  = (order.OrderFulfillDate != null) ? order.OrderFulfillDate.ToString() : "not filled";
                    newRow["Number of Items"] = order.NumberOrderItems.ToString();
                    newRow["Order Status"]    = order.OrderStatus;
                    orderTable.Rows.Add(newRow);
                }

                dgvOrders.AutoResizeColumns();
            }
            else
            {
                MessageBox.Show("Your search turned up no results.  Please try again.", "No Results Found", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Пример #3
0
        // Begin CREATE CUSTOMER button click event
        private void btnCreateCustomer_Click(object sender, EventArgs e)
        {
            // BEGIN USER INPUT DATA VALIDATION.....
            // Verify that PERSONAL information was not left blank
            if ((tbx_FirstName.Text == "") || (tbx_LastName.Text == "") || (tbx_PhoneNumber.Text == "") || (tbx_EMail.Text == ""))
            {   // If any personal information was blank, display error and break code
                ApplicationObjects.DisplayInvalidInput("Please make sure that you have filled out all of the personal fields and try again.");
                return;
            }

            // Verify that MAILING address information was not left blank
            if ((tbx_MailingStreetNumber.Text == "") || (tbx_MailingStreetName.Text == "") || (tbx_MailingCity.Text == "") ||
                (tbx_MailingState.Text == "") || (tbx_MailingZipCode.Text == ""))
            {   // If any mailing address information was blank, display error and break code
                ApplicationObjects.DisplayInvalidInput("Please make sure that you have filled out all of the mailing address fields and try again.");
                return;
            }

            // Verify that BILLING address information was not left blank
            if ((tbx_BillingStreetNumber.Text == "") || (tbx_BillingStreetName.Text == "") || (tbx_BillingCity.Text == "") ||
                (tbx_BillingState.Text == "") || (tbx_BillingZipCode.Text == ""))
            {   // If any billing address information was blank, display error and break code
                ApplicationObjects.DisplayInvalidInput("Please make sure that you have filled out all of the billing address fields and try again.");
                return;
            }

            // Variable used in TryParse functions
            long number;

            // Validate numeric input for phone number
            if ((!long.TryParse((tbx_PhoneNumber.Text), out number)) || (tbx_PhoneNumber.Text.Length != 10))
            {   // If phone number input was not numeric, display error and break code
                ApplicationObjects.DisplayInvalidInput("Invalid phone number entered.  Please enter 10 digits (no dashes) & try again.");
                return;
            }

            // validate email address format
            if (!ApplicationObjects.EmailIsValid(tbx_EMail.Text))
            {   // If email address was not in specified format, display error and break code
                ApplicationObjects.DisplayInvalidInput("Invalid e-mail address entered.  Please try again.");
                return;
            }

            // Validate numeric input for street numbers
            if ((!long.TryParse((tbx_MailingStreetNumber.Text), out number)) || (!long.TryParse((tbx_BillingStreetNumber.Text), out number)))
            {   // If street number input was not numeric, display error and break code
                ApplicationObjects.DisplayInvalidInput("Invalid street number entered.  Please enter only numeric values & try again.");
                return;
            }

            // Verify that the state is only 2 characters
            if ((tbx_MailingState.Text.Length != 2) || (tbx_BillingState.Text.Length != 2))
            {   // If state input does not have only 2 characters, display error and break code
                ApplicationObjects.DisplayInvalidInput("Invalid state entered.  Please enter a 2-letter state abbreviation & try again.");
                return;
            }

            // Validate numeric input for zip codes
            if ((!long.TryParse((tbx_MailingZipCode.Text), out number)) || (!long.TryParse((tbx_BillingZipCode.Text), out number)))
            {   // If zip code input was not numeric, display error and break code
                ApplicationObjects.DisplayInvalidInput("Invalid zip code entered.  Please enter only numeric values & try again.");
                return;
            }

            // If zip is numeric, validate only 5 digits
            else if ((tbx_MailingZipCode.Text.Length != 5) || (tbx_BillingZipCode.Text.Length != 5))
            {   // If zip code does not have only 5 characters, display error and break code
                ApplicationObjects.DisplayInvalidInput("Invalid zip code entered.  Please enter only 5 digits & try again.");
                return;
            }
            // .....END USER INPUT DATA VALIDATION


            // Populate customer object with user input
            Customer customer = new Customer();

            customer.FirstName    = tbx_FirstName.Text;
            customer.LastName     = tbx_LastName.Text;
            customer.PhoneNumber  = tbx_PhoneNumber.Text;
            customer.EmailAddress = tbx_EMail.Text;

            // Populate mailing address object with user input
            Address mailingAddress = new Address();

            mailingAddress.PersonId     = customer.PersonId;
            mailingAddress.StreetNumber = int.Parse(tbx_MailingStreetNumber.Text);
            mailingAddress.StreetName   = tbx_MailingStreetName.Text;
            mailingAddress.AddressCity  = tbx_MailingCity.Text;
            mailingAddress.AddressState = tbx_MailingState.Text;
            mailingAddress.AddressZip   = tbx_MailingZipCode.Text;
            mailingAddress.AddressType  = AddressType.Mailing;

            // Populate billing address object with user input
            Address billingAddress = new Address();

            billingAddress.PersonId     = customer.PersonId;
            billingAddress.StreetNumber = int.Parse(tbx_BillingStreetNumber.Text);
            billingAddress.StreetName   = tbx_BillingStreetName.Text;
            billingAddress.AddressCity  = tbx_BillingCity.Text;
            billingAddress.AddressState = tbx_BillingState.Text;
            billingAddress.AddressZip   = tbx_BillingZipCode.Text;
            billingAddress.AddressType  = AddressType.Billing;

            // Transaction to perform 4 inter-related data inserts on multiple database tables
            using (TransactionScope scope = new TransactionScope())
            {
                int returnValue = 1;

                // Write PERSON record to database
                BusinessObjects _personBusinessObject = new BusinessObjects();
                returnValue = _personBusinessObject.InsertPersonFromCustomer(customer);
                if (returnValue == 1)
                {   // If insert fails, rollback transaction & display error message
                    scope.Dispose();
                    ApplicationObjects.DisplayDataStatus(returnValue);
                    return;
                }

                // Write CUSTOMER record to database
                BusinessObjects _customerBusinessObject = new BusinessObjects();
                returnValue = _customerBusinessObject.InsertCustomer(customer);
                if (returnValue == 1)
                {   // If insert fails, rollback transaction & display error message
                    scope.Dispose();
                    ApplicationObjects.DisplayDataStatus(returnValue);
                    return;
                }

                // Write MAILING ADDRESS record to database
                BusinessObjects _mailingAddressBusinessObject = new BusinessObjects();
                returnValue = _mailingAddressBusinessObject.InsertAddress(mailingAddress);
                if (returnValue == 1)
                {   // If insert fails, rollback transaction & display error message
                    scope.Dispose();
                    ApplicationObjects.DisplayDataStatus(returnValue);
                    return;
                }

                // Write BILLING ADDRESS record to database
                BusinessObjects _billingAddressBusinessObject = new BusinessObjects();
                returnValue = _billingAddressBusinessObject.InsertAddress(billingAddress);
                if (returnValue == 1)
                {   // If insert fails, rollback transaction & display error message
                    scope.Dispose();
                    ApplicationObjects.DisplayDataStatus(returnValue);
                    return;
                }

                // Committ data transaction & display success message
                scope.Complete();
                ApplicationObjects.DisplayDataStatus(returnValue);
            }// End transaction

            _loginForm.ShowCustomerInfoForm(userAccount, _loginForm);
            this.Close();
        }// End CREATE CUSTOMER button click event
        // CUSTOMER SEARCH BUTTON click event
        private void btn_CustomerSearch_Click(object sender, EventArgs e)
        {
            // Make sure all controls are visible
            gbx_SearchCriteria.Visible     = true;
            btn_ViewOrders.Visible         = true;
            btn_CreateCustomer.Visible     = true;
            btn_CustomerSearch.Visible     = true;;
            btn_MainPage.Visible           = true;
            btn_EnableEditing.Visible      = true;
            btn_NewOrder.Visible           = true;
            btn_SaveChanges.Visible        = false;
            lbl_CustomerResultSort.Visible = false;

            //Make all customer data fields read-only by default
            MakeReadOnly();

            //Reset form to prepare for new search results
            ClearResults();

            // Verify that a query type was selected by the user
            if ((cbx_CustomerSearchType.SelectedItem == null) || (tbx_CustomerSearchInput.Text == null))
            {
                ApplicationObjects.DisplayInvalidInput("Please make sure all search criterea is filled out.");
                return;
            }

            // SEARCH BY CUSTOMER FIRST NAME - Chech to see if user entered a customer first name
            else if (cbx_CustomerSearchType.SelectedItem.ToString() == "First Name")
            {
                // Generate a list of customers that match the first name entered by the user
                customers = ApplicationObjects.GetCustomerByFirstName(tbx_CustomerSearchInput.Text);

                // If customer list is empty, display no results found
                if (customers == null)
                {
                    lbl_CustomerResultsFound.Text = "No results found!";
                }

                else
                {
                    // Populate the search results combo box with result first and last names
                    foreach (Customer customer in customers)
                    {
                        cbx_CustomerResultsList.Items.Add(customer.FirstName + " " + customer.LastName);
                    }

                    // Change result label to show how results are listed in the results combobox
                    lbl_CustomerResultSort.Text   = "results listed by [first name] [last name]";
                    lbl_CustomerResultsFound.Text = cbx_CustomerResultsList.Items.Count.ToString() + " results found!";
                }
            }

            // SEARCH BY CUSTOMER LAST NAME - Check to see if user entered a customer last name
            else if (cbx_CustomerSearchType.SelectedItem.ToString() == "Last Name")
            {
                // Generate a list of customers that match the last name entered by the user
                customers = ApplicationObjects.GetCustomerByLastName(tbx_CustomerSearchInput.Text);

                if (customers == null)
                {
                    lbl_CustomerResultsFound.Text = "No results found!";
                }

                else
                {
                    // Populate the search results combo box with result last, first names
                    foreach (Customer customer in customers)
                    {
                        cbx_CustomerResultsList.Items.Add(customer.LastName + ", " + customer.FirstName);
                    }

                    // Change result label to show how results are listed in the results combobox
                    lbl_CustomerResultSort.Text   = "results listed by [last name], [first name]";
                    lbl_CustomerResultsFound.Text = cbx_CustomerResultsList.Items.Count.ToString() + " results found!";
                }
            }

            // SEARCH BY CUSTOMER ID - Check to see if user entered a customer ID
            else if (cbx_CustomerSearchType.SelectedItem.ToString() == "Customer ID")
            {    //if invalid Guid, display error
                if (!Guid.TryParse((tbx_CustomerSearchInput.Text), out guidValidation))
                {
                    ApplicationObjects.DisplayInvalidInput("Invalid customer ID.  Please try again.");
                    return;
                }

                //If valid Guid, continue with search
                else
                {
                    // Generate a list of customers that match the customer ID entered by the user
                    customers = ApplicationObjects.GetCustomerByCustomerId(Guid.Parse(tbx_CustomerSearchInput.Text));

                    if (customers == null)
                    {
                        lbl_CustomerResultsFound.Text = "No results found!";
                    }

                    else
                    {
                        // Populate the search results combo box with result last, first names
                        foreach (Customer customer in customers)
                        {
                            cbx_CustomerResultsList.Items.Add(customer.CustomerId.ToString());
                        }

                        // Change result label to show how results are listed in the results combobox
                        lbl_CustomerResultSort.Text   = "results listed by [customer id]";
                        lbl_CustomerResultsFound.Text = cbx_CustomerResultsList.Items.Count.ToString() + " results found!";
                    }
                }
            }

            // SEARCH BY CUSTOMER PHONE NUMBER - Check to see if user entered a customer phone number
            else if (cbx_CustomerSearchType.SelectedItem.ToString() == "Phone Number")
            {
                // Validate numeric input for phone number
                if ((!long.TryParse((tbx_CustomerSearchInput.Text), out longValidation)) || (tbx_CustomerSearchInput.Text.Length != 10))
                {
                    ApplicationObjects.DisplayInvalidInput("Invalid phone number entered.  Please enter 10 digits (no dashes) & try again.");
                    return;
                }
                else
                {
                    // Generate a list of customers that match the phone number entered by the user
                    customers = ApplicationObjects.GetCustomerByPhoneNumber(tbx_CustomerSearchInput.Text);

                    // If customer list is empty, display no results found
                    if (customers == null)
                    {
                        lbl_CustomerResultsFound.Text = "No results found!";
                    }

                    else
                    {
                        // Populate the search results combo box with result last, first names
                        foreach (Customer customer in customers)
                        {
                            cbx_CustomerResultsList.Items.Add(customer.PhoneNumber);
                        }

                        // Change result label to show how results are listed in the results combobox
                        lbl_CustomerResultSort.Text   = "results listed by [phone number]";
                        lbl_CustomerResultsFound.Text = cbx_CustomerResultsList.Items.Count.ToString() + " results found!";
                    }
                }
            }

            // SEARCH BY CUSTOMER EMAIL ADDRESS - Check to see if user entered a customer email address
            else if (cbx_CustomerSearchType.SelectedItem.ToString() == "Email Address")
            {
                // validate email address format
                if (!ApplicationObjects.EmailIsValid(tbx_CustomerSearchInput.Text))
                {
                    ApplicationObjects.DisplayInvalidInput("Invalid e-mail address entered.  Please try again.");
                    return;
                }
                else
                {
                    // Generate a list of customers that match the email address entered by the user
                    customers = ApplicationObjects.GetCustomerByEmail(tbx_CustomerSearchInput.Text);

                    // If customer list is empty, display no results found
                    if (customers == null)
                    {
                        lbl_CustomerResultsFound.Text = "No results found!";
                    }

                    else
                    {
                        // Populate the search results combo box with result last, first names
                        foreach (Customer customer in customers)
                        {
                            cbx_CustomerResultsList.Items.Add(customer.EmailAddress);
                        }

                        // Change result label to show how results are listed in the results combobox
                        lbl_CustomerResultSort.Text   = "results listed by [email address]";
                        lbl_CustomerResultsFound.Text = cbx_CustomerResultsList.Items.Count.ToString() + " results found!";
                    }
                }
            }
            // If the customer list is empty (no results found)
            if (customers.Count == 0)
            {   // Display no results found
                lbl_CustomerResultsFound.Text = "No results found!";
                return;
            }

            // If customer list is not empty, display results
            else
            {
                lbl_CustomerResultSort.Visible        = true;
                cbx_CustomerResultsList.Visible       = true;
                cbx_CustomerResultsList.SelectedIndex = 0;

                //Populate Customer details for first search result
                PopulateCustomerDetailsWithSelectedIndex();
            }
        }
        // SAVE CHANGES BUTTON click event - Save changes made to currently selected customer
        private void btn_SaveChanges_Click(object sender, EventArgs e)
        {
            // BEGIN USER INPUT DATA VALIDATION.....
            // Verify that PERSONAL information was not left blank
            if ((this.tbx_FirstName.Text == "") || (this.tbx_LastName.Text == "") || (this.tbx_PhoneNumber.Text == "") || (this.tbx_EMail.Text == ""))
            {   // If any personal information was blank, display error and break code
                ApplicationObjects.DisplayInvalidInput("Please make sure that you have filled out all of the personal fields and try again.");
                return;
            }

            // Verify that MAILING address information was not left blank
            if ((this.tbx_MailingStreetNumber.Text == "") || (this.tbx_MailingStreetName.Text == "") || (this.tbx_MailingCity.Text == "") ||
                (this.tbx_MailingState.Text == "") || (this.tbx_MailingZipCode.Text == ""))
            {   // If any mailing address information was blank, display error and break code
                ApplicationObjects.DisplayInvalidInput("Please make sure that you have filled out all of the mailing address fields and try again.");
                return;
            }

            // Verify that BILLING address information was not left blank
            if ((this.tbx_BillingStreetNumber.Text == "") || (this.tbx_BillingStreetName.Text == "") || (this.tbx_BillingCity.Text == "") ||
                (this.tbx_BillingState.Text == "") || (this.tbx_BillingZipCode.Text == ""))
            {   // If any billing address information was blank, display error and break code
                ApplicationObjects.DisplayInvalidInput("Please make sure that you have filled out all of the billing address fields and try again.");
                return;
            }

            // Validate numeric input for phone number
            if ((!long.TryParse((this.tbx_PhoneNumber.Text), out longValidation)) || (this.tbx_PhoneNumber.Text.Length != 10))
            {   // If phone number input was not numeric, display error and break code
                ApplicationObjects.DisplayInvalidInput("Invalid phone number entered.  Please enter 10 digits (no dashes) & try again.");
                return;
            }

            // validate email address format
            if (!ApplicationObjects.EmailIsValid(this.tbx_EMail.Text))
            {   // If email address was not in specified format, display error and break code
                ApplicationObjects.DisplayInvalidInput("Invalid e-mail address entered.  Please try again.");
                return;
            }

            // Validate numeric input for street numbers
            if ((!long.TryParse((this.tbx_MailingStreetNumber.Text), out longValidation)) || (!long.TryParse((this.tbx_BillingStreetNumber.Text), out longValidation)))
            {   // If street number input was not numeric, display error and break code
                ApplicationObjects.DisplayInvalidInput("Invalid street number entered.  Please enter only numeric values & try again.");
                return;
            }

            // Verify that the state is only 2 characters
            if ((this.tbx_MailingState.Text.Length != 2) || (this.tbx_BillingState.Text.Length != 2))
            {   // If state input does not have only 2 characters, display error and break code
                ApplicationObjects.DisplayInvalidInput("Invalid state entered.  Please enter a 2-letter state abbreviation & try again.");
                return;
            }

            // Validate numeric input for zip codes
            if ((!long.TryParse((this.tbx_MailingZipCode.Text), out longValidation)) || (!long.TryParse((this.tbx_BillingZipCode.Text), out longValidation)))
            {   // If zip code input was not numeric, display error and break code
                ApplicationObjects.DisplayInvalidInput("Invalid zip code entered.  Please enter only numeric values & try again.");
                return;
            }

            // If zip is numeric, validate only 5 digits
            else if ((this.tbx_MailingZipCode.Text.Length != 5) || (this.tbx_BillingZipCode.Text.Length != 5))
            {   // If zip code does not have only 5 characters, display error and break code
                ApplicationObjects.DisplayInvalidInput("Invalid zip code entered.  Please enter only 5 digits & try again.");
                return;
            }
            // .....END USER INPUT DATA VALIDATION

            // Take the user input from the text boxes and update the currently selected...
            // ...customer's information within the customer object
            PopulateCustomerObjectWithDetails();

            // Send update request to business layer
            int returnValue = ApplicationObjects.UpdateCustomer(customers[cbx_CustomerResultsList.SelectedIndex]);

            // Re-run search
            if (returnValue == 0)
            {   // If update successfull, re-run search based on the customerID of the customer that was just updated
                cbx_CustomerSearchType.SelectedIndex = 2;
                tbx_CustomerSearchInput.Text         = customers[cbx_CustomerResultsList.SelectedIndex].CustomerId.ToString();
            }

            // Perform search button click to re-populate search results
            gbx_SearchCriteria.Visible     = true;
            btn_ViewOrders.Visible         = true;
            btn_CreateCustomer.Visible     = true;
            btn_CustomerSearch.Visible     = true;;
            btn_MainPage.Visible           = true;
            btn_EnableEditing.Visible      = true;
            btn_NewOrder.Visible           = true;
            btn_SaveChanges.Visible        = false;
            lbl_CustomerResultSort.Visible = false;
            cbx_SameAsMailing.Visible      = true;
            btn_CustomerSearch.PerformClick();
        }