📄 subtopicmanage.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 System.Data.SqlClient;
namespace Service
{
/// <summary>
/// Summary description for SubtopicManage.
/// </summary>
public partial class SubtopicManage : System.Web.UI.Page
{
public String sOperation = "";
public String sLinkName = "";
protected void Page_Load(object sender, System.EventArgs e)
{
if(Session["UserID"] == null)
{
Response.Redirect("~/Default.aspx");
}
else
{
String sUserRoleName = UserDB.GetUserLoginRole(Int32.Parse(Session["UserID"].ToString()));
if(sUserRoleName.IndexOf("Admin") == -1)
{
Response.Redirect("~/Default.aspx");
}
}
if(!Page.IsPostBack)
{
BindDirectionData();
if(DirectionList.Items.Count > 0)
{
BindChannelData(Int32.Parse(DirectionList.SelectedValue));
}
if(ChannelList.Items.Count > 0)
{
BindTopicData(Int32.Parse(ChannelList.SelectedValue));
}
if(TopicList.Items.Count > 0)
{
BindSubTopicData(Int32.Parse(TopicList.SelectedValue));
}
}
deleteBtn.Attributes.Add("onclick","return confirm('你确定要删除所选择的问题吗?');");
if(Request.Params["LinkID"] != null)
{
GetLinkName(Request.Params["LinkID"].ToString());
}
}
private void GetLinkName(String sLinkID)
{
String[] aName = new String[2];
aName = GlobalVarables.GetLinkName(sLinkID);
if(GlobalVarables.aLinkName.Count > 0)
{
sOperation = aName[0].ToString();
sLinkName = aName[1].ToString();
}
}
private void BindDirectionData()
{
DirectionList.Items.Clear();
DirectionDB dir = new DirectionDB();
SqlDataReader recd = dir.GetDirections();
DirectionList.DataSource = recd;
DirectionList.DataTextField = "DirectionName";
DirectionList.DataValueField = "ID";
DirectionList.DataBind();
recd.Close();
}
private void BindChannelData(int nDirectionID)
{
ChannelList.Items.Clear();
ChannelDB channel = new ChannelDB();
SqlDataReader recc = channel.GetChannels(nDirectionID);
ChannelList.DataSource = recc;
ChannelList.DataTextField = "ChannelName";
ChannelList.DataValueField = "ID";
ChannelList.DataBind();
recc.Close();
}
private void BindTopicData(int nChannelID)
{
TopicList.Items.Clear();
TopicDB topic = new TopicDB();
SqlDataReader recc = topic.GetTopics(nChannelID);
TopicList.DataSource = recc;
TopicList.DataTextField = "TopicName";
TopicList.DataValueField = "ID";
TopicList.DataBind();
recc.Close();
}
private void BindSubTopicData(int nTopicID)
{
SubTopicList.Items.Clear();
SubTopicDB subtopic = new SubTopicDB();
SqlDataReader recs = subtopic.GetSubtopics(nTopicID);
SubTopicList.DataSource = recs;
SubTopicList.DataTextField = "SubTopicName";
SubTopicList.DataValueField = "ID";
SubTopicList.DataBind();
recs.Close();
}
private void MoveEdit_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
String commandName = ((ImageButton)sender).CommandName;
if(SubTopicList.SelectedIndex > -1)
{
switch(commandName)
{
case "edit":
{
UpdateSubTopicName();
break;
}
case "delete":
{
DeleteSubTopic();
//控制更新Panel的可见性
ControlUpdatePanelVisible();
break;
}
default:
{
//控制更新Panel的可见性
ControlUpdatePanelVisible();
break;
}
}
if(commandName == "delete")
{
//重新绑定SubTopicList的数据
BindSubTopicData(Int32.Parse(TopicList.SelectedValue));
}
}
else
{
Response.Write("<script>alert(\"请选择你的数据项!\")</script>");
}
}
private void UpdateSubTopicName()
{
UpdatePanel.Visible = true;
SubTopicDB subTopic = new SubTopicDB();
SqlDataReader recc = subTopic.GetSingleSubtopic(Int32.Parse(SubTopicList.SelectedValue));
while(recc.Read())
{
EditSubTopicName.Text = recc["SubTopicName"].ToString();
}
recc.Close();
}
private void DeleteSubTopic()
{
SubTopicDB subTopic = new SubTopicDB();
try
{
subTopic.DeleteSubTopic(Int32.Parse(SubTopicList.SelectedValue));
}
catch(Exception ex)
{
string sRawURL = Request.RawUrl;
if(sRawURL.IndexOf("?") > -1)
{
sRawURL = sRawURL.Substring(0,sRawURL.IndexOf("?"));
}
Response.Redirect("~/ManageSystem/ErrorPage.aspx?ErrorUrl=" + sRawURL + "&ErrorMessage=" + ex.Message.Replace("\n"," "));
}
}
protected void UpdateBtn_Click(object sender, System.EventArgs e)
{
UpdatePanel.Visible = false;
SubTopicDB subTopic = new SubTopicDB();
if(EditSubTopicName.Text.Length > 0)
{
if(IsExistEqualName(SubTopicList,EditSubTopicName.Text.Trim()) == false)
{
try
{
subTopic.UpdateSubTopic(Int32.Parse(SubTopicList.SelectedValue),EditSubTopicName.Text.Trim(),Int32.Parse(TopicList.SelectedValue));
}
catch(Exception ex)
{
string sRawURL = Request.RawUrl;
if(sRawURL.IndexOf("?") > -1)
{
sRawURL = sRawURL.Substring(0,sRawURL.IndexOf("?"));
}
Response.Redirect("~/ManageSystem/ErrorPage.aspx?ErrorUrl=" + sRawURL + "&ErrorMessage=" + ex.Message.Replace("\n"," "));
}
BindSubTopicData(Int32.Parse(TopicList.SelectedValue));
}
else
{
Response.Write("<script>alert(\"添加数据项已经存在,请重新输入!\");</script>");
}
}
else
{
Response.Write("<script>alert(\"主题的名称不能为空!\")</script>");
}
}
protected void AddSubTopic_Click(object sender, System.EventArgs e)
{
if(TopicList.SelectedIndex > -1)
{
SubTopicDB subTopic = new SubTopicDB();
if(SubTopicName.Text.Length > 0)
{
if(IsExistEqualName(SubTopicList,SubTopicName.Text.Trim()) == false)
{
try
{
subTopic.AddSubTopic(SubTopicName.Text.Trim(),Int32.Parse(TopicList.SelectedValue));
}
catch(Exception ex)
{
string sRawURL = Request.RawUrl;
if(sRawURL.IndexOf("?") > -1)
{
sRawURL = sRawURL.Substring(0,sRawURL.IndexOf("?"));
}
Response.Redirect("~/ManageSystem/ErrorPage.aspx?ErrorUrl=" + sRawURL + "&ErrorMessage=" + ex.Message.Replace("\n"," "));
}
//增加成功后,重新绑定数据和清空名称输入框
SubTopicName.Text = "";
BindSubTopicData(Int32.Parse(TopicList.SelectedValue));
}
else
{
Response.Write("<script>alert(\"添加数据项已经存在,请重新输入!\");</script>");
}
}
else
{
Response.Write("<script>alert(\"主题的名称不能为空!\")</script>");
}
}
else
{
Response.Write("<script>alert(\"添加数据错误,无上级目录,请在更高一级上重新添加!\")</script>");
}
//控制更新Panel的可见性
ControlUpdatePanelVisible();
}
protected void DirectionList_SelectedIndexChanged(object sender, System.EventArgs e)
{
if(DirectionList.Items.Count > 0)
{
BindChannelData(Int32.Parse(DirectionList.SelectedValue));
}
if(ChannelList.Items.Count > 0)
{
BindTopicData(Int32.Parse(ChannelList.SelectedValue));
}
else
{
TopicList.Items.Clear();
}
if(TopicList.Items.Count > 0)
{
BindSubTopicData(Int32.Parse(TopicList.SelectedValue));
}
else
{
SubTopicList.Items.Clear();
}
}
private void ControlUpdatePanelVisible()
{
if(UpdatePanel.Visible == true)
{
UpdatePanel.Visible = false;
}
}
private bool IsExistEqualName(ListBox listBox,String addText)
{
bool isExist = false;
if(listBox.Items.Count > 0)
{
for(int i = 0; i < listBox.Items.Count; i++)
{
if(listBox.Items[i].Text == addText)
{
isExist = true;
break;
}
}
}
return(isExist);
}
#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.editBtn.Click += new System.Web.UI.ImageClickEventHandler(this.MoveEdit_Click);
this.deleteBtn.Click += new System.Web.UI.ImageClickEventHandler(this.MoveEdit_Click);
}
#endregion
protected void ChannelList_SelectedIndexChanged(object sender, System.EventArgs e)
{
if(ChannelList.Items.Count > 0)
{
BindTopicData(Int32.Parse(ChannelList.SelectedValue));
}
if(TopicList.Items.Count > 0)
{
BindSubTopicData(Int32.Parse(TopicList.SelectedValue));
}
else
{
SubTopicList.Items.Clear();
}
}
protected void TopicList_SelectedIndexChanged(object sender, System.EventArgs e)
{
if(TopicList.Items.Count > 0)
{
BindSubTopicData(Int32.Parse(TopicList.SelectedValue));
}
else
{
SubTopicList.Items.Clear();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -