using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Bowin.Common.Linq.Entity;
using EMIS.ViewModel;
using EMIS.ViewModel.MinorGraduation.MinorGraduationSetting;
using System.Linq.Expressions;
using EMIS.Entities;
using Bowin.Common.Linq;
using EMIS.DataLogic.MinorGraduation.MinorGraduationSetting;
using EMIS.DataLogic.MinorManage.MinorPlanManage;
namespace EMIS.CommonLogic.MinorGraduation.MinorGraduationSetting
{
public class MinorGraduationStandardServices : BaseServices, IMinorGraduationStandardServices
{
public MinorGraduationStandardDAL minorGraduationStandardDAL { get; set; }
public MinorSpecialtyDAL minorSpecialtyDAL { get; set; }
///
/// 辅修毕业要求列表信息
///
///
///
///
///
///
///
///
public IGridResultSet GetMinorGraduationStandardViewGrid(ConfiguretView configuretView, Guid? collegeID, int? yearID, int? standardID, int pageIndex, int pageSize)
{
Expression> exp = x => true;
if (collegeID.HasValue)
{
exp = exp.And(x => x.CollegeID == collegeID);
}
if (yearID.HasValue)
{
exp = exp.And(x => x.YearID == yearID);
}
if (standardID.HasValue)
{
exp = exp.And(x => x.StandardID == standardID);
}
var query = minorGraduationStandardDAL.GetMinorGraduationStandardView(exp);
//查询条件
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
{
query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
}
return this.GetQueryByDataRangeByCollege(query)
.OrderByDescending(x => x.YearID).OrderBy(x => x.StandardID)
.ToGridResultSet(pageIndex, pageSize);
}
///
/// 辅修毕业要求列表信息(Excel)
///
///
///
///
///
///
///
public List GetMinorGraduationStandardViewList(ConfiguretView configuretView, Guid? collegeID, int? yearID, int? standardID, List idList)
{
Expression> exp = x => true;
if (collegeID.HasValue)
{
exp = exp.And(x => x.CollegeID == collegeID);
}
if (yearID.HasValue)
{
exp = exp.And(x => x.YearID == yearID);
}
if (standardID.HasValue)
{
exp = exp.And(x => x.StandardID == standardID);
}
if (idList != null && idList.Count > 0)
{
exp = exp.And(x => idList.Contains(x.MinorGraduationStandardID));
}
var query = minorGraduationStandardDAL.GetMinorGraduationStandardView(exp);
//查询条件
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
{
query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
}
return this.GetQueryByDataRangeByCollege(query).OrderByDescending(x => x.YearID).OrderBy(x => x.StandardID).ToList();
}
///
/// 查询单个辅修毕业要求
///
///
///
public MinorGraduationStandardView GetMinorGraduationStandardView(Guid? minorGraduationStandardID)
{
try
{
var query = minorGraduationStandardDAL.GetMinorGraduationStandardView(x => x.MinorGraduationStandardID == minorGraduationStandardID)
.SingleOrDefault();
return query;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// 生成
///
///
public void MinorGraduationStandardGenerate(int? yearID, Guid? collegeID)
{
try
{
Expression> exp = x => true;
exp = exp.And(x => x.RecordStatus == (int)CF_GrademinorStatus.Opened || x.RecordStatus == (int)CF_GrademinorStatus.Confirmed);
if (yearID.HasValue)
{
exp = exp.And(x => x.YearID == yearID);
}
if (collegeID.HasValue)
{
exp = exp.And(x => x.CollegeID == collegeID);
}
var grademinorList = minorSpecialtyDAL.GetMinorSpecialtyViewQueryable(exp).ToList();
List minorGraduationStandardList = new List();
var dbminorGraduationStandardList = minorGraduationStandardDAL.GetMinorGraduationStandardView(x => true).ToList();
foreach (var grademinor in grademinorList)
{
if (dbminorGraduationStandardList.Any(x => x.CollegeID == grademinor.CollegeID && x.YearID == grademinor.YearID && x.StandardID == grademinor.StandardID))
{
continue;
}
ER_MinorGraduationStandard minorGraduationStandard = new ER_MinorGraduationStandard();
minorGraduationStandard.MinorGraduationStandardID = Guid.NewGuid();
minorGraduationStandard.CollegeID = grademinor.CollegeID;
minorGraduationStandard.YearID = grademinor.YearID;
minorGraduationStandard.StandardID = grademinor.StandardID;
minorGraduationStandard.GraduationCredit = 0;
SetNewStatus(minorGraduationStandard);
minorGraduationStandardList.Add(minorGraduationStandard);
}
UnitOfWork.BulkInsert(minorGraduationStandardList);
UnitOfWork.Commit();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// 编辑(新增、修改,业务主键:年级专业ID)
///
///
public void MinorGraduationStandardEdit(MinorGraduationStandardView minorGraduationStandardView)
{
try
{
//查询数据库进行验证
var minorGraduationStandardVerification = minorGraduationStandardDAL.minorGraduationStandardRepository
.GetList(x => x.MinorGraduationStandardID != minorGraduationStandardView.MinorGraduationStandardID
&& x.StandardID == minorGraduationStandardView.StandardID && x.YearID == minorGraduationStandardView.YearID)
.SingleOrDefault();
if (minorGraduationStandardVerification == null)
{
//数据有误验证
if (minorGraduationStandardView.MinorGraduationStandardID != Guid.Empty)
{
var minorGraduationStandard = minorGraduationStandardDAL.minorGraduationStandardRepository
.GetList(x => x.MinorGraduationStandardID == minorGraduationStandardView.MinorGraduationStandardID)
.SingleOrDefault();
if (minorGraduationStandard == null)
{
throw new Exception("数据有误,请核查");
}
else
{
//表示修改
minorGraduationStandard.GraduationCredit = minorGraduationStandardView.GraduationCredit;
SetModifyStatus(minorGraduationStandard);
}
}
else
{
//表示新增
ER_MinorGraduationStandard minorGraduationStandard = new ER_MinorGraduationStandard();
minorGraduationStandard.MinorGraduationStandardID = Guid.NewGuid();
minorGraduationStandard.CollegeID = minorGraduationStandardView.CollegeID;
minorGraduationStandard.YearID = minorGraduationStandardView.YearID;
minorGraduationStandard.StandardID = minorGraduationStandardView.StandardID;
minorGraduationStandard.GraduationCredit = minorGraduationStandardView.GraduationCredit;
SetNewStatus(minorGraduationStandard);
UnitOfWork.Add(minorGraduationStandard);
}
}
else
{
throw new Exception("已存在相同的辅修毕业标准,请核查");
}
//事务提交
UnitOfWork.Commit();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// 删除
///
///
///
public void MinorGraduationStandardDelete(List minorGraduationStandardIDs)
{
try
{
UnitOfWork.Delete(x => minorGraduationStandardIDs.Contains(x.MinorGraduationStandardID));
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
}
}