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.03.08 /// 描 述:数据源 /// public class DataSourceService : RepositoryFactory { #region 属性 构造函数 private string fieldSql; public DataSourceService() { fieldSql = @" t.F_Id, t.F_Code, t.F_Name, t.F_DbId, t.F_Description, t.F_CreateUserId, t.F_CreateUserName, t.F_CreateDate, t.F_ModifyUserId, t.F_ModifyUserName, t.F_ModifyDate "; } #endregion #region 获取数据 /// /// 获取分页数据 /// /// 分页参数 /// 关键字 /// public IEnumerable GetPageList(Pagination pagination, string keyword) { try { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append(fieldSql); strSql.Append(" FROM LR_Base_DataSource t "); strSql.Append(" WHERE 1=1 "); if (!string.IsNullOrEmpty(keyword)) { strSql.Append(" AND ( t.F_Name like @keyword OR t.F_Code like @keyword ) "); keyword = "%" + keyword + "%"; } return this.BaseRepository().FindList(strSql.ToString(), new { keyword = keyword }, pagination); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowServiceException(ex); } } } /// /// 获取列表数据 /// /// public IEnumerable GetList() { try { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append(fieldSql); strSql.Append(" FROM LR_Base_DataSource t "); return this.BaseRepository().FindList(strSql.ToString()); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowServiceException(ex); } } } /// /// 获取实体 /// /// 编码 /// public DataSourceEntity GetEntityByCode(string code) { try { return this.BaseRepository().FindEntity(t => t.F_Code.Equals(code)); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowServiceException(ex); } } } /// /// 获取实体 /// /// 主键 /// public DataSourceEntity GetEntity(string keyValue) { try { return this.BaseRepository().FindEntity(keyValue); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowServiceException(ex); } } } #endregion #region 提交数据 /// /// 删除数据源 /// /// 主键 public void DeleteEntity(string keyValue) { try { DataSourceEntity entity = new DataSourceEntity() { F_Id = keyValue, }; this.BaseRepository().Delete(entity); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowServiceException(ex); } } } /// /// 保存(新增、修改) /// /// 主键值 /// 数据源实体 /// public bool SaveEntity(string keyValue, DataSourceEntity dataSourceEntity) { try { if (!string.IsNullOrEmpty(keyValue)) { DataSourceEntity entity = this.BaseRepository().FindEntity(t => t.F_Code.Equals(dataSourceEntity.F_Code) && t.F_Id != keyValue); if (entity != null) { return false; } dataSourceEntity.Modify(keyValue); this.BaseRepository().Update(dataSourceEntity); } else { DataSourceEntity entity = GetEntityByCode(dataSourceEntity.F_Code); if (entity != null) { return false; } dataSourceEntity.Create(); this.BaseRepository().Insert(dataSourceEntity); } return true; } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowServiceException(ex); } } } #endregion } }