Пример #1
0
        public ActionResult Add(double X, double Y)
        {
            string Error     = string.Empty;
            var    layerName = HttpContext.Request.Form["LayerName"].ToString();
            Dictionary <string, string> values = Core.FeatureManager.GetFeatureValues(layerName);

            if (Math.Abs(X - 0) < 0.01 && Math.Abs(Y - 0) < 0.01)
            {
                HttpPostedFileBase file = null;
                foreach (string upload in Request.Files)
                {
                    if (Request.Files[upload].HasFile())
                    {
                        file = Request.Files[upload];
                        break;
                    }
                }
                if (file == null)
                {
                    return(JsonFail("请上传文件"));
                }
                var filePath = UploadHelper.Upload(file);
                var fileID   = UploadHelper.AddFileEntity(new UploadFile
                {
                    FileName  = filePath,
                    LayerName = layerName
                });
                var tempFile = UploadHelper.GetAbsolutePath(filePath);
                try
                {
                    Core.FeatureManager.CreateFeature(tempFile, values, layerName);
                }
                catch (Exception ex)
                {
                    Error = ex.ToString();
                }
            }
            else
            {
                try
                {
                    Core.FeatureManager.CreateFeature(X, Y, values, layerName);
                }
                catch (Exception ex)
                {
                    Error = ex.ToString();
                }
            }
            if (string.IsNullOrEmpty(Error))
            {
                return(JavascriptResult("alert('添加成功');window.parent.application.hideAddModal();"));
            }
            else
            {
                return(JavascriptResult("alert('操作失败:" + Error + "');window.parent.application.hideAddModal();"));
            }
        }