using Learun.DataBase.Repository;
using Learun.Util;
using System;
using System.Collections.Generic;
using System.Text;
namespace Learun.Application.Base.SystemModule
{
///
/// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
/// Copyright (c) 2013-2018 北京泉江科技有限公司
/// 创建人:陈彬彬
/// 日 期:2017.04.01
/// 描 述:行政区域
///
public class AreaService : RepositoryFactory
{
#region 构造函数和属性
private string fieldSql;
public AreaService()
{
fieldSql = @"
t.F_AreaId,
t.F_ParentId,
t.F_AreaCode,
t.F_AreaName,
t.F_QuickQuery,
t.F_SimpleSpelling,
t.F_Layer,
t.F_SortCode,
t.F_DeleteMark,
t.F_EnabledMark,
t.F_Description,
t.F_CreateDate,
t.F_CreateUserId,
t.F_CreateUserName,
t.F_ModifyDate,
t.F_ModifyUserId,
t.F_ModifyUserName ";
}
#endregion
#region 获取数据
///
/// 区域列表
///
/// 父节点Id
///
public IEnumerable GetList(string parentId)
{
try
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(fieldSql);
strSql.Append(" FROM LR_Base_Area t WHERE t.F_EnabledMark = 1 AND t.F_DeleteMark = 0 ");
if (parentId == "2")
{
strSql.Append(" AND t.F_Layer=2 ");
}
else
if (!string.IsNullOrEmpty(parentId))
{
strSql.Append(" AND F_ParentId = @F_ParentId ");
}
strSql.Append(" ORDER BY t.F_AreaCode ");
return this.BaseRepository().FindList(strSql.ToString(), new { F_ParentId = parentId });
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 区域实体
///
/// 主键值
///
public AreaEntity GetEntity(string keyValue)
{
try
{
return this.BaseRepository().FindEntity(keyValue);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
public AreaEntity GetEntityByCode(string code)
{
try
{
return this.BaseRepository().FindEntity(x => x.F_AreaCode == code);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
#endregion
#region 提交数据
///
/// 虚拟删除区域
///
/// 主键
public void VirtualDelete(string keyValue)
{
try
{
AreaEntity entity = new AreaEntity()
{
F_AreaId = keyValue,
F_DeleteMark = 1
};
this.BaseRepository().Update(entity);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 保存区域表单(新增、修改)
///
/// 主键值
/// 区域实体
///
public void SaveEntity(string keyValue, AreaEntity areaEntity)
{
try
{
if (!string.IsNullOrEmpty(keyValue))
{
areaEntity.Modify(keyValue);
this.BaseRepository().Update(areaEntity);
}
else
{
areaEntity.Create();
this.BaseRepository().Insert(areaEntity);
}
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
#endregion
}
}