管道基础大数据平台系统开发-【CS】-ExportMap
13693261870
2024-01-06 04a22f3f691e76c1449969048b502f80a19a06ec
添加网格接口
已添加3个文件
已修改3个文件
264 ■■■■■ 文件已修改
JiangSu/App_Data/js.db 补丁 | 查看 | 原始文档 | blame | 历史
JiangSu/Controllers/GridController.cs 132 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
JiangSu/JiangSu.csproj 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
JiangSu/Models/Grid.cs 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
JiangSu/cs/GridDAL.cs 71 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
JiangSu/index.html 42 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
JiangSu/App_Data/js.db
Binary files differ
JiangSu/Controllers/GridController.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,132 @@
using JiangSu.cs;
using JiangSu.Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
namespace JiangSu.Controllers
{
    public class GridController : ApiController
    {
        [HttpGet]
        public object SelectAll()
        {
            try
            {
                List<Grid> grids = GridDAL.SelectAll();
                List<JObject> list = GetJObjects(grids);
                Dictionary<string, object> dict = GetDict();
                dict.Add("features", list);
                return dict;
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
                return null;
            }
        }
        private Dictionary<string, object> GetDict()
        {
            string crs = "{ \"type\": \"name\", \"properties\": { \"name\": \"urn:ogc:def:crs:OGC:1.3:CRS84\" } }";
            JObject crsJObj = JsonConvert.DeserializeObject<JObject>(crs);
            Dictionary<string, object> dict = new Dictionary<string, object>();
            dict.Add("type", "FeatureCollection");
            dict.Add("name", "网格4549");
            dict.Add("crs", crsJObj);
            return dict;
        }
        private List<JObject> GetJObjects(List<Grid> grids)
        {
            List<JObject> list = new List<JObject>();
            if (null != grids && grids.Count > 0)
            {
                foreach (Grid g in grids)
                {
                    JObject obj = JsonConvert.DeserializeObject<JObject>(g.json);
                    list.Add(obj);
                }
            }
            return list;
        }
        [HttpGet]
        public object SelectById(long id)
        {
            try
            {
                Grid grid = GridDAL.SelectById(id);
                List<JObject> list = GetJObjects(null == grid ? null : new List<Grid> { grid });
                Dictionary<string, object> dict = GetDict();
                dict.Add("features", list);
                return dict;
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
                return null;
            }
        }
        [HttpGet]
        public int DeleteByIds([FromUri] List<int> ids)
        {
            try
            {
                if (null == ids || ids.Count == 0) return 0;
                return GridDAL.DeleteByIds(ids);
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
                return 0;
            }
        }
        [HttpPost]
        public int Insert([FromBody] Grid grid)
        {
            try
            {
                if (null == grid) return 0;
                return GridDAL.Insert(grid);
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
                return 0;
            }
        }
        [HttpPost]
        public int UpdateById([FromBody] Grid grid)
        {
            try
            {
                if (null == grid) return 0;
                return GridDAL.UpdateById(grid);
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
                return 0;
            }
        }
    }
}
JiangSu/JiangSu.csproj
@@ -136,6 +136,8 @@
    <Compile Include="Controllers\HomeController.cs" />
    <Compile Include="Controllers\OpController.cs" />
    <Compile Include="Controllers\ValuesController.cs" />
    <Compile Include="Controllers\GridController.cs" />
    <Compile Include="cs\GridDAL.cs" />
    <Compile Include="cs\LogOut.cs" />
    <Compile Include="cs\ModelDAL.cs" />
    <Compile Include="cs\ModelHandler.cs" />
@@ -143,6 +145,7 @@
    <Compile Include="Global.asax.cs">
      <DependentUpon>Global.asax</DependentUpon>
    </Compile>
    <Compile Include="Models\Grid.cs" />
    <Compile Include="Models\Model.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
JiangSu/Models/Grid.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace JiangSu.Models
{
    public class Grid
    {
        public Grid() { }
        public long id { set; get; }
        public string json { set; get; }
    }
}
JiangSu/cs/GridDAL.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,71 @@
using JiangSu.Models;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using System.Linq;
using System.Web;
namespace JiangSu.cs
{
    public class GridDAL
    {
        public static List<Grid> SelectAll()
        {
            string sql = "select * from grid";
            DataTable dt = SQLiteHelper.GetDataTable(sql);
            if (null == dt || dt.Rows.Count == 0)
            {
                return null;
            }
            List<Grid> list = ModelHandler.FillModel<Grid>(dt);
            return list;
        }
        public static Grid SelectById(long id)
        {
            string sql = "select * from grid where id = @id";
            SQLiteParameter param = new SQLiteParameter("@id");
            param.Value = id;
            DataTable dt = SQLiteHelper.GetDataTable(sql, param);
            if (null == dt || dt.Rows.Count == 0)
            {
                return null;
            }
            List<Grid> list = ModelHandler.FillModel<Grid>(dt);
            return null == list || list.Count == 0 ? null : list[0];
        }
        public static int DeleteByIds(List<int> ids)
        {
            string str = string.Join(",", ids.ToArray());
            string sql = string.Format("delete from grid where id in ({0})", str);
            return SQLiteHelper.ExecuteNonQuery(sql);
        }
        public static int Insert(Grid grid)
        {
            string sql = "insert into grid (json) values (@json);select last_insert_rowid();";
            SQLiteParameter[] sqlParams = ModelDAL.GetParams<Grid>(sql, grid);
            object obj = SQLiteHelper.ExecuteScalar(sql, sqlParams);
            return null == obj ? 0 : Convert.ToInt32(obj);
        }
        public static int UpdateById(Grid grid)
        {
            string sql = "update grid set json = @json where id = @id";
            SQLiteParameter[] sqlParams = ModelDAL.GetParams<Grid>(sql, grid);
            return SQLiteHelper.ExecuteNonQuery(sql, sqlParams);
        }
    }
}
JiangSu/index.html
@@ -42,6 +42,33 @@
      return JSON.stringify(model);
    }
    function InsertGrid() {
      var data = getGrid();
      ajax("Grid/Insert", "POST", data, null, null, function (rs) {
        console.log(rs);
        alert(rs);
      });
    }
    function UpdateGridById() {
      var data = getGrid();
      ajax("Grid/UpdateById", "POST", data, null, null, function (rs) {
        console.log(rs);
        alert(rs);
      });
    }
    function getGrid() {
      var model = {
        id: $("#gid").val(),
        json: $("#gjson").val()
      };
      return JSON.stringify(model);
    }
    function ajax(url, type, data, dataType, contentType, fn) {
      $.ajax({
        url: url,
@@ -60,13 +87,13 @@
  </script>
</head>
<body>
  <a href="http://localhost/JiangSu/Values/Get">Test</a> <br />
  <a href="http://localhost/JiangSu/Values/Get">Test</a> <br /> <br />
  <a href="http://localhost/JiangSu/Op/SelectByPage?pageSize=10&pageIndex=1&name=">SelectByPage?pageSize=10&pageIndex=1&name=</a> <br />
  <a href="http://localhost/JiangSu/Op/SelectById?id=1">SelectById?id=1</a> <br />
  <a href="http://localhost/JiangSu/Op/DeleteByIds?ids=13&ids=14">DeleteByIds?ids=13&ids=14</a> <br />
  <a href="http://localhost/JiangSu/Op/DeleteByIds?ids=47&ids=14">DeleteByIds?ids=47&ids=14</a> <br /> <br />
  <form>
    id: <input id="id" name="id" value="3" /> <br />
@@ -74,7 +101,16 @@
    json: <input id="json" name="json" value="{}" /> <br />
    <input type="button" value="Insert" onclick="Insert();" />
    <input type="button" value="UpdateById" onclick="UpdateById();" /><br />
    <input type="button" value="UpdateById" onclick="UpdateById();" /><br /> <br />
    ç½‘格:<a href="http://localhost/JiangSu/Grid/SelectAll">SelectAll</a>
    <a href="http://localhost/JiangSu/Grid/SelectById?id=1">SelectById?id=1</a>
    <a href="http://localhost/JiangSu/Grid/DeleteByIds?ids=12&ids=13">DeleteByIds?ids=12&ids=13</a> <br />
    &nbsp;&nbsp; id: <input id="gid" value="12" /> <br />
    json: <textarea id="gjson" style="width: 1024px;height: 70px;">{ "type": "Feature", "properties": { "ID": "12", "NAME": "Area8", "REMARK": "" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 120.24179180542139, 32.005615085853492, 13.770 ], [ 120.24175240823769, 32.005610442630996, 13.770 ], [ 120.24173428512847, 32.005722106674966, 13.770 ], [ 120.24177368235908, 32.005726749902777, 13.770 ], [ 120.24179180542139, 32.005615085853492, 13.770 ] ] ] } }</textarea> <br />
    <input type="button" value="InsertGrid" onclick="InsertGrid();" />
    <input type="button" value="UpdateGridById" onclick="UpdateGridById();" /><br /> <br />
  </form>
</body>
</html>