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

📄 form_sknl.cs

📁 一个很简单的考试系统。实用性很强啊!数据库在里面
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;

namespace bizdb
{
	/// <summary>
	/// Form_sknl 的摘要说明。
	/// </summary>
	public class Form_sknl : System.Windows.Forms.Form
	{
		private System.Windows.Forms.ListBox ltb_sykc;
		private System.Windows.Forms.Button btn_tj;
		private System.Windows.Forms.Button btn_yc;
		private System.Windows.Forms.ListBox ltb_sskc;
		private System.Windows.Forms.Label lbl_sykc;
		private System.Windows.Forms.Label lbl_sskc;
		private System.Windows.Forms.Button btn_qd;
		private System.Windows.Forms.DataGrid dgd_sknl;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form_sknl()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.ltb_sykc = new System.Windows.Forms.ListBox();
			this.btn_tj = new System.Windows.Forms.Button();
			this.btn_yc = new System.Windows.Forms.Button();
			this.ltb_sskc = new System.Windows.Forms.ListBox();
			this.lbl_sykc = new System.Windows.Forms.Label();
			this.lbl_sskc = new System.Windows.Forms.Label();
			this.btn_qd = new System.Windows.Forms.Button();
			this.dgd_sknl = new System.Windows.Forms.DataGrid();
			((System.ComponentModel.ISupportInitialize)(this.dgd_sknl)).BeginInit();
			this.SuspendLayout();
			// 
			// ltb_sykc
			// 
			this.ltb_sykc.ItemHeight = 12;
			this.ltb_sykc.Location = new System.Drawing.Point(104, 320);
			this.ltb_sykc.Name = "ltb_sykc";
			this.ltb_sykc.Size = new System.Drawing.Size(136, 220);
			this.ltb_sykc.TabIndex = 0;
			this.ltb_sykc.MouseUp += new System.Windows.Forms.MouseEventHandler(this.ltb_sykc_MouseUp);
			this.ltb_sykc.SelectedIndexChanged += new System.EventHandler(this.ltb_sykc_SelectedIndexChanged);
			// 
			// btn_tj
			// 
			this.btn_tj.Location = new System.Drawing.Point(352, 352);
			this.btn_tj.Name = "btn_tj";
			this.btn_tj.TabIndex = 1;
			this.btn_tj.Text = ">>";
			this.btn_tj.Click += new System.EventHandler(this.btn_tj_Click);
			// 
			// btn_yc
			// 
			this.btn_yc.Location = new System.Drawing.Point(352, 400);
			this.btn_yc.Name = "btn_yc";
			this.btn_yc.TabIndex = 2;
			this.btn_yc.Text = "<<";
			this.btn_yc.Click += new System.EventHandler(this.btn_yc_Click);
			// 
			// ltb_sskc
			// 
			this.ltb_sskc.ItemHeight = 12;
			this.ltb_sskc.Location = new System.Drawing.Point(520, 320);
			this.ltb_sskc.Name = "ltb_sskc";
			this.ltb_sskc.Size = new System.Drawing.Size(136, 220);
			this.ltb_sskc.TabIndex = 3;
			this.ltb_sskc.MouseUp += new System.Windows.Forms.MouseEventHandler(this.ltb_sskc_MouseUp);
			this.ltb_sskc.SelectedIndexChanged += new System.EventHandler(this.ltb_sskc_SelectedIndexChanged);
			// 
			// lbl_sykc
			// 
			this.lbl_sykc.Location = new System.Drawing.Point(104, 272);
			this.lbl_sykc.Name = "lbl_sykc";
			this.lbl_sykc.TabIndex = 4;
			this.lbl_sykc.Text = "可选课程";
			// 
			// lbl_sskc
			// 
			this.lbl_sskc.Location = new System.Drawing.Point(520, 272);
			this.lbl_sskc.Name = "lbl_sskc";
			this.lbl_sskc.TabIndex = 5;
			this.lbl_sskc.Text = "所授课程";
			// 
			// btn_qd
			// 
			this.btn_qd.Location = new System.Drawing.Point(352, 456);
			this.btn_qd.Name = "btn_qd";
			this.btn_qd.TabIndex = 6;
			this.btn_qd.Text = "确定";
			this.btn_qd.Click += new System.EventHandler(this.btn_qd_Click);
			// 
			// dgd_sknl
			// 
			this.dgd_sknl.DataMember = "";
			this.dgd_sknl.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dgd_sknl.Location = new System.Drawing.Point(0, 0);
			this.dgd_sknl.Name = "dgd_sknl";
			this.dgd_sknl.ReadOnly = true;
			this.dgd_sknl.Size = new System.Drawing.Size(928, 256);
			this.dgd_sknl.TabIndex = 7;
			this.dgd_sknl.MouseUp += new System.Windows.Forms.MouseEventHandler(this.dgd_sknl_MouseUp);
			// 
			// Form_sknl
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(792, 573);
			this.Controls.Add(this.dgd_sknl);
			this.Controls.Add(this.btn_qd);
			this.Controls.Add(this.lbl_sskc);
			this.Controls.Add(this.lbl_sykc);
			this.Controls.Add(this.ltb_sskc);
			this.Controls.Add(this.btn_yc);
			this.Controls.Add(this.btn_tj);
			this.Controls.Add(this.ltb_sykc);
			this.Name = "Form_sknl";
			this.Text = "授课能力管理";
			this.Load += new System.EventHandler(this.Form_sknl_Load);
			((System.ComponentModel.ISupportInitialize)(this.dgd_sknl)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion
		public SqlConnection  sqlcnt= new SqlConnection();
		SqlDataAdapter sqldpt_sknl1= new SqlDataAdapter();
		DataSet dst_sknl1 = new DataSet ();
		SqlDataAdapter sqldpt_sknl2= new SqlDataAdapter();
		DataSet dst_sknl2 = new DataSet ();
		SqlDataAdapter sqldpt_sknl3= new SqlDataAdapter();
		DataSet dst_sknl3 = new DataSet ();
		SqlDataAdapter sqldpt_sknl4= new SqlDataAdapter();
		DataSet dst_sknl4 = new DataSet ();

		SqlCommand StrCommand = new SqlCommand();
		SqlCommand StrUpdate = new SqlCommand ();

		private void Form_sknl_Load(object sender, System.EventArgs e)
		{
			this.load_sknl ();
			sqlcnt.ConnectionString = dbAccess.conn;
			try
			{
				sqlcnt.Open();
							
			}
			catch
			{
				MessageBox.Show("服务器连接出错","阜和教育课程体系试题库系统提示");
				return;                
			}
			StrCommand.CommandText = "select cou_name ,cou_kind=(case cou_kind when 1 then '基础课' when 2 then '公共课' when 3 then '专业课' when 4 then '其他' end),cou_level = (case cou_level when 1 then '第一阶段' when 2 then '第二阶段' when 3 then '第三阶段' end) ,cou_outline ,cou_material  from course";
			StrCommand.Connection = sqlcnt;
			sqldpt_sknl4.SelectCommand = StrCommand;
			sqldpt_sknl4.Fill (dst_sknl4);

			DataGridTableStyle style=new DataGridTableStyle();
			style.MappingName="table";

			DataGridTextBoxColumn cou_name = new DataGridTextBoxColumn();
			cou_name.HeaderText = "课程名称";
			cou_name.MappingName = "cou_name";
			cou_name.Width = 150;

			DataGridTextBoxColumn cou_kind = new DataGridTextBoxColumn();
			cou_kind.HeaderText = "课程属类";
			cou_kind.MappingName = "cou_kind";
			cou_kind.Width = 150;

			DataGridTextBoxColumn cou_level = new DataGridTextBoxColumn();
			cou_level.HeaderText = "课程阶段";
			cou_level.MappingName = "cou_level";
			cou_level.Width = 150;
			
			DataGridTextBoxColumn cou_outline = new DataGridTextBoxColumn();
			cou_outline.HeaderText = "课程教学大纲说明";
			cou_outline.MappingName = "cou_outline";
			cou_outline.Width = 200;

			DataGridTextBoxColumn cou_material = new DataGridTextBoxColumn();
			cou_material.HeaderText = "参考教材";
			cou_material.MappingName = "cou_material";
			cou_material.Width = 200;

			style.GridColumnStyles.AddRange(new DataGridColumnStyle[]{cou_name ,cou_kind,cou_level ,cou_outline ,cou_material});
			this.dgd_sknl.TableStyles.Clear ();
			this.dgd_sknl.TableStyles.Add (style);
			this.dgd_sknl.SetDataBinding (this.dst_sknl4 ,"table");
			this.sqlcnt.Close ();
	
		}
		private void load_sknl()
		{
			this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
			this.ControlBox = false;
		
			this.dst_sknl1.Clear ();
			this.dst_sknl2.Clear ();
			this.dst_sknl3.Clear ();

			
			btn_qd.Enabled = false;
			sqlcnt.ConnectionString = dbAccess.conn;
			try
			{
				sqlcnt.Open();
							
			}
			catch
			{
				MessageBox.Show("服务器连接出错","阜和教育课程体系试题库系统提示");
				return;                
			}

			StrUpdate.CommandText = "select * from teachingAbility where emp_id ='" + common.emplidstr + "'";
			StrUpdate.Connection = sqlcnt;
			sqldpt_sknl3.SelectCommand = StrUpdate;
			sqldpt_sknl3.Fill(dst_sknl3);
					
			StrCommand.CommandText = "select cou_name,cou_no from Course where cou_no not in(select cou_no from teachingAbility where emp_id = '" + common.emplidstr + "')";
			StrCommand.Connection = sqlcnt;
			sqldpt_sknl1.SelectCommand = StrCommand;
			sqldpt_sknl1.Fill(dst_sknl1);

			StrCommand.CommandText = "select cou_name,cou_no from Course where cou_no in (select cou_no from teachingAbility where emp_id = '" + common.emplidstr +"')";
			StrCommand.Connection =	sqlcnt;
			sqldpt_sknl2.SelectCommand = StrCommand;
			sqldpt_sknl2.Fill(dst_sknl2);

			sqlcnt.Close();
		
			ltb_sykc.DataSource = dst_sknl1;
			ltb_sykc.DisplayMember = "table.cou_name";
			ltb_sskc.DataSource = dst_sknl2;
			ltb_sskc.DisplayMember = "table.cou_name";

			ltb_sykc.ClearSelected();
			ltb_sskc.ClearSelected();
			ltb_sykc.ClearSelected();
			ltb_sskc.ClearSelected();

			btn_yc.Enabled =false;
			btn_tj.Enabled = true;

		}

		private void btn_tj_Click(object sender, System.EventArgs e)
		{
			this.btn_qd.Enabled = true;
			try
			{	
				int index = ltb_sykc.SelectedIndex;
              
				object []yy = new object[2];
				yy[0] = dst_sknl1.Tables[0].Rows[index][0];
				yy[1] = dst_sknl1.Tables[0].Rows[index][1];
				dst_sknl2.Tables[0].Rows.Add(yy);
				dst_sknl2.AcceptChanges ();

				dst_sknl1.Tables[0].Rows[index].Delete();
				dst_sknl1.AcceptChanges ();
				
				ltb_sykc.ClearSelected();
				ltb_sskc.ClearSelected();

			}
			catch
			{
				MessageBox.Show("请选择一个课程删除","阜和教育课程体系试题库系统提示");
			}
	
		}

		private void btn_yc_Click(object sender, System.EventArgs e)
		{
			this.btn_qd.Enabled = true;
			try
			{	
			
				int index = ltb_sskc.SelectedIndex;
				
				object []yy = new object[2];
				yy[0] = dst_sknl2.Tables[0].Rows[index][0];
				yy[1] = dst_sknl2.Tables[0].Rows[index][1];
                dst_sknl1.Tables[0].Rows.Add(yy);
				dst_sknl1.AcceptChanges ();

				dst_sknl2.Tables[0].Rows[index].Delete();
				dst_sknl2.AcceptChanges ();	

				ltb_sykc.ClearSelected();
				ltb_sskc.ClearSelected();

			}
			catch
			{
				MessageBox.Show("请选择一个课程删除","阜和教育课程体系试题库系统提示");
			}

		}

		private void ltb_sykc_SelectedIndexChanged(object sender, System.EventArgs e)
		{
//			if(ltb_sykc.SelectedIndex >=0)
//			{
//				btn_tj.Enabled = true;
//				btn_yc.Enabled =false;
//				ltb_sskc.ClearSelected();
//			}
		}

		private void ltb_sskc_SelectedIndexChanged(object sender, System.EventArgs e)
		{
//			if (ltb_sskc.SelectedIndex >=0)
//			{
//				btn_tj.Enabled = false;
//				btn_yc.Enabled =true;
//				ltb_sykc.ClearSelected ();
//			}
//			
		}

		private void btn_qd_Click(object sender, System.EventArgs e)
		{
			try
			{
				sqlcnt.Open();
							
			}
			catch
			{
				MessageBox.Show("服务器连接出错","阜和教育课程体系试题库系统提示");
				return;                
			}
				
				int index = dst_sknl3.Tables[0].Rows.Count ;
				int iLoop = 0;
				while(iLoop < index)
				{
					dst_sknl3.Tables [0].Rows[iLoop].Delete ();
					iLoop ++;
				}
				
				SqlCommandBuilder scb = new SqlCommandBuilder(sqldpt_sknl3);
				sqldpt_sknl3.Update(dst_sknl3);

				index = dst_sknl2.Tables[0].Rows.Count;
				int Loop = 0;
				while (Loop < index)
				{
					DataRow drw = dst_sknl3.Tables[0].NewRow();
					drw["emp_id"] = common.emplidstr ;
					drw["cou_no"] = dst_sknl2.Tables [0].Rows[Loop][1].ToString ();
					dst_sknl3.Tables[0].Rows.Add (drw);
					Loop++;
				}
				try
				{
					SqlCommandBuilder qscb = new SqlCommandBuilder(sqldpt_sknl3);
					sqldpt_sknl3.Update(dst_sknl3);
				}
				catch(System.Exception error)
				{
					MessageBox.Show (error.Message);
				}
				MessageBox.Show("数据库更新成功","阜和教育课程体系试题库系统提示");
				sqlcnt.Close ();
				this.load_sknl ();
		}

		

		private void ltb_sykc_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if(ltb_sykc.SelectedIndex >=0)
			{
				btn_tj.Enabled = true;
				btn_yc.Enabled =false;
				ltb_sskc.ClearSelected();
				ltb_sskc.ClearSelected();
			}
		}

		private void ltb_sskc_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if (ltb_sskc.SelectedIndex >=0)
			{
				btn_tj.Enabled = false;
				btn_yc.Enabled =true;
				ltb_sykc.ClearSelected ();
				ltb_sykc.ClearSelected ();
			}
		}

		private void dgd_sknl_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if (e.Button == System.Windows.Forms.MouseButtons.Left)
			{
				Point pt = new Point(e.X,e.Y);
				DataGrid.HitTestInfo hit = dgd_sknl.HitTest(pt);
				if(hit.Type == DataGrid.HitTestType.Cell) 
				{
					dgd_sknl.Select(hit.Row);
				}
			}
		}

		
	}
}

⌨️ 快捷键说明

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