123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Linq.Expressions;
- using System.Transactions;
- using Bowin.Common.Linq;
- using Bowin.Common.Linq.Entity;
- using EMIS.Entities;
- using EMIS.ViewModel;
- using EMIS.ViewModel.StudentManage.StudentStatistics;
- using EMIS.DataLogic.StudentManage.StudentStatistics;
- namespace EMIS.CommonLogic.StudentManage.StudentStatistics
- {
- public class InSchoolSettingServices : BaseServices, IInSchoolSettingServices
- {
- public InSchoolSettingDAL InSchoolSettingDAL { get; set; }
- /// <summary>
- /// 查询对应的在校设定信息InSchoolSettingView
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="inSchoolStatusID"></param>
- /// <param name="isSelected"></param>
- /// <param name="isDisplayID"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <returns></returns>
- public IGridResultSet<InSchoolSettingView> GetInSchoolSettingViewGrid(ConfiguretView configuretView, int? inSchoolStatusID, int? isSelected, int? isDisplayID, int pageIndex, int pageSize)
- {
- Expression<Func<Sys_DictionaryItem, bool>> expInschoolStatus = (x => x.DictionaryCode == typeof(CF_InschoolStatus).Name);
- Expression<Func<CF_InSchoolSetting, bool>> expInSchoolSetting = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- var query = InSchoolSettingDAL.GetInSchoolSettingViewQueryable(expInschoolStatus, expInSchoolSetting);
- if (inSchoolStatusID.HasValue)
- {
- query = query.Where(x => x.InSchoolStatusID == inSchoolStatusID);
- }
- if (isSelected.HasValue)
- {
- if (isSelected == (int)CF_GeneralPurpose.IsYes)
- {
- query = query.Where(x => x.IsSelected == true);
- }
- if (isSelected == (int)CF_GeneralPurpose.IsNo)
- {
- query = query.Where(x => x.IsSelected != true);
- }
- }
- if (isDisplayID.HasValue)
- {
- if (isDisplayID == (int)CF_GeneralPurpose.IsYes)
- {
- query = query.Where(x => x.IsDisplay == true);
- }
- if (isDisplayID == (int)CF_GeneralPurpose.IsNo)
- {
- query = query.Where(x => x.IsDisplay != true);
- }
- }
- //查询条件
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- {
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
- }
- return query.OrderBy(x => x.InSchoolStatusID).ToGridResultSet<InSchoolSettingView>(pageIndex, pageSize);
- }
- /// <summary>
- /// 查询对应的在校设定信息List
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="inSchoolStatusID"></param>
- /// <param name="isSelected"></param>
- /// <param name="isDisplayID"></param>
- /// <returns></returns>
- public IList<InSchoolSettingView> GetInSchoolSettingViewList(ConfiguretView configuretView, int? inSchoolStatusID, int? isSelected, int? isDisplayID)
- {
- Expression<Func<Sys_DictionaryItem, bool>> expInschoolStatus = (x => x.DictionaryCode == typeof(CF_InschoolStatus).Name);
- Expression<Func<CF_InSchoolSetting, bool>> expInSchoolSetting = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- var query = InSchoolSettingDAL.GetInSchoolSettingViewQueryable(expInschoolStatus, expInSchoolSetting);
- if (inSchoolStatusID.HasValue)
- {
- query = query.Where(x => x.InSchoolStatusID == inSchoolStatusID);
- }
- if (isSelected.HasValue)
- {
- if (isSelected == (int)CF_GeneralPurpose.IsYes)
- {
- query = query.Where(x => x.IsSelected == true);
- }
- if (isSelected == (int)CF_GeneralPurpose.IsNo)
- {
- query = query.Where(x => x.IsSelected != true);
- }
- }
- if (isDisplayID.HasValue)
- {
- if (isDisplayID == (int)CF_GeneralPurpose.IsYes)
- {
- query = query.Where(x => x.IsDisplay == true);
- }
- if (isDisplayID == (int)CF_GeneralPurpose.IsNo)
- {
- query = query.Where(x => x.IsDisplay != true);
- }
- }
- //查询条件
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- {
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
- }
- return query.OrderBy(x => x.InSchoolStatusID).ToList();
- }
- /// <summary>
- /// 查询对应的在校设定中状态List
- /// </summary>
- /// <param name="isSelected"></param>
- /// <returns></returns>
- public List<int?> GetInschoolStatusList(bool? isSelected)
- {
- Expression<Func<Sys_DictionaryItem, bool>> expInschoolStatus = (x => x.DictionaryCode == typeof(CF_InschoolStatus).Name);
- Expression<Func<CF_InSchoolSetting, bool>> expInSchoolSetting = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- var inSchoolSettingViewList = InSchoolSettingDAL.GetInSchoolSettingViewQueryable(expInschoolStatus, expInSchoolSetting);
- var inSchoolStatusIDList = inSchoolSettingViewList.Where(x => x.IsSelected == isSelected).Select(x => x.InSchoolStatusID).ToList();
- return inSchoolStatusIDList;
- }
- /// <summary>
- /// 查询对应的在校设定信息InSchoolSettingView(根据在校设定ID)
- /// </summary>
- /// <param name="inSchoolSettingID"></param>
- /// <returns></returns>
- public InSchoolSettingView GetInSchoolSettingView(Guid? inSchoolSettingID)
- {
- try
- {
- var inSchoolSettingView = InSchoolSettingDAL.GetInSchoolSettingViewQueryable(x => x.InSchoolSettingID == inSchoolSettingID).SingleOrDefault();
- return inSchoolSettingView;
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- /// <summary>
- /// 设置(新增、修改、删除)
- /// </summary>
- /// <param name="inSchoolSettingViewList"></param>
- public void InSchoolSettingEdit(IEnumerable<InSchoolSettingView> inSchoolSettingViewList)
- {
- try
- {
- var inSchoolSettingInList = new List<CF_InSchoolSetting>();
- var inSchoolSettingUpList = new List<CF_InSchoolSetting>();
- var inschoolStatusList = InSchoolSettingDAL.DictionaryItemRepository.GetList(x => x.DictionaryCode == typeof(CF_InschoolStatus).Name).ToList();
- var inschoolStatusIDList = inschoolStatusList.Select(x => x.Value).ToList();
- var inSchoolSettingList = InSchoolSettingDAL.InSchoolSettingRepository.GetList(x => true);
- var inSchoolSettingIDDelList = inSchoolSettingList.Where(x => !inschoolStatusIDList.Contains(x.InSchoolStatusID)).Select(x => x.InSchoolSettingID).ToList();
- foreach (var inSchoolSettingView in inSchoolSettingViewList)
- {
- if (inSchoolSettingView.InSchoolSettingID == null || inSchoolSettingView.InSchoolSettingID == Guid.Empty)
- {
- var inSchoolSetting = inSchoolSettingList.Where(x => x.InSchoolStatusID == inSchoolSettingView.InSchoolStatusID).SingleOrDefault();
- if (inSchoolSetting != null)
- {
- inSchoolSettingIDDelList.Add(inSchoolSetting.InSchoolSettingID);
- }
- var newInSchoolSetting = new CF_InSchoolSetting();
- newInSchoolSetting.InSchoolSettingID = Guid.NewGuid();
- newInSchoolSetting.InSchoolStatusID = inSchoolSettingView.InSchoolStatusID;
- newInSchoolSetting.IsSelected = inSchoolSettingView.IsSelected == null ? false : inSchoolSettingView.IsSelected;
- SetNewStatus(newInSchoolSetting);
- inSchoolSettingInList.Add(newInSchoolSetting);
- }
- else
- {
- var inSchoolSetting = inSchoolSettingList.SingleOrDefault(x => x.InSchoolSettingID == inSchoolSettingView.InSchoolSettingID);
- inSchoolSetting.IsSelected = inSchoolSettingView.IsSelected == null ? false : inSchoolSettingView.IsSelected;
- SetModifyStatus(inSchoolSetting);
- inSchoolSettingUpList.Add(inSchoolSetting);
- }
- }
- using (TransactionScope ts = new TransactionScope())
- {
- UnitOfWork.Delete<CF_InSchoolSetting>(x => inSchoolSettingIDDelList.Contains(x.InSchoolSettingID));
- UnitOfWork.BulkInsert<CF_InSchoolSetting>(inSchoolSettingInList);
- if (inSchoolSettingUpList != null && inSchoolSettingUpList.Count() > 0)
- {
- UnitOfWork.BatchUpdate<CF_InSchoolSetting>(inSchoolSettingUpList);
- }
- ts.Complete();
- }
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- }
- }
|