Advertisement
Guest User

Untitled

a guest
May 15th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.23 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using System.Text;
  5.  
  6.  
  7. namespace OOP
  8. {
  9.     class Program
  10.     {
  11.  
  12.         private static User[] Users = new User[0];
  13.         private static Book[] Books = new Book[0];
  14.  
  15.         static void Main(string[] args)
  16.         {
  17.             AddUser(new User("Admin", "1234"));
  18.             AddUser(new User("User", "12345"));
  19.             ListUser();
  20.             Login("User_", "12345");
  21.             AddBook(new Book("Book1"));
  22.             AddBook(new Book("Book2"));
  23.             string command = "";
  24.            
  25.             while (command != "exit")
  26.             {
  27.                 command = Console.ReadLine();
  28.  
  29.                 switch (command)
  30.                 {
  31.                     case "AddUser":
  32.                         Console.WriteLine("Добавление пользователя. Введите имя:");
  33.                         var n = Console.ReadLine();
  34.                         Console.WriteLine("Введите пароль:");
  35.                         var p = Console.ReadLine();
  36.                         AddUser(new User(n, p));
  37.                         Console.WriteLine("Пользователь сохранен.");
  38.                        
  39.                         break;
  40.                     case "ListUser":
  41.                         Console.WriteLine(" Список пользователей программы:");
  42.                         ListUser();
  43.                         break;
  44.                     case "Login":
  45.                         Console.WriteLine("Авторизация: \n Введите логин:");
  46.                         var l = Console.ReadLine();
  47.                         Console.WriteLine("Введите пароль:");
  48.                         var s = Console.ReadLine();
  49.                         Login(l,s);
  50.                         break;
  51.  
  52.                 }
  53.             }
  54.            
  55.            
  56.          
  57.  
  58.  
  59.         }
  60.  
  61.  
  62.         static void AddUser(User user)
  63.         {
  64.             User[] tempArr = new User[Users.Length + 1];
  65.             for (int j = 0; j < Users.Length; j++)
  66.             {
  67.                 tempArr[j] = Users[j];
  68.             }
  69.             Users = tempArr;
  70.             Users[Users.Length - 1] = user;
  71.         }
  72.  
  73.         static void ListUser()
  74.         {
  75.             for (int i = 0; i < Users.Length; i++)
  76.             {
  77.                 Console.WriteLine(Users[i].Name);
  78.             }
  79.         }
  80.  
  81.         static void Login(string name, string password)
  82.         {
  83.             foreach (var u in Users)
  84.             {
  85.                 if (u.Name == name)
  86.                 {
  87.                     if (u.Checkpassword(password))
  88.                     {
  89.                         Console.WriteLine("Вы авторизованы!");
  90.                         User CurrentUser = u;
  91.  
  92.                     }
  93.                     else
  94.                     {
  95.                         Console.WriteLine("Вы ввели неверный пароль");
  96.                     }
  97.  
  98.                 }
  99.                
  100.             }
  101.         }
  102.  
  103.  
  104.         static void AddBook(Book book)
  105.         {
  106.             Book[] tempArr = new Book[Books.Length + 1];
  107.             for (int j = 0; j < Books.Length; j++)
  108.             {
  109.                 tempArr[j] = Books[j];
  110.             }
  111.             Books = tempArr;
  112.             Books[Books.Length - 1] = book;
  113.         }
  114.  
  115.         static void ListBook()
  116.         {
  117.             for (int i = 0; i < Books.Length; i++)
  118.             {
  119.                 Console.WriteLine(Users[i].Name);
  120.             }
  121.         }
  122.  
  123.         static void ChooseBook(string name)
  124.         {
  125.             foreach (var u in Books)
  126.             {
  127.                 if (u.NameBook == name)
  128.                 {
  129.                         Console.WriteLine("Книга {0} выбрана!", name);
  130.                         Book CurrentBook = u;
  131.                 }
  132.             }
  133.         }
  134.     }
  135.  
  136.     class Note
  137.     {
  138.         public string Message
  139.         {
  140.             get;
  141.             private set;
  142.         }
  143.  
  144.         public Note(string message)
  145.         {
  146.             Message = message;
  147.         }
  148.  
  149.     }
  150.  
  151.     class Book
  152.     {
  153.         public string NameBook;
  154.         static int nextId;
  155.         public int BookId { get; private set; }
  156.    
  157.  
  158.         public Book(string name)
  159.         {
  160.             NameBook = name;
  161.             BookId = Interlocked.Increment(ref nextId);
  162.  
  163.         }
  164.  
  165.         private Note[] _notes;
  166.        
  167.  
  168.         public void AddNote(Note note)
  169.         {
  170.             Note[] notes = new Note[_notes.Length + 1];
  171.             for (int i = 0; i < _notes.Length; i++)
  172.             {
  173.                 notes[i] = _notes[i];
  174.             }
  175.             _notes = notes;
  176.             _notes[_notes.Length - 1] = note;
  177.             GC.Collect();
  178.         }
  179.  
  180.  
  181.     }
  182.  
  183.     class User
  184.     {
  185.         public string Name { get; private set; }
  186.         private string Password;
  187.         public bool isLogin { get; private set; }
  188.  
  189.         public User(string name, string password, bool isLogin = false)
  190.         {
  191.             Name = name;
  192.             Password = password;
  193.         }
  194.  
  195.        
  196.         public bool Checkpassword(string password)
  197.         {
  198.             return Password == password;
  199.         }
  200.  
  201.     }
  202.  
  203. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement