CheckListExtentions.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 Bowin.Web.Controls.Mvc;
  8. using EMIS.Utility;
  9. using EMIS.CommonLogic.AdministrativeOrgan;
  10. using EMIS.CommonLogic.SystemServices;
  11. using EMIS.ViewModel;
  12. namespace EMIS.Web.Controls
  13. {
  14. public static class CheckListExtentions
  15. {
  16. public static MvcHtmlString UserCampusList(this HtmlHelper htmlHelper,
  17. ListControlOptions listControlOptions, Guid userID,
  18. System.Collections.Generic.IDictionary<string, string> htmlAttributes = null)
  19. {
  20. using (var scope = AutofacHelper.Container.BeginLifetimeScope())
  21. {
  22. ICampusServices CampusServices = scope.Resolve<ICampusServices>();
  23. IUserServices UserServices = scope.Resolve<IUserServices>();
  24. var campusList = CampusServices.GetCampusListWithoutDataRange().Select(x => new ListControlItem { Text = x.Name, Value = x.CampusID });
  25. var userCampusList = UserServices.GetUserInchargeCampus(userID);
  26. listControlOptions.ItemList = campusList.ToList();
  27. listControlOptions.SelectedValues = userCampusList.Select(x => (object)x.CampusID).ToList();
  28. }
  29. return MvcHtmlString.Create(Bowin.Web.Controls.Mvc.CheckList.CreateControl(listControlOptions, htmlAttributes).Render());
  30. }
  31. public static MvcHtmlString UserCollegeList(this HtmlHelper htmlHelper,
  32. ListControlOptions listControlOptions, Guid userID,
  33. System.Collections.Generic.IDictionary<string, string> htmlAttributes = null)
  34. {
  35. using (var scope = AutofacHelper.Container.BeginLifetimeScope())
  36. {
  37. ICollegeServices CollegeServices = scope.Resolve<ICollegeServices>();
  38. IUserServices UserServices = scope.Resolve<IUserServices>();
  39. var collegeList = CollegeServices.GetCollegeViewListWithoutDataRange().Select(x => new ListControlItem { Text = x.Name, Value = x.CollegeID });
  40. var userCollegeList = UserServices.GetUserInchargeCollege(userID);
  41. listControlOptions.ItemList = collegeList.ToList();
  42. listControlOptions.SelectedValues = userCollegeList.Select(x => (object)x.CollegeID).ToList();
  43. }
  44. return MvcHtmlString.Create(Bowin.Web.Controls.Mvc.CheckList.CreateControl(listControlOptions, htmlAttributes).Render());
  45. }
  46. public static MvcHtmlString UserDepartmentList(this HtmlHelper htmlHelper,
  47. ListControlOptions listControlOptions, Guid userID,
  48. System.Collections.Generic.IDictionary<string, string> htmlAttributes = null)
  49. {
  50. using (var scope = AutofacHelper.Container.BeginLifetimeScope())
  51. {
  52. IDepartmentServices DepartmentServices = scope.Resolve<IDepartmentServices>();
  53. IUserServices UserServices = scope.Resolve<IUserServices>();
  54. var departmentList = DepartmentServices.GetDepartmentList().Select(x => new ListControlItem { Text = x.Name, Value = x.DepartmentID });
  55. var userDepartmentList = UserServices.GetUserInchargeDepartment(userID);
  56. listControlOptions.ItemList = departmentList.ToList();
  57. listControlOptions.SelectedValues = userDepartmentList.Select(x => (object)x.DepartmentID).ToList();
  58. }
  59. return MvcHtmlString.Create(Bowin.Web.Controls.Mvc.CheckList.CreateControl(listControlOptions, htmlAttributes).Render());
  60. }
  61. public static MvcHtmlString UserRoleList(this HtmlHelper htmlHelper,
  62. ListControlOptions listControlOptions, Guid userID,
  63. System.Collections.Generic.IDictionary<string, string> htmlAttributes = null)
  64. {
  65. using (var scope = AutofacHelper.Container.BeginLifetimeScope())
  66. {
  67. IRoleServices RoleServices = scope.Resolve<IRoleServices>();
  68. IUserServices UserServices = scope.Resolve<IUserServices>();
  69. var roleList = RoleServices.GetEnabledTeacherRoleViewList().Select(x => new ListControlItem { Text = x.RoleName, Value = x.RoleID });
  70. var userRoleList = UserServices.GetUserRoles(userID);
  71. listControlOptions.ItemList = roleList.ToList();
  72. listControlOptions.SelectedValues = userRoleList.Select(x => (object)x.RoleID).ToList();
  73. }
  74. return MvcHtmlString.Create(Bowin.Web.Controls.Mvc.CheckList.CreateControl(listControlOptions, htmlAttributes).Render());
  75. }
  76. /// <summary>
  77. /// 列出字典表的项的多选列表
  78. /// </summary>
  79. /// <param name="htmlHelper"></param>
  80. /// <param name="dictionaryItem"></param>
  81. /// <param name="listControlOptions"></param>
  82. /// <param name="htmlAttributes"></param>
  83. /// <returns></returns>
  84. public static MvcHtmlString DictionaryCheckList(this HtmlHelper htmlHelper, DictionaryItem dictionaryItem,
  85. ListControlOptions listControlOptions, System.Collections.Generic.IDictionary<string, string> htmlAttributes = null)
  86. {
  87. if (listControlOptions == null)
  88. {
  89. listControlOptions = new ListControlOptions();
  90. }
  91. listControlOptions.ItemList = DictionaryHelper.GetDictionaryValue(dictionaryItem).Where(x => x.RecordStatus == (int)SYS_STATUS.USABLE)
  92. .Select(x => new ListControlItem { Text = x.Name, Value = x.Value }).ToList();
  93. return MvcHtmlString.Create(Bowin.Web.Controls.Mvc.CheckList.CreateControl(listControlOptions, htmlAttributes).Render());
  94. }
  95. }
  96. }