套打.二开案例.动态表单套打
【场景】由于动态表单是由插件实现的绑定界面数据,并非按照字段的数据库映射逻辑取数,因此动态表单套打的逻辑也需要插件进行绑定处理
【案例】
自定义一个动态表单,根据单据头字段过滤,实现自定义查询逻辑在单据体中,并进行套打打印
a)设计动态表单,增加单据头字段,过滤,单据体字段,以及打印关联查询操作
![image.webp](/download/01001b524971205b4d568e661db7cffd7960.webp)
b)代码案例
GetData——获取表体的数据逻辑
OnPrepareNotePrintData——套打显示逻辑,将表体的数据填入套打模板
```csharp
using Kingdee.BOS;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Orm.DataEntity;
using System;
using System.Collections.Generic;
using System.Data;
namespace DynamicFormPlugIn.NotePrint
{
[Kingdee.BOS.Util.HotUpdate]
[System.ComponentModel.Description("动态表单套打逻辑")]
public class DynamicForm_NotePrint : AbstractDynamicFormPlugIn
{
public static string Head_Key = "FBillHead";
public static string Head_Date = "FDate";
public static string Entity_Key = "FEntity";
public static string Entity_BillNo = "FBillNo";
public static string Entity_Material = "FMATERIALNAME";
public static string Entity_Qty = "FQty";
private DataTable curShowTable;
public override void ButtonClick(ButtonClickEventArgs e)
{
if(string.Equals(e.Key, "FRefresh", StringComparison.OrdinalIgnoreCase))
{
curShowTable = GetData();
ShowInEntity(curShowTable);
}
}
/// <summary>
/// 实现取自定义逻辑
/// </summary>
/// <returns></returns>
private DataTable GetData()
{
var dateVal = this.View.Model.GetValue(Head_Date);
if (dateVal == null)
throw new Exception("日期为空");
DateTime date = Convert.ToDateTime(dateVal);
string strSelect = @"SELECT BILL.FBILLNO,WLL.FNAME AS FMATERIALNAME,ENTRY.FQTY FROM T_PUR_POORDER BILL
LEFT JOIN T_PUR_POORDERENTRY ENTRY ON BILL.FID = ENTRY.FID
LEFT JOIN T_BD_MATERIAL WL ON ENTRY.FMATERIALID = WL.FMATERIALID
LEFT JOIN T_BD_MATERIAL_L WLL ON WL.FMATERIALID = WLL.FMATERIALID AND WLL.FLOCALEID = 2052
WHERE BILL.FCREATEDATE >= @ST AND BILL.FCREATEDATE < @ET";
List<SqlParam> paramList = new List<SqlParam>();
paramList.Add(new SqlParam("@ST", KDDbType.DateTime, date.Date));
paramList.Add(new SqlParam("@ET", KDDbType.DateTime, date.Date.AddDays(1)));
var dataSet = DBUtils.ExecuteDataSet(this.Context, strSelect, paramList);
if (dataSet == null || dataSet.Tables.Count <= 0)
throw new Exception("查询异常");
return dataSet.Tables[0];
}
/// <summary>
/// 界面显示逻辑
/// </summary>
/// <param name="dt"></param>
private void ShowInEntity(DataTable dt)
{
var entity = this.View.BillBusinessInfo.GetEntity(Entity_Key);
var entityObjs = this.View.Model.GetEntityDataObject(entity);
entityObjs.Clear();
for (int i = 0; i < dt.Rows.Count; ++i)
{
var entityObj = new DynamicObject(entityObjs.DynamicCollectionItemPropertyType);
var dr = dt.Rows[i];
entityObj[Entity_BillNo] = dr[Entity_BillNo];
entityObj[Entity_Material] = dr[Entity_Material];
entityObj[Entity_Qty] = dr[Entity_Qty];
entityObjs.Add(entityObj);
}
this.View.UpdateView(entity.Key);
}
/// <summary>
/// 套打显示逻辑
/// </summary>
/// <param name="e"></param>
public override void OnPrepareNotePrintData(PreparePrintDataEventArgs e)
{
if (e.DataSourceId == Head_Key)
{ //单据头字段
var objType = e.DynamicObjectType;
var billObj = new DynamicObject(objType);
List<string> keyList = new List<string>() { Head_Date };
foreach (string key in keyList)
{
if (objType.Properties.ContainsKey(key))
{
billObj[key] = this.View.Model.GetValue(key);
}
}
e.DataObjects = new DynamicObject[] { billObj };
return;
}
if(e.DataSourceId == Entity_Key)
{
if (curShowTable == null)
return;
//表体字段,根据显示数据填入
var objType = e.DynamicObjectType;
List<string> keyList = new List<string>() { Entity_BillNo, Entity_Material, Entity_Qty };
List<DynamicObject> printDatas = new List<DynamicObject>();
for (int i = 0; i < curShowTable.Rows.Count; ++i)
{
var rowObj = new DynamicObject(objType);
var datatRow = curShowTable.Rows[i];
foreach (string key in keyList)
{
if (objType.Properties.ContainsKey(key))
{
rowObj[key] = datatRow[key];
}
}
printDatas.Add(rowObj);
}
e.DataObjects = printDatas.ToArray();
return;
}
}
}
}
```
【效果】动态表单实现套打
![Image_20230414161933.webp](/download/0100506dc604374445f39126e85f5325ddbe.webp)
动态表单套打的时候单据设置了为0不显示,但是套打的时候还是打印出0来了,这个怎么解决?
套打.二开案例.动态表单套打
【场景】由于动态表单是由插件实现的绑定界面数据,并非按照字段的数据库映射逻辑取数,因此动态表单套打的逻辑也需要插件进行绑定处理【案...
点击下载文档
本文2024-09-16 18:22:27发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-21717.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章