using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EMIS.DataLogic.ScoreManage;
using Bowin.Common.Linq.Entity;
using EMIS.Entities;
using EMIS.ViewModel;
using EMIS.ViewModel.ScoreManage;
using EMIS.DataLogic.Repositories;
namespace EMIS.CommonLogic.ScoreManage
{
public class ScoreFormulaServices : BaseServices, IScoreFormulaServices
{
public CustomScoreFormulaRepository CustomScoreFormulaRepository { get; set; }
public ScoreFormulaDAL scoreFormulaDAL { get; set; }
///
/// 查询成绩公式设置列表
///
///
///
///
///
public Bowin.Common.Linq.Entity.IGridResultSet GetScoreFormulaGrid(string name, int pageIndex, int pageSize)
{
var query = scoreFormulaDAL.scoreFormulaRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
if (!string.IsNullOrEmpty(name))
query = query.Where(x => name.Contains(x.Name));
return query.OrderByDescending(x => x.CreateTime).ToGridResultSet(pageIndex, pageSize);
}
///
/// 查询成绩公式设置列表
///
///
///
///
///
public List GetScoreFormulaList(string name)
{
var query = scoreFormulaDAL.scoreFormulaRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE, (x => x.ER_ScoreFormulaDetail));
if (!string.IsNullOrEmpty(name))
query = query.Where(x => name.Contains(x.Name));
return query.OrderByDescending(x => x.CreateTime).ToList();
}
//
/// 查询成绩公式设置列表
///
///
///
///
///
public List GetScoreFormulaDropdownViewList(string name)
{
var query = scoreFormulaDAL.scoreFormulaRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE, (x => x.ER_ScoreFormulaDetail));
if (!string.IsNullOrEmpty(name))
query = query.Where(x => name.Contains(x.Name));
var list = query.OrderByDescending(x => x.CreateTime).ToList();
var result = new List();
list.ForEach(x => result.Add(new ScoreFormulaDropdownView
{
ScoreFormulaID = x.ScoreFormulaID,
Name = x.Name,
ScoreFormulaDetail = x.ER_ScoreFormulaDetail.Select(w => new ScoreFormulaDropdownDetailView
{
ScoreFormulaDetailID = w.ScoreFormulaDetailID,
ScoreFormulaID = w.ScoreFormulaID,
ScoreType = w.ScoreType,
Percentage = w.Percentage,
IsRequirePass = w.IsRequirePass,
PassScore=w.PassScore
}).ToList()
}));
return result;
}
///
/// 添加
///
///
public void ScoreFormulaAdd(ScoreFormulaView scoreFormulaView, List scoreFormulaDetailList)
{
try
{
ER_ScoreFormula scoreFormula = null;
if (scoreFormulaView.ScoreFormulaID == null || scoreFormulaView.ScoreFormulaID == Guid.Empty)
{
scoreFormula = new ER_ScoreFormula();
scoreFormula.ScoreFormulaID = Guid.NewGuid();
scoreFormula.Name = scoreFormulaView.Name;
SetNewStatus(scoreFormula);
UnitOfWork.Add(scoreFormula);
scoreFormula.ER_ScoreFormulaDetail = new HashSet();
foreach (var scoreDetail in scoreFormulaDetailList)
{
if (scoreDetail.IsRequirePass == true && scoreDetail.PassScore == null)
{
throw new Exception("勾选必须通过的项没有设置必须通过成绩!");
}
ER_ScoreFormulaDetail scoreFormulaDetail = new ER_ScoreFormulaDetail();
scoreFormulaDetail.ScoreFormulaDetailID = Guid.NewGuid();
scoreFormulaDetail.ScoreFormulaID = scoreFormula.ScoreFormulaID;
scoreFormulaDetail.ScoreType = scoreDetail.ScoreType;
scoreFormulaDetail.Percentage = scoreDetail.Percentage;
scoreFormulaDetail.IsRequirePass = scoreDetail.IsRequirePass;
if (scoreDetail.PassScoreStr != "" && scoreDetail.PassScoreStr != null)
{
scoreFormulaDetail.PassScore = Convert.ToDecimal(scoreDetail.PassScoreStr);
}
else {
scoreFormulaDetail.PassScore = null;
}
SetNewStatus(scoreFormulaDetail);
UnitOfWork.Add(scoreFormulaDetail);
}
}
else
{
scoreFormula = GetScoreFormula(scoreFormulaView.ScoreFormulaID);
if(scoreFormula == null)
throw new Exception("未找到相对应的成绩公式设置!");
scoreFormula.Name = scoreFormulaView.Name;
SetModifyStatus(scoreFormula);
scoreFormula.ER_ScoreFormulaDetail = new HashSet();
foreach (var scoreDetail in scoreFormulaDetailList)
{
if (scoreDetail.IsRequirePass == true && scoreDetail.PassScore == null)
{
throw new Exception("勾选必须通过的项没有设置必须通过成绩!");
}
ER_ScoreFormulaDetail scoreFormulaDetail = new ER_ScoreFormulaDetail();
scoreFormulaDetail.ScoreFormulaDetailID = Guid.NewGuid();
scoreFormulaDetail.ScoreFormulaID = scoreFormula.ScoreFormulaID;
scoreFormulaDetail.ScoreType = scoreDetail.ScoreType;
scoreFormulaDetail.Percentage = scoreDetail.Percentage;
scoreFormulaDetail.IsRequirePass = scoreDetail.IsRequirePass;
if (scoreDetail.PassScoreStr != "" && scoreDetail.PassScoreStr != null)
{
scoreFormulaDetail.PassScore = Convert.ToDecimal(scoreDetail.PassScoreStr);
}
else
{
scoreFormulaDetail.PassScore = null;
}
SetNewStatus(scoreFormulaDetail);
UnitOfWork.Add(scoreFormulaDetail);
}
}
UnitOfWork.Commit();
}
catch (Exception)
{
throw;
}
}
///
/// 删除
///
///
public void ScoreFormulaDelete(List scoreFormulaIDs)
{
try
{
if (scoreFormulaIDs.Count > 0)
{
UnitOfWork.Delete(x => scoreFormulaIDs.Contains(x.ScoreFormulaID));
}
}
catch (Exception)
{
throw;
}
}
///
/// 根据ID获取成绩公式设置
///
///
///
public ER_ScoreFormula GetScoreFormula(Guid? scoreFormulaID)
{
return scoreFormulaDAL.scoreFormulaRepository.GetSingle(x => x.ScoreFormulaID == scoreFormulaID, (x => x.ER_ScoreFormulaDetail));
}
///
/// 根据成绩公式设置ID查询明细
///
///
///
public List GetScoreFormulaDetailList(Guid? scoreFormulaID)
{
if (scoreFormulaID == null)
{
return new List();
}
return scoreFormulaDAL.scoreFormulaDetailRepository
.GetList(x => x.ScoreFormulaID == scoreFormulaID).OrderBy(x => x.ScoreType).ToList();
}
///
/// 根据成绩公式设置ID查询明细
///
///
///
public List GetScoreFormulaDetailListByScoreFormulaID(Guid? scoreFormulaID)
{
if (scoreFormulaID == null)
{
return new List();
}
return scoreFormulaDAL.GetScoreFormulaDetailViewQueryableByID(scoreFormulaID.Value).ToList();
}
public List GetCustomerScoreFormula()
{
return this.CustomScoreFormulaRepository.Entities.ToList();
}
}
}