tangxu
2024-05-04 39579aa528747af7ca7b17b04453095e2a27a009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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;
        //    }
        //}
    }
}