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

📄 directionmanage.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 DirectionManage.
	/// </summary>
	public partial class DirectionManage : 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();
			}

			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 Direction = new DirectionDB();
			SqlDataReader recr = Direction.GetDirections();

			DirectionList.DataSource = recr;
			DirectionList.DataTextField = "DirectionName";
			DirectionList.DataValueField = "ID";
			DirectionList.DataBind();

			recr.Close();
		}

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

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

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

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

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

						break;
					}
				}
				if(commandName == "delete")
				{
					BindDirectionData();
				}
			}
			else
			{
				Response.Write("<script>alert(\"请选择你的数据项!\")</script>");
			}			
		}

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

			DirectionDB direction = new DirectionDB();
			SqlDataReader recr = direction.GetSingleDirection(Int32.Parse(DirectionList.SelectedValue));

			while(recr.Read())
			{
				EditDirectionName.Text = recr["DirectionName"].ToString();
			}
			recr.Close();
		}

		private void DeleteDirection()
		{
			DirectionDB dir = new DirectionDB();

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

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

			DirectionDB direction = new DirectionDB();

			if(IsExistEqualName(DirectionList,EditDirectionName.Text.Trim()) == false)
			{
				try
				{
					direction.UpdateDirection(Int32.Parse(DirectionList.SelectedValue),EditDirectionName.Text.Trim());
				}
				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"," "));
				}

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

		protected void AddDirection_Click(object sender, System.EventArgs e)
		{
			DirectionDB direction = new DirectionDB();

			if(DirectionName.Text.Trim() != "")
			{
				if(IsExistEqualName(DirectionList,DirectionName.Text.Trim()) == false)
				{
					try
					{
						direction.AddDirection(DirectionName.Text.Trim());
					}
					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"," "));
					}

					//增加成功后,重新绑定数据和清空名称输入框
					DirectionName.Text = "";
					BindDirectionData();
				}
				else
				{
					Response.Write("<script>alert(\"添加数据项已经存在,请重新输入!\");</script>");
				}
			}
			else
			{
				Response.Write("<script>alert(\"报修的方向不能为空!\")</script>");
			}

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

		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.EditDeleteBtn_Click);
			this.deleteBtn.Click += new System.Web.UI.ImageClickEventHandler(this.EditDeleteBtn_Click);

		}
		#endregion
	}
}

⌨️ 快捷键说明

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