ContextMenuBarExtensions.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using Autofac;
  7. using EMIS.Entities;
  8. using EMIS.Utility;
  9. using EMIS.CommonLogic.SystemServices;
  10. using Bowin.Common;
  11. using Bowin.Web.Controls.Mvc;
  12. using System.Text;
  13. namespace EMIS.Web.Controls
  14. {
  15. public static class ContextMenuBarExtensions
  16. {
  17. /// <summary>
  18. /// 工具栏控件,列出当前登录用户有权限操作的按钮,需要通过数据库配置
  19. /// </summary>
  20. /// <param name="htmlHelper"></param>
  21. /// <param name="formClass">页面标识,同一菜单内的不同页面可通过该字段区分,对应数据库中的FormClass字段</param>
  22. /// <returns></returns>
  23. public static MvcHtmlString ContextMenuBar(this HtmlHelper htmlHelper, string formClass)
  24. {
  25. var contextMenuBarId = "div_" + Guid.NewGuid().ToString().Replace("-", "");
  26. HttpRequest request = HttpContext.Current.Request;
  27. var sb = new StringBuilder();
  28. sb.AppendLine("<div id=\"" + contextMenuBarId + "\" class=\"current_navbar toolbar\"> <div class=\"func_info\">");
  29. sb.AppendLine("</div></div>");
  30. sb.Append("<script type = \"text/javascript\" language = \"javascript\"> $(function () { EMISFunction.LoadContextMenuBar('" + contextMenuBarId + "','" + formClass + "','" + request["MNU"] + "'); });</script>");
  31. return MvcHtmlString.Create(sb.ToString());
  32. }
  33. //public static MvcHtmlString ContextMenuBar(this HtmlHelper htmlHelper, string formClass,
  34. // ToolbarOptions toolbarOptions = null,
  35. // System.Collections.Generic.IDictionary<string, string> htmlAttributes = null)
  36. //{
  37. // BaseExtensions.GetContextUser();
  38. // if (toolbarOptions == null)
  39. // {
  40. // toolbarOptions = new ToolbarOptions();
  41. // }
  42. // GetContextMenuList(formClass).ToList().ForEach(x => toolbarOptions.ButtonList.Add(new ToolbarButton()
  43. // {
  44. // Name = x.ContextMnuNo,
  45. // Text = x.Title,
  46. // Icon = x.IconName,
  47. // OnClick = x.Scripts
  48. // }));
  49. // return MvcHtmlString.Create(Bowin.Web.Controls.Mvc.Toolbar.CreateControl(toolbarOptions, htmlAttributes).Render());
  50. //}
  51. private static IList<Sys_ContextMenu> GetContextMenuList(string formClass)
  52. {
  53. var user = HttpContext.Current.User as EMIS.Utility.FormValidate.CustomPrincipal;
  54. using (var scop = AutofacHelper.Container.BeginLifetimeScope())
  55. {
  56. IContextMenuServices ContextMenuServices = scop.Resolve<IContextMenuServices>();
  57. HttpRequest request = HttpContext.Current.Request;
  58. var contextMenuList = ContextMenuServices.GetContextMenuListByUserAndRoleID(request["MNU"], formClass, user.UserID, user.RoleID);
  59. return contextMenuList.OrderBy(x => x.SeqNo).ToList();
  60. }
  61. }
  62. }
  63. }