管道基础大数据平台系统开发-【CS】-ExportMap
13693261870
2024-01-08 76f9e7b13c2c87717f033e5c30de2a4b14348712
上传GPS图片功能
已修改4个文件
79 ■■■■ 文件已修改
JiangSu/App_Data/js.db 补丁 | 查看 | 原始文档 | blame | 历史
JiangSu/Controllers/ImgController.cs 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
JiangSu/Models/Img.cs 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
JiangSu/index.html 33 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
JiangSu/App_Data/js.db
Binary files differ
JiangSu/Controllers/ImgController.cs
@@ -96,7 +96,7 @@
        }
        [HttpPost]
        public Task<IEnumerable<FileDesc>> Post()
        public Task<IEnumerable<FileDesc>> Upload()
        {
            string root = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, uploadPath);
            if (!Directory.Exists(root)) Directory.CreateDirectory(root);
@@ -120,17 +120,20 @@
                    string md5 = Tools.CalcFileMD5(f.LocalFileName);
                    string newName = md5 + info.Extension;
                    string newFile = Path.Combine(root, uploadPath, newName);
                    string newFile = Path.Combine(root, newName);
                    Img img = new Img();
                    img.name = info.Name;
                    img.path = uploadPath + "\\" + newName;
                    //img.geom = Tools.GetImgGps(f.LocalFileName);
                    List<string> pz = Tools.GetImgGps(f.LocalFileName);
                    Img img = new Img(info.Name, uploadPath + "/" + newName, string.Empty);
                    if (null != pz) img.SetXYZ(pz[0], pz[1], pz[2]);
                    if (!File.Exists(newFile)) File.Move(f.LocalFileName, newFile);
                    FileDesc desc = new FileDesc(info.Name, info.Length);
                    if (File.Exists(newFile))
                        File.Delete(f.LocalFileName);
                    else
                        File.Move(f.LocalFileName, newFile);
                    int rows = ImgDAL.Insert(img);
                    infos.Add(new FileDesc(info.Name, info.Length));
                    if (rows > 0) infos.Add(desc);
                }
                return infos;
JiangSu/Models/Img.cs
@@ -9,6 +9,31 @@
    {
        public Img() { }
        public Img(string name, string path, string json)
        {
            this.name = name;
            this.path = path;
            this.json = json;
        }
        public Img(string name, string path, string json, double x, double y, double z)
        {
            this.name = name;
            this.path = path;
            this.json = json;
            this.x = x;
            this.y = y;
            this.z = z;
        }
        public void SetXYZ(string x, string y, string z)
        {
            double val = 0;
            if (double.TryParse(x, out val)) this.x = val;
            if (double.TryParse(y, out val)) this.y = val;
            if (double.TryParse(z, out val)) this.z = val;
        }
        public long id { set; get; }
        public string name { set; get; }
JiangSu/index.html
@@ -98,6 +98,31 @@
      return JSON.stringify(model);
    }
    function UploadImg() {
      var formData = new FormData();
      var fs = document.getElementById("imgs");
      for (var i = 0, c = fs.files.length; i < c; i++) {
        formData.append(fs.files[i].name, fs.files[i]); // name, file
      }
      $.ajax("Img/Upload", {
        type: "POST",
        data: formData,
        async: true,
        cache: false,
        processData: false,
        contentType: false,
        success: function (rs) {
          console.log(rs);
          alert(JSON.stringify(rs));
        },
        error: function (e) {
          console.error(e);
          alert("上传文件失败!");
        }
      });
    }
    function ajax(url, type, data, dataType, contentType, fn) {
      $.ajax({
        url: url,
@@ -151,10 +176,14 @@
    &nbsp;&nbsp; id: <input id="iid" value="1" /> <br />
    name: <input id="iname" value="1.jpg"/> <br />
    path: <input id="ipath" value="Images\1.jpg"/> <br />
    path: <input id="ipath" value="Images/1.jpg"/> <br />
    json: <input id="ijson" value="{}"/> <br />
    <input type="button" value="InsertImg" onclick="InsertImg();" />
    <input type="button" value="UpdateImgById" onclick="UpdateImgById();" /><br /> <br />
    <input type="button" value="UpdateImgById" onclick="UpdateImgById();" />
    <label for="apifiles">选择图片:</label>
    <input id="imgs" type="file" multiple="multiple" accept=".jpg,.png" />
    <input value="UploadImg" type="button" onclick="UploadImg();" />
    <br /> <br />
  </form>
</body>
</html>