标签打印的开发过程
1. 功能
供应商送货单要根据物料的最小包装数量和送货数量,确定批次,每个批次一个数量,每个批次一个标签。
标签打印的模板来回切换很麻烦,所以在打印或预览的时候,不再选择模板。
1. 逻辑
因为单据有多个套打模板,每次需要来回切换,所以通过通过插件实现打印,插件里调用打印服务,插件里重新构造打印数据。
2. 步骤
套打模板设计好标签;
BOS设计器在列表和表单里添加上空按钮;
列表插件和表单插件监听按钮的点击事件;
点击事件调用金蝶的打印服务;
重写OnPrepareNotePrintData事件,重构打印数据;
1. 开发
标签设计:打开套打设计器,没用数据表格,只是用布局表格和对应的文本,文本里绑定的动态字段;
![1672305588692.webp](/download/01009c1d36ba193c4f7ca0deb89af6dcb0fe.webp)
添加按钮:。。。。
监听按钮的点击事件:
```C#
public override void BarItemClick(BarItemClickEventArgs e)
{
base.BarItemClick(e);
//if条件判断
if (e.BarItemKey.Equals("ZZY_LabelPreview"))
{
var formId = View.BusinessInfo.GetForm().Id;
var templateId = "cd0f5e24-8102-4530-9c4a-0160990d3c8";//供应商送货单
//这个方法获取当前表单所有的模板id,可以监听获取后,在代码里写死
//var templateIdDic= PrintServiceHelper.GetTemplatesByFormId(this.Context, View.BusinessInfo.GetForm().Id);
//获取FID
var fId = this.View.Model.DataObject["Id"].ToString();
//fId:打印单据id;templateId:套打模板id;formId:表单id,注意不能是扩展的表单,要是未扩展的表单id,上边有获取方法
var printJobs = Generateprintjobs(fId, templateId, formId); /生成打印job
var printJobKey=Guid.NewGuid().ToString();
this.View.Session[printJobKey] = printJobs;//任务放入session
NoteTemplateoperation(printJobKey,"Preview");
}
}
```
调用金蝶的打印服务:
这个是参考的大佬的帖子: [跳转过去,给他格赞](https://wenku.my7c.com/article/362702335958459648?productLineId=1&isKnowledge=2)
```C#
///<summary>生成打印任务</summary>
/// <param name="billId">单据内码</param>
/// <param name="templateId">套打模板标识</param>
/// <param name="formId”>业务对象标识</param>
private List<PrintJob> Generateprintjobs(string billid, string templateid, string formid) {
List<PrintJob> result = new List<PrintJob>();
PrintJob printJob = new PrintJob();
printJob.FormId = formid;
printJob.PrintJobItems = new List<PrintJobItem>();
printJob.PrintJobItems.Add(new PrintJobItem(billid, templateid));
result.Add(printJob);
return result;
}
///<summary>
/// 打模板的执行操作
/// </summary>
/// <param name="printJobId">打印任务ID</param>
/// <param name="printType">打的</param>
/// <param name="printer">打打的ID</param>
public void NoteTemplateoperation(string printJobid, string printType, object printer = null) {
JSONObject jsonobj = new JSONObject();
jsonobj.Put("pageID", this.View.PageId);
jsonobj.Put("printJobId", printJobid);
jsonobj.Put("action", printType);
string action = string.Empty;
if (printType == "Preview")
{
action = JSAction.printPreview;
}
else {
action = JSAction.print;
}
this.View.AddAction(action, jsonobj);
}
```
重写OnPrepareNotePrintData事件:
每个动态字段要注册一下;
```C#
public override void OnPrepareNotePrintData(PreparePrintDataEventArgs e)
{
var metaData = FormMetaDataCache.GetCachedFormMetaData(this.Context, this.View.BillBusinessInfo.GetForm().Id);
if (e.NotePrintTplId == "cd0f5e24-8102-4530-9c4a-0160990d3c58")
{
DynamicObject billObj = this.Model.DataObject;
DynamicObject SupplierIdField = billObj["SupplierId"] as DynamicObject;
DynamicObject ConfirmerIdField = billObj["ConfirmerId"] as DynamicObject;
//动态字段注册赋值
DynamicObjectType dot = e.DataObjects[0].DynamicObjectType;// metaData.BusinessInfo.GetDynamicObjectType();
#region 注册动态字段
if (!dot.Properties.ContainsKey("QRCode"))
{
dot.RegisterSimpleProperty( "QRCode", typeof(object) );
}
if (!dot.Properties.ContainsKey("GoodsCode"))
{
dot.RegisterSimpleProperty("GoodsCode", typeof(object));
}
if (!dot.Properties.ContainsKey("GoodsName"))
{
dot.RegisterSimpleProperty("GoodsName", typeof(object));
}
if (!dot.Properties.ContainsKey("GoodsStandard"))
{
dot.RegisterSimpleProperty("GoodsStandard", typeof(object));
}
if (!dot.Properties.ContainsKey("SupplyName"))
{
dot.RegisterSimpleProperty("SupplyName", typeof(object));
}
if (!dot.Properties.ContainsKey("BanShu"))
{
dot.RegisterSimpleProperty("BanShu", typeof(object));
}
if (!dot.Properties.ContainsKey("SaleOrderCode"))
{
dot.RegisterSimpleProperty("SaleOrderCode", typeof(object));
}
if (!dot.Properties.ContainsKey("PurOrderCode"))
{
dot.RegisterSimpleProperty("PurOrderCode", typeof(object));
}
if (!dot.Properties.ContainsKey("Qty"))
{
dot.RegisterSimpleProperty("Qty", typeof(object));
}
if (!dot.Properties.ContainsKey("ProductDate"))
{
dot.RegisterSimpleProperty("ProductDate", typeof(object));
}
if (!dot.Properties.ContainsKey("ConfirmDate"))
{
dot.RegisterSimpleProperty("ConfirmDate", typeof(object));
}
if (!dot.Properties.ContainsKey("ConfirmUser"))
{
dot.RegisterSimpleProperty("ConfirmUser", typeof(object));
}
if (!dot.Properties.ContainsKey("ConfirmStatus"))
{
dot.RegisterSimpleProperty("ConfirmStatus", typeof(object));
}
if (!dot.Properties.ContainsKey("BillNo"))
{
dot.RegisterSimpleProperty("BillNo", typeof(object));
}
if (!dot.Properties.ContainsKey("BatchNo"))
{
dot.RegisterSimpleProperty("BatchNo", typeof(object));
}
#endregion
List<DynamicObject> allDataObjects = new List <DynamicObject>();
//获取单据体【明细信息】的数据
EntryEntity fentity = this.View.BusinessInfo.GetEntryEntity("FDetailEntity");
DynamicObjectCollection dataObjs2 = this.Model.GetEntityDataObject(fentity);
//子单据体【看板批次码】的对象
SubEntryEntity FBatchSubEntity = this.View.BusinessInfo.GetEntryEntity("F_ZZY_SubEntity") as SubEntryEntity;
for (int i = 0; i < dataObjs2.Count; i++)
{
var entryRow = dataObjs2[i];
var meterialObj = entryRow["MaterialID"] as DynamicObject;
//当前单据体下子单据体【看板批次码】的行集合
DynamicObjectCollection batchEntryRows = FBatchSubEntity.DynamicProperty.GetValue(entryRow) as DynamicObjectCollection;
foreach (var row in batchEntryRows)
{
DynamicObject printObj = new DynamicObject(dot);
//动态字段赋值
printObj["BillNo"] = billObj["BillNo"].ToString();
printObj["ProductDate"] = Convert.ToDateTime(billObj["Date"]).ToString("yyyy-MM-dd");
printObj["ConfirmDate"] = billObj["ConfirmDate"];
printObj["ConfirmUser"] = ConfirmerIdField == null ? "" : ConfirmerIdField["Name"].ToString();
printObj["ConfirmStatus"] = billObj["ConfirmStatus"];
printObj["SupplyName"] = SupplierIdField["Name"].ToString();
printObj["GoodsCode"] = meterialObj["Number"].ToString();
printObj["GoodsName"] = meterialObj["Name"].ToString();
printObj["GoodsStandard"] = meterialObj["Specification"].ToString();
printObj["SaleOrderCode"] = entryRow["OrderBillNo"] == null ? "" : entryRow["OrderBillNo"].ToString();
printObj["PurOrderCode"] = entryRow["SrcBillNo"] == null ? "" : entryRow["SrcBillNo"].ToString();
printObj["BatchNo"] = entryRow["Lot_Text"] == null ? "" : entryRow["Lot_Text"].ToString();
printObj["BanShu"]= String.Format("{0:f2}", row["BatchQty"]) + "/"+ String.Format("{0:f2}", entryRow["ActReceiveQty"]);
printObj["Qty"] = String.Format("{0:f2}", row["BatchQty"]);
printObj["QRCode"] = printObj["GoodsCode"].ToString()+"|"+
printObj["GoodsName"].ToString() + "|"+
(printObj["GoodsStandard"] == null ? "" : printObj["GoodsStandard"].ToString()) + "|" +
printObj["SupplyName"].ToString() + "|" +
printObj["BanShu"].ToString() + "|" +
(printObj["SaleOrderCode"] == null ? "" : printObj["SaleOrderCode"].ToString()) + "|" +
(printObj["PurOrderCode"] == null ? "" : printObj["PurOrderCode"].ToString()) + "|" +
printObj["Qty"].ToString() + "|" +
printObj["ProductDate"].ToString() + "|" +
(printObj["SaleOrderCode"] == null ? "" : printObj["SaleOrderCode"].ToString()) + "|" +
(printObj["ConfirmDate"] == null ? "" : printObj["ConfirmDate"].ToString()) + "|" +
(printObj["ConfirmUser"] == null ? "" : printObj["ConfirmUser"].ToString()) + "|" +
(printObj["ConfirmStatus"] == null ? "" : printObj["ConfirmStatus"].ToString()) + "|" +
(printObj["BatchNo"] == null ? "" : printObj["BatchNo"].ToString()) + "|" +
printObj["BillNo"].ToString();
allDataObjects.Add(printObj);
}
}
e.DataObjects = allDataObjects.ToArray();
}
base.OnPrepareNotePrintData(e);
}
```
最后效果:
![1672306346511.webp](/download/0100b4ed369d763a4ff8936fca62f1bc12fc.webp)
标签打印的开发过程
1. 功能供应商送货单要根据物料的最小包装数量和送货数量,确定批次,每个批次一个数量,每个批次一个标签。标签打印的模板来回切换很麻烦...
点击下载文档
本文2024-09-16 17:42:13发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-17416.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章