啊鑫
2024-07-11 afbf8700d137710713db61955879d0f5acb73738
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
using CSFrameworkV5.Core;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
 
namespace CSFrameworkV5.Core
{
    /// <summary>
    /// 系统参数,保存在数据库,对应系统库的sys_SystemSettings表
    /// </summary>
    public class SystemSettings
    {
        #region Instance
 
        private static SystemSettings _Current = null;
 
        /// <summary>
        /// 当前用户个性设置(单件模式)
        /// </summary>
        public static SystemSettings Current
        {
            get
            {
                if (_Current == null) _Current = new SystemSettings();
                return _Current;
            }
        }
 
        #endregion
 
        #region 属性
 
        /// <summary>
        /// 启用数据库日志
        /// </summary>
        public bool AllowDBLog { get; set; }
 
        /// <summary>
        /// 启用本地文件日志
        /// </summary>
        public bool AllowLocalLog { get; set; }
 
        /// <summary>
        /// 系统登录类型
        /// </summary>
        public LoginAuthType LoginAuthType { get; set; }
 
        /// <summary>
        /// 模块加载类型
        /// </summary>
        public ModuleLoadType ModuleLoadType { get; set; }
 
        /// <summary>
        /// 运行程序时检查新版本
        /// </summary>
        public bool CheckVersion { get; set; }
 
        /// <summary>
        /// 禁止运行未更新版本的程序
        /// </summary>
        public bool ExitAppIfOldVersion { get; set; }
 
        /// <summary>
        /// 双击表格记录进入编辑状态
        /// </summary>
        public bool DoubleClickEditMode { get; set; }
 
        /// <summary>
        /// 允许允许多个实例
        /// </summary>
        public bool MultiInstance { get; set; }
 
        /// <summary>
        /// DevExpress皮肤名称
        /// </summary>
        public string SkinName { get; set; }
 
        /// <summary>
        /// 是否Demo版本
        /// </summary>
        public bool IsDemoVersion { get; set; }
 
        /// <summary>
        /// 数据权限匹配类型,制单人匹配;部门架构匹配;全部匹配
        /// </summary>
        public string DataPermission { get; set; }
 
        #endregion
 
        #region Methods
 
        /// <summary>
        /// 从系统库:sys_SystemSettings表加载数据
        /// </summary>
        public void Load(DataTable sys_SystemSettings)
        {
            LoginAuthType = (LoginAuthType)Enum.Parse(typeof(LoginAuthType),
                GetString(sys_SystemSettings, "LoginAuthType"));
            AllowDBLog = GetString(sys_SystemSettings, "AllowDBLog") == "Y";
            AllowLocalLog =
                GetString(sys_SystemSettings, "AllowLocalLog") == "Y";
            ModuleLoadType =
                (ModuleLoadType)int.Parse(GetString(sys_SystemSettings,
                    "ModuleLoadType"));
 
            if (ModuleLoadType == ModuleLoadType.Unknow)
                ModuleLoadType = ModuleLoadType.SearchAppDir;
 
            CheckVersion = GetString(sys_SystemSettings, "CheckVersion") == "Y";
            ExitAppIfOldVersion =
                GetString(sys_SystemSettings, "ExitAppIfOldVersion") == "Y";
            DoubleClickEditMode =
                GetString(sys_SystemSettings, "DoubleClickEditMode") == "Y";
            MultiInstance =
                GetString(sys_SystemSettings, "MultiInstance") == "Y";
            SkinName = GetString(sys_SystemSettings, "SkinName");
            IsDemoVersion =
                GetString(sys_SystemSettings, "IsDemoVersion") == "Y";
 
            DataPermission = GetString(sys_SystemSettings, "DataPermission");
        }
 
        /// <summary>
        /// 定位DataRow,取值
        /// </summary>
        /// <param name="dtSettings"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        private string GetString(DataTable dtSettings, string key)
        {
            var rs = dtSettings.Select("ParamCode='" + key + "'");
            return rs.Length > 0 ? rs[0]["ParamValue"].ToStringEx() : "";
        }
 
        /// <summary>
        /// 获取系统参数设置的DataRow
        /// </summary>
        /// <param name="dtSettings">系统参数配置表</param>
        /// <param name="paramCode">参数类型</param>
        /// <returns></returns>
        public static DataRow GetRow(DataTable dtSettings, string paramCode)
        {
            var rs = dtSettings.Select("ParamCode='" + paramCode + "'");
            if (rs.Length > 0)
                return rs[0];
            else
                throw new Exception("未找到匹配ParamCode的记录!");
        }
 
        #endregion
    }
}