Trim()
/// <summary>
/// 通过User Name获取user id的table
/// 如果有非法的user则提示用户修改并返回null
/// </summary>
/// <param name="userNameList">user names 比如:Sammy Song;Lili Zhang;</param>
/// <returns>user table</returns>
public DataTable GetUserIDsForAdmin(string userNameList)
{
//对参数字符串处理,比如';;;;;;Sammy Song;;;;;;Lili Zhang;;;;;;' 这样的字符串,先Trim掉两边所有的分号,再把中间多个分号用正则替换成一个
userNameList = userNameList.Trim(';');
userNameList = Regex.Replace(userNameList, ";+", ";");
string[] userCheckString = userNameList.Split(';');
List<string> userCheckList = new List<string>();
userCheckList.Add(userCheckString[0].ToLower());
//去除重复的名字
for (int i = 0; i < userCheckString.Length; i++)
{
if (!userCheckList.Contains(userCheckString[i].ToLower()) && userCheckString[i].Trim() != "")
{
userCheckList.Add(userCheckString[i].ToLower());
}
}
//获取user table
BenQ.Public.Web.WSC.Entity.Wscuser entityCheckUser = new BenQ.Public.Web.WSC.Entity.Wscuser();
entityCheckUser.QueryMode = true;
entityCheckUser.Account.In(userCheckString);
entityCheckUser.Active += true;
DataTable userTable = entityCheckUser.Query(new QString[] { entityCheckUser.Userid, entityCheckUser.Account },
false, -1).Tables[0];
//返回的行数小于非重复user name的个数,则有非法的user name,提示用户出错
if (userTable.Rows.Count != userCheckList.Count)
{
for (int j = 0; j < userTable.Rows.Count; j++)
{
if (userCheckList.Contains(userTable.Rows[j]["account"].ToString().ToLower()))
{
userCheckList.Remove(userTable.Rows[j]["account"].ToString().ToLower());
}
}
string invalidUser = "";
for (int k = 0; k < userCheckList.Count; k++)
{
invalidUser += "," + userCheckList[k];
}
invalidUser = invalidUser.TrimStart(',');
this.showMessageInfo(this.getMessage("WM10005").Replace("%User%", invalidUser));
return null;
}
//没有非法用户,
return userTable;
}
/// 通过User Name获取user id的table
/// 如果有非法的user则提示用户修改并返回null
/// </summary>
/// <param name="userNameList">user names 比如:Sammy Song;Lili Zhang;</param>
/// <returns>user table</returns>
public DataTable GetUserIDsForAdmin(string userNameList)
{
//对参数字符串处理,比如';;;;;;Sammy Song;;;;;;Lili Zhang;;;;;;' 这样的字符串,先Trim掉两边所有的分号,再把中间多个分号用正则替换成一个
userNameList = userNameList.Trim(';');
userNameList = Regex.Replace(userNameList, ";+", ";");
string[] userCheckString = userNameList.Split(';');
List<string> userCheckList = new List<string>();
userCheckList.Add(userCheckString[0].ToLower());
//去除重复的名字
for (int i = 0; i < userCheckString.Length; i++)
{
if (!userCheckList.Contains(userCheckString[i].ToLower()) && userCheckString[i].Trim() != "")
{
userCheckList.Add(userCheckString[i].ToLower());
}
}
//获取user table
BenQ.Public.Web.WSC.Entity.Wscuser entityCheckUser = new BenQ.Public.Web.WSC.Entity.Wscuser();
entityCheckUser.QueryMode = true;
entityCheckUser.Account.In(userCheckString);
entityCheckUser.Active += true;
DataTable userTable = entityCheckUser.Query(new QString[] { entityCheckUser.Userid, entityCheckUser.Account },
false, -1).Tables[0];
//返回的行数小于非重复user name的个数,则有非法的user name,提示用户出错
if (userTable.Rows.Count != userCheckList.Count)
{
for (int j = 0; j < userTable.Rows.Count; j++)
{
if (userCheckList.Contains(userTable.Rows[j]["account"].ToString().ToLower()))
{
userCheckList.Remove(userTable.Rows[j]["account"].ToString().ToLower());
}
}
string invalidUser = "";
for (int k = 0; k < userCheckList.Count; k++)
{
invalidUser += "," + userCheckList[k];
}
invalidUser = invalidUser.TrimStart(',');
this.showMessageInfo(this.getMessage("WM10005").Replace("%User%", invalidUser));
return null;
}
//没有非法用户,
return userTable;
}