Exemple #1
0
        /// <summary>
        /// Creates a vehicle of a given state dependent on selected customer type(null,pri,bus). Has inputbox fault logic to stop the creation of bugged inputs
        /// </summary>
        private void create_vehicle_click(object sender, RoutedEventArgs e)
        {
            bool car_null_exception     = false;
            bool truck_null_exception   = false;
            bool car_format_exception   = false;
            bool truck_format_exception = false;
            bool error_found_truck      = false;
            bool error_found_car        = false;

            string car_boxes_empty_string    = "";
            string truck_boxes_empty_string  = "";
            string car_wrong_format_string   = "";
            string truck_wrong_format_string = "";

            //selected private
            #region
            if (select_combobox_customer.SelectedValue is Private || select_combobox_customer.SelectedValue == null)
            {
                //Test if text boxes in the car section are empty.
                if (string.IsNullOrEmpty(textbox_car_model.Text) == true ||
                    string.IsNullOrEmpty(textbox_car_license.Text) == true ||
                    string.IsNullOrEmpty(textbox_car_price.Text) == true ||
                    string.IsNullOrEmpty(textbox_car_colour.Text) == true)
                {
                    car_boxes_empty_string = "You have forgotten to fill in informationboxes in your car informations\n";
                    car_null_exception     = true;
                }

                //Test if text boxes in the car section are in the right format
                if (IsALLnumeric(textbox_car_price.Text, false) == false)
                {
                    car_wrong_format_string = "Your have format errors in your car informations\n";
                    car_format_exception    = true;
                }
                if ((car_null_exception ||
                     car_format_exception) == true)
                {
                    MessageBox.Show(car_boxes_empty_string +
                                    car_wrong_format_string);
                    error_found_car = true;
                }
            }

            //selected business
            if (select_combobox_customer.SelectedValue is Business || select_combobox_customer.SelectedValue == null)
            {
                //Test if text boxes in the truck section are empty
                if (string.IsNullOrEmpty(textbox_truck_model.Text) == true ||
                    string.IsNullOrEmpty(textbox_truck_license.Text) == true ||
                    string.IsNullOrEmpty(textbox_truck_rent.Text) == true ||
                    string.IsNullOrEmpty(textbox_truck_colour.Text) == true)
                {
                    truck_boxes_empty_string = "You have forgotten to fill in informationboxes in your truck informations \n";
                    truck_null_exception     = true;
                }
                //Test if text boxes in the truck section are in the right format
                if (IsALLnumeric(textbox_truck_rent.Text, false) == false)
                {
                    truck_wrong_format_string = "Your have format errors in your truck informations\n";
                    truck_format_exception    = true;
                }
            }
            //If any of the boxes were in the wrong format or empty,
            //then show the messagebox notifying the user and break the finalize action.
            if ((truck_null_exception ||
                 truck_format_exception) == true)
            {
                MessageBox.Show(truck_boxes_empty_string +
                                truck_wrong_format_string);
                error_found_truck = true;
            }

            #endregion
            // if no errors found then complete the finalize action and bring up the finalize window.

            //check if private customer and create contract.
            if (error_found_car == false)
            {
                if (select_combobox_customer.SelectedValue == null)
                {
                    if (combo_veh_size_small_item.IsSelected) //Remember to add size parameter
                    {
                        Small myveh = new Small(textbox_car_colour.Text,
                                                textbox_car_model.Text,
                                                Convert.ToInt32(textbox_car_price.Text),
                                                "in stock",
                                                textbox_car_license.Text);

                        mycardealer.AddVehicle(myveh);
                    }
                    if (combo_veh_size_large_item.IsSelected)
                    {
                        Large myveh = new Large(textbox_car_colour.Text,
                                                textbox_car_model.Text,
                                                Convert.ToInt32(textbox_car_price.Text),
                                                "in stock",
                                                textbox_car_license.Text);

                        mycardealer.AddVehicle(myveh);
                    }


                    MessageBox.Show("Car Added");
                    this.comboBox_Del_Vehicle.ItemsSource = mycardealer.VehicleList;
                }

                if (select_combobox_customer.SelectedValue is Private)
                {
                    if (combo_veh_size_small_item.IsSelected) //Remember to add size parameter
                    {
                        Small myveh = new Small(textbox_car_colour.Text,
                                                textbox_car_model.Text,
                                                Convert.ToInt32(textbox_car_price.Text),
                                                "sold",
                                                textbox_car_license.Text);

                        mycardealer.AddVehicle(myveh);
                        Private b = (Private)select_combobox_customer.SelectedValue;
                        mycardealer.DeleteCustomer(b.Address);
                        Contract gui_contract = new Contract(myveh, "contract");

                        b.AddContract(gui_contract);
                        mycardealer.AddCustomer(b);
                        //MessageBox.Show("ADDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD contract\n");
                    }

                    if (combo_veh_size_large_item.IsSelected)
                    {
                        Large myveh = new Large(textbox_car_colour.Text,
                                                textbox_car_model.Text,
                                                Convert.ToInt32(textbox_car_price.Text),
                                                "sold",
                                                textbox_car_license.Text);

                        mycardealer.AddVehicle(myveh);
                        Private b = (Private)select_combobox_customer.SelectedValue;
                        //Delete the customer without the contract
                        mycardealer.DeleteCustomer(b.Address);
                        Contract gui_contract = new Contract(myveh, "contract");
                        b.AddContract(gui_contract);
                        //Update the new customer with the contract
                        mycardealer.AddCustomer(b);
                    }
                    //       mycardealer.SaveCustomersToFile();

                    this.comboBox_del_customer.ItemsSource = mycardealer.LoadCustomers();
//__________
                    this.select_combobox_customer.ItemsSource = mycardealer.CustomerList;

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

                mycardealer.SaveVehiclesToFile();
            }
            //check if business customer and create lease.
            if (error_found_truck == false)
            {
                if (select_combobox_customer.SelectedValue == null)
                {
                    Truck myveh = new Truck(textbox_truck_colour.Text,
                                            textbox_truck_model.Text,
                                            Convert.ToInt32(textbox_truck_rent.Text),
                                            "in stock",
                                            textbox_truck_license.Text);

                    mycardealer.AddVehicle(myveh);
                    MessageBox.Show(mycardealer.ToString());
                    //this.comboBox_Del_Vehicle.ItemsSource = mycardealer.VehicleList;
                }

                if (select_combobox_customer.SelectedValue is Business)
                {
                    Truck myveh = new Truck(textbox_truck_colour.Text,
                                            textbox_truck_model.Text,
                                            Convert.ToInt32(textbox_truck_rent.Text),
                                            "leased",
                                            textbox_truck_license.Text);

                    mycardealer.AddVehicle(myveh);
                    Business b = (Business)select_combobox_customer.SelectedValue;
                    mycardealer.DeleteCustomer(b.Address);
                    Leasing gui_contract = new Leasing(myveh,
                                                       "truckContract",
                                                       Convert.ToInt32(textbox_truck_rent.Text),
                                                       datepicker_truck_start.SelectedDate,
                                                       datepicker_truck_end.SelectedDate);
                    b.AddLease(gui_contract);
                    mycardealer.AddCustomer(b);
                    MessageBox.Show(mycardealer.ToString());
                }

                mycardealer.SaveVehiclesToFile();
                this.comboBox_Del_Vehicle.ItemsSource = mycardealer.VehicleList;
                MessageBox.Show(mycardealer.ToString());
            }
        }