一、增加Command定义 (在Smart.App.Public.Commands.cs 中)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Input;
using System.Windows.Controls;
using System.Windows.Media;
using Smart.Controls;
using System.Collections;
namespace Smart.App.Public
{
public class Commands
{
/*----------*/
/* TK新加 */
/*----------*/
private static SmartCommand finish = new SmartCommand(9000, "標記完成", "Finish", new KeyGesture(Key.None, ModifierKeys.None, ""));
public static SmartCommand Finish { get { return finish; } }
}
}
二、Browse Form XAML 代码
<s:BrowserPage.CommandBindings>
<!--有权限可用-->
<CommandBinding Command="local:Commands.Finish" CanExecute="CanExecuted" Executed="OnFinish" />
</s:BrowserPage.CommandBindings>
或
<s:BrowserPage.CommandBindings>
<!--有权限且有记录才可用-->
<CommandBinding Command="local:Commands.Finish" CanExecute="CanExecutedWithCurrentItem" Executed="OnFinish" />
</s:BrowserPage.CommandBindings>
三、BrowseForm 额外附加条件 (非必要)
public override void CanExecutedWithCurrentItem(object sender, CanExecuteRoutedEventArgs e)
{
base.CanExecutedWithCurrentItem(sender, e);
if (e.Command == Smart.App.Public.Commands.Finish)
{
e.CanExecute = e.CanExecute && (1 == 2); //1==2 为额外条件
}
}
或
四、BrowseForm 执行方法public override void CanExecuted(object sender, CanExecuteRoutedEventArgs e) { base.CanExecuted(sender, e); if (e.Command == Smart.App.Public.Commands.Finish) { e.CanExecute = e.CanExecute && (1==2); //1==2 为额外条件 } }
private void OnFinish(object sender, ExecutedRoutedEventArgs e)
{
if (dm.CurrentItem == null)
{
MessageBox.Show("请先选中要標記的行記錄。");
return;
}
if (string.IsNullOrEmpty(dm.CurrentItem.Row.Field<string>("OrderResult")))
{
MessageBox.Show("未處理的記錄不能做標記完成。");
return;
}
var editor = new PubOrderEditor();
editor.State = DataState.Edit;
editor.IsMarkFinish = true;
editor.IsDisableInput = true;
editor.DataModel = dm;
AppManager.ShowWindowInTab("標記完成", editor);
}
详见: TK的订单