Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Threading;
- using System.Text;
- namespace OOP
- {
- class Program
- {
- private static User[] Users = new User[0];
- private static Book[] Books = new Book[0];
- static void Main(string[] args)
- {
- AddUser(new User("Admin", "1234"));
- AddUser(new User("User", "12345"));
- ListUser();
- Login("User_", "12345");
- AddBook(new Book("Book1"));
- AddBook(new Book("Book2"));
- string command = "";
- while (command != "exit")
- {
- command = Console.ReadLine();
- switch (command)
- {
- case "AddUser":
- Console.WriteLine("Добавление пользователя. Введите имя:");
- var n = Console.ReadLine();
- Console.WriteLine("Введите пароль:");
- var p = Console.ReadLine();
- AddUser(new User(n, p));
- Console.WriteLine("Пользователь сохранен.");
- break;
- case "ListUser":
- Console.WriteLine(" Список пользователей программы:");
- ListUser();
- break;
- case "Login":
- Console.WriteLine("Авторизация: \n Введите логин:");
- var l = Console.ReadLine();
- Console.WriteLine("Введите пароль:");
- var s = Console.ReadLine();
- Login(l,s);
- break;
- }
- }
- }
- static void AddUser(User user)
- {
- User[] tempArr = new User[Users.Length + 1];
- for (int j = 0; j < Users.Length; j++)
- {
- tempArr[j] = Users[j];
- }
- Users = tempArr;
- Users[Users.Length - 1] = user;
- }
- static void ListUser()
- {
- for (int i = 0; i < Users.Length; i++)
- {
- Console.WriteLine(Users[i].Name);
- }
- }
- static void Login(string name, string password)
- {
- foreach (var u in Users)
- {
- if (u.Name == name)
- {
- if (u.Checkpassword(password))
- {
- Console.WriteLine("Вы авторизованы!");
- User CurrentUser = u;
- }
- else
- {
- Console.WriteLine("Вы ввели неверный пароль");
- }
- }
- }
- }
- static void AddBook(Book book)
- {
- Book[] tempArr = new Book[Books.Length + 1];
- for (int j = 0; j < Books.Length; j++)
- {
- tempArr[j] = Books[j];
- }
- Books = tempArr;
- Books[Books.Length - 1] = book;
- }
- static void ListBook()
- {
- for (int i = 0; i < Books.Length; i++)
- {
- Console.WriteLine(Users[i].Name);
- }
- }
- static void ChooseBook(string name)
- {
- foreach (var u in Books)
- {
- if (u.NameBook == name)
- {
- Console.WriteLine("Книга {0} выбрана!", name);
- Book CurrentBook = u;
- }
- }
- }
- }
- class Note
- {
- public string Message
- {
- get;
- private set;
- }
- public Note(string message)
- {
- Message = message;
- }
- }
- class Book
- {
- public string NameBook;
- static int nextId;
- public int BookId { get; private set; }
- public Book(string name)
- {
- NameBook = name;
- BookId = Interlocked.Increment(ref nextId);
- }
- private Note[] _notes;
- public void AddNote(Note note)
- {
- Note[] notes = new Note[_notes.Length + 1];
- for (int i = 0; i < _notes.Length; i++)
- {
- notes[i] = _notes[i];
- }
- _notes = notes;
- _notes[_notes.Length - 1] = note;
- GC.Collect();
- }
- }
- 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;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement