📄 return.cs
字号:
// btnReturn
//
this.btnReturn.Location = new System.Drawing.Point(192, 424);
this.btnReturn.Name = "btnReturn";
this.btnReturn.TabIndex = 2;
this.btnReturn.Text = "归还图书";
this.btnReturn.Click += new System.EventHandler(this.btnReturn_Click);
//
// btnOvertime
//
this.btnOvertime.Location = new System.Drawing.Point(304, 424);
this.btnOvertime.Name = "btnOvertime";
this.btnOvertime.TabIndex = 3;
this.btnOvertime.Text = "超期借书";
this.btnOvertime.Click += new System.EventHandler(this.btnOvertime_Click);
//
// da1
//
this.da1.InsertCommand = this.sqlInsertCommand1;
this.da1.SelectCommand = this.sqlSelectCommand1;
this.da1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "读者借阅", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("证号", "证号"),
new System.Data.Common.DataColumnMapping("读者姓名", "读者姓名"),
new System.Data.Common.DataColumnMapping("已借书", "已借书"),
new System.Data.Common.DataColumnMapping("书号", "书号"),
new System.Data.Common.DataColumnMapping("书名", "书名"),
new System.Data.Common.DataColumnMapping("借阅时间", "借阅时间"),
new System.Data.Common.DataColumnMapping("应还时间", "应还时间"),
new System.Data.Common.DataColumnMapping("状态", "状态")})});
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = "INSERT INTO 读者借阅(证号, 读者姓名, 已借书, 书号, 书名, 借阅时间, 应还时间, 状态) VALUES (@证号, @读者姓名, @已借书," +
" @书号, @书名, @借阅时间, @应还时间, @状态); SELECT 证号, 读者姓名, 已借书, 书号, 书名, 借阅时间, 应还时间, 状态 FROM" +
" 读者借阅 a";
this.sqlInsertCommand1.Connection = this.sqlConnection1;
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@证号", System.Data.SqlDbType.VarChar, 10, "证号"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@读者姓名", System.Data.SqlDbType.VarChar, 20, "读者姓名"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@已借书", System.Data.SqlDbType.Int, 4, "已借书"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@书号", System.Data.SqlDbType.VarChar, 10, "书号"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@书名", System.Data.SqlDbType.VarChar, 100, "书名"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@借阅时间", System.Data.SqlDbType.DateTime, 8, "借阅时间"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@应还时间", System.Data.SqlDbType.DateTime, 4, "应还时间"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@状态", System.Data.SqlDbType.VarChar, 50, "状态"));
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=YXK;packet size=4096;integrated security=SSPI;data source=YXK;pers" +
"ist security info=False;initial catalog=library";
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT 证号, 读者姓名, 已借书, 书号, 书名, 借阅时间, 应还时间, 状态 FROM 读者借阅 a WHERE (证号 LIKE @Param29)" +
" AND (书号 LIKE @Param30) AND (读者姓名 LIKE @Param31) AND (状态 LIKE @Param32)";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param29", System.Data.SqlDbType.VarChar, 10, "证号"));
this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param30", System.Data.SqlDbType.VarChar, 10, "书号"));
this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param31", System.Data.SqlDbType.VarChar, 20, "读者姓名"));
this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param32", System.Data.SqlDbType.VarChar, 50, "状态"));
//
// checkBox1
//
this.checkBox1.Location = new System.Drawing.Point(408, 424);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(112, 24);
this.checkBox1.TabIndex = 4;
this.checkBox1.Text = "更新借阅数据库";
//
// Return
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.AutoScroll = true;
this.ClientSize = new System.Drawing.Size(624, 462);
this.Controls.Add(this.checkBox1);
this.Controls.Add(this.btnOvertime);
this.Controls.Add(this.btnReturn);
this.Controls.Add(this.dataGrid1);
this.Controls.Add(this.groupBox1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "Return";
this.Text = "图书归还";
this.Load += new System.EventHandler(this.Return_Load);
this.groupBox1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataSet21)).EndInit();
this.ResumeLayout(false);
}
#endregion
//------------初始化窗体时,填充数据-------------
private void Return_Load(object sender, System.EventArgs e)
{
da1.SelectCommand.Parameters[0].Value="%%";
da1.SelectCommand.Parameters[1].Value="%%";
da1.SelectCommand.Parameters[2].Value="%%";
da1.SelectCommand.Parameters[3].Value="%%";
dataSet21.读者借阅.Clear();
da1.Fill(dataSet21);
cmOrders=(CurrencyManager) BindingContext[dataSet21,"读者借阅"];
}
//-----------搜索借书记录-----------
private void btnSearch_Click(object sender, System.EventArgs e)
{
da1.SelectCommand.Parameters[0].Value="%%"; //证号
da1.SelectCommand.Parameters[1].Value="%%"; //书号
da1.SelectCommand.Parameters[2].Value="%%"; //读者姓名
da1.SelectCommand.Parameters[3].Value="%%"; //状态
if(txt1.Text!="")
{
da1.SelectCommand.Parameters[0].Value="%"+txt1.Text+"%";
}
if(txt2.Text!="")
{
da1.SelectCommand.Parameters[2].Value="%"+txt2.Text+"%";
}
if(txt3.Text!="")
{
da1.SelectCommand.Parameters[1].Value="%"+txt3.Text+"%";
}
dataSet21.读者借阅.Clear();
da1.Fill(dataSet21);
}
//--------------------------显示所有超期借阅的情况------------------------------------------
private void btnOvertime_Click(object sender, System.EventArgs e)
{
if(checkBox1.Checked==true)
{
string strConn = "workstation id=localhost;Integrated Security=SSPI;database=library";
SqlConnection cn=new SqlConnection(strConn);
cn.Open();
SqlCommand cmd=cn.CreateCommand();
cmd.CommandText="exec sf_超期";
cmd.ExecuteNonQuery();
}
//查找所有超期的情况
da1.SelectCommand.Parameters[0].Value="%%";
da1.SelectCommand.Parameters[1].Value="%%";
da1.SelectCommand.Parameters[2].Value="%%";
da1.SelectCommand.Parameters[3].Value="超期";
dataSet21.读者借阅.Clear();
da1.Fill(dataSet21);
}
//--------读者还书----------
private void btnReturn_Click(object sender, System.EventArgs e)
{
int curRow=dataGrid1.CurrentCell.RowNumber;
string ReaderID = null;
try
{
ReaderID=dataGrid1[curRow,0].ToString().Trim();//证号
}
catch
{
string msg="目前没有任何图书借阅!";
MessageBox.Show(msg,"警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
return;
}
string BookID=dataGrid1[curRow,3].ToString().Trim();//书号
DateTime returnTime=Convert.ToDateTime(dataGrid1[curRow,6]);//应还时间
if(returnTime<System.DateTime.Now)
{
string msg="该图书超期"+(System.DateTime.Now.DayOfYear-returnTime.DayOfYear)+"天!";
MessageBox.Show(msg,"图书超期",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
string strConn = "workstation id=localhost;Integrated Security=SSPI;database=library";
SqlConnection cn=new SqlConnection(strConn);
cn.Open();
SqlCommand cmd=cn.CreateCommand();
cmd.CommandText="exec sf_图书归还 '"+ReaderID+"','"+BookID+"'";
cmd.ExecuteNonQuery();
dataSet21.读者借阅.Clear();
da1.Fill(dataSet21);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -