📄 form3.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace 图书馆管理系统
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (this.textBox1.Text == "")
{
MessageBox.Show("请输入图书编号!");
}
else
{
SqlConnection myConnection = new SqlConnection();
string conStr = "server=localhost;integrated security=sspi;database=pubs";
myConnection.ConnectionString = conStr;
myConnection.Open();
//确认给图书编号存在
SqlCommand sc3 = new SqlCommand("select num from books where bid="+this .textBox1 .Text ,myConnection );
SqlDataReader sdr3 = sc3.ExecuteReader();
if (sdr3.Read())
{
int num = Convert.ToInt32(sdr3.GetValue(0));
sdr3.Close();
//确认该书确实外借过
SqlCommand sc4 = new SqlCommand("select borrowDate from states where returnDate='0'and bid='" + this.textBox1.Text + "'", myConnection);
SqlDataReader sdr4 = sc4.ExecuteReader();
if (sdr4.Read())
{
System.DateTime bDate = Convert.ToDateTime(sdr4.GetValue(0));
// 计算借书时间
int d = System.DateTime.Now.DayOfYear - bDate.DayOfYear;
sdr4.Close();
//更改还书时间
String date = Convert.ToString(System.DateTime.Now);
SqlCommand sc1 = new SqlCommand("update states set returnDate='" + date + "'where bid='" + this.textBox1.Text + "'and returnDate='" + 0 + "'", myConnection);
sc1.ExecuteNonQuery();
//更改库存图书数目
SqlCommand sc2 = new SqlCommand("update books set num=" + Convert.ToString(num + 1) + "where bid ='" + this.textBox1.Text + "'", myConnection);
sc2.ExecuteNonQuery();
//检验借书时间是否超过30天
if (d > 30)
{
MessageBox.Show("借书超期" + Convert.ToString(d - 30) + " 天,罚款!");
}
MessageBox.Show("归还成功 ");
}
else
{
sdr4.Close();
MessageBox.Show(" 该书从未外借过!");
}
}
else
{
sdr3.Close();
MessageBox.Show("该书编号非法!");
}
myConnection.Close();
}
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -