You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
D7QUANTAI/DSWeb/Authority/UserAuthorityGridSource.asp...

312 lines
14 KiB
C#

10 months ago
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using DSWeb.Models;
using DSWeb.EntityDA;
using System.Text;
using System.Data.SqlClient;
using System.Collections.Generic;
namespace DSWeb.Authority
{
public partial class UserAuthorityGridSource : System.Web.UI.Page
{
private string strHandle;//操作类型
public string strUserID;//操作人GID
private string strCheckUserID;//被操作人GID
private string strAuthorityID;//权限范围GID
private int iRangeType;//范围类型 1-可视范围 2-可操作范围
private int iRangeVal;//范围值
protected void Page_Load(object sender, EventArgs e)
{
if (Session["USERID"] != null)
{
strUserID = Session["USERID"].ToString();
}
if (Request.QueryString["handle"] != null)
{
strHandle = Request.QueryString["handle"].ToString().Trim().ToLower();
}
if (Request.QueryString["checkuser"] != null)
{
strCheckUserID = Request.QueryString["checkuser"].ToString().Trim();
}
if (Request.QueryString["authgid"] != null)
{
strAuthorityID = Request.QueryString["authgid"].ToString();
}
if (Request.QueryString["rtype"] != null)
{
iRangeType = int.Parse(Request.QueryString["rtype"].ToString().Trim());
}
else
{
iRangeType = -1;
}
if (Request.QueryString["rval"] != null)
{
iRangeVal = int.Parse(Request.QueryString["rval"].ToString().Trim());
}
else
{
iRangeVal = -1;
}
if (strHandle != null && strUserID != null)
{
if (strHandle == "getranges" && strCheckUserID != null)
{
if (strCheckUserID != "")
{
Response.Write(GetCheckUserAuthorityRange(strCheckUserID));
}
}
if (strHandle == "saverange" && strCheckUserID != null && iRangeType > 0 && iRangeVal >= 0 && strAuthorityID != null)
{
Response.Write(SaveCheckUserAuthorityRange(strCheckUserID, iRangeType, iRangeVal, strAuthorityID));
}
}
}
#region 保存用户权限范围设置
/// <summary>
/// 保存用户权限范围设置
/// </summary>
/// <param name="tempCheckUserID">被操作用户GID</param>
/// <param name="tempRangeType">权限类型</param>
/// <param name="tempRangeVal">权限范围值</param>
/// <param name="tempAuthorityID">权限范围GID</param>
/// <returns>返回JSON数据</returns>
private string SaveCheckUserAuthorityRange(string tempCheckUserID,int tempRangeType,int tempRangeVal,string tempAuthorityID)
{
int iResult = 0;
StringBuilder sourceBuilder = new StringBuilder();
sourceBuilder.Append("{");
sourceBuilder.Append("authority:[");
DataTable sourceTable = new DataTable();
UserAuthorityDA userAuthorityDA = new UserAuthorityDA();
iResult = userAuthorityDA.UpdateUserAuthority(strUserID, tempRangeType, tempRangeVal, tempAuthorityID, tempCheckUserID);
if (iResult == 1)
{
string strSql = "";
strSql = String.Format(" SELECT A.GID,A.DESCRIPTION,CASE WHEN ISNULL(VISIBLERANGE,4)= 0 THEN 1 ELSE 0 END as VISALL,CASE WHEN ISNULL(VISIBLERANGE,4)= 1 THEN 1 ELSE 0 END as VISCOMP,"
+ " CASE WHEN ISNULL(VISIBLERANGE,4)= 2 THEN 1 ELSE 0 END as VISDEPT,CASE WHEN ISNULL(VISIBLERANGE,4)= 3 THEN 1 ELSE 0 END as VISSELF,"
+ " CASE WHEN ISNULL(VISIBLERANGE,4)= 4 THEN 1 ELSE 0 END as VISNULL,CASE WHEN ISNULL(OPERATERANGE,4)= 0 THEN 1 ELSE 0 END as OPALL,"
+ " CASE WHEN ISNULL(OPERATERANGE,4)= 1 THEN 1 ELSE 0 END as OPCOMP,CASE WHEN ISNULL(OPERATERANGE,4)= 2 THEN 1 ELSE 0 END as OPDEPT,"
+ " CASE WHEN ISNULL(OPERATERANGE,4)= 3 THEN 1 ELSE 0 END as OPSELF,CASE WHEN ISNULL(OPERATERANGE,4)= 4 THEN 1 ELSE 0 END as OPNULL "
+ " FROM user_authority_info as A LEFT JOIN user_authority_range as B ON A.GID = B.AUTHORITYID "
+ " WHERE B.USERID = '{0}' AND ISDELETE <> 1 AND A.GID = '{1}' ORDER BY A.DESCRIPTION ", tempCheckUserID, tempAuthorityID);
sourceTable = userAuthorityDA.GetExcuteSql(strSql).Tables[0];
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
if (i == 0)
{
sourceBuilder.Append("{id:\"" + sourceTable.Rows[i]["GID"].ToString() + "\",");
}
else
{
sourceBuilder.Append(",{id:\"" + sourceTable.Rows[i]["GID"].ToString() + "\",");
}
sourceBuilder.Append("\"vall\":" + sourceTable.Rows[i]["VISALL"].ToString() + ",");
sourceBuilder.Append("\"vcomp\":" + sourceTable.Rows[i]["VISCOMP"].ToString() + ",");
sourceBuilder.Append("\"vdept\":" + sourceTable.Rows[i]["VISDEPT"].ToString() + ",");
sourceBuilder.Append("\"vself\":" + sourceTable.Rows[i]["VISSELF"].ToString() + ",");
sourceBuilder.Append("\"vnull\":" + sourceTable.Rows[i]["VISNULL"].ToString() + ",");
sourceBuilder.Append("\"oall\":" + sourceTable.Rows[i]["OPALL"].ToString() + ",");
sourceBuilder.Append("\"ocomp\":" + sourceTable.Rows[i]["OPCOMP"].ToString() + ",");
sourceBuilder.Append("\"odept\":" + sourceTable.Rows[i]["OPDEPT"].ToString() + ",");
sourceBuilder.Append("\"oself\":" + sourceTable.Rows[i]["OPSELF"].ToString() + ",");
sourceBuilder.Append("\"onull\":" + sourceTable.Rows[i]["OPNULL"].ToString() + ",");
sourceBuilder.Append("\"state\":1}");
}
//return sourceBuilder.ToString();
}
else
{
sourceBuilder.Append("{id:\"\",");
sourceBuilder.Append("\"vall\":0,");
sourceBuilder.Append("\"vcomp\":0,");
sourceBuilder.Append("\"vdept\":0,");
sourceBuilder.Append("\"vself\":0,");
sourceBuilder.Append("\"vnull\":0,");
sourceBuilder.Append("\"oall\":0,");
sourceBuilder.Append("\"ocomp\":0,");
sourceBuilder.Append("\"odept\":0,");
sourceBuilder.Append("\"oself\":0,");
sourceBuilder.Append("\"onull\":0,");
sourceBuilder.Append("\"state\":0}");
}
sourceBuilder.Append("]");
sourceBuilder.Append("}");
return sourceBuilder.ToString();
}
#endregion
#region 根据用户GID获取相应的权限范围信息
/// <summary>
/// 根据用户GID获取相应的权限范围信息
/// </summary>
/// <param name="tempCheckUserID">用户GID</param>
/// <returns>返回用户的JSON权限范围信息</returns>
private string GetCheckUserAuthorityRange(string tempCheckUserID)
{
UserAuthorityDA userAuthorityDA = new UserAuthorityDA();
DataTable sourceTable;
//string strCondition = "";
//string strTopInclude = "";
//string strTopNotInclude = "";
//if (strSearch != null)
//{
// if (!strSearch.Trim().Equals(""))
// {
// string tempSearch = strSearch;
// tempSearch = tempSearch.Replace("{", "");
// tempSearch = tempSearch.Replace("}", "");
// tempSearch = tempSearch.Replace("[", "");
// tempSearch = tempSearch.Replace("]", "");
// string[] searchArg = tempSearch.Split(new char[] { ',' });
// for (int i = 0; i < searchArg.Length; i++)
// {
// string[] strArg = searchArg[i].Split(new char[] { ':' });
// if (!strArg[1].Replace("\"", "").Trim().Equals(""))
// {
// switch (strArg[0].Replace("\"", ""))
// {
// case "btime"://Customer
// strCondition += String.Format(" AND A.APPLYTIME >= '{0} 00:00:00' ", strArg[1].Replace("\"", ""));
// break;
// case "etime"://BillNO
// strCondition += String.Format(" AND A.APPLYTIME <= '{0} 23:59:59' ", strArg[1].Replace("\"", ""));
// break;
// case "cus"://ETD BeginDate
// strCondition += String.Format(" AND A.CUSTOMERNAME LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
// break;
// case "no"://ETD EndDate
// strCondition += String.Format(" AND A.BILLNO LIKE '%{0}%'", strArg[1].Replace("\"", ""));
// break;
// default:
// break;
// }
// }
// }
// }
//}
string strSql = "";
strSql = String.Format(" SELECT A.GID,A.DESCRIPTION,CASE WHEN ISNULL(VISIBLERANGE,4)= 0 THEN 1 ELSE 0 END as VISALL,CASE WHEN ISNULL(VISIBLERANGE,4)= 1 THEN 1 ELSE 0 END as VISCOMP,"
+ " CASE WHEN ISNULL(VISIBLERANGE,4)= 2 THEN 1 ELSE 0 END as VISDEPT,CASE WHEN ISNULL(VISIBLERANGE,4)= 3 THEN 1 ELSE 0 END as VISSELF,"
+ " CASE WHEN ISNULL(VISIBLERANGE,4)= 4 THEN 1 ELSE 0 END as VISNULL,CASE WHEN ISNULL(OPERATERANGE,4)= 0 THEN 1 ELSE 0 END as OPALL,"
+ " CASE WHEN ISNULL(OPERATERANGE,4)= 1 THEN 1 ELSE 0 END as OPCOMP,CASE WHEN ISNULL(OPERATERANGE,4)= 2 THEN 1 ELSE 0 END as OPDEPT,"
+ " CASE WHEN ISNULL(OPERATERANGE,4)= 3 THEN 1 ELSE 0 END as OPSELF,CASE WHEN ISNULL(OPERATERANGE,4)= 4 THEN 1 ELSE 0 END as OPNULL "
+ " FROM user_authority_info as A LEFT JOIN user_authority_range as B ON A.GID = B.AUTHORITYID "
+ " WHERE B.USERID = '{0}' AND ISDELETE <> 1 ORDER BY A.DESCRIPTION ", tempCheckUserID);
sourceTable = userAuthorityDA.GetExcuteSql(strSql).Tables[0];
IList<UserAuthorityEntity> userAuthorityEntities = new List<UserAuthorityEntity>();
userAuthorityEntities = userAuthorityDA.GetAllUserAuthorityInfo();
if (sourceTable.Rows.Count == 0 && userAuthorityEntities.Count > 0)
{
strSql = String.Format(" SELECT GID,DESCRIPTION,0,0,0,0,0,0,0,0,0,0 FROM user_authority_info WHERE ISDELETE <> 1");
sourceTable = userAuthorityDA.GetExcuteSql(strSql).Tables[0];
}
else if (sourceTable.Rows.Count < userAuthorityEntities.Count)
{
for (int j = 0; j < userAuthorityEntities.Count; j++)
{
int iExistCount = 0;
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
if (userAuthorityEntities[j].GID == sourceTable.Rows[i]["GID"].ToString())
{
iExistCount++;
break;
}
}
if (iExistCount == 0)
{
DataRow newRow = sourceTable.NewRow();
newRow["GID"] = userAuthorityEntities[j].GID;
newRow["DESCRIPTION"] = userAuthorityEntities[j].Description;
newRow["VISALL"] = "0";
newRow["VISCOMP"] = "0";
newRow["VISDEPT"] = "0";
newRow["VISSELF"] = "0";
newRow["VISNULL"] = "0";
newRow["OPALL"] = "0";
newRow["VISALL"] = "0";
newRow["OPCOMP"] = "0";
newRow["OPDEPT"] = "0";
newRow["OPSELF"] = "0";
newRow["OPNULL"] = "0";
sourceTable.Rows.Add(newRow);
}
}
}
StringBuilder sourceBuilder = new StringBuilder();
sourceBuilder.Append("{");
sourceBuilder.Append("rows:[");
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
sourceBuilder.Append("{id:\"" + sourceTable.Rows[i][0].ToString() + "\",");
sourceBuilder.Append("data:[");
//sourceBuilder.Append("\"0\",");
for (int j = 1; j < sourceTable.Columns.Count; j++)
{
if (j == sourceTable.Columns.Count - 1)
{
sourceBuilder.Append("\"" + sourceTable.Rows[i][j].ToString() + "\"");
}
else
{
sourceBuilder.Append("\"" + sourceTable.Rows[i][j].ToString() + "\",");
}
}
if (i == sourceTable.Rows.Count - 1)
{
sourceBuilder.Append("]}");
}
else
{
sourceBuilder.Append("]},");
}
}
sourceBuilder.Append("]");
sourceBuilder.Append("}");
return sourceBuilder.ToString();
}
#endregion
}
}