📄 publishcompany.cs
字号:
this.sqlDeleteCommand1.Connection = this.sqlConnection1;
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_PublishName", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "PublishName", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_PbulishEmail", System.Data.SqlDbType.VarChar, 30, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "PbulishEmail", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_PublishAddress", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "PublishAddress", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_PublishPhoneNo", System.Data.SqlDbType.VarChar, 15, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "PublishPhoneNo", System.Data.DataRowVersion.Original, null));
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = @"INSERT INTO PublishCompany(PublishName, PublishAddress, PublishPhoneNo, PbulishEmail) VALUES (@PublishName, @PublishAddress, @PublishPhoneNo, @PbulishEmail); SELECT PublishName, PublishAddress, PublishPhoneNo, PbulishEmail FROM PublishCompany WHERE (PublishName = @PublishName)";
this.sqlInsertCommand1.Connection = this.sqlConnection1;
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PublishName", System.Data.SqlDbType.VarChar, 50, "PublishName"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PublishAddress", System.Data.SqlDbType.VarChar, 50, "PublishAddress"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PublishPhoneNo", System.Data.SqlDbType.VarChar, 15, "PublishPhoneNo"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PbulishEmail", System.Data.SqlDbType.VarChar, 30, "PbulishEmail"));
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT PublishName, PublishAddress, PublishPhoneNo, PbulishEmail FROM PublishComp" +
"any";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlUpdateCommand1
//
this.sqlUpdateCommand1.CommandText = @"UPDATE PublishCompany SET PublishName = @PublishName, PublishAddress = @PublishAddress, PublishPhoneNo = @PublishPhoneNo, PbulishEmail = @PbulishEmail WHERE (PublishName = @Original_PublishName) AND (PbulishEmail = @Original_PbulishEmail OR @Original_PbulishEmail IS NULL AND PbulishEmail IS NULL) AND (PublishAddress = @Original_PublishAddress OR @Original_PublishAddress IS NULL AND PublishAddress IS NULL) AND (PublishPhoneNo = @Original_PublishPhoneNo OR @Original_PublishPhoneNo IS NULL AND PublishPhoneNo IS NULL); SELECT PublishName, PublishAddress, PublishPhoneNo, PbulishEmail FROM PublishCompany WHERE (PublishName = @PublishName)";
this.sqlUpdateCommand1.Connection = this.sqlConnection1;
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PublishName", System.Data.SqlDbType.VarChar, 50, "PublishName"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PublishAddress", System.Data.SqlDbType.VarChar, 50, "PublishAddress"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PublishPhoneNo", System.Data.SqlDbType.VarChar, 15, "PublishPhoneNo"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PbulishEmail", System.Data.SqlDbType.VarChar, 30, "PbulishEmail"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_PublishName", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "PublishName", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_PbulishEmail", System.Data.SqlDbType.VarChar, 30, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "PbulishEmail", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_PublishAddress", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "PublishAddress", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_PublishPhoneNo", System.Data.SqlDbType.VarChar, 15, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "PublishPhoneNo", System.Data.DataRowVersion.Original, null));
//
// Publishing
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(544, 318);
this.Controls.Add(this.btnDelete);
this.Controls.Add(this.lblDatasetPosition);
this.Controls.Add(this.btnPrevious);
this.Controls.Add(this.btnNext);
this.Controls.Add(this.btnLast);
this.Controls.Add(this.btnFirst);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.groupBox3);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "Publishing";
this.Text = "出版社信息维护";
this.Load += new System.EventHandler(this.Publishing_Load);
this.groupBox1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.objDataSetPublishing)).EndInit();
this.groupBox3.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
public void ErrorHandle(System.Exception E)
{
MessageBox.Show(E.ToString());
}
private void ButtonPositonChange()
{
this.btnPrevious.Enabled=true;
this.btnNext.Enabled=true;
this.btnFirst.Enabled=true;
this.btnLast.Enabled=true;
if(this.BindingContext[this.objDataSetPublishing,"PublishCompany"].Position==0)
{
this.btnFirst.Enabled=false;
this.btnPrevious.Enabled=false;
}
if(this.BindingContext[this.objDataSetPublishing,"PublishCompany"].Position==this.BindingContext[this.objDataSetPublishing,"PublishCompany"].Count-1)
{
this.btnNext.Enabled=false;
this.btnLast.Enabled=false;
}
}
private void DatasetPostionChange()
{
this.lblDatasetPosition.Text=(this.BindingContext[this.objDataSetPublishing,"PublishCompany"].Position+1)+"的"+
(this.BindingContext[this.objDataSetPublishing,"PublishCompany"].Count);
}
private void TextEnableControl(bool valid)
{
if(valid)
{
this.textName.Enabled=true;
this.textAdress.Enabled=true;
this.textEmail.Enabled=true;
this.textTelNo.Enabled=true;
}
else
{
this.textName.Enabled=false;
this.textAdress.Enabled=false;
this.textEmail.Enabled=false;
this.textTelNo.Enabled=false;
}
}
private void ButtonEnableControl(bool valid)
{
if(valid)
{
this.btnCancel.Enabled=true;
this.btnApply.Enabled=true;
}
else
{
this.btnCancel.Enabled=false;
this.btnApply.Enabled=false;
}
}
private void LoadDataSet()
{
DataSetPublishing objDataSetTemp=new DataSetPublishing();
try
{
this.FillDataSet(objDataSetTemp);
}
catch (System.Exception E)
{
// 在此处添加错误处理代码。
this.ErrorHandle(E);
}
try
{
this.objDataSetPublishing.Clear();
this.objDataSetPublishing.Merge(objDataSetTemp);
}
catch(System.Exception E)
{
// 在此处添加错误处理代码。
this.ErrorHandle(E);
}
}
private void FillDataSet(DataSetPublishing dataset)
{
dataset.EnforceConstraints=false;
try
{
this.sqlConnection1.Open();
this.sqlDataAdapter1.Fill(dataset);
}
catch(System.Exception E)
{
this.ErrorHandle(E);
}
finally
{
dataset.EnforceConstraints=true;
this.sqlConnection1.Close();
}
}
private void Publishing_Load(object sender, System.EventArgs e)
{
this.LoadDataSet();
this.DatasetPostionChange();
this.ButtonPositonChange();
this.TextEnableControl(false);
this.ButtonEnableControl(false);
}
private void btnNext_Click(object sender, System.EventArgs e)
{
this.BindingContext[this.objDataSetPublishing,"PublishCompany"].Position+=1;
this.ButtonPositonChange();
this.DatasetPostionChange();
}
private void btnPrevious_Click(object sender, System.EventArgs e)
{
this.BindingContext[this.objDataSetPublishing,"PublishCompany"].Position-=1;
this.ButtonPositonChange();
this.DatasetPostionChange();
}
private void btnFirst_Click(object sender, System.EventArgs e)
{
this.BindingContext[this.objDataSetPublishing,"PublishCompany"].Position=0;
this.ButtonPositonChange();
this.DatasetPostionChange();
}
private void btnLast_Click(object sender, System.EventArgs e)
{
this.BindingContext[this.objDataSetPublishing,"PublishCompany"].Position=this.BindingContext[this.objDataSetPublishing,"PublishCompany"].Count-1;
this.ButtonPositonChange();
this.DatasetPostionChange();
}
private void btnAdd_Click(object sender, System.EventArgs e)
{
try
{
this.BindingContext[this.objDataSetPublishing,"PublishCompany"].AddNew();
}
catch(System.Exception E)
{
this.ErrorHandle(E);
}
this.DatasetPostionChange();
this.ButtonPositonChange();
this.TextEnableControl(true);
this.ButtonEnableControl(true);
}
private void btnDelete_Click(object sender, System.EventArgs e)
{
if((this.BindingContext[this.objDataSetPublishing,"PublishCompany"].Count>0)&
(MessageBox.Show("真的要删除此记录吗","确定删除",MessageBoxButtons.OKCancel,MessageBoxIcon.Question).Equals(DialogResult.OK)))
{
try
{
int currentPosition=this.BindingContext[this.objDataSetPublishing,"PublishCompany"].Position;
this.objDataSetPublishing.Tables[0].Rows[currentPosition].Delete();
}
catch(System.Exception E)
{
this.ErrorHandle(E);
}
this.ButtonPositonChange();
this.DatasetPostionChange();
}
else
return;
}
private void btnModify_Click(object sender, System.EventArgs e)
{
this.TextEnableControl(true);
this.ButtonEnableControl(true);
}
private void btnQuery_Click(object sender, System.EventArgs e)
{
}
public void UpdateDataSet()
{
this.BindingContext[this.objDataSetPublishing,"PublishCompany"].EndCurrentEdit();
DataSetPublishing objDataSetTemp=new DataSetPublishing();
objDataSetTemp=(DataSetPublishing)(this.objDataSetPublishing.GetChanges());
try
{
this.UpdateDataSource(objDataSetTemp);
this.objDataSetPublishing.Merge(objDataSetTemp);
this.objDataSetPublishing.AcceptChanges();
}
catch(System.Exception E)
{
this.ErrorHandle(E);
}
}
public void UpdateDataSource(DataSetPublishing Changerows)
{
try
{
this.sqlConnection1.Open();
this.sqlDataAdapter1.Update(Changerows);
}
catch(System.Exception E)
{
this.ErrorHandle(E);
}
finally
{
this.sqlConnection1.Close();
}
}
private void btnApply_Click(object sender, System.EventArgs e)
{
try
{
this.UpdateDataSet();
}
catch(System.Exception E)
{
this.ErrorHandle(E);
}
this.ButtonPositonChange();
this.DatasetPostionChange();
this.TextEnableControl(false);
this.ButtonEnableControl(false);
}
private void btnCancel_Click(object sender, System.EventArgs e)
{
try
{
this.BindingContext[this.objDataSetPublishing,"PublishCompany"].CancelCurrentEdit();
}
catch(System.Exception E)
{
this.ErrorHandle(E);
}
this.DatasetPostionChange();
this.TextEnableControl(false);
this.TextEnableControl(false);
this.ButtonEnableControl(false);
}
private void btnExit_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void btnQuery_Click_1(object sender, System.EventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -