static void Main(string[] args) { Book Book = new Book(1, "Пушкин", "Руслан и Людмила", "Поэма"); Exemplar exemplar = new Exemplar(1, Book, DateTime.Now, "Exmo"); Position position = new Position(1, "Библиотекарь"); Reader reader = new ReaderPro("вип", 1, "Семенов", "Игорь", "Евгеньевич", "муж.", 79835); Employee employee = new Employee(1, position, "Петрова", "Людмила", "Сергеевна", 345678892, 4, "Киров", "Попова", "6"); Delivery delivery = new Delivery(1, new DateTime(2018, 05, 04), employee, reader, exemplar); Reader reader2 = new ReaderSimple("обычный", 1, "Крючкова", "Антонина", "Александровна", "жен.", 79835); Book Book1 = new Book(1, "Лермонтов", "Мцыри", "Поэма"); Exemplar exemplar1 = new Exemplar(1, Book, DateTime.Now, "Exmo"); Position position1 = new Position(1, "Библиотекарь"); Delivery delivery1 = new Delivery(2, new DateTime(2018, 05, 10), employee, reader2, exemplar1); DateTime start = new DateTime(2018, 05, 6); DateTime end = new DateTime(2019, 12, 31); List <Delivery> ListDelivery = new List <Delivery>(); ListDelivery.Add(delivery); ListDelivery.Add(delivery1); List <Reader> ListReader = new List <Reader>(); ListReader.Add(reader); ListReader.Add(reader2); List <Type> TypeList = new List <Type>(); foreach (Reader t in ListReader) { try { TypeList.Add(t.GetType()); } catch (Exception ex) { Console.WriteLine("Ошибка {0}", ex.Message); } } XmlSerializer formatter = new XmlSerializer(ListReader.GetType(), TypeList.ToArray()); using (FileStream fs = new FileStream("reader.xml", FileMode.OpenOrCreate)) { formatter.Serialize(fs, ListReader); Console.WriteLine("Сериализация XML прошла успешно"); } using (FileStream fs = new FileStream("reader.xml", FileMode.OpenOrCreate)) { List <Reader> ListDeserTovar = formatter.Deserialize(fs) as List <Reader>; foreach (Reader tv in ListDeserTovar) { tv.Info(); } } Console.ReadLine(); }
static void Main(string[] args) { Book Book = new Book(1, "Пушкин", "Руслан и Людмила", "Поэма"); Exemplar exemplar = new Exemplar(1, Book, DateTime.Now, "Exmo"); Position position = new Position(1, "Библиотекарь"); IReader reader = new ReaderPro("вип", 1, "Семенов", "Игорь", "Евгеньевич", "муж.", 79835); Employee employee = new Employee(1, position, "Петрова", "Людмила", "Сергеевна", 345678892, 4, "Киров", "Попова", "6"); Delivery delivery = new Delivery(1, new DateTime(2018, 05, 04), employee, reader, exemplar); // delivery.Info(); //Console.ReadLine(); IReader reader2 = new ReaderSimple("обычный", 1, "Крючкова", "Антонина", "Александровна", "жен.", 79835); Book Book1 = new Book(1, "Лермонтов", "Мцыри", "Поэма"); Exemplar exemplar1 = new Exemplar(1, Book, DateTime.Now, "Exmo"); Position position1 = new Position(1, "Библиотекарь"); Delivery delivery1 = new Delivery(2, new DateTime(2018, 05, 10), employee, reader2, exemplar1); DateTime start = new DateTime(2018, 05, 6); DateTime end = new DateTime(2019, 12, 31); List <Delivery> ListDelivery = new List <Delivery>(); ListDelivery.Add(delivery); ListDelivery.Add(delivery1); foreach (Delivery date in ListDelivery) { date.Info(); Console.WriteLine(" "); } Console.ReadLine(); }
static void Main(string[] args) { Book Book = new Book(1, "Пушкин", "Руслан и Людмила", "Поэма"); Exemplar exemplar = new Exemplar(1, Book, DateTime.Now, "Exmo"); Position position = new Position(1, "Библиотекарь"); IReader reader = new ReaderPro("вип", 1, "Семенов", "Игорь", "Евгеньевич", "муж.", 79835); Employee employee = new Employee(1, position, "Петрова", "Людмила", "Сергеевна", 345678892, 4, "Киров", "Попова", "6"); Delivery delivery = new Delivery(1, new DateTime(2018, 05, 04), employee, reader, exemplar); IReader reader2 = new ReaderSimple("обычный", 1, "Крючкова", "Антонина", "Александровна", "жен.", 79835); Book Book1 = new Book(1, "Лермонтов", "Мцыри", "Поэма"); Exemplar exemplar1 = new Exemplar(1, Book, DateTime.Now, "Exmo"); Position position1 = new Position(1, "Библиотекарь"); Delivery delivery1 = new Delivery(2, new DateTime(2018, 05, 10), employee, reader2, exemplar1); DateTime start = new DateTime(2018, 05, 6); DateTime end = new DateTime(2019, 12, 31); List <Delivery> ListDelivery = new List <Delivery>(); ListDelivery.Add(delivery); ListDelivery.Add(delivery1); // массив для сериализации: Delivery[] DeliveryBook = new Delivery[] { delivery, delivery1 }; BinaryFormatter formatter = new BinaryFormatter(); using (FileStream fs = new FileStream("delivery.dat", FileMode.OpenOrCreate)) { // сериализуем весь массив tovar formatter.Serialize(fs, DeliveryBook); Console.WriteLine("Сериализация в поток байтов прошла успешно"); } // десериализация using (FileStream fs = new FileStream("delivery.dat", FileMode.OpenOrCreate)) { Delivery[] deserilizeTovar = (Delivery[])formatter.Deserialize(fs); foreach (Delivery tv in deserilizeTovar) { tv.Info(); } Console.ReadLine(); } }
static void Main(string[] args) { IReader reader1 = new ReaderPro("вип", 1, "Семенов", "Игорь", "Евгеньевич", "муж", 79835); Book Book = new Book(1, "Пушкин", "Руслан и Людмила", "Поэма"); Exemplar exemplar1 = new Exemplar(1, Book, DateTime.Now, "Exmo"); Position position1 = new Position(1, "Библиотекарь"); Employee employee = new Employee(1, position1, "Петрова", "Людмила", "Сергеевна", 345678892, 4, "Киров", "Попова", "6"); Delivery delivery1 = new Delivery(1, new DateTime(2018, 05, 04), employee, reader1, exemplar1); IReader reader2 = new ReaderSimple("обычный", 2, "Крючкова", "Антонина", "Александровна", "жен", 79835); Book Book2 = new Book(1, "Лермонтов", "Мцыри", "Поэма"); Exemplar exemplar2 = new Exemplar(2, Book, DateTime.Now, "Exmo"); Position position2 = new Position(1, "Библиотекарь"); Delivery delivery2 = new Delivery(2, new DateTime(2018, 05, 10), employee, reader2, exemplar2); IReader reader3 = new ReaderPro("вип", 3, "Капустин", "Константин", "Евгеньевич", "муж", 756835); Book Book3 = new Book(1, "Толстой", "Война и мир", "Роман"); Exemplar exemplar3 = new Exemplar(3, Book, DateTime.Now, "Exmo"); Position position3 = new Position(1, "Библиотекарь"); Delivery delivery3 = new Delivery(3, new DateTime(2018, 05, 10), employee, reader3, exemplar3); IReader reader4 = new ReaderPro("обычный", 4, "Раскольников", "Валентин", "Семенович", "муж", 31525); Book Book4 = new Book(1, "Есенин", "Сборник стихов", "Стихотворения"); Exemplar exemplar4 = new Exemplar(4, Book, DateTime.Now, "Exmo"); Position position4 = new Position(1, "Библиотекарь"); Delivery delivery4 = new Delivery(4, new DateTime(2018, 05, 10), employee, reader4, exemplar4); IReader reader5 = new ReaderPro("обычный", 5, "Зюзина", "Ольга", "Николаевна", "жен", 31725); Book Book5 = new Book(1, "Достоевский", "Преступение и наказание", "Роман"); Exemplar exemplar5 = new Exemplar(5, Book, DateTime.Now, "Exmo"); Position position5 = new Position(1, "Библиотекарь"); Delivery delivery5 = new Delivery(5, new DateTime(2018, 05, 10), employee, reader5, exemplar5); IReader reader6 = new ReaderPro("вип", 6, "Лапшина", "Ирина", "Георгиевна", "жен", 36225); Book Book6 = new Book(1, "Пришвин", "Рассказы", "Рассказы"); Exemplar exemplar6 = new Exemplar(5, Book, DateTime.Now, "Exmo"); Position position6 = new Position(1, "Библиотекарь"); Delivery delivery6 = new Delivery(5, new DateTime(2018, 05, 10), employee, reader6, exemplar6); DateTime start = new DateTime(2018, 05, 6); DateTime end = new DateTime(2019, 12, 31); List <Delivery> ListDelivery = new List <Delivery>(); ListDelivery.Add(delivery1); ListDelivery.Add(delivery2); ListDelivery.Add(delivery3); ListDelivery.Add(delivery4); ListDelivery.Add(delivery5); ListDelivery.Add(delivery6); List <IReader> ListReader = new List <IReader>(); ListReader.Add(reader1); ListReader.Add(reader2); ListReader.Add(reader3); ListReader.Add(reader4); ListReader.Add(reader5); ListReader.Add(reader6); foreach (IReader date in ListReader) { date.Info(); Console.WriteLine(" "); } Console.WriteLine("Сортировать читателей по полу?(да, нет)"); string g = Console.ReadLine(); if (g == "да") { Console.WriteLine("мужчины-'муж', женщины-'жен':"); string gen = Console.ReadLine(); foreach (IReader date in ListReader.Where(i => i.Gender == gen)) { //Console.WriteLine(date.Surname + date.Name + date.Patronymic); date.Info(); Console.WriteLine(" "); } Console.WriteLine("Для просмотра информации по выдаче конкретному читателю введите его фамилию:"); string family = Console.ReadLine(); foreach (Delivery date in ListDelivery.Where(i => i.Reader1.Surname == family)) { //Console.WriteLine(date.Surname + date.Name + date.Patronymic); date.Info(); Console.WriteLine(" "); } } else if (g == "нет") { Console.WriteLine("Для просмотра информации по выдаче книги конкретному читателю введите его фамилию:"); string family2 = Console.ReadLine(); foreach (Delivery date in ListDelivery.Where(i => i.Reader1.Surname == family2)) { //Console.WriteLine(date.Surname + date.Name + date.Patronymic); date.Info(); Console.WriteLine(" "); } } Console.ReadLine(); }