123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Linq.Expressions;
- using Bowin.Common.Linq;
- using Bowin.Common.Linq.Entity;
- using Bowin.Common.Utility;
- using EMIS.DataLogic.Common.CalendarManage;
- using EMIS.Entities;
- using EMIS.ViewModel;
- using EMIS.ViewModel.CalendarManage;
- using EMIS.Utility;
- namespace EMIS.CommonLogic.CalendarManage
- {
- public partial class SchoolYearServices : BaseServices, ISchoolYearServices
- {
- public SchoolYearDAL schoolYearDAL { get; set; }
- public CoursesTimeDAL CoursesTimeDAL { get; set; }
- /// <summary>
- /// 查询学年学期信息
- /// </summary>
- /// <param name="configuretView">查询条件实体</param>
- /// <param name="SchoolyearsType">活动类型</param>
- /// <param name="timesSegment">时间段</param>
- /// <param name="pageIndex">页码</param>
- /// <param name="pageSize">显示页数</param>
- /// <returns></returns>
- public IGridResultSet<SchoolYearView> GetSchoolYearViewGrid(ConfiguretView configuretView, int? isCurrent, int pageIndex, int pageSize)
- {
- var query = schoolYearDAL.GetSchoolYearQueryable(x => true);
- if (isCurrent > -1)
- {
- bool current = isCurrent == 1 ? true : false;
- query = query.Where(x => x.IsCurrent == current);
- }
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderByDescending(x => x.Years).ThenBy(t => t.SchoolcodeID).ToGridResultSet<SchoolYearView>(pageIndex, pageSize);
- return query.OrderByDescending(x => x.IsCurrent).ThenByDescending(x => x.Value).ToGridResultSet<SchoolYearView>(pageIndex, pageSize);
- }
- /// <summary>
- /// 查询学年学期信息
- /// </summary>
- /// <param name="configuretView">查询条件实体</param>
- /// <returns></returns>
- public List<SchoolYearView> GetSchoolYearViewList(ConfiguretView configuretView, int? isCurrent)
- {
- var query = schoolYearDAL.GetSchoolYearQueryable(x => true);
- if (isCurrent > -1)
- {
- bool current = isCurrent == 1 ? true : false;
- query = query.Where(x => x.IsCurrent == current);
- }
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderByDescending(x => x.Years).ThenBy(t => t.SchoolcodeID).ToList();
- return query.OrderByDescending(x => x.Value).ToList();
- }
- /// <summary>
- /// 查询之后的学年学期信息
- /// </summary>
- /// <returns></returns>
- public List<SchoolYearView> GetSchoolYearViewListAfterCurrent()
- {
- var currentSchoolYear = schoolYearDAL.schoolyearRepository.GetSingle(x => x.IsCurrent == true);
- if (currentSchoolYear == null)
- {
- throw new Exception("请先设置当前的学年学期。");
- }
- var query = schoolYearDAL.GetSchoolYearQueryable(x => x.Value >= currentSchoolYear.Value);
- return query.OrderByDescending(x => x.Value).ToList();
- }
- /// <summary>
- /// 查询之前的学年学期信息
- /// </summary>
- /// <returns></returns>
- public List<SchoolYearView> GetSchoolYearViewListBeforeCurrent()
- {
- var currentSchoolYear = schoolYearDAL.schoolyearRepository.GetSingle(x => x.IsCurrent == true);
- if (currentSchoolYear == null)
- {
- throw new Exception("请先设置当前的学年学期。");
- }
- var query = schoolYearDAL.GetSchoolYearQueryable(x => x.Value <= currentSchoolYear.Value);
- return query.OrderByDescending(x => x.Value).ToList();
- }
- /// <summary>
- /// 查询前一个学年学期信息
- /// </summary>
- /// <returns></returns>
- public SchoolYearView GetSchoolYearViewBeforeCurrent()
- {
- var currentSchoolYear = schoolYearDAL.schoolyearRepository.GetSingle(x => x.IsCurrent == true);
- if (currentSchoolYear == null)
- {
- throw new Exception("请先设置当前的学年学期。");
- }
- var query = schoolYearDAL.GetSchoolYearQueryable(x => x.Value ==currentSchoolYear.Value-1);
- return query.OrderByDescending(x => x.Value).FirstOrDefault();
- }
- /// <summary>
- /// 获取学年学期信息
- /// </summary>
- /// <param name="SchoolyearsID">主键ID</param>
- /// <returns></returns>
- public EMIS.Entities.CF_Schoolyear GetSchoolYear(Guid? schoolyearID)
- {
- //查询条件
- Expression<Func<EMIS.Entities.CF_Schoolyear, bool>> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- expression = (x => x.SchoolyearID == schoolyearID);
- return schoolYearDAL.schoolyearRepository.GetSingle(expression);
- }
- /// <summary>
- /// 获取学年学期信息
- /// </summary>
- /// <param name="SchoolyearsID">主键ID</param>
- /// <returns></returns>
- public EMIS.Entities.CF_Schoolyear GetSchoolYearByValue(int value)
- {
- //查询条件
- Expression<Func<EMIS.Entities.CF_Schoolyear, bool>> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- expression = (x => x.Value == value);
- return schoolYearDAL.schoolyearRepository.GetSingle(expression);
- }
- /// <summary>
- /// 获取学年学期信息
- /// </summary>
- /// <param name="schoolyearID">主键ID</param>
- /// <param name="IsCurrent">是否当前学期</param>
- /// <returns></returns>
- public List<EMIS.Entities.CF_Schoolyear> GetSchoolYearList(Guid? schoolyearID, bool IsCurrent)
- {
- var schoolyearList = schoolYearDAL.schoolyearRepository.Entities.Where(w => w.SchoolyearID != schoolyearID && w.IsCurrent == IsCurrent).ToList();
- return schoolyearList;
- }
- /// <summary>
- /// 获取学年学期信息
- /// </summary>
- /// <param name="Years">学年</param>
- /// <param name="Name">学期名称</param>
- /// <returns></returns>
- public EMIS.Entities.CF_Schoolyear GetSchoolYear(int Years, int SchoolcodeID)
- {
- //查询条件
- Expression<Func<EMIS.Entities.CF_Schoolyear, bool>> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- expression = (x => x.Years == Years && x.SchoolcodeID == SchoolcodeID);
- return schoolYearDAL.schoolyearRepository.GetSingle(expression);
- }
- /// <summary>
- /// 获取学年学期信息
- /// </summary>
- /// <param name="schoolyearID">主键ID</param>
- /// <returns></returns>
- public SchoolYearView GetSchoolYearView(Guid? schoolyearID)
- {
- SchoolYearView schoolYearView = new SchoolYearView();
- if (schoolyearID.HasValue)
- schoolYearView = schoolYearDAL.GetSchoolYearQueryable(x => true).Where(x => x.SchoolYearID == schoolyearID).FirstOrDefault();
- return schoolYearView;
- }
- /// <summary>
- /// 添加
- /// </summary>
- /// <param name="schoolyear">实体</param>
- /// <returns></returns>
- public bool SchoolYearAdd(SchoolYearView schoolyearView)
- {
- try
- {
- if(this.schoolYearDAL.schoolyearRepository.GetList(x=>x.RecordStatus>(int)SYS_STATUS.UNUSABLE&&x.Code==schoolyearView.Code).Count()>0)
- {
- throw new Exception("学年学期"+schoolyearView.Code+"已存在,请重新输入!");
- }
- if (this.schoolYearDAL.schoolyearRepository
- .GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE
- && x.Years == schoolyearView.Years && x.SchoolcodeID == schoolyearView.SchoolcodeID).Count() > 0)
- {
- var schoolCode = DictionaryHelper.GetSingleDictionary(schoolyearView.SchoolcodeID.Value, DictionaryItem.CF_Schoolcode.ToString());
- throw new Exception(schoolyearView.Years.Value.ToString() + "年下已存在" + schoolCode.Name + ",请重新输入!");
- }
- EMIS.Entities.CF_Schoolyear schoolyear = new EMIS.Entities.CF_Schoolyear();
- schoolyear.SchoolyearID = Guid.NewGuid();
- schoolyear.Code = schoolyearView.Code;
- schoolyear.Years = schoolyearView.Years.Value;
- schoolyear.SchoolcodeID = schoolyearView.SchoolcodeID.Value;
- schoolyear.WeeksNum = schoolyearView.WeeksNum.Value;
- schoolyear.FirstWeek = schoolyearView.FirstWeek.Value;
- schoolyear.IsCurrent = schoolyearView.IsCurrent;
- schoolyear.WeekDays = schoolyearView.WeekDays.Value;
- schoolyear.Value = (schoolyearView.Years.Value * 2) - 1 + (schoolyearView.SchoolcodeID.Value - 1);
- this.SetNewStatus(schoolyear);
- UnitOfWork.Add(schoolyear);
- if (schoolyearView.IsCurrent == true)//如果该数据为当前学期,则把其他数据的是否当前学期改成否
- {
- var schoolyearList = GetSchoolYearList(schoolyear.SchoolyearID, true);
- if (schoolyearList.Count > 0)
- {
- SchoolYearUpdateList(schoolyearList);
- }
- }
- UnitOfWork.Commit();
- return true;
- }
- catch (Exception)
- {
- throw;
- }
- }
- /// <summary>
- /// 修改
- /// </summary>
- /// <param name="SchoolyearsSets">实体</param>
- /// <returns></returns>
- public bool SchoolYearUpdate(SchoolYearView schoolyearView)
- {
- try
- {
- if (this.schoolYearDAL.schoolyearRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && x.Code == schoolyearView.Code&&x.SchoolyearID!=schoolyearView.SchoolYearID).Count() > 0)
- {
- throw new Exception("学年学期" + schoolyearView.Code + "已存在,请重新输入!");
- }
- if (this.schoolYearDAL.schoolyearRepository
- .GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE
- && x.Years == schoolyearView.Years && x.SchoolcodeID == schoolyearView.SchoolcodeID
- && x.SchoolyearID != schoolyearView.SchoolYearID).Count() > 0)
- {
- var schoolCode = DictionaryHelper.GetSingleDictionary(schoolyearView.SchoolcodeID.Value,
- DictionaryItem.CF_Schoolcode.ToString());
- throw new Exception(schoolyearView.Years.Value.ToString() + "年下已存在" + schoolCode.Name + ",请重新输入!");
- }
- var schoolyear = GetSchoolYear(schoolyearView.SchoolYearID);
- if (schoolyear == null)
- {
- throw new Exception("保存失败,未能找到相对应的数据!");
- }
- schoolyear.Code = schoolyearView.Code;
- schoolyear.Years = schoolyearView.Years.Value;
- schoolyear.SchoolcodeID = schoolyearView.SchoolcodeID.Value;
- schoolyear.WeeksNum = schoolyearView.WeeksNum.Value;
- schoolyear.FirstWeek = schoolyearView.FirstWeek.Value;
- schoolyear.IsCurrent = schoolyearView.IsCurrent;
- schoolyear.WeekDays = schoolyearView.WeekDays.Value;
- schoolyear.Value = (schoolyearView.Years.Value * 2) - 1 + (schoolyearView.SchoolcodeID.Value - 1);
- this.SetModifyStatus(schoolyear);
- if (schoolyearView.IsCurrent == true)//如果该数据为当前学期,则把其他数据的是否当前学期改成否
- {
- var schoolyearList = GetSchoolYearList(schoolyear.SchoolyearID, true);
- if (schoolyearList.Count > 0)
- {
- SchoolYearUpdateList(schoolyearList);
- }
- }
- UnitOfWork.Commit();
- return true;
- }
- catch (Exception)
- {
- throw;
- }
- }
- /// <summary>
- /// 修改
- /// </summary>
- /// <param name="schoolyearList">实体集合</param>
- /// <returns></returns>
- private bool SchoolYearUpdateList(List<EMIS.Entities.CF_Schoolyear> schoolyearList)
- {
- try
- {
- foreach (var schoolyear in schoolyearList)
- {
- schoolyear.IsCurrent = false;
- }
- return true;
- }
- catch (Exception)
- {
- throw;
- }
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="schoolyearIDs"></param>
- /// <returns></returns>
- public bool SchoolYearDelete(List<Guid> schoolyearIDs)
- {
- try
- {
- UnitOfWork.Delete<EMIS.Entities.CF_Schoolyear>(x => schoolyearIDs.Contains(x.SchoolyearID));
- UnitOfWork.Commit();
- return true;
- }
- catch (Exception)
- {
- throw;
- }
- }
- public IGridResultSet<SchoolYearView> GetYearsViewGrid(ConfiguretView configuretView, int? isCurrent, int pageIndex, int pageSize)
- {
- var query = schoolYearDAL.GetYearsQueryable(x => true);
- //if (isCurrent > -1)
- //{
- // bool current = isCurrent == 1 ? true : false;
- // query = query.Where(x => x.IsCurrent == current);
- //}
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderByDescending(x => x.Years).ThenBy(t => t.SchoolcodeID).ToGridResultSet<SchoolYearView>(pageIndex, pageSize);
- return query.OrderByDescending(x => x.Years).ToGridResultSet<SchoolYearView>(pageIndex, pageSize);
- }
- /// <summary>
- /// 获取当前校历启用的学年学期ID
- /// </summary>
- /// <returns></returns>
- public SchoolYearView GetCurrentSchoolYear()
- {
- var curSchoolYear = schoolYearDAL.GetSchoolYearQueryable(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && x.IsCurrent == true)
- .FirstOrDefault();
- if (curSchoolYear == null)
- {
- throw new Exception("请先设置当前启用的学年学期。");
- }
- return curSchoolYear;
- }
- /// <summary>
- /// 获取当前校历启用的下一个学年学期ID
- /// </summary>
- /// <returns></returns>
- public SchoolYearView GetNextSchoolYear()
- {
- var curSchoolYear = GetCurrentSchoolYear();
- var nextSchoolYear = schoolYearDAL.GetSchoolYearQueryable(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && x.Value > curSchoolYear.Value)
- .OrderBy(x => x.Value).FirstOrDefault();
- if (nextSchoolYear == null)
- {
- throw new Exception("当前启用的学年学期对应的下一学期信息为空,请添加。");
- }
- return nextSchoolYear;
- }
- public void UpdateCurrentSchoolYear()
- {
- var currentSchoolYear = this.GetCurrentSchoolYear();
- this.UnitOfWork.Update<EMIS.Entities.CF_Schoolyear>((x => new EMIS.Entities.CF_Schoolyear { IsCurrent = false }), (x => true));
- var dbSchoolYear = this.GetSchoolYear(currentSchoolYear.SchoolYearID);
- dbSchoolYear.IsCurrent = true;
- this.UnitOfWork.Commit();
- }
- /// <summary>
- /// 获取当前学年学期
- /// </summary>
- /// <param name="IsCurrent"></param>
- /// <returns></returns>
- public Entities.CF_Schoolyear GetSchoolYearIsCurrent(bool IsCurrent)
- {
- //查询条件
- Expression<Func<EMIS.Entities.CF_Schoolyear, bool>> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- expression = (x => x.IsCurrent == IsCurrent);
- return schoolYearDAL.schoolyearRepository.GetSingle(expression);
- }
- /// <summary>
- /// 自动创建充足的学年学期和学年字典
- /// (仅针对松山,松山的学年学期记法比较怪异)
- /// </summary>
- public void AutoCreateSchoolyearAndYearsSS()
- {
- int year = DateTime.Today.Year;
- //设置要预留多少年的数据
- int addYears = 3;
- int endYear = year + addYears;
- int weeksNum = 20; //默认20,因为没有特定的规律判断到底是多少周,只能按一般大学的标准设置成20,如果不对,用户可以自己在页面上调整
- int weekdays = 5; //一周5天工作制,如果不对,用户可以自己在页面上调整
- var schoolyearList = schoolYearDAL.schoolyearRepository.GetList(x => x.Years >= year && x.Years <= endYear).ToList();
- var yearList = schoolYearDAL.dictionaryItemRepository.GetList(x => x.DictionaryCode == typeof(EMIS.ViewModel.CF_Schoolyear).Name
- && x.Value >= year && x.Value <= endYear).ToList();
- for (int i = 0; i <= addYears; i++)
- {
- var curYear = (year + i);
- if (!yearList.Any(x => x.Value == curYear))
- {
- Sys_DictionaryItem dictionaryItem = new Sys_DictionaryItem();
- dictionaryItem.DictionaryItemID = Guid.NewGuid();
- dictionaryItem.Code = "Year" + curYear.ToString();
- dictionaryItem.DictionaryCode = typeof(EMIS.ViewModel.CF_Schoolyear).Name;
- dictionaryItem.Value = curYear;
- dictionaryItem.Name = curYear.ToString();
- dictionaryItem.OrderNo = (short)(curYear - 2005);
- dictionaryItem.RecordStatus = (int)SYS_STATUS.USABLE;
- dictionaryItem.IsEditable = false;
- this.UnitOfWork.Add(dictionaryItem);
- }
- if (!schoolyearList.Any(x => x.Years == curYear && x.SchoolcodeID == 1))
- {
- var firstDay = new DateTime(curYear, 3, 1);
- switch (firstDay.DayOfWeek)
- {
- case DayOfWeek.Sunday:
- firstDay = firstDay.AddDays(1);
- break;
- case DayOfWeek.Saturday:
- firstDay = firstDay.AddDays(2);
- break;
- default:
- firstDay = firstDay.AddDays(1 - (int)firstDay.DayOfWeek);
- break;
- }
- EMIS.Entities.CF_Schoolyear schoolyear = new Entities.CF_Schoolyear();
- schoolyear.SchoolyearID = Guid.NewGuid();
- schoolyear.Code = (curYear - 1).ToString() + "-" + curYear.ToString() + "02";
- schoolyear.Years = curYear;
- schoolyear.SchoolcodeID = 1;
- schoolyear.WeeksNum = weeksNum;
- schoolyear.FirstWeek = firstDay;
- schoolyear.IsCurrent = false;
- schoolyear.WeekDays = weekdays;
- schoolyear.RecordStatus = (int)SYS_STATUS.USABLE;
- schoolyear.CreateTime = schoolyear.ModifyTime = DateTime.Now;
- schoolyear.Value = (curYear * 2 - 1);
- this.UnitOfWork.Add(schoolyear);
- }
- if (!schoolyearList.Any(x => x.Years == curYear && x.SchoolcodeID == 2))
- {
- var firstDay = new DateTime(curYear, 9, 1);
- switch (firstDay.DayOfWeek)
- {
- case DayOfWeek.Sunday:
- firstDay = firstDay.AddDays(1);
- break;
- case DayOfWeek.Saturday:
- firstDay = firstDay.AddDays(2);
- break;
- default:
- firstDay = firstDay.AddDays(1 - (int)firstDay.DayOfWeek);
- break;
- }
- EMIS.Entities.CF_Schoolyear schoolyear = new Entities.CF_Schoolyear();
- schoolyear.SchoolyearID = Guid.NewGuid();
- schoolyear.Code = curYear.ToString() + "-" + (curYear + 1).ToString() + "01";
- schoolyear.Years = curYear;
- schoolyear.SchoolcodeID = 2;
- schoolyear.WeeksNum = weeksNum;
- schoolyear.FirstWeek = firstDay;
- schoolyear.IsCurrent = false;
- schoolyear.WeekDays = weekdays;
- schoolyear.RecordStatus = (int)SYS_STATUS.USABLE;
- schoolyear.CreateTime = schoolyear.ModifyTime = DateTime.Now;
- schoolyear.Value = (curYear * 2 - 1) + 1;
- this.UnitOfWork.Add(schoolyear);
- }
- }
- this.UnitOfWork.Commit();
- }
- /// <summary>
- /// 自动创建充足的学年学期和学年字典
- /// </summary>
- public void AutoCreateSchoolyearAndYears()
- {
- int year = DateTime.Today.Year;
- //设置要预留多少年的数据
- int addYears = 3;
- int endYear = year + addYears;
- int weeksNum = 20; //默认20,因为没有特定的规律判断到底是多少周,只能按一般大学的标准设置成20,如果不对,用户可以自己在页面上调整
- int weekdays = 5; //一周5天工作制,如果不对,用户可以自己在页面上调整
- var schoolyearList = schoolYearDAL.schoolyearRepository.GetList(x => x.Years >= year && x.Years <= endYear).ToList();
- var yearList = schoolYearDAL.dictionaryItemRepository.GetList(x => x.DictionaryCode == typeof(EMIS.ViewModel.CF_Schoolyear).Name
- && x.Value >= year && x.Value <= endYear).ToList();
- for (int i = 0; i <= addYears; i++)
- {
- var curYear = (year + i);
- if (!yearList.Any(x => x.Value == curYear))
- {
- Sys_DictionaryItem dictionaryItem = new Sys_DictionaryItem();
- dictionaryItem.DictionaryItemID = Guid.NewGuid();
- dictionaryItem.Code = "Year" + curYear.ToString();
- dictionaryItem.DictionaryCode = typeof(EMIS.ViewModel.CF_Schoolyear).Name;
- dictionaryItem.Value = curYear;
- dictionaryItem.Name = curYear.ToString();
- dictionaryItem.OrderNo = (short)(curYear - 2005);
- dictionaryItem.RecordStatus = (int)SYS_STATUS.USABLE;
- dictionaryItem.IsEditable = false;
- this.UnitOfWork.Add(dictionaryItem);
- }
- if (!schoolyearList.Any(x => x.Years == curYear && x.SchoolcodeID == 1))
- {
- var firstDay = new DateTime(curYear, 9, 1);
- switch (firstDay.DayOfWeek)
- {
- case DayOfWeek.Sunday:
- firstDay = firstDay.AddDays(1);
- break;
- case DayOfWeek.Saturday:
- firstDay = firstDay.AddDays(2);
- break;
- default:
- firstDay = firstDay.AddDays(1 - (int)firstDay.DayOfWeek);
- break;
- }
- EMIS.Entities.CF_Schoolyear schoolyear = new Entities.CF_Schoolyear();
- schoolyear.SchoolyearID = Guid.NewGuid();
- schoolyear.Code = curYear.ToString() + "-" + (curYear + 1).ToString() + "-1";
- schoolyear.Years = curYear;
- schoolyear.SchoolcodeID = 1;
- schoolyear.WeeksNum = weeksNum;
- schoolyear.FirstWeek = firstDay;
- schoolyear.IsCurrent = false;
- schoolyear.WeekDays = weekdays;
- schoolyear.RecordStatus = (int)SYS_STATUS.USABLE;
- schoolyear.CreateTime = schoolyear.ModifyTime = DateTime.Now;
- schoolyear.Value = (curYear * 2 - 1);
- this.UnitOfWork.Add(schoolyear);
- }
- if (!schoolyearList.Any(x => x.Years == curYear && x.SchoolcodeID == 2))
- {
- var firstDay = new DateTime(curYear + 1, 3, 1);
- switch (firstDay.DayOfWeek)
- {
- case DayOfWeek.Sunday:
- firstDay = firstDay.AddDays(1);
- break;
- case DayOfWeek.Saturday:
- firstDay = firstDay.AddDays(2);
- break;
- default:
- firstDay = firstDay.AddDays(1 - (int)firstDay.DayOfWeek);
- break;
- }
- EMIS.Entities.CF_Schoolyear schoolyear = new Entities.CF_Schoolyear();
- schoolyear.SchoolyearID = Guid.NewGuid();
- schoolyear.Code = curYear.ToString() + "-" + (curYear + 1).ToString() + "-2";
- schoolyear.Years = curYear;
- schoolyear.SchoolcodeID = 2;
- schoolyear.WeeksNum = weeksNum;
- schoolyear.FirstWeek = firstDay;
- schoolyear.IsCurrent = false;
- schoolyear.WeekDays = weekdays;
- schoolyear.RecordStatus = (int)SYS_STATUS.USABLE;
- schoolyear.CreateTime = schoolyear.ModifyTime = DateTime.Now;
- schoolyear.Value = (curYear * 2 - 1) + 1;
- this.UnitOfWork.Add(schoolyear);
- }
- }
- this.UnitOfWork.Commit();
- }
- public List<int> GetCurrentSchoolyearWeekNumList()
- {
- List<int> result = new List<int>();
- var schoolyear = this.GetCurrentSchoolYear();
- for (int i = 1; i <= schoolyear.WeeksNum; i++)
- {
- result.Add(i);
- }
- return result;
- }
- public List<int> GetSchoolyearWeekNumList(Guid? SchoolYearID)
- {
-
- List<int> result = new List<int>();
- if (SchoolYearID.HasValue)
- {
- var schoolyear = schoolYearDAL.schoolyearRepository.GetList(x => x.SchoolyearID == SchoolYearID).FirstOrDefault();
- if (schoolyear != null)
- {
- for (int i = 1; i <= schoolyear.WeeksNum; i++)
- {
- result.Add(i);
- }
- }
- }
- else
- {
- result=GetCurrentSchoolyearWeekNumList();
- }
- return result;
- }
- public List<WeekDayView> GetFutureWeekdayList(int weekNum)
- {
- var curDate = DateTime.Today;
- var curSchoolyear = this.schoolYearDAL.schoolyearRepository.GetSingle(x => x.IsCurrent == true);
- var firstWeek = curSchoolyear.FirstWeek.AddDays(1 - (int)curSchoolyear.FirstWeek.DayOfWeek);
- var nowWeekNum = (curDate.Subtract(firstWeek).Days + 7) / 7;
- var nowWeekday = (int)curDate.DayOfWeek == 0 ? 7 : (int)curDate.DayOfWeek;
- var weekList = WeekHelper.WeekDictionary;
- if (weekNum < nowWeekNum)
- {
- weekList = new Dictionary<int,string>();
- }
- if (weekNum == nowWeekNum)
- {
- weekList = weekList.Where(x => (x.Key == 0 ? 7 : x.Key) >= nowWeekday).ToDictionary(x => x.Key, x => x.Value);
- }
- return weekList.Select(x => new WeekDayView { WeekDay = x.Key, ChineseName = x.Value }).ToList();
- }
- public List<CoursesTimeView> GetFutureCourseTimeList(int weekNum, int weekday)
- {
- var curDate = DateTime.Today;
- var curTimeValue = DateTime.Now.Hour * 60 + DateTime.Now.Minute;
- var curSchoolyear = this.schoolYearDAL.schoolyearRepository.GetSingle(x => x.IsCurrent == true);
- var firstWeek = curSchoolyear.FirstWeek.AddDays(1 - (int)curSchoolyear.FirstWeek.DayOfWeek);
- var nowWeekNum = (curDate.Subtract(firstWeek).Days + 7) / 7;
- var nowWeekday = (int)curDate.DayOfWeek == 0 ? 7 : (int)curDate.DayOfWeek;
- Expression<Func<EM_CoursesTime, bool>> exp = (x => true);
- if (weekNum < nowWeekNum)
- {
- return new List<CoursesTimeView>();
- }
- if (weekNum == nowWeekNum && (weekday == 0 ? 7 : weekday) < nowWeekday)
- {
- return new List<CoursesTimeView>();
- }
- if (weekNum == nowWeekNum && (weekday == 0 ? 7 : weekday) == nowWeekday)
- {
- exp = exp.And(x => (x.StartHour * 60 + x.StartMinutes) > curTimeValue);
- }
- var courseTimeList = CoursesTimeDAL.GetCoursesTimeQueryable(exp).ToList();
- return courseTimeList;
- }
- public bool IsTimePassed(SchoolYearView currentSchoolyear, int? weekNum, int? weekday, int? startHour, int? startMinute)
- {
- if (!weekNum.HasValue || !weekday.HasValue)
- {
- return true;
- }
- var curDate = DateTime.Today;
- var curTimeValue = DateTime.Now.Hour * 60 + DateTime.Now.Minute;
- var firstWeek = currentSchoolyear.FirstWeek.Value.AddDays(1 - (int)currentSchoolyear.FirstWeek.Value.DayOfWeek);
- var nowWeekNum = (curDate.Subtract(firstWeek).Days + 7) / 7;
- var nowWeekday = (int)curDate.DayOfWeek == 0 ? 7 : (int)curDate.DayOfWeek;
- if (weekNum < nowWeekNum)
- {
- return true;
- }
- if (weekNum == nowWeekNum && (weekday == 0 ? 7 : weekday) < nowWeekday)
- {
- return true;
- }
- if (weekNum == nowWeekNum && (weekday == 0 ? 7 : weekday) == nowWeekday && (startHour * 60 + startMinute) < curTimeValue)
- {
- return true;
- }
- return false;
- }
- public List<FullCoursesTimeView> GetCoursesTimeByDateTime(Guid schoolyearID, IList<StartEndTimeView> datetimeList)
- {
- var schoolyear = this.GetSchoolYearView(schoolyearID);
- var firstWeek = schoolyear.FirstWeek.Value.AddDays(1 - (int)schoolyear.FirstWeek.Value.DayOfWeek);
- var lastDay = firstWeek.AddDays(7 * (schoolyear.WeeksNum ?? 0));
- var courseTimeList = CoursesTimeDAL.GetCoursesTimeQueryable(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).ToList();
- var availableDateTimeList = datetimeList
- .Where(x => x.StartTime.HasValue && x.StartTime >= firstWeek && x.StartTime < lastDay
- && x.EndTime.HasValue && x.EndTime >= firstWeek && x.EndTime < lastDay
- && x.StartTime.Value.Date == x.EndTime.Value.Date).ToList();
- var fullCoursesTimeViewList = new List<FullCoursesTimeView>();
- availableDateTimeList.ForEach(x =>
- {
- var courseTime = courseTimeList.Where(w => new DateTime(x.StartTime.Value.Year, x.StartTime.Value.Month, x.StartTime.Value.Day,
- w.StartHour.Value, w.StartMinutes.Value, 0) <= x.EndTime.Value
- && new DateTime(x.StartTime.Value.Year, x.StartTime.Value.Month, x.StartTime.Value.Day,
- w.EndHour.Value, w.EndMinutes.Value, 0) >= x.StartTime.Value).ToList();
- courseTime.ForEach(w =>
- fullCoursesTimeViewList.Add(new FullCoursesTimeView
- {
- WeekNum = x.StartTime.Value.Date.Subtract(firstWeek).Days / 7 + 1,
- Weekday = (int)x.StartTime.Value.DayOfWeek == 0 ? 7 : (int)x.StartTime.Value.DayOfWeek,
- CoursesTimeID = w.CoursesTimeID,
- Date = x.StartTime.Value.Date,
- StartHour = w.StartHour,
- StartMinute = w.StartMinutes,
- EndHour = w.EndHour,
- EndMinute = w.EndMinutes
- })
- );
- });
- return fullCoursesTimeViewList;
- }
- public List<StartEndTimeView> GetCoursesTimeByDateTime(Guid schoolyearID, IList<FullCoursesTimeView> coursesTimeList)
- {
- var schoolyear = this.GetSchoolYearView(schoolyearID);
- var firstWeek = schoolyear.FirstWeek.Value.AddDays(1 - (int)schoolyear.FirstWeek.Value.DayOfWeek);
- var lastDay = firstWeek.AddDays(7 * (schoolyear.WeeksNum ?? 0));
- var courseTimeDbList = CoursesTimeDAL.GetCoursesTimeQueryable(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).ToList();
- return coursesTimeList.Select(x => new StartEndTimeView
- {
- StartTime = firstWeek.AddDays((double)(((x.WeekNum ?? 0) - 1) * 7 + (x.Weekday == 0 ? 7 : x.Weekday ?? 1) - 1))
- .AddHours((double)x.StartHour.Value).AddMinutes((double)x.StartMinute.Value),
- EndTime = firstWeek.AddDays((double)(((x.WeekNum ?? 0) - 1) * 7 + (x.Weekday == 0 ? 7 : x.Weekday ?? 1) - 1))
- .AddHours((double)x.EndHour.Value).AddMinutes((double)x.EndMinute.Value)
- }).ToList();
- }
- }
- }
|