using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Bowin.Common.Linq.Entity;
using EMIS.DataLogic.ChargeManage.ChargeSituation;
using EMIS.ViewModel;
using EMIS.ViewModel.ChargeManage.ChargeSituation;
using System.Text.RegularExpressions;
using EMIS.Entities;
using Bowin.Common.Linq;
using System.Linq.Expressions;
using EMIS.ViewModel.UniversityManage.SpecialtyClassManage;
using EMIS.ViewModel.Students;
using EMIS.CommonLogic.StudentManage.StudentStatistics;
namespace EMIS.CommonLogic.ChargeManage.ChargeSituation
{
public class ChargeStandardServices : BaseServices, IChargeStandardServices
{
public ChargeStandardDAL ChargeStandardDAL { get; set; }
public ChargeProjectDAL ChargeProjectDAL { get; set; }
public StudentChargeDAL StudentChargeDAL { get; set; }
public IInSchoolSettingServices InSchoolSettingServices { get; set; }
///
/// 查询收费标准信息列表
///
///
///
///
///
public IGridResultSet GetChargeStandardViewGrid(ConfiguretView configuretView,
Guid? collegeID, int? yearID, int? chargeYearID, int? standardID, int? educationID, int? learningformID,
Guid? chargeProjectID, string LearnSystem, int? inSchoolStatus, int pageIndex, int pageSize)
{
Expression> expChargeStandard = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
if (chargeYearID.HasValue)
{
//缴费学年
expChargeStandard = expChargeStandard.And(x => x.ChargeYear == chargeYearID);
}
if (chargeProjectID.HasValue)
{
//收费项目
expChargeStandard = expChargeStandard.And(x => x.ChargeProjectID == chargeProjectID);
}
Expression> expStudent = (x => true);
if (inSchoolStatus != null && inSchoolStatus > -1)
{
var inschoolStatusList = InSchoolSettingServices.GetInschoolStatusList(true);
if (inSchoolStatus == 1)
{
//表示在校
expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
}
if (inSchoolStatus == 0)
{
//不在校
expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
}
}
var query = ChargeStandardDAL.GetChargeStandarViewQueryAble(expChargeStandard, expStudent);
if (collegeID.HasValue)
{
query = query.Where(x => x.CollegeID == collegeID);
}
if (yearID.HasValue)
{
query = query.Where(x => x.GradeStr == yearID);
}
if (standardID.HasValue)
{
query = query.Where(x => x.StandardID == standardID);
}
if (educationID.HasValue)
{
query = query.Where(x => x.EducationID == educationID);
}
if (learningformID.HasValue)
{
query = query.Where(x => x.LearningformID == learningformID);
}
if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1")
{
var LearnSystems = Convert.ToDecimal(LearnSystem);
query = query.Where(x => x.LearnSystem == LearnSystems);
}
////去掉学生人数为0的数据
//if (inSchoolStatus != null && inSchoolStatus > -1)
//{
// query = query.Where(x => x.StudentCount > 0);
//}
//查询条件()
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
{
query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
}
return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.GrademajorStr)
.ThenByDescending(x => x.ChargeYear).ThenBy(x => x.ChargeProjectStr)
.ToGridResultSet(pageIndex, pageSize);
}
///
/// 查询收费标准信息列表
///
///
///
///
///
///
public List GetChargeStandardList(ConfiguretView configuretView, Guid? collegeID, int? yearID, int? standardID,
int? learningformID, int? chargeYearID, Guid? chargeProjectID, string LearnSystem, int? educationID, int? inSchoolStatus)
{
Expression> expChargeStandard = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
if (chargeYearID.HasValue)
{
//缴费学年
expChargeStandard = expChargeStandard.And(x => x.ChargeYear == chargeYearID);
}
if (chargeProjectID.HasValue)
{
//收费项目
expChargeStandard = expChargeStandard.And(x => x.ChargeProjectID == chargeProjectID);
}
Expression> expStudent = (x => true);
if (inSchoolStatus != null && inSchoolStatus > -1)
{
var inschoolStatusList = InSchoolSettingServices.GetInschoolStatusList(true);
if (inSchoolStatus == 1)
{
//表示在校
expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
}
if (inSchoolStatus == 0)
{
//不在校
expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
}
}
var query = ChargeStandardDAL.GetChargeStandarViewQueryAble(expChargeStandard, expStudent);
if (collegeID.HasValue)
{
query = query.Where(x => x.CollegeID == collegeID);
}
if (yearID.HasValue)
{
query = query.Where(x => x.GradeStr == yearID);
}
if (standardID.HasValue)
{
query = query.Where(x => x.StandardID == standardID);
}
if (educationID.HasValue)
{
query = query.Where(x => x.EducationID == educationID);
}
if (learningformID.HasValue)
{
query = query.Where(x => x.LearningformID == learningformID);
}
if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1")
{
var LearnSystems = Convert.ToDecimal(LearnSystem);
query = query.Where(x => x.LearnSystem == LearnSystems);
}
////去掉学生人数为0的数据
//if (inSchoolStatus != null && inSchoolStatus > -1)
//{
// query = query.Where(x => x.StudentCount > 0);
//}
//查询条件
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
{
string conditionValue = string.Empty;
Regex rg = new Regex(@"^[0-9]*$");
if (rg.IsMatch(configuretView.ConditionValue))
conditionValue = Convert.ToInt32(configuretView.ConditionValue).ToString();
else
conditionValue = configuretView.ConditionValue;
query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, conditionValue);
}
return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.GrademajorStr).ThenByDescending(x => x.ChargeYear)
.ThenBy(x => x.ChargeProjectStr).ToList();
}
///
/// 查询收费标准新增年级专业列表
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
public IGridResultSet GetGradeMajorViewGrid(ConfiguretView configuretView, Guid? gradeMajorID,
Guid? collegeID, int? yearID, int? standardID, int? educationID, int? learningformID,
string learnSystem, int? inSchoolStatus, int? chargeYearID, Guid? chargeProjectID, int pageIndex, int pageSize)
{
Expression> expChargeStandard = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
if (chargeYearID!=null && chargeYearID.HasValue)
{
//缴费学年
expChargeStandard = expChargeStandard.And(x => x.ChargeYear == chargeYearID);
}
if (chargeProjectID != null && chargeProjectID.HasValue)
{
//收费项目
expChargeStandard = expChargeStandard.And(x => x.ChargeProjectID == chargeProjectID);
}
Expression> expStudent = (x => true);
if (inSchoolStatus != null && inSchoolStatus > -1)
{
var inschoolStatusList = InSchoolSettingServices.GetInschoolStatusList(true);
if (inSchoolStatus == 1)
{
//表示在校
expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
}
if (inSchoolStatus == 0)
{
//不在校
expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
}
}
var query = ChargeStandardDAL.GetGradeMajorViewQueryAble(expChargeStandard, expStudent);
if (collegeID.HasValue)
{
query = query.Where(x => x.CollegeID == collegeID);
}
if (yearID.HasValue)
{
query = query.Where(x => x.GradeID == yearID);
}
if (standardID.HasValue)
{
query = query.Where(x => x.StandardID == standardID);
}
if (educationID.HasValue)
{
query = query.Where(x => x.EducationID == educationID);
}
if (learningformID.HasValue)
{
query = query.Where(x => x.LearningformID == learningformID);
}
if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
{
var LearnSystems = Convert.ToDecimal(learnSystem);
query = query.Where(x => x.LearnSystem == LearnSystems);
}
//去掉学生人数为0的数据(去除人数为0的年级专业,但选全部时可不去除)
if (inSchoolStatus != null && inSchoolStatus > -1)
{
query = query.Where(x => x.StudentCount > 0);
}
//查询条件()
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
{
query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
}
return this.GetQueryByDataRangeByCollege(query).OrderByDescending(x => x.GradeID)
.OrderBy(x=>x.StandardID).OrderBy(x=>x.EducationID).OrderBy(x=>x.LearningformID)
.OrderBy(x=>x.LearnSystem).OrderBy(x=>x.Name)
.ToGridResultSet(pageIndex, pageSize);
}
///
/// 刷新名单(生成对应的收费标准应收名单,注:目前只对不在应收名单中的学生进行插入操作)
///
///
///
///
public string CreatStudentChargeList(List chargeStandardIDs, int? inschoolStatus)
{
try
{
//查询收费标准信息
var chargeStandardList = ChargeStandardDAL.ChargeStandardRepository
.GetList(x => chargeStandardIDs.Contains(x.ChargeStandardID)).ToList();
//获取年级专业列表
var gradeMajorIDList = chargeStandardList.Where(x => !string.IsNullOrEmpty(x.GrademajorID.ToString()))
.Select(x => x.GrademajorID).ToList();
//获取缴费学年列表
var chargeYearIDList = chargeStandardList.Where(x => !string.IsNullOrEmpty(x.ChargeYear.ToString()))
.Select(x => x.ChargeYear).ToList();
//获取收费项目列表
var chargeProjectIDList = chargeStandardList.Where(x => !string.IsNullOrEmpty(x.ChargeProjectID.ToString()))
.Select(x => x.ChargeProjectID).ToList();
//应收名单
Expression> expStudentCharge = (x => true);
if (chargeYearIDList != null && chargeYearIDList.Count() > 0)
{
expStudentCharge = expStudentCharge.And(x => chargeYearIDList.Contains(x.ChargeYear));
}
if (chargeProjectIDList != null && chargeProjectIDList.Count() > 0)
{
expStudentCharge = expStudentCharge.And(x => chargeProjectIDList.Contains(x.ChargeProjectID));
}
//查询当前应收名单信息(根据应收名单、年级专业查询)
var studentChargeViewList = ChargeStandardDAL.GetGradeMajorStudentChargeViewQueryAble(expStudentCharge,
x => gradeMajorIDList.Contains(x.GrademajorID)).ToList();
//在校状态
Expression> expStudent = (x => true);
if (inschoolStatus != null && inschoolStatus > -1)
{
var inschoolStatusList = InSchoolSettingServices.GetInschoolStatusList(true);
if (inschoolStatus == 1)
{
//表示在校
expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
}
if (inschoolStatus == 0)
{
//不在校
expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
}
}
//查询各年级专业对应的学生信息List(含在校状态)
var gradeMajorStudentList = ChargeStandardDAL.GetGradeMajorStudentViewQueryAble(x => gradeMajorIDList.Contains(x.GrademajorID),
expStudent).ToList();
int success = 0; //成功
int fail = 0; //失败
string tipMessage = null; //提示消息
//注:只对不在应收名单中的学生进行插入操作
List studentChargeInList = new List();
foreach (var chargeStandard in chargeStandardList)
{
//收费标准信息验证
var chargeStandardVerify = chargeStandardList.Where(x => x.ChargeStandardID == chargeStandard.ChargeStandardID)
.SingleOrDefault();
if (chargeStandardVerify != null)
{
//查询对应的应收名单List
var studentChargeList = studentChargeViewList.Where(x => x.ChargeYear == chargeStandardVerify.ChargeYear
&& x.ChargeProjectID == chargeStandardVerify.ChargeProjectID
&& x.GradeMajorID == chargeStandardVerify.GrademajorID).ToList();
//查询年级专业对应的学生信息List(含在校状态)
var studentIDList = gradeMajorStudentList.Where(x => x.GradeMajorID == chargeStandardVerify.GrademajorID)
.Select(x => x.UserID).ToList();
if (studentIDList != null && studentIDList.Count() > 0)
{
foreach (var studentID in studentIDList)
{
//对应的应收名单信息
var studentChargeVerify = studentChargeList.Where(x => x.UserID == studentID)
.SingleOrDefault();
if (studentChargeVerify == null)
{
//表示不存在对应的应收名单
EC_StudentCharge studentCharge = new EC_StudentCharge();
studentCharge.StudentChargeID = Guid.NewGuid();
studentCharge.UserID = studentID;
studentCharge.ChargeProjectID = chargeStandardVerify.ChargeProjectID;
studentCharge.ChargeYear = chargeStandardVerify.ChargeYear;
studentCharge.Amount = chargeStandardVerify.Amount;
studentCharge.ActualAmount = studentCharge.Amount; //减免后金额
studentCharge.ChargeTag = (int)EC_ChargeTag.Normal; //默认为正常收费
SetNewStatus(studentCharge, (int)SYS_STATUS.USABLE);
studentChargeInList.Add(studentCharge);
}
else
{
//表示已存在对应的应收名单(可做更新)
}
}
}
else
{
//表示学生信息为空
}
success++;
}
else
{
//数据有误,刷新失败
fail++;
}
}
if (studentChargeInList != null && studentChargeInList.Count() > 0)
{
//批量插入
UnitOfWork.BulkInsert(studentChargeInList);
}
if (success > 0 && fail <= 0)
{
tipMessage = success + "条";
}
else
{
tipMessage = success + "条," + fail + "条失败,原因:选择刷新的数据有误,请检查";
}
return tipMessage;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// 收费标准新增(批量新增,同时生成应收名单)
///
///
///
///
public string ChargeStandardAdd(List gradeMajorIDs, ChargeStandardView chargeStandardView)
{
try
{
//收费标准信息List
var chargeStandardList = ChargeStandardDAL.ChargeStandardRepository
.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).ToList();
//在校状态
Expression> expStudent = (x => true);
if (chargeStandardView.InSchoolStatus != null && chargeStandardView.InSchoolStatus > -1)
{
var inschoolStatusList = InSchoolSettingServices.GetInschoolStatusList(true);
if (chargeStandardView.InSchoolStatus == 1)
{
//表示在校
expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
}
if (chargeStandardView.InSchoolStatus == 0)
{
//不在校
expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
}
}
//各年级专业对应的学生信息List(含在校状态)
var gradeMajorStudentList = ChargeStandardDAL.GetGradeMajorStudentViewQueryAble(x => gradeMajorIDs.Contains(x.GrademajorID),
expStudent).ToList();
//应收名单
Expression> expStudentCharge = (x => true);
if (chargeStandardView.ChargeYear != null && chargeStandardView.ChargeYear.HasValue)
{
//缴费学年
expStudentCharge = expStudentCharge.And(x => x.ChargeYear == chargeStandardView.ChargeYear);
}
if (chargeStandardView.ChargeProjectID != null && chargeStandardView.ChargeProjectID.HasValue)
{
//收费项目
expStudentCharge = expStudentCharge.And(x => x.ChargeProjectID == chargeStandardView.ChargeProjectID);
}
//查询应收名单信息
var studentChargeViewList = ChargeStandardDAL.GetGradeMajorStudentChargeViewQueryAble(expStudentCharge,
x => gradeMajorIDs.Contains(x.GrademajorID)).ToList();
int success = 0; //成功
int fail = 0; //失败
string tipMessage = null; //提示消息
List chargeStandardInList = new List();
List studentChargeInList = new List();
//注:收费标准业务主键(年级专业ID、学年、收费项目ID)
foreach (var gradeMajorID in gradeMajorIDs)
{
var chargeStandardVerify = chargeStandardList.Where(x => x.GrademajorID == gradeMajorID
&& x.ChargeYear == chargeStandardView.ChargeYear
&& x.ChargeProjectID == chargeStandardView.ChargeProjectID)
.SingleOrDefault();
if (chargeStandardVerify == null)
{
//表示收费标准不存在
EC_ChargeStandard chargeStandard = new EC_ChargeStandard();
chargeStandard.ChargeStandardID = Guid.NewGuid();
chargeStandard.GrademajorID = gradeMajorID;
chargeStandard.ChargeProjectID = chargeStandardView.ChargeProjectID;
chargeStandard.ChargeYear = chargeStandardView.ChargeYear;
chargeStandard.Amount = chargeStandardView.Amount;
SetNewStatus(chargeStandard, (int)SYS_STATUS.USABLE);
chargeStandardInList.Add(chargeStandard);
//查询年级专业对应的学生信息ID(含在校状态)
var studentIDList = gradeMajorStudentList.Where(x => x.GradeMajorID == gradeMajorID)
.Select(x => x.UserID).ToList();
if (studentIDList != null && studentIDList.Count() > 0)
{
foreach (var studentID in studentIDList)
{
//对应的应收名单信息
var studentChargeVerify = studentChargeViewList.Where(x => x.UserID == studentID)
.SingleOrDefault();
if (studentChargeVerify == null)
{
//表示不存在对应的应收名单
EC_StudentCharge studentCharge = new EC_StudentCharge();
studentCharge.StudentChargeID = Guid.NewGuid();
studentCharge.UserID = studentID;
studentCharge.ChargeProjectID = chargeStandardView.ChargeProjectID;
studentCharge.ChargeYear = chargeStandardView.ChargeYear;
studentCharge.Amount = chargeStandardView.Amount;
studentCharge.ActualAmount = studentCharge.Amount; //减免后金额
studentCharge.ChargeTag = (int)EC_ChargeTag.Normal; //默认为正常收费
SetNewStatus(studentCharge, (int)SYS_STATUS.USABLE);
studentChargeInList.Add(studentCharge);
}
else
{
//表示已存在对应的应收名单(可做更新)
}
}
}
else
{
//表示学生信息为空
}
success++;
}
else
{
//表示已存在相同的收费标准
fail++;
}
}
//批量插入
UnitOfWork.BulkInsert(chargeStandardInList);
UnitOfWork.BulkInsert(studentChargeInList);
if (success > 0 && fail <= 0)
{
tipMessage = success + "条";
}
else
{
tipMessage = success + "条," + fail + "条失败,原因:已存在相同的收费标准,请检查";
}
return tipMessage;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// 获取年级专业各在校状态学生
///
///
///
///
///
///
public IGridResultSet GetGradeMajorStudentViewGrid(Guid? grademajorID, int? inschoolStatus, int pageIndex, int pageSize)
{
//在校状态
Expression> expStudent = (x => true);
if (inschoolStatus != null && inschoolStatus > -1)
{
var inschoolStatusList = InSchoolSettingServices.GetInschoolStatusList(true);
if (inschoolStatus == 1)
{
//表示在校
expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
}
if (inschoolStatus == 0)
{
//不在校
expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
}
}
var query = ChargeStandardDAL.GetGradeMajorStudentViewQueryAble(x => x.GrademajorID == grademajorID, expStudent);
return this.GetQueryByDataRangeByCollege(query).OrderByDescending(x => x.ClassMajorCode.Length)
.OrderBy(x => x.ClassMajorCode).OrderBy(x => x.LoginID)
.ToGridResultSet(pageIndex, pageSize);
}
///
/// 获取年级专业各在校状态学生
///
///
///
///
public List GetGradeMajorStudentViewGrid(Guid? grademajorID, int? inschoolStatus)
{
//在校状态
Expression> expStudent = (x => true);
if (inschoolStatus != null && inschoolStatus > -1)
{
var inschoolStatusList = InSchoolSettingServices.GetInschoolStatusList(true);
if (inschoolStatus == 1)
{
//表示在校
expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
}
if (inschoolStatus == 0)
{
//不在校
expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
}
}
var query = ChargeStandardDAL.GetGradeMajorStudentViewQueryAble(x => x.GrademajorID == grademajorID, expStudent);
return this.GetQueryByDataRangeByCollege(query).OrderByDescending(x => x.ClassMajorCode.Length)
.OrderBy(x => x.ClassMajorCode).OrderBy(x => x.LoginID)
.ToList();
}
///
/// 获取收费标准对应的年级专业应收名单
///
///
///
///
///
///
///
///
public IGridResultSet GetGradeMajorStudentChargeViewGrid(Guid? grademajorID, int? chargeYearID, Guid? chargeProjectID, int? inschoolStatus, int pageIndex, int pageSize)
{
//应收名单
Expression> expStudentCharge = (x => true);
if (chargeYearID != null && chargeYearID.HasValue)
{
//缴费学年
expStudentCharge = expStudentCharge.And(x => x.ChargeYear == chargeYearID);
}
if (chargeProjectID != null && chargeProjectID.HasValue)
{
//收费项目
expStudentCharge = expStudentCharge.And(x => x.ChargeProjectID == chargeProjectID);
}
//在校状态
Expression> expStudent = (x => true);
if (inschoolStatus != null && inschoolStatus > -1)
{
var inschoolStatusList = InSchoolSettingServices.GetInschoolStatusList(true);
if (inschoolStatus == 1)
{
//表示在校
expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
}
if (inschoolStatus == 0)
{
//不在校
expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
}
}
//年级专业
Expression> expGrademajor = (x => true);
if (grademajorID != null && grademajorID.HasValue)
{
expGrademajor = expGrademajor.And(x => x.GrademajorID == grademajorID);
}
var query = ChargeStandardDAL.GetGradeMajorStudentChargeViewQueryAble(expStudentCharge, expGrademajor);
return this.GetQueryByDataRangeByCollege(query).OrderByDescending(x => x.ClassNo.Length)
.OrderBy(x => x.ClassNo).OrderBy(x => x.StudentNo)
.ToGridResultSet(pageIndex, pageSize);
}
///
/// 获取收费标准对应的年级专业应收名单
///
///
///
///
///
///
public List GetGradeMajorStudentChargeViewGrid(Guid? grademajorID, int? chargeYearID, Guid? chargeProjectID, int? inschoolStatus)
{
//应收名单
Expression> expStudentCharge = (x => true);
if (chargeYearID != null && chargeYearID.HasValue)
{
//缴费学年
expStudentCharge = expStudentCharge.And(x => x.ChargeYear == chargeYearID);
}
if (chargeProjectID != null && chargeProjectID.HasValue)
{
//收费项目
expStudentCharge = expStudentCharge.And(x => x.ChargeProjectID == chargeProjectID);
}
//在校状态
Expression> expStudent = (x => true);
if (inschoolStatus != null && inschoolStatus > -1)
{
var inschoolStatusList = InSchoolSettingServices.GetInschoolStatusList(true);
if (inschoolStatus == 1)
{
//表示在校
expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
}
if (inschoolStatus == 0)
{
//不在校
expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
}
}
//年级专业
Expression> expGrademajor = (x => true);
if (grademajorID != null && grademajorID.HasValue)
{
expGrademajor = expGrademajor.And(x => x.GrademajorID == grademajorID);
}
var query = ChargeStandardDAL.GetGradeMajorStudentChargeViewQueryAble(expStudentCharge, expGrademajor);
return this.GetQueryByDataRangeByCollege(query).OrderByDescending(x => x.ClassNo.Length)
.OrderBy(x => x.ClassNo).OrderBy(x => x.StudentNo)
.ToList();
}
///
/// 查询收费标准信息View(ChargeStandardView)
///
///
///
public ChargeStandardView GetChargeStandardView(Guid? chargeStandardID)
{
var query = ChargeStandardDAL.GetChargeStandarViewQueryAble(x => x.ChargeStandardID == chargeStandardID, x => true);
return query.FirstOrDefault();
}
///
/// 查询收费标准信息实体
///
///
///
public Entities.EC_ChargeStandard GetChargeStandard(Guid? chargeStandardID)
{
System.Linq.Expressions.Expression> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
expression = (x => x.ChargeStandardID == chargeStandardID);
return ChargeStandardDAL.ChargeStandardRepository.GetSingle(expression);
}
///
/// 查询应收名单实体
///
///
///
public EC_StudentCharge GetStudentCharge(Guid? studentChargeID)
{
System.Linq.Expressions.Expression> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
expression = (x => x.StudentChargeID == studentChargeID);
return ChargeStandardDAL.StudentChargeRepository.GetSingle(expression);
}
///
/// 新增、修改(处理方式:当存在对应的应收名单时,无法修改)
///
///
///
public void ChargeStandardEdit(ChargeStandardView chargeStandardView)
{
try
{
//查询数据库进行验证(需排除自己)
var chargeStandardVerification = ChargeStandardDAL.ChargeStandardRepository.GetList(x => x.ChargeStandardID != chargeStandardView.ChargeStandardID
&& x.GrademajorID == chargeStandardView.GrademajorID
&& x.ChargeYear == chargeStandardView.ChargeYear
&& x.ChargeProjectID == chargeStandardView.ChargeProjectID)
.SingleOrDefault();
if (chargeStandardVerification == null)
{
//数据有误验证
if (chargeStandardView.ChargeStandardID != Guid.Empty)
{
//表示修改
var chargeStandard = ChargeStandardDAL.ChargeStandardRepository
.GetList(x => x.ChargeStandardID == chargeStandardView.ChargeStandardID)
.SingleOrDefault();
if (chargeStandard == null)
{
throw new Exception("数据有误,请核查");
}
else
{
//应收名单
Expression> expStudentCharge = (x => true);
if (chargeStandard.ChargeYear != null && chargeStandard.ChargeYear.HasValue)
{
//缴费学年
expStudentCharge = expStudentCharge.And(x => x.ChargeYear == chargeStandard.ChargeYear);
}
if (chargeStandard.ChargeProjectID != null && chargeStandard.ChargeProjectID.HasValue)
{
//收费项目
expStudentCharge = expStudentCharge.And(x => x.ChargeProjectID == chargeStandard.ChargeProjectID);
}
//年级专业
Expression> expGrademajor = (x => true);
if (chargeStandard.GrademajorID != null && chargeStandard.GrademajorID.HasValue)
{
expGrademajor = expGrademajor.And(x => x.GrademajorID == chargeStandard.GrademajorID);
}
//查询应收名单信息(业务主键:年级专业ID、缴费学年、收费项目ID)
var studentChargeList = ChargeStandardDAL.GetGradeMajorStudentChargeViewQueryAble(expStudentCharge, expGrademajor).ToList();
if (studentChargeList != null && studentChargeList.Count() > 0)
{
//表示已存在应收名单
throw new Exception("已生成应收名单,如需修改请删除相关的应收名单信息");
}
else
{
//chargeStandard.GrademajorID = chargeStandardView.GrademajorID;
//chargeStandard.ChargeProjectID = chargeStandardView.ChargeProjectID;
//chargeStandard.ChargeYear = chargeStandardView.ChargeYear;
chargeStandard.Amount = chargeStandardView.Amount;
SetModifyStatus(chargeStandard);
}
}
}
else
{
//表示新增
EC_ChargeStandard chargeStandard = new EC_ChargeStandard();
chargeStandard.ChargeStandardID = Guid.NewGuid();
chargeStandard.GrademajorID = chargeStandardView.GrademajorID;
chargeStandard.ChargeProjectID = chargeStandardView.ChargeProjectID;
chargeStandard.ChargeYear = chargeStandardView.ChargeYear;
chargeStandard.Amount = chargeStandardView.Amount;
SetNewStatus(chargeStandard, (int)SYS_STATUS.USABLE);
UnitOfWork.Add(chargeStandard);
}
}
else
{
throw new Exception("已存在相同的收费标准,请核查");
}
//事务提交
UnitOfWork.Commit();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// 删除(当选择删除的信息中存在的应收名单时,无法删除)
///
///
///
public bool ChargeStandardDelete(List chargeStandardIDs)
{
try
{
//查询收费标准信息List
var chargeStandardList = ChargeStandardDAL.ChargeStandardRepository
.GetList(x => chargeStandardIDs.Contains(x.ChargeStandardID)).ToList();
//年级专业IDList
var gradeMajorIDList = chargeStandardList.Where(x => !string.IsNullOrEmpty(x.GrademajorID.ToString()))
.Select(x => x.GrademajorID).ToList();
//缴费学年IDList
var chargeYearIDList = chargeStandardList.Where(x => !string.IsNullOrEmpty(x.ChargeYear.ToString()))
.Select(x => x.ChargeYear).ToList();
//收费项目IDList
var chargeProjectIDList = chargeStandardList.Where(x => !string.IsNullOrEmpty(x.ChargeProjectID.ToString()))
.Select(x => x.ChargeProjectID).ToList();
//年级专业
Expression> expGrademajor = (x => true);
if (gradeMajorIDList != null && gradeMajorIDList.Count() > 0)
{
expGrademajor = expGrademajor.And(x => gradeMajorIDList.Contains(x.GrademajorID));
}
//应收名单
Expression> expStudentCharge = (x => true);
if (chargeYearIDList != null && chargeYearIDList.Count() > 0)
{
//缴费学年
expStudentCharge = expStudentCharge.And(x => chargeYearIDList.Contains(x.ChargeYear));
}
if (chargeProjectIDList != null && chargeProjectIDList.Count() > 0)
{
//收费项目
expStudentCharge = expStudentCharge.And(x => chargeProjectIDList.Contains(x.ChargeProjectID));
}
//查询应收名单信息(业务主键:年级专业ID、缴费学年、收费项目ID)
var studentChargeList = ChargeStandardDAL.GetGradeMajorStudentChargeViewQueryAble(expStudentCharge, expGrademajor).ToList();
//注:由于用户会选择多条信息进行删除
//目前的删除逻辑暂时不处理更进一步的删除操作(如:同时存在可删除、不可删除的信息)
if (studentChargeList != null && studentChargeList.Count() > 0)
{
//表示已存在应收名单
throw new Exception("选择删除的信息中存在相应的应收名单,如需删除,请删除相关的应收名单信息。");
}
else
{
UnitOfWork.Delete(x => chargeStandardIDs.Contains(x.ChargeStandardID));
}
return true;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// 收费标准验证(业务主键:年级专业ID、缴费学年、收费项目ID)
///
///
///
///
///
///
public string GetVerification(Guid? chargeStandardID, Guid? grademajorID, int? chargeYearID, Guid? chargeProjectID)
{
//查询数据库进行验证(需排除自己)
var chargeStandard = ChargeStandardDAL.ChargeStandardRepository.GetList(x => x.ChargeStandardID != chargeStandardID
&& x.GrademajorID == grademajorID
&& x.ChargeYear == chargeYearID
&& x.ChargeProjectID == chargeProjectID)
.SingleOrDefault();
if (chargeStandard == null)
{
//数据有误验证
if (chargeStandardID.HasValue && chargeStandardID != Guid.Empty)
{
chargeStandard = ChargeStandardDAL.ChargeStandardRepository.GetList(x => x.ChargeStandardID == chargeStandardID)
.SingleOrDefault();
if (chargeStandard == null)
{
return "数据有误,请核查";
}
else
{
return "成功";
}
}
else
{
return "成功";
}
}
else
{
return "已存在相同的收费标准";
}
}
}
}