Example #1
0
 /// <summary>
 /// Create a lease
 /// </summary>
 /// <remarks>Business and a truck</remarks>
 // add rentperiod logic, atm it accepts a string, but it needs to do calculations on start to end date.
 public Leasing(Truck truck, string leaseName, int rent, DateTime? rent_start, DateTime? rent_end )
 {
     //this.formatter = new BinaryFormatter();
     this.truck = truck;
     this.leaseName = leaseName;
     this.rentPerMonth = rent;
     this.rent_start = rent_start;
     this.rent_end = rent_end;
 }
Example #2
0
            static void Main(string[] args)
            {
                //1- 2 lists
                List<Vehicle> veh_list = new List<Vehicle>();
                List<Customer> cust_list = new List<Customer>();
                //2- CarDealer with empty list
                CarDealer CD = new CarDealer(veh_list, cust_list);

                //3 customers
                Private pri_cust = new Private("address", 123123123, "G******g", null, "yes");
                Business bus_cust = new Business("address", 4444444, 1001001, 555555, "MR Coder", "Even god code SA");          //Add customers
                CD.AddCustomer(pri_cust);
                CD.AddCustomer(bus_cust);

                //4 create cars
                Car c = new Car("Ford", "Fiesta", 12000, "sold","111");
                Truck t = new Truck("Mercedes", "truck5000", 112000, "sold", "222");
                //add vehicles
                CD.AddVehicle(c);
                CD.AddVehicle(t);

                //6 Create a contract
                Contract contract2 = new Contract(c, "contractForCar");
                //7 Select customer and add the contract to him
                pri_cust.AddContract(contract2);
                //Or a lease
                Leasing lease = new Leasing(t, "serious truck business", 3000,null, null);
                bus_cust.AddLease(lease);

                //8 Save all the stuff in files, 1 time is enough
                CD.SaveVehiclesToFile();
                CD.SaveCustomersToFile();

                //9 Load stuff in new object
                CarDealer CD_DeserializedStuff = new CarDealer(new List<Vehicle>(), new List<Customer>());
                CD_DeserializedStuff.VehicleList = CD.LoadVehicles();
                CD_DeserializedStuff.CustomerList = CD.LoadCustomers();
                Console.Out.WriteLine(CD_DeserializedStuff.ToString());

                Console.In.ReadLine();
            }
        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);
                    }

                    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;

                        Contract gui_contract = new Contract(myveh, "contract");

                        b.AddContract(gui_contract);

                        MessageBox.Show(mycardealer.ToString());

                    }

                    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;

                        Contract gui_contract = new Contract(myveh, "contract");

                        b.AddContract(gui_contract);

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

                    //this.comboBox_Del_Vehicle.ItemsSource = mycardealer.LoadVehicles();
                    //this.select_combobox_customer.ItemsSource = mycardealer.LoadVehicles();

                }
                mycardealer.SaveVehiclesToFile();
            }
            //check if business customer and create lease.
            else 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);
                    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;

                    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);
                }
                MessageBox.Show(mycardealer.ToString());
                mycardealer.SaveVehiclesToFile();
                this.comboBox_Del_Vehicle.ItemsSource = mycardealer.LoadVehicles();
            }
        }