From 7837c082fffb594c22269e7557b3dae32fe280f1 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期五, 17 三月 2023 15:47:31 +0800
Subject: [PATCH] 1

---
 ExportMap/cs/ExportUtil.cs  |    1 
 /dev/null                   |   16 --------
 ExportMap/ExportMap.csproj  |    2 
 ExportMap/db/PubDBHelper.cs |   74 +++++++++++++++++++++++++++++++++++++
 4 files changed, 75 insertions(+), 18 deletions(-)

diff --git a/ExportMap/ExportMap.csproj b/ExportMap/ExportMap.csproj
index 334f4fe..7e00cca 100644
--- a/ExportMap/ExportMap.csproj
+++ b/ExportMap/ExportMap.csproj
@@ -144,7 +144,7 @@
     <Compile Include="cs\XYZUtils.cs" />
     <Compile Include="db\ModelHandler.cs" />
     <Compile Include="db\PostgreHelper.cs" />
-    <Compile Include="db\PublishHelper.cs" />
+    <Compile Include="db\PubDBHelper.cs" />
     <Compile Include="db\SQLiteHelper.cs" />
     <Compile Include="Global.asax.cs">
       <DependentUpon>Global.asax</DependentUpon>
diff --git a/ExportMap/cs/ExportUtil.cs b/ExportMap/cs/ExportUtil.cs
index 1663669..d7534a2 100644
--- a/ExportMap/cs/ExportUtil.cs
+++ b/ExportMap/cs/ExportUtil.cs
@@ -218,7 +218,6 @@
         /// <returns>鏁版嵁</returns>
         public static string GetData(string url)
         {
-
             Uri uri = new Uri(url);
             HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
             request.Method = "GET";
diff --git a/ExportMap/db/PubDBHelper.cs b/ExportMap/db/PubDBHelper.cs
new file mode 100644
index 0000000..b41875e
--- /dev/null
+++ b/ExportMap/db/PubDBHelper.cs
@@ -0,0 +1,74 @@
+锘縰sing ExportMap.cs;
+using ExportMap.Models;
+using Npgsql;
+using System;
+using System.Collections.Generic;
+using System.Data.Common;
+using System.Linq;
+using System.Reflection;
+using System.Web;
+
+namespace ExportMap.db
+{
+    public class PubDBHelper
+    {
+        private static string insertPublishSql = "insert into lf.sys_publish(name, url, path, type, status, dirid, depid, min, max, json, create_user, geom, bak) values (@name, @url, @path, @type, @status, @dirid, @depid, @min, @max, @json, @create_user, @geom, @bak) returning id";
+
+        private static string insertMetaPubSql = "insert into lf.sys_meta_pub (metaid, pubid) select {0}, {1} from (select 1) temp where not exists (select 1 from lf.sys_meta_pub where metaid = {0} and pubid = {1})";
+
+        /// <summary>
+        /// 鎻掑叆鍏冩暟鎹�-鏁版嵁鍙戝竷琛ㄨ褰�
+        /// </summary>
+        public static int InsertMetaPub(int metaid, int pubid)
+        {
+            string sql = string.Format(insertMetaPubSql, metaid, pubid);
+
+            return Tool.DBHelper.ExecuteNonQuery(sql);
+        }
+
+        /// <summary>
+        /// 鎻掑叆鏁版嵁鍙戝竷琛ㄨ褰�
+        /// </summary>
+        /// <returns></returns>
+        public static int InsertPublish(SysPublish sys)
+        {
+            List<DbParameter> list = Tool.GetParams<SysPublish>(insertPublishSql, sys);
+
+            object obj = Tool.DBHelper.GetScalar(insertPublishSql, list.ToArray());
+
+            return obj == null ? 0 : Convert.ToInt32(obj);
+        }
+
+        /// <summary>
+        /// 鑾峰彇鍙傛暟鍒楄〃
+        /// </summary>
+        public static List<DbParameter> GetParams<T>(string sql, T t)
+        {
+            List<DbParameter> list = new List<DbParameter>();
+            Type tType = typeof(T);
+            BindingFlags flags = BindingFlags.Public | BindingFlags.IgnoreCase | BindingFlags.Instance;
+
+            int start = sql.IndexOf("@");
+            while (start != -1)
+            {
+                int end = sql.IndexOf(",", start);
+                if (end == -1) end = sql.IndexOf(")", start);
+                if (end == -1) end = sql.IndexOf(" ", start);
+                if (end == -1) end = sql.Length;
+
+                string name = sql.Substring(start + 1, end - start - 1);
+                PropertyInfo pi = tType.GetProperty(name, flags);
+                if (pi != null)
+                {
+                    object value = pi.GetValue(t, null);
+                    DbParameter dp = new NpgsqlParameter("@" + name, value);
+                    list.Add(dp);
+                }
+
+                start = sql.IndexOf("@", end);
+            }
+
+            return list;
+        }
+    }
+}
diff --git a/ExportMap/db/PublishHelper.cs b/ExportMap/db/PublishHelper.cs
deleted file mode 100644
index b6438c4..0000000
--- a/ExportMap/db/PublishHelper.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-锘縰sing System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Web;
-
-namespace ExportMap.db
-{
-    public class PublishHelper
-    {
-        private static string insertPublish = "insert into lf.sys_publish(name, url, path, type, status, dirid, depid, min, max, json, create_user, geom, bak) values (@name, @url, @path, @type, @status, @dirid, @depid, @min, @max, @json, @create_user, @geom, @bak)";
-
-        private static string insertMetaPub = "insert into lf.sys_meta_pub (metaid, pubid) select 1, 1 from (select 1) temp where not exists (select 1 from lf.sys_meta_pub where metaid = 1 and pubid = 1)";
-
-
-    }
-}
\ No newline at end of file

--
Gitblit v1.9.3