You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.9 KiB

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Sql
{
public partial class Form31 : Form
{
string SID;
public Form31(string sID)
{
SID = sID;
InitializeComponent();
Table();
}
public void Table() //此私有类是将数据加载到窗体中
{
dataGridView2.Rows.Clear(); //清除前面的数据,方便后面重新刷新数据
string sql = "select * from BookRecord where sID="+SID+""; //这个逻辑是查找借阅表中的学号,然后找到学号对应的书籍,将书籍展示出来
Dao dao = new Dao();
IDataReader dr = dao.read(sql);
while (dr.Read())
{
/* string cID = dr["cID"].ToString();
string sql2 = "select * from Book where Id='" + cID + "'";
IDataReader dr2 = dao.read(sql2);
dr2.Read();*/
string a, b, c, d ;
a = dr["BookId"].ToString(); //这例可以自己修改
b = dr["BookName"].ToString();
c = dr["jytime"].ToString();
d = dr["ghtime"].ToString();
//e = dr["SID"].ToString(); // 不用展示学号sid了
string[] str = { a, b, c, d};
dataGridView2.Rows.Add(str); //添加数据
}
dr.Close();//关闭连接
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (dataGridView2.Rows.Count == 0) //判断是否为空
{
MessageBox.Show("你当前还没有借阅任何图书");
}
else
{
DialogResult hh = MessageBox.Show(" 是否归还此书", "提示", MessageBoxButtons.OKCancel);
if (hh == DialogResult.OK)
{
string BookId = dataGridView2.SelectedCells[0].Value.ToString(); //注意dataGridView2要与所选窗口对应
string sql = "delete BookRecord where sID='" + SID + "'and BookId='" + BookId + "'"; //思考一下双引号与单引号的用法
Dao dao = new Dao();
dao.Execute(sql);
string sql2 = "UPDATE Book SET Count = Count+1 WHERE Id = " + BookId + " ";
Dao dao2 = new Dao();
dao.Execute(sql2);
Table();
}
else
{
//不执行任何操作
}
}
}
private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
}
}