AreaAndDeviceService.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. using LeaRun.Data;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using LeaRun.Application.Entity.JiangSuWaterResource;
  8. using System.Data;
  9. using LeaRun.Util;
  10. using LeaRun.Util.WebControl;
  11. namespace LeaRun.Application.Service.JiangSuWaterResourceManage
  12. {
  13. /// <summary>
  14. /// 区域 测点管理
  15. /// </summary>
  16. public class AreaAndDeviceService
  17. {
  18. SqlHelper sqlHelper = new SqlHelper("JSSYDB");
  19. #region 获取区域列表
  20. public IEnumerable<Area> GetAreaList()
  21. {
  22. try
  23. {
  24. string selSql = "SELECT * FROM VIEW_区域信息";
  25. DataTable dtResult = sqlHelper.ExecuteDataTable(selSql, CommandType.Text, null);
  26. return DataHelper.DataTableToT<Area>(dtResult);
  27. }
  28. catch (Exception ex)
  29. {
  30. return null;
  31. }
  32. }
  33. #endregion
  34. #region 获取测点列表
  35. public DataTable GetMeterList()
  36. {
  37. try
  38. {
  39. string selSql = "SELECT* FROM dbo.设备信息 sb LEFT JOIN dbo.VIEW_区域信息 qy ON sb.管理ID = qy.id";
  40. DataTable dtResult = sqlHelper.ExecuteDataTable(selSql, CommandType.Text, null);
  41. return dtResult;
  42. }
  43. catch (Exception ex)
  44. {
  45. return null;
  46. }
  47. }
  48. /// <summary>
  49. /// 区域 分页
  50. /// </summary>
  51. /// <param name="pagination">分页参数</param>
  52. /// <param name="keyWord">查询关键字</param>
  53. /// <returns></returns>
  54. public IEnumerable<Area> GetAreaListByPage(Pagination pagination, string keyWord)
  55. {
  56. try
  57. {
  58. string selSql = "SELECT * FROM VIEW_区域信息 ";
  59. if (!string.IsNullOrEmpty(keyWord))
  60. {
  61. selSql = selSql + " WHERE 名称 like '%" + keyWord + "%'";
  62. }
  63. int total = pagination.records;
  64. DataTable dtResult = sqlHelper.ExecuteDataTable(selSql, "ID", true, pagination.rows, pagination.page, out total, null);
  65. pagination.records = total;
  66. return DataHelper.DataTableToT<Area>(dtResult);
  67. }
  68. catch (Exception ex)
  69. {
  70. return null;
  71. }
  72. }
  73. #endregion
  74. #region 区域操作
  75. /// <summary>
  76. /// 区域增加
  77. /// </summary>
  78. /// <param name="area">区域实体</param>
  79. /// <param name="lgt">经度</param>
  80. /// <param name="lat">维度</param>
  81. /// <returns></returns>
  82. public bool SaveArea(Area area, string lgt, string lat)
  83. {
  84. try
  85. {
  86. //StringBuilder saveSql = new StringBuilder();
  87. string insertSql = DataHelper.ModelToInsertSql<Area>(area, "管理信息");
  88. string insertId = sqlHelper.ExecuteScalar(insertSql + " SELECT @@IDENTITY", CommandType.Text, null).ToString();
  89. //如果 经纬度不为空 则数据插入管理信息辅助表
  90. if (string.IsNullOrEmpty(lgt) && string.IsNullOrEmpty(lat))
  91. {
  92. string insertLnt = "INSERT INTO 管理辅助信息(管理ID,名称,值) VALUES(" + insertId + ",'经度','" + lgt + "')";
  93. sqlHelper.ExecuteNoParams(insertSql, CommandType.Text);
  94. insertLnt = "INSERT INTO 管理辅助信息(管理ID,名称,值) VALUES(" + insertId + ",'纬度','" + lat + "')";
  95. sqlHelper.ExecuteNoParams(insertSql, CommandType.Text);
  96. }
  97. return true;
  98. }
  99. catch (Exception ex)
  100. {
  101. return false;
  102. }
  103. }
  104. #endregion
  105. /// <summary>
  106. /// 测点列表
  107. /// </summary>
  108. /// <param name="pagination">分页参数</param>
  109. /// <param name="managerId">管理ID</param>
  110. /// <param name="meterName">测点名称</param>
  111. /// <param name="yingshou">营收账号</param>
  112. /// <returns></returns>
  113. public DataTable GetGridMeterList(Pagination pagination, string managerId, string meterName, string yingshou)
  114. {
  115. try
  116. {
  117. string searchSql = "SELECT * FROM VIEW_设备详细信息 WHERE 协议类型='用户站'";
  118. if (!string.IsNullOrEmpty(managerId))
  119. {
  120. searchSql = searchSql + " AND 管理ID = " + managerId;
  121. }
  122. if (!string.IsNullOrEmpty(meterName))
  123. {
  124. searchSql = searchSql + " AND 名称 LIKE '%" + managerId + "%' ";
  125. }
  126. if (!string.IsNullOrEmpty(yingshou))
  127. {
  128. searchSql = searchSql + " AND 营收账号 LIKE '%" + yingshou + "%' ";
  129. }
  130. int total = pagination.records;
  131. DataTable dtResult = sqlHelper.ExecuteDataTable(searchSql, "ID", true, pagination.rows, pagination.page, out total, null);
  132. pagination.records = total;
  133. return dtResult;
  134. }
  135. catch (Exception ex)
  136. {
  137. throw ex;
  138. }
  139. }
  140. /// <summary>
  141. /// 测点列表-全部
  142. /// </summary>
  143. /// <param name="managerId">管理ID</param>
  144. /// <param name="meterName">测点名称</param>
  145. /// <param name="yingshou">营收账号</param>
  146. /// <returns></returns>
  147. public DataTable GetGridMeterList(string managerId, string meterName, string yingshou)
  148. {
  149. try
  150. {
  151. string searchSql = "SELECT * FROM VIEW_设备详细信息 WHERE 协议类型='用户站'";
  152. if (!string.IsNullOrEmpty(managerId))
  153. {
  154. searchSql = searchSql + " AND 管理ID = " + managerId;
  155. }
  156. if (!string.IsNullOrEmpty(meterName))
  157. {
  158. searchSql = searchSql + " AND 名称 LIKE '%" + managerId + "%' ";
  159. }
  160. if (!string.IsNullOrEmpty(yingshou))
  161. {
  162. searchSql = searchSql + " AND 营收账号 LIKE '%" + yingshou + "%' ";
  163. }
  164. DataTable dtResult = sqlHelper.ExecuteDataTable(searchSql, CommandType.Text, null);
  165. return dtResult;
  166. }
  167. catch (Exception ex)
  168. {
  169. throw ex;
  170. }
  171. }
  172. /// <summary>
  173. /// type 0 (用户站 终端类型) 1 (通讯设备 设备协议) 2(传输设备 传输协议) 其他 全部查询
  174. /// </summary>
  175. /// <param name="types"></param>
  176. /// <returns></returns>
  177. public DataTable GetTerminalTypes(string types)
  178. {
  179. try
  180. {
  181. string selSql = "SELECT * FROM dbo.模板信息 ";
  182. switch (types)
  183. {
  184. case "0":
  185. selSql = selSql + " WHERE 协议类型='用户站'";
  186. break;
  187. case "1":
  188. selSql = selSql + " WHERE 协议类型='通讯设备'";
  189. break;
  190. case "2":
  191. selSql = selSql + " WHERE 协议类型='传输设备'";
  192. break;
  193. }
  194. DataTable dtResult = sqlHelper.ExecuteDataTable(selSql, CommandType.Text, null);
  195. return dtResult;
  196. }
  197. catch (Exception ex)
  198. {
  199. return null;
  200. }
  201. }
  202. /// <summary>
  203. /// 获取数据通道数据
  204. /// </summary>
  205. /// <param name="chanleName">通道服务类型</param>
  206. /// <returns></returns>
  207. public DataTable GetDataChannele(string chanleName)
  208. {
  209. try
  210. {
  211. string selSql = "SELECT * FROM dbo.数据通道 ";
  212. if (string.IsNullOrEmpty(chanleName))
  213. {
  214. selSql += " WHERE IN ('" + chanleName + "')";
  215. }
  216. DataTable dtResult = sqlHelper.ExecuteDataTable(selSql, CommandType.Text, null);
  217. return dtResult;
  218. }
  219. catch (Exception ex)
  220. {
  221. return null;
  222. }
  223. }
  224. public bool SaveDataChannele(DataChannele entity)
  225. {
  226. try
  227. {
  228. string insertSql = DataHelper.ModelToInsertSql(entity, "数据通道");
  229. return sqlHelper.ExecuteNoQuery(insertSql, null) > 0 ? true : false;
  230. }
  231. catch (Exception ex)
  232. {
  233. return false;
  234. }
  235. }
  236. }
  237. }