二开案例.服务插件.创建单据时不记录修改人
【应用场景】
单据在新增保存时,系统默认会将最后修改人和最后修改日期字段赋值为等于单据的当前创建人和创建日期字段的值。
某些特殊场景下,可能希望在新增保存单据时,不要记录修改人信息。受限于平台设计,目前想实现不记录修改人信息还挺麻烦的。
【案例演示】
采购订单,新增保存时,不记录修改人和修改日期。
【实现步骤】
编写服务插件,代码如下。
using Kingdee.BOS;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.Metadata.FieldElement;
using Kingdee.BOS.JSON;
using Kingdee.BOS.Util;
using System.Collections.Generic;
using System.ComponentModel;
//using System.Linq;
namespace Jac.XkDemo.BOS.App.PlugIn
{
///
/// 【服务插件】创建单据时不记录修改人
///
[Description(“【服务插件】创建单据时不记录修改人”), HotUpdate]
public class ResetModifyerAfterSaveOperationServicePlugIn : AbstractOperationServicePlugIn
{
///
/// 修改人字段标识
///
const string ModifierIdFieldKey = “FModifierId”;
///
/// 修改时间字段标识
///
const string ModifyDateFieldKey = “FModifyDate”;
public override void OnPrepareOperationServiceOption(OnPrepareOperationServiceEventArgs e)
{
base.OnPrepareOperationServiceOption(e);
if (!string.IsNullOrWhiteSpace(this.FormOperation.LoadKeys) && this.FormOperation.LoadKeys != “null”)
{
// 设置操作完后刷新修改人字段
var loadKeys = KDObjectConverter.DeserializeObject(this.FormOperation.LoadKeys);
if (loadKeys == null)
{
loadKeys = new List();
}
if (!loadKeys.Contains(ModifierIdFieldKey))
{
loadKeys.Add(ModifierIdFieldKey);
}
if (!loadKeys.Contains(ModifyDateFieldKey))
{
loadKeys.Add(ModifyDateFieldKey);
}
this.FormOperation.LoadKeys = KDObjectConverter.SerializeObject(loadKeys);
}
}
public override void EndOperationTransaction(EndOperationTransactionArgs e)
{
base.EndOperationTransaction(e);
if (this.FormOperation.OperationId == 8)
{
var needSaveIds = new List();
foreach (var dataEntity in e.DataEntitys)
{
if (!dataEntity.DataEntityState.FromDatabase)
{
// 清除单据在内存数据包中的修改人数据
dataEntity[“ModifierId_Id”] = null;
dataEntity[“ModifierId”] = null;
dataEntity[“ModifyDate”] = null;
needSaveIds.Add(dataEntity[0]);
}
}
if (needSaveIds.Count > 0)
{
ResetModifyer(Context, this.BusinessInfo, needSaveIds);
}
}
}
///
/// 清除单据的修改人
///
///
///
///
private void ResetModifyer(Context ctx, BusinessInfo businessInfo, List ids)
{
//var modifyerField = businessInfo.Entrys[0].Fields.FirstOrDefault(o => o is ModifyerField) as ModifyerField;
//var modifyDateField = businessInfo.Entrys[0].Fields.FirstOrDefault(o => o is ModifyDateField) as ModifyDateField;
var modifyerField = businessInfo.GetField(ModifierIdFieldKey) as ModifyerField;
var modifyDateField = businessInfo.GetField(ModifyDateFieldKey) as ModifyDateField;
if (modifyerField == null || modifyDateField == null)
{
return;
}
var sql = string.Format(“UPDATE {0} SET {1}=0,{2}=NULL WHERE {3} IN ({4})”
, modifyerField.Entity.TableName
, modifyerField.FieldName
, modifyDateField.FieldName
, modifyerField.Entity.EntryPkFieldName
, string.Join(“,”, ids));
DBUtils.Execute(ctx, sql);
}
}
}
拷贝插件组件到应用站点的WebSite\Bin目录下,重启IIS。
BOSIDE扩展采购订单,保存操作上注册服务插件,保存元数据,开发完毕。
【功能验证】
登录业务站点,打开采购订单新增界面,保存单据,此时不再记录修改人信息。
———————————————————————————————————
【金蝶云星空BOS二次开发案例演示】https://vip.kingdee.com/article/94751030918525696
【C#】【服务插件】创建单据时不记录修改人.rar(1.40KB)