Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp14
- {
- class Program
- {
- static void Main(string[] args)
- {
- Users users = new Users();
- users.currentUser = null;
- users.users = new User[0];
- Book book = new Book(0);
- bool logged = false;
- while (true)
- {
- Console.WriteLine("Введите команду");
- string command = Console.ReadLine();
- switch (command)
- {
- case "AddUser":
- users.AddUser(users.GetName(), users.GetPassword());
- break;
- case "Login":
- logged = users.CheckPassword(users.GetName(), users.GetPassword());
- if (logged)
- {
- Console.WriteLine("Logged in");
- }
- else
- {
- Console.WriteLine("Wrong pair");
- }
- break;
- case "List":
- users.ShowUsers();
- break;
- }
- //залогинен
- if (logged)
- {
- switch (command)
- {
- case "AddNote":
- book.AddNote(users.currentUser);
- break;
- case "ShowAllNotes":
- book.ShowAll();
- break;
- case "Books":
- break;
- }
- }
- }
- }
- }
- class Users
- {
- public User currentUser;
- public User[] users;
- public void AddUser(string name, string password)
- {
- User[] temp = new User[users.Length + 1];
- if (users.Length > 0)
- {
- for (int i = 0; i < temp.Length - 1; i++)
- {
- temp[i] = new User();
- temp[i] = users[i];
- }
- }
- temp[temp.Length - 1] = new User();
- temp[temp.Length - 1].Name = name;
- temp[temp.Length - 1].Password = password;
- users = temp;
- }
- public void ShowUsers()
- {
- for (int i = 0; i < users.Length; i++)
- {
- Console.WriteLine(users[i].Name);
- }
- }
- public bool CheckPassword(string name, string password)
- {
- for (int i = 0; i < users.Length; i++)
- {
- if (users[i].Name == name)
- {
- if (users[i].Password == password)
- {
- currentUser = users[i];
- return true;
- }
- }
- }
- return false;
- }
- public string GetName()
- {
- Console.WriteLine("Укажите логин");
- return Console.ReadLine();
- }
- public string GetPassword()
- {
- Console.WriteLine("Укажите пароль");
- return Console.ReadLine();
- }
- }
- class User
- {
- public string Name;
- public string Password;
- }
- class Book
- {
- public int ID;
- private Note[] _notes;
- public void AddNote(User currentUser)
- {
- Console.WriteLine("Текст заметки");
- string note = Console.ReadLine();
- Note[] temp = new Note[_notes.Length + 1];
- for (int i = 0; i < _notes.Length; i++)
- {
- temp[i] = _notes[i];
- }
- temp[temp.Length - 1] = new Note();
- temp[temp.Length - 1].Text = note;
- temp[temp.Length - 1].Owner = currentUser;
- _notes = temp;
- }
- public void ShowAll()
- {
- for (int i = 0; i < _notes.Length; i++)
- {
- Console.WriteLine(_notes[i].Text);
- }
- }
- public Book(int ID)
- {
- this.ID = ID;
- _notes = new Note[0];
- }
- }
- class Note
- {
- public string Text;
- public User Owner;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement