本帖主要是简单讲解一下复杂套打(套打数据源来自多个单据或动态列头等)如何通过二开实现
如下图,以服装行业的动态列头套打为例来说明
1、绑定好数据表格的数据源,由于列头的颜色、尺码都是动态加载,因此先布好局,然后拖文本控件,设置文本的数据为“动态字段”
2、使用表单插件处理套打数据,根据DataSourceId对应的处理数据
public override void OnPrepareNotePrintData(PreparePrintDataEventArgs e)
{
if (e.DataObjects != null && e.DataObjects.Count() > 0)
{
switch (e.DataSourceId)
{
case "FBillHead":
e.DataObjects[0] = this.GetBillHeadObject(e);
break;
case "FTreeEntity":
e.DataObjects = this.GetDetailEntity(e);
break;
default:
break;
} }
base.OnPrepareNotePrintData(e);
}
/// <summary>
/// 获取单据头数据
/// </summary>
/// <param name="e">e</param>
/// <returns>单据头数据</returns>
private DynamicObject GetBillHeadObject(PreparePrintDataEventArgs e)
{
//将动态字段的字段标识注册到数据包中
string[] fieldArray = new string[] { "FParentMaterialNo","FParentMaterialName","FDesigner","FTechnician","FPatternMaker",
"FColor0", "FColor1", "FColor2", "FColor3", "FColor4",
"FSize0", "FSize1","FSize2", "FSize3", "FSize4","FSize5", "FSize6", "FSize7" };
DynamicObject dataObject = e.DataObjects.FirstOrDefault();
DynamicObjectType dot = dataObject.DynamicObjectType;
var propertyArray = dataObject.DynamicObjectType.Properties;
//注册动态字段
foreach (var filed in fieldArray)
{
if (propertyArray.Contains(filed))
continue;
dot.RegisterSimpleProperty(
filed,
typeof(object),
attributes: new SimplePropertyAttribute() { Alias = filed }
);
}
DynamicObject obj = new DynamicObject(dot);
foreach (var p in dataObject.DynamicObjectType.Properties)
{
obj[p] = dataObject[p];
}
//以下就是针对自身需求对数据包赋值,单据头数据只需对e.DataObjects的第一个对象做处理,单据体的话则都要处理
//参考代码
DynamicObject bomSetObj = CommonData.GetBomSettingData(this.Context, bomFid);
if (bomSetObj == null)
return obj;
string bomSetFid = bomSetObj["FID"].ToNullString();
obj["FParentMaterialNo"] = bomSetObj["FMATERIALNO"];
obj["FParentMaterialName"] = bomSetObj["FNAME"];
obj["FDesigner"] = bomSetObj["FDesigner"];
obj["FTechnician"] = bomSetObj["FTechnician"];
obj["FPatternMaker"] = bomSetObj["FPatternMaker"];
DynamicObjectCollection colorObjs = CommonData.GetParentColorData(this.Context, bomSetFid);
DynamicObjectCollection sizeObjs = CommonData.GetParentSizeData(this.Context, bomSetFid);
int count = colorObjs.Count > 5 ? 5 : colorObjs.Count;
for (int i = 0; i < count; i++)
{
string key = "FColor" + i.ToString();
obj[key] = colorObjs[i]["FNUMBER"].ToNullString() + Environment.NewLine + colorObjs[i]["FDATAVALUE"].ToNullString();
}
count = sizeObjs.Count > 8 ? 8 : sizeObjs.Count;
for (int i = 0; i < count; i++)
{
string key = "FSize" + i.ToString();
obj[key] = CommonTools.SplitSizeTitle(sizeObjs[i]["FDATAVALUE"].ToNullString());
}
return obj;
}
处理单据体数据的方法GetDetailEntity就不贴出,做法跟单据头一样,只是需要对e.DataObjects里的所有对象都做处理,甚至于把e.DataObjects的对象清除掉自定义添加自己想要的对象都可以。
效果图如下:
推荐阅读