Advertisement
qzya256

Untitled

May 25th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.85 KB | None | 0 0
  1. using System;
  2. using System.Threading;
  3.  
  4. namespace ConsoleApp17
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string command = "";
  11.  
  12.             while (command != "exit")
  13.             {
  14.                 command = Console.ReadLine();
  15.  
  16.                 switch (command)
  17.                 {
  18.                     case "AddUser":
  19.                         Console.WriteLine("Введите имя пользователя которого хотите добавить:");
  20.                         var name = Console.ReadLine();
  21.                         Console.WriteLine("Придумайте пароль");
  22.                         var password = Console.ReadLine();
  23.                         DataBase.AddUser(new User(name,password));
  24.                         Console.WriteLine("пользователь добавлен");
  25.                         break;
  26.                     case "ListUser":
  27.                         Console.WriteLine("Список пользователей:");
  28.                         DataBase.ListUser();
  29.                             break;
  30.                     case "Login":
  31.                         Console.WriteLine("Введите логин:");
  32.                         var login = Console.ReadLine();
  33.                         if (DataBase.Login(login))
  34.                         {
  35.                             Console.WriteLine("Ведите пароль:");
  36.                             var pas = Console.ReadLine();
  37.                             if (DataBase.CurrentUser.CheckPassword(pas))
  38.                             {
  39.                                 Console.WriteLine("Вы авторизованы");
  40.                             }
  41.                             else
  42.                             {
  43.                                 Console.WriteLine("Вы ввели неверный пароль");
  44.                             }
  45.                         }
  46.                         else
  47.                         {
  48.                             Console.WriteLine("Пользователя с таким логином не существует");
  49.                         }
  50.                         break;
  51.  
  52.                 }
  53.                 if (DataBase.CurrentUser != null)
  54.                 {
  55.                     switch (command)
  56.                     {
  57.                         case "AddBook":
  58.                             Console.WriteLine("Введите название книги:");
  59.                             DataBase.AddBook(new Book(Console.ReadLine()));
  60.                             Console.WriteLine("Книга добавлена");
  61.                             break;
  62.                         case "ListBook":
  63.                             DataBase.ListBook();
  64.                             break;
  65.                         case "ChooseBook":
  66.                             Console.WriteLine("Введите название книги:");
  67.                             var cb = Console.ReadLine();
  68.                             if (DataBase.ChooseBook(cb))
  69.                             {
  70.                                 Console.WriteLine("Книга выбрана");
  71.                             }
  72.                             else
  73.                             {
  74.                                 Console.WriteLine("Такой книги нет");
  75.                             }
  76.                             break;
  77.                         case "BoolkID":
  78.  
  79.                             break;
  80.  
  81.                     }
  82.                 }
  83.                 if (DataBase.CurrentBook != null)
  84.                 {
  85.                     switch (command)
  86.                     {
  87.                         case "AddNote":
  88.                             Console.WriteLine("Введите текст заметки");
  89.                             DataBase.CurrentBook.AddNote(new Note(Console.ReadLine()));
  90.                             Console.WriteLine("Заметка успешно добавлена в книгу");
  91.                             break;
  92.                         case "ShowAllNotes":          
  93.                             DataBase.CurrentBook.ShowAllNotes();
  94.                             break;
  95.                     }
  96.                 }
  97.             }
  98.  
  99.         }
  100.     }
  101.     class User
  102.     {
  103.         public string Name { get; private set; }
  104.         private string Password;
  105.         public bool isLogin { get; private set; }
  106.  
  107.         public User(string name, string password, bool isLogin = false)
  108.         {
  109.             Name = name;
  110.             Password = password;
  111.         }
  112.  
  113.         public bool CheckPassword(string password)
  114.         {
  115.             return Password == password;
  116.         }
  117.     }
  118.     class Note
  119.     {
  120.         public string Message
  121.         {
  122.             get;
  123.             private set;
  124.         }
  125.  
  126.         public Note(string message)
  127.         {
  128.             Message = message;
  129.         }
  130.     }
  131.     class Book
  132.     {
  133.         private Note[] Notes = new Note[0];
  134.         public string NameBook;
  135.         public int BookId { get; private set; }
  136.         static int nextId;
  137.         public Book(string name)
  138.         {
  139.             NameBook = name;
  140.             BookId = Interlocked.Increment(ref nextId);
  141.         }
  142.  
  143.         public Note[] AddNote(Note note)
  144.         {
  145.             Note[] returnNotes = new Note[Notes.Length + 1];
  146.             for (int i = 0; i < Notes.Length; i++)
  147.             {
  148.                 returnNotes[i] = Notes[i];
  149.             }
  150.             Notes = returnNotes;
  151.             Notes[Notes.Length - 1] = note;
  152.             return returnNotes;
  153.         }
  154.         public void ShowAllNotes()
  155.         {
  156.             for (int i = 0; i < Notes.Length; i++)
  157.             {
  158.                 Console.WriteLine(Notes[i].Message);
  159.             }
  160.         }
  161.     }
  162.     class DataBase
  163.     {
  164.         private static User[] Users = new User[0];
  165.         public static User CurrentUser;
  166.         private static Book[] Books = new Book[0];
  167.         public static Book CurrentBook;
  168.  
  169.  
  170.         public static User[] AddUser(User user)
  171.         {
  172.             User[] returnArray = new User[Users.Length + 1];
  173.             for (int i = 0; i < Users.Length; i++)
  174.             {
  175.                 returnArray[i] = Users[i];
  176.             }
  177.             Users = returnArray;
  178.             Users[Users.Length - 1] = user;
  179.             return returnArray;
  180.  
  181.         }
  182.  
  183.         public static void ListUser()
  184.         {
  185.             for (int i = 0; i < Users.Length; i++)
  186.             {
  187.                 Console.WriteLine(Users[i].Name);
  188.             }
  189.         }
  190.  
  191.         public static bool Login(string name)
  192.         {
  193.             foreach (var u in Users)
  194.             {
  195.                 if (u.Name == name)
  196.                 {
  197.                     CurrentUser = u;
  198.                     return true;
  199.                 }
  200.             }
  201.             return false;
  202.         }
  203.  
  204.         public static Book[] AddBook(Book book)
  205.         {
  206.             Book[] returnArray = new Book[Books.Length + 1];
  207.             for (int i = 0; i < Books.Length; i++)
  208.             {
  209.                 returnArray[i] = Books[i];
  210.             }
  211.             Books = returnArray;
  212.             Books[Books.Length - 1] = book;
  213.             return returnArray;
  214.         }
  215.  
  216.         public static void ListBook()
  217.         {
  218.             for (int i = 0; i < Books.Length; i++)
  219.             {
  220.                 Console.WriteLine(Books[i].NameBook);
  221.             }
  222.         }
  223.  
  224.         public static bool ChooseBook(string name)
  225.         {
  226.             foreach (var item in Books)
  227.             {
  228.                 if (item.NameBook == name)
  229.                 {
  230.                     CurrentBook = item;
  231.                     return true;
  232.                 }
  233.             }
  234.             return false;
  235.         }
  236.  
  237.         public static void BookID()
  238.         {
  239.             for (int i = 0; i < Books.Length; i++)
  240.             {
  241.                 Console.WriteLine(Books[i].BookId);
  242.             }
  243.         }
  244.  
  245.     }
  246.        
  247. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement