45 lines
1.2 KiB
C#
45 lines
1.2 KiB
C#
using CeramicProjectTool.Model;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace CeramicProjectTool.Util
|
|
{
|
|
public static partial class DBHelper
|
|
{
|
|
private static SqlSugar.SqlSugarClient? _db;
|
|
public static SqlSugar.SqlSugarClient Db
|
|
{
|
|
get
|
|
{
|
|
NewDB();
|
|
return _db;
|
|
|
|
}
|
|
}
|
|
public static bool isInit = false;
|
|
public static void NewDB()
|
|
{
|
|
_db = new SqlSugar.SqlSugarClient(new SqlSugar.ConnectionConfig()
|
|
{
|
|
ConnectionString = connStr,
|
|
DbType = SqlSugar.DbType.SqlServer,
|
|
IsAutoCloseConnection = true,
|
|
InitKeyType = SqlSugar.InitKeyType.Attribute
|
|
});
|
|
isInit = true;
|
|
}
|
|
|
|
public static void SetConnStr(Dictionary<string, string> dbConfig)
|
|
{
|
|
DBHelper.connStr = $"Data Source={dbConfig["dbSource"]};Initial Catalog={dbConfig["dbName"]};User ID={dbConfig["dbUserName"]};Password={dbConfig["dbUserPwd"]}";
|
|
}
|
|
|
|
|
|
private static string connStr = "";
|
|
|
|
}
|
|
}
|