/// <summary> /// 添加至权限组按钮事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void ButtonAddToGroup_Click(object sender, EventArgs e) { if (DropDownListGroup.SelectedValue == "0") { //提示请选择要添加的用户组 Show(Page, "请选择要添加到的权限组"); return; } WebBean bean = WebBean.GetInstance(); int count = 0; foreach (RepeaterItem item in Repeater1.Items) { if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem) { var chk = (CheckBox)item.FindControl("CheckBoxItemID"); if (chk.Checked) { count++; var hf = (HiddenField)item.FindControl("HiddenFieldGUID"); bean.AddUserToUserGroup(hf.Value, DropDownListGroup.SelectedValue, !RadioButtonIsTrue.Checked); } } } if (count > 0) { Show(Page, "添加成功!"); DataBind(); } else { //提示请选择要添加的用户 Show(Page, "请选择要添加的用户"); } }
/// <summary> /// 保存按钮事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void ButtonSave_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(TextBoxAccount.Text.Trim()) || String.IsNullOrEmpty(TextBoxUserName.Text.Trim())) { return; } if (RadioButtonListBan.SelectedItem == null) { return; } UserDataModel userDataModel = new UserDataModel { GUID = String.IsNullOrEmpty(UserGuid)?Guid.NewGuid().ToString():UserGuid, Account = TextBoxAccount.Text.Trim(), UserName = TextBoxUserName.Text.Trim(), Password = "******", Ban = RadioButtonListBan.SelectedItem.Value == "0" }; try { WebBean bean = WebBean.GetInstance(); bean.AddOrUpdateUser(userDataModel, string.IsNullOrEmpty(UserGuid)?"add":"update"); //如果用户组信息 bean.AddUserToUserGroup(UserGuid, string.Empty, false); foreach (ListItem item in CheckBoxListUserGroups.Items) { if (item.Selected) { bean.AddUserToUserGroup(userDataModel.GUID, item.Value, true); } } //if (CheckBoxListUserGroups.SelectedItem != null && DropDownListUserGroup.SelectedValue != "0") //{ // bean.AddUserToUserGroup(userDataModel.GUID, DropDownListUserGroup.SelectedValue, true); //} } catch (Exception ex) { WriteLog.WriteExceptionLog(ex.ToString()); } }
/// <summary> /// 行点击事件 /// </summary> /// <param name="source"></param> /// <param name="e"></param> protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e) { WebBean bean = WebBean.GetInstance(); if (e.CommandName == "action") { List <String> args = e.CommandArgument.ToString().Split(',').ToList(); if (args.Count <= 0) { return; } bean.ChangeUserState(args[0], Convert.ToBoolean(args[1])); DataBind(); } if (e.CommandName == "delete") { string arg = e.CommandArgument.ToString().Trim(); bean.AddUserToUserGroup(arg, string.Empty, false); bean.DeleteUserData(arg); DataBind(); } }