动态表单

加载和关闭

OnLoad

页面加载。该事件在BeforeBindData前触发,并且不受StyleManager管理,在此事件设置单据字段的可见性和锁定性无效。

OnLoad时,数据已经获取到,通常我们在此事件处理一些数据设置。

例如:过滤界面插件设置缺省值和页签可见性。

public class SaleCollectFilter : AbstractCommonFilterPlugIn
{
public override void OnLoad(EventArgs e)
{
base.OnLoad(e);
//设置日期缺省值
    this.View.Model.SetValue("FStartDate", dateFrom.ToString("yyyy-MM-dd"));
this.View.Model.SetValue("FEndDate", dateTo.ToString("yyyy-MM-dd"));
//隐藏过滤界面排序页签
this.View.StyleManager.SetVisible("FTab_P21", null, false);
}
}

列表界面隐藏分组滑动控件。

public class SPMPromotionPolicyList : AbstractListPlugIn
{
     public override void OnLoad(EventArgs e)
     {
         base.OnLoad(e);
         // 隐藏分组滑动控件(默认不展开)
         this.View.GetControl<SplitContainer>("FSpliter").HideFirstPanel(true);
this.View.GetControl("FPanel").SetCustomPropertyValue("BackColor", "#FFEEEEEE");
     }
}

注:该事件在每次UpdateView()时候都会调用。

BeforeClosed

页面关闭前插件。对于单个表单关闭,该插件基本不需要处理。对于多个表单交互,或者嵌入式表单,通常需要关闭窗体时,返回数据时,通过该插件实现。

如:关闭时刷新父窗体。

public override void BeforeClosed(BeforeClosedEventArgs e)
{
    object isDataChanged = this.View.OpenParameter.GetCustomParameter("Changed");
    if (isDataChanged != null && (bool)isDataChanged)
    {
        this.View.ParentFormView.Refresh();
        this.View.SendDynamicFormAction(this.View.ParentFormView);
}
    base.BeforeClosed(e);
}

关闭时传递数据到父窗体。

public override void BeforeClosed(BeforeClosedEventArgs e)
{
this.View.ReturnToParentWindow(_data);
    base.BeforeClosed(e);
}

关闭窗体判断数据是否修改并提示保存。

/// <summary>
/// 界面关闭前事件:判断用户是否修改了数据,提示保存
/// </summary>
/// <param name="e"></param>
public override void BeforeClosed(BeforeClosedEventArgs e)
{
    if (this._dataChanged == true) // 仅关注模型数据发生了改变的情况
    {
        e.Cancel = true;
        string msg = "内容已经修改,是否保存?";
        this.View.ShowMessage(msg, MessageBoxOptions.YesNoCancel, new Action<MessageBoxResult>((result) =>
        {
            if (result == MessageBoxResult.Yes) // 保存
            {
                       this.View.GetControl("FDesignPanel").InvokeControlMethod("Save");
            }
            else if (result == MessageBoxResult.No) // 不要保存
            {
                this._dataChanged = false;         
                this.View.Close();
            }
        }));
    }
}


原文地址:https://www.cnblogs.com/fyq891014/p/4188781.html