分享过滤条件中增加一个自定义过滤变量插件代码

// 以下代码示例演示过滤条件中增加一个自定义过滤变量,例如预算部门
// 另外还需要在t_mdl_filtercondition,t_mdl_filtercondition_l中增加相应记录,例如
/*--插入配置过滤条件<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
DELETE FROM T_MDL_FILTERCONDITION WHERE FID=1000001;
INSERT INTO T_MDL_FILTERCONDITION(FID,FCONDITIONTYPEID,FSEQ,FOPERATE,FINPUTCTLTYPE,FDATASOURCETYPE,FDATAFIELDINDEX,FVALUE,FINPUT,FCLASSNAME) VALUES (1000001, 1000001,1,'=',0,0,0,'ISNULL',0,'XXApp.Core.BuggetDeptFilter.CurrBuggetDeptFilter,XXApp.Core') ;

--插入配置过滤条件多语言
DELETE FROM T_MDL_FILTERCONDITION_L WHERE FID=1000001;
INSERT INTO T_MDL_FILTERCONDITION_L(FPKID,FID,FLOCALEID,FNAME,FDATASOURCE,FTOOLTIP) VALUES (1000001,1000001,2052,N'当前预算部门',null,null) ;

*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kingdee.BOS.Core.CommonFilter.ConditionVariableAnalysis;
using Kingdee.BOS.Core.CommonFilter;
using System.ComponentModel;
using Kingdee.BOS.App.Data;

namespace XXApp.Core.BuggetDeptFilter
{
/// <summary>
/// 当前用户根据预算部门进行过滤
/// </summary>
[Description("当前用户根据预算部门进行过滤")]
public class CurrBuggetDeptFilter : AbstractVariableAnalysisPlugin 
{
public override string GetVariableFilter(ConditionVariableContext ctx)
{
StringBuilder sb = new StringBuilder();

// 获取当前登录用户所在的部门
sb.AppendFormat("select staff.FDEPTID ");
sb.AppendFormat(" from t_bd_staff staff ");
sb.AppendFormat(" inner join t_sec_user suser on staff.fpersonid=suser.FLINKOBJECT ");
sb.AppendFormat(" inner join V_BD_CONTACTOBJECT vcon on vcon.fid=suser.FLINKOBJECT and vcon.ftype=1 ");
sb.AppendFormat(" where suser.fuserid={0} ", ctx.Context.UserId);

// 获取部门对应的预算部门内码
string strSelect = string.Format(@"select fdeptid
from t_bd_department where fdeptid IN ({0}) and FISBUDGET=1
union all
select FBudgetDept
from t_bd_department where fdeptid IN ({0}) and FISBUDGET=0", sb.ToString());


long currDeptId = DBUtils.ExecuteScalar<long>(ctx.Context, strSelect, 0, null);

// 当前用户没有关联职员
if (currDeptId <= 0)
{
return "1=1";
}

// 取出当前预算部门的名称
string strSql = string.Format(@"SELECT FNAME FROM T_BD_DEPARTMENT_L 
WHERE FDEPTID={0} AND FLOCALEID={1}", currDeptId, ctx.Context.UserLocale.LCID);

string strName = DBUtils.ExecuteScalar<string>(ctx.Context, strSql, string.Empty, null);

return string.Format("{0} {1} '{2}'", ctx.FieldName , ctx.Operater, strName);
}
}
}

转载于:https://www.cnblogs.com/fyq891014/p/4188790.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值