using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using Bowin.Common.Linq.Entity;
using Bowin.Common.Linq;
using EMIS.Utility;
using EMIS.Entities;
using EMIS.ViewModel;
using EMIS.ViewModel.EducationManage;
using EMIS.DataLogic.EducationManage;
using EMIS.ViewModel.UniversityManage.AdministrativeOrgan;
namespace EMIS.CommonLogic.EducationManage
{
public class EducationMissionOpenControlServices : BaseServices, IEducationMissionOpenControlServices
{
public EducationMissionOpenControlDAL EducationMissionOpenControlDAL { get; set; }
///
/// 查询对应的教学任务控制信息EducationMissionOpenControlView
///
///
///
///
///
///
///
///
///
public IGridResultSet GetEducationMissionOpenControlViewGrid(ConfiguretView configuretView,
Guid? schoolyearID, Guid? campusID, Guid? collegeID, DateTime? dateRange, int pageIndex, int pageSize)
{
Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
if (schoolyearID.HasValue)
{
exp = exp.And(x => x.SchoolyearID == schoolyearID);
}
if (collegeID.HasValue)
{
exp = exp.And(x => x.CollegeID == collegeID);
}
if (dateRange.HasValue)
{
exp = exp.And(x => x.StartDate <= dateRange);
}
if (dateRange.HasValue)
{
exp = exp.And(x => x.EndDate >= dateRange);
}
var query = EducationMissionOpenControlDAL.GetEducationMissionOpenControlViewQueryable(exp);
if (campusID.HasValue)
{
query = query.Where(x => x.CampusID == campusID);
}
//查询条件
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
{
query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
}
return this.GetQueryByDataRangeByCollege(query).OrderByDescending(x => x.Value)
.ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo)
.ToGridResultSet(pageIndex, pageSize);
}
///
/// 查询对应的教学任务控制信息List
///
///
///
///
///
///
///
public List GetEducationMissionOpenControlViewList(ConfiguretView configuretView,
Guid? schoolyearID, Guid? campusID, Guid? collegeID, DateTime? dateRange)
{
Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
if (schoolyearID.HasValue)
{
exp = exp.And(x => x.SchoolyearID == schoolyearID);
}
if (collegeID.HasValue)
{
exp = exp.And(x => x.CollegeID == collegeID);
}
if (dateRange.HasValue)
{
exp = exp.And(x => x.StartDate <= dateRange);
}
if (dateRange.HasValue)
{
exp = exp.And(x => x.EndDate >= dateRange);
}
var query = EducationMissionOpenControlDAL.GetEducationMissionOpenControlViewQueryable(exp);
if (campusID.HasValue)
{
query = query.Where(x => x.CampusID == campusID);
}
//查询条件
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
{
query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
}
return this.GetQueryByDataRangeByCollege(query).OrderByDescending(x => x.Value)
.ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo)
.ToList();
}
///
/// 根据对应的教学任务控制ID查询教学任务控制信息EducationMissionOpenControlView
///
///
///
public EducationMissionOpenControlView GetEducationMissionOpenControlView(Guid? educationMissionOpenControlID)
{
try
{
Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
exp = exp.And(x => x.EducationMissionOpenControlID == educationMissionOpenControlID);
var query = EducationMissionOpenControlDAL.GetEducationMissionOpenControlViewQueryable(exp).SingleOrDefault();
return query;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// 编辑(新增、修改)
///
///
public void EducationMissionOpenControlEdit(EducationMissionOpenControlView educationMissionOpenControlView)
{
try
{
//查询数据库进行验证
var educationMissionOpenControlVerify = EducationMissionOpenControlDAL.EducationMissionOpenControlRepository
.GetList(x => x.EducationMissionOpenControlID != educationMissionOpenControlView.EducationMissionOpenControlID
&& x.SchoolyearID == educationMissionOpenControlView.SchoolyearID
&& x.CollegeID == educationMissionOpenControlView.CollegeID).SingleOrDefault();
if (educationMissionOpenControlVerify == null)
{
//数据有误验证
if (educationMissionOpenControlView.EducationMissionOpenControlID != Guid.Empty)
{
var educationMissionOpenControl = EducationMissionOpenControlDAL.EducationMissionOpenControlRepository
.GetList(x => x.EducationMissionOpenControlID == educationMissionOpenControlView.EducationMissionOpenControlID)
.SingleOrDefault();
if (educationMissionOpenControl == null)
{
throw new Exception("数据有误,请核查。");
}
else
{
//表示修改
educationMissionOpenControl.CollegeID = educationMissionOpenControlView.CollegeID;
educationMissionOpenControl.SchoolyearID = educationMissionOpenControlView.SchoolyearID;
educationMissionOpenControl.StartDate = educationMissionOpenControlView.StartDate;
educationMissionOpenControl.EndDate = educationMissionOpenControlView.EndDate;
SetModifyStatus(educationMissionOpenControl);
}
}
else
{
//表示新增
EM_EducationMissionOpenControl educationMissionOpenControl = new EM_EducationMissionOpenControl();
educationMissionOpenControl.EducationMissionOpenControlID = Guid.NewGuid();
educationMissionOpenControl.CollegeID = educationMissionOpenControlView.CollegeID;
educationMissionOpenControl.SchoolyearID = educationMissionOpenControlView.SchoolyearID;
educationMissionOpenControl.StartDate = educationMissionOpenControlView.StartDate;
educationMissionOpenControl.EndDate = educationMissionOpenControlView.EndDate;
SetNewStatus(educationMissionOpenControl);
UnitOfWork.Add(educationMissionOpenControl);
}
}
else
{
throw new Exception("已存在相同的教学控制信息,请核查。");
}
//事务提交
UnitOfWork.Commit();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// 教学控制信息批量新增
///
///
///
///
public string EducationMissionOpenControlBatchAdd(List collegeIDList, EducationMissionOpenControlView educationMissionOpenControlView)
{
try
{
Expression> expEduOpenControl = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
expEduOpenControl = expEduOpenControl.And(x => collegeIDList.Contains(x.CollegeID));
var eduOpenControlList = EducationMissionOpenControlDAL.EducationMissionOpenControlRepository.GetList(expEduOpenControl).ToList();
int success = 0; //成功
int fail = 0; //失败
string tipMessage = null; //提示消息
List eduOpenControlInList = new List();
foreach (var collegeID in collegeIDList)
{
var eduOpenControlVerify = eduOpenControlList.Where(x => x.CollegeID == collegeID
&& x.SchoolyearID == educationMissionOpenControlView.SchoolyearID).SingleOrDefault();
if (eduOpenControlVerify == null)
{
//新增
var newEduOpenControl = new EM_EducationMissionOpenControl();
newEduOpenControl.EducationMissionOpenControlID = Guid.NewGuid();
newEduOpenControl.SchoolyearID = educationMissionOpenControlView.SchoolyearID;
newEduOpenControl.CollegeID = collegeID;
newEduOpenControl.StartDate = educationMissionOpenControlView.StartDate;
newEduOpenControl.EndDate = educationMissionOpenControlView.EndDate;
SetNewStatus(newEduOpenControl);
eduOpenControlInList.Add(newEduOpenControl);
success++;
}
else
{
//表示已存在相同的教学控制信息
fail++;
}
}
//批量插入
UnitOfWork.BulkInsert(eduOpenControlInList);
if (success > 0 && fail <= 0)
{
tipMessage = success + "条";
}
else
{
tipMessage = success + "条," + fail + "条失败,原因:已存在相同的教学控制信息,请检查";
}
return tipMessage;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// 查询教学控制中未新增的院系所信息CollegeView
///
///
///
///
///
///
///
///
///
public IGridResultSet GetCollegeViewNoAddGrid(ConfiguretView configuretView, Guid? campusID, Guid? collegeID,
int? unitCategoryID, Guid? schoolyearID, int pageIndex, int pageSize)
{
//院系所信息
Expression> expCollege = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
if (campusID.HasValue)
{
expCollege = expCollege.And(x => x.CampusID == campusID);
}
if (collegeID.HasValue)
{
expCollege = expCollege.And(x => x.CollegeID == collegeID);
}
if (unitCategoryID.HasValue)
{
expCollege = expCollege.And(x => x.CF_CollegeProfile.UnitCategoryID == unitCategoryID);
}
//教学控制
Expression> expEduOpenControl = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
if (schoolyearID.HasValue)
{
expEduOpenControl = expEduOpenControl.And(x => x.SchoolyearID == schoolyearID);
}
var query = EducationMissionOpenControlDAL.GetCollegeViewNoAddQueryable(expCollege, expEduOpenControl);
//查询条件
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
{
query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
}
return this.GetQueryByDataRangeByCollege(query)
.OrderBy(x => x.No.Length).ThenBy(x => x.No)
.ToGridResultSet(pageIndex, pageSize);
}
///
/// 查询教学控制中未新增的院系所信息List
///
///
///
///
///
///
public IList GetCollegeViewNoAddList(ConfiguretView configuretView, Guid? campusID, Guid? collegeID,
int? unitCategoryID, Guid? schoolyearID)
{
//院系所信息
Expression> expCollege = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
if (campusID.HasValue)
{
expCollege = expCollege.And(x => x.CampusID == campusID);
}
if (collegeID.HasValue)
{
expCollege = expCollege.And(x => x.CollegeID == collegeID);
}
if (unitCategoryID.HasValue)
{
expCollege = expCollege.And(x => x.CF_CollegeProfile.UnitCategoryID == unitCategoryID);
}
//教学控制
Expression> expEduOpenControl = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
if (schoolyearID.HasValue)
{
expEduOpenControl = expEduOpenControl.And(x => x.SchoolyearID == schoolyearID);
}
var query = EducationMissionOpenControlDAL.GetCollegeViewNoAddQueryable(expCollege, expEduOpenControl);
//查询条件
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
{
query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
}
return this.GetQueryByDataRangeByCollege(query)
.OrderBy(x => x.No.Length).ThenBy(x => x.No).ToList();
}
///
/// 删除
///
///
///
public bool EducationMissionOpenControlDelete(List educationMissionOpenControlIDs)
{
try
{
UnitOfWork.Delete(x => educationMissionOpenControlIDs.Contains(x.EducationMissionOpenControlID));
UnitOfWork.Commit();
return true;
}
catch (Exception)
{
throw;
}
}
}
}