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

📄 frmexam.cs

📁 本论文叙述了联机考试系统的现状以及C#语言的概况。重点介绍了联机考试系统的实现过程:包括系统分析、 系统调查、 数据流程分析、功能设计、 数据库设计、 系统物理配置方案、 系统实现、 系统测试和调试。
💻 CS
📖 第 1 页 / 共 2 页
字号:
			// 
			// btnSave
			// 
			this.btnSave.BackColor = System.Drawing.Color.Transparent;
			this.btnSave.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
			this.btnSave.Font = new System.Drawing.Font("Verdana", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnSave.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
			this.btnSave.Location = new System.Drawing.Point(200, 424);
			this.btnSave.Name = "btnSave";
			this.btnSave.Size = new System.Drawing.Size(96, 26);
			this.btnSave.TabIndex = 45;
			this.btnSave.Text = "创建(&C)";
			this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
			// 
			// lblMarks
			// 
			this.lblMarks.AutoSize = true;
			this.lblMarks.BackColor = System.Drawing.Color.Transparent;
			this.lblMarks.Font = new System.Drawing.Font("Century Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.lblMarks.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
			this.lblMarks.Location = new System.Drawing.Point(288, 190);
			this.lblMarks.Name = "lblMarks";
			this.lblMarks.Size = new System.Drawing.Size(18, 18);
			this.lblMarks.TabIndex = 49;
			this.lblMarks.Text = "10";
			// 
			// btnHelp
			// 
			this.btnHelp.BackColor = System.Drawing.Color.Transparent;
			this.btnHelp.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
			this.btnHelp.Font = new System.Drawing.Font("Verdana", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnHelp.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
			this.btnHelp.Location = new System.Drawing.Point(616, 25);
			this.btnHelp.Name = "btnHelp";
			this.btnHelp.Size = new System.Drawing.Size(72, 26);
			this.btnHelp.TabIndex = 50;
			this.btnHelp.Text = "帮助(&H)";
			this.btnHelp.Click += new System.EventHandler(this.btnHelp_Click);
			// 
			// cboNumofQuestions
			// 
			this.cboNumofQuestions.BackColor = System.Drawing.SystemColors.Info;
			this.cboNumofQuestions.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboNumofQuestions.Items.AddRange(new object[] {
																   "10",
																   "20",
																   "25",
																   "50"});
			this.cboNumofQuestions.Location = new System.Drawing.Point(557, 155);
			this.cboNumofQuestions.Name = "cboNumofQuestions";
			this.cboNumofQuestions.Size = new System.Drawing.Size(134, 20);
			this.cboNumofQuestions.TabIndex = 51;
			this.cboNumofQuestions.SelectedIndexChanged += new System.EventHandler(this.cboNumofQuestions_SelectedIndexChanged);
			// 
			// label1
			// 
			this.label1.AutoSize = true;
			this.label1.BackColor = System.Drawing.Color.Transparent;
			this.label1.Font = new System.Drawing.Font("Century Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label1.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
			this.label1.Location = new System.Drawing.Point(595, 302);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(32, 18);
			this.label1.TabIndex = 52;
			this.label1.Text = "分钟";
			// 
			// errExam
			// 
			this.errExam.ContainerControl = this;
			// 
			// frmExam
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
			this.ClientSize = new System.Drawing.Size(783, 520);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.lblMarks);
			this.Controls.Add(this.lblMarksperQuestion);
			this.Controls.Add(this.txtExamTitle);
			this.Controls.Add(this.lblExamTitle);
			this.Controls.Add(this.txtExamCode);
			this.Controls.Add(this.lblSubject);
			this.Controls.Add(this.lblNumberOfQuestion);
			this.Controls.Add(this.lblExamCode);
			this.Controls.Add(this.lblCreateExam);
			this.Controls.Add(this.cboNumofQuestions);
			this.Controls.Add(this.btnHelp);
			this.Controls.Add(this.btnClose);
			this.Controls.Add(this.btnSave);
			this.Controls.Add(this.grpPersonalDetails);
			this.Controls.Add(this.cboSubject);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
			this.Location = new System.Drawing.Point(146, 115);
			this.Name = "frmExam";
			this.ShowInTaskbar = false;
			this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
			this.Text = "frmExam";
			this.TopMost = true;
			this.Load += new System.EventHandler(this.frmExam_Load);
			this.grpPersonalDetails.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void btnClose_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private bool syntaxCheck()
		{
			if (this.txtExamTitle.Text.Trim().Length == 0)
			{
				MessageBox.Show("考试标题不能为空!");
				this.txtExamTitle.Focus();
				return false;
			}
			if (this.cboNumofQuestions.Text.Trim().Length == 0)
			{
				MessageBox.Show("试题数目不能为空!");
				this.cboNumofQuestions.Focus();
				return false;
			}
			if (this.txtScheduledAt.Text.Trim().Length == 0)
			{
				MessageBox.Show("预定考试不能为空!");
				this.txtScheduledAt.Focus();
				return false;
			}
			try
			{
				DateTime.Parse(this.txtScheduledAt.Text.Trim());
			}
			catch(Exception)
			{
				
				MessageBox.Show("预定时间格式应该为 ##:## !");
				this.txtScheduledAt.Focus();
				return false;
			}
			if (this.txtDuration.Text.Trim().Length == 0)
			{
				MessageBox.Show("持续时间不能为空!");
				this.txtDuration.Focus();
				return false;
			}
			if (chkNum(this.txtDuration.Text.Trim()) == false)
			{
				MessageBox.Show("持续时间应该为数字!");
				this.txtDuration.Focus();
				return false;
			}
			int duration;
			try
			{
				duration=Convert.ToInt32(this.txtDuration.Text.Trim());
			}
			catch(Exception)
			{
				MessageBox.Show("持续时间应该为数字!");
				//this.txtDuration.Focus();
				this.txtDuration.SelectAll();
				return false;
			}
			if ( (duration<1)||(duration>180))
			{
				MessageBox.Show("持续时间应该为 1-180 分钟!");
				this.txtDuration.Focus();
				return false;
			}
			return true;
		}
		private void btnSave_Click(object sender, System.EventArgs e)
		{
			//Modify by DongPing on 2004-12-25
			//if (this.txtScheduledAt.Text.Trim().Length == 0)
			//{
			//	errorMsg = ("Scheduled Time cannot be empty. Please enter valid value");

			//	this.errExam.SetError(this.txtScheduledAt, errorMsg);
			//	this.btnSave.Enabled=false;
			//	this.txtScheduledAt.Focus();
			//}
			
			if (syntaxCheck()==true)
			{
				//this.errExam.SetError(txtScheduledAt, "");	Modify by dongping 2004-12-25			
				
				//call CreateTable to create a temporary table
				CreateTable();

				Exam objExam =new Exam();
			
				//add a new row to the temporary table
				DataRow drExam=dtExam.NewRow();

				drExam["ExamCode"]=this.txtExamCode.Text;
				drExam["SubjectCode"]=this.cboSubject.Text;
				drExam["ExamTitle"]=this.txtExamTitle.Text;
				int num=Convert.ToInt32(this.cboNumofQuestions.Text);
				drExam["TotalQuest"]=num;
				drExam["ScheduledOn"]=this.dtpSchedule.Value.ToString("dd/MM/yyyy");
				drExam["ScheduledTime"]=this.txtScheduledAt.Text;
				drExam["Duration"]=this.txtDuration.Text;

				//call create exam of the exam class
				

				//MessageBox.Show("The exam has been successfully created");

			
				//call GenerateTestPaper to generate a paper for the exam and
				//store it in the TestPaper table

				bool result;
				DataAccess objDA=DataAccess.GetInstance ();
				result=objExam.GenerateTestPaper(this.txtExamCode.Text,this.cboSubject.Text,Convert.ToInt32(cboNumofQuestions.Text));
				if(result)
				{
					objExam.CreateExam(drExam);

					MessageBox.Show("已成功创建考试");
					MessageBox.Show("已成功生成试卷");
				}
				else
				{
					MessageBox.Show("由于试题数目不够不能生成试卷,请为该科目添加试题");
					MessageBox.Show("考试尚未创建");
				}

				this.Close();

			}
		}

		
		public void CreateTable()
		{
			dtExam = new DataTable("tbl_Exams");
			DataColumn pKeyCol = dtExam.Columns.Add("ExamCode",  typeof(String));
			pKeyCol.AllowDBNull = false;
			pKeyCol.Unique = true;
			dtExam.Columns.Add("SubjectCode", typeof(String));
			dtExam.Columns.Add("ScheduledOn", typeof(String));
			dtExam.Columns.Add("ScheduledTime", typeof(String));
			
			dtExam.Columns.Add("TotalQuest", typeof(Int32));
			dtExam.Columns.Add("ExamTitle", typeof(String));
			
			dtExam.Columns.Add("Duration", typeof(String));
		}


		private void cboNumofQuestions_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			//call a function to display the marks per question based on the
			//number of questions selected
			DisplayMarks(this.cboNumofQuestions.Text);
		}

		public void DisplayMarks(string questSelected)
		{
			int quest=Convert.ToInt32(questSelected);
			int mksPerQuest=100/quest;
			lblMarks.Text=mksPerQuest.ToString();
			
		}

		private void cboSubject_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			Exam objExam=new Exam();			

			//call a method from the Exam class to generate the exam code 
			//based on the subject selected
			this.txtExamCode.Text= objExam.GenerateExamCode(this.cboSubject.Text);
			btnSave.Enabled=true;
		}

		
		private void dtpSchedule_ValueChanged(object sender, System.EventArgs e)
		{
			//validate date entered
			if (dtpSchedule.Value <=DateTime.Now)
			{
				MessageBox.Show("选定的日期无效...请选择将来的日期");
			}
		}

		//	private void txtDuration_Leave(object sender, System.EventArgs e)
		//	{
		//		//validate duration entered - call a method to check if number
		//		if ((this.txtDuration.Text.Trim().Length == 0) || (! this.chkNum(this.///txtDuration.Text)))
		//	{
		//	errorMsg = ("Duration cannot be empty or non-numeric. Please Enter valid value");

		///	this.errExam.SetError(this.txtDuration, errorMsg);
		//	this.txtDuration.Focus();
		//	}
		//	else
		//		this.errExam.SetError(txtDuration, "");
		//	}

		private bool chkNum(string str)
		{
			for(int i=0; i<str.Length;i++)
			{
				if(! Char.IsNumber(str,i))
				{
					return false;
				}
			}
			return true;
		}
		//		private void txtExamTitle_Leave(object sender, System.EventArgs e)
		//		{
		//			if (this.txtExamTitle.Text.Trim().Length == 0)
		//			{
		//				errorMsg = ("Title cannot be empty. Please Enter valid value");
		//				this.errExam.SetError(this.txtExamTitle, errorMsg);
		//				this.txtExamTitle.Focus();
		//			}
		//			else
		//			{
		//				this.errExam.SetError(txtExamTitle, "");
		//			}
		//		}

		//	private void txtScheduledAt_Leave(object sender, System.EventArgs e)
		//	{
		//		if (this.txtScheduledAt.Text.Trim().Length == 0)
		//		{
		//			errorMsg = ("Scheduled Time cannot be empty. Please enter valid value");
		//			this.errExam.SetError(this.txtScheduledAt, errorMsg);
		//			this.btnSave.Enabled=false;
		//			this.txtScheduledAt.Focus();
		//		}
		//		else
		//		{
		//			this.errExam.SetError(txtScheduledAt, "");				
		//			this.btnSave.Enabled=true; 
		//		}
		//	}

		private void frmExam_Load(object sender, System.EventArgs e)
		{
			btnSave.Enabled=false;
			
		}

		private void btnHelp_Click(object sender, System.EventArgs e)
		{
			Help.ShowHelp(this,Environment.CurrentDirectory +@"\\OES_Help\OES_Help.chm");
		}	
	}
}

⌨️ 快捷键说明

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