在动态表单上新建套打,没有表体的时候能够正常预览打印,加了表体预览无数据
以下完整代码:
public static string BarCodePrint(IBillView View, string PrintType, string PrintTemplateID, string PrinterName, string SortField)
{
List
PrintJobItem printJobItem = new PrintJobItem();
string gudPrintJobID = string.Empty, PrintActionName = string.Empty, PrintTypeChsName = string.Empty;
JSONObject jobjPrintParams = null;
try
{
//唯一ID
gudPrintJobID = Guid.NewGuid().ToString();
//表单参数
printJobItem.BillId = "0";
printJobItem.FormId = View.BillBusinessInfo.GetForm().Id;
printJobItem.TemplateId = PrintTemplateID;
//缺省为空值
printJobItem.SortString = SortField;
lstPrintJobItem.Add(printJobItem);
//设置打印参数
jobjPrintParams = new JSONObject();
jobjPrintParams.Put("pageID", View.PageId);
jobjPrintParams.Put("printJobId", gudPrintJobID);
jobjPrintParams.Put("action", PrintType);//预览--"preview";打印--"print"
if (PrintType.ToUpper().Equals("preview".ToUpper()))
{
PrintActionName = "printPreview";
PrintTypeChsName = "打印预览";
jobjPrintParams.Put("printBarName", null);
}
else if (PrintType.ToUpper().Equals("print".ToUpper()))
{
PrintActionName = "print";
PrintTypeChsName = "打印";
if (!string.IsNullOrEmpty(PrinterName))
{
jobjPrintParams.Put("printerAddress", PrinterName);
}
}
//设置调用表单打印信息
View.Session[gudPrintJobID] = lstPrintJobItem;
//提交打印任务
View.AddAction(PrintActionName, jobjPrintParams);
//正常返回空字符串
return string.Empty;
}
catch (Exception ex)
{
throw new Exception(PrintTypeChsName + "失败.\r\n" + ex.Message);
}
}
public static void SetDynamicBillPrintData(PreparePrintDataEventArgs PrepareDataEvent, Context ctx, string PrintTemplateID,
DelegateSetBarCodePrintData SetDataMethod)
{
List
//获取元数据服务
IMetaDataService metadataService = Kingdee.BOS.App.ServiceHelper.GetService
FormMetadata fmdPrintData = null;
DynamicObject[] doPrintData = null;
try
{
fmdPrintData = metadataService.Load(ctx, PrintTemplateID, true) as FormMetadata;
DelegateSetBarCodePrintData xx = new DelegateSetBarCodePrintData(SetDataMethod);
doPrintData = xx.Invoke(ctx, fmdPrintData);
//设置数据信息
PrepareDataEvent.DynamicObjectType = fmdPrintData.BusinessInfo.GetDynamicObjectType();
//设置数据
PrepareDataEvent.DataObjects = doPrintData;
}
catch (Exception ex)
{
throw new Exception("打印加载数据失败.\r\n" + ex.Message);
}
}
public override void OnPrepareNotePrintData(Kingdee.BOS.Core.DynamicForm.PlugIn.Args.PreparePrintDataEventArgs e)
{
try
{
//
base.OnPrepareNotePrintData(e);
BarCodeUtils.SetDynamicBillPrintData(e, Context, "COZ_WALLASSMODEL", SetMeterialBarCodePrintData); //动态表单
}
catch (Exception ex)
{
this.View.ShowMessage(ex.Message);
}
}
private DynamicObject[] SetMeterialBarCodePrintData(Context ctx, FormMetadata metaData)
{
var barcodeobj = new DynamicObject(metaData.BusinessInfo.GetDynamicObjectType());
//表头
barcodeobj["FCONTRACTNUMBER"] = "2016-163-001";
barcodeobj["FPROJECTNAME"] = "央视密云拓展基地集装箱房项目";
barcodeobj["FPRODUCTNAME"] = "SMAC地盘总成1420AL";
barcodeobj["FMODEL"] = "直排(G)米黄竹编C12133";
barcodeobj["FBARCODE"] = "1201604080001";
//表体
Entity entity = metaData.BusinessInfo.GetEntity("FEntity");
DynamicObjectCollection rows = entity.DynamicProperty.GetValue(barcodeobj) as DynamicObjectCollection;
for (int rowIndex = 0; rowIndex < 6; rowIndex++)
{
DynamicObject row = new DynamicObject(entity.DynamicObjectType);
rows.Add(row);
row["FMaterialNumber"] = "1234455";
row["FMATERIALNAME"] = "直排(G)米";
row["FNumber"] = "3";
//rowIndex++;
}
return new DynamicObject[] { barcodeobj };
}
推荐阅读