|
|
|
|
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.Text.RegularExpressions;
|
|
|
|
|
|
|
|
|
|
namespace DSWeb.Users
|
|
|
|
|
{
|
|
|
|
|
public partial class UserGridSource : System.Web.UI.Page
|
|
|
|
|
{
|
|
|
|
|
private string strHandle;//值list表示返回用户信息
|
|
|
|
|
private string strCompanyName;//分公司名称
|
|
|
|
|
private string strDepartmentName;//部门名称
|
|
|
|
|
private string strCheckUserID;//被操作用户GID
|
|
|
|
|
private string strUserID;//用户GID
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Request.QueryString["compname"] != null)
|
|
|
|
|
{
|
|
|
|
|
strCompanyName = UnicodeToGB(Request.QueryString["compname"].ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Request.QueryString["deptname"] != null)
|
|
|
|
|
{
|
|
|
|
|
strDepartmentName = UnicodeToGB(Request.QueryString["deptname"].ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(Request.QueryString["checkuser"] != null)
|
|
|
|
|
{
|
|
|
|
|
strCheckUserID = Request.QueryString["checkuser"].ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (strHandle != null)
|
|
|
|
|
{
|
|
|
|
|
if (strHandle == "list")
|
|
|
|
|
{
|
|
|
|
|
Response.Write(GetUserList());
|
|
|
|
|
}
|
|
|
|
|
if (strHandle == "userlist")
|
|
|
|
|
{
|
|
|
|
|
Response.Write(GetUserListByCondition());
|
|
|
|
|
}
|
|
|
|
|
if (strHandle == "deleteuser" && strCheckUserID != null)
|
|
|
|
|
{
|
|
|
|
|
Response.Write(DeleteUser(strCheckUserID));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 删除用户
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除用户
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="tempCheckUserID">被删除用户GID</param>
|
|
|
|
|
/// <returns>值1表示删除成功 值不等于1表示删除失败</returns>
|
|
|
|
|
private int DeleteUser(string tempCheckUserID)
|
|
|
|
|
{
|
|
|
|
|
int iResult = 0;
|
|
|
|
|
|
|
|
|
|
UserDA userDA = new UserDA();
|
|
|
|
|
iResult = userDA.UpdateUserDelete(tempCheckUserID, strUserID);
|
|
|
|
|
|
|
|
|
|
return iResult;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
private string GetUserListByCondition()
|
|
|
|
|
{
|
|
|
|
|
UserDA userDA = new UserDA();
|
|
|
|
|
DataTable sourceTable;
|
|
|
|
|
|
|
|
|
|
string condition = "";
|
|
|
|
|
|
|
|
|
|
if (strCompanyName != null)
|
|
|
|
|
{
|
|
|
|
|
if (strCompanyName != "")
|
|
|
|
|
{
|
|
|
|
|
condition += String.Format(" AND B.COMPANYNAME = '{0}' ", strCompanyName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (strDepartmentName != null)
|
|
|
|
|
{
|
|
|
|
|
if (strDepartmentName != "")
|
|
|
|
|
{
|
|
|
|
|
condition += String.Format(" AND B.DEPTNAME = '{0}' ", strDepartmentName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string strSql = String.Format(" SELECT A.GID,A.CODENAME,A.SHOWNAME,B.COMPANYNAME,B.DEPTNAME,B.OFFICEPHONE,B.FAX,(SELECT TOP 1 CASE WHEN VALUE='true' THEN '是' ELSE '否' END FROM user_userattribute"
|
|
|
|
|
+ " WHERE USERID=a.GID and ATTRIBUTEID='D4BF2204-F0AC-4F12-B02C-6520D57BF800') ISDISABLE ,(SELECT TOP 1 CASE WHEN VALUE='true' THEN '是' ELSE '否' END FROM user_userattribute WHERE USERID=a.GID and ATTRIBUTEID='2E5E6066-1C5D-4B04-BF8C-56637C20FC8C') ISUSESYSTEM "
|
|
|
|
|
+" FROM [user] as A LEFT JOIN user_baseinfo as B "
|
|
|
|
|
+ " ON A.GID = B.USERID WHERE A.ISDELETED <> 1 {0} ORDER BY A.CODENAME,B.COMPANYNAME,B.DEPTNAME ASC ",condition);
|
|
|
|
|
|
|
|
|
|
sourceTable = userDA.GetExcuteSql(strSql).Tables[0];
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetUserList()
|
|
|
|
|
{
|
|
|
|
|
UserDA userDA = new UserDA();
|
|
|
|
|
DataTable sourceTable;
|
|
|
|
|
|
|
|
|
|
//string strSql = " SELECT A.GID, A.USERNAME,A.SHOWNAME, A.PASSWORD, A.CODENAME, A.ENROLLTIME, B.USERNAME as CREATEUSER, CASE WHEN A.ISDELETED = 1 THEN 1 ELSE 0 END as ISDELETED,CASE WHEN A.ISDISABLE = 1 THEN 1 ELSE 0 END as ISDISABLE FROM [user] as A INNER JOIN [user] as B ON A.CREATEUSER = B.GID ORDER BY ENROLLTIME DESC ";
|
|
|
|
|
string strSql = "SELECT a.GID,a.CODENAME,a.SHOWNAME,b.COMPANYNAME,b.DEPTNAME,b.OFFICEPHONE,b.FAX,(SELECT TOP 1 CASE WHEN VALUE='true' THEN '是' ELSE '否' END FROM user_userattribute ";
|
|
|
|
|
strSql = strSql + " WHERE USERID=a.GID and ATTRIBUTEID='D4BF2204-F0AC-4F12-B02C-6520D57BF800') ISDISABLE ,(SELECT TOP 1 CASE WHEN VALUE='true' THEN '是' ELSE '否' END FROM user_userattribute WHERE USERID=a.GID and ATTRIBUTEID='2E5E6066-1C5D-4B04-BF8C-56637C20FC8C') ISUSESYSTEM ";
|
|
|
|
|
strSql = strSql + " FROM [user] as a, user_baseinfo b where a.GID=b.USERID and a.ISDELETED=0 ORDER BY b.COMPANYNAME ";
|
|
|
|
|
|
|
|
|
|
sourceTable = userDA.GetExcuteSql(strSql).Tables[0];
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region Unicode-GB Code转换
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Unicode-GB Code转换
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="text">将Unicode编码字符转换成GB编码字符</param>
|
|
|
|
|
/// <returns>GB Code字符串</returns>
|
|
|
|
|
public string UnicodeToGB(string text)
|
|
|
|
|
{
|
|
|
|
|
UnicodeEncoding unicode = new UnicodeEncoding();
|
|
|
|
|
text = unicode.GetString(unicode.GetBytes(Regex.Unescape(text.Trim())));
|
|
|
|
|
return text;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Unicode-GB Code转换
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="text">将Unicode编码字符转换成GB编码字符</param>
|
|
|
|
|
/// <returns>GB Code字符串</returns>
|
|
|
|
|
public string UnicodeToGB_Old(string text)
|
|
|
|
|
{
|
|
|
|
|
MatchCollection mc = Regex.Matches(text, "([\\w]+)|(\\\\u([\\w]{4}))");
|
|
|
|
|
if (mc != null && mc.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
foreach (Match m2 in mc)
|
|
|
|
|
{
|
|
|
|
|
string v = m2.Value;
|
|
|
|
|
if (v.IndexOf("\\") >= 0)
|
|
|
|
|
{
|
|
|
|
|
string word = v.Substring(2);
|
|
|
|
|
byte[] codes = new byte[2];
|
|
|
|
|
int code = Convert.ToInt32(word.Substring(0, 2), 16);
|
|
|
|
|
int code2 = Convert.ToInt32(word.Substring(2), 16);
|
|
|
|
|
codes[0] = (byte)code2;
|
|
|
|
|
codes[1] = (byte)code;
|
|
|
|
|
sb.Append(Encoding.Unicode.GetString(codes));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sb.Append(v);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return text;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|