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

📄 course.cs

📁 c# + sql2000 学生管理系统
💻 CS
📖 第 1 页 / 共 2 页
字号:
            // btnCancel
            // 
            this.btnCancel.Cursor = System.Windows.Forms.Cursors.Hand;
            this.btnCancel.ForeColor = System.Drawing.Color.Black;
            this.btnCancel.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btnCancel.Location = new System.Drawing.Point(112, 24);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new System.Drawing.Size(56, 24);
            this.btnCancel.TabIndex = 101;
            this.btnCancel.Text = "取消";
            this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click_1);
            // 
            // dataGrid1
            // 
            this.dataGrid1.AlternatingBackColor = System.Drawing.Color.White;
            this.dataGrid1.BackColor = System.Drawing.Color.White;
            this.dataGrid1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.dataGrid1.CaptionBackColor = System.Drawing.Color.Teal;
            this.dataGrid1.CaptionFont = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold);
            this.dataGrid1.CaptionForeColor = System.Drawing.Color.White;
            this.dataGrid1.DataMember = "";
            this.dataGrid1.FlatMode = true;
            this.dataGrid1.Font = new System.Drawing.Font("Tahoma", 8F);
            this.dataGrid1.ForeColor = System.Drawing.Color.Black;
            this.dataGrid1.GridLineColor = System.Drawing.Color.Silver;
            this.dataGrid1.HeaderBackColor = System.Drawing.Color.Black;
            this.dataGrid1.HeaderFont = new System.Drawing.Font("Tahoma", 8F);
            this.dataGrid1.HeaderForeColor = System.Drawing.Color.White;
            this.dataGrid1.LinkColor = System.Drawing.Color.Purple;
            this.dataGrid1.Location = new System.Drawing.Point(12, 1);
            this.dataGrid1.Name = "dataGrid1";
            this.dataGrid1.ParentRowsBackColor = System.Drawing.Color.Gray;
            this.dataGrid1.ParentRowsForeColor = System.Drawing.Color.White;
            this.dataGrid1.ReadOnly = true;
            this.dataGrid1.SelectionBackColor = System.Drawing.Color.Maroon;
            this.dataGrid1.SelectionForeColor = System.Drawing.Color.White;
            this.dataGrid1.Size = new System.Drawing.Size(440, 240);
            this.dataGrid1.TabIndex = 5;
            this.dataGrid1.Navigate += new System.Windows.Forms.NavigateEventHandler(this.dataGrid1_Navigate);
            // 
            // groupBox3
            // 
            this.groupBox3.Controls.Add(this.btnApply);
            this.groupBox3.Controls.Add(this.btnCancel);
            this.groupBox3.Location = new System.Drawing.Point(258, 265);
            this.groupBox3.Name = "groupBox3";
            this.groupBox3.Size = new System.Drawing.Size(194, 62);
            this.groupBox3.TabIndex = 103;
            this.groupBox3.TabStop = false;
            // 
            // Course
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
            this.ClientSize = new System.Drawing.Size(467, 485);
            this.Controls.Add(this.groupBox3);
            this.Controls.Add(this.groupBox2);
            this.Controls.Add(this.btnExit);
            this.Controls.Add(this.groupBox1);
            this.Controls.Add(this.dataGrid1);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.MaximizeBox = false;
            this.Name = "Course";
            this.Text = "课程管理";
            this.Load += new System.EventHandler(this.Course_Load);
            this.groupBox2.ResumeLayout(false);
            this.groupBox2.PerformLayout();
            this.groupBox1.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
            this.groupBox3.ResumeLayout(false);
            this.ResumeLayout(false);

		}
		#endregion



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

		private void Course_Load(object sender, System.EventArgs e)
		{
			try
			{
				this.conn1.Open();
				this.sqlDataAdapter1.Fill(this.DataSetDep,"Course");
				this.DataSet_Bingding();
				this.Buttons_Control(false);
				this.Combo_Fill();
			}
			catch(Exception E)
			{
				MessageBox.Show(E.ToString());
			}
			finally
			{
				this.conn1.Close();			
			}
		}
		private void DataSet_Bingding()
		{
			this.dataGrid1.DataSource=this.DataSetDep;
			this.dataGrid1.DataMember="Course";			
			this.textClaID.DataBindings.Add("Text",this.DataSetDep,"Course.CourseID");
			this.textClaName.DataBindings.Add("Text",this.DataSetDep,"Course.CourseName");
			this.comboDep.DataBindings.Add("Text",this.DataSetDep,"Course.Department");
			this.textStuNum.DataBindings.Add("Text",this.DataSetDep,"Course.ScoreHour");	

		}

		private void btnAdd_Click(object sender, System.EventArgs e)
		{
			this.Buttons_Control(true);			
			this.BindingContext[this.DataSetDep,"Course"].AddNew();		
		}

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

		
		private void Buttons_Control(bool IsValid)
		{
			if(IsValid)
			{
				this.btnCancel.Enabled=true;
				this.btnApply.Enabled=true;
				this.textClaID.Enabled=true;
				this.textClaName.Enabled=true;
				this.comboDep.Enabled=true;
				this.textStuNum.Enabled=true;
			}
			else
			{
				this.btnCancel.Enabled=false;
				this.btnApply.Enabled=false;
				this.textClaID.Enabled=false;
				this.textClaName.Enabled=false;
				this.comboDep.Enabled=false;
				this.textStuNum.Enabled=false;
			}
		}

		private void btnCancel_Click_1(object sender, System.EventArgs e)
		{
			try
			{
				this.BindingContext[this.DataSetDep,"Course"].CancelCurrentEdit();
			}
			catch(System.Exception E)
			{
				this.ErrorHandle(E);
			}
			this.Buttons_Control(false);	
		
		}

		private void btnApply_Click(object sender, System.EventArgs e)
		{				
			try
			{
				this.BindingContext[this.DataSetDep,"Course"].EndCurrentEdit();
				if(this.conn1.State==ConnectionState.Closed)
					this.conn1.Open();
				SqlCommandBuilder commandbuilder1=new SqlCommandBuilder(this.sqlDataAdapter1);
				this.sqlDataAdapter1.Update(this.DataSetDep,"Course");
				this.DataSetDep.AcceptChanges();
				this.dataGrid1.Refresh();
			}
			catch(Exception E)
			{
				this.ErrorHandle(E);
			}
			finally
			{
				this.conn1.Close();
					
				this.Buttons_Control(false);
			}	

		}

		private void btnDelete_Click(object sender, System.EventArgs e)
		{
			if((this.BindingContext[this.DataSetDep,"Course"].Count>0)&
				(MessageBox.Show("真的要删除此记录吗","确定删除",MessageBoxButtons.OKCancel,MessageBoxIcon.Question).Equals(DialogResult.OK)))
			{
				int position=this.BindingContext[this.DataSetDep,"Course"].Position;
				this.BindingContext[this.DataSetDep,"Course"].RemoveAt(position);
			}
			else
				return;
			try
			{
				this.BindingContext[this.DataSetDep,"Course"].EndCurrentEdit();
				if(this.conn1.State==ConnectionState.Closed)
					this.conn1.Open();
				SqlCommandBuilder commandbuilder1=new SqlCommandBuilder(this.sqlDataAdapter1);
				this.sqlDataAdapter1.Update(this.DataSetDep,"Course");
				this.DataSetDep.AcceptChanges();
				this.dataGrid1.Refresh();
			}
			catch(Exception E)
			{
				this.ErrorHandle(E);
			}
			finally
			{
				this.conn1.Close();
					
				this.Buttons_Control(false);
			}	

		}

		private void btnModify_Click(object sender, System.EventArgs e)
		{
			this.Buttons_Control(true);
		}

		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.comboDep.Items.Add(this.DataReader1["DepartmentName"].ToString());
					
				}
				this.conn1.Close();	
			}
			catch(Exception E)
			{
				MessageBox.Show(E.ToString());
			}
			finally
			{
				this.conn1.Close();			
			}				

		}

        private void dataGrid1_Navigate(object sender, NavigateEventArgs ne)
        {

        }
	}
}

⌨️ 快捷键说明

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