//JS: $("#btnInsert").click(function (e) { var b = $("#txtMore").val() var tmp1 = $("#txtMore").val().split("\n"); //過濾換行符,獲取每一行的數據 var tmp = ""; var ...
//JS:
$("#btnInsert").click(function (e) {
var b = $("#txtMore").val()
var tmp1 = $("#txtMore").val().split("\n"); //過濾換行符,獲取每一行的數據
var tmp = "";
var a = "";
for (i = 0; i < tmp1.length; i++)
{
tmp1[i] = tmp1[i].replace(/\s+/g, ' '); //過濾字元串前面的空格
tmp1[i] = tmp1[i].replace(/(^\s*)|(\s*$)/g, ''); //過濾字元串中間的空格
tmp = tmp1[i].split(" ");//過濾空格,獲取每行裡面的三個數據
//下麵是對數據做判斷生成log提示用戶,還沒做全
if (tmp.length != 3) {
a += "第" + i + 1 + "行數據格式不正確!\n";
}
if (!tmp[2] == "" && tmp[2].length < 6)
a += "第" + i + 1 + "行第三個密碼長度必須超過6位\n";
}
if (a != "")
{
aler(a);
return false;
}
return true;
});
//c#:
try
{
BasePage_Common bp = new BasePage_Common();
if (string.IsNullOrEmpty(txtMore.Text))
{
MessageBox.Show(this, "批量用戶數據不能為空,請輸入用戶");
return;
}
var tmp1 = txtMore.Text.Split(new Char[] {'\r', '\n' },StringSplitOptions.RemoveEmptyEntries);
String[] tmp;
List<UserInfo_Base> List = new List<UserInfo_Base>();
for (var i = 0; i < tmp1.Length; i++)
{
var entity =ConversionHelper.NameValueCollectionToGeneric<UserInfo_Base>(Request.Form);
tmp1[i] = tmp1[i].ToString().Replace("\t", " ");
tmp1[i] = new Regex("[\\s]+").Replace(tmp1[i], " ");
tmp1[i] = tmp1[i].Trim();
tmp=tmp1[i].Split(' ');
if (tmp.Length!= 3)
throw new LogicError("非法訪問");//如果用戶跳過js驗證,說明是非法用戶
entity.TrueName = tmp[0].ToString();
entity.LoginName = tmp[1].ToString();
if (tmp[2].Length < 6)
throw new LogicError("密碼長度不能小於6位");
entity.LoginPWD = tmp[2].ToString();
List.Add(entity); //用List裝數據
}
var nentity = sys.Insert(Request.Url.ToString(), "systemuser", "systemuser_add", bp.UserIP, LoginUser.UserID, List); //因為採用的是多層架構所以直接調用DAL層,遍歷List執行插入操作,執行成功事務Commit;
if (nentity)
MessageBox.Show(this," ","添加成功","user.aspx");
}
catch (LogicError lgex)
{
LogHelper.Debug(lgex.Message);
MessageBox.Show(this, lgex.Message);
}