📄 topicmanage.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 TopicManage.
/// </summary>
public partial class TopicManage : 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));
}
}
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 MoveEdit_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
String commandName = ((ImageButton)sender).CommandName;
if(TopicList.SelectedIndex > -1)
{
switch(commandName)
{
case "edit":
{
UpdateTopicName();
break;
}
case "delete":
{
DeleteTopic();
//控制更新Panel的可见性
ControlUpdatePanelVisible();
break;
}
default:
{
//控制更新Panel的可见性
ControlUpdatePanelVisible();
break;
}
}
if(commandName == "delete")
{
//重新绑定TopicList的数据
BindTopicData(Int32.Parse(ChannelList.SelectedValue));
}
}
else
{
Response.Write("<script>alert(\"请选择你的数据项!\")</script>");
}
}
private void UpdateTopicName()
{
UpdatePanel.Visible = true;
TopicDB topic = new TopicDB();
SqlDataReader recc = topic.GetSingleTopic(Int32.Parse(TopicList.SelectedValue));
while(recc.Read())
{
EditTopicName.Text = recc["TopicName"].ToString();
}
recc.Close();
}
private void DeleteTopic()
{
TopicDB topic = new TopicDB();
try
{
topic.DeleteTopic(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"," "));
}
}
protected void UpdateBtn_Click(object sender, System.EventArgs e)
{
UpdatePanel.Visible = false;
TopicDB topic = new TopicDB();
if(EditTopicName.Text.Length > 0)
{
if(IsExistEqualName(TopicList,EditTopicName.Text.Trim()) == false)
{
try
{
topic.UpdateTopic(Int32.Parse(TopicList.SelectedValue),EditTopicName.Text.Trim(),Int32.Parse(ChannelList.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"," "));
}
BindTopicData(Int32.Parse(DirectionList.SelectedValue));
}
else
{
Response.Write("<script>alert(\"添加数据项已经存在,请重新输入!\");</script>");
}
}
else
{
Response.Write("<script>alert(\"栏目的名称不能为空!\")</script>");
}
}
protected void AddTopic_Click(object sender, System.EventArgs e)
{
if(ChannelList.SelectedIndex > -1)
{
TopicDB topic = new TopicDB();
if(TopicName.Text.Trim().Length > 0)
{
if(IsExistEqualName(TopicList,TopicName.Text.Trim()) == false)
{
try
{
topic.AddTopic(TopicName.Text.Trim(),Int32.Parse(ChannelList.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"," "));
}
//增加成功后,重新绑定数据和清空名称输入框
TopicName.Text = "";
BindTopicData(Int32.Parse(ChannelList.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.SelectedIndex > -1)
{
BindTopicData(Int32.Parse(ChannelList.SelectedValue));
}
else
{
TopicList.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));
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -