Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- namespace ConsoleApp17
- {
- class Program
- {
- static void Main(string[] args)
- {
- string command = "";
- while (command != "exit")
- {
- command = Console.ReadLine();
- switch (command)
- {
- case "AddUser":
- Console.WriteLine("Введите имя пользователя которого хотите добавить:");
- var name = Console.ReadLine();
- Console.WriteLine("Придумайте пароль");
- var password = Console.ReadLine();
- DataBase.AddUser(new User(name,password));
- Console.WriteLine("пользователь добавлен");
- break;
- case "ListUser":
- Console.WriteLine("Список пользователей:");
- DataBase.ListUser();
- break;
- case "Login":
- Console.WriteLine("Введите логин:");
- var login = Console.ReadLine();
- if (DataBase.Login(login))
- {
- Console.WriteLine("Ведите пароль:");
- var pas = Console.ReadLine();
- if (DataBase.CurrentUser.CheckPassword(pas))
- {
- Console.WriteLine("Вы авторизованы");
- }
- else
- {
- Console.WriteLine("Вы ввели неверный пароль");
- }
- }
- else
- {
- Console.WriteLine("Пользователя с таким логином не существует");
- }
- break;
- }
- if (DataBase.CurrentUser != null)
- {
- switch (command)
- {
- case "AddBook":
- Console.WriteLine("Введите название книги:");
- DataBase.AddBook(new Book(Console.ReadLine()));
- Console.WriteLine("Книга добавлена");
- break;
- case "ListBook":
- DataBase.ListBook();
- break;
- case "ChooseBook":
- Console.WriteLine("Введите название книги:");
- var cb = Console.ReadLine();
- if (DataBase.ChooseBook(cb))
- {
- Console.WriteLine("Книга выбрана");
- }
- else
- {
- Console.WriteLine("Такой книги нет");
- }
- break;
- case "BoolkID":
- break;
- }
- }
- if (DataBase.CurrentBook != null)
- {
- switch (command)
- {
- case "AddNote":
- Console.WriteLine("Введите текст заметки");
- DataBase.CurrentBook.AddNote(new Note(Console.ReadLine()));
- Console.WriteLine("Заметка успешно добавлена в книгу");
- break;
- case "ShowAllNotes":
- DataBase.CurrentBook.ShowAllNotes();
- break;
- }
- }
- }
- }
- }
- class User
- {
- public string Name { get; private set; }
- private string Password;
- public bool isLogin { get; private set; }
- public User(string name, string password, bool isLogin = false)
- {
- Name = name;
- Password = password;
- }
- public bool CheckPassword(string password)
- {
- return Password == password;
- }
- }
- class Note
- {
- public string Message
- {
- get;
- private set;
- }
- public Note(string message)
- {
- Message = message;
- }
- }
- class Book
- {
- private Note[] Notes = new Note[0];
- public string NameBook;
- public int BookId { get; private set; }
- static int nextId;
- public Book(string name)
- {
- NameBook = name;
- BookId = Interlocked.Increment(ref nextId);
- }
- public Note[] AddNote(Note note)
- {
- Note[] returnNotes = new Note[Notes.Length + 1];
- for (int i = 0; i < Notes.Length; i++)
- {
- returnNotes[i] = Notes[i];
- }
- Notes = returnNotes;
- Notes[Notes.Length - 1] = note;
- return returnNotes;
- }
- public void ShowAllNotes()
- {
- for (int i = 0; i < Notes.Length; i++)
- {
- Console.WriteLine(Notes[i].Message);
- }
- }
- }
- class DataBase
- {
- private static User[] Users = new User[0];
- public static User CurrentUser;
- private static Book[] Books = new Book[0];
- public static Book CurrentBook;
- public static User[] AddUser(User user)
- {
- User[] returnArray = new User[Users.Length + 1];
- for (int i = 0; i < Users.Length; i++)
- {
- returnArray[i] = Users[i];
- }
- Users = returnArray;
- Users[Users.Length - 1] = user;
- return returnArray;
- }
- public static void ListUser()
- {
- for (int i = 0; i < Users.Length; i++)
- {
- Console.WriteLine(Users[i].Name);
- }
- }
- public static bool Login(string name)
- {
- foreach (var u in Users)
- {
- if (u.Name == name)
- {
- CurrentUser = u;
- return true;
- }
- }
- return false;
- }
- public static Book[] AddBook(Book book)
- {
- Book[] returnArray = new Book[Books.Length + 1];
- for (int i = 0; i < Books.Length; i++)
- {
- returnArray[i] = Books[i];
- }
- Books = returnArray;
- Books[Books.Length - 1] = book;
- return returnArray;
- }
- public static void ListBook()
- {
- for (int i = 0; i < Books.Length; i++)
- {
- Console.WriteLine(Books[i].NameBook);
- }
- }
- public static bool ChooseBook(string name)
- {
- foreach (var item in Books)
- {
- if (item.NameBook == name)
- {
- CurrentBook = item;
- return true;
- }
- }
- return false;
- }
- public static void BookID()
- {
- for (int i = 0; i < Books.Length; i++)
- {
- Console.WriteLine(Books[i].BookId);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement