📄 department.cs
字号:
this.dataGridTextBoxColumn3.HeaderText = "电话";
this.dataGridTextBoxColumn3.MappingName = "PhoneNO";
this.dataGridTextBoxColumn3.Width = 75;
//
// groupBox2
//
this.groupBox2.Controls.Add(this.textTelNo);
this.groupBox2.Controls.Add(this.textDepName);
this.groupBox2.Controls.Add(this.label3);
this.groupBox2.Controls.Add(this.label2);
this.groupBox2.Controls.Add(this.label1);
this.groupBox2.Controls.Add(this.textDepID);
this.groupBox2.Location = new System.Drawing.Point(16, 8);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(440, 56);
this.groupBox2.TabIndex = 1;
this.groupBox2.TabStop = false;
//
// textTelNo
//
this.textTelNo.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.textTelNo.Location = new System.Drawing.Point(336, 24);
this.textTelNo.Name = "textTelNo";
this.textTelNo.Size = new System.Drawing.Size(64, 21);
this.textTelNo.TabIndex = 5;
this.textTelNo.Text = "";
//
// textDepName
//
this.textDepName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.textDepName.Location = new System.Drawing.Point(200, 24);
this.textDepName.Name = "textDepName";
this.textDepName.Size = new System.Drawing.Size(64, 21);
this.textDepName.TabIndex = 4;
this.textDepName.Text = "";
//
// label3
//
this.label3.Location = new System.Drawing.Point(144, 31);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(56, 23);
this.label3.TabIndex = 3;
this.label3.Text = "院系名称";
//
// label2
//
this.label2.Location = new System.Drawing.Point(272, 31);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(56, 23);
this.label2.TabIndex = 2;
this.label2.Text = "电话号码";
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 31);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(56, 23);
this.label1.TabIndex = 1;
this.label1.Text = "院系代码";
//
// textDepID
//
this.textDepID.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.textDepID.Location = new System.Drawing.Point(72, 24);
this.textDepID.Name = "textDepID";
this.textDepID.Size = new System.Drawing.Size(64, 21);
this.textDepID.TabIndex = 0;
this.textDepID.Text = "";
//
// CancelAll
//
this.CancelAll.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.CancelAll.Image = ((System.Drawing.Image)(resources.GetObject("CancelAll.Image")));
this.CancelAll.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.CancelAll.Location = new System.Drawing.Point(248, 24);
this.CancelAll.Name = "CancelAll";
this.CancelAll.Size = new System.Drawing.Size(64, 24);
this.CancelAll.TabIndex = 106;
this.CancelAll.Text = "取消所有";
this.CancelAll.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
this.CancelAll.Click += new System.EventHandler(this.CancelAll_Click);
//
// Department
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(480, 421);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.dataGrid1);
this.Name = "Department";
this.Text = "院系管理";
this.Load += new System.EventHandler(this.Department_Load);
this.groupBox1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.groupBox2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void btnExit_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void Department_Load(object sender, System.EventArgs e)
{
try
{
this.conn1.Open();
this.sqlDataAdapter1.Fill(this.DataSetDep,"Department");
this.DataSet_Bingding();
this.Buttons_Control(false);
}
catch(Exception E)
{
MessageBox.Show(E.ToString());
}
finally
{
this.conn1.Close();
}
}
private void DataSet_Bingding()
{
this.dataGrid1.DataSource=this.DataSetDep;
this.dataGrid1.DataMember="Department";
this.textDepID.DataBindings.Add("Text",this.DataSetDep,"Department.DepartmentID");
this.textDepName.DataBindings.Add("Text",this.DataSetDep,"Department.DepartmentName");
this.textTelNo.DataBindings.Add("Text",this.DataSetDep,"Department.PhoneNO");
}
private void btnAdd_Click(object sender, System.EventArgs e)
{
this.Buttons_Control(true);
this.BindingContext[this.DataSetDep,"Department"].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.textDepID.Enabled=true;
this.textDepName.Enabled=true;
this.textTelNo.Enabled=true;
}
else
{
this.btnCancel.Enabled=false;
this.btnApply.Enabled=false;
this.textDepID.Enabled=false;
this.textDepName.Enabled=false;
this.textTelNo.Enabled=false;
}
}
private void btnCancel_Click_1(object sender, System.EventArgs e)
{
try
{
this.BindingContext[this.DataSetDep,"Department"].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,"Department"].EndCurrentEdit();
if(this.conn1.State==ConnectionState.Closed)
this.conn1.Open();
SqlCommandBuilder commandbuilder1=new SqlCommandBuilder(this.sqlDataAdapter1);
this.sqlDataAdapter1.Update(this.DataSetDep,"Department");
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,"Department"].Count>0)&
(MessageBox.Show("真的要删除此记录吗","确定删除",MessageBoxButtons.OKCancel,MessageBoxIcon.Question).Equals(DialogResult.OK)))
{
int position=this.BindingContext[this.DataSetDep,"Department"].Position;
this.BindingContext[this.DataSetDep,"Department"].RemoveAt(position);
}
else
return;
try
{
this.BindingContext[this.DataSetDep,"Department"].EndCurrentEdit();
if(this.conn1.State==ConnectionState.Closed)
this.conn1.Open();
SqlCommandBuilder commandbuilder1=new SqlCommandBuilder(this.sqlDataAdapter1);
this.sqlDataAdapter1.Update(this.DataSetDep,"Department");
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 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 + -