📄 course.cs
字号:
this.btnExit.TabIndex = 100;
this.btnExit.Text = "退出";
this.btnExit.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
//
// btnDelete
//
this.btnDelete.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnDelete.Image = ((System.Drawing.Image)(resources.GetObject("btnDelete.Image")));
this.btnDelete.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.btnDelete.Location = new System.Drawing.Point(152, 24);
this.btnDelete.Name = "btnDelete";
this.btnDelete.Size = new System.Drawing.Size(48, 24);
this.btnDelete.TabIndex = 104;
this.btnDelete.Text = "删除";
this.btnDelete.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click);
//
// btnCancel
//
this.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnCancel.Image = ((System.Drawing.Image)(resources.GetObject("btnCancel.Image")));
this.btnCancel.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.btnCancel.Location = new System.Drawing.Point(224, 24);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(56, 24);
this.btnCancel.TabIndex = 101;
this.btnCancel.Text = "取消";
this.btnCancel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click_1);
//
// dataGrid1
//
this.dataGrid1.AlternatingBackColor = System.Drawing.Color.GhostWhite;
this.dataGrid1.BackColor = System.Drawing.Color.GhostWhite;
this.dataGrid1.BackgroundColor = System.Drawing.Color.Lavender;
this.dataGrid1.CaptionBackColor = System.Drawing.Color.RoyalBlue;
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.MidnightBlue;
this.dataGrid1.GridLineColor = System.Drawing.Color.RoyalBlue;
this.dataGrid1.HeaderBackColor = System.Drawing.Color.MidnightBlue;
this.dataGrid1.HeaderFont = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Bold);
this.dataGrid1.HeaderForeColor = System.Drawing.Color.Lavender;
this.dataGrid1.LinkColor = System.Drawing.Color.Teal;
this.dataGrid1.Location = new System.Drawing.Point(48, 192);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.ParentRowsBackColor = System.Drawing.Color.Lavender;
this.dataGrid1.ParentRowsForeColor = System.Drawing.Color.MidnightBlue;
this.dataGrid1.ReadOnly = true;
this.dataGrid1.SelectionBackColor = System.Drawing.Color.Teal;
this.dataGrid1.SelectionForeColor = System.Drawing.Color.PaleGreen;
this.dataGrid1.Size = new System.Drawing.Size(440, 240);
this.dataGrid1.TabIndex = 5;
//
// Course
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(592, 493);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.dataGrid1);
this.Name = "Course";
this.Text = "课程设置";
this.Load += new System.EventHandler(this.Course_Load);
this.groupBox2.ResumeLayout(false);
this.groupBox1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
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();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -