HomeController.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6. using Microsoft.AspNetCore.Mvc;
  7. using Microsoft.Extensions.Logging;
  8. using Library;
  9. namespace MySystem.Controllers
  10. {
  11. public class HomeController : Controller
  12. {
  13. private readonly ILogger<HomeController> _logger;
  14. public HomeController(ILogger<HomeController> logger)
  15. {
  16. _logger = logger;
  17. }
  18. public IActionResult Index()
  19. {
  20. return View();
  21. }
  22. public IActionResult Error()
  23. {
  24. string isapi = Request.Headers["Api"].ToString();
  25. if (isapi != "1")
  26. {
  27. if (Response.StatusCode == 500)
  28. {
  29. return Redirect("/public/errpage/pc/500.html");
  30. }
  31. else if (Response.StatusCode == 502)
  32. {
  33. return Redirect("/public/errpage/pc/502.html");
  34. }
  35. else if (Response.StatusCode == 404)
  36. {
  37. return Redirect("/public/errpage/pc/404.html");
  38. }
  39. }
  40. return View();
  41. }
  42. public string checkMySql(string dbname = "")
  43. {
  44. if(string.IsNullOrEmpty(dbname))
  45. {
  46. return "请传入数据库名";
  47. }
  48. string connstrdev = "";
  49. string connstrdis = "";
  50. List<string> tblistdev = new List<string>();
  51. List<string> tblistdis = new List<string>();
  52. if(dbname == "KxsMainServer")
  53. {
  54. connstrdev = "server=47.109.31.237;port=3306;user=KxsMainServer2;password=FrW8ZfxlcaVdm1r0;database=KxsMainServer2;charset=utf8;";
  55. connstrdis = "server=47.108.231.170;port=3306;user=KxsMain;password=mzeqjriUWore0dwT;database=KxsMainServer;charset=utf8;";
  56. }
  57. string[] connstrlist = { connstrdev, connstrdis };
  58. int index = 0;
  59. foreach(string connstr in connstrlist)
  60. {
  61. index += 1;
  62. if(index == 1)
  63. {
  64. dbname += "2";
  65. }
  66. else
  67. {
  68. dbname = dbname.Replace("2", "");
  69. }
  70. OtherMySqlConn.connstr = connstr;
  71. System.Data.DataTable tablecollection = OtherMySqlConn.dtable("select DISTINCT TABLE_NAME from information_schema.columns where table_schema = '" + dbname + "'");
  72. foreach (System.Data.DataRow subtable in tablecollection.Rows)
  73. {
  74. string tbname = subtable["TABLE_NAME"].ToString();
  75. Dictionary<string, string> Columns = new Dictionary<string, string>();
  76. System.Data.DataTable columncollection = Library.OtherMySqlConn.dtable("select COLUMN_NAME,DATA_TYPE from information_schema.columns where table_schema = '" + dbname + "' and TABLE_NAME='" + tbname + "'");
  77. foreach (System.Data.DataRow column in columncollection.Rows)
  78. {
  79. string datatype = column["DATA_TYPE"].ToString();
  80. string columnName = column["COLUMN_NAME"].ToString();
  81. if(index == 1)
  82. {
  83. tblistdev.Add(tbname + "--" + columnName);
  84. }
  85. if(index == 2)
  86. {
  87. tblistdis.Add(tbname + "--" + columnName);
  88. }
  89. }
  90. }
  91. OtherMySqlConn.connstr = "";
  92. }
  93. List<string> list = tblistdev.Where(m => !tblistdis.Contains(m)).OrderBy(m => m).ToList();
  94. string result = "开始\n";
  95. foreach(string sub in list)
  96. {
  97. result += sub + "\n";
  98. }
  99. result += "结束\n";
  100. return result;
  101. }
  102. }
  103. }