Check.aspx.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using System;
  2. using System.Text;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Web;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. using MySql.Data.MySqlClient;
  9. using System.Diagnostics;
  10. using System.Collections;
  11. using System.IO;
  12. using Microsoft.Win32;
  13. using System.Data;
  14. using System.Text.RegularExpressions;
  15. using System.Web.UI.HtmlControls;
  16. using System.Configuration;
  17. namespace LYFZ.NationalMarketing
  18. {
  19. public partial class Check : System.Web.UI.Page
  20. {
  21. protected void Page_Load(object sender, EventArgs e)
  22. { }
  23. string strDB = Admin.PublicClass.myDB.ToString();
  24. string strchuuang = Admin.PublicClass.mysqls.ToString();
  25. protected void Button1_Click(object sender, EventArgs e)
  26. {
  27. Admin.PublicClass.chkLogin(this);
  28. string[] StrID = Request.QueryString["id"].Split(',');
  29. if (Request.QueryString["id"] == "")
  30. {
  31. Response.Write("<script>alert('请选择要删除的数据!');</script>"); return;
  32. }
  33. if (this.shujuku.Checked == true)
  34. {
  35. for (int i = 0; i < StrID.Length - 1; i++)
  36. {
  37. string StrPhone = StrID[i].Split('_')[1];
  38. string Strshujuku = "SELECT `SCHEMA_NAME` FROM `information_schema`.`SCHEMATA` WHERE SCHEMA_NAME='wzyx" + StrPhone + "'";
  39. string Strdelete = "DROP DATABASE wzyx" + StrPhone + "";
  40. MySqlConnection con = new MySql.Data.MySqlClient.MySqlConnection(strchuuang);
  41. MySqlCommand da = new MySql.Data.MySqlClient.MySqlCommand(Strshujuku, con);
  42. con.Open();
  43. MySqlDataReader date = da.ExecuteReader();
  44. int leng = 0;
  45. while (date.Read())
  46. {
  47. leng++;
  48. }
  49. con.Clone();
  50. if (leng > 0)
  51. {
  52. MySqlConnection cons = new MySql.Data.MySqlClient.MySqlConnection(strchuuang);
  53. MySqlCommand das = new MySql.Data.MySqlClient.MySqlCommand(Strdelete, cons);
  54. cons.Open();
  55. das.ExecuteNonQuery();
  56. cons.Clone();
  57. }
  58. else
  59. {
  60. Response.Write("<script>alert('数据库不存在!');</script>"); return;
  61. }
  62. con.Close();
  63. }
  64. // Response.Write("<script>alert('数据库删除成功!');</script>");
  65. }
  66. if (this.shuju.Checked == true)
  67. {
  68. string Sphone = Request.QueryString["id"].Split('_')[1].Split(',')[0].ToString();
  69. string Strjies = this.Server.MapPath("~/wzyx" + Sphone + "");
  70. if (!Directory.Exists(Strjies))
  71. {
  72. Response.Write("<script>alert('源站点不存在!');</script>"); return;
  73. }
  74. for (int i = 0; i < StrID.Length - 1; i++)
  75. {
  76. string StrPhone = StrID[i].Split('_')[1].ToString();
  77. string Strjie = this.Server.MapPath("~/wzyx" + StrPhone + "");
  78. if (Directory.Exists(Strjie))
  79. {
  80. Directory.Delete(Strjie, true);
  81. }
  82. else { return; }
  83. }
  84. // Response.Write("<script>alert('源站点删除成功!');</script>");
  85. }
  86. this.Delete();
  87. Response.Write("<script>alert('删除成功!');window.close(); parent.location = 'Management.aspx';</script> ");
  88. }
  89. public void Delete()
  90. {
  91. string[] StrID = Request.QueryString["id"].Split(',');
  92. for (int i = 0; i < StrID.Length - 1; i++)
  93. {
  94. string ID = StrID[i].Split('_')[0];
  95. string Delete = "DELETE FROM admin WHERE id=" + ID + "";
  96. MySqlConnection con = new MySql.Data.MySqlClient.MySqlConnection(strDB);
  97. MySqlCommand da = new MySql.Data.MySqlClient.MySqlCommand(Delete, con);
  98. con.Open();
  99. da.ExecuteNonQuery();
  100. con.Close();
  101. }
  102. }
  103. }
  104. }