Advertisement
Guest User

Untitled

a guest
May 21st, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.67 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace ConsoleApp14
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             Users users = new Users();
  15.             users.currentUser = null;
  16.             users.users = new User[0];
  17.             Book book = new Book(0);
  18.             bool logged = false;
  19.  
  20.             while (true)
  21.             {
  22.                 Console.WriteLine("Введите команду");
  23.                 string command = Console.ReadLine();
  24.  
  25.                 switch (command)
  26.                 {
  27.                     case "AddUser":
  28.                        
  29.                         users.AddUser(users.GetName(), users.GetPassword());
  30.                         break;
  31.                     case "Login":
  32.  
  33.                         logged = users.CheckPassword(users.GetName(), users.GetPassword());
  34.                         if (logged)
  35.                         {
  36.                             Console.WriteLine("Logged in");
  37.                         }
  38.                         else
  39.                         {
  40.                             Console.WriteLine("Wrong pair");
  41.                         }
  42.                         break;
  43.                     case "List":
  44.                         users.ShowUsers();
  45.                         break;
  46.                 }
  47.  
  48.                 //залогинен
  49.                 if (logged)
  50.                 {
  51.                     switch (command)
  52.                     {
  53.                         case "AddNote":
  54.                             book.AddNote(users.currentUser);
  55.                             break;
  56.                         case "ShowAllNotes":
  57.                             book.ShowAll();
  58.                             break;
  59.                         case "Books":
  60.                             break;
  61.                     }
  62.                 }
  63.             }
  64.         }
  65.    
  66.     }
  67.     class Users
  68.     {
  69.         public User currentUser;
  70.         public User[] users;
  71.         public void AddUser(string name, string password)
  72.         {
  73.             User[] temp = new User[users.Length + 1];
  74.             if (users.Length > 0)
  75.             {
  76.                 for (int i = 0; i < temp.Length - 1; i++)
  77.                 {
  78.                 temp[i] = new User();
  79.                 temp[i] = users[i];
  80.                 }
  81.             }
  82.            
  83.            
  84.             temp[temp.Length - 1] = new User();
  85.             temp[temp.Length - 1].Name = name;
  86.             temp[temp.Length - 1].Password = password;
  87.             users = temp;
  88.         }
  89.         public void ShowUsers()
  90.         {
  91.             for (int i = 0; i < users.Length; i++)
  92.             {
  93.                 Console.WriteLine(users[i].Name);
  94.             }
  95.         }
  96.         public bool CheckPassword(string name, string password)
  97.         {
  98.             for (int i = 0; i < users.Length; i++)
  99.             {
  100.                 if (users[i].Name == name)
  101.                 {
  102.                     if (users[i].Password == password)
  103.                     {
  104.                         currentUser = users[i];
  105.                         return true;
  106.                     }
  107.                 }
  108.             }
  109.             return false;
  110.  
  111.         }
  112.         public string GetName()
  113.         {
  114.             Console.WriteLine("Укажите логин");
  115.             return Console.ReadLine();
  116.         }
  117.         public string GetPassword()
  118.         {
  119.             Console.WriteLine("Укажите пароль");
  120.             return Console.ReadLine();
  121.         }
  122.     }
  123.     class User
  124.     {
  125.         public string Name;
  126.         public string Password;
  127.     }
  128.  
  129.     class Book
  130.     {
  131.         public int ID;
  132.         private Note[] _notes;
  133.  
  134.        
  135.  
  136.         public void AddNote(User currentUser)
  137.         {
  138.             Console.WriteLine("Текст заметки");
  139.             string note = Console.ReadLine();
  140.             Note[] temp = new Note[_notes.Length + 1];
  141.             for (int i = 0; i < _notes.Length; i++)
  142.             {
  143.                 temp[i] = _notes[i];
  144.             }
  145.             temp[temp.Length - 1] = new Note();
  146.             temp[temp.Length - 1].Text = note;
  147.             temp[temp.Length - 1].Owner = currentUser;
  148.             _notes = temp;
  149.         }
  150.  
  151.         public void ShowAll()
  152.         {
  153.             for (int i = 0; i < _notes.Length; i++)
  154.             {
  155.                 Console.WriteLine(_notes[i].Text);
  156.             }
  157.         }
  158.         public Book(int ID)
  159.         {
  160.             this.ID = ID;
  161.             _notes = new Note[0];
  162.  
  163.  
  164.         }
  165.     }
  166.  
  167.     class Note
  168.     {
  169.         public string Text;
  170.         public User Owner;
  171.     }
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement