Exemplo n.º 1
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();
            }
Exemplo n.º 2
0
        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.LoadCustomers();
                this.select_combobox_customer.ItemsSource = this.mycardealer.LoadCustomers();

                MessageBox.Show(mycardealer.ToString());

            }
        }