1
yhj
2024-07-24 5e5d945e91568b973faa27d8ab0bcef99fc4a6c5
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#region
 
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Threading;
using System.Windows.Forms;
 
#endregion
 
namespace CSFrameworkV5.Common
{
    /// <summary>
    ///     公共单元,Globals类
    /// </summary>
    public sealed class Globals
    {
        #region 系统常量定义
 
        public const string DEF_DATE_FORMAT = "yyyy-MM-dd"; // "dd/MM/yyyy";
 
        public const string
            DEF_LONE_DATE_FORMAT =
                "yyyy-MM-dd hh:mm:ss"; //"dd/MM/yyyy hh:mm:ss";
 
        public const string DEF_YYYYMMDD = "yyyyMMdd"; //日期格式
        public const string DEF_YYYYMMDD_LONG = "yyyy-MM-dd"; //"yyyy/MM/dd";
 
        public const string
            DEF_DATE_LONG_FORMAT =
                "yyyy-MM-dd hh:mm:ss"; //"yyyy/MM/dd hh:mm:ss";                
 
        public const string DEF_NULL_DATETIME = "1900-01-01"; //日期为空预设的日期
        public const string DEF_NULL_VALUE = "NULL"; //转换数值为字符串,用于与NULL比较
        public const string DEF_CURRENCY = "RMB"; //预设货币
        public const string DEF_DECIMAL_FORMAT = "0.00"; //输出格式        
        public const string DEF_NO_TEXT = "*自动生成*"; //新增状态下,单据号码显示的文本
 
        public const string DEF_CONFIG_DIR = @"\Config\"; //应用程序下的配置目录
        public const string DEF_USER_CFG = @"\config\user.ini"; //用户配置
        public const string DEF_DB_CFG = @"\config\db.ini"; //用户配置
 
        public const string
            DEF_SYSTEM_CONFIG = @"\config\SystemSettings.xml"; //系统设置文件
 
        public const string DEF_LOCAL_LOG = @"\err.log"; //本地日志文件
 
        /// <summary>
        ///     四舍五入小数位
        /// </summary>
        public const int DEF_DECIMAL_ROUND = 2;
 
        public const string DEF_PROGRAM_NAME = "C/S系统快速开发框架-旗舰版";
        public const string DEF_PROGRAM_VERSION = "V5.1(2021)";
 
        public const string
            ProgramVersion = "V5.0 (202105-Last Release)"; //程序版本
 
        public const string MainVersion = "20210516-2350";
 
        /// <summary>
        ///     最新版本号
        /// </summary>
        //*****最近更新的模块***********************************************************/
        public const string SalesDepartment = "20210516-1533"; // 营业部管理;
 
        public const string DataDictionary = "20210516-1753"; //"数据字典";
        public const string AccountModule = "2018020210516516-1533"; //"财务管理";
        public const string HumanResourceModule = "20210516-1533"; //"人力资源";
 
        public const string
            SystemManage = "20210516-1753"; //"系统管理";               
 
        public const string InventoryModule = "20210516-1533"; //"仓库管理";
        public const string PurchaseModule = "20210516-1753"; //"采购管理";
 
        public const string SalesModule = "20210516-1753"; //"销售模块-演示使用";
        //******************************************************************************/        
 
        public static int
            DEF_MSG_INTERVAL = 5 * 60 * 1000; //毫秒,每5分钟查一次消息            
 
        public static string DEF_UPGRADER_PROCESS_NAME =
            "CSFramework.AutoUpgrader4.0"; //升级程序进程名称
 
        public static string
            DEF_DEMO_DAL = "CSFrameworkV5.DemoDAL.DLL"; //演示数据访问层文件名
 
        //请将常量名改为您自己项目的名称,比如:YourProject*.DLL
        public static string
            DEF_SYS_MODULE = "CSFramework*.DLL"; //搜索开发框架的业务模块,文件名匹配
 
        /// <summary>
        ///     WCF模块下预设的32位令牌密码,可以改为更长,必须使用静态属性
        /// </summary>
        public static string WCF_LOGIN_TICKET =>
            "!RuTa=S$z+G$*FGs2+a/z3aDdf1G@$^1";
 
        /// 用户管理,新增用户预设密码,必须使用静态属性
        /// </summary>
        public static string DEF_PWD => "123456";
 
        /// <summary>
        ///     SQL的连接参数配置注册表路径
        /// </summary>
        public static string REG_SQL_CFG = @"SOFTWARE\CSFramework\V4.6\SQL";
 
        /// <summary>
        ///     系统数据库名。
        /// </summary>
        public static string DEF_SYSTEM_DBName = "CSFrameworkV5_System";
 
        /// <summary>
        ///     系统业务数据库名。
        /// </summary>
        public static string DEF_US_DBName = "CSFrameworkV5_Normal";
 
        /// <summary>
        ///     系统数据库账套编号(平台使用)
        /// </summary>
        public static string DEF_SYSTEM_DBID = "CSFramework.SystemDB";
 
        /// <summary>
        ///     用户自定义模块的主窗体名称
        /// </summary>
        public static string DEF_CUSTOM_MODULE_MAIN =
            "CSFrameworkV5.UserCustom.frmUserCustomMain";
 
        #endregion
 
        #region 伪造登录信息的常量定义(用于测试模拟用户登录的数据)
 
        public static string DEF_TEST_USER = "admin"; //测试用户,管理员
        public static string DEF_TEST_DATASET = "Normal"; //帐套编号
        public static string DEF_TEST_DBName = "CSFrameworkV5_Normal"; //测试数据库名
 
        #endregion
 
        #region 模块文件&子系统程序文件名定义
 
        /// <summary>
        ///     客户端WCF配置文件(WebRef.dll.config)
        /// </summary>
        public static string DEF_WEB_SERVICE_CFG =
            @"\CSFrameworkV5.WebRef.dll.config";
 
        /// <summary>
        ///     升级程序文件名(UpgraderClient.EXE)
        /// </summary>
        public static string DEF_UPGRADER_NAME =
            "CSFrameworkV5.AutoUpgrader.exe";
 
        /// <summary>
        ///     用户界面层公共库模块文件名(Library.DLL)
        /// </summary>
        public static string DEF_LIBRARY_UI_MODULE =
            @"CSFrameworkV5.Library.dll";
 
        /// <summary>
        ///     系统管理模块文件名(SystemModule.DLL)
        /// </summary>
        public static string DEF_SYSTEM_MODULE =
            @"CSFrameworkV5.SystemModule.dll";
 
        /// <summary>
        ///     数据访问层模块文件名(DataAccess.dll)
        /// </summary>
        public static string DEF_DAL_DLL = "CSFrameworkV5.DataAccess.dll";
 
        /// <summary>
        ///     业务模块文件名(Business.DLL)
        /// </summary>
        public static string DEF_BLL_MODULE = @"CSFrameworkV5.Business.dll";
 
        /// <summary>
        ///     SQL连接配置工具文件名(SqlConnector.EXE)
        /// </summary>
        public static string DEF_SQLCONFIG_NAME =
            "CSFrameworkV5.SqlConnector.exe";
 
        /// <summary>
        ///     核心库DLL文件(Core.dll)
        /// </summary>
        public static string DEF_CORE_DLL = "CSFrameworkV5.Core.dll";
 
        /// <summary>
        ///     框架基类库文件(Library.dll)
        /// </summary>
        public static string DEF_LIBRARY_DLL = "CSFrameworkV5.Library.dll";
 
        #endregion
 
        #region 公共方法
 
        /// <summary>
        ///     加载Debug\Images目录下的的图片
        /// </summary>
        /// <param name="imgFileName">文件名,如:32_Print.png</param>
        /// <returns></returns>
        public static Image LoadImage(string imgFileName)
        {
            var file = Application.StartupPath + @"\images\" + imgFileName;
            if (File.Exists(file)) return Image.FromFile(file);
 
            return null;
        }
 
        /// <summary>
        ///     加载Debug\Images目录下的图标或图片
        /// </summary>
        /// <param name="imgFileName">文件名,如:32_Print.png</param>
        /// <returns></returns>
        public static Bitmap LoadBitmap(string imgFileName)
        {
            try
            {
                var file = Application.StartupPath + @"\images\" + imgFileName;
                if (File.Exists(file))
                    using (var ms = new MemoryStream(File.ReadAllBytes(file)))
                    {
                        return new Bitmap(ms);
                    }
 
                return null;
            }
            catch
            {
                return null;
            }
        }
 
        /// <summary>
        ///     生成GUID32字符串,去掉"-"分隔符
        /// </summary>
        /// <returns></returns>
        public static object NewRowID()
        {
            Thread.Sleep(10);
            return Guid.NewGuid().ToStringEx().Replace("-", "");
        }
 
        /// <summary>
        ///     移除SQL注入非法字符
        /// </summary>
        /// <param name="content">字符串内容</param>
        /// <param name="returnMaxLength">返回的长度,0长度为不处理.</param>
        /// <returns></returns>
        public static string RemoveInjection(string content,
            int returnMaxLength = 0)
        {
            var replaced = content.Replace("'", "").Replace("@", "")
                .Replace("0x", "");
 
            if (returnMaxLength == 0) return replaced;
 
            return replaced.Substring(0,
                replaced.Length < returnMaxLength
                    ? replaced.Length
                    : returnMaxLength);
        }
 
        /// <summary>
        ///     杀掉进程
        /// </summary>
        /// <param name="processName">进程名称</param>
        /// <param name="tryKillTimes">尝试次数</param>
        public static void KillProcess(string processName, int tryKillTimes)
        {
            var tryTimes = 0;
            var ps = Process.GetProcessesByName(processName);
            while (ps.Length > 0)
            {
                ps[0].Kill();
                Application.DoEvents();
                Thread.Sleep(500); //等待0.5秒,继续查杀
 
                tryTimes++;
                if (tryTimes > tryKillTimes)
                    throw new Exception("不能删除主程序:" + processName +
                                        ",请关掉主程序后再试一次!");
 
                ps = Process.GetProcessesByName(processName);
            }
        }
 
        #endregion
    }
}