示例#1
0
        /// <summary>
        /// 更新角色,功能关系
        /// </summary>
        protected void updateFunction()
        {
            string value = "", values = "", sqlText = "";
            int    count    = Convert.ToInt32(Request["rows"]);
            int    roleId   = Convert.ToInt32(Request["roleId"]);
            string roleName = Request["roleName"];
            string oldName  = Request["oldName"];
            string funIds   = Request["funIds"];

            if (oldName != roleName)
            {
                if (userBll.IsDelete("T_User", "roleId", roleId.ToString()) == Result.关联引用)
                {
                    Response.Write("该数据在其他表中被引用,不可编辑");
                    Response.End();
                }
                else
                {
                    //批量删除
                    Result del = roleBll.DeletePer(roleId, count);
                    if (del == Result.除成功)
                    {
                        string   func      = funIds.Substring(0, funIds.Length - 1);
                        string[] functions = func.Split('?');
                        for (int i = 0; i < functions.Length; i++)
                        {
                            int functionId = Convert.ToInt32(functions[i]);
                            value  = "(" + roleId + "," + functionId + "),";
                            values = values + value;
                        }
                        sqlText = values.Substring(0, values.Length - 1);
                        Result inserts = roleBll.InsertPer(sqlText, roleId, "更新");
                        if (inserts == Result.添加失败)
                        {
                            Response.Write("更新失败");
                            Response.End();
                        }
                        else
                        {
                            Role role = new Role();
                            role.RoleId   = Convert.ToInt32(roleId);
                            role.RoleName = roleName;
                            Result edit = roleBll.Update(role);
                            if (edit == Result.更新成功)
                            {
                                Response.Write("更新成功");
                                Response.End();
                            }
                            else
                            {
                                Response.Write("更新失败");
                                Response.End();
                            }
                        }
                    }
                    else
                    {
                        Response.Write("更新失败");
                        Response.End();
                    }
                }
            }
            else
            {
                //批量删除
                Result del = roleBll.DeletePer(roleId, count);
                if (del == Result.除成功)
                {
                    string   func      = funIds.Substring(0, funIds.Length - 1);
                    string[] functions = func.Split('?');
                    for (int i = 0; i < functions.Length; i++)
                    {
                        int functionId = Convert.ToInt32(functions[i]);
                        value  = "(" + roleId + "," + functionId + "),";
                        values = values + value;
                    }
                    sqlText = values.Substring(0, values.Length - 1);
                    Result inserts = roleBll.InsertPer(sqlText, roleId, "更新");
                    if (inserts == Result.添加失败)
                    {
                        Response.Write("更新失败");
                        Response.End();
                    }
                    else
                    {
                        Response.Write("更新成功");
                        Response.End();
                    }
                }
                else
                {
                    Response.Write("更新失败");
                    Response.End();
                }
            }
        }