父窗体接收子窗体返回的数据

需求:生产用料清单上面点击按钮弹出一个窗体,窗体上面有个单据体,选中单据体中的某些数据,点击返回按钮,就会把选中的数据添加到父窗体中。

BOS截图如下:

新建一个普通动态表单,拖入一个按钮和一个单据体,并在单据体中加入需要的字段。

生产用料清单上面添加按钮。

在生产用料清单和新建的普通动态表单上分别注册插件。

 

插件源码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.Metadata.EntityElement;
using Kingdee.BOS.Orm.DataEntity;
using System.Text.RegularExpressions;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Bill.PlugIn.Args;
using Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel;
using Kingdee.BOS.Core.Metadata;
using System.Data;
using Kingdee.BOS.Util;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.JSON;
using Kingdee.BOS.Core.Bill;
using Kingdee.BOS.Core.Metadata.ControlElement;
using Kingdee.BOS.Cache;
using System.ComponentModel;
using Kingdee.BOS.Core;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Orm;

namespace GetMat
{
    [Description("演示如何从子界面返回数据 - 父界面插件")]
    public class GetMat : AbstractDynamicFormPlugIn
    {
        public override void ButtonClick(ButtonClickEventArgs e)
        {
            if (e.Key.ToUpperInvariant().Equals("F_PAEZ_GETMAT"))
            {
                string FBillNO = this.View.Model.GetValue("FBillNo").ToString();
                string Sql = "exec Z_GetMatInfo '"+ FBillNO+"'";
                DataSet ds = new DataSet();
                ds = Kingdee.BOS.ServiceHelper.DBServiceHelper.ExecuteDataSet(this.Context,Sql);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    MatInfo.MatNO = ds.Tables[0].Rows[0]["MatNO"].ToString();
                    MatInfo.MatName = ds.Tables[0].Rows[0]["MatName"].ToString();
                    MatInfo.MatXH = ds.Tables[0].Rows[0]["XH"].ToString();
                    //MatInfo.MatGL = ds.Tables[0].Rows[0][""].ToString();
                    MatInfo.MatZZ = ds.Tables[0].Rows[0]["ZZNO"].ToString();
                    MatInfo.MatWX = ds.Tables[0].Rows[0]["WX"].ToString();
                    MatInfo.MatTouLiao = Convert.ToDecimal(ds.Tables[0].Rows[0]["TouLiao"].ToString());
                }

                DynamicFormShowParameter showParam = new DynamicFormShowParameter();
                showParam.FormId = "kf6e7eb2e185e4130ab7d44cde217a532";
                this.View.ShowForm(showParam,
                    new Action<FormResult>((formResult) =>
                    {
                        if (formResult != null && formResult.ReturnData != null)
                        {
                            this.Model.SetValue("F_PAEZ_Text",
                                ((ReturnDataInfo)formResult.ReturnData).F_PAEZ_Text);
                            for (int i = 0; i < ((ReturnDataInfo)formResult.ReturnData).entityrows.Count; i++)
                            {
                                if (((ReturnDataInfo)formResult.ReturnData).entityrows[i]["F_PAEZ_CheckBox"].ToString().Equals("True"))
                                {
                                    this.View.Model.CreateNewEntryRow("FEntity");
                                    int RowCount = this.View.Model.GetEntryRowCount("FEntity");
                                    this.View.Model.SetItemValueByID("FMaterialID2", ((ReturnDataInfo)formResult.ReturnData).entityrows[i]["F_PAEZ_Mat_ID"], RowCount - 1);
                                }
                            }
                        }
                    }));
            }
        }
    }
    [Description("演示如何从子界面返回数据 - 子界面插件")]
    public class ReturnInfoChild : AbstractDynamicFormPlugIn
    {
        public override void ButtonClick(ButtonClickEventArgs e)
        {
            // 用户点击确定按钮
            if (e.Key.ToUpperInvariant().Equals("F_PAEZ_RETURN"))
            {
                //取单据体对象数据
                Entity entity = this.View.BusinessInfo.GetEntity("F_PAEZ_Entity");
                DynamicObjectCollection rowObjs = this.View.Model.GetEntityDataObject(entity);                
                // 构建返回数据对象
                ReturnDataInfo returnInfo = new ReturnDataInfo();
                returnInfo.F_PAEZ_Text = Convert.ToString(this.Model.GetValue("F_PAEZ_Text"));
                returnInfo.Entry = entity;
                returnInfo.entityrows = rowObjs;
                int rowcount = rowObjs.Count;
                // 把数据对象,返回给父界面
                this.View.ReturnToParentWindow(new FormResult(returnInfo));
                this.View.Close();
            }
        }
        public override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            //this.View.Model.SetValue("F_PAEZ_Text","123456");
            string sql = "exec Z_GetPartMat '"+ MatInfo.MatXH+"','"+MatInfo.MatZZ+"',"+MatInfo.MatTouLiao;
            DataSet ds = new DataSet();
            ds = Kingdee.BOS.ServiceHelper.DBServiceHelper.ExecuteDataSet(this.Context,sql);
            int RowCount = ds.Tables[0].Rows.Count;
            if (RowCount > 0)
            {
                for (int i = 0; i < RowCount; i++)
                {
                    this.View.Model.CreateNewEntryRow("F_PAEZ_Entity");
                    this.View.Model.SetItemValueByNumber("F_PAEZ_Mat",ds.Tables[0].Rows[i]["MatNO"].ToString(),i);
                    this.View.Model.SetValue("F_PAEZ_LH", ds.Tables[0].Rows[i]["Lot"].ToString(),i);
                    this.View.Model.SetValue("F_PAEZ_XH", ds.Tables[0].Rows[i]["FGL"].ToString(), i);
                    this.View.Model.SetValue("F_PAEZ_ZZ", ds.Tables[0].Rows[i]["CZ"].ToString(), i);
                    this.View.Model.SetValue("F_PAEZ_WX", ds.Tables[0].Rows[i]["WX"].ToString(), i);
                    this.View.Model.SetValue("F_PAEZ_STOCKQTY", ds.Tables[0].Rows[i]["Qty"].ToString(), i);
                }
            }

        }
    }
    /// <summary>
    /// 由子窗体返回给父窗体的数据对象
    /// </summary>
    public class ReturnDataInfo
    {
        public string F_PAEZ_Text { get; set; }
        public Entity Entry { get; set; }
        public DynamicObjectCollection entityrows { get; set; }
    }

    ///成品阻值,温度系数信息
    public static class MatInfo
    {
        public static string MatNO { get; set; }
        public static string MatName { get; set; }
        public static string MatXH { get; set; }
        public static string MatGL { get; set; }
        public static string MatZZ { get; set; }
        public static string MatWX { get; set; }
        public static decimal MatTouLiao { get; set; }
    }
}

 

posted @ 2018-12-03 14:41  放放的Blog  阅读(383)  评论(1编辑  收藏  举报