using System.Reflection;
|
using SqlSugar;
|
|
namespace IStation.ChEr.DAL
|
{
|
/// <summary>
|
/// 数据库连接辅助类
|
/// </summary>
|
public class ConnectionFactory
|
{
|
private static ConnectionConfig _mainConfig = null;
|
|
/// <summary>
|
/// 创建连接对象
|
/// </summary>
|
public static ConnectionConfig MainConnection(int year)
|
{
|
try
|
{
|
if (_mainConfig != null)
|
return _mainConfig;
|
|
|
var root_directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
|
var dsName = string.Format("WaterPredict{0}.db", year);
|
|
var filePath = Path.Combine(root_directory, "Data", dsName);
|
if (!System.IO.File.Exists(filePath))
|
{
|
throw new System.Exception($"{dsName}文件不存在!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;
|
// }
|
//}
|
}
|
}
|