📄 customerform.cs
字号:
this.btnExit.Size = new System.Drawing.Size(72, 23);
this.btnExit.TabIndex = 2;
this.btnExit.Text = "E&xit";
this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
//
// btnNext
//
this.btnNext.Image = ((System.Drawing.Image)(resources.GetObject("btnNext.Image")));
this.btnNext.Location = new System.Drawing.Point(424, 224);
this.btnNext.Name = "btnNext";
this.btnNext.Size = new System.Drawing.Size(72, 23);
this.btnNext.TabIndex = 2;
this.btnNext.Text = ">";
this.btnNext.Click += new System.EventHandler(this.btnNext_Click);
//
// btnPrevious
//
this.btnPrevious.Image = ((System.Drawing.Image)(resources.GetObject("btnPrevious.Image")));
this.btnPrevious.Location = new System.Drawing.Point(64, 224);
this.btnPrevious.Name = "btnPrevious";
this.btnPrevious.Size = new System.Drawing.Size(72, 23);
this.btnPrevious.TabIndex = 2;
this.btnPrevious.Text = "<";
this.btnPrevious.Click += new System.EventHandler(this.btnPrevious_Click);
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand1;
this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "tblCustomer", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("CarNo", "CarNo"),
new System.Data.Common.DataColumnMapping("Name", "Name"),
new System.Data.Common.DataColumnMapping("Address", "Address"),
new System.Data.Common.DataColumnMapping("Make", "Make")})});
this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1;
//
// sqlDeleteCommand1
//
this.sqlDeleteCommand1.CommandText = @"DELETE FROM tblCustomer WHERE (CarNo = @Original_CarNo) AND (Address = @Original_Address OR @Original_Address IS NULL AND Address IS NULL) AND (Make = @Original_Make OR @Original_Make IS NULL AND Make IS NULL) AND (Name = @Original_Name OR @Original_Name IS NULL AND Name IS NULL)";
this.sqlDeleteCommand1.Connection = this.sqlConnection1;
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_CarNo", System.Data.SqlDbType.NVarChar, 15, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "CarNo", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Address", System.Data.SqlDbType.NVarChar, 255, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Address", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Make", System.Data.SqlDbType.NVarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Make", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Name", System.Data.SqlDbType.NVarChar, 255, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Name", System.Data.DataRowVersion.Original, null));
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=25918CBF7A5641A;packet size=4096;integrated security=SSPI;data sou" +
"rce=25918CBF7A5641A;persist security info=False;initial catalog=CMS";
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = "INSERT INTO tblCustomer(CarNo, Name, Address, Make) VALUES (@CarNo, @Name, @Addre" +
"ss, @Make); SELECT CarNo, Name, Address, Make FROM tblCustomer WHERE (CarNo = @C" +
"arNo)";
this.sqlInsertCommand1.Connection = this.sqlConnection1;
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CarNo", System.Data.SqlDbType.NVarChar, 15, "CarNo"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Name", System.Data.SqlDbType.NVarChar, 255, "Name"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Address", System.Data.SqlDbType.NVarChar, 255, "Address"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Make", System.Data.SqlDbType.NVarChar, 50, "Make"));
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT CarNo, Name, Address, Make FROM tblCustomer";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlUpdateCommand1
//
this.sqlUpdateCommand1.CommandText = @"UPDATE tblCustomer SET CarNo = @CarNo, Name = @Name, Address = @Address, Make = @Make WHERE (CarNo = @Original_CarNo) AND (Address = @Original_Address OR @Original_Address IS NULL AND Address IS NULL) AND (Make = @Original_Make OR @Original_Make IS NULL AND Make IS NULL) AND (Name = @Original_Name OR @Original_Name IS NULL AND Name IS NULL); SELECT CarNo, Name, Address, Make FROM tblCustomer WHERE (CarNo = @CarNo)";
this.sqlUpdateCommand1.Connection = this.sqlConnection1;
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CarNo", System.Data.SqlDbType.NVarChar, 15, "CarNo"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Name", System.Data.SqlDbType.NVarChar, 255, "Name"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Address", System.Data.SqlDbType.NVarChar, 255, "Address"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Make", System.Data.SqlDbType.NVarChar, 50, "Make"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_CarNo", System.Data.SqlDbType.NVarChar, 15, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "CarNo", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Address", System.Data.SqlDbType.NVarChar, 255, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Address", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Make", System.Data.SqlDbType.NVarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Make", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Name", System.Data.SqlDbType.NVarChar, 255, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Name", System.Data.DataRowVersion.Original, null));
//
// errCustForm
//
this.errCustForm.ContainerControl = this;
//
// CustomerForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.Color.DodgerBlue;
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(600, 373);
this.Controls.Add(this.btnSave);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.lblCarNo);
this.Controls.Add(this.lblAddress);
this.Controls.Add(this.lblName);
this.Controls.Add(this.lblMake);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.textBox4);
this.Controls.Add(this.textBox5);
this.Controls.Add(this.btnEdit);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.btnNext);
this.Controls.Add(this.btnPrevious);
this.ForeColor = System.Drawing.SystemColors.ControlText;
this.Name = "CustomerForm";
this.Text = "CustomerForm";
this.Load += new System.EventHandler(this.CustomerForm_Load);
((System.ComponentModel.ISupportInitialize)(this.customerDataSet1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void label2_Click(object sender, System.EventArgs e)
{
}
private void CustomerForm_Load(object sender, System.EventArgs e)
{
errCustForm.SetError(textBox1,"");
errCustForm.SetError(textBox2,"");
errCustForm.SetError(textBox3,"");
errCustForm.SetError(textBox4,"");
}
private void CurrentPosition()
{
int currentPosition,ctr;
ctr =this.BindingContext[customerDataSet1,"tblCustomer"].Count;
if(ctr==0)
{
textBox5.Text="(There are no records in the Customer table.)";
}
else
{
currentPosition = this.BindingContext[customerDataSet1,"tblCustomer"].Position+1;
textBox5.Text= currentPosition.ToString() +"of" +ctr.ToString();
}
}
private void btnEdit_Click(object sender, System.EventArgs e)
{
customerDataSet1.Clear ();
sqlDataAdapter1.Fill (customerDataSet1);
}
private void btnSave_Click(object sender, System.EventArgs e)
{
bool flag;
flag = true;
if(textBox1.Text=="")
{
errCustForm.SetError(textBox1,"Please sepecify a valid car number.");
flag=false;
}
else
errCustForm.SetError(textBox1,"");
if(textBox2.Text=="")
{
errCustForm.SetError(textBox2,"Please sepecify a valid namer.");
flag=false;
}
else
errCustForm.SetError(textBox2,"");
if(textBox3.Text=="")
{
errCustForm.SetError(textBox3,"Please sepecify a valid address.");
flag=false;
}
else
errCustForm.SetError(textBox3,"");
if(textBox4.Text=="")
{
errCustForm.SetError(textBox4,"Please sepecify a valid make.");
flag=false;
}
else
errCustForm.SetError(textBox4,"");
if(flag==false)
return;
else
{
sqlDataAdapter1.Update(customerDataSet1);
MessageBox.Show("Database updated!");
}
}
private void btnCancel_Click(object sender, System.EventArgs e)
{
customerDataSet1.Clear ();
sqlDataAdapter1.Fill (customerDataSet1);
}
private void btnExit_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void btnPrevious_Click(object sender, System.EventArgs e)
{
this.BindingContext[customerDataSet1,"tblCustomer"].Position = (this.BindingContext[customerDataSet1,"tblCustomer"].Position - 1);
this.CurrentPosition();
}
private void btnNext_Click(object sender, System.EventArgs e)
{
this.BindingContext[customerDataSet1,"tblCustomer"].Position = (this.BindingContext[customerDataSet1,"tblCustomer"].Position + 1);
this.CurrentPosition();
}
private void textBox5_TextChanged(object sender, System.EventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -