protected void btnSure_Click(object sender, EventArgs e) { User ull = new User(); if (ull.UpdateUserGroup((List <object>)Session["UserIDList"], Convert.ToInt32(ddlUserGroup.SelectedValue))) { JSHelper.AlertAndCloseModalWin("更新成功!", this); } else { JSHelper.Alert("更新失败!", this); } }
protected void btnSave_Click(object sender, EventArgs e) { if (lstSelectedRole.Items.Count > 0) { foreach (var uid in (List <object>)Session["UserIDList"]) { txtTRole.Text = ""; BindRole(uid.ToString()); foreach (ListItem item in lstSelectedRole.Items) { txtTRole.Text += item.Value + ","; } User bll = new User(); List <string> ar = new List <string>(); //添加表 List <string> dr = new List <string>(); //删除表 string s = txtTRole.Text; if (s != "") { string[] str = s.Substring(0, s.Length - 1).Split(','); string[] ostr = txtOldRole.Text.ToString().Split(','); for (int i = 0; i < str.Length; i++) { if (!TypeParse.IsStringArray(str[i], ostr)) { //不存在则添加到插入记录列表 ar.Add(uid.ToString() + "," + str[i]); } } for (int i = 0; i < ostr.Length; i++) { if (!TypeParse.IsStringArray(ostr[i], str)) { //不存在则添加到删除记录列表 dr.Add(uid.ToString() + "," + ostr[i]); } } } else { //如果提交角色为空则删除该用户的所有角色 string[] ostr = txtOldRole.Text.ToString().Split(','); for (int i = 0; i < ostr.Length; i++) { //不存在则添加到删除记录列表 dr.Add(uid.ToString() + "," + ostr[i]); } } try { if (ar.Count != 0) { bll.AddUserRole(ar); } if (dr.Count != 0) { bll.DeleteUserRole(dr); } JSHelper.AlertAndCloseModalWin("更新成功!", this); } catch { JSHelper.Alert("角色修改失败!", this); } } } else { JSHelper.Alert("请至少选择一个角色!", this); } }