예제 #1
0
        public List <Tour_Info> LoadFromFile(string fileName)
        {
            try
            {
                using (StreamReader sr = new StreamReader(path + fileName, System.Text.Encoding.Default))
                {
                    List <Tour_Info> list = new List <Tour_Info>();
                    while (sr.Peek() > -1)
                    {
                        string   country  = sr?.ReadLine();
                        string   city     = sr?.ReadLine();
                        string   hotel    = sr?.ReadLine();
                        DateTime dep_date = DateTime.Parse(sr?.ReadLine()); //сделать отдельную функцию ввода данных
                        DateTime ret_date = DateTime.Parse(sr?.ReadLine());
                        int      price;
                        int.TryParse(sr?.ReadLine(), out price);
                        sr?.ReadLine();
                        Tour_Info tmp = new Tour_Info(country, city, hotel, dep_date, ret_date, price);
                        list.Add(tmp);
                    }
                    sr.Close();
                    return(list);
                }
            }

            catch
            {
                throw new Exception("Такого файла не существует"); //жесткое исключение. Делал для проверки файла на существование, но для этого есть FileExists
            }
        }
예제 #2
0
        public static void SetTour(List <Tour_Info> list) //Создание объекта Tour_Info
        {
            Console.WriteLine("Введите страну");
            string country = Console.ReadLine();

            Console.WriteLine("Введите город");
            string city = Console.ReadLine();

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

            Console.WriteLine("Введите дату вылета");
            DateTime dep_date = DateTime.Parse(Console.ReadLine());

            Console.WriteLine("Введите дату возврата");
            DateTime ret_date = DateTime.Parse(Console.ReadLine());

            Console.WriteLine("Введите цену");
            int price;

            int.TryParse(Console.ReadLine(), out price);
            Console.ReadLine();
            Tour_Info tmp = new Tour_Info(country, city, hotel, dep_date, ret_date, price);

            list.Add(tmp);
        }