예제 #1
0
        //button logic
        #region
        /// <summary>
        /// Creates a customer of a given type dependent on selected type (pri,bus). Has inputbox fault logic to stop the creation of bugged bugged inputs
        /// </summary>
        private void create_customer_click(object sender, RoutedEventArgs e)
        {
            bool pri_null_exception   = false;
            bool bus_null_exception   = false;
            bool pri_format_exception = false;
            bool bus_format_exception = false;

            string pri_boxes_empty_string  = "";
            string bus_boxes_empty_string  = "";
            string pri_wrong_format_string = "";
            string bus_wrong_format_string = "";

            if (select_pri_customer.IsChecked == true)
            {
                //Test if text boxes in the private section are empty.
                if (string.IsNullOrEmpty(textbox_pri_address.Text) == true ||
                    string.IsNullOrEmpty(textbox_pri_phone.Text) == true ||
                    string.IsNullOrEmpty(textbox_pri_name.Text) == true)
                {
                    pri_boxes_empty_string = "You have forgotten to fill in informationboxes in private customer \n";
                    pri_null_exception     = true;
                }
                //Test if text boxes in the private section are in the right format.
                if (IsAllAlphabetic(textbox_pri_name.Text, false) == false ||
                    IsALLnumeric(textbox_pri_phone.Text, false) == false)
                {
                    pri_wrong_format_string = "Your have format errors in your private customer \n";
                    pri_format_exception    = true;
                }
            }
            if (select_bus_customer.IsChecked == true)
            {
                //Test if text boxes in the business section are empty
                if (string.IsNullOrEmpty(textbox_bus_address.Text) == true ||
                    string.IsNullOrEmpty(textbox_bus_phone.Text) == true ||
                    string.IsNullOrEmpty(textbox_bus_seno.Text) == true ||
                    string.IsNullOrEmpty(textbox_bus_fax.Text) == true ||
                    string.IsNullOrEmpty(textbox_bus_contact.Text) == true ||
                    string.IsNullOrEmpty(textbox_bus_company.Text) == true)
                {
                    bus_boxes_empty_string = "You have forgotten to fill in informationboxes in business customer \n";
                    bus_null_exception     = true;
                }
                //Test if text boxes in the business section are in the right format
                if (IsAllAlphabetic(textbox_bus_contact.Text, false) == false ||
                    IsALLnumeric(textbox_bus_phone.Text, false) == false ||
                    IsALLnumeric(textbox_bus_seno.Text, false) == false ||
                    IsALLnumeric(textbox_bus_fax.Text, false) == false
                    )
                {
                    bus_wrong_format_string = "Your have format errors in your private customer \n";
                    bus_format_exception    = true;
                }
            }
            if ((pri_null_exception ||
                 bus_null_exception ||
                 pri_format_exception ||
                 bus_format_exception) == true)
            {
                MessageBox.Show(pri_boxes_empty_string +
                                bus_boxes_empty_string +
                                pri_wrong_format_string +
                                bus_wrong_format_string);
            }

            else
            {
                //check if private customer.
                if (select_pri_customer.IsChecked == true)
                {
                    Private gui_pri_customer = new Private(textbox_pri_address.Text,
                                                           Convert.ToInt32(textbox_pri_phone.Text),
                                                           textbox_pri_name.Text,
                                                           datepicker_pri_birth.SelectedDate,
                                                           combo_pri_sex.Text);
                    mycardealer.AddCustomer(gui_pri_customer);
                }
                //check if business customer and create lease.
                if (select_bus_customer.IsChecked == true)
                {
                    Business gui_bus_customer = new Business(textbox_bus_address.Text,
                                                             Convert.ToInt32(textbox_bus_phone.Text),
                                                             Convert.ToInt32(textbox_bus_seno.Text),
                                                             Convert.ToInt32(textbox_bus_fax.Text),
                                                             textbox_bus_contact.Text, textbox_bus_company.Text);
                    mycardealer.AddCustomer(gui_bus_customer);
                }

                mycardealer.SaveCustomersToFile();
                this.comboBox_del_customer.ItemsSource = mycardealer.CustomerList;

                this.select_combobox_customer.ItemsSource = mycardealer.CustomerList;

                MessageBox.Show(mycardealer.ToString());
            }
        }