革博士程序V1仓库
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

60 líneas
1.9 KiB

  1. using SqlSugar;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace LeatherApp.Utils
  9. {
  10. public class DBUtils
  11. {
  12. private static SqlSugarClient db;
  13. //public static dbBackup()
  14. //{
  15. // //mysqldump -uroot-p123456 mydb > /data/mysqlDump/mydb.sql
  16. // //mysqldump - uroot - p123456 mydb > / data / mysqlDump / mydb.sql
  17. //}
  18. public static SqlSugarClient getErpDBCon(SqlSugar.DbType dbType = SqlSugar.DbType.SqlServer)
  19. {
  20. if (string.IsNullOrEmpty(Config.ErpDBConStr))
  21. return null;
  22. if (db != null) return db;
  23. db = new SqlSugarClient(new ConnectionConfig()
  24. {
  25. ConnectionString = Config.ErpDBConStr,
  26. DbType = dbType,
  27. IsAutoCloseConnection = true
  28. },
  29. db =>
  30. {
  31. db.Aop.OnLogExecuting = (sql, pars) =>
  32. {
  33. Console.WriteLine(sql);//输出sql,查看执行sql 性能无影响
  34. //获取原生SQL推荐 5.1.4.63 性能OK
  35. //UtilMethods.GetNativeSql(sql,pars)
  36. //获取无参数化SQL 对性能有影响,特别大的SQL参数多的,调试使用
  37. //UtilMethods.GetSqlString(DbType.SqlServer,sql,pars)
  38. };
  39. });
  40. return db;
  41. }
  42. public static DataTable execSql(string sql, List<SugarParameter> parameters, SqlSugar.DbType dbType = SqlSugar.DbType.SqlServer)
  43. {
  44. //查询表的所有
  45. var mydb = getErpDBCon(dbType);
  46. if(mydb == null) return null;
  47. if (!mydb.Ado.IsValidConnection())
  48. mydb.Ado.Open();
  49. return mydb.Ado.GetDataTable(sql, parameters);
  50. }
  51. }
  52. }