您的位置:首页 > 其它

xaf框架中web项目弹出提示框

2012-12-14 14:42 295 查看
//在Controllers文件夹下添加一个TestController.cs文件。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevExpress.Xpo;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.SystemModule;
using DevExpress.ExpressApp.Actions;
using DevExpress.Persistent.Base;
using Solution34.Module.BusinessObjects;

namespace Solution34.Module {
[NonPersistent]
public class MessageBox {
private string message;
public string Message { get { return message; } }
private MessageBox(string message) {
this.message = message;
}
public static void Show(XafApplication app, ShowViewParameters svp, string message, Action okMethod, Action cancelMethod) {
IObjectSpace os = ObjectSpaceInMemory.CreateNew();
MessageBox obj = new MessageBox(message);
svp.CreatedView = app.CreateDetailView(os, obj);
DialogController dc = app.CreateController<DialogController>();
dc.Accepting += new EventHandler<DialogControllerAcceptingEventArgs>(delegate {
if (okMethod != null) okMethod();
});
dc.Cancelling += new EventHandler(delegate {
if (cancelMethod != null) cancelMethod();
});
svp.Controllers.Add(dc);
svp.Context = TemplateContext.PopupWindow;
svp.TargetWindow = TargetWindow.NewModalWindow;
svp.NewWindowTarget = NewWindowTarget.Separate;
}
public static void Show(XafApplication app, string message, Action okMethod, Action cancelMethod) {
ShowViewParameters svp = new ShowViewParameters();
Show(app, svp, message, okMethod, cancelMethod);
app.ShowViewStrategy.ShowView(svp, new ShowViewSource(null, null));
}
}

public class MyController:ViewController {
public MyController() {
SimpleAction action = new SimpleAction(this, "TestMe", PredefinedCategory.View);
action.Execute += new SimpleActionExecuteEventHandler(action_Execute);
}
void action_Execute(object sender, SimpleActionExecuteEventArgs e) {
DomainObject obj = ObjectSpace.CreateObject<DomainObject>();
obj.Name = string.Format("sample {0:G}", DateTime.Now);
MessageBox.Show(Application, "Confirm test action?",
new Action(delegate {
obj.Description = "Test OK";
ObjectSpace.CommitChanges();
ObjectSpace.Refresh();
}),
new Action(delegate {
obj.Description = "Test Cancel";
ObjectSpace.CommitChanges();
ObjectSpace.Refresh();
}));
}
}
}


//BusinessObjects文件夹下添加一个BO.cs文件
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevExpress.Persistent.BaseImpl;
using DevExpress.Xpo;
using DevExpress.Persistent.Base;

namespace Solution34.Module.BusinessObjects {
[NavigationItem]
public class DomainObject : BaseObject{
public DomainObject(Session s) : base(s) { }
public string Name { get; set; }
public string Description { get; set; }
}
}


运行效果图:



本例子参考=====点击打开链接 http://www.devexpress.com/Support/Center/p/Q427991.aspx
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  xaf web 弹出提示框
相关文章推荐