using SqlSugar;
|
|
namespace IStation.DAL
|
{
|
/// <summary>
|
/// 数据库连接辅助类
|
/// </summary>
|
public class ConnectionFactory
|
{
|
private static long _projectId;
|
private static ConnectionConfig _basicConfig = null;
|
|
/// <summary>
|
/// 创建连接对象
|
/// </summary>
|
public static ConnectionConfig BasicConnection(long projectId)
|
{
|
try
|
{
|
if (_projectId == projectId)
|
{
|
if (_basicConfig != null)
|
return _basicConfig;
|
}
|
_projectId = projectId;
|
var dbName = Settings.File.BasicDB;
|
var filePath = $"{FileHelper.GetProjectFolder(projectId)}\\{dbName}";
|
if (!System.IO.File.Exists(filePath))
|
{
|
throw new System.Exception($"{dbName}文件不存在!Path:{filePath}");
|
}
|
|
_basicConfig = new ConnectionConfig()
|
{
|
ConnectionString = $"DataSource={filePath}",
|
IsAutoCloseConnection = true,
|
DbType = SqlSugar.DbType.Sqlite
|
};
|
return _basicConfig;
|
}
|
catch (System.Exception ex)
|
{
|
// LogHelper.Error(ex.Message);
|
return null;
|
}
|
}
|
|
|
|
}
|
}
|