ModuleFormService.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. using LeaRun.Application.Entity.AuthorizeManage;
  2. using LeaRun.Application.IService.AuthorizeManage;
  3. using LeaRun.Data;
  4. using LeaRun.Data.Repository;
  5. using LeaRun.Util;
  6. using LeaRun.Util.Extension;
  7. using LeaRun.Util.WebControl;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Data;
  11. using System.Data.Common;
  12. using System.Text;
  13. namespace LeaRun.Application.Service.AuthorizeManage
  14. {
  15. /// <summary>
  16. /// 版 本 6.1
  17. /// Copyright (c) 2013-2016 上海力软信息技术有限公司
  18. /// 创建人:陈彬彬
  19. /// 日 期:2016.04.14 09:16
  20. /// 描 述:系统表单
  21. /// </summary>
  22. public class ModuleFormService : RepositoryFactory, IModuleFormService
  23. {
  24. #region 获取数据
  25. /// <summary>
  26. /// 获取分页数据(管理页面调用)
  27. /// </summary>
  28. /// <param name="pagination"></param>
  29. /// <param name="queryJson"></param>
  30. /// <returns></returns>
  31. public DataTable GetPageList(Pagination pagination, string queryJson)
  32. {
  33. try
  34. {
  35. var strSql = new StringBuilder();
  36. strSql.Append(@"SELECT
  37. m.FormId,
  38. m.ModuleId,
  39. m1.FullName as ModuleName,
  40. m.EnCode,
  41. m.FullName,
  42. m.SortCode,
  43. m.DeleteMark,
  44. m.EnabledMark,
  45. m.Description,
  46. m.CreateDate,
  47. m.CreateUserId,
  48. m.CreateUserName,
  49. m.ModifyDate,
  50. m.ModifyUserId,
  51. m.ModifyUserName
  52. FROM
  53. Base_ModuleForm m
  54. LEFT JOIN Base_Module m1 ON m1.ModuleId = m.ModuleId
  55. WHERE m.DeleteMark = 0");
  56. var parameter = new List<DbParameter>();
  57. var queryParam = queryJson.ToJObject();
  58. if (!queryParam["Keyword"].IsEmpty())//关键字查询
  59. {
  60. string keyord = queryParam["Keyword"].ToString();
  61. strSql.Append(@" AND ( m1.FullName LIKE @keyword
  62. or m.FullName LIKE @keyword
  63. or m.CreateUserName LIKE @keyword
  64. )");
  65. parameter.Add(DbParameters.CreateDbParameter("@keyword", '%' + keyord + '%'));
  66. }
  67. return this.BaseRepository().FindTable(strSql.ToString(), parameter.ToArray(), pagination);
  68. }
  69. catch
  70. {
  71. throw;
  72. }
  73. }
  74. /// <summary>
  75. /// 获取一个实体类
  76. /// </summary>
  77. /// <param name="keyValue"></param>
  78. /// <returns></returns>
  79. public ModuleFormEntity GetEntity(string keyValue)
  80. {
  81. try
  82. {
  83. return this.BaseRepository().FindEntity<ModuleFormEntity>(keyValue);
  84. }
  85. catch
  86. {
  87. throw;
  88. }
  89. }
  90. /// <summary>
  91. /// 通过模块Id获取系统表单
  92. /// </summary>
  93. /// <param name="moduleId"></param>
  94. /// <returns></returns>
  95. public ModuleFormEntity GetEntityByModuleId(string moduleId)
  96. {
  97. try
  98. {
  99. var expression = LinqExtensions.True<ModuleFormEntity>();
  100. expression = expression.And(t => t.ModuleId.Equals(moduleId));
  101. return this.BaseRepository().FindEntity<ModuleFormEntity>(expression);
  102. }
  103. catch
  104. {
  105. throw;
  106. }
  107. }
  108. /// <summary>
  109. /// 判断模块是否已经有系统表单
  110. /// </summary>
  111. /// <param name="keyValue"></param>
  112. /// <param name="moduleId"></param>
  113. /// <returns></returns>
  114. public bool IsExistModuleId(string keyValue,string moduleId)
  115. {
  116. var expression = LinqExtensions.True<ModuleFormEntity>();
  117. if(string.IsNullOrEmpty(keyValue))
  118. {
  119. expression = expression.And(t => t.ModuleId.Equals(moduleId));
  120. }
  121. else
  122. {
  123. expression = expression.And(t => t.ModuleId.Equals(moduleId) && t.FormId != keyValue);
  124. }
  125. ModuleFormEntity entity = this.BaseRepository().FindEntity<ModuleFormEntity>(expression);
  126. return entity == null ? false : true;
  127. }
  128. #endregion
  129. #region 提交数据
  130. /// <summary>
  131. /// 保存一个实体
  132. /// </summary>
  133. /// <param name="keyValue"></param>
  134. /// <param name="entity"></param>
  135. /// <returns></returns>
  136. public int SaveEntity(string keyValue, ModuleFormEntity entity)
  137. {
  138. try
  139. {
  140. if (string.IsNullOrEmpty(keyValue))
  141. {
  142. entity.Create();
  143. return this.BaseRepository().Insert(entity);
  144. }
  145. else
  146. {
  147. entity.Modify(keyValue);
  148. return this.BaseRepository().Update(entity);
  149. }
  150. }
  151. catch
  152. {
  153. throw;
  154. }
  155. }
  156. /// <summary>
  157. /// 虚拟删除一个实体
  158. /// </summary>
  159. /// <param name="keyValue"></param>
  160. /// <returns></returns>
  161. public int VirtualDelete(string keyValue)
  162. {
  163. try
  164. {
  165. ModuleFormEntity entity = this.BaseRepository().FindEntity<ModuleFormEntity>(keyValue);
  166. if (entity != null)
  167. {
  168. entity.DeleteMark = 1;
  169. return this.BaseRepository().Update(entity);
  170. }
  171. else
  172. {
  173. throw (new Exception("没有该记录无法删除"));
  174. }
  175. }
  176. catch
  177. {
  178. throw;
  179. }
  180. }
  181. #endregion
  182. }
  183. }