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 RenameTable. /// public class RenameTable : System.Web.UI.Page { protected System.Web.UI.WebControls.TextBox TableNameTextBox; protected System.Web.UI.WebControls.Button RenameButton; protected System.Web.UI.WebControls.Button CancelButton; protected System.Web.UI.WebControls.RequiredFieldValidator TableNameRequiredValidator; protected System.Web.UI.WebControls.Label ErrorCreatingLabel; public RenameTable() { Page.Init += new System.EventHandler(Page_Init); } private void Page_Load(object sender, System.EventArgs e) { ErrorCreatingLabel.Visible = false; HttpCookie cookie = Request.Cookies["WebDataAdministrator"]; if (cookie == null) Response.Redirect("default.aspx?error=sessionexpired"); if (!IsPostBack) TableNameTextBox.Text = Request["table"]; } 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.Load += new System.EventHandler(this.Page_Load); this.RenameButton.Click += new System.EventHandler(this.RenameButton_Click); this.CancelButton.Click += new System.EventHandler(this.CancelButton_Click); } #endregion private void RenameButton_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; } SqlTable table = database.Tables[Request["table"]]; if (table == null) { server.Disconnect(); // Table doesn't exist - break out and go to error page Response.Redirect(String.Format("error.aspx?error={0}", 1002)); return; } // Rename the table try { table.Name = TableNameTextBox.Text; // If successful, disconnect server.Disconnect(); // Redirect to info page Response.Redirect(String.Format("tables.aspx?database={0}", Server.UrlEncode(Request["database"]))); } catch (Exception ex) { ErrorCreatingLabel.Visible = true; ErrorCreatingLabel.Text = "There was an error renaming the table:
" + Server.HtmlEncode(ex.Message).Replace("\n", "
"); server.Disconnect(); } } private void CancelButton_Click(object sender, System.EventArgs e) { // Redirect to info page Response.Redirect(String.Format("tables.aspx?database={0}", Server.UrlEncode(Request["database"]))); } } }