/// <summary>
        /// 绑定角色数据
        /// </summary>
        private void BindRoles()
        {
            DataSet ds = rolesbll.GetList("IsDelete = 1");

            ddlRoles.DataSource     = ds;
            ddlRoles.DataTextField  = "RoleName";
            ddlRoles.DataValueField = "ID";
            ddlRoles.DataBind();
        }
Beispiel #2
0
        /// <summary>
        /// 点击提交
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnSubmit_Click(object sender, EventArgs e)
        {
            if (tbRoleName.Text != "")
            {
                if (Request.QueryString["ID"] != null)
                {
                    var id = Convert.ToInt32(Request.QueryString["ID"]);
                    if (id > 0) // 修改
                    {
                        _systemRolesModel = _systemRolesBll.GetModel(int.Parse(Request.QueryString["ID"]));

                        _systemRolesModel.RoleName = tbRoleName.Text;
                        _systemRolesModel.Remarks  = tbRemarks.Text;

                        var actionStr = "";

                        foreach (Control item1 in MyMenus.Items)
                        {
                            // 页面checkbox集合对象
                            var myCheckBoxList = item1.FindControl("MyCheckBoxList") as CheckBoxList;

                            // 添加子项的权限
                            actionStr += ControlTools.GetStringFromCheckList(myCheckBoxList);
                        }

                        _systemRolesModel.Actionstr = actionStr;
                        _systemRolesBll.Update(_systemRolesModel);

                        // 写系统日志
                        AddSystemLog("用户修改角色信息,角色名为:" + tbRoleName.Text + ",权限字符串为:" + actionStr, "修改");

                        // 提示框
                        AlertAndParentSkip("角色信息修改成功!", "SystemRolesList.aspx");
                    }
                }
                else // 添加
                {
                    // 如果是新增,则要判断是否存在同名的角色名称
                    var ds = _systemRolesBll.GetList("RoleName='" + tbRoleName.Text + "'");

                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        Alert("该角色名已经存在,请更换其他名称!");
                    }
                    else
                    {
                        // 获取控件信息
                        _systemRolesModel.RoleName  = tbRoleName.Text;                                     // 角色名称
                        _systemRolesModel.Remarks   = tbRemarks.Text;                                      // 备注信息
                        _systemRolesModel.AddTime   = DateTime.Now.ToString(CultureInfo.InvariantCulture); // 添加时间
                        _systemRolesModel.AddPeople = Session["TrueName"].ToString();                      // 添加人真实姓名

                        var actionStr = "";

                        foreach (Control item1 in MyMenus.Items)
                        {
                            var checklist1 = item1.FindControl("MyCheckBoxList") as CheckBoxList;
                            actionStr += ControlTools.GetStringFromCheckList(checklist1);
                        }

                        _systemRolesModel.Actionstr = actionStr;
                        _systemRolesModel.IsDelete  = 1;
                        _systemRolesBll.Add(_systemRolesModel);

                        //写系统日志
                        AddSystemLog("用户添加角色信息,角色名为:" + tbRoleName.Text, "添加");

                        AlertAndParentSkip("角色信息添加成功!", "SystemRolesList.aspx");
                    }
                }
            }
            else
            {
                Alert("请输入角色名称!");
            }
        }