套打.二开案例.自实现合并套打全部分录
<0>场景
销售出库单打印,其中物料类型很多,不适合针对每一个物料建一个套打模板(在模板上设置过滤),同时数据量较大(列表一样显示不全);客户想要合并套打所有同一个物料的分录数据。
<1>现状
套打目前不支持合并套打全部分录操作。
<2>方案一:通过报表实现
基本很少会有按列表全部数据操作(按分录)的述求,列表本身就是分页取数的,如果需要对全部数据,可以通过报表实现;该方案需要二开报表并在报表上做一个套打模板即可;
账表开发教程https://vip.kingdee.com/school/61521382768880384
缺点,套打模板不共享,部分单据特性无法在报表套打上使用。
<3>方案二:二开操作实现
所有数据依照列表的呈现实现,列表过滤中设置了过滤方案为分录字段,那么列表则显示满足条件的分录。
增加一个列表套打操作,模拟合并套打全部单据和合并套打所选分录的逻辑。
代码:
增加表单操作项:
修改对应sql的fid(操作内码),foperation(操作标识),fserviceclass(操作服务运行时);并预插多语言操作脚本
select * from T_MDL_FORMOPERATIONTYPE where FOPERATION = 'MergeAllEntityPrint'
insert into T_MDL_FORMOPERATIONTYPE(FID,FOPERATION,FISCONFIRM,FRESOURCE,FENABLEDSTATE,FOPERELEIDS,FSERVICECLASS,FDESIGNERCLASS,
FTOPCLASSIDS,FISSUPPORTWF,FSERVICEINVOKECLASS,FSERVICECLASSEXT,FWEBSERVICECLASS,FWEBDESIGNERCLASS,FAPPSCENARIOTYPE)
select 99999999,'MergeAllEntityPrint', FISCONFIRM,FRESOURCE,FENABLEDSTATE,FOPERELEIDS,'NotePrintPlugin.Sample.MergeAllEntityPrint,NotePrintPlugin.Sample',op.FDESIGNERCLASS,
FTOPCLASSIDS,FISSUPPORTWF,FSERVICEINVOKECLASS,FSERVICECLASSEXT,FWEBSERVICECLASS,FWEBDESIGNERCLASS,FAPPSCENARIOTYPE from T_MDL_FORMOPERATIONTYPE op where FOPERATION = 'PrintMergeAll'
insert into T_MDL_FORMOPERATIONTYPE_l(FPKID,FID,FLOCALEID,FNAME) values
((SELECT ISNULL(MAX(FPKID), 0) + 1 FROM T_MDL_FORMOPERATIONTYPE_l WHERE FPKID < 100000),99999999,2052,'自定义合并套打全部分录');
单据界面配置:
增加菜单项和关联对应操作项
<4>效果
<5>附录——代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Kingdee.BOS.Business.Bill.Operation;
using Kingdee.BOS.Core.CommonFilter;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.List;
using Kingdee.BOS.Core.NotePrint;
using Kingdee.BOS.Model.List;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
namespace NotePrintPlugin.Sample
{
public class MergeAllEntityPrint : AbstractPrintOperation
{
/// <summary>
/// 是否选中行
/// </summary>
private bool IsSelectEntryId = true;
/// <summary>
/// 是否预览
/// </summary>
private bool IsPreview = true;
private int rowCnt;
private Dictionary<string, List<string>> AllPageEntryPKData;
public override IFormOperation GetNewInstance()
{
return new MergeAllEntityPrint();
}
protected override bool DoAuthPermission(IOperationResult result)
{
return this.ValidateListData(false);
}
protected override IOperationResult ExecuteOperation()
{
if (!(this.View is IListView))
return null;
if (!(this.View.Model is IListModel))
return null;
//合并套打只进行套打操作,不判断是否启用套打选项
ExecuteAllRowPrint();
return null;
}
/// <summary>
/// 执行所有行套打
/// </summary>
private void ExecuteAllRowPrint()
{
IListModelService modelService = this.ListView.Model as IListModelService;
if (modelService == null)
return;
rowCnt = modelService.GetRowCount(modelService.TableName);
if (rowCnt <= 0)
{
string errMsg = IsPreview ? Kingdee.BOS.Resource.ResManager.LoadKDString("没有可以预览的数据。", "002012030003448", Kingdee.BOS.Resource.SubSystemType.BOS) :
Kingdee.BOS.Resource.ResManager.LoadKDString("没有可以打印的数据。", "002012030003433", Kingdee.BOS.Resource.SubSystemType.BOS);
this.View.ShowErrMessage(errMsg);
return;
}
List<string> pkIds = GetAllAllowPKs();
if (pkIds.Count == 0)
{
string errMsg = IsPreview ? Kingdee.BOS.Resource.ResManager.LoadKDString("没有可以预览的数据,请您确认拥有该数据的打印权限。", "002012030003451", Kingdee.BOS.Resource.SubSystemType.BOS) :
Kingdee.BOS.Resource.ResManager.LoadKDString("没有可以打印的数据,请您确认拥有该数据的打印权限。", "002012030003436", Kingdee.BOS.Resource.SubSystemType.BOS);
this.View.ShowErrMessage(errMsg);
return;
}
DoAction(pkIds.ToArray());
}
private string GetOpType()
{
return IsPreview ? "PrintMergePreview" : "PrintMerge";
}
/// <summary>
/// 套打操作执行
/// </summary>
/// <param name="billIds">操作内码</param>
private void DoAction(string[] billIds)
{
if (GetSelectTemplateParm())
{
DoInteractiveAction(billIds, GetOpType(), IsSelectEntryId);
}
else if (IsAdvancedSetting)
{
DoAdvancedAction(billIds, GetOpType(), IsSelectEntryId);
}
else
{
DoNormalAction(billIds, GetOpType(), IsSelectEntryId);
}
}
protected override void SetSelectEntry(PrintJobItem printJobItem)
{
//修正选中分录逻辑
if (AllPageEntryPKData == null)
{
InitAllPageData();
}
string billId = printJobItem.BillId;
if (AllPageEntryPKData != null && AllPageEntryPKData.ContainsKey(billId))
{
printJobItem.SelectedEtyIds = AllPageEntryPKData[billId];
}
}
private void InitAllPageData()
{
AllPageEntryPKData = new Dictionary<string, List<string>>();
List<FilterEntity> selectEntitnes = this.ListView.Model.FilterParameter.SelectedEntities;
var selectEntryEntity =
selectEntitnes.FirstOrDefault(
x => x.EntityType == Kingdee.BOS.Core.Enums.BOSEnums.Enum_EntityType.Entity);
if (selectEntryEntity == null)
return;
ListModel listModel = this.ListView.Model as ListModel;
if (listModel == null)
return;
string pkFieldName = this.ListView.BillBusinessInfo.GetForm().PkFieldName;
string entryPkFieldName = listModel.PKEntryFieldName;
//实现所有页数据的获取,并构建主键和分录主键
DynamicObjectCollection allPageData = this.ListView.Model.GetData(0, rowCnt, false);
foreach (var rowData in allPageData)
{
string pkVal = ObjectUtils.Object2String(rowData[pkFieldName]);
string entryPkVal = ObjectUtils.Object2String(rowData[entryPkFieldName]);
if (!AllPageEntryPKData.ContainsKey(pkVal))
{
AllPageEntryPKData.Add(pkVal, new List<string>());
}
AllPageEntryPKData[pkVal].Add(entryPkVal);
}
}
}
}
套打.二开案例.自实现合并套打全部分录
本文2024-09-23 04:12:44发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-163846.html