CheckListExtentions.cs 6.6 KB

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