using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Bowin.Common.Linq;
using Bowin.Common.Linq.Entity;
using EMIS.ViewModel;
using EMIS.ViewModel.StudentManage.OnlineChecking;
using EMIS.ViewModel.SystemView;
using EMIS.DataLogic.StudentManage.OnlineChecking;
using EMIS.Entities;
using System.Linq.Expressions;
namespace EMIS.CommonLogic.StudentManage.OnlineChecking
{
public class OpenObjectServices : BaseServices, IOpenObjectServices
{
public OpenObjectDAL OpenObjectDAL { get; set; }
///
/// 查询对应的学生校对控制开放对象信息OpenObjectView
///
///
///
///
///
///
///
///
public IGridResultSet GetStudentEditObjectViewGrid(ConfiguretView configuretView, int? educationID, int? schoolyearNumID, DateTime? dateRange, int pageIndex, int pageSize)
{
Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
if (educationID.HasValue)
{
exp = exp.And(x => x.EducationID == educationID);
}
if (schoolyearNumID.HasValue)
{
exp = exp.And(x => x.SchoolyearNumID == schoolyearNumID);
}
if (dateRange.HasValue)
{
exp = exp.And(x => x.Starttime <= dateRange);
}
if (dateRange.HasValue)
{
exp = exp.And(x => x.Endtime >= dateRange);
}
var query = OpenObjectDAL.GetStudentEditObjectQueryable(exp);
//查询条件
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
{
query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
}
return query.OrderBy(x => x.EducationID).ThenBy(x => x.SchoolyearNumID).ToGridResultSet(pageIndex, pageSize);
}
///
/// 查询对应的学生校对控制开放对象信息List
///
///
///
///
///
///
public IList GetStudentEditObjectViewList(ConfiguretView configuretView, int? educationID, int? schoolyearNumID, DateTime? dateRange)
{
Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
if (educationID.HasValue)
{
exp = exp.And(x => x.EducationID == educationID);
}
if (schoolyearNumID.HasValue)
{
exp = exp.And(x => x.SchoolyearNumID == schoolyearNumID);
}
if (dateRange.HasValue)
{
exp = exp.And(x => x.Starttime <= dateRange);
}
if (dateRange.HasValue)
{
exp = exp.And(x => x.Endtime >= dateRange);
}
var query = OpenObjectDAL.GetStudentEditObjectQueryable(exp);
//查询条件
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
{
query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
}
return query.OrderBy(x => x.EducationID).ThenBy(x => x.SchoolyearNumID).ToList();
}
///
/// 查询对应的开放对象信息OpenObjectView
///
///
///
public OpenObjectView GetStudentEditObjectView(Guid? studentEditObjectID)
{
try
{
Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
exp = exp.And(x => x.StudentEditObjectsID == studentEditObjectID);
var query = OpenObjectDAL.GetStudentEditObjectQueryable(exp).SingleOrDefault();
return query;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// 编辑(新增、修改)
///
///
public void StudentEditObjectEdit(OpenObjectView openObjectView)
{
try
{
var studentEditObjectVerify = OpenObjectDAL.StudentEditObjectsRepository.GetList(x => x.StudentEditObjectsID != openObjectView.StudentEditObjectsID
&& x.EducationID == openObjectView.EducationID && x.SchoolyearNumID == openObjectView.SchoolyearNumID).SingleOrDefault();
if (studentEditObjectVerify == null)
{
if (openObjectView.StudentEditObjectsID != Guid.Empty)
{
var studentEditObject = OpenObjectDAL.StudentEditObjectsRepository.GetList(x => x.StudentEditObjectsID == openObjectView.StudentEditObjectsID).SingleOrDefault();
if (studentEditObject == null)
{
throw new Exception("数据有误,请核查。");
}
else
{
//表示修改
studentEditObject.EducationID = openObjectView.EducationID;
studentEditObject.SchoolyearNumID = openObjectView.SchoolyearNumID;
studentEditObject.Starttime = openObjectView.Starttime;
studentEditObject.Endtime = openObjectView.Endtime;
studentEditObject.Remark = openObjectView.Remark;
SetModifyStatus(studentEditObject);
}
}
else
{
//表示新增
var newStudentEditObject = new CF_StudentEditObjects();
newStudentEditObject.StudentEditObjectsID = Guid.NewGuid();
newStudentEditObject.EducationID = openObjectView.EducationID;
newStudentEditObject.SchoolyearNumID = openObjectView.SchoolyearNumID;
newStudentEditObject.Starttime = openObjectView.Starttime;
newStudentEditObject.Endtime = openObjectView.Endtime;
newStudentEditObject.Remark = openObjectView.Remark;
SetNewStatus(newStudentEditObject);
UnitOfWork.Add(newStudentEditObject);
}
}
else
{
throw new Exception("已存在相同的开放对象信息,请核查。");
}
UnitOfWork.Commit();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// 开放对象批量新增
///
///
///
///
public string StudentEditObjectBatchAdd(List schoolyearNumIDList, OpenObjectView openObjectView)
{
try
{
Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
exp = exp.And(x => schoolyearNumIDList.Contains(x.SchoolyearNumID));
var studentEditObjectList = OpenObjectDAL.StudentEditObjectsRepository.GetList(exp).ToList();
int success = 0;
int fail = 0;
string tipMessage = null;
List studentEditObjectInList = new List();
foreach (var schoolyearNumID in schoolyearNumIDList)
{
var studentEditObjectVerify = studentEditObjectList.Where(x => x.EducationID == openObjectView.EducationID &&
x.SchoolyearNumID == schoolyearNumID).SingleOrDefault();
if (studentEditObjectVerify == null)
{
//新增
var newStudentEditObject = new CF_StudentEditObjects();
newStudentEditObject.StudentEditObjectsID = Guid.NewGuid();
newStudentEditObject.EducationID = openObjectView.EducationID;
newStudentEditObject.SchoolyearNumID = schoolyearNumID;
newStudentEditObject.Starttime = openObjectView.Starttime;
newStudentEditObject.Endtime = openObjectView.Endtime;
//newStudentEditObject.Remark = openObjectView.Remark;
SetNewStatus(newStudentEditObject);
studentEditObjectInList.Add(newStudentEditObject);
success++;
}
else
{
//表示已存在相同的开放对象信息
fail++;
}
}
UnitOfWork.BulkInsert(studentEditObjectInList);
if (success > 0 && fail <= 0)
{
tipMessage = success + "条";
}
else
{
tipMessage = success + "条," + fail + "条失败,原因:已存在相同的开放对象信息,请检查";
}
return tipMessage;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// 查询开放对象中未新增的培养层次信息DictionaryItemView
///
///
///
///
///
///
public IGridResultSet GetSchoolyearNumNoAddGrid(ConfiguretView configuretView, int? educationID, int pageIndex, int pageSize)
{
Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
if (educationID.HasValue)
{
exp = exp.And(x => x.EducationID == educationID);
}
var query = OpenObjectDAL.GetSchoolyearNumNoAddQueryable(exp);
query = query.Where(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
//查询条件
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
{
query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
}
return query.OrderBy(x => x.DictionaryCode).ThenBy(x => x.OrderNo).ToGridResultSet(pageIndex, pageSize);
}
///
/// 查询开放对象中未新增的培养层次信息List
///
///
///
///
public IList GetSchoolyearNumNoAddList(ConfiguretView configuretView, int? educationID)
{
Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
if (educationID.HasValue)
{
exp = exp.And(x => x.EducationID == educationID);
}
var query = OpenObjectDAL.GetSchoolyearNumNoAddQueryable(exp);
query = query.Where(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
//查询条件
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
{
query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
}
return query.OrderBy(x => x.DictionaryCode).ThenBy(x => x.OrderNo).ToList();
}
///
/// 删除
///
///
///
public bool StudentEditObjectDelete(List studentEditObjectIDs)
{
try
{
UnitOfWork.Delete(x => studentEditObjectIDs.Contains(x.StudentEditObjectsID));
return true;
}
catch (Exception)
{
throw;
}
}
}
}