Пример #1
0
        /// <summary>
        /// Чтение из  xml файла.
        /// </summary>
        /// <param name="taxi">Объект таксопарка.</param>
        /// <param name="fileName">Название файла.</param>
        public void ReaderFile(ref TaxiStation taxi, string fileName)
        {
            var xml  = XDocument.Load(fileName);
            var qwe  = new List <Car>();
            var cars = xml.Root.Descendants("taxi").Select(x => x);

            foreach (var el in cars)
            {
                var name1 = el.Attribute("type").Value;
                switch (name1)
                {
                case "Truck":
                    var tempCarT = new Truck();
                    tempCarT.Make  = Convert.ToString(el.Element("make").Value);
                    tempCarT.Model = Convert.ToString(el.Element("model").Value);
                    tempCarT.Speed = Convert.ToInt32(el.Element("speed").Value);
                    tempCarT.Price = Convert.ToInt32(el.Element("price").Value);
                    tempCarT.Load  = Convert.ToInt32(el.Element("load").Value);
                    qwe.Add(tempCarT);
                    break;

                case "Bus":
                    var tempCarB = new Bus();
                    tempCarB.Make  = Convert.ToString(el.Element("make").Value);
                    tempCarB.Model = Convert.ToString(el.Element("model").Value);
                    tempCarB.Speed = Convert.ToInt32(el.Element("speed").Value);
                    tempCarB.Price = Convert.ToInt32(el.Element("price").Value);
                    tempCarB.Count = Convert.ToInt32(el.Element("count").Value);
                    qwe.Add(tempCarB);
                    break;

                case "PassengerCar":
                    var tempCarP = new PassengerCar();
                    tempCarP.Make         = Convert.ToString(el.Element("make").Value);
                    tempCarP.Model        = Convert.ToString(el.Element("model").Value);
                    tempCarP.Speed        = Convert.ToInt32(el.Element("speed").Value);
                    tempCarP.Price        = Convert.ToInt32(el.Element("price").Value);
                    tempCarP.EngineVolume = Convert.ToDouble(el.Element("engineVolume").Value);
                    qwe.Add(tempCarP);
                    break;

                default: break;
                }
            }
            var taxi1 = new TaxiStation()
            {
                CarsList = qwe.ToList()
            };

            taxi = taxi1;
        }
Пример #2
0
        /// <summary>
        /// Добавление транспорта в список.
        /// </summary>
        /// <returns>Список всех транспортных средств таксопарка.</returns>
        public List <Car> AddToFile()
        {
            List <Car> temp      = CarsList;
            int        countList = temp.Count();

            Console.WriteLine("Введите тип транспорта(Truck/Bus/PassengerCar):");
            string type = Console.ReadLine();

            Console.WriteLine("Введите марку:");
            string make = Console.ReadLine();

            Console.WriteLine("Введите модель:");
            string model = Console.ReadLine();

            Console.WriteLine("Введите максимальную  скорость:");
            int speed = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Введите цену:");
            int price = Convert.ToInt32(Console.ReadLine());

            if (type == "Truck")
            {
                var tempAddList = new Truck();
                Console.WriteLine("Введите грузоподъемность:");
                tempAddList.Load = Convert.ToInt32(Console.ReadLine());
                temp.Add(tempAddList);
            }
            else if (type == "Bus")
            {
                var tempAddList = new Bus();
                Console.WriteLine("Введите количество  мест:");
                tempAddList.Count = Convert.ToInt32(Console.ReadLine());
                temp.Add(tempAddList);
            }
            else
            {
                var tempAddList = new PassengerCar();
                Console.WriteLine("Введите объем двигателя:");
                tempAddList.EngineVolume = Convert.ToInt32(Console.ReadLine());
                temp.Add(tempAddList);
            }
            temp[countList].Make  = make;
            temp[countList].Model = model;
            temp[countList].Speed = speed;
            temp[countList].Price = price;
            return(CarsList = temp);
        }