Beispiel #1
0
        public Car AddTransaction(Car car, Client client, bool airConditioning, bool radio, bool cruiseControl, bool navigation)
        {
            if (airConditioning)
            {
                car = new AirConditioning(car);
            }
            if (radio)
            {
                car = new Radio(car);
            }
            if (cruiseControl)
            {
                car = new CruiseControl(car);
            }
            if (navigation)
            {
                car = new Navigation(car);
            }

            _transactions.Add(new Transaction(car, client));

            return car;
        }
Beispiel #2
0
        public void InitData()
        {
            Char delimiter = ' ';
            CarCreator creator = null;

            using (var srToyota = new StreamReader("toyota.txt"))
            {
                creator = new CarToyota();
                do
                {
                    var line = srToyota.ReadLine();
                    String[] substrings = line.Split(delimiter);

                    var car = creator.Create();
                    car.SetModel(substrings[0]);
                    car.SetPrice(int.Parse(substrings[1]));
                    _cars.AddCar(car);

                } while (srToyota.EndOfStream == false);
            }

            using (var srMercedes = new StreamReader("mercedes.txt"))
            {
                creator = new CarMercedes();
                do
                {
                    var line = srMercedes.ReadLine();
                    String[] substrings = line.Split(delimiter);

                    var car = creator.Create();
                    car.SetModel(substrings[0]);
                    car.SetPrice(int.Parse(substrings[1]));
                    _cars.AddCar(car);

                } while (srMercedes.EndOfStream == false);
            }

            using (var srFirmy = new StreamReader("firmy.txt"))
            {
                do
                {
                    var line = srFirmy.ReadLine();
                    String[] substrings = line.Split(delimiter);

                    _clients.Add(new Company(substrings[0]));


                } while (srFirmy.EndOfStream == false);
            }

            using (var srPrywatni = new StreamReader("klienciPrywatni.txt"))
            {
                do
                {
                    var line = srPrywatni.ReadLine();
                    String[] substrings = line.Split(delimiter);

                    _clients.Add(new Person(substrings[0], substrings[1]));

                } while (srPrywatni.EndOfStream == false);
            }

            using (var srPrywatni = new StreamReader("transakcje.txt"))
            {
                do
                {
                    var count = 0;
                    var line = srPrywatni.ReadLine();
                    String[] substrings = line.Split(delimiter);
                    Car car = null;
                    Client client = null;
                    var radio = line.Contains("radio");
                    var navigation = line.Contains("nawigacja");
                    var airConditioning = line.Contains("klimatyzacja");
                    var cruiseControl = line.Contains("tempomat");
                    var isMercedes = line.Contains("Mercedes");

                    if (isMercedes)
                    {
                        creator = new CarMercedes();
                        car = creator.Create();
                    }
                    else
                    {
                        creator = new CarToyota();
                        car = creator.Create();

                    }

                    car.SetModel(substrings[1]);

                    if (radio)
                    {
                        count += 2;
                        car = new Radio(car);

                    }
                    if (navigation)
                    {
                        count += 2;
                        car = new Navigation(car);

                    }
                    if (airConditioning)
                    {
                        count += 2;
                        car = new AirConditioning(car);

                    }
                    if (cruiseControl)
                    {
                        count += 2;
                        car = new CruiseControl(car);
                    }
                    var price = int.Parse(substrings[2 + count]);

                    var type = substrings[3 + count];
                    if (type == "Osoba")
                        client = new Person(substrings[4 + count], substrings[5 + count]);
                    else
                    {
                        client = new Company(substrings[4 + count]);
                    }
                    _transactions.Add(new Transaction(car, client, price));

                } while (srPrywatni.EndOfStream == false);
            }
        }