// 以下代码示例演示过滤条件中增加一个自定义过滤变量,例如预算部门 // 另外还需要在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); } } }