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

📄 class.cs

📁 c# + sql2000 学生管理系统
💻 CS
📖 第 1 页 / 共 2 页
字号:
            this.btnCancel.ForeColor = System.Drawing.SystemColors.ControlText;
            this.btnCancel.Location = new System.Drawing.Point(100, 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, 12);
            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(483, 208);
            this.dataGrid1.TabIndex = 2;
            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.dataGridTextBoxColumn2,
            this.dataGridTextBoxColumn3,
            this.dataGridTextBoxColumn4});
            this.dataGridTableStyle1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
            this.dataGridTableStyle1.MappingName = "Class";
            // 
            // dataGridTextBoxColumn1
            // 
            this.dataGridTextBoxColumn1.Format = "";
            this.dataGridTextBoxColumn1.FormatInfo = null;
            this.dataGridTextBoxColumn1.HeaderText = "班级代码";
            this.dataGridTextBoxColumn1.MappingName = "ClassID";
            this.dataGridTextBoxColumn1.Width = 75;
            // 
            // dataGridTextBoxColumn2
            // 
            this.dataGridTextBoxColumn2.Format = "";
            this.dataGridTextBoxColumn2.FormatInfo = null;
            this.dataGridTextBoxColumn2.HeaderText = "班级名称";
            this.dataGridTextBoxColumn2.MappingName = "ClassName";
            this.dataGridTextBoxColumn2.Width = 120;
            // 
            // dataGridTextBoxColumn3
            // 
            this.dataGridTextBoxColumn3.Format = "";
            this.dataGridTextBoxColumn3.FormatInfo = null;
            this.dataGridTextBoxColumn3.HeaderText = "所属院系";
            this.dataGridTextBoxColumn3.MappingName = "DepartmentName";
            this.dataGridTextBoxColumn3.Width = 150;
            // 
            // dataGridTextBoxColumn4
            // 
            this.dataGridTextBoxColumn4.Format = "";
            this.dataGridTextBoxColumn4.FormatInfo = null;
            this.dataGridTextBoxColumn4.HeaderText = "学生人数";
            this.dataGridTextBoxColumn4.MappingName = "StudentNumber";
            this.dataGridTextBoxColumn4.Width = 75;
            // 
            // groupBox3
            // 
            this.groupBox3.Controls.Add(this.btnApply);
            this.groupBox3.Controls.Add(this.btnCancel);
            this.groupBox3.Location = new System.Drawing.Point(321, 235);
            this.groupBox3.Name = "groupBox3";
            this.groupBox3.Size = new System.Drawing.Size(174, 65);
            this.groupBox3.TabIndex = 103;
            this.groupBox3.TabStop = false;
            // 
            // Class
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
            this.ClientSize = new System.Drawing.Size(507, 451);
            this.Controls.Add(this.groupBox3);
            this.Controls.Add(this.groupBox2);
            this.Controls.Add(this.groupBox1);
            this.Controls.Add(this.dataGrid1);
            this.Controls.Add(this.btnExit);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.MaximizeBox = false;
            this.Name = "Class";
            this.Text = "班级管理";
            this.Load += new System.EventHandler(this.Class_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 Class_Load(object sender, System.EventArgs e)
		{
			try
			{
				this.conn1.Open();
				this.sqlDataAdapter1.Fill(this.DataSetDep,"Class");
				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="Class";			
			this.textClaID.DataBindings.Add("Text",this.DataSetDep,"Class.ClassID");
			this.textClaName.DataBindings.Add("Text",this.DataSetDep,"Class.ClassName");
			this.comboDep.DataBindings.Add("Text",this.DataSetDep,"Class.DepartmentName");
			this.textStuNum.DataBindings.Add("Text",this.DataSetDep,"Class.StudentNumber");	

		}

		private void btnAdd_Click(object sender, System.EventArgs e)
		{
			this.Buttons_Control(true);			
			this.BindingContext[this.DataSetDep,"Class"].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,"Class"].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,"Class"].EndCurrentEdit();
				if(this.conn1.State==ConnectionState.Closed)
					this.conn1.Open();
				SqlCommandBuilder commandbuilder1=new SqlCommandBuilder(this.sqlDataAdapter1);
				this.sqlDataAdapter1.Update(this.DataSetDep,"Class");
				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,"Class"].Count>0)&
				(MessageBox.Show("真的要删除此记录吗","确定删除",MessageBoxButtons.OKCancel,MessageBoxIcon.Question).Equals(DialogResult.OK)))
			{
				int position=this.BindingContext[this.DataSetDep,"Class"].Position;
				this.BindingContext[this.DataSetDep,"Class"].RemoveAt(position);
			}
			else
				return;			

		}

		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 CancelAll_Click(object sender, System.EventArgs e)
		{
			try
			{
				this.DataSetDep.RejectChanges();
			}
			catch(System.Exception E)
			{
				this.ErrorHandle(E);
			}
			this.Buttons_Control(false);			
		}
	}
}

⌨️ 快捷键说明

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