套打.二开案例.自定义套打导出次数
【场景】自定义套打导出次数
【案例仿照】[套打.二开案例.自定义记录打印次数](https://wenku.my7c.com/article/378549008505683712?productLineId=1)
【案例】采购合同,列表和单据,记录导出次数
<0>对象、单据、模板打印次数表
```sql
--ksql
/****** 对象、单据、模板打印次数记录表 ******/
/****** 表结构 ******/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_Test_NotePrintRecord')
CREATE TABLE T_Test_NotePrintRecord
(
FID VARCHAR(36) DEFAULT ' ' NOT NULL,
FOBJECTID VARCHAR(50) DEFAULT ' ' NOT NULL,
FINTERID VARCHAR(50) DEFAULT ' ' NOT NULL,
FTEMPTELAEID NVARCHAR(50) DEFAULT ' ' NOT NULL,
FCOUNT INT DEFAULT 0 NOT NULL
);
/****** 索引 ******/
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_Test_NotePrintRecord')
CREATE INDEX IDX_Test_NotePrintRecord ON T_Test_NotePrintRecord ( FOBJECTID, FINTERID, FTEMPTELAEID);
/****** 主键 ******/
IF EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_Test_NotePrintRecord')
EXEC p_AlterPK 'PK_Test_NotePrintRecord', 'T_Test_NotePrintRecord', 'FID', '1';
/****** 锁记录 ******/
INSERT T_Test_NotePrintRecord(FID) Values('LOCK')
```
<1>表单插件、列表插件
![Image_20230301143256.webp](/download/0100376b26fb56da4b7d98081e8a225dbbbf.webp)
```csharp
using Kingdee.BOS;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.List.PlugIn;
using Kingdee.BOS.Core.Metadata;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Transactions;
namespace DynamicFormPlugIn.NotePrint
{
public class NoteExportRecordHandler
{
private readonly AbstractDynamicFormPlugIn PlugIn;
public NoteExportRecordHandler(AbstractDynamicFormPlugIn plugIn)
{
PlugIn = plugIn;
}
private bool IsExportOp;
public void SetIsExportOp(bool isExportOp)
{
IsExportOp = isExportOp;
}
public void Execute(BeforePrintExportEventArgs e)
{
//<0> 仅针对套打导出操作,因为发送邮件的套打附件和工作流的套打附件,均不是以操作的实现调用
if (!IsExportOp)
return;
if(e.ExportInfo == null)
{
return;
}
//<1>获取本次操作 模板和单据的导出次数
var templateBillCntMap = GetPrintBillSet(e, PlugIn.View.BillBusinessInfo);
if (!UpdatePrintCount(templateBillCntMap))
{
//取消操作的逻辑,将导出任务清空
PlugIn.View.ShowMessage("更新失败");
e.ExportInfo = null;
}
//<2>如果需要控制次数,可针对不满足的取消打印
//取消操作的逻辑,将导出任务清空
//PlugIn.View.ShowMessage("超出控制次数");
//e.ExportInfo = null;
}
/// <summary>
/// 获取 模板、单据内码的打印次数
/// </summary>
/// <param name="e"></param>
/// <param name="billBusinessInfo"></param>
/// <returns></returns>
private static Dictionary<string, Dictionary<string, int>> GetPrintBillSet(BeforePrintExportEventArgs e, BusinessInfo billBusinessInfo)
{
string curFormId = billBusinessInfo.GetForm().Id;
Dictionary<string, Dictionary<string, int>> templateBillCntMap = new Dictionary<string, Dictionary<string, int>>();
if(e.ExportInfo.ExportItems != null && e.ExportInfo.ExportItems.Count >0)
{
//套打高级设置
foreach (var pExportInfo in e.ExportInfo.ExportItems)
{
if (pExportInfo == null || pExportInfo.BillIds == null)
continue;
foreach (var billId in pExportInfo.BillIds)
{
if (billId == null)
continue;
//任务中包含单据内码和模板ID,这里只需要记录单据内码
if (!templateBillCntMap.ContainsKey(pExportInfo.TemplateId))
{
templateBillCntMap[pExportInfo.TemplateId] = new Dictionary<string, int>();
}
if (!templateBillCntMap[pExportInfo.TemplateId].ContainsKey(billId))
{
templateBillCntMap[pExportInfo.TemplateId][billId] = 1;
}
else
{
templateBillCntMap[pExportInfo.TemplateId][billId] += 1;
}
}
}
return templateBillCntMap;
}
if (e.ExportInfo.BillIds != null)
{
if(e.ExportInfo.OperationType == Kingdee.BOS.Core.NotePrint.PrintOperationType.SelectTempate)
{
//套打选择模板配对
for (int i = 0; i < e.ExportInfo.BillIds.Count; ++i)
{
string billId = e.ExportInfo.BillIds[i];
for (int j = 0; j < e.ExportInfo.TemplateIds.Count; ++j)
{
string templateId = e.ExportInfo.TemplateIds.Count > i ? e.ExportInfo.TemplateIds[j] : null;
if (billId == null || templateId == null)
continue;
//任务中包含单据内码和模板ID,这里只需要记录单据内码
if (!templateBillCntMap.ContainsKey(templateId))
{
templateBillCntMap[templateId] = new Dictionary<string, int>();
}
if (!templateBillCntMap[templateId].ContainsKey(billId))
{
templateBillCntMap[templateId][billId] = 1;
}
else
{
templateBillCntMap[templateId][billId] += 1;
}
}
}
}
else
{
//套打普通映射
for (int i = 0; i < e.ExportInfo.BillIds.Count; ++i)
{
string billId = e.ExportInfo.BillIds[i];
string templateId = e.ExportInfo.TemplateIds.Count > i ? e.ExportInfo.TemplateIds[i] : null;
if (billId == null || templateId == null)
continue;
//任务中包含单据内码和模板ID,这里只需要记录单据内码
if (!templateBillCntMap.ContainsKey(templateId))
{
templateBillCntMap[templateId] = new Dictionary<string, int>();
}
if (!templateBillCntMap[templateId].ContainsKey(billId))
{
templateBillCntMap[templateId][billId] = 1;
}
else
{
templateBillCntMap[templateId][billId] += 1;
}
}
}
}
return templateBillCntMap;
}
/// <summary>
/// 更新模板打印次数
/// </summary>
/// <param name="templateBillCntMap"></param>
/// <returns></returns>
private bool UpdatePrintCount(Dictionary<string, Dictionary<string, int>> templateBillCntMap)
{
string curFormId = this.PlugIn.View.BillBusinessInfo.GetForm().Id;
string strLock = "UPDATE T_Test_NotePrintRecord SET FCOUNT = -1 WHERE FID = 'LOCK'";
string insertOrUpdateSql = @"IF NOT EXISTS (SELECT 1 FROM T_Test_NotePrintRecord WHERE FOBJECTID = @FOBJECTID AND FINTERID = @FINTERID AND FTEMPTELAEID = @FTEMPTELAEID)
INSERT INTO T_Test_NotePrintRecord(FID, FOBJECTID, FINTERID, FTEMPTELAEID, FCOUNT)
VALUES(NEWID(), @FOBJECTID, @FINTERID, @FTEMPTELAEID, @FCOUNT)
ELSE
UPDATE T_Test_NotePrintRecord SET FCOUNT = FCOUNT + @FCOUNT
WHERE FOBJECTID = @FOBJECTID AND FINTERID = @FINTERID AND FTEMPTELAEID = @FTEMPTELAEID";
List<SqlObject> sqlObjects = new List<SqlObject>();
foreach (var templateItem in templateBillCntMap)
{
string templateId = templateItem.Key;
foreach (var billItem in templateItem.Value)
{
string billId = billItem.Key;
int count = billItem.Value;
List<SqlParam> paramList = new List<SqlParam>();
paramList.Add(new SqlParam("@FOBJECTID", KDDbType.AnsiString, curFormId));
paramList.Add(new SqlParam("@FINTERID", KDDbType.AnsiString, billId));
paramList.Add(new SqlParam("@FTEMPTELAEID", KDDbType.AnsiString, templateId));
paramList.Add(new SqlParam("@FCOUNT", KDDbType.Int32, count));
sqlObjects.Add(new SqlObject(insertOrUpdateSql, paramList));
}
}
using (KDTransactionScope scope = new KDTransactionScope(TransactionScopeOption.RequiresNew))
{
DBUtils.Execute(PlugIn.Context, strLock);
DBUtils.ExecuteBatch(PlugIn.Context, sqlObjects);
scope.Complete();
}
return true;
}
}
[Kingdee.BOS.Util.HotUpdate]
[System.ComponentModel.Description("表单插件")]
public class NoteExportBillPlugIn : AbstractBillPlugIn
{
private NoteExportRecordHandler handler;
public override void BeforeDoOperation(BeforeDoOperationEventArgs e)
{
base.BeforeDoOperation(e);
bool isExportOp = e.Operation.FormOperation != null && string.Equals(e.Operation.FormOperation.Operation, "PrintExport");
if (handler == null)
{
handler = new NoteExportRecordHandler(this);
}
handler.SetIsExportOp(isExportOp);
}
public override void BeforePrintExport(BeforePrintExportEventArgs e)
{
if (handler == null)
{
handler = new NoteExportRecordHandler(this);
}
handler.Execute(e);
}
}
[Kingdee.BOS.Util.HotUpdate]
[System.ComponentModel.Description("列表插件")]
public class NoteExportListPlugIn : AbstractListPlugIn
{
private NoteExportRecordHandler handler;
public override void BeforeDoOperation(BeforeDoOperationEventArgs e)
{
base.BeforeDoOperation(e);
bool isExportOp = e.Operation.FormOperation != null && string.Equals(e.Operation.FormOperation.Operation, "PrintExport");
if (handler == null)
{
handler = new NoteExportRecordHandler(this);
}
handler.SetIsExportOp(isExportOp);
}
public override void BeforePrintExport(BeforePrintExportEventArgs e)
{
if (handler == null)
{
handler = new NoteExportRecordHandler(this);
}
handler.Execute(e);
}
}
}
```
【效果】导出时记录次数
![Image_20230301143556.webp](/download/0100e4cd9ed44fad4c04a123bd86e3d888f3.webp)
套打.二开案例.自定义套打导出次数
【场景】自定义套打导出次数【案例仿照】[套打.二开案例.自定义记录打印次数](https://wenku.my7c.com/article/378549008505683712?product...
点击下载文档
本文2024-09-16 18:32:15发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-22789.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章