#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
|
}
|
}
|