123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using LeaRun.Application.IService.PipeNetworkManage;
- using LeaRun.Data;
- using LeaRun.Application.Entity.PipeNetworkManage;
- using System.Data;
- using LeaRun.Util;
- namespace LeaRun.Application.Service.PipeNetworkManage
- {
- public class PipeMapService : IPipeMapService
- {
- SqlHelper sqlHelper = new SqlHelper("PipeNetworkDb");
- /// <summary>
- /// 保存管网区域
- /// </summary>
- /// <param name="areaName"></param>
- /// <param name="remark"></param>
- /// <returns></returns>
- public bool SavePipeArea(string areaName, string remark)
- {
- try
- {
- string insertSql = "INSERT INTO PipeArea(PipeName,PipeRemark)VALUES('" + areaName + "','" + remark + "')";
- int result = sqlHelper.ExecuteNoParams(insertSql, System.Data.CommandType.Text);
- return result > 0;
- }
- catch (Exception ex)
- {
- return false;
- }
- }
- /// <summary>
- /// 管网区域列表
- /// </summary>
- /// <returns></returns>
- public IEnumerable<PipeArea> GetPipeAreaList()
- {
- try
- {
- string selSql = "SELECT * FROM PipeArea";
- DataTable dtResult = sqlHelper.ExecuteDataTable(selSql, CommandType.Text, null);
- return DataHelper.DataTableToT<PipeArea>(dtResult) == null ? new List<PipeArea>() : DataHelper.DataTableToT<PipeArea>(dtResult);
- }
- catch (Exception ex)
- {
- return null;
- }
- }
- /// <summary>
- /// 区域下的管线列表
- /// </summary>
- /// <param name="areaId"></param>
- /// <returns></returns>
- public IEnumerable<PipeLine> GetPipeLineList(string areaId)
- {
- try
- {
- string selSql = "SELECT * FROM PipeLine WHERE PipeAreaId = " + areaId;
- DataTable dtResult = sqlHelper.ExecuteDataTable(selSql, CommandType.Text, null);
- return DataHelper.DataTableToT<PipeLine>(dtResult) == null ? new List<PipeLine>() : DataHelper.DataTableToT<PipeLine>(dtResult);
- }
- catch (Exception ex)
- {
- return null;
- }
- }
- /// <summary>
- /// 所有管线列表
- /// </summary>
- /// <returns></returns>
- public IEnumerable<PipeLine> GetAllPipeLine()
- {
- try
- {
- string selSql = "SELECT * FROM PipeLine ";
- DataTable dtResult = sqlHelper.ExecuteDataTable(selSql, CommandType.Text, null);
- return DataHelper.DataTableToT<PipeLine>(dtResult) == null ? new List<PipeLine>() : DataHelper.DataTableToT<PipeLine>(dtResult);
- }
- catch (Exception ex)
- {
- return null;
- }
- }
- /// <summary>
- /// 保存管线
- /// </summary>
- /// <param name="pipeLine"></param>
- /// <returns></returns>
- public bool SavePipeLine(PipeLine pipeLine)
- {
- try
- {
- string insertSql = DataHelper.ModelToInsertSql<PipeLine>(pipeLine, "PipeLine");
- int result = sqlHelper.ExecuteNoParams(insertSql, CommandType.Text);
- return result > 0;
- }
- catch (Exception ex)
- {
- return false;
- }
- }
- /// <summary>
- /// 保存管线坐标
- /// </summary>
- /// <param name="lineId">管线ID</param>
- /// <param name="points">坐标集合</param>
- /// <returns></returns>
- public bool SavePipeLinePoints(string lineId, string points)
- {
- try
- {
- string updateSql = "UPDATE PipeLine SET Coordinates ='" + points + "' WHERE PipeLineId =" + lineId;
- int result = sqlHelper.ExecuteNoParams(updateSql, CommandType.Text);
- return result > 0;
- }
- catch (Exception ex)
- {
- return false;
- }
- }
- /// <summary>
- /// 获取管网信息
- /// </summary>
- /// <returns></returns>
- public PipeArea GetPipeAreaById(string areaId)
- {
- try
- {
- string selSql = "SELECT * FROM PipeArea WHERE PipeAreaId=" + areaId;
- DataTable dtTable = sqlHelper.ExecuteDataTable(selSql, CommandType.Text, null);
- List<PipeArea> areas = DataHelper.DataTableToT<PipeArea>(dtTable);
- return areas[0];
- }
- catch (Exception ex)
- {
- return null;
- }
- }
- /// <summary>
- /// 更新管网区域
- /// </summary>
- /// <param name="areaName">区域名称</param>
- /// <param name="remark">备注</param>
- /// <param name="areaId">区域ID</param>
- /// <returns></returns>
- public bool UpdatePipeArea(string areaName, string remark, string areaId)
- {
- try
- {
- string updateSql = "UPDATE PipeArea SET PipeName='" + areaName + "', PipeRemark='" + remark + "' WHERE PipeAreaId=" + areaId;
- int result = sqlHelper.ExecuteNoParams(updateSql, CommandType.Text);
- return result > 0;
- }
- catch (Exception ex)
- {
- return false;
- }
- }
- /// <summary>
- /// 获取管线信息
- /// </summary>
- /// <returns></returns>
- public PipeLine GetPipeLineById(string lineId)
- {
- try
- {
- string selSql = "SELECT * FROM PipeLine WHERE PipeLineId=" + lineId;
- DataTable dtTable = sqlHelper.ExecuteDataTable(selSql, CommandType.Text, null);
- List<PipeLine> areas = DataHelper.DataTableToT<PipeLine>(dtTable);
- return areas[0];
- }
- catch (Exception ex)
- {
- return null;
- }
- }
- /// <summary>
- /// 更新管线基本信息
- /// </summary>
- /// <param name="pipeLine"></param>
- /// <returns></returns>
- public bool UpdatePipeLine(PipeLine pipeLine)
- {
- try
- {
- string updateSql = DataHelper.ModelToUpdateSql<PipeLine>(pipeLine, "PipeLine");
- int result = sqlHelper.ExecuteNoParams(updateSql, CommandType.Text);
- return result > 0;
- }
- catch (Exception ex)
- {
- return false;
- }
- }
- /// <summary>
- /// 删除管网区域
- /// </summary>
- /// <param name="areaId"></param>
- /// <returns></returns>
- public bool DeletePipeArea(string areaId)
- {
- try
- {
- //第一步 删除 次管网区域下的所有管线
- string deletePipeLineInArea = "DELETE FROM PipeLine WHERE PipeAreaId="+areaId;
- sqlHelper.ExecuteNoParams(deletePipeLineInArea, CommandType.Text);
- string deletePipeArea = "DELETE FROM PipeArea WHERE PipeAreaId=" + areaId;
- sqlHelper.ExecuteNoParams(deletePipeArea,CommandType.Text);
- return true;
- }
- catch (Exception ex)
- {
- return false;
- }
- }
- /// <summary>
- /// 删除管线
- /// </summary>
- /// <param name="lineId"></param>
- /// <returns></returns>
- public bool DeltePipeLine(string lineId)
- {
- try
- {
- //删除管线信息
- string deletePipeArea = "DELETE FROM PipeLine WHERE PipeLineId=" + lineId;
- sqlHelper.ExecuteNoParams(deletePipeArea, CommandType.Text);
- return true;
- }
- catch (Exception ex)
- {
- return false;
- }
- }
- }
- }
|