📄 department.cs
字号:
this.groupBox2.Location = new System.Drawing.Point(7, 280);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(445, 56);
this.groupBox2.TabIndex = 1;
this.groupBox2.TabStop = false;
//
// textTelNo
//
this.textTelNo.Location = new System.Drawing.Point(352, 24);
this.textTelNo.Name = "textTelNo";
this.textTelNo.Size = new System.Drawing.Size(73, 21);
this.textTelNo.TabIndex = 5;
//
// textDepName
//
this.textDepName.Location = new System.Drawing.Point(200, 24);
this.textDepName.Name = "textDepName";
this.textDepName.Size = new System.Drawing.Size(75, 21);
this.textDepName.TabIndex = 4;
this.textDepName.TextChanged += new System.EventHandler(this.textDepName_TextChanged);
//
// 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(290, 31);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(56, 23);
this.label2.TabIndex = 2;
this.label2.Text = "电话号码";
this.label2.Click += new System.EventHandler(this.label2_Click);
//
// 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.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.TextChanged += new System.EventHandler(this.textDepID_TextChanged);
//
// groupBox3
//
this.groupBox3.Controls.Add(this.btnCancel);
this.groupBox3.Controls.Add(this.btnApply);
this.groupBox3.Location = new System.Drawing.Point(299, 342);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(153, 62);
this.groupBox3.TabIndex = 103;
this.groupBox3.TabStop = false;
//
// Department
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(475, 446);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.dataGrid1);
this.Controls.Add(this.groupBox1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
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.groupBox2.PerformLayout();
this.groupBox3.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");
//this.textBox1.DataBindings.Add("Text", this.DataSetDep, "Department.Son");
}
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);
}
private void dataGrid1_Navigate(object sender, NavigateEventArgs ne)
{
}
private void label2_Click(object sender, EventArgs e)
{
}
private void textDepID_TextChanged(object sender, EventArgs e)
{
}
private void textDepName_TextChanged(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -