在销售退货单的保存操作上写了自动提交审核的服务插件(之前丁老师写的实例代码),测试的时候提交可以成功,走到审核服务操作的时候就卡死了,之后又把插件挂到其他单据测试可是实现自动提交审核,但在销售出库单,销售退货单这张单据上老是卡死,请大神们指点是什么问题?
代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using Kingdee.BOS;
using Kingdee.BOS.Util;
using Kingdee.BOS.Core;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Orm;
using Kingdee.BOS.Contracts;
using Kingdee.BOS.App;
namespace SH.K3.PM.BNKC01
{
[Description("保存时自动提交、审核")]
public class tjsh : AbstractOperationServicePlugIn
{
// 保存操作完毕,事务结束之前,进行自动提交、审核
public override void EndOperationTransaction(EndOperationTransactionArgs e)
{
// 取到需要自动提交、审核的单据内码
object[] pkArray = (from p in e.DataEntitys
select p[0]).ToArray();
// 设置提交参数:忽略操作过程中的警告,避免与用户交互
// using Kingdee.BOS.Orm;
OperateOption submitOption = OperateOption.Create();
submitOption.SetIgnoreWarning(true);
// 创建提交服务:using Kingdee.BOS.Contracts; using Kingdee.BOS.App;
ISubmitService submitService = ServiceHelper.GetService
IOperationResult submitResult = submitService.Submit(
this.Context, this.BusinessInfo,
pkArray, "Submit", submitOption);
// 判断提交结果,如果失败,则内部会抛出错误,回滚代码
if (CheckOpResult(submitResult) == false)
{
return;
}
// 构建操作可选参数对象:忽略交互性的警告提示
OperateOption auditOption = OperateOption.Create();
auditOption.SetIgnoreWarning(true);
// 构建单据主键参数
List
foreach (var pkValue in pkArray)
{
pkEntityIds.Add(new KeyValuePair
// 调用审核操作
ISetStatusService setStatusService = ServiceHelper.GetService
IOperationResult auditResult = setStatusService.SetBillStatus(this.Context,
this.BusinessInfo,
pkEntityIds,
null,
"Audit",
auditOption);
// 判断审核结果,如果失败,则内部会抛出错误,回滚代码
if (CheckOpResult(auditResult) == false)
{
return;
}
}
///
/// 子函数:判断操作结果是否成功,如果不成功,则直接抛错中断进程
///
///
///
private bool CheckOpResult(IOperationResult opResult)
{
bool isSuccess = false;
if (opResult.IsSuccess == true)
{
// 操作成功
isSuccess = true;
}
else
{
// 操作失败,拼接失败原因,然后抛出中断
opResult.MergeValidateErrors();
if (opResult.OperateResult == null)
{// 未知原因导致提交失败
throw new KDBusinessException("AutoOperate-001", "未知原因导致自动提交、审核失败!");
}
else
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("自动提交、审核失败,失败原因:");
foreach (var operateResult in opResult.OperateResult)
{
sb.AppendLine(operateResult.Message);
}
throw new KDBusinessException("AutoOperate-002", sb.ToString());
}
}
return isSuccess;
}
}
}
推荐阅读