EPR类企业管理系统

在我们现有系统基础上或全新开发,提供定制服务
为您的企业高效快速实施ERP,WMS,MES,CRM管理系统
全面管控物料仓库、销售业务、采购业务、仓库业务
生产过程、质量检验、组织架构、业务报表


定制
QQ:460-3528

开发
QQ群:3360-90194

源码
微信:136-3650-3721

显示确认对话框的方法

本主题描述如何显示带有其他字段的确认消息/对话框。

本主题包括以下部分:

提示

如果要显示文本通知,请参考以下主题:

使用ConfirmationMessage属性

使用代码中的ActionBase.ConfirmationMessage属性或模型编辑器中的IModelAction.ConfirmationMessage可以更改内置或自定义Actions的默认确认消息。

例如,实现以下Controller来更改Delete Action的确认消息:

public class ConfirmationWindowActionController : ViewController {
    DeleteObjectsViewController deleteObjectsViewController;
    protected override void OnActivated() {
        base.OnActivated();
        deleteObjectsViewController = Frame.GetController<DeleteObjectsViewController>();
        if (deleteObjectsViewController != null) {
            View.SelectionChanged  = View_SelectionChanged;
        }
    }
    void View_SelectionChanged(object sender, System.EventArgs e) {
        deleteObjectsViewController.DeleteAction.ConfirmationMessage =
                String.Format("You are about to delete {0} object(s). Do you want to proceed?", 
(View.SelectedObjects.Count));
    }
    protected override void OnDeactivated() {
        base.OnDeactivated();
        if (deleteObjectsViewController != null) {
            View.SelectionChanged -= View_SelectionChanged;
            deleteObjectsViewController = null;
        }
    }
}

单击删除操作以查看结果:

ActionBase_ConfirmationMessage_Win

ActionBase_ConfirmationMessage_Web

使用新的详细视图

本节演示如何使用非持久对象的Detail View调用弹出窗口。

将以下非持久类添加到与平台无关的模块项目中。用DomainComponentAttribute装饰此类,以在Types Info Subsystem中注册它。

using DevExpress.ExpressApp.DC;
using DevExpress.ExpressApp.Model;
//...
[DomainComponent]
public class ConfirmationWindowParameters {
    public ConfirmationWindowParameters() { }
    [ModelDefault("AllowEdit", "False")]
    public string ConfirmationMessage { get; set; }
}

执行操作时,请使用以下方法之一在弹出窗口中显示确认消息:

使用CustomizePopupWindowParams事件

  1. 在其构造函数中创建一个新的ViewControllerPopupWindowShowAction
  2. 在Action的CustomizePopupWindowParams事件中,创建一个非持久对象空间,一个新的 ConfirmationWindowParameters类实例以及该对象的DetailView
  3. 指定ConfirmationWindowParameters对象的属性,并将CustomizePopupWindowParamsEventArgs.View参数设置为新创建的Detail View,以在弹出窗口中显示它。
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
//...
public class ConfirmationWindowController : ViewController {
    public ConfirmationWindowController() {
        PopupWindowShowAction showConfirmationWindowAction = 
new PopupWindowShowAction(this, "CustomConfirmationWindow", DevExpress.Persistent.Base.PredefinedCategory.View);
        showConfirmationWindowAction.ImageName = "ModelEditor_Views";
        showConfirmationWindowAction.CustomizePopupWindowParams  = 
showConfirmationWindowAction_CustomizePopupWindowParams;
    }
    private void showConfirmationWindowAction_CustomizePopupWindowParams(object sender, 
CustomizePopupWindowParamsEventArgs e) {
        NonPersistentObjectSpace objectSpace = 
        (NonPersistentObjectSpace)Application.CreateObjectSpace(typeof(ConfirmationWindowParameters));
        ConfirmationWindowParameters parameters = 
        objectSpace.CreateObject<ConfirmationWindowParameters>();
        parameters.ConfirmationMessage = "Confirmation message text.";
        objectSpace.CommitChanges();
        DetailView confirmationDetailView = Application.CreateDetailView(objectSpace, parameters);
        confirmationDetailView.Caption = "Custom Confirmation Window";
        confirmationDetailView.ViewEditMode = DevExpress.ExpressApp.Editors.ViewEditMode.View;
        e.View = confirmationDetailView;
    }
}

下图显示了此确认窗口:

CustomConfirmationWindow_Win

CustomConfirmationWindow_Web

CustomConfirmationWindow_Mobile

注意

您还可以处理“确定”和“关闭”按钮的单击。为此,请使用CustomizePopupWindowParamsEventArgs.DialogController属性访问对话框控制器,并预订其接受取消事件。

使用ShowViewInPopupWindow方法

  1. 在其构造函数中创建一个新的ViewControllerSimpleAction
  2. 在Action的Execute事件中,创建一个非持久对象空间,一个新的ConfirmationWindowParameters类实例以及该对象的DetailView
  3. ConfirmationWindowParameters对象的属性设置为必需的值,然后调用ShowViewStrategyBase.ShowViewInPopupWindow方法。将新创建的Detail View传递为ShowViewInPopupWindow的第一个参数,以在弹出窗口中显示此View。您还可以传递代表以处理“确定”和“取消”按钮的单击。
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.Persistent.Base;
// ...
public class ConfirmationWindowController : ViewController {
    public ConfirmationWindowController() {
        SimpleAction showConfirmationWindowAction = new SimpleAction(this, "CustomConfirmationWindow", PredefinedCategory.View);
        showConfirmationWindowAction.ImageName = "ModelEditor_Views";
        showConfirmationWindowAction.Execute  = ShowConfirmationWindowAction_Execute;
    }
    private void ShowConfirmationWindowAction_Execute(object sender, 
    SimpleActionExecuteEventArgs e) {
        NonPersistentObjectSpace objectSpace = 
        (NonPersistentObjectSpace)Application.CreateObjectSpace(typeof(ConfirmationWindowParameters));
        ConfirmationWindowParameters parameters = new ConfirmationWindowParameters();
        parameters.ConfirmationMessage = "A confirmation message text.";
        DetailView confirmationDetailView = Application.CreateDetailView(objectSpace, parameters);
        confirmationDetailView.Caption = "Custom Confirmation Window";
        Application.ShowViewStrategy.ShowViewInPopupWindow(confirmationDetailView, OkDelegate, CancelDelegate);
    }
    public void OkDelegate() {
            Application.ShowViewStrategy.ShowMessage("The message is accepted!");
    }
    public void CancelDelegate() {
            Application.ShowViewStrategy.ShowMessage("The message is canceled!");
    }
}

使用消息传递类的方法

使用Messaging类的方法在WinForms应用程序中显示带有标准对话框按钮(请参见MessageBoxButtons)的确认消息。以下控制器演示了如何使用此类显示确认窗口:

public class MessagingController : ViewController {
    public MessagingController() {
        SimpleAction showMessagingConfirmationForm = new SimpleAction(this, "CustomDeleteAction", DevExpress.Persistent.Base.PredefinedCategory.View);
        showMessagingConfirmationForm.ImageName = "Action_Delete";
        showMessagingConfirmationForm.Execute  = showMessagingConfirmationForm_Execute;
    }
    void showMessagingConfirmationForm_Execute(object sender, SimpleActionExecuteEventArgs e) {
        if (WinApplication.Messaging.GetUserChoice("Do you want to delete the selected object(s)?", 
"Confirmation Window", MessageBoxButtons.YesNo) == DialogResult.Yes)
            View.ObjectSpace.Delete(e.SelectedObjects);
        View.ObjectSpace.CommitChanges();
    }
}

下图演示了此实现结果。

CustomConfirmationMessage_Messaging

相关文章

转载保留此链接,注明出处