📄 publishcompany.cs
字号:
//
// updateComm
//
this.updateComm.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.updateComm.Connection = this.conn;
this.updateComm.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PublishName", System.Data.SqlDbType.VarChar, 50, "PublishName"));
this.updateComm.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PublishAddress", System.Data.SqlDbType.VarChar, 50, "PublishAddress"));
this.updateComm.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PublishPhoneNo", System.Data.SqlDbType.VarChar, 15, "PublishPhoneNo"));
this.updateComm.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PbulishEmail", System.Data.SqlDbType.VarChar, 30, "PbulishEmail"));
this.updateComm.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.updateComm.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.updateComm.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.updateComm.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.BackColor = System.Drawing.Color.LightBlue;
this.ClientSize = new System.Drawing.Size(544, 318);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.groupBox3);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "Publishing";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
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 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(string sqlQuery)
{
DataSetPublishing objDataSetTemp=new DataSetPublishing();
try
{
this.FillDataSet(objDataSetTemp,sqlQuery);
}
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,string sqlQuery)
{
dataset.EnforceConstraints=false;
try
{
da.SelectCommand.CommandText=sqlQuery;
conn.Open();
da.Fill(dataset);
}
catch(System.Exception E)
{
this.ErrorHandle(E);
}
finally
{
dataset.EnforceConstraints=true;
conn.Close();
}
}
private void Publishing_Load(object sender, System.EventArgs e)
{
if(this.sqlQuery!="")
{
this.LoadDataSet(sqlQuery);
this.TextEnableControl(false);
this.ButtonEnableControl(false);
this.TextEnableControl(true);
this.ButtonEnableControl(true);
}
else
{
addnewPublishing();
}
}
private void addnewPublishing()
{
try
{
this.BindingContext[this.objDataSetPublishing,"PublishCompany"].AddNew();
}
catch(System.Exception E)
{
this.ErrorHandle(E);
}
this.TextEnableControl(true);
this.ButtonEnableControl(true);
}
private void btnAdd_Click(object sender, System.EventArgs e)
{
addnewPublishing();
}
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);
}
}
else
return;
}
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
{
conn.Open();
da.Update(Changerows);
}
catch(System.Exception E)
{
this.ErrorHandle(E);
}
finally
{
conn.Close();
}
}
private void btnApply_Click(object sender, System.EventArgs e)
{
try
{
this.UpdateDataSet();
}
catch(System.Exception E)
{
this.ErrorHandle(E);
}
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.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 + -