父窗體接收子窗體返回的資料
需求:生產用料清單上面點選按鈕彈出一個窗體,窗體上面有個單據體,選中單據體中的某些資料,點選返回按鈕,就會把選中的資料新增到父窗體中。
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; }
}
}