📄 backinfo.cs
字号:
//
// comboBox6
//
this.comboBox6.Items.AddRange(new object[] {
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"12"});
this.comboBox6.Location = new System.Drawing.Point(240, 24);
this.comboBox6.Name = "comboBox6";
this.comboBox6.Size = new System.Drawing.Size(40, 20);
this.comboBox6.TabIndex = 2;
//
// comboBox7
//
this.comboBox7.Items.AddRange(new object[] {
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"12",
"13",
"14",
"15",
"16",
"17",
"18",
"19",
"20",
"21",
"22",
"23",
"24",
"25",
"26",
"27",
"28",
"29",
"30",
"31"});
this.comboBox7.Location = new System.Drawing.Point(336, 24);
this.comboBox7.Name = "comboBox7";
this.comboBox7.Size = new System.Drawing.Size(40, 20);
this.comboBox7.TabIndex = 3;
//
// label7
//
this.label7.Location = new System.Drawing.Point(200, 28);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(32, 16);
this.label7.TabIndex = 4;
this.label7.Text = "年";
//
// label8
//
this.label8.Location = new System.Drawing.Point(288, 28);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(32, 16);
this.label8.TabIndex = 5;
this.label8.Text = "月";
//
// label9
//
this.label9.Location = new System.Drawing.Point(384, 28);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(24, 16);
this.label9.TabIndex = 6;
this.label9.Text = "日";
this.label9.Click += new System.EventHandler(this.label9_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", "Tborrowinfo", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("readerid", "readerid"),
new System.Data.Common.DataColumnMapping("readername", "readername"),
new System.Data.Common.DataColumnMapping("bookid", "bookid"),
new System.Data.Common.DataColumnMapping("bookname", "bookname")})});
this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1;
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT readerid, readername, bookid, bookname FROM Tborrowinfo";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = "INSERT INTO Tborrowinfo(readerid, readername, bookid, bookname) VALUES (@readerid" +
", @readername, @bookid, @bookname); SELECT readerid, readername, bookid, booknam" +
"e FROM Tborrowinfo WHERE (readerid = @readerid)";
this.sqlInsertCommand1.Connection = this.sqlConnection1;
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@readerid", System.Data.SqlDbType.VarChar, 10, "readerid"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@readername", System.Data.SqlDbType.VarChar, 10, "readername"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@bookid", System.Data.SqlDbType.VarChar, 10, "bookid"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@bookname", System.Data.SqlDbType.VarChar, 10, "bookname"));
//
// sqlUpdateCommand1
//
this.sqlUpdateCommand1.CommandText = @"UPDATE Tborrowinfo SET readerid = @readerid, readername = @readername, bookid = @bookid, bookname = @bookname WHERE (readerid = @Original_readerid) AND (bookid = @Original_bookid OR @Original_bookid IS NULL AND bookid IS NULL) AND (bookname = @Original_bookname OR @Original_bookname IS NULL AND bookname IS NULL) AND (readername = @Original_readername OR @Original_readername IS NULL AND readername IS NULL); SELECT readerid, readername, bookid, bookname FROM Tborrowinfo WHERE (readerid = @readerid)";
this.sqlUpdateCommand1.Connection = this.sqlConnection1;
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@readerid", System.Data.SqlDbType.VarChar, 10, "readerid"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@readername", System.Data.SqlDbType.VarChar, 10, "readername"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@bookid", System.Data.SqlDbType.VarChar, 10, "bookid"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@bookname", System.Data.SqlDbType.VarChar, 10, "bookname"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_readerid", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "readerid", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_bookid", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "bookid", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_bookname", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "bookname", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_readername", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "readername", System.Data.DataRowVersion.Original, null));
//
// sqlDeleteCommand1
//
this.sqlDeleteCommand1.CommandText = @"DELETE FROM Tborrowinfo WHERE (readerid = @Original_readerid) AND (bookid = @Original_bookid OR @Original_bookid IS NULL AND bookid IS NULL) AND (bookname = @Original_bookname OR @Original_bookname IS NULL AND bookname IS NULL) AND (readername = @Original_readername OR @Original_readername IS NULL AND readername IS NULL)";
this.sqlDeleteCommand1.Connection = this.sqlConnection1;
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_readerid", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "readerid", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_bookid", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "bookid", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_bookname", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "bookname", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_readername", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "readername", System.Data.DataRowVersion.Original, null));
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "data source =222.20.54.54;initial catalog =yuan;user id =sa;password =0517;";
//
// bookback1
//
this.bookback1.DataSetName = "bookback";
this.bookback1.Locale = new System.Globalization.CultureInfo("zh-CN");
//
// button1
//
this.button1.Location = new System.Drawing.Point(240, 312);
this.button1.Name = "button1";
this.button1.TabIndex = 2;
this.button1.Text = "确定";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(344, 312);
this.button2.Name = "button2";
this.button2.TabIndex = 3;
this.button2.Text = "取消";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// backinfo
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(432, 350);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Name = "backinfo";
this.Text = "添加还书信息";
this.Load += new System.EventHandler(this.backinfo_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.bookback1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void groupBox1_Enter(object sender, System.EventArgs e)
{
}
private void backinfo_Load(object sender, System.EventArgs e)
{
sqlDataAdapter1.Fill (bookback1);
}
private void label9_Click(object sender, System.EventArgs e)
{
}
private void button1_Click(object sender, System.EventArgs e)
{
if(comboBox1.SelectedItem.ToString () !=""&&comboBox2.SelectedItem.ToString ()!="")
{
string cstring="data source =222.20.54.54;initial catalog =yuan;user id =sa ;password=0517";
SqlConnection conn=new SqlConnection ();
conn.ConnectionString =cstring;
string cmdstring="insert Treturninfo values(";
cmdstring+="'"+comboBox1.SelectedItem.ToString () +"'," ;
cmdstring+="'"+comboBox2.SelectedItem.ToString ()+"'," ;
cmdstring+="'"+comboBox3.SelectedItem.ToString ()+"'," ;
cmdstring+="'"+comboBox4.SelectedItem.ToString ()+"'," ;
cmdstring+="'"+textBox1.Text+"'," ;
cmdstring+="'"+comboBox5.SelectedItem.ToString ()+comboBox6.SelectedItem.ToString ()+comboBox6.SelectedItem.ToString ()+"')" ;
SqlCommand cmd=new SqlCommand ();
cmd.CommandText =cmdstring;
cmd.Connection =conn;
conn.Open ();
SqlCommand cmd2=new SqlCommand ();
cmd2.CommandText ="select * from Tborrowinfo where readerid="+"'"+comboBox1.SelectedItem.ToString () +"'";
cmd2.Connection =conn;
int i=0;
//conn.Open ();
SqlDataReader rdr =cmd2.ExecuteReader ();
if(rdr.Read ())
{
i+=1;
}
if(i>=1)
{
MessageBox.Show ("对不起,您选择的读者编号已经存在!");
textBox1.Text ="";
}
else
{
conn.Close ();
conn.Open ();
cmd.ExecuteNonQuery ();
MessageBox.Show ("已经成功的添加到了数据库 !");
}
//cmd.ExecuteNonQuery ();
conn.Close ();
}
else
{
MessageBox.Show ("第一项和第二项不能为空!请将其填满","错误!",MessageBoxButtons.OKCancel ,MessageBoxIcon.Error );
}
}
private void button2_Click(object sender, System.EventArgs e)
{
textBox1.Text ="";
this.Close ();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -