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

📄 frmpro.cs

📁 一个学籍管理系统 以在某高校投入使用了
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace prjClass
{
	/// <summary>
	/// frmPro 的摘要说明。
	/// </summary>
	public class frmPro : System.Windows.Forms.Form
	{
		Class1 c = new Class1();
		private System.Windows.Forms.Panel panel1;
		private System.Windows.Forms.TreeView treeView1;
		private System.Windows.Forms.DataGrid dataGrid1;
		private System.Windows.Forms.Panel panel2;
		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;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmPro()
		{
			//
			// 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.panel1 = new System.Windows.Forms.Panel();
            this.label2 = new System.Windows.Forms.Label();
            this.label1 = new System.Windows.Forms.Label();
            this.treeView1 = new System.Windows.Forms.TreeView();
            this.dataGrid1 = new System.Windows.Forms.DataGrid();
            this.panel2 = new System.Windows.Forms.Panel();
            this.button3 = new System.Windows.Forms.Button();
            this.button2 = new System.Windows.Forms.Button();
            this.button1 = new System.Windows.Forms.Button();
            this.panel1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
            this.panel2.SuspendLayout();
            this.SuspendLayout();
            // 
            // panel1
            // 
            this.panel1.Controls.Add(this.label2);
            this.panel1.Controls.Add(this.label1);
            this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
            this.panel1.Location = new System.Drawing.Point(0, 0);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(1028, 48);
            this.panel1.TabIndex = 0;
            // 
            // label2
            // 
            this.label2.Location = new System.Drawing.Point(352, 24);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(100, 23);
            this.label2.TabIndex = 1;
            this.label2.Text = "课程浏览";
            // 
            // label1
            // 
            this.label1.Location = new System.Drawing.Point(24, 24);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(120, 23);
            this.label1.TabIndex = 0;
            this.label1.Text = "专业/班级/学期选择";
            // 
            // treeView1
            // 
            this.treeView1.Dock = System.Windows.Forms.DockStyle.Left;
            this.treeView1.Location = new System.Drawing.Point(0, 48);
            this.treeView1.Name = "treeView1";
            this.treeView1.Size = new System.Drawing.Size(241, 621);
            this.treeView1.TabIndex = 1;
            this.treeView1.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterSelect);
            // 
            // dataGrid1
            // 
            this.dataGrid1.DataMember = "";
            this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
            this.dataGrid1.Location = new System.Drawing.Point(0, 0);
            this.dataGrid1.Name = "dataGrid1";
            this.dataGrid1.ReadOnly = true;
            this.dataGrid1.Size = new System.Drawing.Size(818, 488);
            this.dataGrid1.TabIndex = 2;
            this.dataGrid1.CurrentCellChanged += new System.EventHandler(this.dataGrid1_CurrentCellChanged);
            this.dataGrid1.GotFocus += new System.EventHandler(this.dataGrid1_GotFocus);
            // 
            // panel2
            // 
            this.panel2.Controls.Add(this.button3);
            this.panel2.Controls.Add(this.button2);
            this.panel2.Controls.Add(this.button1);
            this.panel2.Controls.Add(this.dataGrid1);
            this.panel2.Dock = System.Windows.Forms.DockStyle.Fill;
            this.panel2.Location = new System.Drawing.Point(241, 48);
            this.panel2.Name = "panel2";
            this.panel2.Size = new System.Drawing.Size(787, 621);
            this.panel2.TabIndex = 3;
            // 
            // button3
            // 
            this.button3.Location = new System.Drawing.Point(496, 560);
            this.button3.Name = "button3";
            this.button3.Size = new System.Drawing.Size(136, 23);
            this.button3.TabIndex = 5;
            this.button3.Text = "取   消";
            this.button3.Click += new System.EventHandler(this.button3_Click);
            // 
            // button2
            // 
            this.button2.Location = new System.Drawing.Point(280, 560);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(136, 23);
            this.button2.TabIndex = 4;
            this.button2.Text = "删除班级课程";
            this.button2.Click += new System.EventHandler(this.button2_Click);
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(40, 560);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(136, 23);
            this.button1.TabIndex = 3;
            this.button1.Text = "修改班级课程";
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // frmPro
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
            this.ClientSize = new System.Drawing.Size(1028, 669);
            this.Controls.Add(this.panel2);
            this.Controls.Add(this.treeView1);
            this.Controls.Add(this.panel1);
            this.Name = "frmPro";
            this.Text = "frmPro";
            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
            this.Load += new System.EventHandler(this.frmPro_Load);
            this.panel1.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
            this.panel2.ResumeLayout(false);
            this.ResumeLayout(false);

		}
		#endregion

		private void frmPro_Load(object sender, System.EventArgs e)
		{
			setDataGridStyle();
			bool flag;
			string Sql = "select * from Class..SpecialtyInfo";
			ArrayList a = c.getDatas(Sql,1);	
			for(int i = 0;i <a.Count;i++ )
			{
				TreeNode node = new TreeNode();
				node.Text=a[i].ToString();
				this.treeView1.Nodes.Add(node);
				string Sql1 = "select * from Class..ClassInfo where SpecialtyName = '"+a[i].ToString()+"'"; 
				ArrayList a1 = c.getDatas(Sql1,1);
				for(int j = 0;j<a1.Count;j++)
				{
					TreeNode node1 = new TreeNode();
					node1.Text=a1[j].ToString();
					node.Nodes.Add(node1);
					string Sql2 = "select * from Class..CourseInfo where ClassID = (select ClassID from Class..ClassInfo where ClassName = '"+a1[j].ToString()+"')";
					ArrayList a2 = c.getDatas(Sql2,3);
					for(int x = 0;x<a2.Count;x++)
					{
						flag = true;
						TreeNode node2 = new TreeNode();
						string seme = a2[x].ToString();
						int year = int.Parse(seme)/10;
						int nextyear = int.Parse(seme)/10+1;
						int s= int.Parse(seme)%10;
						node2.Text=year.ToString()+"至"+nextyear.ToString()+"年度第"+s.ToString()+"学期";
						node2.Tag=a2[x].ToString();

						for(int y = 0;y<node1.Nodes.Count;y++ )
						{
							if(a2[x].ToString()==node1.Nodes[y].Tag.ToString())
							{
								flag=false;
								continue;
							}
						}
						if(flag==true)
						{
							node1.Nodes.Add(node2);
						}
					}
				}
			}
		}

		private void treeView1_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
		{
			if(e.Node.Tag!=null)
			{
				this.dataGrid1.CaptionText=e.Node.Parent.Text+" "+e.Node.Text+"课程表";
				string Sql = "select * from Class..CourseInfo where Semester = '"+e.Node.Tag.ToString()+"' and ClassID = (select ClassID from Class..ClassInfo where ClassName = '"+e.Node.Parent.Text+"')";
				DataAccess da = new DataAccess();
				string table = "CourseInfo";
				this.dataGrid1.DataSource=da.ExecuteDataTable(Sql,table);
			}
		}

		private CourseInfo course = new CourseInfo();
		private void dataGrid1_CurrentCellChanged(object sender, EventArgs e)
		{
			if(this.dataGrid1.VisibleRowCount!=0)
			{
				DataTable dt = (DataTable)this.dataGrid1.DataSource;
				course.CourseID=dt.Rows[this.dataGrid1.CurrentRowIndex][0].ToString();
				course.ClassID=dt.Rows[this.dataGrid1.CurrentRowIndex][1].ToString();
				course.Course=dt.Rows[this.dataGrid1.CurrentRowIndex][2].ToString();
				course.Seme=dt.Rows[this.dataGrid1.CurrentRowIndex][3].ToString();
				flag=true;
			}
		}

		private void dataGrid1_GotFocus(object sender, EventArgs e)
		{
			if(this.dataGrid1.VisibleRowCount!=0)
			{
				DataTable dt = (DataTable)this.dataGrid1.DataSource;
				course.CourseID=dt.Rows[this.dataGrid1.CurrentRowIndex][0].ToString();
				course.ClassID=dt.Rows[this.dataGrid1.CurrentRowIndex][1].ToString();
				course.Course=dt.Rows[this.dataGrid1.CurrentRowIndex][2].ToString();
				course.Seme=dt.Rows[this.dataGrid1.CurrentRowIndex][3].ToString();
				flag=true;
			}
		}

		private bool flag = false;
		private void button1_Click(object sender, System.EventArgs e)
		{
			
			if(this.flag==false)
			{
				MessageBox.Show("请选择要修改的课程信息!","提示信息!",MessageBoxButtons.OK,MessageBoxIcon.Question);
			}
			else
			{
				frmEditPro f = new frmEditPro(this.course);
				f.EditCourseEvent+=new EditCoursehandler(f_EditCourseEvent);
				f.ShowDialog();
			}
		}

		private void f_EditCourseEvent()
		{
			string Sql = "select * from Class..CourseInfo where Semester = '"+this.course.Seme+"' and ClassID = "+this.course.ClassID+"";
			DataAccess da = new DataAccess();
			string table = "CourseInfo";
			this.dataGrid1.DataSource=da.ExecuteDataTable(Sql,table);
			this.flag=false;
		}

		private void setDataGridStyle()
		{
			DataGridTableStyle dgs = new DataGridTableStyle();
			dgs.MappingName="CourseInfo";
			this.dataGrid1.TableStyles.Add(dgs);

			DataGridColumnStyle dgs1 = new DataGridTextBoxColumn();
			dgs1.HeaderText="自动编号";
			dgs1.MappingName="CourseID";
			dgs1.Width=100;

			DataGridColumnStyle dgs2 = new DataGridTextBoxColumn();
			dgs2.HeaderText="课程名称";
			dgs2.MappingName="Course";
			dgs2.Width=100;

			dgs.GridColumnStyles.Add(dgs1);
			dgs.GridColumnStyles.Add(dgs2);
		}
		private void button3_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void button2_Click(object sender, System.EventArgs e)
		{
			string Sql = "select * from ((Class..ScoreInfo inner join Class..CourseInfo on Class..ScoreInfo.Course = Class..CourseInfo.Course) inner join Class..StudentInfo on Class..StudentInfo.StudentNumber = Class..ScoreInfo.StudentNumber) where Class..ScoreInfo.semester = '"+this.course.Seme
				+"' and Class..ScoreInfo.Course = '"+this.course.Course+"' ";

			if(this.flag==false)
			{
				MessageBox.Show("请选择要删除的课程信息!","提示信息!",MessageBoxButtons.OK,MessageBoxIcon.Question);
			}
			else if(c.IsExits(Sql)==true)
			{
				MessageBox.Show("请先删除相关信息!","提示信息!",MessageBoxButtons.OK,MessageBoxIcon.Question);
			}
			else
			{
				string Sql1 = "delete from Class..CourseInfo where CourseID = "+this.course.CourseID+"";
				if(MessageBox.Show("确认删除该课程?","提示信息!",MessageBoxButtons.OKCancel,MessageBoxIcon.Question,MessageBoxDefaultButton.Button2)==DialogResult.OK)
				{
					c.EditData(Sql1);
					f_EditCourseEvent();
				}
			}
		}
	}
}

⌨️ 快捷键说明

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