using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EMIS.CommonLogic.ChargeManage;
using EMIS.CommonLogic;
using Bowin.Common.Linq.Entity;
using EMIS.ViewModel.ChargeManage.ChargeSituation;
using EMIS.ViewModel;
using EMIS.Entities;
using System.Text.RegularExpressions;
using EMIS.DataLogic.ChargeManage.ChargeSituation;
using System.Linq.Expressions;
using Bowin.Common.Linq;
namespace EMIS.CommonLogic.ChargeManage.ChargeSituation
{
public class ChargeProjectServices : BaseServices, IChargeProjectServices
{
public ChargeProjectDAL ChargeProjectDAL { get; set; }
///
/// 查询收费项目信息View
///
///
///
///
///
public IGridResultSet GetChargeProjectViewGrid(ConfiguretView configuretView,
int pageIndex, int pageSize)
{
Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
var query = ChargeProjectDAL.GetChargeProjectViewQueryAble(exp);
//查询条件
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
{
query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
}
return query.OrderBy(x => x.ChrageProjectName)
.ToGridResultSet(pageIndex, pageSize);
}
///
/// 查询收费项目信息List
///
///
///
public List GetChargeProjectViewList(ConfiguretView configuretView)
{
Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
var query = ChargeProjectDAL.GetChargeProjectViewQueryAble(exp);
//查询条件
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 query.OrderBy(x => x.ChrageProjectName).ToList();
}
///
/// 查询收费项目实体
///
///
///
public EC_ChargeProject GetChargeProject(Guid? chargeProjectID)
{
try
{
Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
exp = exp.And(x => x.ChargeProjectID == chargeProjectID);
return ChargeProjectDAL.chargeProjectRepository.GetSingle(exp);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// 查询收费项目View
///
///
///
public ChargeProjectView GetChargeProjectView(Guid? chargeProjectID)
{
try
{
Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
exp = exp.And(x => x.ChargeProjectID == chargeProjectID);
var query = ChargeProjectDAL.GetChargeProjectViewQueryAble(exp);
return query.SingleOrDefault();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// 查询收费项目明细View
///
///
///
public ChargeProjectView GetChargeProjectDetailsView(Guid? chargeProjectID)
{
try
{
Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
exp = exp.And(x => x.ChargeProjectID == chargeProjectID);
var query = ChargeProjectDAL.GetChargeProjectViewQueryAble(exp);
return query.SingleOrDefault();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// 编辑(新增、修改)
///
///
public void ChargeProjectAdd(ChargeProjectView chargeProjectView)
{
try
{
//查询数据库进行验证(需排除自己)
var chargeProject = ChargeProjectDAL.chargeProjectRepository
.GetList(x => x.ChargeProjectID != chargeProjectView.ChargeProjectID
&& x.Name == chargeProjectView.ChrageProjectName).FirstOrDefault();
if (chargeProject == null)
{
//数据有误验证
if (chargeProjectView.ChargeProjectID != null && chargeProjectView.ChargeProjectID != Guid.Empty)
{
chargeProject = ChargeProjectDAL.chargeProjectRepository
.GetList(x => x.ChargeProjectID == chargeProjectView.ChargeProjectID).SingleOrDefault();
if (chargeProject == null)
{
throw new Exception("数据有误,请核查");
}
else
{
chargeProject.Name = chargeProjectView.ChrageProjectName;
chargeProject.Remark = chargeProjectView.Remark;
SetModifyStatus(chargeProject);
}
}
else
{
EC_ChargeProject newChargeProject = new EC_ChargeProject();
newChargeProject.ChargeProjectID = Guid.NewGuid();
newChargeProject.Name = chargeProjectView.ChrageProjectName;
newChargeProject.Remark = chargeProjectView.Remark;
SetNewStatus(newChargeProject);
UnitOfWork.Add(newChargeProject);
}
}
else
{
throw new Exception("已存在相同的收费项目");
}
UnitOfWork.Commit();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// 删除
///
///
///
public bool ChargeProjectDelete(List chargeProjectIDs)
{
try
{
UnitOfWork.Delete(x => chargeProjectIDs.Contains(x.ChargeProjectID));
UnitOfWork.Commit();
return true;
}
catch (Exception)
{
throw;
}
}
///
/// 验证
///
///
///
///
public string GetVerification(Guid? chargeProjectID, string chrageProjectName)
{
//查询数据库进行验证(需排除自己)
var chargeProject = ChargeProjectDAL.chargeProjectRepository.GetList(x => x.ChargeProjectID != chargeProjectID
&& x.Name == chrageProjectName).FirstOrDefault();
if (chargeProject == null)
{
//数据有误验证
if (chargeProjectID.HasValue && chargeProjectID != Guid.Empty)
{
chargeProject = ChargeProjectDAL.chargeProjectRepository
.GetList(x => x.ChargeProjectID == chargeProjectID).SingleOrDefault();
if (chargeProject == null)
{
return "数据有误,请核查";
}
else
{
return "成功";
}
}
else
{
return "成功";
}
}
else
{
return "已存在相同的收费项目";
}
}
}
}