点击保存按钮时自动添加相关记录(用于界面查看),另外还有Audit控件可使用,此处只是一个简单的功能。
新建一个VC并关联到相关的View,代码如下:
public partial class GongZuoJiaoShenController : ViewController
{
public GongZuoJiaoShenController()
{
InitializeComponent();
// Target required Views (via the TargetXXX properties) and create their Actions.
} protected override void OnActivated()
{
base.OnActivated();
// Perform various tasks depending on the target View.
//注册提交事件
ObjectSpace.Committing += ObjectSpace_Committing;
} private void ObjectSpace_Committing(object sender, System.ComponentModel.CancelEventArgs e)
{
GongZuoJiaoShen gongZuoJiaoShen = View.CurrentObject as GongZuoJiaoShen;
JiaoShenJiLu jiaoShenJiLu = ObjectSpace.CreateObject<JiaoShenJiLu>();
//新建时自动添加处理记录
if (View.ObjectSpace.IsNewObject(gongZuoJiaoShen))
{
jiaoShenJiLu.CaoZuoLeiXing = JiaoShenCaoZuoLeiXing.新建;
jiaoShenJiLu.ChuLiRen = (YuanGong)ObjectSpace.GetObject(SecuritySystem.Instance.User);
jiaoShenJiLu.ChuLiShiJian = DateTime.Now;
jiaoShenJiLu.ChuLiYiJian = "自校通过";
gongZuoJiaoShen.JiaoShenJiLu.Add(jiaoShenJiLu);
}
} protected override void OnViewControlsCreated()
{
base.OnViewControlsCreated();
// Access and customize the target View control.
} protected override void OnDeactivated()
{
// Unsubscribe from previously subscribed events and release other references and resources.
base.OnDeactivated();
ObjectSpace.Committing -= ObjectSpace_Committing;
} #region 审核通过事件
private void ShenHe_CustomizePopupWindowParams(object sender, CustomizePopupWindowParamsEventArgs e)
{
ShenHeJieMian(e, "审核通过");
} private void ShenHe_Execute(object sender, PopupWindowShowActionExecuteEventArgs e)
{
//创建对象并赋值
JiaoShenJiLu_Create(e.PopupWindowViewCurrentObject, JiaoShenCaoZuoLeiXing.审核通过);
View.ObjectSpace.CommitChanges();
}
#endregion #region 审核不通过事件
private void ShenHeBuTongGuo_CustomizePopupWindowParams(object sender, CustomizePopupWindowParamsEventArgs e)
{
ShenHeJieMian(e, "审核不通过");
} private void ShenHeBuTongGuo_Execute(object sender, PopupWindowShowActionExecuteEventArgs e)
{
JiaoShenJiLu_Create(e.PopupWindowViewCurrentObject, JiaoShenCaoZuoLeiXing.审核不通过);
}
#endregion /// 创建校审记录对象
/// <summary>
/// 创建校审记录对象
/// </summary>
/// <param name="obj"></param>
/// <param name="caoZuoLeiXing"></param>
private void JiaoShenJiLu_Create(object obj, JiaoShenCaoZuoLeiXing caoZuoLeiXing)
{
//创建对象并赋值
JiaoShenJiLu jiaoShenJiLu = (JiaoShenJiLu)obj;
jiaoShenJiLu.GongZuoJiaoShen = View.CurrentObject as GongZuoJiaoShen;
jiaoShenJiLu.CaoZuoLeiXing = caoZuoLeiXing;
jiaoShenJiLu.ChuLiRen = (YuanGong)ObjectSpace.GetObject(SecuritySystem.Instance.User);
jiaoShenJiLu.ChuLiShiJian = DateTime.Now;
View.ObjectSpace.CommitChanges();
//View.Refresh(true);
// View.RefreshDataSource();
} /// 弹出窗口对象
/// <summary>
/// 弹出窗口对象
/// </summary>
/// <param name="e"></param>
/// <param name="caption">标题</param>
private void ShenHeJieMian(CustomizePopupWindowParamsEventArgs e, string caption)
{
e.DialogController.SaveOnAccept = false;
IObjectSpace objectSpace = this.ObjectSpace;
//创建DetailView对象
JiaoShenJiLu jiaoShenJiLu = objectSpace.CreateObject(typeof(JiaoShenJiLu)) as JiaoShenJiLu;
e.View = Application.CreateDetailView(objectSpace, jiaoShenJiLu, this.View);
e.View.Caption = caption;
} }
效果图如下: