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

📄 form_da.cs

📁 一个很简单的考试系统。实用性很强啊!数据库在里面
💻 CS
📖 第 1 页 / 共 4 页
字号:
						//}
						if(ofd_fjtp.FileName != "")
						{
							System.IO.FileStream fs = new System.IO.FileStream(ofd_fjtp.FileName,System.IO.FileMode.Open,System.IO.FileAccess.Read);
							byte[] by = new byte[fs.Length];
							fs.Read(by,0,(int)fs.Length);
							fs.Close();
							this.sqlcmd_sts.Parameters.Add("@ans_picture",System.Data.SqlDbType.Image);
							this.sqlcmd_sts.Parameters["@ans_picture"].Value = by;
						}
						else
						{
							byte[] by = new byte[0];
							this.sqlcmd_sts.Parameters.Add("@ans_picture",System.Data.SqlDbType.Image);
							this.sqlcmd_sts.Parameters["@ans_picture"].Value = by;
						}
						this.sqlcmd_sts.Parameters.Add("@ans_no",System.Data.SqlDbType.Int);
						this.sqlcmd_sts.Parameters["@ans_no"].Value = dst_st.Tables["Answer"].Rows[this.dgd_da.CurrentRowIndex]["ans_no"];
						this.sqlcnt_st.Open();
						this.sqlcmd_sts.ExecuteNonQuery();
						this.sqlcnt_st.Close();
						if(this.dst_st.Tables.IndexOf("Answer") != -1)
						{
							this.dst_st.Tables["Answer"].Clear();
						}
						sqlcmd_st.CommandText = "SELECT cou_no,teau_no,que_no,ans_no,ans_content,ans_picture,ans_item,ans_isResult=" +
							"(case ans_isResult when 0 then '正确' when 1 then '错误' end),ans_memo FROM Answer WHERE que_no =" + stno;
						sqldpt_st.SelectCommand = sqlcmd_st;
						sqlcnt_st.Open();
						sqldpt_st.Fill(dst_st,"Answer");
						sqlcnt_st.Close();
					}
					//this.dgd_da.UnSelect(this.dgd_st.CurrentRowIndex);
					//this.dgd_da.CurrentRowIndex = 0;
					//this.dgd_da.Select(0);
				}
			}
			catch(System.Exception mess)
			{
				MessageBox.Show(mess.Message,"阜和教育课程体系试题库系统提示",MessageBoxButtons.OK);
				sqlcnt_st.Close();
			}
		}

		private void btn_qrtj_Click(object sender, System.EventArgs e)
		{
			if(bl_qx == 1)
			{
				try
				{
					this.sqlcmd_sts = this.sqlcnt_st.CreateCommand();
					this.sqlcmd_sts.CommandType = System.Data.CommandType.StoredProcedure;
					this.sqlcmd_sts.CommandText = "InsertAnswer";
					this.sqlcmd_sts.Parameters.Add("@cou_no",System.Data.SqlDbType.Int);
					this.sqlcmd_sts.Parameters["@cou_no"].Value = cno;
					this.sqlcmd_sts.Parameters.Add("@teau_no",System.Data.SqlDbType.Int);
					this.sqlcmd_sts.Parameters["@teau_no"].Value = jno;
					this.sqlcmd_sts.Parameters.Add("@que_no",System.Data.SqlDbType.Int);
					this.sqlcmd_sts.Parameters["@que_no"].Value = stno;
					if(ckb_zqda.Checked == true)
					{
						char typ = '0';
						this.sqlcmd_sts.Parameters.Add("@ans_isResult",System.Data.SqlDbType.Char);
						this.sqlcmd_sts.Parameters["@ans_isResult"].Value = typ;
					}
					else
					{
						char typ = '1';
						this.sqlcmd_sts.Parameters.Add("@ans_isResult",System.Data.SqlDbType.Char);
						this.sqlcmd_sts.Parameters["@ans_isResult"].Value = typ;
					}
					//if(txt_danr.Text !="")
					//{
						this.sqlcmd_sts.Parameters.Add("@ans_content",System.Data.SqlDbType.Text);
						this.sqlcmd_sts.Parameters["@ans_content"].Value = txt_danr.Text;
					//}
					//else
					//{
						//MessageBox.Show("试题内容不能为空","阜和教育课程体系试题库系统提示",MessageBoxButtons.OK);
					//}
					//if(txt_daxx.Text != "")
					//{
						this.sqlcmd_sts.Parameters.Add("@ans_item",System.Data.SqlDbType.Char);
						string daxx = txt_daxx.Text.ToUpper();
						this.sqlcmd_sts.Parameters["@ans_item"].Value = daxx.Trim()[0];
					//}
					//else
					//{
						//MessageBox.Show("答案内容不能为空","阜和教育课程体系试题库系统提示",MessageBoxButtons.OK);
					//}
					if(ofd_fjtp.FileName != "")
					{
						System.IO.FileStream fs = new System.IO.FileStream(ofd_fjtp.FileName,System.IO.FileMode.Open,System.IO.FileAccess.Read);
						byte[] by = new byte[fs.Length];
						fs.Read(by,0,(int)fs.Length);
						fs.Close();
						this.sqlcmd_sts.Parameters.Add("@ans_picture",System.Data.SqlDbType.Image);
						this.sqlcmd_sts.Parameters["@ans_picture"].Value = by;
					}
					else
					{
						byte[] by = new byte[0];
						this.sqlcmd_sts.Parameters.Add("@ans_picture",System.Data.SqlDbType.Image);
						this.sqlcmd_sts.Parameters["@ans_picture"].Value = by;
					}
					this.sqlcnt_st.Open();
					this.sqlcmd_sts.ExecuteNonQuery();
					this.sqlcnt_st.Close();
					if(this.dst_st.Tables.IndexOf("Answer") != -1)
					{
						this.dst_st.Tables["Answer"].Clear();
					}
					sqlcmd_st.CommandText = "SELECT cou_no,teau_no,que_no,ans_no,ans_content,ans_picture,ans_item,ans_isResult=" +
						"(case ans_isResult when 0 then '正确' when 1 then '错误' end),ans_memo FROM Answer WHERE que_no =" + stno;
					sqldpt_st.SelectCommand = sqlcmd_st;
					sqlcnt_st.Open();
					sqldpt_st.Fill(dst_st,"Answer");
					sqlcnt_st.Close();
					//this.dgd_da.UnSelect(this.dgd_st.CurrentRowIndex);
					//this.dgd_da.CurrentRowIndex = 0;
					//this.dgd_da.Select(0);
					bl_qx = 0;
					this.txt_danr.Enabled = false;
					this.ckb_zqda.Enabled = false;
					this.txt_daxx.Enabled = false;
					this.btn_cx.Enabled = true;
					this.btn_tj.Enabled = true;
					this.btn_xg.Enabled = true;
					this.btn_sc.Enabled = true;
					this.btn_fjtp.Enabled = false;
				}
				catch(System.Exception mess)
				{
					MessageBox.Show(mess.Message,"阜和教育课程体系试题库系统提示",MessageBoxButtons.OK);
					sqlcnt_st.Close();
					bl_qx = 0;
				}
			}
			else if(bl_qx == 2)
			{
				this.sqlcmd_sts = this.sqlcnt_st.CreateCommand();
				this.sqlcmd_sts.CommandType = System.Data.CommandType.StoredProcedure;
				this.sqlcmd_sts.CommandText = "UpdateAnswer";
				if(ckb_zqda.Checked == true)
				{
					char typ = '0';
					this.sqlcmd_sts.Parameters.Add("@ans_isResult",System.Data.SqlDbType.Char);
					this.sqlcmd_sts.Parameters["@ans_isResult"].Value = typ;
				}
				else
				{
					char typ = '1';
					this.sqlcmd_sts.Parameters.Add("@ans_isResult",System.Data.SqlDbType.Char);
					this.sqlcmd_sts.Parameters["@ans_isResult"].Value = typ;
				}
				if(txt_danr.Text !="")
				{
					this.sqlcmd_sts.Parameters.Add("@ans_content",System.Data.SqlDbType.Text);
					this.sqlcmd_sts.Parameters["@ans_content"].Value = txt_danr.Text;
				}
				else
				{
					MessageBox.Show("试题内容不能为空","阜和教育课程体系试题库系统提示",MessageBoxButtons.OK);
				}
				if(txt_daxx.Text != "")
				{
					this.sqlcmd_sts.Parameters.Add("@ans_item",System.Data.SqlDbType.Char);
					string daxx = txt_daxx.Text.ToUpper();
					this.sqlcmd_sts.Parameters["@ans_item"].Value = daxx.Trim()[0];
				}
				else
				{
					MessageBox.Show("答案内容不能为空","阜和教育课程体系试题库系统提示",MessageBoxButtons.OK);
				}
				if(ofd_fjtp.FileName != "")
				{
					System.IO.FileStream fs = new System.IO.FileStream(ofd_fjtp.FileName,System.IO.FileMode.Open,System.IO.FileAccess.Read);
					byte[] by = new byte[fs.Length];
					fs.Read(by,0,(int)fs.Length);
					fs.Close();
					this.sqlcmd_sts.Parameters.Add("@ans_picture",System.Data.SqlDbType.Image);
					this.sqlcmd_sts.Parameters["@ans_picture"].Value = by;
				}
				else
				{
					byte[] by = new byte[0];
					this.sqlcmd_sts.Parameters.Add("@ans_picture",System.Data.SqlDbType.Image);
					this.sqlcmd_sts.Parameters["@ans_picture"].Value = by;
				}
				this.sqlcmd_sts.Parameters.Add("@ans_no",System.Data.SqlDbType.Int);
				this.sqlcmd_sts.Parameters["@ans_no"].Value = dst_st.Tables["Answer"].Rows[this.dgd_da.CurrentRowIndex]["ans_no"];
				try
				{
					this.sqlcnt_st.Open();
					this.sqlcmd_sts.ExecuteNonQuery();
					this.sqlcnt_st.Close();
				}
				catch(System.Exception mass)
				{
					MessageBox.Show(mass.Message,"阜和教育课程体系试题库系统提示",MessageBoxButtons.OK);
					sqlcnt_st.Close();
				}
				if(this.dst_st.Tables.IndexOf("Answer") != -1)
				{
					this.dst_st.Tables["Answer"].Clear();
				}
				sqlcmd_st.CommandText = "SELECT cou_no,teau_no,que_no,ans_no,ans_content,ans_picture,ans_item,ans_isResult=" +
					"(case ans_isResult when 0 then '正确' when 1 then '错误' end),ans_memo FROM Answer WHERE que_no =" + stno;
				sqldpt_st.SelectCommand = sqlcmd_st;
				sqlcnt_st.Open();
				sqldpt_st.Fill(dst_st,"Answer");
				sqlcnt_st.Close();
				//this.dgd_da.UnSelect(this.dgd_st.CurrentRowIndex);
				//this.dgd_da.CurrentRowIndex = 0;
				//this.dgd_da.Select(0);
				this.txt_danr.Enabled = false;
				this.ckb_zqda.Enabled = false;
				this.txt_daxx.Enabled = false;
				this.btn_cx.Enabled = true;
				this.btn_tj.Enabled = true;
				this.btn_xg.Enabled = true;
				this.btn_sc.Enabled = true;
				this.btn_fjtp.Enabled = false;
				bl_qx = 0;
			}
		}

		private void btn_qx_Click(object sender, System.EventArgs e)
		{
			if(this.dst_st.Tables.IndexOf("Answer") != -1)
			{
				this.dst_st.Tables["Answer"].RejectChanges();
				this.pcb_yltp.Image = null;
			}
				this.txt_daxx.Enabled = false;
				this.txt_danr.Enabled = false;
				this.ckb_zqda.Enabled = false;
				this.btn_sc.Enabled = true;
				this.btn_tj.Enabled = true;
				this.btn_xg.Enabled = true;
				this.btn_fjtp.Enabled = false;
				bl_qx = 0;
		}

		private void dgd_st_Click(object sender, System.EventArgs e)
		{
			if(this.dst_st.Tables.IndexOf("Answer") != -1)
			{
				this.dst_st.Tables["Answer"].RejectChanges();
			}
			this.txt_daxx.Enabled = false;
			this.txt_danr.Enabled = false;
			this.ckb_zqda.Enabled = false;
			this.btn_tj.Enabled = true;
			this.btn_xg.Enabled = true;
			this.btn_sc.Enabled = true;
			this.btn_fjtp.Enabled = false;
			bl_qx = 0;
		}

		private void dgd_da_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			try
			{
				//Point pt = new Point(e.X,e.Y);
				//DataGrid.HitTestInfo hit = dgd_da.HitTest(pt);
				//if(hit.Type == DataGrid.HitTestType.Cell) 
				//{
				if(e.Button == System.Windows.Forms.MouseButtons.Left)
				{
					if(this.dgd_da.CurrentRowIndex != -1)
					{
						dgd_da.Select(this.dgd_da.CurrentRowIndex);//(hit.Row); 
						//this.dgd_da.CurrentRowIndex = hit.Row;
						if(dst_st.Tables["Answer"].Rows[this.dgd_da.CurrentRowIndex]["ans_isResult"].ToString() == "0")
						{
							this.ckb_zqda.CheckState = System.Windows.Forms.CheckState.Checked;
						}
						else
						{
							this.ckb_zqda.CheckState = System.Windows.Forms.CheckState.Unchecked;
						}
						try
						{
							byte[] by = (byte[])this.dst_st.Tables["Answer"].Rows[this.dgd_da.CurrentRowIndex]["ans_picture"];
							System.IO.MemoryStream ms = new System.IO.MemoryStream(by);
							//ofd_fjtp.ShowDialog();
							Image img = Image.FromStream(ms); //Image.FromFile(ofd_fjtp.FileName);
							this.pcb_yltp.Image = img.GetThumbnailImage(this.pcb_yltp.Width,this.pcb_yltp.Height,null,IntPtr.Zero);
						}
						catch
						{
							this.pcb_yltp.Image = null;
						}
						//}
						if(bl_qx != 0)
						{
							if(this.dst_st.Tables.IndexOf("Answer") != -1)
							{
								this.dst_st.Tables["Answer"].RejectChanges();
							}
							this.txt_daxx.Enabled = false;
							this.txt_danr.Enabled = false;
							this.ckb_zqda.Enabled = false;
							this.btn_sc.Enabled = true;
							this.btn_tj.Enabled = true;
							this.btn_xg.Enabled = true;
							this.btn_fjtp.Enabled = false;
							bl_qx = 0;
						}
					}
				}
			}
			catch
			{}
		}

		private void dgd_da_Click(object sender, System.EventArgs e)
		{
			if(this.dst_st.Tables.IndexOf("Answer") != -1)
			{
				this.dst_st.Tables["Answer"].RejectChanges();
			}
			this.txt_daxx.Enabled = false;
			this.txt_danr.Enabled = false;
			this.ckb_zqda.Enabled = false;
			this.btn_tj.Enabled = true;
			this.btn_xg.Enabled = true;
			this.btn_sc.Enabled = true;
			this.btn_fjtp.Enabled = false;
			bl_qx = 0;
			
		}
		private void dst_st_dst_st_RosChanged(object sender,System.EventArgs e)
		{
			try
			{
				//Point pt = new Point(e.X,e.Y);
				//DataGrid.HitTestInfo hit = dgd_da.HitTest(pt);
				//if(hit.Type == DataGrid.HitTestType.Cell) 
				//{
				dgd_da.Select(this.dgd_da.CurrentRowIndex);//(hit.Row); 
				//this.dgd_da.CurrentRowIndex = hit.Row;
				if(dst_st.Tables["Answer"].Rows[this.dgd_da.CurrentRowIndex]["ans_isResult"].ToString() == "0")
				{
					this.ckb_zqda.CheckState = System.Windows.Forms.CheckState.Checked;
				}
				else
				{
					this.ckb_zqda.CheckState = System.Windows.Forms.CheckState.Unchecked;
				}
				try
				{
					byte[] by = (byte[])this.dst_st.Tables["Answer"].Rows[this.dgd_da.CurrentRowIndex]["ans_picture"];
					System.IO.MemoryStream ms = new System.IO.MemoryStream(by);
					//ofd_fjtp.ShowDialog();
					Image img = Image.FromStream(ms); //Image.FromFile(ofd_fjtp.FileName);
					this.pcb_yltp.Image = img.GetThumbnailImage(this.pcb_yltp.Width,this.pcb_yltp.Height,null,IntPtr.Zero);
				}
				catch
				{
					this.pcb_yltp.Image = null;
				}
				//}
			}
			catch
			{}
		}
	}
}

⌨️ 快捷键说明

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