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

📄 mainform.cs

📁 学生选课系统 可工学生学习用!大家可以互相学习互相借鉴
💻 CS
📖 第 1 页 / 共 5 页
字号:

			if(this.listBox1.Items.Count==0)
				this.outlesson.Enabled=false;
			else
				this.outlesson.Enabled=true;
            restore();
		}
		private bool test(string temp)
		{
			int j=0;
			for(int i=0;i<=this.listBox1.Items.Count-1;i++)
			{
				if(temp==this.listBox1.Items[i].ToString())
					j=1;					
			}
			if(j==1)
				return false;
			else return true;
		}

		private void listBox2_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			//this.listBox1.SelectedIndex=-1;
			this.sqlConnection1.Open();
			//MessageBox.Show(this.listBox2.SelectedItem.ToString());
			this.sqlSelectCommand1.CommandText = "SELECT  CourseInfo.Teacher, CourseInfo.ClassTime, CourseInfo.Credit, ClassRoom.Buliding, ClassRoom.RoomName, CourseInfo.Capacity FROM ClassRoom  INNER JOIN CourseInfo  ON ClassRoom.RoomID = CourseInfo.RoomID where CourseInfo.CourseName='"+this.listBox2.SelectedItem.ToString()+"'";
			SqlDataReader db;
			try
			{				
				db=this.sqlSelectCommand1.ExecuteReader(); 
				if(db.Read())
				{
					this.textBox1.Text=db["Teacher"].ToString();	
					this.textBox2.Text=db["ClassTime"].ToString();
					this.textBox3.Text=db["Credit"].ToString();
					this.textBox4.Text=db["Buliding"].ToString()+db["RoomName"].ToString();
					this.textBox7.Text=db["Capacity"].ToString();
					this.coursecapacitytemp=Convert.ToInt32(db["Capacity"]);
				}
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
			this.sqlConnection1.Close();
						
		}
		//写入数据库***************************************88
		private void button1_Click(object sender, System.EventArgs e)
		{
			//bool ok=true;
			if(timechongtu())
				return;
			SqlDataAdapter dateadapter=new SqlDataAdapter();
			for(int i=0;i<this.coursecapacity.Length;i++)
			{
				if(this.coursecapacity[i]<=0)
				{
					MessageBox.Show("你有不能选的课程请查看课程容量");
					//ok=false;
					break;
				}
			}	
			this.sqlConnection1.Open();
			SqlCommand comm;
			for(int i=0;i<this.listBox1.Items.Count;i++)
			{
				comm=new SqlCommand("insert into coursestudent(id,courseid) values(" + this.id + "," + this.courseid[i] + ") update CourseInfo set Capacity=" + (this.coursecapacity[i]-1).ToString() + " where CourseID="+this.courseid[i],this.sqlConnection1);

				try
				{
					comm.ExecuteNonQuery();	
				}
				catch(Exception ex)
				{
					MessageBox.Show(ex.Message);
				}

			}
			this.sqlConnection1.Close();
			this.selectlesson.Enabled=false;
			this.outlesson.Enabled=false;

			MessageBox.Show("选课成功");
		}
		//*******************************

		private void button1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if(this.listBox1.Items.Count==0)
				MessageBox.Show("你还没有选课");
			else
				if(Convert.ToInt32(this.textBox9.Text)<Convert.ToInt32(this.textBox8.Text))
				MessageBox.Show("注意:\t你所选的学分不够最底限度");		
		}

		private void print_Click(object sender, System.EventArgs e)
		{	
			this.printAdapter.SelectCommand .CommandText ="SELECT CourseInfo.CourseName,ClassRoom.Buliding,ClassRoom.RoomName, CourseInfo.ClassTime, CourseInfo.Teacher FROM ClassRoom INNER JOIN CourseInfo ON ClassRoom.RoomID = CourseInfo.RoomID INNER JOIN CourseStudent ON CourseInfo.CourseID = CourseStudent.CourseID INNER JOIN StudentInfo ON StudentInfo.ID = CourseStudent.ID where StudentInfo.id="+this.id.ToString();
			//sqlDataAdapter1.SelectCommand .CommandText ="SELECT StudentInfo.name, ClassRoom.RoomID, ClassRoom.RoomName, ClassRoom.Buliding, CourseInfo.CourseName, CourseInfo.CourseID, CourseInfo.ClassTime, CourseInfo.Teacher FROM ClassRoom INNER JOIN CourseInfo ON ClassRoom.RoomID = CourseInfo.RoomID INNER JOIN CourseStudent ON CourseInfo.CourseID = CourseStudent.CourseID INNER JOIN StudentInfo ON StudentInfo.ID = CourseStudent.ID where StudentInfo.id="+this.id.ToString();
			//this.s
			try
			{
				this.dataSet41.Clear();
				this.printAdapter.Fill(dataSet41,"ClassRoom");
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
			
		}

		private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			this.outlesson.Enabled=true;
		}
//退课函数
		private void like()
		{
			SqlCommand comm=new SqlCommand(" select distinct coursename from coursestudent,courseinfo where coursestudent.courseid=courseinfo.courseid and  coursestudent.courseid =(select top 1 courseid  from coursestudent,studentinfo  where sex='男'and studentinfo.id=coursestudent.id group by courseid  order by count(*) desc) ",this.sqlConnection1);
			this.sqlConnection1.Open();
			SqlDataReader dr=comm.ExecuteReader();
			if(dr.Read())
				this.textBox6.Text=dr["coursename"].ToString();
			dr.Close();
			this.sqlConnection1.Close();
			
			SqlCommand comm1=new SqlCommand(" select distinct coursename from coursestudent,courseinfo where coursestudent.courseid=courseinfo.courseid and  coursestudent.courseid =(select top 1 courseid  from coursestudent,studentinfo  where sex='女'and studentinfo.id=coursestudent.id group by courseid  order by count(*) desc) ",this.sqlConnection1);
			this.sqlConnection1.Open();
			SqlDataReader dr1=comm1.ExecuteReader();
			try
			{
				dr1.Read();
				this.textBox5.Text=dr1["coursename"].ToString();
			}
			catch(Exception ex)
			{
				//MessageBox.Show(ex.Message);
			}
			dr1.Close();  
			this.sqlConnection1.Close();
		}
		private bool timechongtu()
		{
			for(int i=0;(i<this.time.Length) && (this.time[i+1]!="0000");i++)
			{
				for(int j=i;(j<this.time.Length-1) && (this.time[j+1]!=null);j++)
					if(this.time[i]==this.time[j+1])
					{
						MessageBox.Show("所选课程上课时间有冲突");
						return true;
					}
			}
			return false;
		}

		private void orderbyscore_Click(object sender, System.EventArgs e)
		{
			try
			{
				this.dataSet41.Clear();
				this.scoreadapter.Fill(this.dataSet41,"StudentInfo");
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
			this.dataGridscore.Visible=true;
			this.dataGrid2.Visible=false;
			this.dataGridrenci.Visible=false;
		}

		private void orderbyperson_Click(object sender, System.EventArgs e)
		{
			try
			{
				this.dataSet41.Clear();
				this.zongfenAdapter.Fill(this.dataSet41,"CourseInfo");
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
			this.dataGridrenci.Visible=true;
			this.dataGrid2.Visible=false;
			this.dataGridscore.Visible=false;
		}
		private void restore()
		{
			this.index=0;
			this.index1=0;
			this.index2=0;
			for(int i=0;i<this.time.Length;i++)
			{
				time[i]="0000";
				this.courseid[i]=10000;
				this.coursecapacity[i]=10000;
			}
			this.sqlConnection1.Open();
			for(int i=0;i<this.listBox1.Items.Count;i++)
			{
				//MessageBox.Show(this.listBox2.SelectedItem.ToString());
				this.sqlSelectCommand1.CommandText = "SELECT  CourseInfo.Credit,CourseInfo.CourseID, CourseInfo.Capacity, CourseInfo.ClassTime FROM  CourseInfo  where CourseInfo.CourseName='"+this.listBox1.Items[i].ToString()+"'";
				SqlDataReader db;
				db=this.sqlSelectCommand1.ExecuteReader();
				try
				{
					if(db.Read())
					{
						this.courseid[index++]=Convert.ToInt32(db["CourseID"]);
						this.coursecapacity[index1++]=Convert.ToInt32(db["Capacity"]);
						this.time[index2++]=Convert.ToString(db["ClassTime"]);
					}
				}
				catch(Exception ex)
				{
					MessageBox.Show(ex.Message);
				}
				db.Close();
			}
			this.sqlConnection1.Close();
		}

		private void updatemima_Click(object sender, System.EventArgs e)
		{
			//bool bo=false;
			string mima=null;
			mima=dumima();
			if(mima.ToString()!=this.textBox12.Text)
			{				
				MessageBox.Show("原始密码输入不正确");
				this.textBox12.Text="";
			}
			else
			{
				if(this.textBox10.Text.Trim()!=this.textBox11.Text.Trim())
				{
					MessageBox.Show("两次密码输入不一样");
					this.textBox10.Text="";
					this.textBox11.Text="";
				}
				else
				{
					this.sqlConnection1.Open();
					try
					{
						SqlCommand cmd=new SqlCommand("update StudentInfo set mima='"+this.textBox10.Text.ToString().Trim()+"' where ID="+this.id+" ",this.sqlConnection1);
						cmd.ExecuteNonQuery();
						MessageBox.Show("密码修改成功");						
					}
					catch(Exception ex)
					{
						MessageBox.Show(ex.Message);
					}	
				    this.textBox12.Text="";
					this.textBox10.Text="";
					this.textBox11.Text="";			
					this.sqlConnection1.Close();			
				}	
			}
		}
		private string dumima()
		{
			string mima=null;
			//this.sqlConnection1.Open();
			SqlCommand cmd1;//=new SqlCommand("select mima from StudentInfo where ID="+this.id+"",this.sqlConnection1);
			SqlDataReader drr;
			try
			{
				cmd1=new SqlCommand("select mima from StudentInfo where ID="+this.id+"",this.sqlConnection1);
				this.sqlConnection1.Open();
				drr=cmd1.ExecuteReader();
				if(drr.Read())
					mima=drr["mima"].ToString().Trim();
				drr.Close();
			
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.Message);				
			}
			this.sqlConnection1.Close();	
			return mima;
		}
	}
}

⌨️ 快捷键说明

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