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

📄 form_da.cs

📁 一个很简单的考试系统。实用性很强啊!数据库在里面
💻 CS
📖 第 1 页 / 共 4 页
字号:
				{
					this.pcb_yltp.Image = null;
				}
			}
			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 btn_mjl_Click(object sender, System.EventArgs e)
		{
			if(this.dgd_da.CurrentRowIndex !=  -1)
			{
				this.dgd_da.UnSelect(this.dgd_da.CurrentRowIndex);
				this.dgd_da.CurrentRowIndex = this.BindingContext[this.dst_st,"Answer"].Count - 1;
				this.dgd_da.Select(this.dgd_da.CurrentRowIndex);
				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_st.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(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 btn_fjtp_Click(object sender, System.EventArgs e)
		{
			ofd_fjtp.ShowDialog();
			if(ofd_fjtp.FileName != "" & ofd_fjtp.CheckFileExists == false)
			{
				Image img = Image.FromFile(ofd_fjtp.FileName);
				this.pcb_yltp.Image = img.GetThumbnailImage(this.pcb_yltp.Width,this.pcb_yltp.Height,null,IntPtr.Zero);
			}
		}

		private void btn_sc_Click(object sender, System.EventArgs e)
		{
			if(this.dgd_da.CurrentRowIndex != -1)
			{
				DialogResult result=MessageBox.Show("确定要删除记录吗?","阜和教育课程体系试题库系统提示",MessageBoxButtons.YesNo,MessageBoxIcon.Question);  
				if(result == DialogResult.Yes)
				{
					try
					{
						sqlcmd_st = sqlcnt_st.CreateCommand();
						sqlcmd_st.CommandText = "DELETE FROM Answer WHERE ans_no = @ans_no";
						sqlcmd_st.Parameters.Add("@ans_no",System.Data.SqlDbType.Int);
						sqlcmd_st.Parameters["@ans_no"].Value = this.dst_st.Tables["Answer"].Rows[this.dgd_da.CurrentRowIndex]["ans_no"];
						sqlcnt_st.Open();
						sqlcmd_st.ExecuteNonQuery();
						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 mass)
					{
						MessageBox.Show("答案有相关联的数据,请确认后删除","阜和教育课程体系试题库系统提示",MessageBoxButtons.OK);
						sqlcnt_st.Close();
						if(this.dst_st.Tables.IndexOf("Answer") != -1)
						{
							this.dst_st.Tables["Answer"].RejectChanges();
						}
					}
				}
			}
		}

		private void dgd_st_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			//try
			//{
			if(e.Button == System.Windows.Forms.MouseButtons.Left)
			{
				this.txt_danr.DataBindings.Clear();
				this.txt_daxx.DataBindings.Clear();
				//Point pt = new Point(e.X,e.Y);
				//DataGrid.HitTestInfo hit = dgd_st.HitTest(pt);
				//if(hit.Type == DataGrid.HitTestType.Cell) 
				//{
				if(this.dgd_st.CurrentRowIndex != -1)
				{
					dgd_st.Select(this.dgd_st.CurrentRowIndex); 
					//this.dgd_st.CurrentRowIndex = hit.Row;
					stno = this.dst_st.Tables["Question"].Rows[this.dgd_st.CurrentRowIndex]["que_no"].ToString();
					if(dst_st.Tables.IndexOf("Answer") !=-1)
					{
						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.DataSource = dst_st;
					this.dgd_da.DataMember = "Answer";
					this.txt_danr.DataBindings.Add("Text",this.dst_st,"Answer.ans_content");
					this.txt_daxx.DataBindings.Add("Text",this.dst_st,"Answer.ans_item");
					this.pcb_yltp.Image = null;
					this.btn_tj.Enabled = true;
					this.btn_sc.Enabled = true;
					this.btn_xg.Enabled = true;
					this.btn_qx.Enabled = true;
					this.btn_qyjl.Enabled = true;
					this.btn_hyjl.Enabled = true;
					this.btn_sjl.Enabled = true;
					this.btn_mjl.Enabled = true;
					this.btn_qrtj.Enabled = true;
					this.btn_qx.Enabled = true;
				}
				//}
				//}
				//catch{}
				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;
				}
			}
		}

		private void btn_tj_Click(object sender, System.EventArgs e)
		{
			try
			{
				if(bl_qx == 0)
				{
					System.Data.DataRow drw_tj = dst_st.Tables["Answer"].NewRow();
					drw_tj["que_no"] = stno;
					drw_tj["cou_no"] = cno;
					drw_tj["teau_no"] = jno;
					dst_st.Tables["Answer"].Rows.Add(drw_tj);
					this.dgd_da.UnSelect(this.dgd_da.CurrentRowIndex);
					this.dgd_da.CurrentRowIndex = this.dst_st.Tables["Answer"].Rows.Count - 1;//this.BindingContext[this.dst_st,"Answer"].Count - 1;
					this.dgd_da.Select(this.dgd_da.CurrentRowIndex);
					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.dst_st.Tables["Answer"].Rows.Count - 1]["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;
					}
					this.txt_danr.Enabled = true;
					this.ckb_zqda.Enabled = true;
					this.txt_daxx.Enabled = true;
					this.btn_xg.Enabled = false;
					this.btn_sc.Enabled = false;
					this.btn_fjtp.Enabled = true;
					bl_qx = 1;
				}
				else
				{
					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.Int);
						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();
					System.Data.DataRow drw_tj = dst_st.Tables["Answer"].NewRow();
					drw_tj["que_no"] = stno;
					drw_tj["cou_no"] = cno;
					drw_tj["teau_no"] = jno;
					dst_st.Tables["Answer"].Rows.Add(drw_tj);
					this.dgd_da.UnSelect(this.dgd_da.CurrentRowIndex);
					this.dgd_da.CurrentRowIndex = this.dst_st.Tables["Answer"].Rows.Count - 1;//this.BindingContext[this.dst_st,"Answer"].Count - 1;
					this.dgd_da.Select(this.dgd_da.CurrentRowIndex);
					try
					{
						byte[] by = (byte[])this.dst_st.Tables["Answer"].Rows[this.dst_st.Tables["Answer"].Rows.Count - 1]["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;
					}
					txt_danr.Text = "";
					this.ckb_zqda.Checked = false;
					this.pcb_yltp.Image = null;
				}
			}
			catch(System.Exception mess)
			{
				MessageBox.Show(mess.Message,"阜和教育课程体系试题库系统提示",MessageBoxButtons.OK);
				sqlcnt_st.Close();
			}
		}

		private void btn_xg_Click(object sender, System.EventArgs e)
		{
			try
			{
				if(this.dgd_da.CurrentRowIndex != -1)
				{
					if(bl_qx == 0)
					{
						this.txt_danr.Enabled = true;
						this.ckb_zqda.Enabled = true;
						this.txt_daxx.Enabled = true;
						this.btn_fjtp.Enabled = true;
						this.btn_tj.Enabled = false;
						this.btn_sc.Enabled = false;
						bl_qx = 2;
					}
					else
					{
						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);

⌨️ 快捷键说明

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