using LeaRun.Application.Entity.AuthorizeManage; using LeaRun.Application.IService.AuthorizeManage; using LeaRun.Data.Repository; using LeaRun.Util.Extension; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace LeaRun.Application.Service.BaseManage { /// /// 版 本 6.1 /// Copyright (c) 2013-2016 上海力软信息技术有限公司 /// 创建人:佘赐雄 /// 日 期:2015.10.27 09:16 /// 描 述:系统功能 /// public class ModuleService : RepositoryFactory, IModuleService { #region 获取数据 /// /// 获取最大编号 /// /// public int GetSortCode() { int sortCode = this.BaseRepository().IQueryable().Max(t => t.SortCode).ToInt(); if (!string.IsNullOrEmpty(sortCode.ToString())) { return sortCode + 1; } return 100001; } /// /// 功能列表 /// /// public IEnumerable GetList() { StringBuilder strSql = new StringBuilder(); strSql.Append("SELECT * FROM bASE_Module Order By SortCode"); return this.BaseRepository().FindList(strSql.ToString()); } /// /// 功能实体 /// /// 主键值 /// public ModuleEntity GetEntity(string keyValue) { return this.BaseRepository().FindEntity(keyValue); } #endregion #region 验证数据 /// /// 功能编号不能重复 /// /// 编号 /// 主键 /// public bool ExistEnCode(string enCode, string keyValue) { var expression = LinqExtensions.True(); expression = expression.And(t => t.EnCode == enCode); if (!string.IsNullOrEmpty(keyValue)) { expression = expression.And(t => t.ModuleId != keyValue); } return this.BaseRepository().IQueryable(expression).Count() == 0 ? true : false; } /// /// 功能名称不能重复 /// /// 名称 /// 主键 /// public bool ExistFullName(string fullName, string keyValue) { var expression = LinqExtensions.True(); expression = expression.And(t => t.FullName == fullName); if (!string.IsNullOrEmpty(keyValue)) { expression = expression.And(t => t.ModuleId != keyValue); } return this.BaseRepository().IQueryable(expression).Count() == 0 ? true : false; } #endregion #region 提交数据 /// /// 删除功能 /// /// 主键 public void RemoveForm(string keyValue) { IRepository db = new RepositoryFactory().BaseRepository().BeginTrans(); try { int count = db.IQueryable(t => t.ParentId == keyValue).Count(); if (count > 0) { throw new Exception("当前所选数据有子节点数据!"); } db.Delete(keyValue); db.Delete(t => t.ModuleId.Equals(keyValue)); db.Delete(t => t.ModuleId.Equals(keyValue)); db.Commit(); } catch (Exception) { db.Rollback(); throw; } } /// /// 保存表单(新增、修改) /// /// 主键值 /// 功能实体 /// 按钮实体列表 /// 视图实体列表 /// public void SaveForm(string keyValue, ModuleEntity moduleEntity, List moduleButtonList, List moduleColumnList) { IRepository db = new RepositoryFactory().BaseRepository().BeginTrans(); try { if (!string.IsNullOrEmpty(keyValue)) { moduleEntity.Modify(keyValue); db.Update(moduleEntity); } else { moduleEntity.Create(); db.Insert(moduleEntity); } db.Delete(t => t.ModuleId.Equals(keyValue)); if (moduleButtonList != null) { db.Insert(moduleButtonList); } db.Delete(t => t.ModuleId.Equals(keyValue)); if (moduleColumnList != null) { db.Insert(moduleColumnList); } db.Commit(); } catch (Exception) { db.Rollback(); throw; } } #endregion } }