using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using WCS.BLL.Config; using WCS.BLL.DbModels; using WCS.BLL.HardWare; using WCS.DAL; using WCS.DAL.Db; using WCS.DAL.Db.AuthDb; using WCS.DAL.DbModels; namespace WCS.BLL.Manager { public static class DbInit { public static void InitDb() { Logs.Write("【初始化数据库】开始", LogsType.StartBoot); //初始化数据库对象 if (LocalFile.Config.IsMx) { DbHelp.db = new SqlSugarScope(new ConnectionConfig() { ConnectionString = LocalFile.Config.DataDbPath, DbType = DbType.SqlServer,//[Sqlite]安装[System.Data.SQLite]; IsAutoCloseConnection = true }, db => { db.Aop.OnError = ex => { }; }); DbHelp.dbLog = new SqlSugarScope(new ConnectionConfig() { ConnectionString = LocalFile.Config.LogDbPath, DbType = DbType.SqlServer,//[Sqlite]安装[System.Data.SQLite]; IsAutoCloseConnection = true }, db => { db.Aop.OnError = ex => { }; }); AuthDbHelp.db = new SqlSugarScope(new ConnectionConfig() { ConnectionString = LocalFile.Config.AuthDbPath, DbType = DbType.SqlServer,//[Sqlite]安装[System.Data.SQLite]; IsAutoCloseConnection = true }, db => { db.Aop.OnError = ex => { }; }); } DbHelp.db.DbMaintenance.CreateDatabase(); DbHelp.dbLog.DbMaintenance.CreateDatabase(); DbHelp.db.CodeFirst.InitTables(typeof(ModuleInfo), typeof(ShelfInfo), typeof(StoreInfo) , typeof(InventoryDetail), typeof(OutOrder), typeof(OutOrderDetail), typeof(OutOrderMatDetail) , typeof(ShelfTypeInfo), typeof(MatBaseInfo), typeof(MatInfo) , typeof(StockTakingOrder), typeof(StockTakingOrderMatDetail), typeof(InOutRecord) , typeof(DocumentSerialNumber) ); DbHelp.dbLog.CodeFirst.InitTables(typeof(SystemApiLogRecord)); //初始化单据序列号数据 if (!DbHelp.db.Queryable().Any()) { var outDocumentSerialNumber = new DocumentSerialNumber() { DocumentType = DocumentTypeEnum.出库单据, UpdateDate = DateTime.Now, CurrentSerialNumber = 0 }; var stockTakingDocumentSerialNumber = new DocumentSerialNumber() { DocumentType = DocumentTypeEnum.盘点单据, UpdateDate = DateTime.Now, CurrentSerialNumber = 0 }; DbHelp.db.Insertable(outDocumentSerialNumber).ExecuteCommand(); DbHelp.db.Insertable(stockTakingDocumentSerialNumber).ExecuteCommand(); } //初始化货架类型 if (!DbHelp.db.Queryable().Any()) { var smartShelf = new ShelfTypeInfo() { ShelfTypeName = "智能货架" }; var singleLight = new ShelfTypeInfo() { ShelfTypeName = "信息化货架" }; DbHelp.db.Insertable(smartShelf).ExecuteCommand(); DbHelp.db.Insertable(singleLight).ExecuteCommand(); } Logs.Write("【初始化数据库】结束", LogsType.StartBoot); //初始化权限数据库 AuthDbHelp.InitDb(); } } }