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

📄 form_st.cs

📁 一个很简单的考试系统。实用性很强啊!数据库在里面
💻 CS
📖 第 1 页 / 共 4 页
字号:
			this.btn_tj.Enabled = true;
			this.btn_sc.Enabled = true;
			this.cbb_nd.Enabled = false;
			this.cbb_stlx.Enabled = false;
			this.txt_gtfz.Enabled = false;
			this.txt_stnr.Enabled = false;
			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["Question"].NewRow();
				drw_tj["cou_no"] = cno;
				drw_tj["teau_no"] = jno;
				dst_st.Tables["Question"].Rows.Add(drw_tj);
				//cbb_stlx.Text = "";
				//cbb_nd.Text = "";
				this.pcb_yltp.Image = null;
				this.txt_gtfz.Enabled = true;
				this.txt_stnr.Enabled = true;
				this.dgd_st.UnSelect(this.dgd_st.CurrentRowIndex);
				this.dgd_st.CurrentRowIndex = this.BindingContext[this.dst_st,"Question"].Count - 1;
				this.dgd_st.Select(this.dgd_st.CurrentRowIndex);
				this.cbb_nd.Enabled = true;
				this.cbb_stlx.Enabled = true;
				this.btn_sc.Enabled = false;
				this.btn_fjtp.Enabled = true;
				this.btn_xg.Enabled = false;
				try
				{
					byte[] by = (byte[])this.dst_st.Tables["Question"].Rows[this.dgd_st.CurrentRowIndex]["que_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;
				}
				bl_qx = 1;
			}
			else
			{
				this.sqlcmd_st = this.sqlcnt_st.CreateCommand();
				this.sqlcmd_st.CommandType = System.Data.CommandType.StoredProcedure;
				this.sqlcmd_st.CommandText = "InsertQuestion";
				this.sqlcmd_st.Parameters.Add("@cou_no",System.Data.SqlDbType.Int);
				this.sqlcmd_st.Parameters["@cou_no"].Value = int.Parse(cno);
				this.sqlcmd_st.Parameters.Add("@teau_no",System.Data.SqlDbType.Int);
				this.sqlcmd_st.Parameters["@teau_no"].Value = int.Parse(jno);
				if(cbb_stlx.Text == "单选")
				{
					char typ = '1';
					this.sqlcmd_st.Parameters.Add("@que_type",System.Data.SqlDbType.Char);
					this.sqlcmd_st.Parameters["@que_type"].Value = typ;
				}
				else
				{
					char typ = '2';
					this.sqlcmd_st.Parameters.Add("@que_type",System.Data.SqlDbType.Char);
					this.sqlcmd_st.Parameters["@que_type"].Value = typ;
				}
				switch (cbb_nd.Text)
				{
					case "易":
						char dif = '1';
						this.sqlcmd_st.Parameters.Add("@que_difficulty",System.Data.SqlDbType.Char);
						this.sqlcmd_st.Parameters["@que_difficulty"].Value = dif;
						break;
					case "中":
						dif = '2';
						this.sqlcmd_st.Parameters.Add("@que_difficulty",System.Data.SqlDbType.Char);
						this.sqlcmd_st.Parameters["@que_difficulty"].Value = dif;
						break;
					case "难":
						dif = '3';
						this.sqlcmd_st.Parameters.Add("@que_difficulty",System.Data.SqlDbType.Char);
						this.sqlcmd_st.Parameters["@que_difficulty"].Value = dif;
						break;
				}
				//if(txt_gtfz.Text !="")
				//{
					try
					{
						this.sqlcmd_st.Parameters.Add("@que_score",System.Data.SqlDbType.Float);
						this.sqlcmd_st.Parameters["@que_score"].Value = System.Single.Parse(txt_gtfz.Text);
					}
					catch
					{
						MessageBox.Show("分值不能为字符","阜和教育课程体系试题库系统提示",MessageBoxButtons.OK);
						txt_gtfz.Text = "";
					}
				//}
				//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_st.Parameters.Add("@que_picture",System.Data.SqlDbType.Image);
					this.sqlcmd_st.Parameters["@que_picture"].Value = by;
				}
				else
				{
					byte[] by = new byte[0];
					this.sqlcmd_st.Parameters.Add("@que_picture",System.Data.SqlDbType.Image);
					this.sqlcmd_st.Parameters["@que_picture"].Value = by;
				}
				//if(txt_stnr.Text !="")
				//{
					this.sqlcmd_st.Parameters.Add("@que_content",System.Data.SqlDbType.Text);
					this.sqlcmd_st.Parameters["@que_content"].Value = txt_stnr.Text;
				//}
				//else
				//{
					MessageBox.Show("试题内容不能为空","阜和教育课程体系试题库系统提示",MessageBoxButtons.OK);
				//}
				try
				{
					sqlcmd_stc.CommandText = "SELECT getdate()";
					sqldpt_st.SelectCommand = sqlcmd_stc;		
					if(dst_st.Tables.IndexOf("cdate") !=-1)
					{
						dst_st.Tables["cdate"].Clear();
					}
					sqlcnt_st.Open();
					sqldpt_st.Fill(dst_st,"cdata");
					sqlcnt_st.Close();
					this.sqlcmd_st.Parameters.Add("@que_createtime",System.Data.SqlDbType.DateTime);
					string cdata = this.dst_st.Tables["cdata"].Rows[0][0].ToString();
					this.sqlcmd_st.Parameters["@que_createtime"].Value = System.Convert.ToDateTime(cdata);
				}
				catch(System.Exception mass)
				{
					MessageBox.Show(mass.Message,"阜和教育课程体系试题库系统提示",MessageBoxButtons.OK);
				}
				try
				{
					sqlcmd_stc.CommandText = "SELECT getdate()";
					sqldpt_st.SelectCommand = sqlcmd_stc;				
					if(dst_st.Tables.IndexOf("mdate") !=-1)
					{
						dst_st.Tables["mdate"].Clear();
					}
					sqlcnt_st.Open();
					sqldpt_st.Fill(dst_st,"mdata");
					sqlcnt_st.Close();
					this.sqlcmd_st.Parameters.Add("@que_modifytime",System.Data.SqlDbType.DateTime);
					string mdata = this.dst_st.Tables["mdata"].Rows[0][0].ToString();
					this.sqlcmd_st.Parameters["@que_modifytime"].Value = System.Convert.ToDateTime(mdata);
				}
				catch(System.Exception mass)
				{
					MessageBox.Show(mass.Message,"阜和教育课程体系试题库系统提示",MessageBoxButtons.OK);
				}
				this.sqlcnt_st.Open();
				this.sqlcmd_st.ExecuteNonQuery();
				this.sqlcnt_st.Close();
				if(this.dst_st.Tables.IndexOf("Question") != -1)
				{
					this.dst_st.Tables["Question"].Clear();
				}
				sqlcmd_stc.CommandText = "SELECT cou_no,teau_no,que_no,que_type=(case que_type when 1 then '单选' " +
					"when 2 then '多选' end),que_score,que_difficulty=(case que_difficulty when 1 then '易' when 2 then '中' "+
					"when 3 then '难' end),que_picture,que_content,que_createtime,que_modifytime,que_memo FROM Question WHERE teau_no =" + tno;
				sqldpt_st.SelectCommand = sqlcmd_stc;
				sqlcnt_st.Open();
				sqldpt_st.Fill(dst_st,"Question");
				sqlcnt_st.Close();

				System.Data.DataRow drw_tj = dst_st.Tables["Question"].NewRow();
				drw_tj["cou_no"] = cno;
				drw_tj["teau_no"] = jno;
				dst_st.Tables["Question"].Rows.Add(drw_tj);
				//cbb_stlx.Text = "";
				//cbb_nd.Text = "";
				this.dgd_st.UnSelect(this.dgd_st.CurrentRowIndex);
				this.dgd_st.CurrentRowIndex = this.BindingContext[this.dst_st,"Question"].Count - 1;
				this.dgd_st.Select(this.dgd_st.CurrentRowIndex);
				try
				{
					byte[] by = (byte[])this.dst_st.Tables["Question"].Rows[this.dgd_st.CurrentRowIndex]["que_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(System.Exception mass)
			{
				MessageBox.Show(mass.Message,"阜和教育课程体系试题库系统提示",MessageBoxButtons.OK);
				sqlcnt_st.Close();
			}




		}

		private void btn_qrtj_Click(object sender, System.EventArgs e)
		{
			if(bl_qx == 1)
			{
				try
				{
					this.sqlcmd_st = this.sqlcnt_st.CreateCommand();
					this.sqlcmd_st.CommandType = System.Data.CommandType.StoredProcedure;
					this.sqlcmd_st.CommandText = "InsertQuestion";
					this.sqlcmd_st.Parameters.Add("@cou_no",System.Data.SqlDbType.Int);
					this.sqlcmd_st.Parameters["@cou_no"].Value = int.Parse(cno);
					this.sqlcmd_st.Parameters.Add("@teau_no",System.Data.SqlDbType.Int);
					this.sqlcmd_st.Parameters["@teau_no"].Value = int.Parse(jno);
					if(cbb_stlx.Text == "单选")
					{
						char typ = '1';
						this.sqlcmd_st.Parameters.Add("@que_type",System.Data.SqlDbType.Char);
						this.sqlcmd_st.Parameters["@que_type"].Value = typ;
					}
					else
					{
						char typ = '2';
						this.sqlcmd_st.Parameters.Add("@que_type",System.Data.SqlDbType.Char);
						this.sqlcmd_st.Parameters["@que_type"].Value = typ;
					}
					switch (cbb_nd.Text)
					{
						case "易":
							char dif = '1';
							this.sqlcmd_st.Parameters.Add("@que_difficulty",System.Data.SqlDbType.Char);
							this.sqlcmd_st.Parameters["@que_difficulty"].Value = dif;
							break;
						case "中":
							dif = '2';
							this.sqlcmd_st.Parameters.Add("@que_difficulty",System.Data.SqlDbType.Char);
							this.sqlcmd_st.Parameters["@que_difficulty"].Value = dif;
							break;
						case "难":
							dif = '3';
							this.sqlcmd_st.Parameters.Add("@que_difficulty",System.Data.SqlDbType.Char);
							this.sqlcmd_st.Parameters["@que_difficulty"].Value = dif;
							break;
					}
					//if(txt_gtfz.Text !="")
					//{
						//try
						//{
							this.sqlcmd_st.Parameters.Add("@que_score",System.Data.SqlDbType.Float);
							this.sqlcmd_st.Parameters["@que_score"].Value = System.Single.Parse(txt_gtfz.Text);
						//}
						//catch
						//{
							//MessageBox.Show("分值不能为字符","阜和教育课程体系试题库系统提示",MessageBoxButtons.OK);
							//txt_gtfz.Text = "";
						//}
					//}
					//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_st.Parameters.Add("@que_picture",System.Data.SqlDbType.Image);
						this.sqlcmd_st.Parameters["@que_picture"].Value = by;
					}
					else
					{
						byte[] by = new byte[0];
						this.sqlcmd_st.Parameters.Add("@que_picture",System.Data.SqlDbType.Image);
						this.sqlcmd_st.Parameters["@que_picture"].Value = by;
					}
					//if(txt_stnr.Text !="")
					//{
						this.sqlcmd_st.Parameters.Add("@que_content",System.Data.SqlDbType.Text);
						this.sqlcmd_st.Parameters["@que_content"].Value = txt_stnr.Text;
					//}
					//else
					//{
						//MessageBox.Show("试题内容不能为空","阜和教育课程体系试题库系统提示",MessageBoxButtons.OK);
					//}
					try
					{
						sqlcmd_stc.CommandText = "SELECT getdate()";
						sqldpt_st.SelectCommand = sqlcmd_stc;		
						if(dst_st.Tables.IndexOf("cdate") !=-1)
						{
							dst_st.Tables["cdate"].Clear();
						}
						sqlcnt_st.Open();
						sqldpt_st.Fill(dst_st,"cdata");
						sqlcnt_st.Close();
						this.sqlcmd_st.Parameters.Add("@que_createtime",System.Data.SqlDbType.DateTime);
						string cdata = this.dst_st.Tables["cdata"].Rows[0][0].ToString();
						this.sqlcmd_st.Parameters["@que_createtime"].Value = System.Convert.ToDateTime(cdata);
					}
					catch(System.Exception mass)
					{
						MessageBox.Show(mass.Message,"阜和教育课程体系试题库系统提示",MessageBoxButtons.OK);
					}
					try
					{
						sqlcmd_stc.CommandText = "SELECT getdate()";
						sqldpt_st.SelectCommand = sqlcmd_stc;				
						if(dst_st.Tables.IndexOf("mdate") !=-1)
						{
							dst_st.Tables["mdate"].Clear();
						}
						sqlcnt_st.Open();
						sqldpt_st.Fill(dst_st,"mdata");
						sqlcnt_st.Close();
						this.sqlcmd_st.Parameters.Add("@que_modifytime",System.Data.SqlDbType.DateTime);
						string mdata = this.dst_st.Tables["mdata"].Rows[0][0].ToString();
						this.sqlcmd_st.Parameters["@que_modifytime"].Value = System.Convert.ToDateTime(mdata);
					}
					catch(System.Exception mass)
					{
						MessageBox.Show(mass.Message,"阜和教育课程体系试题库系统提示",MessageBoxButtons.OK);
					}
					this.sqlcnt_st.Open();
					this.sqlcmd_st.ExecuteNonQuery();
					this.sqlcnt_st.Close();
					if(this.dst_st.Tables.IndexOf("Question") != -1)
					{
						this.dst_st.Tables["Question"].Clear();
					}
					sqlcmd_stc.CommandText = "SELECT cou_no,teau_no,que_no,que_type=(case que_type when 1 then '单选' " +
						"when 2 then '多选' end),que_score,que_difficulty=(case que_difficulty when 1 then '易' when 2 then '中' "+
						"when 3 then '难' end),que_picture,que_content,que_createtime,que_modifytime,que_memo FROM Question WHERE teau_no =" + tno;
					sqldpt_st.SelectCommand = sqlcmd_stc;
					sqlcnt_st.Open();
					sqldpt_st.Fill(dst_st,"Question");
					sqlcnt_st.Close();
					//this.dgd_st.UnSelect(this.dgd_st.CurrentRowIndex);
					//this.dgd_st.CurrentRowIndex = 0;
					//this.dgd_st.Select(0);
				}
				catch(System.Exception mess)
				{
					MessageBox.Show(mess.Message,"阜和教育课程体系试题库系统提示",MessageBoxButtons.OK);
					sqlcnt_st.Close();
				}
				this.cbb_nd.Enabled = false;
				this.cbb_stlx.Enabled = false;
				this.txt_gtfz.Enabled = false;
				this.txt_stnr.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;
			}
			else if(bl_qx == 2)
			{
				try
				{
					this.sqlcmd_st = this.sqlcnt_st.CreateCommand();
					this.sqlcmd_st.CommandType = System.Data.CommandType.StoredProcedure;
					this.sqlcmd_st.CommandText = "UpdateQuestion";
					if(cbb_stlx.Text == "单选")
					{
						char typ = '1';
						this.sqlcmd_st.Parameters.Add("@que_type",System.Data.SqlDbType.Char);
						this.sqlcmd_st.Parameters["@que_type"].Value = typ;
					}
					else
					{
						char typ = '2';
						this.sqlcmd_st.Parameters.Add("@que_type",System.Data.SqlDbType.Char);
						this.sqlcmd_st.Parameters["@que_type"].Value = typ;
					}
					switch (cbb_nd.Text)
					{
						case "易":
							char dif = '1';
							this.sqlcmd_st.Parameters.Add("@que_difficulty",System.Data.SqlDbType.Char);
							this.sqlcmd_st.Parameters["@que_difficulty"].Value = dif;
							break;
						case "中":
							dif = '2';
							this.sqlcmd_st.Parameters.Add("@que_difficulty",System.Data.SqlDbType.Char);
							this.sqlcmd_st.Parameters["@que_difficulty"].Value = dif;
							break;

⌨️ 快捷键说明

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