tangxu
2024-04-30 866efc04569009746d28ed1c434e0126ad00ad09
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
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;
            }
        }
    }
}