金蝶云星空——打开其他表单编辑页面并传递参数

1. 父窗体添加一个tbShow按钮,点击按钮调出调拨申请单的新增页面,同时传递参数

  • 这个父窗体是一个简单报表,
  • 创建一个表单插件
  • 点击tbShow按钮,获取用户的选中行数据,将该选中的数据作为参数传递到子窗体
using Kingdee.BOS.Core.Bill;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.Report.PlugIn;
using Kingdee.BOS.Util;
using System;
using System.ComponentModel;
using System.Data;
using System.Linq;

namespace WeiWaiFaLiaoQingDan2
{
    /// <summary>
    /// 委外发料清单——表单插件
    /// </summary>
    [Description("委外发料清单——表单插件——获取选中行/创建调拨单")]
    public class GetSelectedRowsSysReportPlugIn : AbstractSysReportPlugIn
    {
        public override void BarItemClick(BarItemClickEventArgs e)
        {
            base.BarItemClick(e);
            //测试:该按钮获取用户在简单报表
            if (e.BarItemKey.EqualsIgnoreCase("tbCreateTransfer"))
            {
                // SelectedDataRows存储了账表当前选中行(BOSIDE开启属性【允许多选】后,支持选中多行)
                var selectedDataRows = this.SysReportView.SelectedDataRows;
                if (selectedDataRows == null || selectedDataRows.Length == 0)
                {
                    this.View.ShowMessage("没有选择任何数据,请先选择数据!");
                    return;
                }
                string a = "";
                foreach (DataRow item in selectedDataRows)
                {
                    a += GetDataRowFormatString(item);
                }

                var selectedRow = selectedDataRows[0];
                var msg = GetDataRowFormatString(selectedRow);
                this.View.ShowMessage("当前选中行数据包:" + msg + "\t\n" + a);
                //this.View.ShowMessage(JsonUtil.Serialize(selectedDataRows));
            }
            if (e.BarItemKey.EqualsIgnoreCase("tbShow"))
            {
                var selectedDataRows = this.SysReportView.SelectedDataRows;

                if (selectedDataRows == null || selectedDataRows.Length == 0)
                {
                    this.View.ShowMessage("没有选择任何数据,请先选择数据!");
                    return;
                }
                DataTable dt = selectedDataRows[0].Table.Clone();
                foreach (DataRow item in selectedDataRows)
                {
                    dt.ImportRow(item);
                }

                BillShowParameter showParameter = new BillShowParameter();
                showParameter.FormId = "STK_TRANSFERAPPLY";//调拨申请单的标识,注意:若是该表单有扩展的表单,依旧是使用原始的标识
                showParameter.OpenStyle.ShowType = ShowType.MainNewTabPage;//窗口打开方式,显示为一个新的页签
                showParameter.PageId = Guid.NewGuid().ToString();

                //已新增的状态打开
                showParameter.Status = OperationStatus.ADDNEW;
                //已编辑的状态打开,并传入需要修改的销售订单内码,这里演示直接固定写死为109574
                //showParameter.Status = OperationStatus.EDIT;
                //showParameter.PKey = "109574";

                //添加自定义参数
                showParameter.CustomParams.Add("MyFEntity", JsonUtil.Serialize(dt));

                //this.View.ShowForm(showParameter);
            }
        }

        private string GetDataRowFormatString(DataRow row)
        {
            return string.Join(",", row.Table.Columns.Cast<DataColumn>().Select(co => string.Format("{0}:{1}", co.ColumnName, row[co.ColumnName])));
        }
    }
}

2. 子窗体中接受父窗体传递来数据,并对表单的单据头和单据体进行初始化赋值

  • 这是一个表单插件
  • 注意这里的数据接受和对表单的数据初始化,是在OnLoad函数中进行的
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Util;
using System;
using System.ComponentModel;
using System.Data;

namespace DiaoBoShenQingDan
{
    [Description("调拨申请单——表单插件获取和设置值")]
    public class DiaoBoShenQingDan : AbstractBillPlugIn
    {
        public override void OnInitialize(InitializeEventArgs e)
        {
            base.OnInitialize(e);

            //if (e.Paramter.GetCustomParameters().ContainsKey("MyFEntity"))
            //{
            //    //this.View.Model.SetValue("", "");
            //    this.View.Model.SetValue("FRemarks", "dddddddddddddddddddd");
            //    //this.View.UpdateView("FRemarks");
            //    this.View.Model.SetItemValueByNumber("FMATERIALID", "C02010100002", 1);
            //    //this.View.UpdateView();
            //    //this.View.Refresh();
            //    this.View.ShowMessage(e.Paramter.GetCustomParameter("MyFEntity").ToString());
            //}
            //else
            //{
            //    this.View.Model.SetValue("FRemarks", "dddddddddddddddddddd");
            //    this.View.Model.SetItemValueByNumber("FMATERIALID", "C02010100002", 1);
            //}
        }

        public override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            //string result = this.View.ParentFormView.OpenParameter.GetCustomParameter("MyFEntity").ToString();
            if (this.View.OpenParameter.GetCustomParameters().ContainsKey("MyFEntity"))
            {
                //获取父页面的传递来的自定义参数
                string result = this.View.OpenParameter.GetCustomParameter("MyFEntity").ToString();
                DataTable dt = JsonUtil.DeserializeObject<DataTable>(result);
                //this.View.ShowMessage("OnLoad中获取到参数" + result);

                //给单据头中的字段进行赋值
                this.View.Model.SetValue("FRemarks", "委外发料清单发起的委外调拨单");
                this.View.Model.SetValue("FBillTypeID", "667122645c766f");
                this.View.Model.SetValue("F_SZAC_GYS", dt.Rows[0]["FSUPPLIERID"].ToString());

                //批量给单据体新增指定的行数
                this.View.Model.BatchCreateNewEntryRow("FEntity", dt.Rows.Count - 1);
                //循环给单据体每一行进行赋值
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    this.View.Model.SetItemValueByNumber("FMATERIALID", dt.Rows[i]["DeMaterialNo"].ToString(), i);
                    //触发字段值更新,将其他相关数据自动带出
                    this.View.InvokeFieldUpdateService("FMATERIALID", i);
                    this.View.Model.SetValue("FQty", dt.Rows[i]["FNOPICKEDQTY"].ToString(), i);
                }

                //刷新
                this.View.UpdateView("FEntity");
            }
        }
    }
}

posted @ 2024-10-30 08:32  shanzm  阅读(2)  评论(0编辑  收藏  举报
TOP