SCalendarServices.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.DataLogic.Common.CalendarManage;
  6. using Bowin.Common.Linq.Entity;
  7. using EMIS.Entities;
  8. using EMIS.ViewModel;
  9. using System.Linq.Expressions;
  10. using EMIS.ViewModel.CalendarManage;
  11. namespace EMIS.CommonLogic.CalendarManage
  12. {
  13. public class SCalendarServices : BaseServices, ISCalendarServices
  14. {
  15. public SCalendarDAL scalendarDAL { get; set; }
  16. /// <summary>
  17. /// 查询校历信息
  18. /// </summary>
  19. /// <param name="configuretView">查询条件实体</param>
  20. /// <param name="activitiesType">活动类型</param>
  21. /// <param name="timesSegment">时间段</param>
  22. /// <param name="pageIndex">页码</param>
  23. /// <param name="pageSize">显示页数</param>
  24. /// <returns></returns>
  25. public IGridResultSet<SCalendarView> GetSCalendarViewGrid(ConfiguretView configuretView, int? activitiesType, int? timesSegment, int pageIndex, int pageSize)
  26. {
  27. var query = scalendarDAL.GetSCalendarQueryable(x => true);
  28. if (activitiesType.HasValue && activitiesType != -1)
  29. query = query.Where(x => x.ActivitiesType == activitiesType);
  30. if (timesSegment.HasValue && timesSegment != -1)
  31. query = query.Where(x => x.TimesSegment == timesSegment);
  32. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  33. return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue)
  34. .OrderByDescending(x => x.ActivitiesTime).ThenBy(x => x.TimesSegment).ToGridResultSet<SCalendarView>(pageIndex, pageSize);
  35. return query.OrderByDescending(x => x.ActivitiesTime).ThenBy(x => x.TimesSegment).ToGridResultSet<SCalendarView>(pageIndex, pageSize);
  36. }
  37. /// <summary>
  38. /// 查询校历信息
  39. /// </summary>
  40. /// <param name="configuretView">查询条件实体</param>
  41. /// <param name="activitiesType">活动类型</param>
  42. /// <param name="timesSegment">时间段</param>
  43. /// <returns></returns>
  44. public List<SCalendarView> GetSCalendarViewList(ConfiguretView configuretView, int? activitiesType, int? timesSegment)
  45. {
  46. var query = scalendarDAL.GetSCalendarQueryable(x => true);
  47. if (activitiesType.HasValue && activitiesType != -1)
  48. query = query.Where(x => x.ActivitiesType == activitiesType);
  49. if (timesSegment.HasValue && timesSegment != -1)
  50. query = query.Where(x => x.TimesSegment == timesSegment);
  51. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  52. return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue)
  53. .OrderByDescending(x => x.ActivitiesTime).ThenBy(x => x.TimesSegment).ToList();
  54. return query.OrderByDescending(x => x.ActivitiesTime).ThenBy(x => x.TimesSegment).ToList();
  55. }
  56. /// <summary>
  57. /// 获取校历信息
  58. /// </summary>
  59. /// <param name="activitiesID">主键ID</param>
  60. /// <returns></returns>
  61. public CF_SCalendar GetSCalendar(Guid? activitiesID)
  62. {
  63. //查询条件
  64. Expression<Func<CF_SCalendar, bool>> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  65. expression = (x => x.ActivitiesID == activitiesID);
  66. return scalendarDAL.scalendarRepository.GetSingle(expression);
  67. }
  68. /// <summary>
  69. /// 获取校历信息
  70. /// </summary>
  71. /// <param name="Name">活动名称</param>
  72. /// <returns></returns>
  73. public CF_SCalendar GetSCalendar(string Name)
  74. {
  75. //查询条件
  76. Expression<Func<CF_SCalendar, bool>> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  77. expression = (x => x.Name == Name);
  78. return scalendarDAL.scalendarRepository.GetSingle(expression);
  79. }
  80. /// <summary>
  81. /// 获取校历信息
  82. /// </summary>
  83. /// <param name="activitiesID">主键ID</param>
  84. /// <returns></returns>
  85. public SCalendarView GetSCalendarView(Guid? activitiesID)
  86. {
  87. SCalendarView scalendarView = new SCalendarView();
  88. if (activitiesID.HasValue)
  89. scalendarView = scalendarDAL.GetSCalendarQueryable(x => true).Where(x => x.ActivitiesID == activitiesID).FirstOrDefault();
  90. return scalendarView;
  91. }
  92. /// <summary>
  93. /// 添加
  94. /// </summary>
  95. /// <param name="scalendar">实体</param>
  96. /// <returns></returns>
  97. public bool SCalendarAdd(SCalendarView scalendarView)
  98. {
  99. try
  100. {
  101. if (this.scalendarDAL.scalendarRepository
  102. .GetList(x => x.Name == scalendarView.Name && x.ActivitiesTime == scalendarView.ActivitiesTime
  103. && x.TimesSegment == scalendarView.TimesSegment).Count() > 0)
  104. {
  105. throw new Exception("已存在相同的数据,请重新输入!");
  106. }
  107. CF_SCalendar scalendar = new CF_SCalendar();
  108. scalendar.ActivitiesID = Guid.NewGuid();
  109. scalendar.Name = scalendarView.Name;
  110. scalendar.ActivitiesTime = scalendarView.ActivitiesTime.Value;
  111. scalendar.TimesSegment = scalendarView.TimesSegment.Value;
  112. scalendar.ActivitiesContent = scalendarView.ActivitiesContent;
  113. scalendar.ActivitiesType = scalendarView.ActivitiesType;
  114. this.SetNewStatus(scalendar);
  115. UnitOfWork.Add(scalendar);
  116. UnitOfWork.Commit();
  117. return true;
  118. }
  119. catch (Exception)
  120. {
  121. throw;
  122. }
  123. }
  124. /// <summary>
  125. /// 修改
  126. /// </summary>
  127. /// <param name="scalendar">实体</param>
  128. /// <returns></returns>
  129. public bool SCalendarUpdate(SCalendarView scalendarView)
  130. {
  131. try
  132. {
  133. if (this.scalendarDAL.scalendarRepository
  134. .GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE
  135. && x.Name == scalendarView.Name && x.ActivitiesTime == scalendarView.ActivitiesTime
  136. && x.TimesSegment == scalendarView.TimesSegment && x.ActivitiesID != scalendarView.ActivitiesID).Count() > 0)
  137. {
  138. throw new Exception("活动名称已存在,请重新输入!");
  139. }
  140. var scalendar = GetSCalendar(scalendarView.ActivitiesID);
  141. if (scalendar == null)
  142. {
  143. throw new Exception("未能找到相对应的数据!");
  144. }
  145. scalendar.Name = scalendarView.Name;
  146. scalendar.ActivitiesTime = scalendarView.ActivitiesTime.Value;
  147. scalendar.TimesSegment = scalendarView.TimesSegment.Value;
  148. scalendar.ActivitiesContent = scalendarView.ActivitiesContent;
  149. scalendar.ActivitiesType = scalendarView.ActivitiesType;
  150. this.SetModifyStatus(scalendar);
  151. UnitOfWork.Commit();
  152. return true;
  153. }
  154. catch (Exception)
  155. {
  156. throw;
  157. }
  158. }
  159. /// <summary>
  160. /// 删除
  161. /// </summary>
  162. /// <param name="activitiesIDs"></param>
  163. /// <returns></returns>
  164. public bool SCalendarDelete(List<Guid> activitiesIDs)
  165. {
  166. try
  167. {
  168. UnitOfWork.Delete<CF_SCalendar>(x => activitiesIDs.Contains(x.ActivitiesID));
  169. UnitOfWork.Commit();
  170. return true;
  171. }
  172. catch (Exception)
  173. {
  174. throw;
  175. }
  176. }
  177. }
  178. }