示例#1
0
    /// <summary>
    /// 提交角色信息
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btRoleAdd_Click(object sender, EventArgs e)
    {
        ROLE myrole = new ROLE();

        myrole.ROLENAME        = this.tb_rolename.Text;
        myrole.ROLEDESCRIPTION = this.tb_rolediscription.Text;
        //判断数据库里面是否存在改名称
        if (myrole.Exists(this.tb_rolename.Text))
        {
            Response.Write(MessageBox.Show("角色" + this.tb_rolename.Text + ":已经存在请重新输入其他的角色名称!"));
            this.tb_rolename.Text        = "";
            this.tb_rolediscription.Text = "";
        }
        else
        {
            myrole.Add();

            //查询出ROLEID
            string selectRoleId = "SELECT ROLEID FROM ROLE WHERE ROLENAME='" + this.tb_rolename.Text + "'";
            int    myroleid     = Convert.ToInt16(DbHelperSQL.GetSingle(selectRoleId));
            //建立关系
            Authority myAuthority = new Authority();
            //设立关系中的 角色id
            myAuthority.ROLEID = myroleid;
            for (int i = 0; i < this.cbl_quanxian.Items.Count; i++)
            {
                //设立关系中的权限id
                myAuthority.MODULEID = Convert.ToInt16(this.cbl_quanxian.Items[i].Value);
                //添加关系入数据库
                myAuthority.Add();
            }
            //添加完毕
            Response.Write(MessageBox.Show("添加成功!"));
        }
    }