PipeMapService.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using LeaRun.Application.IService.PipeNetworkManage;
  7. using LeaRun.Data;
  8. using LeaRun.Application.Entity.PipeNetworkManage;
  9. using System.Data;
  10. using LeaRun.Util;
  11. namespace LeaRun.Application.Service.PipeNetworkManage
  12. {
  13. public class PipeMapService : IPipeMapService
  14. {
  15. SqlHelper sqlHelper = new SqlHelper("PipeNetworkDb");
  16. /// <summary>
  17. /// 保存管网区域
  18. /// </summary>
  19. /// <param name="areaName"></param>
  20. /// <param name="remark"></param>
  21. /// <returns></returns>
  22. public bool SavePipeArea(string areaName, string remark)
  23. {
  24. try
  25. {
  26. string insertSql = "INSERT INTO PipeArea(PipeName,PipeRemark)VALUES('" + areaName + "','" + remark + "')";
  27. int result = sqlHelper.ExecuteNoParams(insertSql, System.Data.CommandType.Text);
  28. return result > 0;
  29. }
  30. catch (Exception ex)
  31. {
  32. return false;
  33. }
  34. }
  35. /// <summary>
  36. /// 管网区域列表
  37. /// </summary>
  38. /// <returns></returns>
  39. public IEnumerable<PipeArea> GetPipeAreaList()
  40. {
  41. try
  42. {
  43. string selSql = "SELECT * FROM PipeArea";
  44. DataTable dtResult = sqlHelper.ExecuteDataTable(selSql, CommandType.Text, null);
  45. return DataHelper.DataTableToT<PipeArea>(dtResult) == null ? new List<PipeArea>() : DataHelper.DataTableToT<PipeArea>(dtResult);
  46. }
  47. catch (Exception ex)
  48. {
  49. return null;
  50. }
  51. }
  52. /// <summary>
  53. /// 区域下的管线列表
  54. /// </summary>
  55. /// <param name="areaId"></param>
  56. /// <returns></returns>
  57. public IEnumerable<PipeLine> GetPipeLineList(string areaId)
  58. {
  59. try
  60. {
  61. string selSql = "SELECT * FROM PipeLine WHERE PipeAreaId = " + areaId;
  62. DataTable dtResult = sqlHelper.ExecuteDataTable(selSql, CommandType.Text, null);
  63. return DataHelper.DataTableToT<PipeLine>(dtResult) == null ? new List<PipeLine>() : DataHelper.DataTableToT<PipeLine>(dtResult);
  64. }
  65. catch (Exception ex)
  66. {
  67. return null;
  68. }
  69. }
  70. /// <summary>
  71. /// 所有管线列表
  72. /// </summary>
  73. /// <returns></returns>
  74. public IEnumerable<PipeLine> GetAllPipeLine()
  75. {
  76. try
  77. {
  78. string selSql = "SELECT * FROM PipeLine ";
  79. DataTable dtResult = sqlHelper.ExecuteDataTable(selSql, CommandType.Text, null);
  80. return DataHelper.DataTableToT<PipeLine>(dtResult) == null ? new List<PipeLine>() : DataHelper.DataTableToT<PipeLine>(dtResult);
  81. }
  82. catch (Exception ex)
  83. {
  84. return null;
  85. }
  86. }
  87. /// <summary>
  88. /// 保存管线
  89. /// </summary>
  90. /// <param name="pipeLine"></param>
  91. /// <returns></returns>
  92. public bool SavePipeLine(PipeLine pipeLine)
  93. {
  94. try
  95. {
  96. string insertSql = DataHelper.ModelToInsertSql<PipeLine>(pipeLine, "PipeLine");
  97. int result = sqlHelper.ExecuteNoParams(insertSql, CommandType.Text);
  98. return result > 0;
  99. }
  100. catch (Exception ex)
  101. {
  102. return false;
  103. }
  104. }
  105. /// <summary>
  106. /// 保存管线坐标
  107. /// </summary>
  108. /// <param name="lineId">管线ID</param>
  109. /// <param name="points">坐标集合</param>
  110. /// <returns></returns>
  111. public bool SavePipeLinePoints(string lineId, string points)
  112. {
  113. try
  114. {
  115. string updateSql = "UPDATE PipeLine SET Coordinates ='" + points + "' WHERE PipeLineId =" + lineId;
  116. int result = sqlHelper.ExecuteNoParams(updateSql, CommandType.Text);
  117. return result > 0;
  118. }
  119. catch (Exception ex)
  120. {
  121. return false;
  122. }
  123. }
  124. /// <summary>
  125. /// 获取管网信息
  126. /// </summary>
  127. /// <returns></returns>
  128. public PipeArea GetPipeAreaById(string areaId)
  129. {
  130. try
  131. {
  132. string selSql = "SELECT * FROM PipeArea WHERE PipeAreaId=" + areaId;
  133. DataTable dtTable = sqlHelper.ExecuteDataTable(selSql, CommandType.Text, null);
  134. List<PipeArea> areas = DataHelper.DataTableToT<PipeArea>(dtTable);
  135. return areas[0];
  136. }
  137. catch (Exception ex)
  138. {
  139. return null;
  140. }
  141. }
  142. /// <summary>
  143. /// 更新管网区域
  144. /// </summary>
  145. /// <param name="areaName">区域名称</param>
  146. /// <param name="remark">备注</param>
  147. /// <param name="areaId">区域ID</param>
  148. /// <returns></returns>
  149. public bool UpdatePipeArea(string areaName, string remark, string areaId)
  150. {
  151. try
  152. {
  153. string updateSql = "UPDATE PipeArea SET PipeName='" + areaName + "', PipeRemark='" + remark + "' WHERE PipeAreaId=" + areaId;
  154. int result = sqlHelper.ExecuteNoParams(updateSql, CommandType.Text);
  155. return result > 0;
  156. }
  157. catch (Exception ex)
  158. {
  159. return false;
  160. }
  161. }
  162. /// <summary>
  163. /// 获取管线信息
  164. /// </summary>
  165. /// <returns></returns>
  166. public PipeLine GetPipeLineById(string lineId)
  167. {
  168. try
  169. {
  170. string selSql = "SELECT * FROM PipeLine WHERE PipeLineId=" + lineId;
  171. DataTable dtTable = sqlHelper.ExecuteDataTable(selSql, CommandType.Text, null);
  172. List<PipeLine> areas = DataHelper.DataTableToT<PipeLine>(dtTable);
  173. return areas[0];
  174. }
  175. catch (Exception ex)
  176. {
  177. return null;
  178. }
  179. }
  180. /// <summary>
  181. /// 更新管线基本信息
  182. /// </summary>
  183. /// <param name="pipeLine"></param>
  184. /// <returns></returns>
  185. public bool UpdatePipeLine(PipeLine pipeLine)
  186. {
  187. try
  188. {
  189. string updateSql = DataHelper.ModelToUpdateSql<PipeLine>(pipeLine, "PipeLine");
  190. int result = sqlHelper.ExecuteNoParams(updateSql, CommandType.Text);
  191. return result > 0;
  192. }
  193. catch (Exception ex)
  194. {
  195. return false;
  196. }
  197. }
  198. /// <summary>
  199. /// 删除管网区域
  200. /// </summary>
  201. /// <param name="areaId"></param>
  202. /// <returns></returns>
  203. public bool DeletePipeArea(string areaId)
  204. {
  205. try
  206. {
  207. //第一步 删除 次管网区域下的所有管线
  208. string deletePipeLineInArea = "DELETE FROM PipeLine WHERE PipeAreaId="+areaId;
  209. sqlHelper.ExecuteNoParams(deletePipeLineInArea, CommandType.Text);
  210. string deletePipeArea = "DELETE FROM PipeArea WHERE PipeAreaId=" + areaId;
  211. sqlHelper.ExecuteNoParams(deletePipeArea,CommandType.Text);
  212. return true;
  213. }
  214. catch (Exception ex)
  215. {
  216. return false;
  217. }
  218. }
  219. /// <summary>
  220. /// 删除管线
  221. /// </summary>
  222. /// <param name="lineId"></param>
  223. /// <returns></returns>
  224. public bool DeltePipeLine(string lineId)
  225. {
  226. try
  227. {
  228. //删除管线信息
  229. string deletePipeArea = "DELETE FROM PipeLine WHERE PipeLineId=" + lineId;
  230. sqlHelper.ExecuteNoParams(deletePipeArea, CommandType.Text);
  231. return true;
  232. }
  233. catch (Exception ex)
  234. {
  235. return false;
  236. }
  237. }
  238. }
  239. }