EPLAN_PROD_Plugin/Sinvo.EplanHpD.Plugin.Service/DBHelper.cs

52 lines
1.7 KiB
C#

using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sinvo.EplanHpD.Plugin.Service
{
public class DBHelper
{
private static string _dbUser = "sa";
#if DEBUG
private static string _dbServer = "192.168.91.130";
private static string _dbPassword = "Sa1234";
#else
private static string _dbPassword = "SA@9512";
private static string _dbServer = "192.168.1.223";
#endif
private static string _dbName = "MotorData";
private static string _connectionString => $"Server={_dbServer};Database={_dbName};User Id={_dbUser};Password={_dbPassword};";
private static SqlSugarClient _db;
public static SqlSugarClient DB
{
get
{
_db = new SqlSugarClient(new ConnectionConfig()
{
ConnectionString = _connectionString,
DbType = DbType.SqlServer,
IsAutoCloseConnection = true,
InitKeyType = InitKeyType.Attribute,
});
return _db;
}
}
public void CodeFirst()
{
DB.CodeFirst.InitTables(typeof(Model.MotorDataModel));
DB.CodeFirst.InitTables(typeof(Model.Motor));
DB.CodeFirst.InitTables(typeof(Model.CableLectotype));
DB.CodeFirst.InitTables(typeof(Model.LectotypeLine));
DB.CodeFirst.InitTables(typeof(Model.MultiCoreWireLecDBModel));
DB.CodeFirst.InitTables(typeof(Model.MultiWireCoreDataModel));
}
}
}