123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Threading.Tasks;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Logging;
- using Library;
- namespace MySystem.Controllers
- {
- public class HomeController : Controller
- {
- private readonly ILogger<HomeController> _logger;
- public HomeController(ILogger<HomeController> logger)
- {
- _logger = logger;
- }
- public IActionResult Index()
- {
- return View();
- }
- public IActionResult Error()
- {
- string isapi = Request.Headers["Api"].ToString();
- if (isapi != "1")
- {
- if (Response.StatusCode == 500)
- {
- return Redirect("/public/errpage/pc/500.html");
- }
- else if (Response.StatusCode == 502)
- {
- return Redirect("/public/errpage/pc/502.html");
- }
- else if (Response.StatusCode == 404)
- {
- return Redirect("/public/errpage/pc/404.html");
- }
- }
- return View();
- }
- public string checkMySql(string dbname = "")
- {
- if(string.IsNullOrEmpty(dbname))
- {
- return "请传入数据库名";
- }
- string connstrdev = "";
- string connstrdis = "";
- List<string> tblistdev = new List<string>();
- List<string> tblistdis = new List<string>();
- if(dbname == "KxsMainServer")
- {
- connstrdev = "server=47.109.31.237;port=3306;user=KxsMainServer2;password=FrW8ZfxlcaVdm1r0;database=KxsMainServer2;charset=utf8;";
- connstrdis = "server=47.108.231.170;port=3306;user=KxsMain;password=mzeqjriUWore0dwT;database=KxsMainServer;charset=utf8;";
- }
- string[] connstrlist = { connstrdev, connstrdis };
- int index = 0;
- foreach(string connstr in connstrlist)
- {
- index += 1;
- if(index == 1)
- {
- dbname += "2";
- }
- else
- {
- dbname = dbname.Replace("2", "");
- }
- OtherMySqlConn.connstr = connstr;
- System.Data.DataTable tablecollection = OtherMySqlConn.dtable("select DISTINCT TABLE_NAME from information_schema.columns where table_schema = '" + dbname + "'");
- foreach (System.Data.DataRow subtable in tablecollection.Rows)
- {
- string tbname = subtable["TABLE_NAME"].ToString();
- Dictionary<string, string> Columns = new Dictionary<string, string>();
- System.Data.DataTable columncollection = Library.OtherMySqlConn.dtable("select COLUMN_NAME,DATA_TYPE from information_schema.columns where table_schema = '" + dbname + "' and TABLE_NAME='" + tbname + "'");
- foreach (System.Data.DataRow column in columncollection.Rows)
- {
- string datatype = column["DATA_TYPE"].ToString();
- string columnName = column["COLUMN_NAME"].ToString();
- if(index == 1)
- {
- tblistdev.Add(tbname + "--" + columnName);
- }
- if(index == 2)
- {
- tblistdis.Add(tbname + "--" + columnName);
- }
- }
- }
- OtherMySqlConn.connstr = "";
- }
- List<string> list = tblistdev.Where(m => !tblistdis.Contains(m)).OrderBy(m => m).ToList();
- string result = "开始\n";
- foreach(string sub in list)
- {
- result += sub + "\n";
- }
- result += "结束\n";
- return result;
- }
-
-
- }
- }
|