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

📄 form_st.cs

📁 一个很简单的考试系统。实用性很强啊!数据库在里面
💻 CS
📖 第 1 页 / 共 4 页
字号:
			this.btn_sjl.Location = new System.Drawing.Point(16, 8);
			this.btn_sjl.Name = "btn_sjl";
			this.btn_sjl.Size = new System.Drawing.Size(64, 23);
			this.btn_sjl.TabIndex = 0;
			this.btn_sjl.Text = "首记录 ";
			this.btn_sjl.Click += new System.EventHandler(this.btn_sjl_Click);
			// 
			// dgd_st
			// 
			this.dgd_st.DataMember = "";
			this.dgd_st.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dgd_st.Location = new System.Drawing.Point(16, 128);
			this.dgd_st.Name = "dgd_st";
			this.dgd_st.ReadOnly = true;
			this.dgd_st.Size = new System.Drawing.Size(760, 200);
			this.dgd_st.TabIndex = 3;
			this.dgd_st.Click += new System.EventHandler(this.dgd_st_Click);
			this.dgd_st.MouseUp += new System.Windows.Forms.MouseEventHandler(this.dgd_st_MouseUp);
			this.dgd_st.Navigate += new System.Windows.Forms.NavigateEventHandler(this.dgd_st_Navigate);
			// 
			// dst_st
			// 
			this.dst_st.DataSetName = "NewDataSet";
			this.dst_st.Locale = new System.Globalization.CultureInfo("zh-CN");
			// 
			// Form_st
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(792, 569);
			this.Controls.Add(this.dgd_st);
			this.Controls.Add(this.pnl_st3);
			this.Controls.Add(this.pnl_st2);
			this.Controls.Add(this.pnl_st1);
			this.Name = "Form_st";
			this.Text = "试题内容管理";
			this.Load += new System.EventHandler(this.Form_st_Load);
			this.pnl_st1.ResumeLayout(false);
			this.pnl_st2.ResumeLayout(false);
			this.pnl_st3.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.dgd_st)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.dst_st)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		private void btn_sjl_Click(object sender, System.EventArgs e)
		{
			if(this.dgd_st.CurrentRowIndex !=  -1)
			{
				this.dgd_st.UnSelect(this.dgd_st.CurrentRowIndex);
				this.dgd_st.CurrentRowIndex = 0;
				this.dgd_st.Select(0);
				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;
				}
			}
			if(this.dst_st.Tables.IndexOf("Question") != -1)
			{
				this.dst_st.Tables["Question"].RejectChanges();
			}
			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_qyjl_Click(object sender, System.EventArgs e)
		{
			if (this.dgd_st.CurrentRowIndex != 0 & this.dgd_st.CurrentRowIndex !=  -1)
			{
				this.dgd_st.UnSelect(this.dgd_st.CurrentRowIndex);
				this.dgd_st.CurrentRowIndex -= 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;
				}
			}
			if(this.dst_st.Tables.IndexOf("Question") != -1)
			{
				this.dst_st.Tables["Question"].RejectChanges();
			}
			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_hyjl_Click(object sender, System.EventArgs e)
		{
			if (this.dgd_st.CurrentRowIndex != this.BindingContext[this.dst_st,"Question"].Count - 1 & this.dgd_st.CurrentRowIndex !=  -1)
			{
				this.dgd_st.UnSelect(this.dgd_st.CurrentRowIndex);
				this.dgd_st.CurrentRowIndex += 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;
				}
			}
			if(this.dst_st.Tables.IndexOf("Question") != -1)
			{
				this.dst_st.Tables["Question"].RejectChanges();
			}
			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_mjl_Click(object sender, System.EventArgs e)
		{
			if(this.dgd_st.CurrentRowIndex !=  -1)
			{
				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;
				}
			}
			if(this.dst_st.Tables.IndexOf("Question") != -1)
			{
				this.dst_st.Tables["Question"].RejectChanges();
			}
			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 cbb_kc_SelectionChange(object sender, System.EventArgs e)
		{
			cno = "";
			string cname = cbb_kc.GetItemText(cbb_kc.SelectedItem);
			foreach(DataRow datar in dst_st.Tables["Course"].Rows)
			{
				if(datar["cou_name"].ToString() == cname)
				{
					cno = datar["cou_no"].ToString();
					break;
				}
			}
			cbb_jxdy.Items.Clear();
			cbb_jxdy.Text="";
			if(dst_st.Tables.IndexOf("teachingUnit") !=-1)
			{
				dst_st.Tables["teachingUnit"].Clear();
			}
			sqlcmd_stc.CommandText = "SELECT * FROM teachingUnit WHERE cou_no =" + cno;
			sqldpt_st.SelectCommand = sqlcmd_stc;
			
			sqlcnt_st.Open();
			sqldpt_st.Fill(dst_st,"teachingUnit");
			sqlcnt_st.Close();
			foreach(DataRow datar in dst_st.Tables["teachingUnit"].Rows)
			{
				cbb_jxdy.Items.Add(datar["teau_name"]);
			}
			if(dst_st.Tables.IndexOf("Question") !=-1)
			{
				dst_st.Tables["Question"].Clear();
				this.btn_tj.Enabled = false;
				this.btn_sc.Enabled = false;
				this.cbb_nd.Enabled = false;
				this.cbb_stlx.Enabled = false;
				this.txt_gtfz.Enabled = false;
				this.txt_stnr.Enabled = false;
				this.btn_xg.Enabled = false;
				this.btn_fjtp.Enabled = false;
				this.btn_qyjl.Enabled = false;
				this.btn_hyjl.Enabled = false;
				this.btn_sjl.Enabled = false;
				this.btn_mjl.Enabled = false;
				this.btn_qrtj.Enabled = false;
				this.btn_qx.Enabled = false;
			}
			bl_qx = 0;
		}

		private void btn_cx_Click(object sender, System.EventArgs e)
		{
			try
			{
				txt_gtfz.DataBindings.Clear();
				txt_stnr.DataBindings.Clear();
				this.cbb_nd.DataBindings.Clear();
				this.cbb_stlx.DataBindings.Clear();
				this.cbb_nd.Text = "";
				this.cbb_stlx.Text = "";
				this.txt_gtfz.Text = "";
				this.pcb_yltp.Image = null;
				string tname = cbb_jxdy.GetItemText(cbb_jxdy.SelectedItem);
				foreach(DataRow datar in dst_st.Tables["teachingUnit"].Rows)
				{
					if(datar["teau_name"].ToString() == tname)
					{
						tno = datar["teau_no"].ToString();
						break;
					}
				}
				if(dst_st.Tables.IndexOf("Question") !=-1)
				{
					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.Windows.Forms.DataGridTableStyle dgt_st = new DataGridTableStyle();
				dgt_st.MappingName = "Question";
				System.Windows.Forms.DataGridColumnStyle dgc_st1 = new DataGridTextBoxColumn();
				dgc_st1.MappingName = "que_content";
				dgc_st1.HeaderText = "试题内容";
				dgc_st1.Width = (dgd_st.Width)*2/3;
				System.Windows.Forms.DataGridColumnStyle dgc_st2 = new DataGridTextBoxColumn();
				dgc_st2.MappingName = "que_type";
				dgc_st2.HeaderText = "试题样式";
				System.Windows.Forms.DataGridColumnStyle dgc_st3 = new DataGridTextBoxColumn();
				dgc_st3.MappingName = "que_score";
				dgc_st3.HeaderText = "试题分值";
				System.Windows.Forms.DataGridColumnStyle dgc_st4 = new DataGridTextBoxColumn();
				dgc_st4.MappingName = "que_difficulty";
				dgc_st4.HeaderText = "试题难度";
				dgt_st.GridColumnStyles.Add(dgc_st1);
				dgt_st.GridColumnStyles.Add(dgc_st2);
				dgt_st.GridColumnStyles.Add(dgc_st3);
				dgt_st.GridColumnStyles.Add(dgc_st4);
				this.dgd_st.TableStyles.Add(dgt_st);
				this.dgd_st.DataSource = dst_st;
				this.dgd_st.DataMember = "Question";
				txt_gtfz.DataBindings.Add("Text",dst_st,"Question.que_score");
				txt_stnr.DataBindings.Add("Text",dst_st,"Question.que_content");
				this.cbb_nd.DataBindings.Add("Text",this.dst_st,"Question.que_difficulty");
				this.cbb_stlx.DataBindings.Add("Text",this.dst_st,"Question.que_type");
			}
			catch
			{
				this.sqlcnt_st.Close();
			}
			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;
		}

		private void Form_st_Load(object sender, System.EventArgs e)
		{
			this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
			this.ControlBox = false;
			try
			{
				dbAccess db = new dbAccess();
				sqlcnt_st.ConnectionString = db.connStr;
				sqlcmd_stc = sqlcnt_st.CreateCommand();
				sqlcmd_stc.CommandText = "SELECT * FROM Course";
				sqldpt_st.SelectCommand = sqlcmd_stc;
				sqlcnt_st.Open();
				sqldpt_st.Fill(dst_st,"Course");
				sqlcnt_st.Close();
				DataTable datat = dst_st.Tables["Course"];
				//comboBox1.DataSource = datas;
				//comboBox1.DisplayMember = "cou_name";
				foreach(DataRow datar in datat.Rows)
				{

					cbb_kc.Items.Add(datar["cou_name"]);
				}
			}
			catch
			{
				MessageBox.Show("未能连接到数据库!","阜和教育课程体系试题库系统提示",MessageBoxButtons.OK);
			}
			this.btn_tj.Enabled = false;
			this.btn_sc.Enabled = false;
			this.cbb_nd.Enabled = false;
			this.cbb_stlx.Enabled = false;
			this.txt_gtfz.Enabled = false;
			this.txt_stnr.Enabled = false;
			this.btn_xg.Enabled = false;
			this.btn_fjtp.Enabled = false;
			this.btn_qyjl.Enabled = false;
			this.btn_hyjl.Enabled = false;
			this.btn_sjl.Enabled = false;
			this.btn_mjl.Enabled = false;
			this.btn_qrtj.Enabled = false;
			this.btn_qx.Enabled = false;
			this.btn_cx.Enabled = false;
			bl_qx = 0;
		}

		private void cbb_stlx_Selectionchange(object sender, System.EventArgs e)
		{
			cbb_stlx.Text = cbb_stlx.GetItemText(cbb_stlx.SelectedItem);
		}

		private void cbb_nd_SelectionChange(object sender, System.EventArgs e)
		{
			cbb_nd.Text = cbb_nd.GetItemText(cbb_nd.SelectedItem);
		}

		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_qx_Click(object sender, System.EventArgs e)
		{
			if(this.dst_st.Tables.IndexOf("Question") != -1)
			{
				this.dst_st.Tables["Question"].RejectChanges();
				this.pcb_yltp.Image = null;
			}
				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 dgd_st_Click(object sender, System.EventArgs e)
		{
			if(this.dst_st.Tables.IndexOf("Question") != -1)
			{
				this.dst_st.Tables["Question"].RejectChanges();
			}

⌨️ 快捷键说明

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