K3cloud 动态表单中,调用其它单据的套打模板
Posted liangyuwen
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了K3cloud 动态表单中,调用其它单据的套打模板相关的知识,希望对你有一定的参考价值。
在动态表单中,调用其它单据的套打模板,还需要在动态表单的 OnPrepareNotePrintData 事件中,为单据的套打准备数据。
完整的示例代码如下:
//**********************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using Kingdee.BOS;
using Kingdee.BOS.Util;
using Kingdee.BOS.Core;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.NotePrint;
using Kingdee.BOS.JSON;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.ServiceHelper;
namespace JDSample.FormPlugIn.DynamicForm
{
[Description("打印其他单据的套打")]
public class S151021NotePrintEdit : AbstractDynamicFormPlugIn
{
/// <summary>
/// 待打印的单据数据包
/// </summary>
private DynamicObject _billObj = null;
public override void AfterBarItemClick(AfterBarItemClickEventArgs e)
{
if (e.BarItemKey.EqualsIgnoreCase("tbPrintConvA"))
{
string billFormId = "0964b538-feea-46df-8e48-c7a78b6ca992";
string billId = "100042";
// 加载单据数据包,放在缓存中,以被后续事件使用
FormMetadata meta = MetaDataServiceHelper.Load(
this.Context, billFormId) as FormMetadata;
this._billObj = BusinessDataServiceHelper.LoadSingle(
this.Context, billId, meta.BusinessInfo.GetDynamicObjectType());
// 下达打印预览指令
List<PrintJobItem> printInfoList = new List<PrintJobItem>();
PrintJobItem printInfoItem = new PrintJobItem();
printInfoItem.BillId = billFormId;
printInfoItem.FormId = billFormId;
printInfoItem.TemplateId = "9be75356-2ee6-46cc-b33a-5a3eb7ef7418";
printInfoItem.SortString = "";
printInfoList.Add(printInfoItem);
string key = Guid.NewGuid().ToString();
this.View.Session[key] = printInfoList;
JSONObject jsonObj = new JSONObject();
jsonObj.Put("pageID", this.View.PageId);
jsonObj.Put("printJobId", key);
jsonObj.Put("action", "preview");//预览--printType赋值为"preview";打印--printType赋值为"print"
string action = "printPreview";
jsonObj.Put("printBarName", null);
this.View.AddAction(action, jsonObj);
}
}
public override void OnPrepareNotePrintData(PreparePrintDataEventArgs e)
{
//构建新数据包并提供给系统
if (e.DataSourceId.Equals("FBillHead", StringComparison.OrdinalIgnoreCase))
{
// 基于套打要求的ORM数据模型,构建数据包,取单据头的字段值
// 特别注意:e.DynamicObjectType,仅包含了套打会用到的单据头字段
DynamicObject notePrintHeadObj = new DynamicObject(e.DynamicObjectType);
// 为字段赋值:本例仅演示给单据编号赋值
notePrintHeadObj["FBillNo"] = _billObj["BillNo"];
e.DataObjects = new DynamicObject[] { notePrintHeadObj };
}
if (e.DataSourceId.Equals("FEntity", StringComparison.OrdinalIgnoreCase))
{
// 基于套打要求的ORM数据模型,构建数据包,取单据体的字段值
// 特别注意:e.DynamicObjectType,仅包含了套打会用到的单据体字段
List<DynamicObject> notePrintEntryRows = new List<DynamicObject>();
DynamicObjectCollection billRows = _billObj["FEntity"] as DynamicObjectCollection;
foreach (var billRow in billRows)
{
DynamicObject notePrintEntryRow = new DynamicObject(e.DynamicObjectType);
// 为字段赋值:演示给物料编码赋值
DynamicObject materialObj = billRow["F_JD_FMaterialID"] as DynamicObject;
if (materialObj != null)
{
notePrintEntryRow["F_JD_FMaterialId_FName"] = materialObj["Name"].ToString();
}
notePrintEntryRows.Add(notePrintEntryRow);
}
e.DataObjects = notePrintEntryRows.ToArray();
}
}
}
}
以上是关于K3cloud 动态表单中,调用其它单据的套打模板的主要内容,如果未能解决你的问题,请参考以下文章