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

📄 score.cs

📁 c#写图书管理系统 界面美观 功能齐全 配有完整的数据库
💻 CS
📖 第 1 页 / 共 2 页
字号:
			this.dataGrid1.Location = new System.Drawing.Point(32, 144);
			this.dataGrid1.Name = "dataGrid1";
			this.dataGrid1.ParentRowsBackColor = System.Drawing.Color.Lavender;
			this.dataGrid1.ParentRowsForeColor = System.Drawing.Color.MidnightBlue;
			this.dataGrid1.SelectionBackColor = System.Drawing.Color.Teal;
			this.dataGrid1.SelectionForeColor = System.Drawing.Color.PaleGreen;
			this.dataGrid1.Size = new System.Drawing.Size(360, 336);
			this.dataGrid1.TabIndex = 108;
			this.dataGrid1.TableStyles.AddRange(new System.Windows.Forms.DataGridTableStyle[] {
																								  this.dataGridTableStyle1});
			// 
			// dataGridTableStyle1
			// 
			this.dataGridTableStyle1.DataGrid = this.dataGrid1;
			this.dataGridTableStyle1.GridColumnStyles.AddRange(new System.Windows.Forms.DataGridColumnStyle[] {
																												  this.dataGridTextBoxColumn1,
																												  this.dataGridTextBoxColumn3,
																												  this.dataGridTextBoxColumn2});
			this.dataGridTableStyle1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGridTableStyle1.MappingName = "Score";
			// 
			// dataGridTextBoxColumn1
			// 
			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;
			// 
			// Score
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.BackColor = System.Drawing.SystemColors.Control;
			this.ClientSize = new System.Drawing.Size(656, 501);
			this.Controls.Add(this.dataGrid1);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.btnApply);
			this.Controls.Add(this.btnExit);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.comboCourse);
			this.ForeColor = System.Drawing.SystemColors.Desktop;
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Name = "Score";
			this.Text = "成绩录入";
			this.Load += new System.EventHandler(this.Score_Load);
			this.groupBox1.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			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)
		{
			this.comboClass.Items.Clear();
			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 Class='"+this.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();				
			}
			catch(Exception E)
			{
				this.ErrorHandle(E);
			}
			finally
			{
				this.conn1.Close();					
				
			}	
		}

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

⌨️ 快捷键说明

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