⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 channelmanage.aspx.cs

📁 这是一个管理系统的源码
💻 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 ChannelManage.
	/// </summary>
	public partial class ChannelManage : 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));
				}
			}

			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();
		}

		#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

		private void MoveEdit_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			String commandName = ((ImageButton)sender).CommandName;

			if(ChannelList.SelectedIndex > -1)
			{
				switch(commandName)
				{		
					case "edit":
					{
						UpdateChannelName();						

						break;
					}
					case "delete":
					{
						DeleteChannel();

						//控制更新Panel的可见性
						ControlUpdatePanelVisible();

						break;
					}
					default:
					{
						//控制更新Panel的可见性
						ControlUpdatePanelVisible();

						break;
					}
				}
				if(commandName == "delete")
				{				
					//重新绑定ChannelList的数据
					BindChannelData(Int32.Parse(DirectionList.SelectedValue));
				}
			}
			else
			{
				Response.Write("<script>alert(\"请选择你的数据项!\")</script>");
			}			
		}

		private void UpdateChannelName()
		{
			UpdatePanel.Visible = true;		

			ChannelDB channel = new ChannelDB();
			SqlDataReader recc = channel.GetSingleChannel(Int32.Parse(ChannelList.SelectedValue));

			while(recc.Read())
			{
				EditChannelName.Text = recc["ChannelName"].ToString();
			}
			recc.Close();
		}

		private void DeleteChannel()
		{
			ChannelDB channel = new ChannelDB();

			try
			{
				channel.DeleteChannel(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"," "));
			}
		}

		protected void UpdateBtn_Click(object sender, System.EventArgs e)
		{
			UpdatePanel.Visible = false;

			ChannelDB channel = new ChannelDB();

			if(IsExistEqualName(ChannelList,EditChannelName.Text.Trim()) == false)
			{
				try
				{
					channel.UpdateChannel(Int32.Parse(ChannelList.SelectedValue),EditChannelName.Text.Trim(),Int32.Parse(DirectionList.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"," "));
				}

				BindChannelData(Int32.Parse(DirectionList.SelectedValue));
			}
			else
			{
				Response.Write("<script>alert(\"添加数据项已经存在,请重新输入!\");</script>");
			}
		}

		protected void AddChannel_Click(object sender, System.EventArgs e)
		{	
			if(DirectionList.SelectedIndex > -1)
			{
				if(ChannelName.Text.Trim().Length > 0)
				{
					if(IsExistEqualName(ChannelList,ChannelName.Text.Trim()) == false)
					{
						ChannelDB channel = new ChannelDB();

						try
						{
							channel.AddChannel(ChannelName.Text.Trim(),Int32.Parse(DirectionList.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"," "));
						}

						//增加成功后,重新绑定数据和清空名称输入框
						ChannelName.Text = "";
						BindChannelData(Int32.Parse(DirectionList.SelectedValue));	
					}
					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));
			}
		}

		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);
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -