ArrangementServices.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Bowin.Common.Linq.Entity;
  6. using EMIS.DataLogic.Common.CalendarManage;
  7. using EMIS.ViewModel;
  8. using EMIS.ViewModel.CalendarManage;
  9. using EMIS.Entities;
  10. namespace EMIS.CommonLogic.CalendarManage
  11. {
  12. public class ArrangementServices : BaseServices, IArrangementServices
  13. {
  14. public ArrangementDAL ArrangementDAL { get; set; }
  15. public List<ViewModel.CalendarManage.ArrangementView> GetArrangementViewList(ViewModel.ConfiguretView configuretView)
  16. {
  17. var query = ArrangementDAL.GetArrangementView(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  18. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  19. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  20. return query.OrderBy(x => x.Weekday).ThenBy(x => x.StartTimes).ToList();
  21. }
  22. /// <summary>
  23. /// 周工作时间安排表
  24. /// </summary>
  25. /// <returns></returns>
  26. public IGridResultSet<ViewModel.CalendarManage.ArrangementView> GetArrangementViewGrid()
  27. {
  28. var resultSet = ArrangementDAL.GetArrangementViewQueryable().OrderBy(x => x.StartTimes).ToGridResultSet<ArrangementView>();
  29. return resultSet;
  30. }
  31. /// <summary>
  32. /// 新增周工作时间
  33. /// </summary>
  34. /// <param name="listArrangement"></param>
  35. public void ArrangementAdd(List<ArrangementView> listArrangement)
  36. {
  37. try
  38. {
  39. var courseTimeIDList = listArrangement.Select(x => x.CoursesTimeID).ToList();
  40. var courseTimeList = ArrangementDAL.coursesTimeRepository.GetList(x => courseTimeIDList.Contains(x.CoursesTimeID), (y => y.CF_Arrangements));
  41. foreach (var arrangementView in listArrangement)
  42. {
  43. EM_CoursesTime coursesTime = courseTimeList.Where(x => x.CoursesTimeID == arrangementView.CoursesTimeID)
  44. .FirstOrDefault();
  45. if (coursesTime != null)
  46. {
  47. UnitOfWork.Remove<CF_Arrangements>(x => x.CoursesTimeID == coursesTime.CoursesTimeID);
  48. bool? IsOnWork = false;
  49. for (int i = 0; i < 7; i++)
  50. {
  51. if (i == (int)DayOfWeek.Monday)
  52. IsOnWork = arrangementView.MondayIsOnWork;
  53. if (i == (int)DayOfWeek.Tuesday)
  54. IsOnWork = arrangementView.TuesdayIsOnWork;
  55. if (i == (int)DayOfWeek.Wednesday)
  56. IsOnWork = arrangementView.WednesdayIsOnWork;
  57. if (i == (int)DayOfWeek.Thursday)
  58. IsOnWork = arrangementView.ThursdayIsOnWork;
  59. if (i == (int)DayOfWeek.Friday)
  60. IsOnWork = arrangementView.FridayIsOnWork;
  61. if (i == (int)DayOfWeek.Saturday)
  62. IsOnWork = arrangementView.SaturdayIsOnWork;
  63. if (i == (int)DayOfWeek.Sunday)
  64. IsOnWork = arrangementView.SundayIsOnWork;
  65. CF_Arrangements arrangements = new CF_Arrangements();
  66. arrangements.ArrangementsID = Guid.NewGuid();
  67. arrangements.CoursesTimeID = coursesTime.CoursesTimeID;
  68. arrangements.Weekday = i;
  69. arrangements.IsOnWork = IsOnWork;
  70. SetNewStatus(arrangements);
  71. UnitOfWork.Add(arrangements);
  72. }
  73. }
  74. }
  75. UnitOfWork.Commit();
  76. }
  77. catch (Exception)
  78. {
  79. throw;
  80. }
  81. }
  82. public bool IsOnWork(int weekday, Guid courseTimeID)
  83. {
  84. var isOnWork = ArrangementDAL.ArrangementsRepository.GetList(x => x.Weekday == weekday && x.CoursesTimeID == courseTimeID && x.IsOnWork == true);
  85. return isOnWork.Count() > 0;
  86. }
  87. }
  88. }