Shuxia Ning
2024-10-08 cf4967a0aebab18c5a37137f3e4c61b2d73a54bb
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
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;
            }
        }
 
 
 
    }
}