using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Bowin.Common.Linq;
using Bowin.Common.Linq.Entity;
using EMIS.ViewModel.SelectCourse;
using EMIS.ViewModel;
using System.Linq.Expressions;
using EMIS.Entities;
using EMIS.DataLogic.SelectCourse;
namespace EMIS.CommonLogic.SelectCourse
{
public class ExaminationSubjectCollegeControlServices : BaseServices, IExaminationSubjectCollegeControlServices
{
public ExaminationSubjectCollegeControlDAL examinationSubjectCollegeControlDAL { get; set; }
///
/// 列表查询
///
///
///
///
///
///
///
///
///
///
public IGridResultSet GetExaminationSubjectCollegeControlViewGrid(ConfiguretView configuretView, Guid? examinationTypeID, Guid? examinationSubjectID, Guid? collegeID, Guid? facultymajorID, int? schoolyearNumID, int pageIndex, int pageSize)
{
Expression> esccexp = x => true;
Expression> esexp= x => true;
Expression> fexp = x => true;
if (examinationTypeID.HasValue)
{
esexp = esexp.And(x => x.ExaminationTypeID == examinationTypeID);
}
if (examinationSubjectID.HasValue)
{
esccexp = esccexp.And(x => x.ExaminationSubjectID == examinationSubjectID);
}
if (collegeID.HasValue)
{
fexp = fexp.And(x => x.CollegeID == collegeID);
}
if (facultymajorID.HasValue)
{
esccexp = esccexp.And(x => x.FacultymajorID == facultymajorID);
}
if (schoolyearNumID.HasValue)
{
esccexp = esccexp.And(x => x.SchoolyearNumID == schoolyearNumID);
}
var query = examinationSubjectCollegeControlDAL.GetExaminationSubjectCollegeControlView(esccexp, esexp, fexp);
if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute))
query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
var result = GetQueryByDataRangeByCollege(query);
return result.OrderBy(x => x.ExaminationSubjectName.Length).ThenBy(x => x.ExaminationSubjectName).ThenBy(x => x.CollegeName.Length).ThenBy(x => x.CollegeName).ThenBy(x => x.SchoolyearNumID).ToGridResultSet(pageIndex, pageSize);
}
///
/// excel导出
///
///
///
///
///
///
///
///
///
public List GetExaminationSubjectCollegeControlViewList(ConfiguretView configuretView, Guid? examinationTypeID, Guid? examinationSubjectID, Guid? collegeID, Guid? facultymajorID, int? schoolyearNumID, List idList)
{
Expression> esccexp = x => true;
Expression> esexp = x => true;
Expression> fexp = x => true;
if (examinationTypeID.HasValue)
{
esexp = esexp.And(x => x.ExaminationTypeID == examinationTypeID);
}
if (examinationSubjectID.HasValue)
{
esccexp = esccexp.And(x => x.ExaminationSubjectID == examinationSubjectID);
}
if (collegeID.HasValue)
{
fexp = fexp.And(x => x.CollegeID == collegeID);
}
if (facultymajorID.HasValue)
{
esccexp = esccexp.And(x => x.FacultymajorID == facultymajorID);
}
if (schoolyearNumID.HasValue)
{
esccexp = esccexp.And(x => x.SchoolyearNumID == schoolyearNumID);
}
if (idList.Count > 0)
{
esccexp = esccexp.And(x => idList.Contains(x.ExaminationSubjectCollegeControlID));
}
var query = examinationSubjectCollegeControlDAL.GetExaminationSubjectCollegeControlView(esccexp, esexp, fexp);
if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute))
query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
var result = GetQueryByDataRangeByCollege(query);
return result.OrderBy(x => x.ExaminationSubjectName.Length).ThenBy(x => x.ExaminationSubjectName).ThenBy(x => x.CollegeName.Length).ThenBy(x => x.CollegeName).ThenBy(x => x.SchoolyearNumID).ToList();
}
public ExaminationSubjectCollegeControlView GetExaminationSubjectCollegeControlView(Guid? examinationSubjectCollegeControlID)
{
Expression> esccexp = x => x.ExaminationSubjectCollegeControlID == examinationSubjectCollegeControlID;
var query = examinationSubjectCollegeControlDAL.GetExaminationSubjectCollegeControlView(esccexp, x => true, x => true).FirstOrDefault();
return query;
}
///
/// 新增
///
///
///
public void ExaminationSubjectCollegeControlAdd(ExaminationSubjectCollegeControlView examinationSubjectCollegeControlView, List facultymajorIDList)
{
try
{
if (facultymajorIDList.Count > 0)
{
List examinationSubjectCollegeControlList = new List();
foreach (Guid facultymajorID in facultymajorIDList)
{
EX_ExaminationSubjectCollegeControl examinationSubjectCollegeControl = new EX_ExaminationSubjectCollegeControl();
//新增
examinationSubjectCollegeControl = examinationSubjectCollegeControlDAL.examinationSubjectCollegeControlRepository
.GetSingle(x => x.ExaminationSubjectID == examinationSubjectCollegeControlView.ExaminationSubjectID && x.FacultymajorID == examinationSubjectCollegeControlView.FacultymajorID
&& x.SchoolyearNumID == examinationSubjectCollegeControlView.SchoolyearNumID);
if (examinationSubjectCollegeControl != null)
{
throw new Exception("已存在相同的专业报考限制信息。");
}
examinationSubjectCollegeControl = new EX_ExaminationSubjectCollegeControl();
examinationSubjectCollegeControl.ExaminationSubjectCollegeControlID = Guid.NewGuid();
examinationSubjectCollegeControl.ExaminationSubjectID = examinationSubjectCollegeControlView.ExaminationSubjectID;
examinationSubjectCollegeControl.FacultymajorID = facultymajorID;
examinationSubjectCollegeControl.SchoolyearNumID = examinationSubjectCollegeControlView.SchoolyearNumID == -1 ? null : examinationSubjectCollegeControlView.SchoolyearNumID;
SetNewStatus(examinationSubjectCollegeControl);
examinationSubjectCollegeControlList.Add(examinationSubjectCollegeControl);
}
UnitOfWork.BulkInsert(examinationSubjectCollegeControlList);
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// 修改
///
///
public void ExaminationSubjectCollegeControlEdit(ExaminationSubjectCollegeControlView examinationSubjectCollegeControlView)
{
try
{
EX_ExaminationSubjectCollegeControl examinationSubjectCollegeControl = new EX_ExaminationSubjectCollegeControl();
//修改
examinationSubjectCollegeControl = examinationSubjectCollegeControlDAL.examinationSubjectCollegeControlRepository
.GetSingle(x => x.ExaminationSubjectCollegeControlID != examinationSubjectCollegeControlView.ExaminationSubjectCollegeControlID
&& x.ExaminationSubjectID == examinationSubjectCollegeControlView.ExaminationSubjectID && x.FacultymajorID == examinationSubjectCollegeControlView.FacultymajorID
&& x.SchoolyearNumID == examinationSubjectCollegeControlView.SchoolyearNumID);
if (examinationSubjectCollegeControl != null)
{
throw new Exception("已存在相同的专业报考限制信息。");
}
examinationSubjectCollegeControl = examinationSubjectCollegeControlDAL.examinationSubjectCollegeControlRepository
.GetSingle(x => x.ExaminationSubjectCollegeControlID == examinationSubjectCollegeControlView.ExaminationSubjectCollegeControlID);
if (examinationSubjectCollegeControl == null)
{
throw new Exception("数据有误,请核查。");
}
examinationSubjectCollegeControl.ExaminationSubjectID = examinationSubjectCollegeControlView.ExaminationSubjectID;
examinationSubjectCollegeControl.FacultymajorID = examinationSubjectCollegeControlView.FacultymajorID;
examinationSubjectCollegeControl.SchoolyearNumID = examinationSubjectCollegeControlView.SchoolyearNumID == -1 ? null : examinationSubjectCollegeControlView.SchoolyearNumID;
SetModifyStatus(examinationSubjectCollegeControl);
UnitOfWork.Commit();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// 删除
///
///
public void ExaminationSubjectCollegeControlDelete(IList examinationSubjectCollegeControlIDList)
{
try
{
if (examinationSubjectCollegeControlIDList.Count > 0)
{
UnitOfWork.Delete(x => examinationSubjectCollegeControlIDList.Contains(x.ExaminationSubjectCollegeControlID));
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
}
}