strSql.Append("SELECT GID,USERID,VISIBLERANGE,OPERATERANGE,AUTHORITYID,DESCRIPTION,NAME,ISNULL((case VISIBLERANGE when 0 then '全部' when 1 then '本公司' ");
strSql.Append("when 2 then '本部门' when 3 then '本人' when 4 then '无' when 5 then '选择公司' ");
strSql.Append("when 6 then '选择人员' end),'') VISIBLERANGEREF,ISNULL((case OPERATERANGE when 0 then '全部' when 1 then '本公司' ");
strSql.Append("when 2 then '本部门' when 3 then '本人' when 4 then '无' when 5 then '选择公司' ");
strSql.Append("when 6 then '选择人员' end),'') OPERATERANGEREF,VSSQL ");
@"update user_authority_range set VISIBLERANGE=@VISIBLERANGE,OPERATERANGE=@OPERATERANGE,MODIFIEDUSER=@MODIFIEDUSER,MODIFIEDTIME=@MODIFIEDTIME,VSSQL=@VSSQL where GID=@GID ");
varcmdInsert=
db.GetSqlStringCommand(
@"insert into user_authority_range (GID,USERID,AUTHORITYID,VISIBLERANGE,OPERATERANGE,CREATEUSER,CREATETIME,VSSQL)
strSql.Append(" left join user_authority_range_op r on AUTHORITYID = '"+AUTHORITYID+"' and r.OPID = u.userid ");
strSql.Append(" and r.userid = '"+userid+"' ");
strSql.Append(" union all ");
strSql.Append(" select distinct vu.companyid id, vu.companyname OPNAME, '0' parentid, 0 isleaf, (case when exists(select 1 from user_authority_range_op op where AUTHORITYID = '"+AUTHORITYID+"' and userid = '"+userid+"' and op.VISIBLERANGE=1 and exists(select(1) from vw_user v2 where v2.COMPANYID = vu.companyid and op.OPID = v2.USERID )) then 1 else 0 end) VISIBLERANGE,'' GID,'' USERID ");
strSql.Append(" from vw_user vu ");
strSql.Append(" union all ");
strSql.Append(" select distinct vu.deptgid id, vu.DEPTNAME OPNAME, vu.companyid parentid, 0 isleaf, (case when exists(select 1 from user_authority_range_op op where AUTHORITYID = '"+AUTHORITYID+"' and userid = '"+userid+"' and op.VISIBLERANGE=1 and exists(select(1) from vw_user v2 where v2.deptgid = vu.deptgid and op.OPID = v2.USERID)) then 1 else 0 end) VISIBLERANGE,'' GID,'' USERID ");
strSql.Append(" from vw_user vu ");
strSql.Append(" )t where PARENTID = '"+PARENTID+"' ");
strSql.Append(" left join user_authority_range_op r on AUTHORITYID = '"+AUTHORITYID+"' and r.OPID = u.userid ");
strSql.Append(" and r.userid = '"+userid+"' ");
strSql.Append(" union all ");
strSql.Append(" select distinct vu.companyid id, vu.companyname OPNAME, '0' parentid, 0 isleaf, (case when exists(select 1 from user_authority_range_op op where AUTHORITYID = '"+AUTHORITYID+"' and userid = '"+userid+"' and op.OPERATERANGE=1 and exists(select(1) from vw_user v2 where v2.COMPANYID = vu.companyid and op.OPID = v2.USERID )) then 1 else 0 end) OPERATERANGE,'' GID,'' USERID ");
strSql.Append(" from vw_user vu ");
strSql.Append(" union all ");
strSql.Append(" select distinct vu.deptgid id, vu.DEPTNAME OPNAME, vu.companyid parentid, 0 isleaf, (case when exists(select 1 from user_authority_range_op op where AUTHORITYID = '"+AUTHORITYID+"' and userid = '"+userid+"' and op.OPERATERANGE=1 and exists(select(1) from vw_user v2 where v2.deptgid = vu.deptgid and op.OPID = v2.USERID)) then 1 else 0 end) OPERATERANGE,'' GID,'' USERID ");
strSql.Append(" from vw_user vu ");
strSql.Append(" )t where PARENTID = '"+PARENTID+"' ");
+"update user_authority_range_op set OPERATERANGE=@OPERATERANGE,MODIFIEDUSER=@MODIFIEDUSER,MODIFIEDTIME=@MODIFIEDTIME where USERID='"+userid+"' and OPID=@OPID AND AUTHORITYID=@AUTHORITYID");
if(rtype=="OP")
{
varcmdInsertOP=
db.GetSqlStringCommand(
@"update user_authority_range_op set OPERATERANGE=0 from user_authority_range_op p where USERID='"+op+"' and AUTHORITYID<>'"+AUTHORITYID+"' "
+" update user_authority_range_op set OPERATERANGE=1,MODIFIEDUSER='"+userid+"',MODIFIEDTIME=getdate() from user_authority_range_op p where USERID='"+op+"' and AUTHORITYID<>'"+AUTHORITYID+"' "
+" and opid in (select opid from user_authority_range_op where AUTHORITYID='"+AUTHORITYID+"' and OPERATERANGE=1 and USERID='"+op+"') "
+" insert into user_authority_range_op (GID,USERID,AUTHORITYID,OPID,VISIBLERANGE,OPERATERANGE,CREATEUSER,CREATETIME) "
+" select newid() GID,'"+op+"' USERID,A.AUTHORITYID,U.OPID,0 VISIBLERANGE,U.OPERATERANGE,'"+userid+"' CREATEUSER,GETDATE() CREATETIME from VW_User_Authority A, user_authority_range_op U where A.OPERATERANGE=6 AND A.USERID='"+op+"' AND U.AUTHORITYID='"+AUTHORITYID+"' and U.OPERATERANGE=1"
+" and a.AUTHORITYID<>'"+AUTHORITYID+"' and u.userid='"+op+"' and not EXISTS (select 1 from user_authority_range_op y where y.AUTHORITYID=a.AUTHORITYID and y.USERID='"+op+"' and y.OPID=u.OPID)");
db.ExecuteNonQuery(cmdInsertOP,tran);
}
else
{
varcmdInsertVs=
db.GetSqlStringCommand(
@"update user_authority_range_op set VISIBLERANGE=0 from user_authority_range_op p where USERID='"+op+"' and AUTHORITYID<>'"+AUTHORITYID+"' "
+" update user_authority_range_op set VISIBLERANGE=1,MODIFIEDUSER='"+userid+"',MODIFIEDTIME=getdate() from user_authority_range_op p where USERID='"+op+"' and AUTHORITYID<>'"+AUTHORITYID+"' "
+" and opid in (select opid from user_authority_range_op where AUTHORITYID='"+AUTHORITYID+"' and VISIBLERANGE=1 and USERID='"+op+"') "
+" insert into user_authority_range_op (GID,USERID,AUTHORITYID,OPID,VISIBLERANGE,OPERATERANGE,CREATEUSER,CREATETIME) "
+" select newid() GID,'"+op+"' USERID,A.AUTHORITYID,U.OPID,U.VISIBLERANGE,0 OPERATERANGE,'"+userid+"' CREATEUSER,GETDATE() CREATETIME from VW_User_Authority A, user_authority_range_op U where A.VISIBLERANGE=6 AND A.USERID='"+op+"' AND U.AUTHORITYID='"+AUTHORITYID+"' and U.VISIBLERANGE=1 "
+" and a.AUTHORITYID<>'"+AUTHORITYID+"' and u.userid='"+op+"' and not EXISTS (select 1 from user_authority_range_op y where y.AUTHORITYID=a.AUTHORITYID and y.USERID='"+op+"' and y.OPID=u.OPID) ");
db.ExecuteNonQuery(cmdInsertVs,tran);
}
//if (UserAuthorityList != null)
//{
// foreach (var enumValueAuthority in UserAuthorityList)
@"update user_authority_range_company set OPERATERANGE=0 from user_authority_range_company p where USERID='"+op+"' and AUTHORITYID<>'"+AUTHORITYID+"' "
+" update user_authority_range_company set OPERATERANGE=1,MODIFIEDUSER='"+userid+"',MODIFIEDTIME=getdate() from user_authority_range_company p where USERID='"+op+"' and AUTHORITYID<>'"+AUTHORITYID+"' "
+" and companyid in (select companyid from user_authority_range_company where AUTHORITYID='"+AUTHORITYID+"' and OPERATERANGE=1 and USERID='"+op+"') "
+" insert into user_authority_range_company (GID,USERID,AUTHORITYID,COMPANYID,VISIBLERANGE,OPERATERANGE,CREATEUSER,CREATETIME) "
+" select newid() GID,'"+op+"' USERID,A.AUTHORITYID,U.COMPANYID,0 VISIBLERANGE,U.OPERATERANGE,'"+userid+"' CREATEUSER,GETDATE() CREATETIME from VW_User_Authority A, user_authority_range_company U where A.OPERATERANGE=5 AND A.USERID='"+op+"' AND U.AUTHORITYID='"+AUTHORITYID+"' and U.OPERATERANGE=1"
+" and a.AUTHORITYID<>'"+AUTHORITYID+"' and u.userid='"+op+"' and not EXISTS (select 1 from user_authority_range_company y where y.AUTHORITYID=a.AUTHORITYID and y.USERID='"+op+"' and y.COMPANYID=u.COMPANYID)");
db.ExecuteNonQuery(cmdInsertOP,tran);
}
else
{
varcmdInsertVs=
db.GetSqlStringCommand(
@"update user_authority_range_company set VISIBLERANGE=0 from user_authority_range_company p where USERID='"+op+"' and AUTHORITYID<>'"+AUTHORITYID+"' "
+" update user_authority_range_company set VISIBLERANGE=1,MODIFIEDUSER='"+userid+"',MODIFIEDTIME=getdate() from user_authority_range_company p where USERID='"+op+"' and AUTHORITYID<>'"+AUTHORITYID+"' "
+" and COMPANYID in (select COMPANYID from user_authority_range_company where AUTHORITYID='"+AUTHORITYID+"' and VISIBLERANGE=1 and USERID='"+op+"') "
+" insert into user_authority_range_company (GID,USERID,AUTHORITYID,COMPANYID,VISIBLERANGE,OPERATERANGE,CREATEUSER,CREATETIME) "
+" select newid() GID,'"+op+"' USERID,A.AUTHORITYID,U.COMPANYID,U.VISIBLERANGE,0 OPERATERANGE,'"+userid+"' CREATEUSER,GETDATE() CREATETIME from VW_User_Authority A, user_authority_range_company U where A.VISIBLERANGE=5 AND A.USERID='"+op+"' AND U.AUTHORITYID='"+AUTHORITYID+"' and U.VISIBLERANGE=1 "
+" and a.AUTHORITYID<>'"+AUTHORITYID+"' and u.userid='"+op+"' and not EXISTS (select 1 from user_authority_range_company y where y.AUTHORITYID=a.AUTHORITYID and y.USERID='"+op+"' and y.COMPANYID=u.COMPANYID) ");