UrlConfigDal.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. using Cksoft.Data;
  2. using DllEapEntity;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. namespace DllEapDal
  8. {
  9. public class UrlConfigDal
  10. {
  11. private IDatabase CurrDb;
  12. public UrlConfigDal(IDatabase db)
  13. {
  14. CurrDb = db;
  15. }
  16. #region UrlConfig
  17. /// <summary>
  18. /// 获取列表
  19. /// </summary>
  20. /// <param name="start"></param>
  21. /// <param name="filter"></param>
  22. /// <param name="sort"></param>
  23. /// <param name="order"></param>
  24. /// <returns></returns>
  25. public IEnumerable<UrlConfig> GetUrlConfigList(int start, int length, string filter, string sort, string order, ref string errorinfo)
  26. {
  27. var list = CurrDb.FindListForCondition<UrlConfig>($" {filter} order by {sort} {order} limit {start - 1},{length}",
  28. ref errorinfo);
  29. return list;
  30. }
  31. /// <summary>
  32. /// 获取单个实体
  33. /// </summary>
  34. /// <param name="id"></param>
  35. /// <returns></returns>
  36. public UrlConfig GetUrlConfig(int id)
  37. {
  38. var model = CurrDb.FindEntityFor<UrlConfig>(id);
  39. return model;
  40. }
  41. /// <summary>
  42. /// 根据类别code查询url
  43. /// </summary>
  44. /// <param name="typeCode"></param>
  45. /// <returns></returns>
  46. public IEnumerable<UrlConfig> GetUrlConfigByType(string typeCode)
  47. {
  48. var urlConfig = CurrDb.FindList<UrlConfig>($"select * from UrlConfig where FType=0 and FCode='{typeCode}'").FirstOrDefault();
  49. if (urlConfig == null)
  50. {
  51. return null;
  52. }
  53. return CurrDb.FindList<UrlConfig>($"select * from UrlConfig where FType={urlConfig.ID}");
  54. }
  55. /// <summary>
  56. /// 更新
  57. /// </summary>
  58. /// <param name="t"></param>
  59. /// <returns></returns>
  60. public int UpdateUrlConfig(UrlConfig model, string usercode, ref string errorinfo)
  61. {
  62. try
  63. {
  64. var sql = $"select * from UrlConfig where fcode='{model.FCode}' and id<>'{model.ID}'";
  65. var temp = CurrDb.FindList<UrlConfig>(sql).FirstOrDefault();
  66. if (temp != null)
  67. {
  68. errorinfo = "代码已存在";
  69. return 0;
  70. }
  71. if (model.FType > 0)
  72. {
  73. sql = $"select * from UrlConfig where FType={model.FType} and Url='{model.Url}' and id<>'{model.ID}'";
  74. temp = CurrDb.FindList<UrlConfig>(sql).FirstOrDefault();
  75. if (temp != null)
  76. {
  77. errorinfo = "Url已存在";
  78. return 0;
  79. }
  80. }
  81. return CurrDb.UpdateFor<UrlConfig>(model, usercode);
  82. }
  83. catch (Exception e)
  84. {
  85. errorinfo = e.Message;
  86. return 0;
  87. }
  88. }
  89. /// <summary>
  90. /// 新增
  91. /// </summary>
  92. /// <param name="t"></param>
  93. /// <returns></returns>
  94. public int InsertUrlConfig(UrlConfig model, ref string errorinfo)
  95. {
  96. try
  97. {
  98. var sql = $"select * from UrlConfig where fcode='{model.FCode}'";
  99. var temp = CurrDb.FindList<UrlConfig>(sql).FirstOrDefault();
  100. if (temp != null)
  101. {
  102. errorinfo = "代码已存在";
  103. return 0;
  104. }
  105. if (model.FType > 0)
  106. {
  107. sql = $"select * from UrlConfig where FType={model.FType} and Url='{model.Url}'";
  108. temp = CurrDb.FindList<UrlConfig>(sql).FirstOrDefault();
  109. if (temp != null)
  110. {
  111. errorinfo = "Url已存在";
  112. return 0;
  113. }
  114. }
  115. return CurrDb.InsertFor(model, model.RecCode);
  116. }
  117. catch (Exception e)
  118. {
  119. errorinfo = e.Message;
  120. return 0;
  121. }
  122. }
  123. public int DeleteUrlConfig(int id, ref string errorinfo)
  124. {
  125. try
  126. {
  127. if (id <= 0)
  128. {
  129. errorinfo = "url不存在";
  130. return 0;
  131. }
  132. return CurrDb.DeleteFor<UrlConfig>(id);
  133. }
  134. catch (Exception e)
  135. {
  136. errorinfo = e.Message;
  137. return 0;
  138. }
  139. }
  140. /// <summary>
  141. /// 获取总的记录数
  142. /// </summary>
  143. /// <param name="filter"></param>
  144. /// <returns></returns>
  145. public int GetUrlConfigCount(string filter)
  146. {
  147. string sql = string.Format($"SELECT COUNT(1) FROM urlconfig a WHERE 1=1 {filter}");
  148. return Convert.ToInt32(CurrDb.FindList<string>(sql).FirstOrDefault() ?? "0");
  149. }
  150. #endregion
  151. }
  152. }