套打.二开案例.汇总翻倍和自定义合并汇总
【场景】汇总翻倍和自定义合并汇总
【案例】检验单 合并套打
![image.webp](/download/0100ffacf8be06244e7c89cdc47bfd3aeeb4.webp)
![image.webp](/download/0100219c760060464de1abe21a192ea9c37d.webp)
```csharp
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.List.PlugIn;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DynamicFormPlugIn.NotePrint
{
[Kingdee.BOS.Util.HotUpdate]
[System.ComponentModel.Description("列表插件")]
public class NotePrintListPlugIn_MergeData : AbstractListPlugIn
{
public override void OnPrepareNotePrintData(PreparePrintDataEventArgs e)
{
new MergeHandler().Execute(e);
new SumHandler().Execute(e);
}
}
[Kingdee.BOS.Util.HotUpdate]
[System.ComponentModel.Description("表单插件")]
public class NotePrintBillPlugIn_MergeData : AbstractBillPlugIn
{
public override void OnPrepareNotePrintData(PreparePrintDataEventArgs e)
{
new MergeHandler().Execute(e);
new SumHandler().Execute(e);
}
}
public class CaleHandler
{
/// <summary>
/// 处理的单据体标识
/// </summary>
public readonly string EntityKey = "FEntity";
/// <summary>
/// 行标识
/// </summary>
public readonly string IdentityKey = "FEntryID";
public readonly string TemplateId = "0adbc4f0-bc05-4aa8-abad-42a6fa8b0642";
public CaleHandler()
{
}
public CaleHandler CheckPropoerty(Kingdee.BOS.Orm.DataEntity.DynamicObject dataObj, string prop)
{
if (!dataObj.DynamicObjectType.Properties.ContainsKey(prop))
throw new Exception("数据包不存在对应字段,检查是否有配置动态字段或者引用字段:" + prop);
return this;
}
public void Execute(PreparePrintDataEventArgs e)
{
if (ExecuteCheck(e))
{
ExecuteInner(e);
}
}
protected virtual bool ExecuteCheck(PreparePrintDataEventArgs e)
{
if (!string.Equals(e.DataSourceId, EntityKey, StringComparison.OrdinalIgnoreCase))
return false;
if (e.DataObjects == null || e.DataObjects.Length <= 0)
return false;
if (TemplateId != string.Empty && !string.Equals(e.NotePrintTplId, TemplateId, StringComparison.OrdinalIgnoreCase))
return false;
CheckPropoerty(e.DataObjects[0], IdentityKey);
return true;
}
protected virtual void ExecuteInner(PreparePrintDataEventArgs e) { }
}
public sealed class MergeHandler : CaleHandler
{
/// <summary>
/// 分组字段标识
/// </summary>
public readonly string GroupKey = "F_BHR_Text_qtr";
/// <summary>
/// 数量字段标识
/// </summary>
public readonly string QtyKey = "FInspectQty";
/// <summary>
/// 填充字段标识
/// </summary>
public readonly string CalcKey = "CustomField_Merge";
private HashSet<string> handleRows = new HashSet<string>();
private Dictionary<string, decimal> groupQty = new Dictionary<string, decimal>();
public MergeHandler()
{
}
protected override bool ExecuteCheck(PreparePrintDataEventArgs e)
{
var check = base.ExecuteCheck(e);
if (!check)
return check;
var rowObj = e.DataObjects[0];
CheckPropoerty(rowObj, GroupKey).CheckPropoerty(rowObj, QtyKey).CheckPropoerty(rowObj, CalcKey);
return true;
}
protected override void ExecuteInner(PreparePrintDataEventArgs e)
{
for (int i = 0; i < e.DataObjects.Length; ++i)
{
var rowObj = e.DataObjects[i];
//计算过的行不处理
string identityId = Convert.ToString(rowObj[IdentityKey]);
if (handleRows.Contains(identityId))
continue;
handleRows.Add(identityId);
string groupVal = Convert.ToString(rowObj[GroupKey]);
decimal qtyVal = Convert.ToDecimal(rowObj[QtyKey]);
if (!groupQty.ContainsKey(groupVal))
{
groupQty[groupVal] = 0;
}
groupQty[groupVal] += qtyVal;
}
StringBuilder msgBuilder = new StringBuilder();
foreach(var item in groupQty)
{
msgBuilder.AppendFormat("{0}:{1}\r\n", item.Key, item.Value.ToString("0.##########"));
}
for (int i = 0; i < e.DataObjects.Length; ++i)
{
var rowObj = e.DataObjects[i];
rowObj[CalcKey] = msgBuilder.ToString();
}
}
}
public sealed class SumHandler : CaleHandler
{
/// <summary>
/// 数量字段标识
/// </summary>
public readonly string QtyKey = "FInspectQty";
/// <summary>
/// 填充字段标识
/// </summary>
public readonly string CalcKey = "CustomField_Sum";
private HashSet<string> handleRows = new HashSet<string>();
private decimal QtySum;
public SumHandler()
{
}
protected override bool ExecuteCheck(PreparePrintDataEventArgs e)
{
var check = base.ExecuteCheck(e);
if (!check)
return check;
var rowObj = e.DataObjects[0];
CheckPropoerty(rowObj, QtyKey).CheckPropoerty(rowObj, CalcKey);
return true;
}
protected override void ExecuteInner(PreparePrintDataEventArgs e)
{
for (int i = 0; i < e.DataObjects.Length; ++i)
{
var rowObj = e.DataObjects[i];
//计算过的行不处理
string identityId = Convert.ToString(rowObj[IdentityKey]);
if (handleRows.Contains(identityId))
continue;
handleRows.Add(identityId);
decimal qtyVal = Convert.ToDecimal(rowObj[QtyKey]);
QtySum += qtyVal;
}
for (int i = 0; i < e.DataObjects.Length; ++i)
{
var rowObj = e.DataObjects[i];
rowObj[CalcKey] = QtySum;
}
}
}
}
```
【效果】
![image.webp](/download/0100f2e980da841946cb925cca3f7bc71a06.webp)
套打.二开案例.汇总翻倍和自定义合并汇总
【场景】汇总翻倍和自定义合并汇总【案例】检验单 合并套打 ![image.webp](/download/0100ffacf8be06244e7c89cdc47bfd3aeeb4.webp)![imag...
点击下载文档
本文2024-09-16 18:14:01发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-20811.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章