61 lines
2.2 KiB
C#
61 lines
2.2 KiB
C#
using SqlSugar;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace WCS.DAL.Db
|
|
{
|
|
public static class DbHelp
|
|
{
|
|
/// <summary>
|
|
/// 业务数据库
|
|
/// </summary>
|
|
public static SqlSugarScope db = new SqlSugarScope(new ConnectionConfig()
|
|
{
|
|
ConnectionString = $"Data Source={DbPath.DataDbPath};",
|
|
DbType = DbType.Sqlite,//[Sqlite]安装[System.Data.SQLite];
|
|
IsAutoCloseConnection = true
|
|
}, db =>
|
|
{
|
|
db.Aop.OnError = ex =>
|
|
{
|
|
//TO DO LOG
|
|
//Logs.Write($@"{nameof(db)}{Environment.NewLine}SQL:{ex?.Sql}{Environment.NewLine}Parametres:{JsonConvert.SerializeObject(ex?.Parametres)}{Environment.NewLine}InnerException:{ex?.InnerException?.ToString()}{Environment.NewLine}Exception:{ex?.ToString()}{Environment.NewLine}", LogsType.DbErr);
|
|
};
|
|
});
|
|
|
|
/// <summary>
|
|
/// 日志数据库
|
|
/// </summary>
|
|
public static SqlSugarScope dbLog = new SqlSugarScope(new ConnectionConfig()
|
|
{
|
|
ConnectionString = $"Data Source={DbPath.LogDbPath};",
|
|
DbType = DbType.Sqlite,//[Sqlite]安装[System.Data.SQLite];
|
|
IsAutoCloseConnection = true
|
|
}, db =>
|
|
{
|
|
db.Aop.OnError = ex =>
|
|
{
|
|
//TO DO LOG
|
|
//Logs.Write($@"{nameof(dbAuth)}{Environment.NewLine}SQL:{ex?.Sql}{Environment.NewLine}Parametres:{JsonConvert.SerializeObject(ex?.Parametres)}{Environment.NewLine}InnerException:{ex?.InnerException?.ToString()}{Environment.NewLine}Exception:{ex?.ToString()}{Environment.NewLine}", LogsType.DbErr);
|
|
};
|
|
});
|
|
|
|
public static void InitDb()
|
|
{
|
|
//#region 初始化业务数据库
|
|
////不存在创建数据库,存在不会创建
|
|
//db.DbMaintenance.CreateDatabase();
|
|
////创建表根据实体类
|
|
//db.CodeFirst.InitTables(typeof(ModuleInfo), typeof(ShelfInfo), typeof(StoreInfo));
|
|
//#endregion
|
|
|
|
//#region 初始化日志数据库
|
|
//dbLog.DbMaintenance.CreateDatabase();
|
|
//#endregion
|
|
}
|
|
}
|
|
}
|