using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using SqlAdmin; namespace SqlWebAdmin { /// /// Summary description for DeleteDatabase. /// public class DeleteDatabase : System.Web.UI.Page { protected System.Web.UI.WebControls.Button YesButton; protected System.Web.UI.WebControls.Button NoButton; protected System.Web.UI.WebControls.Label DatabaseNameLabel; public DeleteDatabase() { Page.Init += new System.EventHandler(Page_Init); } private void Page_Load(object sender, System.EventArgs e) { HttpCookie cookie = Request.Cookies["WebDataAdministrator"]; if (cookie == null) Response.Redirect("default.aspx?error=sessionexpired"); SqlServer server = new SqlServer(cookie.Values["server"], cookie.Values["username"], cookie.Values["password"]); DatabaseNameLabel.Text = Server.HtmlEncode(Request["database"]); } private void Page_Init(object sender, EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); } #region Web Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.NoButton.Click += new System.EventHandler(this.NoButton_Click); this.YesButton.Click += new System.EventHandler(this.YesButton_Click); this.Load += new System.EventHandler(this.Page_Load); } #endregion private void YesButton_Click(object sender, System.EventArgs e) { HttpCookie cookie = Request.Cookies["WebDataAdministrator"]; if (cookie == null) Response.Redirect("default.aspx?error=sessionexpired"); SqlServer server = new SqlServer(cookie.Values["server"], cookie.Values["username"], cookie.Values["password"]); // Delete the database server.Connect(); SqlDatabase database = server.Databases[Request["database"]]; // Check that database actually exists if (database != null) { database.Remove(); } else { server.Disconnect(); // Database doesn't exist - break out and go to error page Response.Redirect(String.Format("error.aspx?error={1}", 1000)); return; } server.Disconnect(); // Redirect to database list page Response.Redirect("databases.aspx"); } private void NoButton_Click(object sender, System.EventArgs e) { // Redirect to database (tables list) page Response.Redirect("tables.aspx?database=" + Server.UrlEncode(Request["database"])); } } }