using SqlSugar;
|
|
namespace ISupply.DAL
|
{
|
/// <summary>
|
/// 数据库连接辅助类
|
/// </summary>
|
public class ConnectionFactory
|
{
|
private static ConnectionConfig _mainConfig = null;
|
|
/// <summary>
|
/// 创建连接对象
|
/// </summary>
|
public static ConnectionConfig MainConnection()
|
{
|
try
|
{
|
if (_mainConfig != null)
|
return _mainConfig;
|
|
var dbName = Settings.SQLite.MainDbName;
|
var filePath = $"{Settings.File.LocalDataDirectory}\\{dbName}";
|
if (!System.IO.File.Exists(filePath))
|
{
|
throw new System.Exception($"{dbName}文件不存在!Path:{filePath}");
|
}
|
|
_mainConfig = new ConnectionConfig()
|
{
|
ConnectionString = $"DataSource={filePath}",
|
IsAutoCloseConnection = true,
|
DbType = SqlSugar.DbType.Sqlite
|
};
|
return _mainConfig;
|
}
|
catch (System.Exception ex)
|
{
|
// LogHelper.Error(ex.Message);
|
return null;
|
}
|
}
|
|
private static ConnectionConfig _gyConfig = null;
|
|
/// <summary>
|
/// 固移分析数据库连接
|
/// </summary>
|
public static ConnectionConfig GyConnection()
|
{
|
try
|
{
|
if (_gyConfig != null)
|
return _gyConfig;
|
|
var dbName = "GyFire.db";
|
var filePath = $"{Settings.File.LocalDataDirectory}\\{dbName}";
|
if (!System.IO.File.Exists(filePath))
|
{
|
throw new System.Exception($"{dbName}文件不存在!Path:{filePath}");
|
}
|
|
_gyConfig = new ConnectionConfig()
|
{
|
ConnectionString = $"DataSource={filePath}",
|
IsAutoCloseConnection = true,
|
DbType = SqlSugar.DbType.Sqlite
|
};
|
return _gyConfig;
|
}
|
catch (System.Exception ex)
|
{
|
//LogHelper.Error(ex.Message);
|
return null;
|
}
|
}
|
}
|
}
|