SqlSugarHelper.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using SqlSugar;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace DBBackupTool.Helpers;
  8. internal class SqlSugarHelper
  9. {
  10. public SqlSugarClient? Client;
  11. public bool Open(string connectionString, SqlSugar.DbType dbType, bool isAutoConnection)
  12. {
  13. if (this.Client is not null)
  14. return false;
  15. ConnectionConfig config = new()
  16. {
  17. ConnectionString = connectionString,
  18. DbType = dbType,
  19. IsAutoCloseConnection = isAutoConnection
  20. };
  21. try
  22. {
  23. SqlSugarClient Db = new(config);
  24. this.Client = Db;
  25. }
  26. catch
  27. {
  28. return false;
  29. }
  30. return true;
  31. }
  32. public bool CreateTable(string database)
  33. {
  34. if (this.Client is null)
  35. return false;
  36. try
  37. {
  38. this.Client.DbMaintenance.CreateDatabase(database);
  39. }
  40. catch
  41. {
  42. return false;
  43. }
  44. return true;
  45. }
  46. }