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 EMIS.ViewModel.RetakeManage; using EMIS.ViewModel; using EMIS.Entities; using EMIS.DataLogic.RetakeManage; using EMIS.CommonLogic.SystemServices; using EMIS.CommonLogic.CalendarManage; namespace EMIS.CommonLogic.RetakeManage { public class RetakeOpenControlServices : BaseServices, IRetakeOpenControlServices { public RetakeOpenControlDAL RetakeOpenControlDAL { get; set; } public Lazy ParameterServices { get; set; } public Lazy ISchoolYearServices { get; set; } /// /// 查询重修控制信息View /// /// /// /// /// /// public IGridResultSet GetRetakeOpenControlViewList(ConfiguretView openControlConditionView, Guid? schoolyearID, int pageIndex, int pageSize) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (schoolyearID.HasValue) { exp = exp.And(x => x.SchoolyearID == schoolyearID); } var query = RetakeOpenControlDAL.GetRetakeOpenControlViewQuery(exp); if (!string.IsNullOrEmpty(openControlConditionView.ConditionValue) && !string.IsNullOrEmpty(openControlConditionView.Attribute)) { query = query.DynamicWhere(openControlConditionView.Attribute, openControlConditionView.Condition, openControlConditionView.ConditionValue); } query = query.OrderByDescending(x => x.SchoolyearCode).ThenByDescending(x => x.StartDate); return query.ToGridResultSet(pageIndex, pageSize); } /// /// 查询重修控制信息List /// /// /// /// public List GetRetakeOpenControlViewList(ConfiguretView openControlConditionView, Guid? schoolyearID) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (schoolyearID.HasValue) { exp = exp.And(x => x.SchoolyearID == schoolyearID); } var query = RetakeOpenControlDAL.GetRetakeOpenControlViewQuery(exp); if (!string.IsNullOrEmpty(openControlConditionView.ConditionValue) && !string.IsNullOrEmpty(openControlConditionView.Attribute)) { query = query.DynamicWhere(openControlConditionView.Attribute, openControlConditionView.Condition, openControlConditionView.ConditionValue); } query = query.OrderByDescending(x => x.SchoolyearCode).ThenByDescending(x => x.StartDate); return query.ToList(); } /// /// 查询对应的重修控制信息 /// /// /// public RetakeOpenControlView GetRetakeOpenControlView(Guid? retakeOpenControlID) { var query = RetakeOpenControlDAL.GetRetakeOpenControlViewQuery(x => x.RetakeOpenControlID == retakeOpenControlID); return query.FirstOrDefault(); } /// /// 查询对应的重修控制信息(根据重修学年学期) /// /// /// public RetakeOpenControlView GetRetakeOpenControlViewBySchoolyearID(Guid? schoolyearID) { var query = RetakeOpenControlDAL.GetRetakeOpenControlViewQuery(x => x.SchoolyearID == schoolyearID); return query.SingleOrDefault(); } /// /// 重修控制编辑(新增、修改) /// /// public void RetakeOpenControlEdit(RetakeOpenControlView retakeOpenControlView) { try { ER_RetakeOpenControl openControl = new ER_RetakeOpenControl(); if (retakeOpenControlView.RetakeOpenControlID == null || retakeOpenControlView.RetakeOpenControlID == Guid.Empty) { openControl = RetakeOpenControlDAL.RetakeOpenControlRepository .GetSingle(x => x.SchoolyearID == retakeOpenControlView.SchoolyearID); if (openControl != null) { throw new Exception("已存在相同学年学期的重修控制信息。"); } openControl = new ER_RetakeOpenControl(); openControl.RetakeOpenControlID = Guid.NewGuid(); openControl.SchoolyearID = retakeOpenControlView.SchoolyearID; openControl.StartDate = retakeOpenControlView.StartDate; openControl.EndDate = retakeOpenControlView.EndDate; SetNewStatus(openControl); UnitOfWork.Add(openControl); } else { openControl = RetakeOpenControlDAL.RetakeOpenControlRepository .GetSingle(x => x.RetakeOpenControlID != retakeOpenControlView.RetakeOpenControlID && x.SchoolyearID == retakeOpenControlView.SchoolyearID); if (openControl != null) { throw new Exception("已存在相同学年学期的重修控制信息。"); } openControl = RetakeOpenControlDAL.RetakeOpenControlRepository .GetSingle(x => x.RetakeOpenControlID == retakeOpenControlView.RetakeOpenControlID); if (openControl == null) { throw new Exception("数据有误,请核查。"); } openControl.SchoolyearID = retakeOpenControlView.SchoolyearID; openControl.StartDate = retakeOpenControlView.StartDate; openControl.EndDate = retakeOpenControlView.EndDate; SetModifyStatus(openControl); } UnitOfWork.Commit(); } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 重修控制删除 /// /// public void RetakeOpenControlDelete(IList openControlIDList) { try { if (openControlIDList.Count > 0) { UnitOfWork.Delete(x => openControlIDList.Contains(x.RetakeOpenControlID)); } } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 查询重修学年学期对应的重修控制信息(根据对应重修学年学期查询) /// /// /// public ER_RetakeOpenControl GetRetakeOpenControl(Guid? schoolyearID) { try { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); exp = exp.And(x => x.SchoolyearID == schoolyearID); var query = RetakeOpenControlDAL.RetakeOpenControlRepository.GetSingle(exp); return query; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 查询重修学年学期对应的重修开放控制信息 /// /// /// public string GetRetakeApplyDateTime(Guid? schoolyearID) { var retakeOpenControl = GetRetakeOpenControl(schoolyearID); if (retakeOpenControl == null) { return "未开放"; } else { if (retakeOpenControl.StartDate > DateTime.Now) { return Convert.ToDateTime(retakeOpenControl.StartDate).ToString("yyyy-MM-dd hh:mm:ss") + " 至 " + Convert.ToDateTime(retakeOpenControl.EndDate).ToString("yyyy-MM-dd hh:mm:ss") + " (即将开始)"; } else if (retakeOpenControl.EndDate < DateTime.Now) { return Convert.ToDateTime(retakeOpenControl.StartDate).ToString("yyyy-MM-dd hh:mm:ss") + " 至 " + Convert.ToDateTime(retakeOpenControl.EndDate).ToString("yyyy-MM-dd hh:mm:ss") + " (报名结束)"; } else { return Convert.ToDateTime(retakeOpenControl.StartDate).ToString("yyyy-MM-dd hh:mm:ss") + " 至 " + Convert.ToDateTime(retakeOpenControl.EndDate).ToString("yyyy-MM-dd hh:mm:ss") + " (开始报名)"; } } } } }