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

📄 queskindmanage.aspx.cs

📁 用ASP.NET(C#)、SQL Server2000数据库开发在线考试系统源代码
💻 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 ExamineSystem
{
	/// <summary>
	/// Summary description for QuesKindManage.
	/// </summary>
	public class QuesKindManage : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.ListBox QuesKindList;
		protected System.Web.UI.WebControls.ImageButton upBtn;
		protected System.Web.UI.WebControls.ImageButton downBtn;
		protected System.Web.UI.WebControls.ImageButton editBtn;
		protected System.Web.UI.WebControls.ImageButton deleteBtn;
		protected System.Web.UI.WebControls.TextBox EditQuesKindName;
		protected System.Web.UI.WebControls.Button UpdateBtn;
		protected System.Web.UI.WebControls.Panel UpdatePanel;
		protected System.Web.UI.WebControls.TextBox QuesKindName;
		protected System.Web.UI.WebControls.Button AddQuesKind;
		protected System.Web.UI.HtmlControls.HtmlGenericControl title;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			///验证用户的权限
			if(Session["UserID"] == null)
			{
				Response.Redirect("~/Default.aspx");
			}
			
			

			if(!Page.IsPostBack)
			{
				BindQuesKindData();
			}

			deleteBtn.Attributes.Add("onclick","return confirm('你确定要删除所选择的页表吗?');");
		}

		private void BindQuesKindData()
		{
			QuesKindList.Items.Clear();

			QuestionKindDB tab = new QuestionKindDB();
			SqlDataReader rect = tab.GetQuesKinds();

			QuesKindList.DataSource = rect;
			QuesKindList.DataTextField = "KindName";
			QuesKindList.DataValueField = "KindID";
			QuesKindList.DataBind();

			rect.Close();
		}

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

			QuestionKindDB tab = new QuestionKindDB();

			try
			{
				tab.UpdateQuesKindName(Int32.Parse(QuesKindList.SelectedValue),EditQuesKindName.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"," "));
			}

			BindQuesKindData();		
		}

		private void AddQuesKind_Click(object sender, System.EventArgs e)
		{
			QuestionKindDB tab = new QuestionKindDB();

			try
			{
				tab.AddQuesKind(QuesKindName.Text.Trim(),QuesKindList.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"," "));
			}

			//增加成功后,重新绑定数据和清空名称输入框
			QuesKindName.Text = "";
			BindQuesKindData();

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

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

			if(QuesKindList.SelectedIndex > -1)
			{
				switch(commandName)
				{
					case "up":
					{
						if(QuesKindList.SelectedIndex > 0)
						{
							UpdateOrder(commandName);
						}

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

						break;
					}
					case "down":
					{
						if(QuesKindList.SelectedIndex < QuesKindList.Items.Count -1)
						{
							UpdateOrder(commandName);
						}

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

						break;
					}
					case "edit":
					{
						UpdateQuesKindName();

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

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

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

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

		private void UpdateOrder(String commandName)
		{
			QuestionKindDB tab = new QuestionKindDB();

			try
			{
				tab.UpdateQuesKindOrder(Int32.Parse(QuesKindList.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 UpdateQuesKindName()
		{
			UpdatePanel.Visible = true;		

			QuestionKindDB tab = new QuestionKindDB();
			SqlDataReader recd = tab.GetSingleQuesKind(Int32.Parse(QuesKindList.SelectedValue));

			while(recd.Read())
			{
				EditQuesKindName.Text = recd["KindName"].ToString();
			}
			recd.Close();
		}

		private void DeleteQuesKind()
		{
			QuestionKindDB tab = new QuestionKindDB();

			try
			{
				tab.DeleteQuesKind(Int32.Parse(QuesKindList.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;
			}
		}

		#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.AddQuesKind.Click += new System.EventHandler(this.AddQuesKind_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion
	}
}

⌨️ 快捷键说明

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