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

📄 question.cs

📁 本论文叙述了联机考试系统的现状以及C#语言的概况。重点介绍了联机考试系统的实现过程:包括系统分析、 系统调查、 数据流程分析、功能设计、 数据库设计、 系统物理配置方案、 系统实现、 系统测试和调试。
💻 CS
字号:
using System;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;


namespace OES
{
	/// <summary>
	/// Summary description for Question.
	/// </summary>
	public class Question
	{
		private int CountRec;
		private int CountQ;
		private OleDbDataReader reader;
		
		public Question()
		{
			//
			// TODO: Add constructor logic here
			//
		}

		
		public void UpdateQuestions(DataTable dtQuestions)
		{
			try
			{ 	
				//for every row in the dataset that was sent 
				//as a parameter, perform an update 
				//into the table	
				foreach(DataRow drQuest in dtQuestions.Rows)
				{
					DataAccess.sql="Update tbl_QuestionBank Set " +							 " Question='" +
						drQuest[3] + "', OptionA='" +
						drQuest[4] + "', OptionB='" +
						drQuest[5] + "', OptionC='" +
						drQuest[6] + "',OptionD='" +
						drQuest[7] + "',CorrectAns='" +
						drQuest[8] + "' where QNumber=" +drQuest[0];

					DataAccess.command.CommandText = DataAccess.sql;
					DataAccess.command.ExecuteNonQuery ();
				}
		
			}
			catch(OleDbException excep)
			{
				Console.WriteLine ("Exception occured: "+excep.Message);   
			}
		}

		//修改情况:部门:ACCP产品开发培训部   修改人:王文  时间:2004-12-26
		public void InsertQuestion(DataRow drQuestion)
		{
			try
			{ 
				Console.WriteLine ("The value is "+drQuestion["SubjectCode"]);
				//to increment the overall question numbers
				DataAccess.command.CommandText = "SELECT max(QNumber)from tbl_QuestionBank";

				reader = DataAccess.command.ExecuteReader(); 
				reader.Read();
				if(! reader.IsDBNull(0)) 
					this.CountQ = reader.GetInt32(0);
				else
					this.CountQ = 1;
	
				reader.Close ();
				drQuestion["QNumber"]=this.CountQ + 1;
				Console.WriteLine("Countq=" + (this.CountQ + 1));

				DataAccess.sql="Insert into tbl_QuestionBank values("+drQuestion["QNumber"] + ",'"+
					drQuestion["SubjectCode"]+ "',"+
					drQuestion["QuestNo"]+ ",'" +
					drQuestion["Question"] + "','" +
					drQuestion["OptionA"]+"','"+
					drQuestion["OptionB"]+"','"+
					drQuestion["OptionC"]+"','"+
					drQuestion["OptionD"]+"','"+
					drQuestion["CorrectAns"]+"')";


				Console.WriteLine(DataAccess.sql);
				DataAccess.command.CommandText=DataAccess.sql;
				DataAccess.command.ExecuteNonQuery ();
				//除去Console.WriteLine("added");
				//除去Console.WriteLine(CountQ);

				
				////除去System.Windows.Forms.MessageBox.Show("done");
			}
			catch(OleDbException excep)
			{
				Console.WriteLine ("Exception occured"+excep.Message);   
			}

		}


		public int  GenerateQuestionNo(string Subject)
		{
			DataAccess.command.CommandText = "SELECT max(QuestNo)from tbl_QuestionBank where SubjectCode in(Select SubjectCode from tbl_SubjectMaster where Description='" +Subject+ "')";

			reader = DataAccess.command.ExecuteReader(); 
			reader.Read();
			if(! reader.IsDBNull(0)) 
				this.CountRec = reader.GetInt32(0);
				
			else
				this.CountRec = 0;

			this.CountRec += 1; //auto calculate Question no
			
			reader.Close ();
			return CountRec;
		}


		//修改情况:部门:ACCP产品开发培训部   修改人:王文  时间:2004-12-25
		public DataTable FetchQuestions(string[] searchValue)
		{
			string str = string.Empty;
			
			if (searchValue.Length==1) //此条件用于frmQuestion的构造函数中
			{
				str = "select * from tbl_QuestionBank where QNumber=" +searchValue[0];
			}
			 //此条件用于frmQuestionSearch.btnSearch_Click方法中
			else  
			{
				//code to return questions of a subject for the specified zero or 
				//more keywords	 for question field of QuestionBank table

				string[] strKeywords = null;//new string[3];

				char  [] splitchar   = {','};

				if (searchValue[1] != string.Empty)
				{
					strKeywords=searchValue[1].Split(splitchar);
				}

				//所添加的CODES
				str = "select * from tbl_QuestionBank where ";
				
				if(searchValue[1] != string.Empty) //subject name is not null
				{
					for(int index = 0;index < strKeywords.Length; index++)
					{
						if(index == 0)
							str += "(Question like '%" + strKeywords[index].Trim() + "%'";
						else
							str +=" or Question like  '%" + strKeywords[index].Trim()  + "%' ";
					}
					str+=")";
					if(searchValue[0] != "")
					{
						str += " and ";
					}					
				}
				//所添加的CODES
				if(searchValue[0] != string.Empty) 
				{
					///除去str += "SubjectCode in (select SubjectCode from tbl_SubjectMaster where Description='" + searchValue[0] +" ')";
					str += "SubjectCode ='" + searchValue[0] +" '";
				}
			
			}
				
			DataAccess.oleAdapter= new OleDbDataAdapter(str,DataAccess.oleconn);
			DataAccess.dSet      = new DataSet("tbl_QuestionBank");
			DataAccess.oleAdapter.Fill(DataAccess.dSet,"tbl_QuestionBank");

			return DataAccess.dSet.Tables[0]; 

		}
	}
}

⌨️ 快捷键说明

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