📄 tabmanage.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
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 System.Configuration;
namespace ComputerWeb
{
/// <summary>
/// Summary description for ManageChannel.
/// </summary>
public class ManageChannel : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox DirectUrl;
protected System.Web.UI.WebControls.CheckBox DirectCheck;
protected System.Web.UI.WebControls.ListBox TabList;
protected System.Web.UI.WebControls.ImageButton editBtn;
protected System.Web.UI.WebControls.ImageButton deleteBtn;
protected System.Web.UI.WebControls.TextBox EditTabName;
protected System.Web.UI.WebControls.Button UpdateBtn;
protected System.Web.UI.WebControls.Panel UpdatePanel;
protected System.Web.UI.WebControls.TextBox TabName;
protected System.Web.UI.WebControls.Button AddTab;
protected System.Web.UI.WebControls.ImageButton upBtn;
protected System.Web.UI.WebControls.ImageButton downBtn;
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
BindTabData();
}
deleteBtn.Attributes.Add("onclick","return confirm('你确定要删除所选择的页表吗?');");
}
private void BindTabData()
{
TabList.Items.Clear();
TabDB tab = new TabDB();
SqlDataReader rect = tab.GetTabs();
TabList.DataSource = rect;
TabList.DataTextField = "TabName";
TabList.DataValueField = "TabID";
TabList.DataBind();
rect.Close();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.upBtn.Click += new System.Web.UI.ImageClickEventHandler(this.MoveEdit_Click);
this.downBtn.Click += new System.Web.UI.ImageClickEventHandler(this.MoveEdit_Click);
this.editBtn.Click += new System.Web.UI.ImageClickEventHandler(this.MoveEdit_Click);
this.deleteBtn.Click += new System.Web.UI.ImageClickEventHandler(this.MoveEdit_Click);
this.UpdateBtn.Click += new System.EventHandler(this.UpdateBtn_Click);
this.AddTab.Click += new System.EventHandler(this.AddTab_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void UpdateBtn_Click(object sender, System.EventArgs e)
{
UpdatePanel.Visible = false;
TabDB tab = new TabDB();
try
{
tab.UpdateTabName(Int32.Parse(TabList.SelectedValue),EditTabName.Text.Trim());
}
catch(Exception ex)
{
string sRawURL = Request.RawUrl;
if(sRawURL.IndexOf("?") > -1)
{
sRawURL = sRawURL.Substring(0,sRawURL.IndexOf("?"));
}
Response.Redirect("~/DesktopModules/ErrorPage.aspx?ErrorUrl=" + sRawURL + "&ErrorMessage=" + ex.Message.Replace("\n"," "));
}
BindTabData();
}
private void AddTab_Click(object sender, System.EventArgs e)
{
TabDB tab = new TabDB();
try
{
if(DirectCheck.Checked == true)
{
tab.AddTab(TabName.Text.Trim(),TabList.Items.Count + 1,DirectUrl.Text);
}
else
{
tab.AddTab(TabName.Text.Trim(),TabList.Items.Count + 1,"");
}
}
catch(Exception ex)
{
string sRawURL = Request.RawUrl;
if(sRawURL.IndexOf("?") > -1)
{
sRawURL = sRawURL.Substring(0,sRawURL.IndexOf("?"));
}
Response.Redirect("~/DesktopModules/ErrorPage.aspx?ErrorUrl=" + sRawURL + "&ErrorMessage=" + ex.Message.Replace("\n"," "));
}
//增加成功后,重新绑定数据和清空名称输入框
TabName.Text = "";
DirectUrl.Text = "";
DirectCheck.Checked = false;
BindTabData();
//控制更新Panel的可见性
ControlUpdatePanelVisible();
}
private void MoveEdit_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
String commandName = ((ImageButton)sender).CommandName;
if(TabList.SelectedIndex > -1)
{
switch(commandName)
{
case "up":
{
if(TabList.SelectedIndex > 0)
{
UpdateOrder(commandName);
}
//控制更新Panel的可见性
ControlUpdatePanelVisible();
break;
}
case "down":
{
if(TabList.SelectedIndex < TabList.Items.Count -1)
{
UpdateOrder(commandName);
}
//控制更新Panel的可见性
ControlUpdatePanelVisible();
break;
}
case "edit":
{
UpdateTabName();
break;
}
case "delete":
{
DeleteTab();
//控制更新Panel的可见性
ControlUpdatePanelVisible();
break;
}
default:
{
//控制更新Panel的可见性
ControlUpdatePanelVisible();
break;
}
}
if((commandName != "")&&(commandName != "edit"))
{
BindTabData();
}
}
else
{
Response.Write("<script>alert(\"请选择你的数据项!\")</script>");
}
}
private void UpdateOrder(String commandName)
{
TabDB tab = new TabDB();
try
{
tab.UpdateTabOrder(Int32.Parse(TabList.SelectedValue),commandName);
}
catch(Exception ex)
{
string sRawURL = Request.RawUrl;
if(sRawURL.IndexOf("?") > -1)
{
sRawURL = sRawURL.Substring(0,sRawURL.IndexOf("?"));
}
Response.Redirect("~/DesktopModules/ErrorPage.aspx?ErrorUrl=" + sRawURL + "&ErrorMessage=" + ex.Message.Replace("\n"," "));
}
}
private void UpdateTabName()
{
UpdatePanel.Visible = true;
if(TabList.SelectedIndex > -1)
{
EditTabName.Text = TabList.SelectedItem.Text;
}
else
{
Response.Write("<script>alert(\"请选择你的数据项!\")</script>");
}
}
private void DeleteTab()
{
TabDB tab = new TabDB();
try
{
tab.DeleteTab(Int32.Parse(TabList.SelectedValue));
}
catch(Exception ex)
{
string sRawURL = Request.RawUrl;
if(sRawURL.IndexOf("?") > -1)
{
sRawURL = sRawURL.Substring(0,sRawURL.IndexOf("?"));
}
Response.Redirect("~/DesktopModules/ErrorPage.aspx?ErrorUrl=" + sRawURL + "&ErrorMessage=" + ex.Message.Replace("\n"," "));
}
}
private void ControlUpdatePanelVisible()
{
if(UpdatePanel.Visible == true)
{
UpdatePanel.Visible = false;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -