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

📄 browsecourse.cs

📁 学生学籍管理系统
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data;

namespace WindowsApplication1
{
	/// <summary>
	/// kcll 的摘要说明。
	/// </summary>
	public class kcll : System.Windows.Forms.Form
	{
		private System.Windows.Forms.TreeView treeView1;
		private System.Windows.Forms.DataGrid dataGrid1;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.Button button3;
		private System.Data.OleDb.OleDbConnection oleDbConnection1;
		private System.Data.OleDb.OleDbConnection oleDbConnection2;
		private System.Data.OleDb.OleDbConnection oleDbConnection3;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

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

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

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

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.treeView1 = new System.Windows.Forms.TreeView();
			this.dataGrid1 = new System.Windows.Forms.DataGrid();
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.button1 = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.button3 = new System.Windows.Forms.Button();
			this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
			this.oleDbConnection2 = new System.Data.OleDb.OleDbConnection();
			this.oleDbConnection3 = new System.Data.OleDb.OleDbConnection();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
			this.SuspendLayout();
			// 
			// treeView1
			// 
			this.treeView1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.treeView1.ForeColor = System.Drawing.SystemColors.ControlText;
			this.treeView1.ImageIndex = -1;
			this.treeView1.Location = new System.Drawing.Point(11, 41);
			this.treeView1.Name = "treeView1";
			this.treeView1.SelectedImageIndex = -1;
			this.treeView1.Size = new System.Drawing.Size(277, 391);
			this.treeView1.TabIndex = 0;
			this.treeView1.Click += new System.EventHandler(this.treeView1_Click);
			this.treeView1.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterSelect);
			// 
			// dataGrid1
			// 
			this.dataGrid1.AllowSorting = false;
			this.dataGrid1.BackgroundColor = System.Drawing.SystemColors.Control;
			this.dataGrid1.CaptionBackColor = System.Drawing.SystemColors.ControlLightLight;
			this.dataGrid1.CaptionFont = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.dataGrid1.CaptionForeColor = System.Drawing.SystemColors.ActiveCaption;
			this.dataGrid1.DataMember = "";
			this.dataGrid1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.dataGrid1.ForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGrid1.Location = new System.Drawing.Point(299, 41);
			this.dataGrid1.Name = "dataGrid1";
			this.dataGrid1.PreferredColumnWidth = 100;
			this.dataGrid1.PreferredRowHeight = 30;
			this.dataGrid1.ReadOnly = true;
			this.dataGrid1.Size = new System.Drawing.Size(352, 340);
			this.dataGrid1.TabIndex = 1;
			// 
			// label1
			// 
			this.label1.AutoSize = true;
			this.label1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label1.ForeColor = System.Drawing.SystemColors.ControlText;
			this.label1.Location = new System.Drawing.Point(11, 10);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(145, 21);
			this.label1.TabIndex = 2;
			this.label1.Text = "专业/班级/学期选择";
			// 
			// label2
			// 
			this.label2.AutoSize = true;
			this.label2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label2.ForeColor = System.Drawing.SystemColors.ControlText;
			this.label2.Location = new System.Drawing.Point(299, 10);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(67, 21);
			this.label2.TabIndex = 3;
			this.label2.Text = "课程浏览";
			// 
			// button1
			// 
			this.button1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.button1.ForeColor = System.Drawing.SystemColors.ControlText;
			this.button1.Location = new System.Drawing.Point(299, 401);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(117, 31);
			this.button1.TabIndex = 4;
			this.button1.Text = "修改班级课程";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// button2
			// 
			this.button2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.button2.ForeColor = System.Drawing.SystemColors.ControlText;
			this.button2.Location = new System.Drawing.Point(576, 401);
			this.button2.Name = "button2";
			this.button2.Size = new System.Drawing.Size(64, 31);
			this.button2.TabIndex = 5;
			this.button2.Text = "退出";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// button3
			// 
			this.button3.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.button3.ForeColor = System.Drawing.SystemColors.ControlText;
			this.button3.Location = new System.Drawing.Point(437, 401);
			this.button3.Name = "button3";
			this.button3.Size = new System.Drawing.Size(118, 31);
			this.button3.TabIndex = 6;
			this.button3.Text = "删除班级课程";
			this.button3.Click += new System.EventHandler(this.button3_Click);
			// 
			// oleDbConnection1
			// 
			this.oleDbConnection1.ConnectionString = "Data Source=xsxxdb.mdb;Jet OLEDB:Engine Type=5;Provider=Microsoft.Jet." +
				"OLEDB.4.0;";
			// 
			// oleDbConnection2
			// 
			this.oleDbConnection2.ConnectionString = "Data Source=xsxxdb.mdb;Jet OLEDB:Engine Type=5;Provider=Microsoft.Jet." +
				"OLEDB.4.0;";
			// 
			// oleDbConnection3
			// 
			this.oleDbConnection3.ConnectionString = "Data Source=xsxxdb.mdb;Jet OLEDB:Engine Type=5;Provider=Microsoft.Jet." +
				"OLEDB.4.0;";
			// 
			// kcll
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(8, 18);
			this.ClientSize = new System.Drawing.Size(664, 440);
			this.Controls.Add(this.button3);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.dataGrid1);
			this.Controls.Add(this.treeView1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.Name = "kcll";
			this.Text = "课程信息浏览";
			this.Load += new System.EventHandler(this.BrowseCourse_Load);
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		private void BrowseCourse_Load(object sender, System.EventArgs e)
		{
			//OleDbConnection cn1,cn2,cn3;
			//cn1=new OleDbConnection("Data Source=D:/学生学籍管理系统/book/xsxxdb.mdb;Jet OLEDB:Engine Type=5;Provider=Microsoft.Jet.OLEDB.4.0");
			//cn2=new OleDbConnection("Data Source=D:/学生学籍管理系统/book/xsxxdb.mdb;Jet OLEDB:Engine Type=5;Provider=Microsoft.Jet.OLEDB.4.0");
			//cn3=new OleDbConnection("Data Source=D:/学生学籍管理系统/book/xsxxdb.mdb;Jet OLEDB:Engine Type=5;Provider=Microsoft.Jet.OLEDB.4.0");
			
			OleDbCommand cmd1,cmd2,cmd3;
			cmd1=new OleDbCommand("",oleDbConnection1);
			cmd2=new OleDbCommand("",oleDbConnection2);
			cmd3=new OleDbCommand("",oleDbConnection3);
			OleDbDataReader rd1,rd2,rd3;
			string sql;
			sql="select specialtyname from specialtyinfo";
			cmd1.CommandText=sql;
			oleDbConnection1.Open();
			
			rd1=cmd1.ExecuteReader();
			while (rd1.Read())
			{
				TreeNode node=new TreeNode();
				node.Text=rd1.GetString(0).ToString();
				treeView1.Nodes.Add(node);
				oleDbConnection2.Open();
                sql="select classid,classname from classinfo where specialtyname='"+node.Text+"' order by classname desc";
				cmd2.CommandText=sql;
				rd2=cmd2.ExecuteReader();
				while (rd2.Read())
				{
					TreeNode node1=new TreeNode();
					node1.Text=rd2.GetString(1);
					node.Nodes.Add(node1);
					oleDbConnection3.Open();
					sql="select distinct semester from courseinfo inner join classinfo on courseinfo.classid=classinfo.classid where classinfo.classname='"+node1.Text+"'";
					cmd3.CommandText=sql;
					rd3=cmd3.ExecuteReader();
					while (rd3.Read())
					{
						TreeNode node2=new TreeNode();
						node2.Text=(Int32.Parse(rd3.GetValue(0).ToString())/10)+"至"+(Int32.Parse(rd3.GetValue(0).ToString())/10+1)+"年度第"+(Int32.Parse(rd3.GetValue(0).ToString())%10)+"学期";
				        node2.Tag=rd3.GetValue(0);
						node1.Nodes.Add(node2);
					}
					rd3.Close();
					oleDbConnection3.Close();
				}
				rd2.Close();
				oleDbConnection2.Close();
			}
			rd1.Close();
			oleDbConnection1.Close();
		}
        DataSet ds;
		private void treeView1_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
		{
			string sql="";
			//OleDbConnection oleDbConnection1;
			//oleDbConnection1=new OleDbConnection("Data Source=D:/学生学籍管理系统/book/xsxxdb.mdb;Jet OLEDB:Engine Type=5;Provider=Microsoft.Jet.OLEDB.4.0");
			//oleDbConnection1.Open();
			OleDbDataAdapter adp=new OleDbDataAdapter(sql,oleDbConnection1);
			ds=new DataSet();
			ds.Clear();
			oleDbConnection1.Open();
			if (e.Node.Tag!=null)
			{
				sql="select courseinfo.courseid as 自动编号,courseinfo.course as 课程名称 from classinfo inner join courseinfo on courseinfo.classid=classinfo.classid where classinfo.classname='"+e.Node.Parent.Text.ToString()+"' and semester='"+e.Node.Tag.ToString()+"'";
				adp.SelectCommand.CommandText=sql;
				adp.Fill(ds,"class_course");
				dataGrid1.DataSource=ds.Tables[0].DefaultView;
				dataGrid1.CaptionText=e.Node.Parent.Text.ToString()+" "+e.Node.Text+"课程表";
			}
			else
			{
				dataGrid1.DataSource=null;
				dataGrid1.CaptionText="";
			}
			oleDbConnection1.Close();
		}

		private void treeView1_Click(object sender, System.EventArgs e)
		{
			
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			if (dataGrid1.DataSource!=null && dataGrid1[dataGrid1.CurrentCell]!=null)
			{
			    ModifyCourse modifycourse=new ModifyCourse();
			    
			    modifycourse.Tag=ds.Tables[0].Rows[dataGrid1.CurrentCell.RowNumber][0].ToString().Trim();
				
				modifycourse.ShowDialog();
			}
			else
				MessageBox.Show("没有指定的课程信息","提示");
		}

		private void button3_Click1(object sender, System.EventArgs e)
		{
			dataGrid1.Refresh();
		}

		private void button2_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void button3_Click(object sender, System.EventArgs e)
		{
			oleDbConnection1.Open();
			


			if (ds.Tables[0].Rows.Count!=0 && dataGrid1.CurrentRowIndex>0 && dataGrid1.DataSource!=null && dataGrid1[dataGrid1.CurrentCell]!=null)
			{
				string pd="select * from ((scoreinfo inner join courseinfo on scoreinfo.course=courseinfo.course) inner join  Studentinfo on  studentinfo.studentnumber=scoreinfo.studentnumber) where scoreinfo.semester=courseinfo.semester and studentinfo.classid=courseinfo.classid and courseinfo.courseid="+ds.Tables["class_course"].Rows[dataGrid1.CurrentCell.RowNumber][0].ToString().Trim();
                OleDbCommand cmd=new OleDbCommand(pd,oleDbConnection1);
				OleDbDataReader dr;
				dr=cmd.ExecuteReader();
				if (!dr.Read())
				{
				    dr.Close();
					string sql="delete * from courseinfo where courseid="+ds.Tables["class_course"].Rows[dataGrid1.CurrentCell.RowNumber][0].ToString().Trim();
					cmd.CommandText=sql;
					cmd.ExecuteNonQuery();
					MessageBox.Show("'"+ds.Tables["class_course"].Rows[dataGrid1.CurrentCell.RowNumber][1].ToString().Trim()+"'课程信息删除成功","提示");
				}
				else
                   MessageBox.Show("暂时不能删除该课程,请先删除有关的成绩纪录","提示");
			    dr.Close();
			}
			else
				MessageBox.Show("没有指定的课程信息","提示");
			oleDbConnection1.Close();
		}


	}
}

⌨️ 快捷键说明

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