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 DeleteStoredProcedure. /// public class DeleteStoredProcedure : System.Web.UI.Page { protected System.Web.UI.WebControls.Label DatabaseNameLabel; protected System.Web.UI.WebControls.Button YesButton; protected System.Web.UI.WebControls.Button NoButton; protected System.Web.UI.WebControls.Label SProcNameLabel; public DeleteStoredProcedure() { 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"]); SProcNameLabel.Text = Server.HtmlEncode(Request["sproc"]); } 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"]); server.Connect(); SqlDatabase database = server.Databases[Request["database"]]; if (database == null) { server.Disconnect(); // Database doesn't exist - break out and go to error page Response.Redirect(String.Format("error.aspx?error={0}", 1000)); return; } SqlStoredProcedure sproc = database.StoredProcedures[Request["sproc"]]; if (sproc == null) { server.Disconnect(); // Stored procedure doesn't exist - break out and go to error page Response.Redirect(String.Format("error.aspx?error={0}", 1001)); return; } // Delete the sproc sproc.Remove(); server.Disconnect(); // Redirect to info page Response.Redirect("storedprocedures.aspx?database=" + Server.UrlEncode(Request["database"])); } private void NoButton_Click(object sender, System.EventArgs e) { // Redirect to info page Response.Redirect("storedprocedures.aspx?database=" + Server.UrlEncode(Request["database"])); } } }