C/S开发框架提供类似SAP系统的快速命令,能快速打开界面窗体(Command模式)
C/S开发框架提供类似SAP系统的快速命令,能快速打开界面窗体(Command模式)
场景
扫一扫加微信
输入命令后按回车,系统自动解析输入内容,并执行相应的动作。
设计采用命令模式:Command Pattern
回车事件:
C# Code:
private void txtCommand_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
if (txtCommand.Text.Trim() != "")
{
e.Handled = true;
CommandHandler.Execute(this, txtCommand.Text.Trim());
txtCommand.Text = "";
}
}
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
{
if (e.KeyCode == Keys.Enter)
{
if (txtCommand.Text.Trim() != "")
{
e.Handled = true;
CommandHandler.Execute(this, txtCommand.Text.Trim());
txtCommand.Text = "";
}
}
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
经典命令模式:
C# Code:
/// <summary>
/// 执行命令
/// </summary>
/// <param name="instance">主窗体实例</param>
/// <param name="cmdText">命令文本</param>
/// <returns></returns>
public static object Execute(IMdiForm instance, string cmdText)
{
//匹配命令字符,返回对象实例
QuickCommand cmd = AllCommands.Find(delegate (QuickCommand p) { return p.Match(cmdText); });
if (cmd == null) throw new Exception("无效的命令!参考:PO,PO1,PO2,SO,LK,HELP");
//界面操作通用处理方法
if (cmd.IsFormAction)
return instance.OpenModuleForm(cmd);
//锁定用户界面命令
if (cmd.CommandCode == "LK")
return frmLock.ExecuteLock(instance as Form);
//打开帮助文档
if (cmd.CommandCode == "HELP")
HelpDoc.HelpAllFile(HelpDoc.CSHelp);
//
//其它命令
//
return null;
}
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
/// 执行命令
/// </summary>
/// <param name="instance">主窗体实例</param>
/// <param name="cmdText">命令文本</param>
/// <returns></returns>
public static object Execute(IMdiForm instance, string cmdText)
{
//匹配命令字符,返回对象实例
QuickCommand cmd = AllCommands.Find(delegate (QuickCommand p) { return p.Match(cmdText); });
if (cmd == null) throw new Exception("无效的命令!参考:PO,PO1,PO2,SO,LK,HELP");
//界面操作通用处理方法
if (cmd.IsFormAction)
return instance.OpenModuleForm(cmd);
//锁定用户界面命令
if (cmd.CommandCode == "LK")
return frmLock.ExecuteLock(instance as Form);
//打开帮助文档
if (cmd.CommandCode == "HELP")
HelpDoc.HelpAllFile(HelpDoc.CSHelp);
//
//其它命令
//
return null;
}
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
C# Code:
/// <summary>
/// 系统定义的所有命令
/// </summary>
private static List<QuickCommand> AllCommands
{
get
{
if (_AllCommands == null)
{
//模拟命令表(从数据库获取)
DataTable dt = new DataTable("sys_Commands");
dt.Columns.Add("CommandCode", typeof(String));//命令,如:PO,PO1,PO2,SO,HELP,LK
dt.Columns.Add("CommandName", typeof(String));//命令名称,PO-打开采购订单
dt.Columns.Add("CommandType", typeof(String));//命令类型:OpenForm-打开窗体,Add,Search,Other
dt.Columns.Add("FormNamespace", typeof(String));//窗体的命名空间
dt.Columns.Add("MenuName", typeof(String));//打开此窗体关联的菜单名称(模块主窗体内定义)
dt.Rows.Add(new object[] { "PO", "打开采购订单", "OpenForm", "CSFrameworkV5.DemoPurchaseModule.frmPO", "menuItemPO" });
dt.Rows.Add(new object[] { "PO1", "采购订单-新增", "Add", "CSFrameworkV5.DemoPurchaseModule.frmPO", "menuItemPO" });
dt.Rows.Add(new object[] { "PO2", "采购订单-搜索", "Search", "CSFrameworkV5.DemoPurchaseModule.frmPO", "menuItemPO" });
dt.Rows.Add(new object[] { "SO", "打开销售订单", "OpenForm", "CSFrameworkV5.DemoSalesModule.frmSO", "menuSalesOrder" });
dt.Rows.Add(new object[] { "HELP", "打开帮助文档", "Other", "", "" });
dt.Rows.Add(new object[] { "LK", "锁定主界面", "Other", "", "" });
dt.AcceptChanges();
//将DataTable转换为对象列表
List<QuickCommand> list = new ModelConverter<QuickCommand>().FillModel(dt);
return list;
}
return _AllCommands;
}
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
/// 系统定义的所有命令
/// </summary>
private static List<QuickCommand> AllCommands
{
get
{
if (_AllCommands == null)
{
//模拟命令表(从数据库获取)
DataTable dt = new DataTable("sys_Commands");
dt.Columns.Add("CommandCode", typeof(String));//命令,如:PO,PO1,PO2,SO,HELP,LK
dt.Columns.Add("CommandName", typeof(String));//命令名称,PO-打开采购订单
dt.Columns.Add("CommandType", typeof(String));//命令类型:OpenForm-打开窗体,Add,Search,Other
dt.Columns.Add("FormNamespace", typeof(String));//窗体的命名空间
dt.Columns.Add("MenuName", typeof(String));//打开此窗体关联的菜单名称(模块主窗体内定义)
dt.Rows.Add(new object[] { "PO", "打开采购订单", "OpenForm", "CSFrameworkV5.DemoPurchaseModule.frmPO", "menuItemPO" });
dt.Rows.Add(new object[] { "PO1", "采购订单-新增", "Add", "CSFrameworkV5.DemoPurchaseModule.frmPO", "menuItemPO" });
dt.Rows.Add(new object[] { "PO2", "采购订单-搜索", "Search", "CSFrameworkV5.DemoPurchaseModule.frmPO", "menuItemPO" });
dt.Rows.Add(new object[] { "SO", "打开销售订单", "OpenForm", "CSFrameworkV5.DemoSalesModule.frmSO", "menuSalesOrder" });
dt.Rows.Add(new object[] { "HELP", "打开帮助文档", "Other", "", "" });
dt.Rows.Add(new object[] { "LK", "锁定主界面", "Other", "", "" });
dt.AcceptChanges();
//将DataTable转换为对象列表
List<QuickCommand> list = new ModelConverter<QuickCommand>().FillModel(dt);
return list;
}
return _AllCommands;
}
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
扫一扫加微信
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网