Эх сурвалжийг харах

startup初始化模型,区分数据库名

lcl 2 жил өмнө
parent
commit
171cf3f9e3
1 өөрчлөгдсөн 30 нэмэгдсэн , 19 устгасан
  1. 30 19
      Startup.cs

+ 30 - 19
Startup.cs

@@ -56,25 +56,6 @@ namespace MySystem
             MySystemLib.SystemPublicFuction.appid = appid;
             MySystemLib.SystemPublicFuction.checkurl = checkurl;
             MySystemLib.SystemPublicFuction.appcheck = "success";
-            string conn = Configuration["Setting:SqlConnStr"];
-            Dictionary<string, Dictionary<string, string>> tables = new Dictionary<string, Dictionary<string, string>>();
-            System.Data.DataTable tablecollection = Library.CustomerSqlConn.dtable("select DISTINCT TABLE_NAME from information_schema.columns where table_schema = 'KxsProfitServer'", conn);
-            foreach (System.Data.DataRow subtable in tablecollection.Rows)
-            {
-                Dictionary<string, string> Columns = new Dictionary<string, string>();
-                System.Data.DataTable columncollection = Library.CustomerSqlConn.dtable("select COLUMN_NAME,DATA_TYPE from information_schema.columns where table_schema = 'KxsProfitServer' and TABLE_NAME='" + subtable["TABLE_NAME"].ToString() + "'", conn);
-                foreach (System.Data.DataRow column in columncollection.Rows)
-                {
-                    string datatype = column["DATA_TYPE"].ToString();
-                    if (datatype == "decimal")
-                    {
-                        datatype = "numeric";
-                    }
-                    Columns.Add(column["COLUMN_NAME"].ToString(), datatype);
-                }
-                tables.Add(subtable["TABLE_NAME"].ToString(), Columns);
-            }
-            MySystemLib.SystemPublicFuction.dbtables = tables;
         }
 
         // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@@ -114,6 +95,8 @@ namespace MySystem
                     name: "default",
                     pattern: "{controller=Home}/{action=Index}/{Id?}");
             });
+
+            initMain();
             
             //必须打开的
             StatService.Instance.StartEverDayV2(); //实时统计交易额
@@ -141,5 +124,33 @@ namespace MySystem
             //必须打开的
 
         }
+
+        private void initMain()
+        {
+            string conn = Configuration["Setting:SqlConnStr"];
+            string dbName = "KxsMainServer";
+            if(Library.ConfigurationManager.EnvironmentFlag == 2)
+            {
+                dbName = "KxsProfitServer";
+            }
+            Dictionary<string, Dictionary<string, string>> tables = new Dictionary<string, Dictionary<string, string>>();
+            System.Data.DataTable tablecollection = Library.CustomerSqlConn.dtable("select DISTINCT TABLE_NAME from information_schema.columns where table_schema = '" + dbName + "'", conn);
+            foreach (System.Data.DataRow subtable in tablecollection.Rows)
+            {
+                Dictionary<string, string> Columns = new Dictionary<string, string>();
+                System.Data.DataTable columncollection = Library.CustomerSqlConn.dtable("select COLUMN_NAME,DATA_TYPE from information_schema.columns where table_schema = '" + dbName + "' and TABLE_NAME='" + subtable["TABLE_NAME"].ToString() + "'", conn);
+                foreach (System.Data.DataRow column in columncollection.Rows)
+                {
+                    string datatype = column["DATA_TYPE"].ToString();
+                    if (datatype == "decimal")
+                    {
+                        datatype = "numeric";
+                    }
+                    Columns.Add(column["COLUMN_NAME"].ToString(), datatype);
+                }
+                tables.Add(subtable["TABLE_NAME"].ToString(), Columns);
+            }
+            MySystemLib.SystemPublicFuction.dbtables = tables;
+        }
     }
 }