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");
}
}
}
}