using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using System.Transactions;
using Bowin.Common.Linq;
using Bowin.Common.Linq.Entity;
using EMIS.Entities;
using EMIS.ViewModel;
using EMIS.ViewModel.StudentManage.StudentChange;
using EMIS.DataLogic.StudentManage.StudentChange;
namespace EMIS.CommonLogic.StudentManage.StudentChange
{
public class ChangeReportServices : BaseServices, IChangeReportServices
{
public ChangeReportDAL ChangeReportDAL { get; set; }
///
/// 查询对应的异动报表信息ChangeReportView
///
///
///
///
///
public IGridResultSet GetChangeReportViewGrid(ConfiguretView configuretView, int pageIndex, int pageSize)
{
Expression> exp = (x => true);
var query = ChangeReportDAL.GetChangeReportViewQueryable(exp);
//查询条件
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
{
query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
}
return query.OrderBy(x => x.Code).ToGridResultSet(pageIndex, pageSize);
}
///
/// 查询对应的异动报表信息List
///
///
///
public IList GetChangeReportViewList(ConfiguretView configuretView)
{
Expression> exp = (x => true);
var query = ChangeReportDAL.GetChangeReportViewQueryable(exp);
//查询条件
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
{
query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
}
return query.OrderBy(x => x.Code).ToList();
}
///
/// 查询对应的异动报表信息ChangeReportView(根据异动报表ID)
///
///
///
public ChangeReportView GetChangeReportView(Guid? changeReportID)
{
try
{
var changeReportView = ChangeReportDAL.GetChangeReportViewQueryable(x => x.ChangeReportID == changeReportID).SingleOrDefault();
return changeReportView;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// 编辑(新增、修改)
///
///
public void ChangeReportEdit(ChangeReportView changeReportView)
{
try
{
var changeReportVerify = ChangeReportDAL.ChangeReportRepository.GetList(x => x.ChangeReportID != changeReportView.ChangeReportID
&& (x.Code == changeReportView.Code || x.Name == changeReportView.Name)).FirstOrDefault();
if (changeReportVerify == null)
{
if (changeReportView.ChangeReportID != Guid.Empty)
{
var changeReport = ChangeReportDAL.ChangeReportRepository.GetList(x => x.ChangeReportID == changeReportView.ChangeReportID).SingleOrDefault();
if (changeReport == null)
{
throw new Exception("数据有误,请核查。");
}
else
{
changeReport.Code = changeReportView.Code;
changeReport.Name = changeReportView.Name;
changeReport.Url = changeReportView.Url;
}
}
else
{
var newChangeReport = new CF_DifferentDynamicReport();
newChangeReport.ChangeReportID = Guid.NewGuid();
newChangeReport.Code = changeReportView.Code;
newChangeReport.Name = changeReportView.Name;
newChangeReport.Url = changeReportView.Url;
UnitOfWork.Add(newChangeReport);
}
}
else
{
throw new Exception("已存在相同的异动报表(报表代码或报表名称唯一),请核查。");
}
UnitOfWork.Commit();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// 删除
///
///
///
public bool ChangeReportDelete(List changeReportIDs)
{
try
{
UnitOfWork.Delete(x => changeReportIDs.Contains(x.ChangeReportID));
return true;
}
catch (Exception)
{
throw;
}
}
}
}