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

📄 frmaddpro.cs

📁 一个学籍管理系统 以在某高校投入使用了
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace prjClass
{
	/// <summary>
	/// frmAddPro 的摘要说明。
	/// </summary>
	public class frmAddPro : System.Windows.Forms.Form
	{
		Class1 c = new Class1();
		DataAccess da = new DataAccess();
		ClassInfo class1 = new ClassInfo();
		private System.Windows.Forms.Button btnOK;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.StatusBar statusBar1;
		private System.Windows.Forms.StatusBarPanel statusBarPanel1;
		private System.Windows.Forms.StatusBarPanel statusBarPanel2;
		private System.Windows.Forms.StatusBarPanel statusBarPanel3;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.ComboBox cboSpe;
		private System.Windows.Forms.ComboBox cboclass;
		private System.Windows.Forms.ComboBox cboSeme;
		private System.Windows.Forms.TextBox txtYear;
		private System.Windows.Forms.TextBox txtProName;
		private System.Windows.Forms.Button btnCancle;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmAddPro()
		{
			//
			// 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.btnOK = new System.Windows.Forms.Button();
			this.label1 = new System.Windows.Forms.Label();
			this.statusBar1 = new System.Windows.Forms.StatusBar();
			this.statusBarPanel1 = new System.Windows.Forms.StatusBarPanel();
			this.statusBarPanel2 = new System.Windows.Forms.StatusBarPanel();
			this.statusBarPanel3 = new System.Windows.Forms.StatusBarPanel();
			this.cboSpe = new System.Windows.Forms.ComboBox();
			this.cboclass = new System.Windows.Forms.ComboBox();
			this.cboSeme = new System.Windows.Forms.ComboBox();
			this.txtYear = new System.Windows.Forms.TextBox();
			this.txtProName = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.label5 = new System.Windows.Forms.Label();
			this.label6 = new System.Windows.Forms.Label();
			this.btnCancle = new System.Windows.Forms.Button();
			((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.statusBarPanel2)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.statusBarPanel3)).BeginInit();
			this.SuspendLayout();
			// 
			// btnOK
			// 
			this.btnOK.Location = new System.Drawing.Point(104, 240);
			this.btnOK.Name = "btnOK";
			this.btnOK.TabIndex = 0;
			this.btnOK.Text = "确定";
			this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(224, 24);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(136, 16);
			this.label1.TabIndex = 11;
			this.label1.Text = "添加班级课程";
			// 
			// statusBar1
			// 
			this.statusBar1.Location = new System.Drawing.Point(0, 287);
			this.statusBar1.Name = "statusBar1";
			this.statusBar1.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
																						  this.statusBarPanel1,
																						  this.statusBarPanel2,
																						  this.statusBarPanel3});
			this.statusBar1.ShowPanels = true;
			this.statusBar1.Size = new System.Drawing.Size(538, 22);
			this.statusBar1.TabIndex = 12;
			this.statusBar1.Text = "statusBar1";
			// 
			// statusBarPanel1
			// 
			this.statusBarPanel1.Width = 180;
			// 
			// statusBarPanel2
			// 
			this.statusBarPanel2.Width = 180;
			// 
			// statusBarPanel3
			// 
			this.statusBarPanel3.Width = 180;
			// 
			// cboSpe
			// 
			this.cboSpe.Location = new System.Drawing.Point(104, 56);
			this.cboSpe.Name = "cboSpe";
			this.cboSpe.Size = new System.Drawing.Size(152, 20);
			this.cboSpe.TabIndex = 1;
			this.cboSpe.Text = "comboBox1";
			this.cboSpe.SelectedIndexChanged += new System.EventHandler(this.cboSpe_SelectedIndexChanged);
			// 
			// cboclass
			// 
			this.cboclass.Location = new System.Drawing.Point(336, 56);
			this.cboclass.Name = "cboclass";
			this.cboclass.Size = new System.Drawing.Size(152, 20);
			this.cboclass.TabIndex = 2;
			this.cboclass.Text = "comboBox2";
			this.cboclass.SelectedIndexChanged += new System.EventHandler(this.cboclass_SelectedIndexChanged);
			// 
			// cboSeme
			// 
			this.cboSeme.Location = new System.Drawing.Point(336, 116);
			this.cboSeme.Name = "cboSeme";
			this.cboSeme.Size = new System.Drawing.Size(152, 20);
			this.cboSeme.TabIndex = 4;
			this.cboSeme.Text = "comboBox3";
			this.cboSeme.TextChanged += new System.EventHandler(this.cboSeme_TextChanged);
			// 
			// txtYear
			// 
			this.txtYear.Location = new System.Drawing.Point(104, 116);
			this.txtYear.Name = "txtYear";
			this.txtYear.Size = new System.Drawing.Size(152, 21);
			this.txtYear.TabIndex = 3;
			this.txtYear.Text = "";
			this.txtYear.TextChanged += new System.EventHandler(this.txtYear_TextChanged);
			this.txtYear.Leave += new System.EventHandler(this.txtYear_Leave);
			// 
			// txtProName
			// 
			this.txtProName.Location = new System.Drawing.Point(104, 176);
			this.txtProName.Name = "txtProName";
			this.txtProName.Size = new System.Drawing.Size(384, 21);
			this.txtProName.TabIndex = 5;
			this.txtProName.Text = "";
			this.txtProName.TextChanged += new System.EventHandler(this.textBox2_TextChanged);
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(56, 56);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(48, 16);
			this.label2.TabIndex = 13;
			this.label2.Text = "专业";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(296, 56);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(40, 16);
			this.label3.TabIndex = 14;
			this.label3.Text = "班级";
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(40, 116);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(64, 16);
			this.label4.TabIndex = 15;
			this.label4.Text = "入学年份";
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(296, 120);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(40, 16);
			this.label5.TabIndex = 16;
			this.label5.Text = "学期";
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(40, 176);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(64, 16);
			this.label6.TabIndex = 17;
			this.label6.Text = "课程名称";
			// 
			// btnCancle
			// 
			this.btnCancle.Location = new System.Drawing.Point(344, 240);
			this.btnCancle.Name = "btnCancle";
			this.btnCancle.TabIndex = 18;
			this.btnCancle.Text = "取消";
			this.btnCancle.Click += new System.EventHandler(this.btnCancle_Click);
			// 
			// frmAddPro
			// 
			this.AcceptButton = this.btnOK;
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(538, 309);
			this.Controls.Add(this.btnCancle);
			this.Controls.Add(this.label6);
			this.Controls.Add(this.label5);
			this.Controls.Add(this.label4);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.txtProName);
			this.Controls.Add(this.txtYear);
			this.Controls.Add(this.cboSeme);
			this.Controls.Add(this.cboclass);
			this.Controls.Add(this.cboSpe);
			this.Controls.Add(this.statusBar1);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.btnOK);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.MaximizeBox = false;
			this.Name = "frmAddPro";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "添加课程";
			this.Load += new System.EventHandler(this.frmAddPro_Load);
			((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.statusBarPanel2)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.statusBarPanel3)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		private void textBox2_TextChanged(object sender, System.EventArgs e)
		{
			this.statusBarPanel3.Text=this.txtProName.Text;
		}

		private void frmAddPro_Load(object sender, System.EventArgs e)
		{
			string Sql = "select * from Class..SpecialtyInfo";
			string table = "SpecialtyInfo";
			if(c.IsExits(Sql)==false)
			{
				this.cboSpe.Items.Add("尚未添加专业");
				this.btnOK.Enabled=false;
			}
			else
			{
				this.cboSpe.DataSource=da.ExecuteDataTable(Sql,table);
				this.cboSpe.DisplayMember="SpecialtyName";
			}
			this.cboSpe.SelectedIndex=0;
			this.cboclass.Items.Add("请输入专业与入学年份");
			this.cboSeme.Items.Add("请输入班级信息");
			this.cboclass.SelectedIndex=0;
			this.cboSeme.SelectedIndex=0;
		}

		/// <summary>
		/// 为学期附值
		/// </summary>
		private void getSeme(int year,int length)
		{
			for(int i=0;i<length;i++)
			{
				for(int j=1;j<=2;j++)
				{
					int Year =year+i; 
					this.cboSeme.Items.Add(Year.ToString()+j.ToString());
				}
			}
		}
		private void txtYear_TextChanged(object sender, System.EventArgs e)
		{
			if(c.IsYear(this.txtYear.Text)==true&&this.txtYear.Text.Length==4)
			{
				string Sql = "select * from Class..ClassInfo where SpecialtyName = '"+this.cboSpe.Text+"' and year(BeginTime)='"+this.txtYear.Text+"'";
				if(c.IsExits(Sql)==true)
				{
					this.cboSeme.Items.Clear();
					string table = "ClassInfo";
					this.cboclass.DataSource=da.ExecuteDataTable(Sql,table);
					this.cboclass.DisplayMember="ClassName";
					this.cboclass.ValueMember="ClassID";
					this.cboclass.SelectedIndex=0;
					this.btnOK.Enabled=true;
					class1.Year=c.getData(Sql,4);
					this.getSeme(int.Parse(this.txtYear.Text),int.Parse(class1.Year));
					this.cboSeme.SelectedIndex=0;
				}
				else
				{
					this.cboclass.DataSource=null;
					this.cboSeme.Items.Clear();
					this.cboclass.Items.Add("未找到相应班级");
					this.cboSeme.Items.Add("请输入班级信息");
					this.cboclass.SelectedIndex=0;
					this.cboSeme.SelectedIndex=0;
					this.btnOK.Enabled=false;
				}
			}
		}

		private void txtYear_Leave(object sender, System.EventArgs e)
		{
			if(c.IsYear(this.txtYear.Text)==false||this.txtYear.Text.Length!=4)
			{
				MessageBox.Show("请填写正确年份","提示信息!",MessageBoxButtons.OK,MessageBoxIcon.Question);
			}
		}

		private void cboclass_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			this.statusBarPanel1.Text=this.cboclass.Text;
		}
		private void cboSeme_TextChanged(object sender, System.EventArgs e)
		{
			if(this.cboSeme.Text!="请输入班级信息")
			{
				int Seme = int.Parse(this.cboSeme.Text);
				int year = Seme/10;
				int nextyear = year+1;
				int seme = Seme%10;
				this.statusBarPanel2.Text=year.ToString()+"-"+nextyear.ToString()+"年度第"+seme.ToString()+"学期";
			}
			else
			{
				this.statusBarPanel2.Text="请输入班级信息";
			}
		}

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

		private void btnOK_Click(object sender, System.EventArgs e)
		{
			string Sql = "select * from Class..CourseInfo where ClassID = '"+this.cboclass.SelectedValue+"' and Course = '"+this.txtProName.Text+"' and Semester = '"+this.cboSeme.Text+"'";
			if(c.IsExits(Sql)==true)
			{
				MessageBox.Show("在同一个班级同一个学期不能添加相同的课程","提示信息!",MessageBoxButtons.OK,MessageBoxIcon.Question);
			}
			else
			{
				string SqlIns = "insert into Class..CourseInfo values('"+this.cboclass.SelectedValue+"','"+this.txtProName.Text+"','"+this.cboSeme.Text+"')";
				c.EditData(SqlIns);
				ArrayList a = new ArrayList();
				string Sql1 = "select * from Class..StudentInfo where ClassID = (select ClassID from Class..ClassInfo where ClassName = '"+this.cboclass.Text+"')";
				a=c.getDatas(Sql1,1);
				for(int i = 0;i<a.Count;i++)
				{
					string Sql2="insert into Class..ScoreInfo values('"+this.cboSeme.Text+"','"+a[i].ToString()+"','"+this.txtProName.Text+"',0,'等待录入')";
					c.EditData(Sql2);
				}
					 MessageBox.Show("添加课程成功!","提示信息!",MessageBoxButtons.OK,MessageBoxIcon.Question);
			}
		}

		private void cboSpe_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			string Sql = "select * from Class..ClassInfo where SpecialtyName = '"+this.cboSpe.Text+"' and year(BeginTime)='"+this.txtYear.Text+"'";
			if(c.IsExits(Sql)==true)
			{
				this.cboSeme.Items.Clear();
				string table = "ClassInfo";
				this.cboclass.DataSource=da.ExecuteDataTable(Sql,table);
				this.cboclass.DisplayMember="ClassName";
				this.cboclass.ValueMember="ClassID";
				this.cboclass.SelectedIndex=0;
				this.btnOK.Enabled=true;
				class1.Year=c.getData(Sql,4);
				this.getSeme(int.Parse(this.txtYear.Text),int.Parse(class1.Year));
				this.cboSeme.SelectedIndex=0;
			}
			else
			{
				this.cboclass.DataSource=null;
				this.cboSeme.Items.Clear();
				this.cboclass.Items.Add("未找到相应班级");
				this.cboSeme.Items.Add("请输入班级信息");
				this.cboclass.SelectedIndex=0;
				this.cboSeme.SelectedIndex=0;
				this.btnOK.Enabled=false;
			}
		
		}
	}
}

⌨️ 快捷键说明

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