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

📄 score.cs

📁 c# + sql2000 学生管理系统
💻 CS
📖 第 1 页 / 共 2 页
字号:
            // 
            this.dataGridTextBoxColumn1.Format = "";
            this.dataGridTextBoxColumn1.FormatInfo = null;
            this.dataGridTextBoxColumn1.HeaderText = "课程";
            this.dataGridTextBoxColumn1.MappingName = "Course";
            this.dataGridTextBoxColumn1.ReadOnly = true;
            this.dataGridTextBoxColumn1.Width = 150;
            // 
            // dataGridTextBoxColumn3
            // 
            this.dataGridTextBoxColumn3.Format = "";
            this.dataGridTextBoxColumn3.FormatInfo = null;
            this.dataGridTextBoxColumn3.HeaderText = "学号";
            this.dataGridTextBoxColumn3.MappingName = "StudentID";
            this.dataGridTextBoxColumn3.ReadOnly = true;
            this.dataGridTextBoxColumn3.Width = 75;
            // 
            // dataGridTextBoxColumn2
            // 
            this.dataGridTextBoxColumn2.Format = "";
            this.dataGridTextBoxColumn2.FormatInfo = null;
            this.dataGridTextBoxColumn2.HeaderText = "成绩";
            this.dataGridTextBoxColumn2.MappingName = "Score";
            this.dataGridTextBoxColumn2.NullText = "";
            this.dataGridTextBoxColumn2.Width = 75;
            // 
            // button2
            // 
            this.button2.ForeColor = System.Drawing.Color.DarkGreen;
            this.button2.Location = new System.Drawing.Point(53, 95);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(74, 35);
            this.button2.TabIndex = 109;
            this.button2.Text = "添加、修改";
            this.button2.UseVisualStyleBackColor = true;
            this.button2.Click += new System.EventHandler(this.button2_Click_1);
            // 
            // groupBox2
            // 
            this.groupBox2.Controls.Add(this.button1);
            this.groupBox2.Controls.Add(this.label1);
            this.groupBox2.Controls.Add(this.comboCourse);
            this.groupBox2.Location = new System.Drawing.Point(391, 6);
            this.groupBox2.Name = "groupBox2";
            this.groupBox2.Size = new System.Drawing.Size(194, 122);
            this.groupBox2.TabIndex = 110;
            this.groupBox2.TabStop = false;
            // 
            // groupBox3
            // 
            this.groupBox3.Controls.Add(this.button2);
            this.groupBox3.Controls.Add(this.btnApply);
            this.groupBox3.Location = new System.Drawing.Point(391, 159);
            this.groupBox3.Name = "groupBox3";
            this.groupBox3.Size = new System.Drawing.Size(193, 146);
            this.groupBox3.TabIndex = 111;
            this.groupBox3.TabStop = false;
            // 
            // Score
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
            this.BackColor = System.Drawing.SystemColors.Control;
            this.ClientSize = new System.Drawing.Size(597, 505);
            this.Controls.Add(this.groupBox3);
            this.Controls.Add(this.groupBox2);
            this.Controls.Add(this.dataGrid1);
            this.Controls.Add(this.btnExit);
            this.Controls.Add(this.groupBox1);
            this.ForeColor = System.Drawing.SystemColors.Desktop;
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.MaximizeBox = false;
            this.Name = "Score";
            this.Text = "成绩载入";
            this.Load += new System.EventHandler(this.Score_Load);
            this.groupBox1.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
            this.groupBox2.ResumeLayout(false);
            this.groupBox3.ResumeLayout(false);
            this.ResumeLayout(false);

		}
		#endregion


		private void Combo_Fill()
		{   
			
			try
			{
				if(this.conn1.State==ConnectionState.Closed)this.conn1.Open();						
				this.commandStr="select DepartmentName from Department";									
				this.Command1.CommandText=this.commandStr;
				this.DataReader1=this.Command1.ExecuteReader();
				while(this.DataReader1.Read())
				{
					this.comboDepartment.Items.Add(this.DataReader1["DepartmentName"].ToString());
					
				}
				this.DataReader1.Close();	
				this.commandStr="select SemesterName from Semester";									
				this.Command1.CommandText=this.commandStr;
				this.DataReader1=this.Command1.ExecuteReader();
				while(this.DataReader1.Read())
				{
					this.comboSemester.Items.Add(this.DataReader1["SemesterName"].ToString());
					
				}
				this.DataReader1.Close();				

			}

			catch(Exception E)
			{
				MessageBox.Show(E.ToString());
			}
			finally
			{
				this.conn1.Close();			
			}				

		}

		private void comboDepartment_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			try
			{
				this.conn1.Open();						
				this.commandStr="select ClassName from Class where DepartmentName="+"'"+this.comboDepartment.Text+"'";									
				this.Command1.CommandText=this.commandStr;
				this.DataReader1=this.Command1.ExecuteReader();
				while(this.DataReader1.Read())
				{
					this.comboClass.Items.Add(this.DataReader1["ClassName"].ToString());					
				}
				this.DataReader1.Close();				
				
			}
			catch(Exception E)
			{
				MessageBox.Show(E.ToString());
			}
			finally
			{
				this.DataReader1.Close();
				this.conn1.Close();	
			}		
		}

		private void Score_Load(object sender, System.EventArgs e)
		{
			this.Combo_Fill();
		}

		private void btnOk_Click(object sender, System.EventArgs e)
		{	
			
			this.comboCourse.Items.Clear();
			try
			{
				if(this.conn1.State==ConnectionState.Closed)this.conn1.Open();						
				this.commandStr="select Course from SelectCourse where Class='"+this.comboClass.Text+"' and Semester='"+this.comboSemester.Text+"'";
				this.Command1.CommandText=this.commandStr;
				this.DataReader1=this.Command1.ExecuteReader();
				while(this.DataReader1.Read())
				{
					this.comboCourse.Items.Add(this.DataReader1["Course"].ToString());
					
				}
				this.DataReader1.Close();								

			}

			catch(Exception E)
			{
				MessageBox.Show(E.ToString());
			}
			finally
			{
				this.conn1.Close();			
			}				
			
		}

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

		private void button1_Click(object sender, System.EventArgs e)
		{
            this.selectStr = "select * from Score where Course='" + this.comboCourse.Text + "'and Class='" + comboClass.Text+"'";			
			this.sqlDataAdapter1=new SqlDataAdapter(this.selectStr,this.conn1);
			this.DataSetScore.Clear();
			this.sqlDataAdapter1.Fill(this.DataSetScore,"Score");
		
			if(this.DataSetScore.Tables[0].Rows.Count==0)
			{
				try
				{
					if(this.conn1.State==ConnectionState.Closed)this.conn1.Open();						
					this.commandStr="select StudentID from Student where Class='"+this.comboClass.Text+"'";
					this.Command1.CommandText=this.commandStr;
					this.DataReader1=this.Command1.ExecuteReader();
					while(this.DataReader1.Read())
					{
					
						DataRow newrow;
						newrow=this.DataSetScore.Tables[0].NewRow();
						newrow["StudentID"]=DataReader1[0].ToString();						
						newrow["Class"]=this.comboClass.Text;
						newrow["Course"]=this.comboCourse.Text;
						newrow["Score"]=0;
						this.DataSetScore.Tables[0].Rows.Add(newrow);
					
					}
					this.DataReader1.Close();			

				}

				catch(Exception E)
				{
					MessageBox.Show(E.ToString());
				}
				finally
				{
					this.conn1.Close();			
				}	

			}
			this.dataGrid1.DataSource=this.DataSetScore;
			this.dataGrid1.DataMember="Score";	
		
		}

		private void btnApply_Click(object sender, System.EventArgs e)
		{
			try
			{	
				this.BindingContext[this.DataSetScore,"Score"].EndCurrentEdit();
				if(this.conn1.State==ConnectionState.Closed)
					this.conn1.Open();
				SqlCommandBuilder commandbuilder1=new SqlCommandBuilder(this.sqlDataAdapter1);
				this.sqlDataAdapter1.Update(this.DataSetScore,"Score");
				this.DataSetScore.AcceptChanges();
                MessageBox.Show("提交成功!!");
			}
			catch(Exception E)
			{
				this.ErrorHandle(E);
			}
			finally
			{
				this.conn1.Close();					
				
			}	
		}

		
		public void ErrorHandle(System.Exception E)
		{
			MessageBox.Show(E.ToString());
		}

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            
        }

        private void button2_Click_1(object sender, EventArgs e)
        {

            Form FormDep = new Form4();
            FormDep.Show();
        }

        private void comboClass_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
	}
}

⌨️ 快捷键说明

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