📄 deletecolumn.aspx.cs
字号:
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>
/// Summary description for DeleteColumn.
/// </summary>
public class DeleteColumn : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label ColumnNameLabel;
protected System.Web.UI.WebControls.Label TableNameLabel;
protected System.Web.UI.WebControls.Button YesButton;
protected System.Web.UI.WebControls.Button NoButton;
public DeleteColumn()
{
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");
TableNameLabel.Text = Server.HtmlEncode(Request["table"]);
ColumnNameLabel.Text = Server.HtmlEncode(Request["column"]);
}
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
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.YesButton.Click += new System.EventHandler(this.YesButton_Click);
this.NoButton.Click += new System.EventHandler(this.NoButton_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;
}
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;
}
if (table.Columns.Count == 1) {
server.Disconnect();
throw new Exception("Cannot delete last column from table. A table must contain at least one column.");
}
// Select column from table
SqlColumn column = table.Columns[Request["column"]];
if (column == null) {
server.Disconnect();
// Column doesn't exist - break out and go to error page
Response.Redirect(String.Format("error.aspx?error={0}", 1003));
return;
}
// Delete the sproc
column.Remove();
server.Disconnect();
// Redirect to info page
Response.Redirect(String.Format("columns.aspx?database={0}&table={1}", Server.UrlEncode(Request["database"]), Server.UrlEncode(Request["table"])));
}
private void NoButton_Click(object sender, System.EventArgs e) {
// Redirect to info page
Response.Redirect(String.Format("columns.aspx?database={0}&table={1}", Server.UrlEncode(Request["database"]), Server.UrlEncode(Request["table"])));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -