Advertisement
vovanhoangtuan

QuanLi

Apr 18th, 2020
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.19 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7.  
  8. namespace WriteFile
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             Console.OutputEncoding = Encoding.Unicode;
  15.             Console.InputEncoding = Encoding.Unicode;
  16.             string filePath = "test.txt";
  17.  
  18.             FileStream fsR = new FileStream(filePath, FileMode.Open);
  19.             StreamReader sReader = new StreamReader(fsR, Encoding.Unicode);
  20.             string firstValue = sReader.ReadLine();
  21.             string[] value = firstValue.Split(':');
  22.             sReader.Close();
  23.  
  24.             Console.Write("Username : ");
  25.             string username = Console.ReadLine();
  26.             Console.Write("Password : ");
  27.             string password = Console.ReadLine();
  28.  
  29.             if (value[0] == username && value[1] == password)
  30.             {
  31.                 Console.WriteLine($"Xin chào {value[2]}, chức vụ hiện tại của bạn là {value[3]}");
  32.                 Console.WriteLine("----------Menu----------");
  33.                 Console.WriteLine("1: Cập nhập username");
  34.                 Console.WriteLine("2: Cập nhập pass");
  35.                 Console.WriteLine("3: Cập nhập họ tên");
  36.                 Console.WriteLine("4: Cập nhập chức vụ");
  37.                 Console.WriteLine("-------------------------");
  38.                 Console.WriteLine("Mời bạn chọn lựa chọn");
  39.                 int option = int.Parse(Console.ReadLine());
  40.  
  41.                 switch (option)
  42.                 {
  43.                     case 1:
  44.                         {
  45.                             Console.Write("Nhập username : ");
  46.                             value[0] = Console.ReadLine();
  47.                             break;
  48.                         }
  49.                     case 2:
  50.                         {
  51.                             Console.Write("Nhập password : ");
  52.                             value[1] = Console.ReadLine();
  53.                             break;
  54.                         }
  55.                     case 3:
  56.                         {
  57.                             Console.Write("Nhập họ tên : ");
  58.                             value[2] = Console.ReadLine();
  59.                             break;
  60.                         }
  61.                     case 4:
  62.                         {
  63.                             Console.Write("Nhập chức vụ : ");
  64.                             value[3] = Console.ReadLine();
  65.                             break;
  66.                         }
  67.                 }
  68.                 writeFile($"{value[0]}:{value[1]}:{value[2]}:{value[3]}");
  69.                 Console.WriteLine("Cập nhập thành công !");
  70.             }
  71.             else Console.WriteLine("Sai tài khoảng hoặc mật khẩu rùi bận êyyyy !");
  72.         }
  73.         static void writeFile(string data)
  74.         {
  75.             string filePath = "test.txt";
  76.             FileStream fsW = new FileStream(filePath, FileMode.Create);
  77.             StreamWriter sWriter = new StreamWriter(fsW, Encoding.Unicode);
  78.             sWriter.Write(data);
  79.             sWriter.Flush();
  80.             fsW.Close();
  81.         }
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement