前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >ASP.NET MVC5+EF6+EasyUI 后台管理系统(22)-权限管理系统-模块导航制作

ASP.NET MVC5+EF6+EasyUI 后台管理系统(22)-权限管理系统-模块导航制作

作者头像
用户1149182
发布于 2018-01-16 06:31:14
发布于 2018-01-16 06:31:14
5.2K028
代码可运行
举报
运行总次数:28
代码可运行

最近比较忙,系统难度独步增加,文章的发布速度明显比以前慢了。

由于我们已经跑通了整个系统,所有东西都回到了简单,接下来我们做模块制作也就是操作SysModule表。

首先我们来回顾一下之前的难点主要就是SysRight这个表Rightflag字段的改变,这个字段关系导航与角色组的关系显示(即有权限时候显示菜单导航,这个更新讲到授权讲到,在这里浮头一下)

所以我们操作SysModule必须更新SysRight这张表,把模块先分配给角色

所以思路已经比较明显和简单了,这里我们模块将用treegrid来做,同时也间接学习怎么用treegrid,我之前也没用过easyui的datagrid,系统是jqgrid

这里用到权限控制了,所以你必须为SysModule添加增加,删除,修改等权限,并为admin用户授权,添加权限跳转到第十八讲 (必须非常熟练这一步,多用手动插入数据)

在此之前,由于我之前没用过treegrid不知道有个字段state(展开或者关闭属性)与数据库表SysModule的state字段冲突。然后更新EF

所以我们要修改一下SysModule的State变成Enable

添加后,我们依旧添加SysModule和SysModuleOperate模块的DAL BLL Model层代码(老套路了)

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using App.Models;

namespace App.IDAL
{
    public interface ISysModuleRepository
    {
        IQueryable<SysModule> GetList(DBContainer db);
        IQueryable<SysModule> GetModuleBySystem(DBContainer db,string parentId);
        int Create(SysModule entity);
        void Delete(DBContainer db, string id);
        int Edit(SysModule entity);
        SysModule GetById(string id);
        bool IsExist(string id);
    }
}
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using App.Models;
using App.IDAL;
using System.Data;

namespace App.DAL
{
    public class SysModuleRepository : IDisposable,ISysModuleRepository
    {
        public IQueryable<SysModule> GetList(DBContainer db)
        {
            IQueryable<SysModule> list = db.SysModule.AsQueryable();
            return list;
        }

        public IQueryable<SysModule> GetModuleBySystem(DBContainer db, string parentId)
        {
            return db.SysModule.Where(a => a.ParentId == parentId).AsQueryable();
        }

        public int Create(SysModule entity)
        {
            using (DBContainer db = new DBContainer())
            {
                db.SysModule.AddObject(entity);
                return db.SaveChanges();
            }
        }

        public void Delete(DBContainer db, string id)
        {
            SysModule entity = db.SysModule.SingleOrDefault(a => a.Id == id);
            if (entity != null)
            {
                
                //删除SysRight表数据
                var sr = db.SysRight.AsQueryable().Where(a=>a.ModuleId==id);
                foreach(var o in sr)
                {
                    //删除SysRightOperate表数据
                    var sro= db.SysRightOperate.AsQueryable().Where(a=>a.RightId==o.Id);
                    foreach(var o2 in sro)
                    {
                        db.SysRightOperate.DeleteObject(o2);
                    }
                    db.SysRight.DeleteObject(o);
                }
                //删除SysModuleOperate数据
                var smo = db.SysModuleOperate.AsQueryable().Where(a => a.ModuleId == id);
                foreach (var o3 in smo)
                {
                    db.SysModuleOperate.DeleteObject(o3);
                }
                db.SysModule.DeleteObject(entity);
            }
        }

        public int Edit(SysModule entity)
        {
            using (DBContainer db = new DBContainer())
            {
                db.SysModule.Attach(entity);
                db.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified);
                return db.SaveChanges();
            }
        }

        public SysModule GetById(string id)
        {
            using (DBContainer db = new DBContainer())
            {
                return db.SysModule.SingleOrDefault(a => a.Id == id);
            }
        }

        public bool IsExist(string id)
        {
            using (DBContainer db = new DBContainer())
            {
                SysModule entity = GetById(id);
                if (entity != null)
                    return true;
                return false;
            }
        }
        public void Dispose()
        {

        }
    }
}
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using App.Models;
using App.Common;
using App.Models.Sys;

namespace App.IBLL
{
    public interface ISysModuleBLL
    {
        List<SysModuleModel> GetList(string parentId);
        List<SysModule> GetModuleBySystem(string parentId);
        bool Create(ref ValidationErrors errors, SysModuleModel model);
        bool Delete(ref ValidationErrors errors, string id);
        bool Edit(ref ValidationErrors errors, SysModuleModel model);
        SysModuleModel GetById(string id);
        bool IsExist(string id);
    }
}
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using App.IBLL;
using Microsoft.Practices.Unity;
using App.IDAL;
using App.Models;
using App.BLL.Core;
using App.Common;
using System.Transactions;
using App.Models.Sys;
namespace App.BLL
{
    public class SysModuleBLL:BaseBLL, ISysModuleBLL
    {
        [Dependency]
        public ISysModuleRepository m_Rep { get; set; }


        public List<SysModuleModel> GetList(string parentId)
        {
            IQueryable<SysModule> queryData = null;
            queryData = m_Rep.GetList(db).Where(a => a.ParentId == parentId).OrderBy(a => a.Sort);
            return CreateModelList(ref queryData);
        }
        private List<SysModuleModel> CreateModelList(ref IQueryable<SysModule> queryData)
        {
            List<SysModuleModel> modelList = (from r in queryData
                                              select new SysModuleModel
                                              {
                                                  Id = r.Id,
                                                  Name = r.Name,
                                                  EnglishName = r.EnglishName,
                                                  ParentId = r.ParentId,
                                                  Url = r.Url,
                                                  Iconic = r.Iconic,
                                                  Sort = r.Sort,
                                                  Remark = r.Remark,
                                                  Enable = r.Enable,
                                                  CreatePerson = r.CreatePerson,
                                                  CreateTime = r.CreateTime,
                                                  IsLast = r.IsLast
                                              }).ToList();
            return modelList;
        }

   
        public List<SysModule> GetModuleBySystem(string parentId)
        {

            return m_Rep.GetModuleBySystem(db,parentId).ToList();
        }

        public bool Create(ref ValidationErrors errors, SysModuleModel model)
        {


            try
            {
                SysModule entity = m_Rep.GetById(model.Id);
                if (entity != null)
                {
                    errors.Add(Suggestion.PrimaryRepeat);
                    return false;
                }
                entity = new SysModule();
                entity.Id = model.Id;
                entity.Name = model.Name;
                entity.EnglishName = model.EnglishName;
                entity.ParentId = model.ParentId;
                entity.Url = model.Url;
                entity.Iconic = model.Iconic;
                entity.Sort = model.Sort;
                entity.Remark = model.Remark;
                entity.Enable = model.Enable;
                entity.CreatePerson = model.CreatePerson;
                entity.CreateTime = model.CreateTime;
                entity.IsLast = model.IsLast;
                if (m_Rep.Create(entity)==1)
                {
                    //分配给角色
                    db.P_Sys_InsertSysRight();
                    return true;
                }
                else
                {
                    errors.Add(Suggestion.InsertFail);
                    return false;
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return false;
            }

          
        }
        public bool Delete(ref ValidationErrors errors, string id)
        {
            try
            {
                //检查是否有下级
                if (db.SysModule.AsQueryable().Where(a=>a.SysModule2.Id==id).Count()>0)
                {
                    errors.Add("有下属关联,请先删除下属!");
                    return false;
                }
                m_Rep.Delete(db, id);
                if (db.SaveChanges() > 0)
                {
                    //清理无用的项
                    db.P_Sys_ClearUnusedRightOperate();
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return false;
            }
        }
        
        public bool Edit(ref ValidationErrors errors, SysModuleModel model)
        {
            try
            {
                SysModule entity = m_Rep.GetById(model.Id);
                if (entity == null)
                {
                    errors.Add(Suggestion.Disable);
                    return false;
                }
                entity.Name = model.Name;
                entity.EnglishName = model.EnglishName;
                entity.ParentId = model.ParentId;
                entity.Url = model.Url;
                entity.Iconic = model.Iconic;
                entity.Sort = model.Sort;
                entity.Remark = model.Remark;
                entity.Enable = model.Enable;
                entity.IsLast = model.IsLast;

                if (m_Rep.Edit(entity) == 1)
                {
                    return true;
                }
                else
                {
                    errors.Add(Suggestion.EditFail);
                    return false;
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return false;
            }
        }

        public SysModuleModel GetById(string id)
        {
            if (IsExist(id))
            {
                SysModule entity = m_Rep.GetById(id);
                SysModuleModel model = new SysModuleModel();
                model.Id = entity.Id;
                model.Name = entity.Name;
                model.EnglishName = entity.EnglishName;
                model.ParentId = entity.ParentId;
                model.Url = entity.Url;
                model.Iconic = entity.Iconic;
                model.Sort = entity.Sort;
                model.Remark = entity.Remark;
                model.Enable = entity.Enable;
                model.CreatePerson = entity.CreatePerson;
                model.CreateTime = entity.CreateTime;
                model.IsLast = entity.IsLast;
                return model;
            }
            else
            {
                return null;
            }
        }
        public bool IsExist(string id)
        {
            return m_Rep.IsExist(id);
        }
    }
}
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
//------------------------------------------------------------------------------
// <auto-generated>
//     此代码由T4模板自动生成
//       生成时间 2012-12-25 15:33:37 by App
//     对此文件的更改可能会导致不正确的行为,并且如果
//     重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.ComponentModel.DataAnnotations;

namespace App.Models.Sys
{

    public class SysModuleModel
    {
        [Display(Name = "ID")]
        public string Id { get; set; }
        [Display(Name = "名称")]
        public string Name { get; set; }

        [Display(Name = "别名")]
        public string EnglishName { get; set; }
        [Display(Name = "上级ID")]
        public string ParentId { get; set; }
        [Display(Name = "链接")]
        public string Url { get; set; }
        [Display(Name = "图标")]
        public string Iconic { get; set; }
        [Display(Name = "排序号")]
        public int? Sort { get; set; }
        [Display(Name = "说明")]
        public string Remark { get; set; }
        [Display(Name = "状态")]
        public bool Enable { get; set; }
        [Display(Name = "创建人")]
        public string CreatePerson { get; set; }
        [Display(Name = "创建时间")]
        public DateTime? CreateTime { get; set; }
        [Display(Name = "是否最后一项")]
        public bool IsLast { get; set; }

        public string state { get; set; }//treegrid

    }
}

-----------------------------------丑陋的分割线----------------------------------------

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
using App.Models;
using System.Linq;
namespace App.IDAL
{
    public interface ISysModuleOperateRepository
    {
        IQueryable<SysModuleOperate> GetList(DBContainer db);
        int Create(SysModuleOperate entity);
        int Delete(string id);
        SysModuleOperate GetById(string id);
        bool IsExist(string id);
    }
}
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
using System;
using System.Linq;
using App.Models;
using System.Data;
using App.IDAL;

namespace App.DAL
{
    public class SysModuleOperateRepository : ISysModuleOperateRepository, IDisposable
    {

        public IQueryable<SysModuleOperate> GetList(DBContainer db)
        {
            IQueryable<SysModuleOperate> list = db.SysModuleOperate.AsQueryable();
            return list;
        }

        public int Create(SysModuleOperate entity)
        {
            using (DBContainer db = new DBContainer())
            {
                db.SysModuleOperate.AddObject(entity);
                return db.SaveChanges();
            }
        }

        public int Delete(string id)
        {
            using (DBContainer db = new DBContainer())
            {
                SysModuleOperate entity = db.SysModuleOperate.SingleOrDefault(a => a.Id == id);
                if (entity != null)
                {

                    db.SysModuleOperate.DeleteObject(entity);
                }
                return db.SaveChanges();
            }
        }

        public SysModuleOperate GetById(string id)
        {
            using (DBContainer db = new DBContainer())
            {
                return db.SysModuleOperate.SingleOrDefault(a => a.Id == id);
            }
        }

        public bool IsExist(string id)
        {
            using (DBContainer db = new DBContainer())
            {
                SysModuleOperate entity = GetById(id);
                if (entity != null)
                    return true;
                return false;
            }
        }
        public void Dispose()
        {

        }
    }
}
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
using System.Collections.Generic;
using App.Common;
using App.Models.Sys;
namespace App.IBLL
{
    public interface ISysModuleOperateBLL
    {
        List<SysModuleOperateModel> GetList(ref GridPager pager, string queryStr);
        bool Create(ref ValidationErrors errors, SysModuleOperateModel model);
        bool Delete(ref ValidationErrors errors, string id);
        SysModuleOperateModel GetById(string id);
        bool IsExist(string id);
    }
}
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Practices.Unity;
using App.Models;
using App.Common;
using System.Transactions;
using App.Models.Sys;
using App.IBLL;
using App.IDAL;
using App.BLL.Core;

namespace App.BLL
{
    public class SysModuleOperateBLL : BaseBLL, ISysModuleOperateBLL
    {
        [Dependency]
        public ISysModuleOperateRepository m_Rep { get; set; }

        public List<SysModuleOperateModel> GetList(ref GridPager pager, string mid)
        {

            IQueryable<SysModuleOperate> queryData = m_Rep.GetList(db).Where(a => a.ModuleId == mid);
            pager.totalRows = queryData.Count();
            queryData = LinqHelper.SortingAndPaging(queryData, pager.sort, pager.order, pager.page, pager.rows);
            return CreateModelList(ref queryData);
        }
        private List<SysModuleOperateModel> CreateModelList(ref IQueryable<SysModuleOperate> queryData)
        {

            List<SysModuleOperateModel> modelList = (from r in queryData
                                                     select new SysModuleOperateModel
                                                     {
                                                         Id = r.Id,
                                                         Name = r.Name,
                                                         KeyCode = r.KeyCode,
                                                         ModuleId = r.ModuleId,
                                                         IsValid = r.IsValid,
                                                         Sort = r.Sort
                                                     }).ToList();
            return modelList;
        }

        public bool Create(ref ValidationErrors errors, SysModuleOperateModel model)
        {
            try
            {
                SysModuleOperate entity = m_Rep.GetById(model.Id);
                if (entity != null)
                {
                    errors.Add(Suggestion.PrimaryRepeat);
                    return false;
                }
                entity = new SysModuleOperate();
                entity.Id = model.Id;
                entity.Name = model.Name;
                entity.KeyCode = model.KeyCode;
                entity.ModuleId = model.ModuleId;
                entity.IsValid = model.IsValid;
                entity.Sort = model.Sort;
                if (m_Rep.Create(entity) == 1)
                {
                    return true;
                }
                else
                {
                    errors.Add(Suggestion.InsertFail);
                    return false;
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return false;
            }
        }

        public bool Delete(ref ValidationErrors errors, string id)
        {
            try
            {
                if (m_Rep.Delete(id) == 1)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return false;
            }
        }

        public bool IsExists(string id)
        {
            if (db.SysModuleOperate.SingleOrDefault(a => a.Id == id) != null)
            {
                return true;
            }
            return false;
        }

        public SysModuleOperateModel GetById(string id)
        {
            if (IsExist(id))
            {
                SysModuleOperate entity = m_Rep.GetById(id);
                SysModuleOperateModel model = new SysModuleOperateModel();
                model.Id = entity.Id;
                model.Name = entity.Name;
                model.KeyCode = entity.KeyCode;
                model.ModuleId = entity.ModuleId;
                model.IsValid = entity.IsValid;
                model.Sort = entity.Sort;
                return model;
            }
            else
            {
                return null;
            }
        }

        public bool IsExist(string id)
        {
            return m_Rep.IsExist(id);
        }
    }
}
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
//------------------------------------------------------------------------------
// <auto-generated>
//     此代码由T4模板自动生成
//       生成时间 2012-12-25 17:15:28 by App
//     对此文件的更改可能会导致不正确的行为,并且如果
//     重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.ComponentModel.DataAnnotations;

namespace App.Models.Sys
{

    public class SysModuleOperateModel
    {
        [Display(Name = "ID")]
        public string Id { get; set; }
        [Display(Name = "操作名称")]
        public string Name { get; set; }
        [Display(Name = "操作码")]
        public string KeyCode { get; set; }
        [Display(Name = "所属模块")]
        public string ModuleId { get; set; }
        [Display(Name = "是否验证")]
        public bool IsValid { get; set; }
        [Required(ErrorMessage = "{0}必须填写")]
        [Display(Name = "排序号")]
        public int Sort { get; set; }


    }
}

-----------------------------------丑陋的分割线----------------------------------------

在BaseController添加方法(获取当前页或操作访问权限)

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
/// <summary>
        /// 获取当前页或操作访问权限
        /// </summary>
        /// <returns>权限列表</returns>
        public List<permModel> GetPermission()
        {
            string filePath = HttpContext.Request.FilePath;

            List<permModel> perm = (List<permModel>)Session[filePath];
            return perm;
        }

控制器

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
//------------------------------------------------------------------------------
// <auto-generated>
//     此代码由T4模板自动生成
//       生成时间 2012-12-25 15:31:19 by YmNets
//     对此文件的更改可能会导致不正确的行为,并且如果
//     重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Microsoft.Practices.Unity;
using App.IBLL;
using App.Common;
using App.Models;
using App.Models.Sys;


namespace App.Admin.Controllers
{
    public class SysModuleController : BaseController
    {
        /// <summary>
        /// 业务层注入
        /// </summary>
        [Dependency]
        public ISysModuleBLL m_BLL { get; set; }
        [Dependency]
        public ISysModuleOperateBLL operateBLL { get; set; }
        ValidationErrors errors = new ValidationErrors();

        /// <summary>
        /// 主页
        /// </summary>
        /// <returns>视图</returns>
        [SupportFilter]
        public ActionResult Index()
        {
            ViewBag.Perm = GetPermission();
            return View();

        }
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="pager">分页</param>
        /// <param name="queryStr">查询条件</param>
        /// <returns></returns>
        [SupportFilter(ActionName = "Index")]
        [HttpPost]
        public JsonResult GetList(string id)
        {
            if (id == null)
                id = "0";
            List<SysModuleModel> list = m_BLL.GetList(id);
            var json = from r in list
                       select new SysModuleModel()
                       {
                           Id = r.Id,
                           Name = r.Name,
                           EnglishName = r.EnglishName,
                           ParentId = r.ParentId,
                           Url = r.Url,
                           Iconic = r.Iconic,
                           Sort = r.Sort,
                           Remark = r.Remark,
                           Enable = r.Enable,
                           CreatePerson = r.CreatePerson,
                           CreateTime = r.CreateTime,
                           IsLast = r.IsLast,
                           state = (m_BLL.GetList(r.Id).Count > 0) ? "closed" : "open"
                       };


            return Json(json);
        }

        [HttpPost]
        [SupportFilter(ActionName = "Index")]
        public JsonResult GetOptListByModule(GridPager pager, string mid)
        {
            pager.rows = 1000;
            pager.page = 1;
            List<SysModuleOperateModel> list = operateBLL.GetList(ref pager, mid);
            var json = new
            {
                total = pager.totalRows,
                rows = (from r in list
                        select new SysModuleOperateModel()
                        {
                    Id = r.Id,
                    Name = r.Name,
                    KeyCode = r.KeyCode,
                    ModuleId = r.ModuleId,
                    IsValid = r.IsValid,
                    Sort = r.Sort

                        }).ToArray()

            };

            return Json(json);
        }
            

        #region 创建模块
        [SupportFilter]
        public ActionResult Create(string id)
        {
            ViewBag.Perm = GetPermission();
            SysModuleModel entity = new SysModuleModel()
            {
                ParentId = id,
                Enable = true,
                Sort = 0
            };
            return View(entity);
        }

        [HttpPost]
        [SupportFilter]
        public JsonResult Create(SysModuleModel model)
        {
            model.Id = ResultHelper.NewId;
            model.CreateTime = ResultHelper.NowTime;
            model.CreatePerson = GetUserId();
            if (model != null && ModelState.IsValid)
            {

                if (m_BLL.Create(ref errors, model))
                {
                    LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",Name" + model.Name, "成功", "创建", "SysModule");
                    return Json(JsonHandler.CreateMessage(1, Suggestion.InsertSucceed));
                }
                else
                {
                    string ErrorCol = errors.Error;
                    LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",Name" + model.Name + "," + ErrorCol, "失败", "创建", "SysModule");
                    return Json(JsonHandler.CreateMessage(0, Suggestion.InsertFail + ErrorCol));
                }
            }
            else
            {
                return Json(JsonHandler.CreateMessage(0, Suggestion.InsertFail));
            }
        }
        #endregion


        #region 创建
        [SupportFilter(ActionName = "Create")]
        public ActionResult CreateOpt(string moduleId)
        {
            ViewBag.Perm = GetPermission();
            SysModuleOperateModel sysModuleOptModel = new SysModuleOperateModel();
            sysModuleOptModel.ModuleId = moduleId;
            sysModuleOptModel.IsValid = true;
            return View(sysModuleOptModel);
        }


        [HttpPost]
        [SupportFilter(ActionName = "Create")]
        public JsonResult CreateOpt(SysModuleOperateModel info)
        {
            if (info != null && ModelState.IsValid)
            {
                SysModuleOperateModel entity = operateBLL.GetById(info.Id);
                if (entity != null)
                    return Json(JsonHandler.CreateMessage(0, Suggestion.PrimaryRepeat), JsonRequestBehavior.AllowGet);
                entity = new SysModuleOperateModel();
                entity.Id = info.ModuleId + info.KeyCode;
                entity.Name = info.Name;
                entity.KeyCode = info.KeyCode;
                entity.ModuleId = info.ModuleId;
                entity.IsValid = info.IsValid;
                entity.Sort = info.Sort;

                if (operateBLL.Create(ref errors, entity))
                {
                    LogHandler.WriteServiceLog(GetUserId(), "Id:" + info.Id + ",Name:" + info.Name, "成功", "创建", "模块设置");
                    return Json(JsonHandler.CreateMessage(1, Suggestion.InsertSucceed), JsonRequestBehavior.AllowGet);
                }
                else
                {
                    string ErrorCol = errors.Error;
                    LogHandler.WriteServiceLog(GetUserId(), "Id:" + info.Id + ",Name:" + info.Name + "," + ErrorCol, "失败", "创建", "模块设置");
                    return Json(JsonHandler.CreateMessage(0, Suggestion.InsertFail + ErrorCol), JsonRequestBehavior.AllowGet);
                }
            }
            else
            {
                return Json(JsonHandler.CreateMessage(0, Suggestion.InsertFail), JsonRequestBehavior.AllowGet);
            }
        }
        #endregion

        #region 修改模块
        [SupportFilter]
        public ActionResult Edit(string id)
        {
            ViewBag.Perm = GetPermission();
            SysModuleModel entity = m_BLL.GetById(id);
            return View(entity);
        }

        [HttpPost]
        [SupportFilter]
        public JsonResult Edit(SysModuleModel model)
        {
            if (model != null && ModelState.IsValid)
            {
                if (m_BLL.Edit(ref errors, model))
                {
                    LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",Name" + model.Name, "成功", "修改", "系统菜单");
                    return Json(JsonHandler.CreateMessage(1, Suggestion.EditSucceed));
                }
                else
                {
                    string ErrorCol = errors.Error;
                    LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",Name" + model.Name + "," + ErrorCol, "失败", "修改", "系统菜单");
                    return Json(JsonHandler.CreateMessage(0, Suggestion.EditFail + ErrorCol));
                }
            }
            else
            {
                return Json(JsonHandler.CreateMessage(0, Suggestion.EditFail));
            }
        }
        #endregion

     

        #region 删除
        [HttpPost]
        [SupportFilter]
        public JsonResult Delete(string id)
        {
            if (!string.IsNullOrWhiteSpace(id))
            {
                if (m_BLL.Delete(ref errors, id))
                {
                    LogHandler.WriteServiceLog(GetUserId(), "Ids:" + id, "成功", "删除", "模块设置");
                    return Json(JsonHandler.CreateMessage(1, Suggestion.DeleteSucceed), JsonRequestBehavior.AllowGet);
                }
                else
                {
                    string ErrorCol = errors.Error;
                    LogHandler.WriteServiceLog(GetUserId(), "Id:" + id + "," + ErrorCol, "失败", "删除", "模块设置");
                    return Json(JsonHandler.CreateMessage(0, Suggestion.DeleteFail + ErrorCol), JsonRequestBehavior.AllowGet);
                }
            }
            else
            {
                return Json(JsonHandler.CreateMessage(0, Suggestion.DeleteFail), JsonRequestBehavior.AllowGet);
            }


        }


        [HttpPost]
        [SupportFilter(ActionName = "Delete")]
        public JsonResult DeleteOpt(string id)
        {
            if (!string.IsNullOrWhiteSpace(id))
            {
                if (operateBLL.Delete(ref errors, id))
                {
                    LogHandler.WriteServiceLog(GetUserId(), "Id:" + id, "成功", "删除", "模块设置KeyCode");
                    return Json(JsonHandler.CreateMessage(1, Suggestion.DeleteSucceed), JsonRequestBehavior.AllowGet);
                }
                else
                {
                    string ErrorCol = errors.Error;
                    LogHandler.WriteServiceLog(GetUserId(), "Id:" + id + "," + ErrorCol, "失败", "删除", "模块设置KeyCode");
                    return Json(JsonHandler.CreateMessage(0, Suggestion.DeleteFail + ErrorCol), JsonRequestBehavior.AllowGet);
                }
            }
            else
            {
                return Json(JsonHandler.CreateMessage(0, Suggestion.DeleteFail), JsonRequestBehavior.AllowGet);
            }


        }

        #endregion
    }
}

补充ExtendMvcHtml这个类的重载!来根据权限获取菜单

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using App.Models.Sys;
 
namespace App.Admin
{
    public static class ExtendMvcHtml
    {
        /// <summary>
        /// 权限按钮
        /// </summary>
        /// <param name="helper">htmlhelper</param>
        /// <param name="id">控件Id</param>
        /// <param name="icon">控件icon图标class</param>
        /// <param name="text">控件的名称</param>
        /// <param name="perm">权限列表</param>
        /// <param name="keycode">操作码</param>
        /// <param name="hr">分割线</param>
        /// <returns>html</returns>
        public static MvcHtmlString ToolButton(this HtmlHelper helper, string id, string icon, string text, List<permModel> perm, string keycode, bool hr)
        {
            if (perm.Where(a => a.KeyCode == keycode).Count() > 0)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("<a id=\"{0}\" style=\"float: left;\" class=\"l-btn l-btn-plain\">", id);
                sb.AppendFormat("<span class=\"l-btn-left\"><span class=\"l-btn-text {0}\" style=\"padding-left: 20px;\">", icon);
                sb.AppendFormat("{0}</span></span></a>", text);
                if (hr)
                {
                    sb.Append("<div class=\"datagrid-btn-separator\"></div>");
                }
                return new MvcHtmlString(sb.ToString());
            }
            else
            {
                return new MvcHtmlString("");
            }
        }
        /// <summary>
        /// 普通按钮
        /// </summary>
        /// <param name="helper">htmlhelper</param>
        /// <param name="id">控件Id</param>
        /// <param name="icon">控件icon图标class</param>
        /// <param name="text">控件的名称</param>
        /// <param name="hr">分割线</param>
        /// <returns>html</returns>
        public static MvcHtmlString ToolButton(this HtmlHelper helper, string id, string icon, string text, bool hr)
        {
 
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("<a id=\"{0}\" style=\"float: left;\" class=\"l-btn l-btn-plain\">", id);
            sb.AppendFormat("<span class=\"l-btn-left\"><span class=\"l-btn-text {0}\" style=\"padding-left: 20px;\">", icon);
            sb.AppendFormat("{0}</span></span></a>", text);
            if (hr)
            {
                sb.Append("<div class=\"datagrid-btn-separator\"></div>");
            }
            return new MvcHtmlString(sb.ToString());
 
        }
    }
}

视图

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
@using App.Admin;
@using App.Common;
@using App.Models.Sys;

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index_Layout.cshtml";

    List<permModel> perm = (List<permModel>)ViewBag.Perm;
    if (perm == null)
    {
        perm = new List<permModel>();
    }
}


<table>
    <tr>
        <td style="vertical-align:top">
            <div class="mvctool">
                @Html.ToolButton("btnCreate", "icon-add", "新增", perm, "Create", true)
                 @Html.ToolButton("btnEdit", "icon-edit", "编辑", perm, "Edit", true)
                @Html.ToolButton("btnDelete", "icon-remove", "删除", perm, "Delete", true)

            </div>

            <table id="List"></table>

        </td>
        <td style="width: 210px; padding-left: 5px; vertical-align:top">
            <div class="mvctool">
                @Html.ToolButton("btnCreateOpt", "icon-add", "新增操作码", perm, "Create", true)
                @Html.ToolButton("btnDeleteOpt", "icon-remove", "删除操作码", perm, "Delete", true)
            </div>


            <table id="OptList"></table>

        </td>
    </tr>
</table>

<div id="modalwindow" class="easyui-window" data-options="modal:true,closed:true,minimizable:false,shadow:false"></div>
<script type="text/javascript">
    $(function () {
        $('#List').treegrid({
            url: '@Url.Action("GetList")',
            width: $(window).width() - 270,
                methord: 'post',
                height: $(window).height() - 35,
                fitColumns: true,
                treeField: 'Name',
                idField: 'Id',
                pagination: false,
                striped: true, //奇偶行是否区分
                singleSelect: true,//单选模式
                //rownumbers: true,//行号
                columns: [[
                    { field: 'Id', title: '唯一标识', width: 120},
                    { field: 'Name', title: '名称', width: 220, sortable: true },
                    { field: 'EnglishName', title: '英文名称', width: 80, sortable: true,hidden:true },
                    { field: 'ParentId', title: '上级Id', width: 80, sortable: true },
                    { field: 'Url', title: '链接地址', width: 80, sortable: true },
                    { field: 'Iconic', title: '图标', width: 80, sortable: true },
                    { field: 'Sort', title: '排序号', width: 80, sortable: true },
                    { field: 'Remark', title: '说明', width: 80, sortable: true },
                     {
                         field: 'Enable', title: '是否启用', width: 60,align:'center', formatter: function (value) {
                             if (value) {
                                 return "<img src='/Content/Images/icon/pass.png'/>";
                             } else {
                                 return "<img src='/Content/Images/icon/no.png'/>";
                             }
                         }
                     },
                    { field: 'CreatePerson', title: '创建人', width: 80, sortable: true },
                    { field: 'CreateTime', title: '创建时间', width: 120, sortable: true },
                    {
                        field: 'IsLast', title: '是否最后一项', align: 'center', width: 100, formatter: function (value) {
                            if (value) {
                                return "是";
                            } else {
                                return "否";
                            }
                        }
                    },
                ]],
                onClickRow: function (index, data) {
                    var row = $('#List').treegrid('getSelected');
                    if (row != null) {
                        $('#OptList').datagrid({
                            url: '@Url.Action("GetOptListByModule")?mid=' + row.Id 
                        });
                    }
                }
            });
        $('#OptList').datagrid({
            url: '@Url.Action("GetOptListByModule")',
            width: 255,
            methord: 'post',
            height: $(window).height() - 35,
            fitColumns: true,
            sortName: 'Sort',
            sortOrder: 'asc',
            idField: 'Id',
            pageSize: 1000,
            pagination: false,
            striped: true, //奇偶行是否区分
            singleSelect: true,//单选模式
            //rownumbers: true,//行号
            columns: [[
                { field: 'Id', title: '', width: 80, hidden: true },
                { field: 'Name', title: '名称', width: 80, sortable: true },
                { field: 'KeyCode', title: '操作码', width: 80, sortable: true },
                { field: 'ModuleId', title: '所属模块', width: 80, sortable: true, hidden: true },
                 {
                     field: 'IsValid', title: '是否验证', width: 80, align: 'center', formatter: function (value) {
                         if (value) {
                             return "<img src='/Content/Images/icon/pass.png'/>";
                         } else {
                             return "<img src='/Content/Images/icon/no.png'/>";
                         }
                     }
                 },
                { field: 'Sort', title: '排序', width: 80, sortable: true }
            ]]
        });

        //自动宽高
        $(window).resize(function () {
            $('#List').datagrid('resize', {
                width: $(window).width() - 270,
                height: $(window).height() - 35
            }).datagrid('resize', {
                width: $(window).width() - 270,
                height: $(window).height() - 35
            });
            $('#OptList').datagrid('resize', {
                height: $(window).height() - 35
            }).datagrid('resize', {
                height: $(window).height() - 35
            });
        });
    });
    //ifram 返回
    function frameReturnByClose() {
        $("#modalwindow").window('close');
    }
    function frameReturnByReload(flag) {
        if (flag)
            $("#List").treegrid('reload');
        else
            $("#List").treegrid('load');
    }
    function frameReturnByReloadOpt(flag) {
        if (flag)
            $("#OptList").datagrid('load');
        else
            $("#OptList").datagrid('reload');
    }
    function frameReturnByMes(mes) {
        $.messageBox5s('提示', mes);
    }
    $(function () {
        $("#btnCreate").click(function () {
            var row = $('#List').treegrid('getSelected');
            $("#modalwindow").html("<iframe width='100%' height='98%' scrolling='no' frameborder='0'' src='/SysModule/Create?id=" + (row != null ? row.Id : "0") + "&Ieguid=" + GetGuid() + "'></iframe>");
            $("#modalwindow").window({ title: '新增', width: 700, height: 400, iconCls: 'icon-add' }).window('open');
        });
        $("#btnEdit").click(function () {
            var row = $('#List').treegrid('getSelected');
            if (row != null) {
                $("#modalwindow").html("<iframe width='100%' height='99%'  frameborder='0' src='/SysModule/Edit?id=" + row.Id + "&Ieguid=" + GetGuid() + "'></iframe>");
                $("#modalwindow").window({ title: '编辑', width: 700, height: 430, iconCls: 'icon-edit' }).window('open');
            } else { $.messageBox5s('提示', '@Suggestion.PlaseChooseToOperatingRecords'); }
        });
        $("#btnDelete").click(function () {
            var row = $('#List').treegrid('getSelected');
            if (row != null) {
                $.messager.confirm('提示', '@Suggestion.YouWantToDeleteTheSelectedRecords', function (r) {
                    if (r) {
                        $.post("@Url.Action("Delete")?id=" + row.Id, function (data) {
                            if (data.type == 1)
                                $("#List").treegrid('reload');
                            $.messageBox5s('提示', data.message);
                        }, "json");

                    }
                });
            } else { $.messageBox5s('提示', '@Suggestion.PlaseChooseToOperatingRecords'); }
        });

        $("#btnCreateOpt").click(function () {
            var row = $('#List').treegrid('getSelected');
            if (row != null) {
                if (row.IsLast) {
                    $("#modalwindow").html("<iframe width='100%' height='99%'  frameborder='0' src='/SysModule/CreateOpt?moduleId=" + row.Id + "&Ieguid=" + GetGuid() + "'></iframe>");
                    $("#modalwindow").window({ title: '新增操作码', width: 500, height: 330, iconCls: 'icon-edit' }).window('open');

                } else {
                    $.messageBox5s('提示', '只有最后一项的菜单才能设置操作码!');
                }
               
            } else { $.messageBox5s('提示', '请选择一个要赋予操作码的模块!'); }
         });
        $("#btnDeleteOpt").click(function () {
            var row = $('#OptList').datagrid('getSelected');
            if (row != null) {
                $.messager.confirm('提示', '您确定要删除“' + row.Name+ '”这个操作码?', function (r) {
                    if (r) {
                        $.post("@Url.Action("DeleteOpt")?id=" + row.Id, function (data) {
                            if (data.type == 1)
                            {
                                $("#OptList").datagrid('load');
                            }
                        }, "json");

                    }
                });
            } else { $.messageBox5s('提示', '请选择一个要赋予操作码的模块!'); }
         });
    });
</script>
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
@model App.Models.Sys.SysModuleModel
@using App.Common;
@using App.Models.Sys;
@using App.Admin;
@{
    ViewBag.Title = "修改";
    Layout = "~/Views/Shared/_Index_LayoutEdit.cshtml";
    List<permModel> perm = (List<permModel>)ViewBag.Perm;
    if (perm == null)
    {
        perm = new List<permModel>();
    }
}

<script type="text/javascript">
$(function () {
    $("#btnSave").click(function () {
        if ($("form").valid()) {
            $.ajax({
                url: "@Url.Action("Edit")",
                type: "Post",
                data: $("form").serialize(),
                dataType: "json",
                success: function (data) {
                    if (data.type == 1) {
                        window.parent.frameReturnByMes(data.message);
                        window.parent.frameReturnByReload(true);
                        window.parent.frameReturnByClose()
                    }
                    else {
                        window.parent.frameReturnByMes(data.message);
                    }
                }
            });
        }
        return false;
    });
    $("#btnReturn").click(function () {
         window.parent.frameReturnByClose();
    });
});
</script>
<div class="mvctool bgb">
@Html.ToolButton("btnSave", "icon-save", "保存", perm, "Save", true)
@Html.ToolButton("btnReturn", "icon-return", "返回",false)
</div>
@using (Html.BeginForm())
{
             @Html.HiddenFor(model => model.Id)
             @Html.HiddenFor(model => model.CreateTime)
             @Html.HiddenFor(model => model.CreatePerson)
 <table class="fromEditTable setTextWidth300">
    <tbody>
        <tr>
            <td style="width:100px; text-align:right;">
                @Html.LabelFor(model => model.Name)</td>
            <td style="width:310px">
                @Html.EditorFor(model => model.Name)
            </td>
            <td>@Html.ValidationMessageFor(model => model.Name)</td>
        </tr>
        <tr>
            <td style="width:100px; text-align:right;">
                @Html.LabelFor(model => model.ParentId)</td>
            <td style="width:310px">
                @Html.EditorFor(model => model.ParentId)
            </td>
            <td>@Html.ValidationMessageFor(model => model.ParentId)</td>
        </tr>
        <tr>
            <td style="width:100px; text-align:right;">
                @Html.LabelFor(model => model.Url)</td>
            <td style="width:310px">
                @Html.EditorFor(model => model.Url)
            </td>
            <td>@Html.ValidationMessageFor(model => model.Url)</td>
        </tr>
        <tr>
            <td style="width:100px; text-align:right;">
                @Html.LabelFor(model => model.Iconic)</td>
            <td style="width:310px">
                @Html.EditorFor(model => model.Iconic)
            </td>
            <td>@Html.ValidationMessageFor(model => model.Iconic)</td>
        </tr>
        <tr>
            <td style="width:100px; text-align:right;">
                @Html.LabelFor(model => model.Sort)</td>
            <td style="width:310px">
                @Html.EditorFor(model => model.Sort)
            </td>
            <td>@Html.ValidationMessageFor(model => model.Sort)</td>
        </tr>
        <tr>
            <td style="width:100px; text-align:right;">
                @Html.LabelFor(model => model.Remark)</td>
            <td style="width:310px">
                @Html.EditorFor(model => model.Remark)
            </td>
            <td>@Html.ValidationMessageFor(model => model.Remark)</td>
        </tr>
        <tr>
            <td style="width:100px; text-align:right;">
                @Html.LabelFor(model => model.Enable)</td>
            <td style="width:310px">
                @Html.CheckBoxFor(model => model.Enable)
            </td>
            <td>@Html.ValidationMessageFor(model => model.Enable)</td>
        </tr>

        <tr>
            <td style="width:100px; text-align:right;">
                @Html.LabelFor(model => model.IsLast)</td>
            <td style="width:310px">
                @Html.CheckBoxFor(model => model.IsLast)
            </td>
            <td>@Html.ValidationMessageFor(model => model.IsLast)</td>
        </tr>
       
    </tbody>
</table>
}
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
@model App.Models.Sys.SysModuleModel
@using App.Common;
@using App.Models.Sys;
@using App.Admin;
@{
    ViewBag.Title = "创建";
    Layout = "~/Views/Shared/_Index_LayoutEdit.cshtml";
    List<permModel> perm = (List<permModel>)ViewBag.Perm;
    if (perm == null)
    {
        perm = new List<permModel>();
    }
}

<script type="text/javascript">
    $(function () {
        $("#btnSave").click(function () {
            if ($("form").valid()) {
                $.ajax({
                    url: "@Url.Action("Create")",
                type: "Post",
                data: $("form").serialize(),
                dataType: "json",
                success: function (data) {
                    if (data.type == 1) {
                        window.parent.frameReturnByMes(data.message);
                        window.parent.frameReturnByReload(true);
                        window.parent.frameReturnByClose()
                    }
                    else {
                        window.parent.frameReturnByMes(data.message);
                    }
                }
            });
        }
        return false;
    });
    $("#btnReturn").click(function () {
        window.parent.frameReturnByClose();
    });
});
</script>
<div class="mvctool bgb">
@Html.ToolButton("btnSave", "icon-save", "保存", perm, "Save", true)
@Html.ToolButton("btnReturn", "icon-return", "返回",false)
</div>
@using (Html.BeginForm())
{
             @Html.HiddenFor(model => model.Id)
             @Html.HiddenFor(model => model.CreateTime)
 <table class="fromEditTable setTextWidth300">
    <tbody>
        <tr>
            <td style="width:100px; text-align:right;">
                @Html.LabelFor(model => model.Name)</td>
            <td style="width:310px">
                @Html.EditorFor(model => model.Name)
            </td>
            <td>@Html.ValidationMessageFor(model => model.Name)</td>
        </tr>
     
        <tr>
            <td style="width:100px; text-align:right;">
                @Html.LabelFor(model => model.ParentId)</td>
            <td style="width:310px">
                @Html.EditorFor(model => model.ParentId)
            </td>
            <td>@Html.ValidationMessageFor(model => model.ParentId)</td>
        </tr>
        <tr>
            <td style="width:100px; text-align:right;">
                @Html.LabelFor(model => model.Url)</td>
            <td style="width:310px">
                @Html.EditorFor(model => model.Url)
            </td>
            <td>@Html.ValidationMessageFor(model => model.Url)</td>
        </tr>
        <tr>
            <td style="width:100px; text-align:right;">
                @Html.LabelFor(model => model.Iconic)</td>
            <td style="width:310px">
                @Html.EditorFor(model => model.Iconic)
            </td>
            <td>@Html.ValidationMessageFor(model => model.Iconic)</td>
        </tr>
        <tr>
            <td style="width:100px; text-align:right;">
                @Html.LabelFor(model => model.Sort)</td>
            <td style="width:310px">
                @Html.EditorFor(model => model.Sort)
            </td>
            <td>@Html.ValidationMessageFor(model => model.Sort)</td>
        </tr>
        <tr>
            <td style="width:100px; text-align:right;">
                @Html.LabelFor(model => model.Remark)</td>
            <td style="width:310px">
                @Html.EditorFor(model => model.Remark)
            </td>
            <td>@Html.ValidationMessageFor(model => model.Remark)</td>
        </tr>
        <tr>
            <td style="width:100px; text-align:right;">
                @Html.LabelFor(model => model.Enable)</td>
            <td style="width:310px">
                @Html.CheckBoxFor(model => model.Enable,  new { @checked = true })
            </td>
            <td>@Html.ValidationMessageFor(model => model.Enable)</td>
        </tr>
    
        <tr>
            <td style="width:100px; text-align:right;">
                @Html.LabelFor(model => model.IsLast)</td>
            <td style="width:310px">
                @Html.CheckBoxFor(model => model.IsLast,  new { @checked = true })
            </td>
            <td>@Html.ValidationMessageFor(model => model.IsLast)</td>
        </tr>
       
    </tbody>
</table>
}
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
@model App.Models.Sys.SysModuleOperateModel
@using App.Common;
@using App.Models.Sys;
@using App.Admin;
@{
    ViewBag.Title = "创建";
    Layout = "~/Views/Shared/_Index_LayoutEdit.cshtml";
    List<permModel> perm = (List<permModel>)ViewBag.Perm;
    if (perm == null)
    {
        perm = new List<permModel>();
    }
}

<script type="text/javascript">
    $(function () {
        $("#btnSave").click(function () {
            if ($("form").valid()) {
                $.ajax({
                url: "@Url.Action("CreateOpt")",
                type: "Post",
                data: $("form").serialize(),
                dataType: "json",
                success: function (data) {
                    if (data.type == 1) {
                        window.parent.frameReturnByMes(data.message);
                        window.parent.frameReturnByReloadOpt(true);
                        window.parent.frameReturnByClose()
                    }
                    else {
                        window.parent.frameReturnByMes(data.message);
                    }
                }
            });
        }
        return false;
    });
    $("#btnReturn").click(function () {
        window.parent.frameReturnByClose();
    });
});
</script>
<div class="mvctool bgb">
@Html.ToolButton("btnSave", "icon-save", "保存", perm, "Save", true)
@Html.ToolButton("btnReturn", "icon-return", "返回",false)
</div>
@using (Html.BeginForm())
{
             @Html.HiddenFor(model => model.Id)
 <table class="fromEditTable setTextWidth300">
    <tbody>
        <tr>
            <td style="width:100px; text-align:right;">
                @Html.LabelFor(model => model.Name)</td>
            <td style="width:310px">
                @Html.EditorFor(model => model.Name)
            </td>
            <td>@Html.ValidationMessageFor(model => model.Name)</td>
        </tr>
        <tr>
            <td style="width:100px; text-align:right;">
                @Html.LabelFor(model => model.KeyCode)</td>
            <td style="width:310px">
                @Html.EditorFor(model => model.KeyCode)
            </td>
            <td>@Html.ValidationMessageFor(model => model.KeyCode)</td>
        </tr>
        <tr>
            <td style="width:100px; text-align:right;">
                @Html.LabelFor(model => model.ModuleId)</td>
            <td style="width:310px">
                @Html.TextBoxFor(model => model.ModuleId, new { @readOnly = "readOnly" })
            </td>
            <td>@Html.ValidationMessageFor(model => model.ModuleId)</td>
        </tr>
        <tr>
            <td style="width:100px; text-align:right;">
                @Html.LabelFor(model => model.IsValid)</td>
            <td style="width:310px">
                @Html.CheckBoxFor(model => model.IsValid,  new { @checked = true })
            </td>
            <td>@Html.ValidationMessageFor(model => model.IsValid)</td>
        </tr>
        <tr>
            <td style="width:100px; text-align:right;">
                @Html.LabelFor(model => model.Sort)</td>
            <td style="width:310px">
                @Html.EditorFor(model => model.Sort)
            </td>
            <td>@Html.ValidationMessageFor(model => model.Sort)</td>
        </tr>
    </tbody>
</table>
}

创建模块的DAL层用到了一个存储过程,这个存储过程就是分配模块给角色的,要添加到EF

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
USE [AppDB]
GO
/****** Object:  StoredProcedure [dbo].[P_Sys_InsertSysRight]    Script Date: 12/24/2013 23:10:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create proc [dbo].[P_Sys_InsertSysRight]
as
--将设置好的模块分配到角色组
    insert into SysRight(Id,ModuleId,RoleId,Rightflag)
        select distinct b.Id+a.Id,a.Id,b.Id,0 from SysModule a,SysRole b
        where a.Id+b.Id not in(select ModuleId+RoleId from SysRight)
        
        
        
    

后面补充一个存储过程,这个存储过程执行了清除无用的SysRightOperate(当每次删除角色或者模块,或者操作码时候会产生的垃圾),当然不清楚也不会对系统造成任何影响

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Create proc [dbo].[P_Sys_ClearUnusedRightOperate]
as
--清理权限中的无用项目
delete from SysRightOperate where Id not in(
    select a.RoleId+a.ModuleId+b.KeyCode from SysRight a,SysModuleOperate b
        where a.ModuleId = b.ModuleId
)
GO

 最后大家别忘记要注入!!!一个丑陋的界面就这样完成了,大家自己动手美化一下吧.

本节演示了Easyui制作菜单,即无限级别树的做法,以及DataGrid之间的联动,我也是和大家一起学习,我也是Easyui的新手,如有不足,请大家见谅

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2013-12-24 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
LLM 效果不好?可能是 Prompt 写错了!Prompt Engineering 技术的最全综述
生成式人工智能(GenAI)系统,特别是基于Transformer架构的大型语言模型(LLM),正在迅速崛起并被广泛应用于各个行业和研究领域。这些模型能够通过文本、图像、音频或视频等多种形式的“提示”(prompt)进行交互,并根据提示生成相应的文本、图像、音频或视频输出。 LLM 从撰写营销邮件到解决数学问题,其应用范围不断拓展。 但是,想要有效地利用LLM需要掌握提示工程(prompt engineering)技术,即设计和优化提示以获得最佳结果。 这门新兴领域正快速发展,新的提示技术层出不穷,但同时也面临着术语混乱和缺乏系统性理解等挑战。
Lion 莱恩呀
2025/04/04
8240
LLM 效果不好?可能是 Prompt 写错了!Prompt Engineering 技术的最全综述
Prompt工程师指南从基础到进阶篇:用于开发和优化提示,以有效地使用语言模型(LMs)进行各种应用和研究主题
Prompt工程是一种相对较新的学科,用于开发和优化提示,以有效地使用语言模型(LMs)进行各种应用和研究主题。Prompt工程技能有助于更好地理解大型语言模型(LLMs)的能力和局限性。研究人员使用Prompt工程来改善LLMs在各种常见和复杂任务上的能力,
汀丶人工智能
2023/05/14
3.7K1
Prompt工程师指南从基础到进阶篇:用于开发和优化提示,以有效地使用语言模型(LMs)进行各种应用和研究主题
提升ChatGPT性能的实用指南:Prompt Engineering的艺术
提示工程是一门新兴学科,就像是为大语言模型(LLM)设计的"语言游戏"。通过这个"游戏",我们可以更有效地引导 LLM 来处理问题。只有熟悉了这个游戏的规则,我们才能更清楚地认识到 LLM 的能力和局限。
腾讯技术工程官方号
2023/08/11
1.7K0
提升ChatGPT性能的实用指南:Prompt Engineering的艺术
Prompt Engineering:提示词工程最佳实践与应用
随着人工智能技术的不断发展,特别是大型语言模型(LLM)的兴起,提示词工程(Prompt Engineering)逐渐成为提升AI模型性能、增强任务执行效率的关键技术。Prompt Engineering通过设计和优化提示词(Prompt),引导LLM生成特定类型的输出,广泛应用于文本生成、数据增强、代码生成、问答系统等领域。本文将深入探讨Prompt Engineering的背景知识、功能点、优点、缺点,以及与市场其他技术的对比,并结合具体业务场景和底层原理,通过Java示例展示其实际应用。
小马哥学JAVA
2024/12/26
9100
提示工程(prompt engineering):技术分类与提示词调优看这篇就够了
在人工智能盛起的当下,出现了一个新兴的行业——提示工程(prompt engineering)。提示词,简言之,就是我们和AI说的话。在人机交互模式下,一个好的提示词,往往能产生事半功倍的效果。文本领域,好的提示词往往能超越RAG/Agent所能发挥的能力;图片对应的视觉领域,好的提示词往往能产生更好地图片/视觉效果。
山行AI
2024/04/30
4.6K0
提示工程(prompt engineering):技术分类与提示词调优看这篇就够了
Agent 应用于提示工程
如果Agent模仿了人类在现实世界中的操作方式,那么,能否应用于提示工程即Prompt Engingeering 呢?
半吊子全栈工匠
2023/10/30
5230
Agent 应用于提示工程
提示工程Prompt Engineering
上一篇大型语言模型LLM中,介绍了什么是LLM、LLM的基础内容,并提到LLM将利用词汇的分布生成文档。这一篇是关于提示和提示工程的介绍,主要内容是我们如何影响词汇的分布。
MySQLSE
2024/06/14
1380
提示工程Prompt Engineering
Prompt learning 教学[进阶篇]:简介Prompt框架并给出自然语言处理技术:Few-Shot Prompting、Self-Consistenc
看完基础篇的各种场景介绍后,你应该对 Prompt 有较深的理解。之前的章节我们讲的都是所谓的「术」,更多地集中讲如何用,但讲「道」的部分不多。高级篇除了会讲更高级的运用外,还会讲更多「道」的部分。高级篇的开篇,我们来讲一下构成 prompt 的框架。
汀丶人工智能
2023/05/12
2.3K0
解锁LLMs的“思考”能力:Chain-of-Thought(CoT) 技术推动复杂推理的新发展
Chain-of-Thought(CoT)是一种改进的Prompt技术,目的在于提升大模型LLMs在复杂推理任务上的表现,如算术推理(arithmetic reasoning)、常识推理(commonsense reasoning)、符号推理(symbolic reasoning)。
汀丶人工智能
2024/06/15
9280
解锁LLMs的“思考”能力:Chain-of-Thought(CoT) 技术推动复杂推理的新发展
一个通用的自适应prompt方法,突破了零样本学习的瓶颈
今天要给大家介绍一篇Google的研究,解决了大语言模型(LLMs)在零样本学习方面的困境。相比于少样本学习,LLMs在零样本学习上常常表现得比较弱,这主要是因为缺乏指导。而且,目前的研究对零样本学习的改进也不多,因为在没有真实标签的任务中设计prompt方法还比较困难。
zenRRan
2023/08/22
7970
一个通用的自适应prompt方法,突破了零样本学习的瓶颈
来啦来啦!关于CoT提示策略综述
思维链(CoT)是一个循序渐进、连贯的推理链,通常被用作大型语言模型(LLM)的提示策略并体现出了巨大的优势。近年来,基于CoT提示的展示出的效果吸引了众多的研究。
zenRRan
2023/10/14
1.3K0
来啦来啦!关于CoT提示策略综述
大语言模型的预训练[6]:思维链(Chain-of-thought,CoT)定义原理详解、Zero-shot CoT、Few-shot CoT 以及在LLM上应
在 2017-2019 年之间,随着 Transformer 模型的提出,计算资源与大规模语料库不断出现,自然语言处理领域发生了翻天覆地的变化,传统的全监督学习的范式逐渐达到了瓶颈,很难在传统的训练方式上取得大幅度提升。这时大规模预训练模型的如 Bert、RoBERTa 等模型的出现使得研究方向转向了以预训练模型为基础 + 下游任务 Fine-tune 的范式。
汀丶人工智能
2023/07/20
3.1K0
大语言模型的预训练[6]:思维链(Chain-of-thought,CoT)定义原理详解、Zero-shot CoT、Few-shot CoT 以及在LLM上应
不写代码也能年薪百万?Prompt+低代码开发实战
近期 AIGC 狂潮席卷,“前端走向穷途”“低代码时代终结”的言论甚嚣尘上。事实上 GPT 不仅不会干掉低代码,反而会大幅度促进低代码相关系统的开发。本文会介绍 GPT Prompt Engineering 的基本原理,以及如何帮助低代码平台相关技术快速开发落地的技术方案。接着往下看吧~
腾讯云开发者
2023/06/13
1.3K0
不写代码也能年薪百万?Prompt+低代码开发实战
提示词(prompt)工程指南(一):提示介绍
提示工程是一种相对较新的学科,专门用于开发和优化提示,以高效地使用语言模型(LM)来处理各种应用和研究主题。提示工程技能有助于更好地理解大型语言模型(LLMs)的能力和局限性。研究人员使用提示工程来提高LLMs在各种常见和复杂任务上的容量,例如问题解答和算术推理。开发人员使用提示工程来设计与LLMs和其他工具接口的强大而有效的提示技术。
云微
2023/03/31
2.3K0
AI在线求鼓励?这些人一句话让GPT-3算术准确率提升61%
机器之心报道 编辑:张倩、小舟 GPT-3 对一些问题的回答令人大跌眼镜,但它可能只是想要一句「鼓励」。 「一个玩杂耍的人总共有 16 个球,其中一半是高尔夫球,高尔夫球中又有一半是蓝色的球,请问蓝球总共有多少个?」 对于一个小学生来说,这是一道再简单不过的数学题。但看似无所不能的 GPT-3 却被这道题难住了。 如果你输入这个问题之后,直接向 GPT-3 发问:「问题的答案(阿拉伯数字)是:__?」它会「不假思索」地给出一个错误答案:8。 GPT-3:你别说准不准,你就说快不快吧。 怎么能让 GPT-
机器之心
2022/05/27
8980
AI在线求鼓励?这些人一句话让GPT-3算术准确率提升61%
提示词(prompt)工程指南(三):高级提示
到此为止,已经很明显完善提示有助于在不同任务上获得更好的结果。这就是提示工程的整体理念。
云微
2023/03/31
1.7K0
大模型Prompt-Tuning技术进阶
近两年来,随之Prompt-Tuning技术的发展,有诸多工作发现,对于超过10亿参数量的模型来说,Prompt-Tuning所带来的增益远远高于标准的Fine-tuning,小样本甚至是零样本的性能也能够极大地被激发出来,得益于这些模型的 参数量足够大 ,训练过程中使用了 足够多的语料 ,同时设计的 预训练任务足够有效 。最为经典的大规模语言模型则是2020年提出的GPT-3,其拥有大约1750亿的参数,且发现只需要设计合适的模板或指令即可以 实现免参数训练的零样本学习 。
@小森
2024/06/06
3910
大模型Prompt-Tuning技术进阶
Google | 提出CoT解码新方法,无需Prompt,就能让大模型(LLM)进行CoT推理
在增强大语言模型(LLM)的推理能力方面,先前的研究主要集中在特定的Prompt技术上,例如少样本(Few-shot)或零样本(Zero-shot)思维链(CoT)提示。这些方法虽然有效,但通常涉及手工密集型Prompt工程。
ShuYini
2024/02/22
6800
Google | 提出CoT解码新方法,无需Prompt,就能让大模型(LLM)进行CoT推理
99%的普通人不会用的AI沟通术:揭秘我与AI对话的沟通技巧
Prompt Engineering(提示工程)作为与 LLM 交互的关键技术,正逐渐成为连接人类需求与模型能力的桥梁。
AIGC新知
2025/04/13
1710
99%的普通人不会用的AI沟通术:揭秘我与AI对话的沟通技巧
LLM最全「怪癖」首曝光!马里兰OpenAI等30+学者祭出75页提示报告
最近,来自马里兰大学、OpenAI、斯坦福、微软等12所机构的30多名研究者,首次对LLM的提示技术进行了大规模的系统研究,并发布了一份长达75页的详尽报告。
新智元
2024/06/17
1120
LLM最全「怪癖」首曝光!马里兰OpenAI等30+学者祭出75页提示报告
推荐阅读
LLM 效果不好?可能是 Prompt 写错了!Prompt Engineering 技术的最全综述
8240
Prompt工程师指南从基础到进阶篇:用于开发和优化提示,以有效地使用语言模型(LMs)进行各种应用和研究主题
3.7K1
提升ChatGPT性能的实用指南:Prompt Engineering的艺术
1.7K0
Prompt Engineering:提示词工程最佳实践与应用
9100
提示工程(prompt engineering):技术分类与提示词调优看这篇就够了
4.6K0
Agent 应用于提示工程
5230
提示工程Prompt Engineering
1380
Prompt learning 教学[进阶篇]:简介Prompt框架并给出自然语言处理技术:Few-Shot Prompting、Self-Consistenc
2.3K0
解锁LLMs的“思考”能力:Chain-of-Thought(CoT) 技术推动复杂推理的新发展
9280
一个通用的自适应prompt方法,突破了零样本学习的瓶颈
7970
来啦来啦!关于CoT提示策略综述
1.3K0
大语言模型的预训练[6]:思维链(Chain-of-thought,CoT)定义原理详解、Zero-shot CoT、Few-shot CoT 以及在LLM上应
3.1K0
不写代码也能年薪百万?Prompt+低代码开发实战
1.3K0
提示词(prompt)工程指南(一):提示介绍
2.3K0
AI在线求鼓励?这些人一句话让GPT-3算术准确率提升61%
8980
提示词(prompt)工程指南(三):高级提示
1.7K0
大模型Prompt-Tuning技术进阶
3910
Google | 提出CoT解码新方法,无需Prompt,就能让大模型(LLM)进行CoT推理
6800
99%的普通人不会用的AI沟通术:揭秘我与AI对话的沟通技巧
1710
LLM最全「怪癖」首曝光!马里兰OpenAI等30+学者祭出75页提示报告
1120
相关推荐
LLM 效果不好?可能是 Prompt 写错了!Prompt Engineering 技术的最全综述
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档