Program.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using ConfigOperator;
  2. using GeneralData;
  3. using Org.BouncyCastle.Tsp;
  4. using ORM;
  5. using SqlSugarORM;
  6. using Universal;
  7. namespace UserTool
  8. {
  9. internal class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. if (!BaseConfigFileLoader.Load(out BasicInfo? basicInfo) || basicInfo is null || string.IsNullOrEmpty(basicInfo.DBConnectionString))
  14. {
  15. Console.WriteLine("Connect to database failed");
  16. return;
  17. }
  18. IORM orm = new SqlSugarCustom();
  19. orm.Initialize();
  20. if (!orm.Open(basicInfo.DBConnectionString, DbType.PostgreSQL))
  21. {
  22. Console.WriteLine("Connect to database failed");
  23. return;
  24. }
  25. Dictionary<int, string> users = [];
  26. bool success;
  27. do
  28. {
  29. Console.WriteLine("Try Reading");
  30. success = orm.Query<UserInfo>("UserAuthority", userInfos =>
  31. {
  32. Console.WriteLine("UserList:");
  33. for (int i = 1; i <= userInfos.Count; i++)
  34. {
  35. string? name = userInfos[i - 1].UserName;
  36. if (string.IsNullOrEmpty(name))
  37. continue;
  38. users[i] = name;
  39. Console.WriteLine($"{i} : {name}");
  40. }
  41. }).Result;
  42. if (!success || users.Count == 0)
  43. {
  44. orm.CreateTable<UserInfo>("UserAuthority");
  45. UserInfo userInfo = new()
  46. {
  47. UserName = "Engineer",
  48. Password = "Aa123456".ToBase64(),
  49. Authority = UserAuthority.Engineer
  50. };
  51. orm.Insert<UserInfo>("UserAuthority", userInfo);
  52. }
  53. } while (users.Count == 0);
  54. Operation:
  55. Console.WriteLine("Operation List:");
  56. Console.WriteLine("1 - Create User");
  57. Console.WriteLine("2 - Change Password");
  58. switch (Console.ReadLine())
  59. {
  60. case "1":
  61. string? newUsername = Console.ReadLine();
  62. break;
  63. case "2":
  64. break;
  65. default:
  66. goto Operation;
  67. }
  68. Thread.Sleep(-1);
  69. }
  70. }
  71. }