using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Bowin.Common.Linq.Entity;
using EMIS.ViewModel.MinorGraduation.MinorGraduationSetting;
using EMIS.ViewModel;
using System.Linq.Expressions;
using EMIS.Entities;
using Bowin.Common.Linq;
using EMIS.DataLogic.MinorGraduation.MinorGraduationSetting;
using EMIS.CommonLogic.ChargeManage.ArrearsSituation;
namespace EMIS.CommonLogic.MinorGraduation.MinorGraduationSetting
{
public class MinorGraduationConditionServices : BaseServices, IMinorGraduationConditionServices
{
public MinorGraduationConditionDAL minorGraduationConditionDAL { get; set; }
public MinorGraduationStandardDAL minorGraduationStandardDAL { get; set; }
public IArrearsListServices arrearsListServices { get; set; }
///
/// 查询辅修条件
///
///
///
///
///
///
public IGridResultSet GetMinorGraduationConditionViewGrid(ConfiguretView configuretView, int? isCurrent, int pageIndex, int pageSize)
{
//辅修毕业条件
Expression> exp = (x => true);
if (isCurrent.HasValue)
{
if (isCurrent == 1)
{
exp = exp.And(x => x.RecordStatus >= (int)SYS_STATUS.USABLE);
}
if (isCurrent == 0)
{
exp = exp.And(x => x.RecordStatus <= (int)SYS_STATUS.UNUSABLE);
}
}
var query = minorGraduationConditionDAL.GetMinorGraduationConditionQueryable(exp);
//查询条件
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
{
query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
}
return query.OrderBy(x => x.Title.Length).OrderBy(x => x.Title).ToGridResultSet(pageIndex, pageSize);
}
public List GetGraduationViewList(ConfiguretView configuretView, int? isCurrent, List idList)
{
//毕业条件
Expression> exp = (x => true);
if (isCurrent.HasValue)
{
if (isCurrent == 1)
{
exp = exp.And(x => x.RecordStatus >= (int)SYS_STATUS.USABLE);
}
if (isCurrent == 0)
{
exp = exp.And(x => x.RecordStatus <= (int)SYS_STATUS.UNUSABLE);
}
}
if (idList != null && idList.Count > 0)
{
exp = exp.And(x => idList.Contains(x.MinorGraduationConditionID));
}
var query = minorGraduationConditionDAL.GetMinorGraduationConditionQueryable(exp);
//查询条件
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
{
query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
}
return query.OrderBy(x => x.Title.Length).OrderBy(x => x.Title).ToList();
}
///
/// 查询单个辅修条件
///
///
///
public MinorGraduationConditionView GetMinorGraduationConditionView(Guid? minorGraduationConditionID)
{
try
{
var query = minorGraduationConditionDAL
.GetMinorGraduationConditionQueryable(x => x.MinorGraduationConditionID == minorGraduationConditionID)
.SingleOrDefault();
return query;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// 编辑
///
///
public void MinorGraduationConditionEdit(MinorGraduationConditionView minorGraduationConditionView)
{
try
{
//查询数据库进行验证
var minorGraduationConditionVerification = minorGraduationConditionDAL.minorGraduationConditionRepository
.GetList(x => x.MinorGraduationConditionID != minorGraduationConditionView.MinorGraduationConditionID
&& x.Title == minorGraduationConditionView.Title)
.SingleOrDefault();
if (minorGraduationConditionVerification == null)
{
//数据有误验证
if (minorGraduationConditionVerification.MinorGraduationConditionID != Guid.Empty)
{
var graduationCondition = minorGraduationConditionDAL.minorGraduationConditionRepository
.GetList(x => x.MinorGraduationConditionID == minorGraduationConditionView.MinorGraduationConditionID)
.SingleOrDefault();
if (graduationCondition == null)
{
throw new Exception("数据有误,请核查");
}
else
{
//表示修改
graduationCondition.Title = minorGraduationConditionView.Title;
graduationCondition.RecordStatus = minorGraduationConditionView.IsEnable ? (int)SYS_STATUS.USABLE : (int)SYS_STATUS.UNUSABLE;
SetModifyStatus(graduationCondition);
}
}
else
{
//表示新增
ER_MinorGraduationCondition minorGraduationCondition = new ER_MinorGraduationCondition();
minorGraduationCondition.MinorGraduationConditionID = Guid.NewGuid();
minorGraduationCondition.Title = minorGraduationConditionView.Title;
minorGraduationCondition.MethodFullName = minorGraduationConditionView.MethodFullName;
SetNewStatus(minorGraduationConditionView);
UnitOfWork.Add(minorGraduationConditionView);
}
}
else
{
throw new Exception("已存在相同条件名称的辅修毕业条件,请核查");
}
//事务提交
UnitOfWork.Commit();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// 所学学分达到专业要求学分
///
///
///
public bool PassGraduationCredit(Guid? userID)
{
try
{
var minorGraduationStandard = minorGraduationStandardDAL.GetMinorGraduationStandardViewByUserID(userID);
if (minorGraduationStandard.FirstOrDefault() == null)
{
throw new Exception("未设置学生所在辅修专业的辅修专业标准");
}
else {
var graduationCredit = minorGraduationStandard.FirstOrDefault().GraduationCredit;
var studentScore = minorGraduationConditionDAL.GetFinallyScoreViewQueryableByUserID(userID);
var scoreCredit = studentScore.Sum(x => x.ScoreCredit);
if (scoreCredit != null && scoreCredit >= graduationCredit)
{
return true;
}
}
return false;
}
catch (Exception)
{
throw;
}
}
///
/// 没有欠费
///
///
///
public bool NotArrearManage(Guid? userID)
{
try
{
var arrearListView = arrearsListServices.GetArrearListView(userID);
if (arrearListView == null)
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// 无条件(测试)
///
///
///
public bool NotCondition(Guid? userID)
{
return true;
}
}
}