using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using Autofac; using EMIS.Entities; using EMIS.Utility; using EMIS.CommonLogic.SystemServices; using Bowin.Common; using Bowin.Web.Controls.Mvc; using System.Text; namespace EMIS.Web.Controls { public static class ContextMenuBarExtensions { /// /// 工具栏控件,列出当前登录用户有权限操作的按钮,需要通过数据库配置 /// /// /// 页面标识,同一菜单内的不同页面可通过该字段区分,对应数据库中的FormClass字段 /// public static MvcHtmlString ContextMenuBar(this HtmlHelper htmlHelper, string formClass) { var contextMenuBarId = "div_" + Guid.NewGuid().ToString().Replace("-", ""); HttpRequest request = HttpContext.Current.Request; var sb = new StringBuilder(); sb.AppendLine("
"); sb.AppendLine("
"); sb.Append(""); return MvcHtmlString.Create(sb.ToString()); } //public static MvcHtmlString ContextMenuBar(this HtmlHelper htmlHelper, string formClass, // ToolbarOptions toolbarOptions = null, // System.Collections.Generic.IDictionary htmlAttributes = null) //{ // BaseExtensions.GetContextUser(); // if (toolbarOptions == null) // { // toolbarOptions = new ToolbarOptions(); // } // GetContextMenuList(formClass).ToList().ForEach(x => toolbarOptions.ButtonList.Add(new ToolbarButton() // { // Name = x.ContextMnuNo, // Text = x.Title, // Icon = x.IconName, // OnClick = x.Scripts // })); // return MvcHtmlString.Create(Bowin.Web.Controls.Mvc.Toolbar.CreateControl(toolbarOptions, htmlAttributes).Render()); //} private static IList GetContextMenuList(string formClass) { var user = HttpContext.Current.User as EMIS.Utility.FormValidate.CustomPrincipal; using (var scop = AutofacHelper.Container.BeginLifetimeScope()) { IContextMenuServices ContextMenuServices = scop.Resolve(); HttpRequest request = HttpContext.Current.Request; var contextMenuList = ContextMenuServices.GetContextMenuListByUserAndRoleID(request["MNU"], formClass, user.UserID, user.RoleID); return contextMenuList.OrderBy(x => x.SeqNo).ToList(); } } } }