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

📄 main.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 OLTest
{
	/// <summary>
	/// Main 的摘要说明。
	/// </summary>
	public class Main : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.Label Label2;
		protected System.Web.UI.WebControls.Label Label3;
		protected System.Web.UI.WebControls.Label Label4;
		protected System.Web.UI.WebControls.Label Label5;
		protected System.Web.UI.WebControls.CheckBoxList CheckBoxList1;
		protected System.Web.UI.WebControls.RadioButtonList RadioButtonList1;
		DataSet ds;
		
		string RAnswer;
		
//        int[] UserAnswer={1,2,3,4};	
		protected System.Web.UI.WebControls.Button Button1;
		protected System.Web.UI.WebControls.Button Button2;
		protected System.Web.UI.WebControls.Button Button3;
		protected System.Web.UI.WebControls.Button Button4;
		protected System.Web.UI.WebControls.Label Label6;
		
		
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面\
			if (!Page.IsPostBack)
			{
				if(Session["uAnswer"].ToString()!="")
				{
					Review();
				}
			}
				
			   dbCon();
				RAnswer=ds.Tables[0].Rows[0]["Answer"].ToString();
			
			
				if (RAnswer.Trim().Length==1)
				{
					RadioButtonList1.Visible=true;
					CheckBoxList1.Visible=false;
				
				}
				else
				{
					RadioButtonList1.Visible=false;
					CheckBoxList1.Visible=true;
				
				}	

				Label1.Text=(Convert.ToInt32(Session["Current"])+1).ToString()+"."+ds.Tables[0].Rows[0]["Quest"].ToString();
			    Label2.Text=ds.Tables[0].Rows[0]["A"].ToString();
				Label3.Text=ds.Tables[0].Rows[0]["B"].ToString();
				Label4.Text=ds.Tables[0].Rows[0]["C"].ToString();
				Label5.Text=ds.Tables[0].Rows[0]["D"].ToString();
			    Label6.Text=Session["uAnswer"].ToString();

//				for (int i=0;i<=3;i++)
//				{
//					Random r=new Random();
//					int b=r.Next(3);
//					int c=UserAnswer[i];
//					UserAnswer[i]=UserAnswer[b];
//					UserAnswer[b]=c;
//				}	
//			    Label2.Text=ds.Tables[0].Rows[0][(UserAnswer[0]+1)].ToString();
//				Label3.Text=ds.Tables[0].Rows[0][(UserAnswer[1]+1)].ToString();
//				Label4.Text=ds.Tables[0].Rows[0][(UserAnswer[2]+1)].ToString();
//				Label5.Text=ds.Tables[0].Rows[0][(UserAnswer[3]+1)].ToString();			          

		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.Button1.Click += new System.EventHandler(this.Button1_Click);
			this.Button2.Click += new System.EventHandler(this.Button2_Click);
			this.Button3.Click += new System.EventHandler(this.Button3_Click);
			this.Button4.Click += new System.EventHandler(this.Button4_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion
		public void dbCon()
		{
	       string[] CurNum=Session["Num"].ToString().Split(',');
			int Cur=Convert.ToInt32(CurNum[Convert.ToInt32(Session["Current"])]);
			string cn="server=.;uid=sa;database=nTest";
	        SqlDataAdapter da=new SqlDataAdapter("select * from Question where Num="+Cur,cn);
			ds=new DataSet();
			da.Fill(ds);		
         
		}

		public void Review()
		{
		 
			string[] GetCNum=Session["uAnswer"].ToString().TrimEnd(',').Split(',');
			
			if (GetCNum.GetLength(0)>=(Convert.ToInt32(Session["Current"])+1))
			{ 
				if (GetCNum[Convert.ToInt32(Session["Current"])].ToString().Length==1)
				{
					if (GetCNum[Convert.ToInt32(Session["Current"])]=="A")
					{
						RadioButtonList1.Items[0].Selected=true;
					}
					if (GetCNum[Convert.ToInt32(Session["Current"])]=="B")
					{
						RadioButtonList1.Items[1].Selected=true;
					}
					if (GetCNum[Convert.ToInt32(Session["Current"])]=="C")
					{
						RadioButtonList1.Items[2].Selected=true;
					}
					if (GetCNum[Convert.ToInt32(Session["Current"])]=="D")
					{
						RadioButtonList1.Items[3].Selected=true;
					}
				}
				else
				{
				       string tempCode=GetCNum[Convert.ToInt32(Session["Current"])].ToString();
//					 Char[] a=tempCode.ToCharArray(0,2);
					
						if (tempCode.StartsWith("A"))
						{
							CheckBoxList1.Items[0].Selected=true;
						}
						if (tempCode.EndsWith("B")||tempCode.StartsWith("B"))
						{
							CheckBoxList1.Items[1].Selected=true;
						}
						if (tempCode.EndsWith("C")||tempCode.StartsWith("C"))
						{
							CheckBoxList1.Items[2].Selected=true;
						}
						if (tempCode.EndsWith("D"))
						{
							CheckBoxList1.Items[3].Selected=true;
						}
					
				}

			}

		}
		public int CheckFin()
		{
			int ChkResult=0;
			if ((RadioButtonList1.Items[0].Selected)||(RadioButtonList1.Items[1].Selected)||(RadioButtonList1.Items[2].Selected)||(RadioButtonList1.Items[3].Selected)||(CheckBoxList1.Items[0].Selected)||(CheckBoxList1.Items[1].Selected)||(CheckBoxList1.Items[2].Selected)||(CheckBoxList1.Items[3].Selected))
			{
			 ChkResult=1;
			}
			else
			{
			 ChkResult=0;
			}
			return ChkResult;
		
		}
		public string GetSAnswer()
		{

			string UAnswer="";

            
			if (RadioButtonList1.Items[0].Selected)
			{
				UAnswer="A";
				
			}
			if (RadioButtonList1.Items[1].Selected)
			{
				UAnswer="B";
				
			}
			if (RadioButtonList1.Items[2].Selected)
			{
				UAnswer="C";
				
			}
			if (RadioButtonList1.Items[3].Selected)
			{
				UAnswer="D";
				
			}

			return UAnswer;
		}
		public string GetMAnswer()
		{
			
			string UAnswer="";
				if (CheckBoxList1.Items[0].Selected)
				{
					UAnswer=UAnswer+"A";
				}
				if (CheckBoxList1.Items[1].Selected)
				{
					UAnswer=UAnswer+"B";
				}
				if (CheckBoxList1.Items[2].Selected)
				{
					UAnswer=UAnswer+"C";
				}
				if (CheckBoxList1.Items[3].Selected)
				{
					UAnswer=UAnswer+"D";
				}
//				UAnswer=UAnswer.TrimEnd(',');

//				string[] tempA=UAnswer.Split(',');
//				if (Convert.ToInt32(tempA[0])>Convert.ToInt32(tempA[1]))
//				{
//					int Change=Convert.ToInt32(tempA[0]);
//					tempA[0]=tempA[1];
//					tempA[1]=Change.ToString();
//				
//				}
//				for (int i=0;i<=1;i++)
//				{
//					switch (Convert.ToInt32(tempA[i]))
//					{
//						case 1:
//							tempA[i]="A";
//							break;
//						case 2:
//							tempA[i]="B";
//							break;
//						case 3:
//							tempA[i]="C";
//							break;
//						case 4:
//							tempA[i]="D";
//							break;
//					}
//				}
//				UAnswer=tempA[0]+tempA[1];
			
			return UAnswer;
		}

		public void getUserAnswer()
		{
			if(RAnswer.TrimEnd().Length==1)
			{
				
				string[] tempUA=Session["uAnswer"].ToString().Split(',');
				tempUA[Convert.ToInt32(Session["Current"])]=GetSAnswer();
				Session["uAnswer"]="";
				for (int i=0;i<tempUA.GetLength(0);i++)
				{
					Session["uAnswer"]=Session["uAnswer"].ToString()+tempUA[i]+",";
				}
				if(Convert.ToInt32(Session["Current"])==9)
				{
					Session["uAnswer"].ToString().TrimEnd(',');
				}
						
			}
			else
			{

				string[] tempUA=Session["uAnswer"].ToString().Split(',');
				tempUA[Convert.ToInt32(Session["Current"])]=GetMAnswer();
				Session["uAnswer"]="";
				for (int i=0;i<tempUA.GetLength(0);i++)
				{
					Session["uAnswer"]=Session["uAnswer"].ToString()+tempUA[i]+",";
				}
				if(Convert.ToInt32(Session["Current"])==9)
				{
					Session["uAnswer"].ToString().TrimEnd(',');
				}
			}

				 
		}

		private void Button1_Click(object sender, System.EventArgs e)
		{
			if (Convert.ToInt32(Session["Current"])==0)
			{
				Label6.Text="到达试卷顶端!";
			}
			else
			{
				if (CheckFin()==0)
				{
					Label6.Text="请先完成该题!";
				}
				else
				{
					getUserAnswer();
					
					Session["Current"]=Convert.ToInt32(Session["Current"])-1;
					
					this.Response.Redirect("Main.aspx");

				}
			}
		}

		private void Button2_Click(object sender, System.EventArgs e)
		{
			if (Convert.ToInt32(Session["Current"])==9)
			{
				getUserAnswer();
				this.Response.Redirect("OverLook.aspx");
			}
			else
			{
				if (CheckFin()==0)
				{
					Label6.Text="请先完成该题!";
				}
				else
				{
					getUserAnswer();
					
					Session["Current"]=Convert.ToInt32(Session["Current"])+1;
                   					
					this.Response.Redirect("Main.aspx");

				}
			}
		}

		private void Button3_Click(object sender, System.EventArgs e)
		{
			this.Response.Redirect("OverLook.aspx");
		}

		private void Button4_Click(object sender, System.EventArgs e)
		{
			string tempS="";
			string[] tempSign=Session["Sign"].ToString().Split(',');
			tempSign[Convert.ToInt32(Session["Current"])]=1.ToString();
			for (int i=0;i<=9;i++)
			{
			 tempS=tempS+tempSign[i]+",";
			}
			Session["Sign"]=tempS.TrimEnd(',');
	
		}
		
		
		
		
	}


	}

⌨️ 快捷键说明

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