Advertisement
StreetKatya

Библиотека

Jan 24th, 2022
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.37 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Ex_2
  8. {
  9.     public class Book
  10.     {
  11.         #region Переменные
  12.         private string autor_;
  13.         public string autor
  14.         {
  15.             set
  16.             {
  17.                 if (value == null)
  18.                 { throw new ArgumentException("Неверный ввод имени автора"); }
  19.                 else autor_ = value;
  20.             }
  21.             get
  22.             {
  23.                 return autor_;
  24.             }
  25.         }
  26.         private string nameBook_;
  27.         public string nameBook
  28.         {
  29.             set
  30.             {
  31.                 if (value == null)
  32.                 { throw new ArgumentException("Неверный ввод названия книги"); }
  33.                 else nameBook_ = value;
  34.             }
  35.             get
  36.             {
  37.                 return nameBook_;
  38.             }
  39.         }
  40.         private string janr_;
  41.         public string janr
  42.         {
  43.             set
  44.             {
  45.                 if (value == null)
  46.                 { throw new ArgumentException("Неверный ввод жанра"); }
  47.                 else janr_ = value;
  48.             }
  49.             get
  50.             {
  51.                 return janr_;
  52.             }
  53.         }
  54.         #endregion
  55.         public Book(string autorIn, string nameBookIn, string janrIn)
  56.         {
  57.             autor = autorIn;
  58.             nameBook = nameBookIn;
  59.             janr = janrIn;
  60.         }
  61.         public override string ToString()
  62.         {
  63.             return $"Название книги {nameBook}. Имя автора {autor}. Жанр {janr}. ";
  64.         }
  65.     }
  66.     public class Record
  67.     {
  68.         public Book book;
  69.         public int timeGet;
  70.         public Record(Book b1, int timeGet1)
  71.         {
  72.             book = b1;
  73.             timeGet = timeGet1;
  74.         }
  75.     }
  76.     public class Person
  77.     {
  78.         private string name_;
  79.         private string numberTelephone_;
  80.  
  81.         public string name
  82.         {
  83.             set
  84.             {
  85.                 if (value == null)
  86.                 { throw new ArgumentException("Неверный ввод имени"); }
  87.                 else name_ = value;
  88.             }
  89.             get
  90.             {
  91.                 return name_;
  92.             }
  93.         }
  94.         public string numberTelephone
  95.         {
  96.             set
  97.             {
  98.                 if (value.Length > 11)
  99.                 { throw new ArgumentException("Неверный ввод номера телефона"); }
  100.                 else numberTelephone_ = value;
  101.             }
  102.             get
  103.             {
  104.                 return numberTelephone_;
  105.             }
  106.         }
  107.         public Person(string nameIn, string numberTelephoneIn)
  108.         {
  109.             name = nameIn;
  110.             numberTelephone = numberTelephoneIn;
  111.         }
  112.         public override string ToString()
  113.         {
  114.             return $"Имя: {name}. Номер телефона {numberTelephone}";
  115.         }
  116.         public void Reply(object sender, EventArgs e)
  117.         {
  118.             Console.WriteLine($"{sender}, у Вас задолженность в библиотеке");
  119.             Random rand = new Random();
  120.             string[] str = { "Да", "Обязательно", "Cкоро приду", "Сегодня не могу", "На следующей неделе"};
  121.             int randInt = rand.Next(0, 4);
  122.             Console.WriteLine(str[randInt]);
  123.         }
  124.     }
  125.     public delegate void Delegate(object sender, EventArgs e);
  126.     public class Library
  127.     {
  128.         public List<Book> listBooks = new List<Book>();
  129.         private Dictionary<Person, List<Record>> cartoteka = new Dictionary<Person, List<Record>>();
  130.         private EventArgs e;
  131.  
  132.         public event Delegate Notify;
  133.  
  134.         public bool Add(Person person)
  135.         {
  136.             if(cartoteka.ContainsKey(person))
  137.             {
  138.                 return false;
  139.             }
  140.             cartoteka.Add(person, new List<Record>());
  141.             Notify += person.Reply;
  142.             return true;
  143.         }
  144.         public IEnumerable<Book> GetBook(string category)
  145.         {
  146.             IEnumerable<Book> temp = listBooks.FindAll(x => x.janr == category);
  147.             return temp;
  148.         }
  149.         public bool Give(Book book, Person person)
  150.         {
  151.             if(listBooks.Contains(book))
  152.             {
  153.                 Add(person);
  154.                 Random rnd = new Random();
  155.                 Record record = new Record(book, rnd.Next(1, 24));
  156.                 cartoteka[person].Add(record);
  157.                 return true;
  158.             }
  159.             return false;
  160.         }
  161.         public void CheckReaders()
  162.         {
  163.             List<Record> listRecords = new List<Record>();
  164.             Console.WriteLine("Введите номер сегодняшнего дня в году");
  165.             int day = int.Parse(Console.ReadLine());
  166.             foreach(var item in cartoteka)
  167.             {
  168.                 listRecords = item.Value;
  169.                 for (int i = 0; i < listRecords.Count; i++)
  170.                 {
  171.                     if(day - listRecords[i].timeGet > 14)
  172.                     {
  173.                         Notify(item.Key, e);
  174.                         break;
  175.                     }
  176.                 }
  177.             }
  178.         }
  179.     }
  180. }
  181.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement