引出时更新字段值并控制引出数据原创
3人赞赏了该文章
1,033次浏览
编辑于2021年06月19日 15:57:27
注册列表插件:
列表插件代码:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.ComponentModel; using Kingdee.BOS.Contracts; using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; using Kingdee.BOS.Core.List.PlugIn; using Kingdee.BOS.ServiceHelper; using Kingdee.BOS.App.Data; using Kingdee.BOS.Util; namespace Kingdee.BOS.TestPlugIn.ListPlugIn { [HotUpdate] [Description("单据A列表插件")] public class TestFormListPlugIn : AbstractListPlugIn { //是否为引出操作 private bool _Export = false; private List<SqlParam> _sqlParams = new List<SqlParam>(); /// <summary> /// 操作前事件 /// </summary> /// <param name="e"></param> public override void BeforeDoOperation(BeforeDoOperationEventArgs e) { base.BeforeDoOperation(e); this._Export = false; if (e.Operation.FormOperation.Operation == "Export") { this._Export = true; } } /// <summary> /// e.TableName临时表包含所有需要导出的数据 /// </summary> /// <param name="e"></param> public override void BeforeGetDataForTempTableAccess(Core.List.PlugIn.Args.BeforeGetDataForTempTableAccessArgs e) { base.BeforeGetDataForTempTableAccess(e); //引出操作 if (_Export) { //得到引出单据内码集合 //方式1 /// var dataObjs = this.ListModel.GetPKData(); //方式2 var pkName = this.View.BillBusinessInfo.GetForm().PkFieldName; var sql = string.Format("select {0} FROM {1}", pkName, e.TableName); var dataObjs = DBUtils.ExecuteDynamicObject(this.Context, sql); if (dataObjs.Count > 0) { List<object> lstPks = new List<object>(); foreach (var obj in dataObjs) { if (!lstPks.Contains(obj[pkName])) { lstPks.Add(obj[pkName]); } } //根据单据内码更新相关字段 var headTableName = this.View.BillBusinessInfo.GetEntity(0).TableName; var filter = this.GetFilter(lstPks, pkName); sql = string.Format("update {0} set F_KKK_Integer = F_KKK_Integer+1 where {1}", headTableName, filter); DBUtils.Execute(this.Context, sql, this._sqlParams); //并且控制整数大于15的单据才能导出 sql = string.Format("delete FROM {0} where F_KKK_Integer >15 ", e.TableName); DBUtils.Execute(this.Context, sql); } } } /// <summary> /// 得到过滤条件 /// </summary> /// <param name="pks"></param> /// <param name="pkName"></param> /// <returns></returns> private string GetFilter(List<object> pks, string pkName) { string strFilter =string.Empty; if (pks.Count == 0) { strFilter = string.Format("{0} = {1}", pkName, pks[0]); } else if (pks.Count <= 50) { strFilter = string.Format("{0} in ({1})", pkName, string.Join(",", pks.ToArray())); } else //使用表变量 { _sqlParams.Add(new SqlParam("@PKValue", KDDbType.udt_inttable, pks)); string pkTmpTable = string.Format("( select /*+ cardinality(b {0})*/ FId from table(fn_StrSplit(@PKValue,',',1)) b )", pks.Count ); strFilter = string.Format("exists (select 1 from {0} t1 where t1.FId = {1})", pkTmpTable, pkName); } return strFilter; } } }
赞 3
3人点赞
还没有人点赞,快来当第一个点赞的人吧!
打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!
推荐阅读