12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- 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
- {
- /// <summary>
- /// 工具栏控件,列出当前登录用户有权限操作的按钮,需要通过数据库配置
- /// </summary>
- /// <param name="htmlHelper"></param>
- /// <param name="formClass">页面标识,同一菜单内的不同页面可通过该字段区分,对应数据库中的FormClass字段</param>
- /// <returns></returns>
- 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("<div id=\"" + contextMenuBarId + "\" class=\"current_navbar toolbar\"> <div class=\"func_info\">");
- sb.AppendLine("</div></div>");
- sb.Append("<script type = \"text/javascript\" language = \"javascript\"> $(function () { EMISFunction.LoadContextMenuBar('" + contextMenuBarId + "','" + formClass + "','" + request["MNU"] + "'); });</script>");
- return MvcHtmlString.Create(sb.ToString());
- }
- //public static MvcHtmlString ContextMenuBar(this HtmlHelper htmlHelper, string formClass,
- // ToolbarOptions toolbarOptions = null,
- // System.Collections.Generic.IDictionary<string, string> 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<Sys_ContextMenu> GetContextMenuList(string formClass)
- {
- var user = HttpContext.Current.User as EMIS.Utility.FormValidate.CustomPrincipal;
- using (var scop = AutofacHelper.Container.BeginLifetimeScope())
- {
- IContextMenuServices ContextMenuServices = scop.Resolve<IContextMenuServices>();
- HttpRequest request = HttpContext.Current.Request;
- var contextMenuList = ContextMenuServices.GetContextMenuListByUserAndRoleID(request["MNU"], formClass, user.UserID, user.RoleID);
- return contextMenuList.OrderBy(x => x.SeqNo).ToList();
- }
- }
- }
- }
|