result=COMPANYFIELDNAME+" in(select top 1 companyid from vw_user where userid='"+USERID+"' or showname='"+USERID+"')";
}
elseif(USERFIELDArray.Length>0)
{
var_S="";
foreach(varUSERFIELDinUSERFIELDArray)
{
if(_S!="")_S+=" or ";
_S=_S+USERFIELD+" in( select USERID from vw_user where companyid in(select companyid from vw_user where userid='"+USERID+"' or showname='"+USERID+"')"+
" union all select SHOWNAME from vw_user where companyid in(select top 1 companyid from vw_user where userid = '"+USERID+"' or showname = '"+USERID+"'))";
}
result="("+_S+")";
}
}
else
if(RANGEVALUE=="2")
{
if(!string.IsNullOrEmpty(COMPANYFIELDNAME))
{
result=COMPANYFIELDNAME+" in(select top 1 companyid from vw_user where userid='"+USERID+"' or showname='"+USERID+"')";
result+=" and "+DEPTFIELDNAME+" in(select top 1 deptgid from vw_user where userid='"+USERID+"' or showname='"+USERID+"' union all select top 1 deptname from vw_user where userid='"+USERID+"' or showname='"+USERID+"' ) ";
}
elseif(USERFIELDArray.Length>0)
{
var_S="";
foreach(varUSERFIELDinUSERFIELDArray)
{
if(_S!="")_S+=" or ";
_S=_S+USERFIELD+" in( select SHOWNAME from vw_user where deptgid in(select deptgid from vw_user where userid = '"+USERID+"' or showname = '"+USERID+"'))";
}
result="("+_S+")";
}
}
else
if(RANGEVALUE=="3")
{
if(USERFIELDArray.Length>0)
{
//result = USERFIELD + " ='" + USERID + "' ";
var_S="";
foreach(varUSERFIELDinUSERFIELDArray)
{
if(_S!="")_S+=" or ";
_S=_S+USERFIELD+" =( select SHOWNAME from vw_user where USERID in(select USERID from vw_user where userid = '"+USERID+"' or showname = '"+USERID+"'))";
}
result="("+_S+")";
}
}
else
if(RANGEVALUE=="4")
{
if(USERFIELDArray.Length>0)
{
result="1=2";
}
}
else
if(RANGEVALUE=="5")
{//选择公司
if(!string.IsNullOrEmpty(COMPANYFIELDNAME))
{
result=COMPANYFIELDNAME+" in(select COMPANYID from user_authority_range_company where AUTHORITYID=(select GID from user_authority_info where Name='"+modName+"' or DESCRIPTION='"+modName+"') and "+RANGENAME+" = 1)";
}
elseif(USERFIELDArray.Length>0)
{
var_S="";
foreach(varUSERFIELDinUSERFIELDArray)
{
if(_S!="")_S+=" or ";
_S=_S+" exists(select 1 from vw_user where companyid in "+
"(select companyid from user_authority_range_company where AUTHORITYID = "+
"(select GID from user_authority_info where Name = '"+modName+"' or DESCRIPTION = '"+modName+"') and "+RANGENAME+" = 1 "+
") and( SHOWNAME = "+USERFIELD+"))";
}
result="("+_S+")";
//result = USERFIELD + " in(select USERID from vw_user where companyid in(select COMPANYID from user_authority_range_company where userid='"
// + USERID + "' and AUTHORITYID=(select GID from user_authority_info where name='" + modName + "') and VISIBLERANGE=1)";
}
}
else
if(RANGEVALUE=="6")
{//选择个人
if(USERFIELDArray.Length>0)
{
var_S="";
foreach(varUSERFIELDinUSERFIELDArray)
{
if(_S!="")_S+=" or ";
_S=_S+USERFIELD+" in(select showname from vw_user where userid in(select OPID from user_authority_range_op where userid = (select userid from vw_user where userid = '"+USERID+"'"+
" or showname = '"+USERID+"') and AUTHORITYID = (select GID from user_authority_info where name = '"+modName+"' or description = '"+modName+"') and "+RANGENAME+" = 1))";
}
result="("+_S+")";
//result = USERFIELD + " in(select OPID from user_authority_range_op where userid='"
// + USERID + "' and AUTHORITYID=(select GID from user_authority_info where name='" + modName + "') and VISIBLERANGE=1)";