当前位置:   article > 正文

毕业设计——基于QT+MySQL实现的图书管理系统_qt图书馆管理系统毕业设计

qt图书馆管理系统毕业设计

毕业设计——基于QT+MySQL实现的图书管理系统

1.1 介绍

本项目设计并实现了一个精简的多用户图书管理系统,应用后端通过与 mysql 进行连接实现对数据的管理,数据存储在本地。游客可以查阅图书信息;用户可以登陆、注册、查看图书,借书、还书等操作;管理员可以通过登陆界面实现对用户和书籍的管理,具有添加/删除用户/书籍等权限。

1.2 运行环境介绍、配置及测试

开发平台: Windows / QT5.5.1 / MySQL5.6
上述QT和Mysql软件的安装可以参考Mysql安装与基础使用(QT、Matlab)
软件安装后,需要配置Mysql环境如下:
1.确认Mysql的端口使用3306,数据库登录的用户名和密码均设置为root,这些是我工程中的基本链接配置;
2.新建数据库mydatabase,命令为:create database mydatabase;
3.数据库mydatabase下新建四个表格:用户(user)、管理员(manager)、图书(book)、借阅信息(borrow)。命令为:

use mydatabase;

create table user(
id varchar(20) primary key not null,
name varchar(20) not null,
password varchar(20) not null,
canBorrow boolean not null
);

create table manager(
id varchar(20) primary key not null,
name varchar(20) not null,
password varchar(20) not null
);

create table book(
book_id varchar(20) primary key,
name varchar(20) not null,
author_name varchar(20),
price numeric(9,2),
num int not null,
stock int not null,
publisher varchar(20),
publish_year year,
type varchar(20) not null
);

create table borrow(
user_id varchar(20),
book_id varchar(20),
borrow_date date,
return_date date,
primary key(user_id,book_id),
foreign key (user_id) references user(id),
foreign key (book_id) references book(book_id)
);
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36

上述表中变量的含义(按顺序):
①用户:学号(主键),姓名,密码、借阅权限
②管理员:账号(主键),姓名,密码
③图书:书籍编号(主键),书名,作者,价格,总库存,剩余量,出版社,出版年份,分类
④借阅信息:用户学号,书籍编号,借阅时间,归还时间

4.为了测试,默认添加1个管理员,3个用户,4本书

insert into manager (id , name, password) values ("0", "管理员", "0");

insert into user (id , name, password,canBorrow) values ("1", "任哲昆", "1",true);
insert into user (id , name, password,canBorrow) values ("2", "tom", "2",true);
insert into user (id , name, password,canBorrow) values ("3", "jime", "3",false);

insert into book (book_id, name, author_name, price, num, stock, publisher, publish_year, type) 
values ("00001", "C++ Primer 中文版", "Stanley B. Lippman", 128, 10, 10, "电子工业出版社", "2013", "计算机类");
insert into book (book_id, name, author_name, price, num, stock, publisher, publish_year, type) 
values ("00002", "月光落在左手上", "余秀华", 58, 2, 2, "北京十月文艺出版社", "2020", "文学类");
insert into book (book_id, name, author_name, price, num, stock, publisher, publish_year, type) 
values ("00003", "清代地方政府", "瞿同祖", 78, 5, 5, "新星出版社", "2022", "历史类");
insert into book (book_id, name, author_name, price, num, stock, publisher, publish_year, type) 
values ("00004", "从格致到科学", "张剑", 66, 8, 8, "中国工人出版社", "2022", "哲学类");
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

5.对于exe测试,可以直接打开前面下载的工程文件下的\EXE\LibraryManageByMysqlQt_boxed.exe,此时没有出现无法创建数据库连接,则环境配置成功。
另外,对于源码,需要在LibraryManageByMysqlQt\文件夹下新建debugrelease文件夹,并将工程构建目录选择为LibraryManageByMysqlQt下,编译源码即可运行。

核心代码:

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    /********** 类中变量初始化(主要针对指针) **********/
    loginwindow = NULL;
    registerwindow = NULL;
    userdetailwindow=NULL;
    bookdetailwindow=NULL;
    addbookwindow = NULL;

    booksearchwidget = NULL;
    bookborrowinfowidget=NULL;
    usermanagementwidget=NULL;
    bookmanagementwidget=NULL;

    people=NULL;
    timer = NULL;

    /********** 标题界面部分 **********/
    // 标题界面背景
    ui->widget_Title->setAutoFillBackground(true);
    QPalette palette;
    palette.setBrush(QPalette::Background, QBrush(QPixmap(":/images/titleBackground.jpg")));
    ui->widget_Title->setPalette(palette);
    // 配置标题界面中的按钮:登录、注册、退出登录
    ui->Button_login->setFlat(true);
    ui->Button_register->setFlat(true);
    ui->Button_quitLogin->setFlat(true);

    ui->Button_quitLogin->setDisabled(true); // 默认 退出登录按钮 隐藏
    ui->Button_quitLogin->hide();
    // 标题界面中的label更新(根据people的值,在timer中定时更新)
    people = new People();
    people->user_Type = People::VISITOR;
    people->user_Name =  "游客";
    people->user_ID="";
    people->user_Password="";
    people->user_canBorrow=false;
    people->booknum=0;

    timer = new QTimer();
    connect(timer, SIGNAL(timeout()), this, SLOT(SLOT_updatetime()));
    timer->start(500);

    /********** 连接数据库 **********/
    db = QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName("localhost");
    db.setPort(3306);
    db.setDatabaseName("mydatabase"); // 数据库名
    db.setUserName("root");  // 数据库用户名
    db.setPassword("root");  // 数据库的密码
    if(!db.open())
    {
        QMessageBox::critical(NULL, "Error", "注意:无法创建数据库连接!", QMessageBox::Yes);
    }

    /********** tabWidget界面部分 **********/
    // 删除UI控件自带的页面,注意:需要从大到小删除
    ui->tabWidget->removeTab(1);
    ui->tabWidget->removeTab(0);

    // 初始时,默认使用者为 游客 ,所以tabWidget只添加并显示 图书搜索页面
    booksearchwidgetCreate(); // 新建
    bookquerySearchUpdate(); // 刷新显示,默认“所有类型”
    ui->tabWidget->addTab(booksearchwidget,"图书搜索");
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::SLOT_updatetime()
{
    QDateTime current_date_time = QDateTime::currentDateTime();
    QString current_date = current_date_time.toString("yyyy-MM-dd  hh:mm:ss  ddd");
    QString text = "当前用户: " + people->user_Name + "     当前时间: " + current_date + "  ";
    ui->label_Title->setText(text);
}

void MainWindow::closeEvent(QCloseEvent *event)
{
    // 防止内存泄漏和野指针
    delete timer;
    timer=NULL;
    delete people;
    people=NULL;

    //window 自动清理
    if(loginwindow!=NULL)
    {
        loginwindow->close();
    }
    if(registerwindow!=NULL)
    {
        registerwindow->close();
    }
    if(userdetailwindow!=NULL)
    {
        userdetailwindow->close();
    }
    if(bookdetailwindow!=NULL)
    {
        bookdetailwindow->close();
    }
    if(addbookwindow!=NULL)
    {
        addbookwindow->close();
    }

    // widget手动清除内存
    if(booksearchwidget!=NULL)
    {
        delete booksearchwidget;
        booksearchwidget=NULL;
    }
    if(bookborrowinfowidget!=NULL)
    {
        delete bookborrowinfowidget;
        bookborrowinfowidget=NULL;
    }
    if(usermanagementwidget!=NULL)
    {
        delete usermanagementwidget;
        usermanagementwidget=NULL;
    }
    if(bookmanagementwidget!=NULL)
    {
        delete bookmanagementwidget;
        bookmanagementwidget=NULL;
    }
}


/****************************************************************************/
/******************************** 登录、注册界面相关 ********************************/
/****************************************************************************/
void MainWindow::on_Button_login_clicked()
{
    // 登录时,登录和注册按钮失能
    ui->Button_login->setDisabled(true);
    ui->Button_register->setDisabled(true);

    // 登录界面 新建与显示
    loginwindowCreateAndShow();
}

void MainWindow::SLOT_loginQuit()
{
    delete loginwindow; // 防止内存泄漏和野指针
    loginwindow=NULL;

    ui->Button_login->setEnabled(true);
    ui->Button_register->setEnabled(true);
}

void MainWindow::SLOT_login(bool isUser,QVector<QString> values)
{
    QSqlQuery query(db);

    if(isUser)
    {
        query.exec("select * from user where id = '"
                        +values.at(0)+"' and password = '"+values.at(1)+"';");
    }
    else
    {
        query.exec("select * from manager where id = '"
                        +values.at(0)+"' and password = '"+values.at(1)+"';");
    }
    if(!query.next()){
        QMessageBox::critical(NULL, "Error", "学号或密码错误,请重新输入", QMessageBox::Yes);
    }
    else
    { //登录成功
        //关闭登录界面
        loginwindow->close();
        /*** 标题界面部分 ***/
        // 配置标题界面中的按钮:登录、注册、退出登录
        ui->Button_login->setDisabled(true);
        ui->Button_login->hide();
        ui->Button_register->setDisabled(true);
        ui->Button_register->hide();
        ui->Button_quitLogin->setEnabled(true);
        ui->Button_quitLogin->show();

        // 保存用户信息
        people->user_Name=query.value("name").toString();
        people->user_ID=query.value("id").toString();
        people->user_Password=query.value("password").toString();
        people->user_Type=isUser?(People::USER):(People::MANAGER);
        people->user_canBorrow=(people->user_Type == People::USER)?query.value("canBorrow").toBool():false;
        people->booknum=0;//保持为0。当管理员登陆后需要使用时,再赋值使用

        /*** 页面以及界面处理 ***/
        if(people->user_Type == People::USER)
        {
            // (图书搜索页面) 恢复初始化
            emit Signal_booksearchwidgetClearAndUpdate();

            //(借阅情况页面) 新建并显示
            bookborrowinfowidgetCreate(); // 新建
            bookborrowqueryUpdate(); // 初始化显示
            ui->tabWidget->addTab(bookborrowinfowidget,"借阅情况");
        }
        else if(people->user_Type == People::MANAGER)
        {
            // (图书搜索页面) 删除
            if(booksearchwidget!=NULL)
            {
                delete booksearchwidget;
                booksearchwidget=NULL;
                ui->tabWidget->removeTab(0);
            }

            //(用户管理页面)新建并显示
            usermanagementwidgetCreate();
            usermanagementUpdate();//(用户管理界面)更新,初始化显示
            ui->tabWidget->addTab(usermanagementwidget,"用户管理");

            //(书籍管理页面)新建并显示
            bookmanagementwidgetCreate();
            bookmanagementUpdate();//(书籍管理界面)更新,初始化显示
            ui->tabWidget->addTab(bookmanagementwidget,"书籍管理");
        }
    }
}

void MainWindow::on_Button_register_clicked()
{
    if(people->user_Type == People::VISITOR)
    {
        // (游客)注册时,登录和注册按钮失能
        ui->Button_login->setDisabled(true);
        ui->Button_register->setDisabled(true);
    }

    // 注册界面 新建与显示
    registerwindowCreateAndShow();
}

void MainWindow::SLOT_registerQuit()
{
    delete registerwindow; //防止内存泄漏和野指针
    registerwindow=NULL;

    ui->Button_login->setEnabled(true);
    ui->Button_register->setEnabled(true);
}

void MainWindow::SLOT_register(QVector<QString> values)
{
    QSqlQuery query(db);
    query.exec("select * from user where id = '"
                    +values.at(0)+"';");
    if(query.next())
    {
        QMessageBox::critical(NULL, "Error", "这个学号已经被注册,请重新确认", QMessageBox::Yes);
    }
    else
    {
        QString queryCommand="insert into user (id , name, password, canBorrow) values('" +
                values.at(0) + "','" + values.at(1) + "','" + values.at(2) + "',false);";
        query.exec(queryCommand);

        QMessageBox::information(NULL, "Info", "id为" + values.at(0) + "的普通用户注册成功", QMessageBox::Yes);

        registerwindow->close();
    }

    if(people->user_Type == People::MANAGER)
    {
        // 管理员注册用户后,更新(用户管理界面)
        usermanagementUpdate();
    }
}

void MainWindow::on_Button_quitLogin_clicked()
{
    int user_Type_Old=people->user_Type; // 保存退出前的用户性质

    // people值恢复成默认值
    people->user_Type = People::VISITOR;
    people->user_Name =  "游客";
    people->user_ID="";
    people->user_Password="";
    people->user_canBorrow=false;
    people->booknum=0;

    // 按钮配置:(退出登录) 隐藏, (注册)、(登录) 显示
    ui->Button_quitLogin->hide();
    ui->Button_login->setEnabled(true);
    ui->Button_login->show();
    ui->Button_register->setEnabled(true);
    ui->Button_register->show();

    /*** 页面以及界面处理 ***/
    if(user_Type_Old == People::USER)
    {
        // (借阅情况页面) 删除
        delete bookborrowinfowidget;
        bookborrowinfowidget=NULL;
        ui->tabWidget->removeTab(1);

        // (图书搜索页面) 删除(需要调用析构函数来删除表中checkbox)
        delete booksearchwidget;
        booksearchwidget=NULL;
        ui->tabWidget->removeTab(0);

    }
    else if(user_Type_Old == People::MANAGER)
    {
        // (书籍管理页面) 删除
        delete bookmanagementwidget;
        bookmanagementwidget = NULL;
        ui->tabWidget->removeTab(1);
        // 书籍管理页面 的 弹窗 (书籍详细信息界面) 如果未关闭则关闭
        if(bookdetailwindow!=NULL)// 判断 (书籍详细信息界面) 是否存在,存在则关闭
        {
            bookdetailwindow->close();//自动清理
        }

        // (用户管理页面) 删除
        delete usermanagementwidget;
        usermanagementwidget=NULL;
        ui->tabWidget->removeTab(0);
        // 用户管理页面 的 弹窗 (用户详细信息界面) 如果未关闭则关闭
        if(userdetailwindow!=NULL)// 判断 (用户详细信息界面) 是否存在,存在则关闭
        {
            userdetailwindow->close(); // 已经定义相关槽函数,会自动清理
        }
    }
    // (图书搜索页面)新建
    booksearchwidgetCreate(); // 新建
    bookquerySearchUpdate(); // 刷新显示,默认“所有类型”
    ui->tabWidget->addTab(booksearchwidget,"图书搜索");
}

void MainWindow::loginwindowCreateAndShow()
{
    loginwindow = new LoginWindow();
    loginwindow->setWindowTitle("登录");
    loginwindow->show();
    connect(loginwindow,SIGNAL(Signal_loginQuit()),this,SLOT(SLOT_loginQuit()));
    connect(loginwindow,SIGNAL(Signal_login(bool,QVector<QString>)),this,SLOT(SLOT_login(bool,QVector<QString>)));
}

void MainWindow::registerwindowCreateAndShow()
{
    registerwindow = new RegisterWindow();
    registerwindow->setWindowTitle("注册");
    registerwindow->show();
    connect(registerwindow,SIGNAL(Signal_registerQuit()),this,SLOT(SLOT_registerQuit()));
    connect(registerwindow,SIGNAL(Signal_register(QVector<QString>)),this,SLOT(SLOT_register(QVector<QString>)));
}

/****************************************************************************/
/******************************** 图书搜索页面相关 ********************************/
/****************************************************************************/
void MainWindow::booksearchwidgetCreate()
{
    booksearchwidget = new BookSearchWidget();

    connect(booksearchwidget,SIGNAL(Signal_bookquerySearch(BookQuery)),this,SLOT(SLOT_bookquerySearch(BookQuery)));
    connect(this,SIGNAL(Signal_bookqueryResult(QVector<Book>,People*)),booksearchwidget,SLOT(SLOT_bookqueryResult(QVector<Book>,People*)));
    connect(booksearchwidget,SIGNAL(Signal_bookBorrow(QVector<QString>)),this,SLOT(SLOT_bookBorrow(QVector<QString>)));
    connect(this,SIGNAL(Signal_booksearchwidgetClearAndUpdate()),booksearchwidget,SLOT(SLOT_booksearchwidgetClearAndUpdate()));
}

void MainWindow::SLOT_bookquerySearch(BookQuery bookquery)
{
    bookquerySearchUpdate(bookquery);
}

void MainWindow::bookquerySearchUpdate(BookQuery bookquery)
{
    QVector<Book> Catalog = booksData(bookquery, false);
    emit Signal_bookqueryResult(Catalog, people); //返回搜索结果
}

void MainWindow::bookquerySearchUpdate()
{
    BookQuery bookquery;
    QVector<Book> Catalog = booksData(bookquery, true);
    emit Signal_bookqueryResult(Catalog, people); //返回搜索结果
}

QVector<Book> MainWindow::booksData(BookQuery bookquery, bool recover)
{
    QSqlQuery query(db);
    QString queryCommand;
    int flag_firstsatisfy=0;
    // 构建数据库命令
    if(recover == true)
    {
        queryCommand="select * from book;";
    }
    else
    {
        queryCommand="select * from book";
        if(!(bookquery.book_id == "" && bookquery.name == "" && bookquery.author_name == "" &&
            bookquery.begin_year == 0 && bookquery.end_year == 0 && bookquery.publisher =="" &&
            bookquery.low_price == 0 && bookquery.high_price == 0 && bookquery.have_stock == false &&
            bookquery.type == "所有类型"))
        { // 需要筛选
            queryCommand += " where ";

            if(bookquery.book_id != "")
            {
                queryCommand += "book_id='"+bookquery.book_id+"'";
                flag_firstsatisfy = 1;
            }
            if(bookquery.name != "")
            {
                if(flag_firstsatisfy == 0)
                {
                    flag_firstsatisfy=1;
                }
                else
                {
                    queryCommand += " and ";
                }
                queryCommand += "name='"+bookquery.name+"'";
            }
            if(bookquery.author_name != "")
            {
                if(flag_firstsatisfy == 0)
                {
                    flag_firstsatisfy=1;
                }
                else
                {
                    queryCommand += " and ";
                }
                queryCommand += "author_name='"+bookquery.author_name+"'";
            }
            if(!(bookquery.begin_year == 0 && bookquery.end_year == 0))
            {
                if(flag_firstsatisfy == 0)
                {
                    flag_firstsatisfy=1;
                }
                else
                {
                    queryCommand += " and ";
                }
                queryCommand += "publish_year>="+QString::number(bookquery.begin_year,10)+
                                " and publish_year<="+QString::number(bookquery.end_year,10);
            }
            if(bookquery.publisher !="")
            {
                if(flag_firstsatisfy == 0)
                {
                    flag_firstsatisfy=1;
                }
                else
                {
                    queryCommand += " and ";
                }
                queryCommand += "publisher='"+bookquery.publisher+"'";
            }
            if(!(bookquery.low_price == 0 && bookquery.high_price == 0))
            {
                if(flag_firstsatisfy == 0)
                {
                    flag_firstsatisfy=1;
                }
                else
                {
                    queryCommand += " and ";
                }
                queryCommand += "price>="+QString::number(bookquery.low_price,'f',2)+
                                " and price<="+QString::number(bookquery.high_price,'f',2);
            }
            if(bookquery.have_stock != false)
            {
                if(flag_firstsatisfy == 0)
                {
                    flag_firstsatisfy=1;
                }
                else
                {
                    queryCommand += " and ";
                }
                queryCommand += "stock!=0";
            }
            if(bookquery.type != "所有类型")
            {
                if(flag_firstsatisfy == 0)
                {
                    flag_firstsatisfy=1;
                }
                else
                {
                    queryCommand += " and ";
                }
                queryCommand += "type='"+bookquery.type+"'";
            }
        }
        queryCommand+=";";
    }
    //执行数据库命令
    query.exec(queryCommand);

    //存储搜索结果
    QVector<Book> Catalog;
    Book book;
    while(query.next())
    {
        book.book_id=query.value("book_id").toString();
        book.name=query.value("name").toString();
        book.author_name=query.value("author_name").toString();
        book.price=query.value("price").toDouble();
        book.num=query.value("num").toInt();
        book.stock=query.value("stock").toInt();
        book.publisher=query.value("publisher").toString();
        book.publish_year=query.value("publish_year").toString();
        book.type=query.value("type").toString();
        Catalog.append(book);
    }
    return Catalog;
}

void MainWindow::SLOT_bookBorrow(QVector<QString> bookborrow)
{
    int sucessNum=0,errorNum=0;
    int borrowNum=bookborrow.size();
    QSqlQuery query(db);
    QString queryCommand;

    QDate dateBorrow = QDate::currentDate();//.toString("yyyy-MM-dd")
    QDate dateReturn = dateBorrow.addDays(+30);//默认借30天,此外,获取剩余时间的方法:dateBorrow.daysTo(dateReturn);

    if(borrowNum>0)
    {
        if(people->user_canBorrow==true)
        {
            for (int i = 0; i < borrowNum; i++)
            {
                queryCommand="insert into borrow (user_id, book_id, borrow_date, return_date) value ('"+
                        people->user_ID+"', '"+bookborrow[i]+"', '"+dateBorrow.toString("yyyy-MM-dd")+"', '"+
                        dateReturn.toString("yyyy-MM-dd")+"');";
                if(query.exec(queryCommand) == true)
                {
                    //更新book中的剩余量
                    queryCommand="select stock from book where book_id='"+bookborrow[i]+"';";
                    query.exec(queryCommand);
                    if(query.next())
                    {
                        int stock=query.value("stock").toInt();
                        stock-=1;
                        queryCommand="update book set stock="+QString::number(stock,10)+" where book_id='"+bookborrow[i]+"';";
                        if(query.exec(queryCommand))
                        {
                            sucessNum++;
                        }
                        else
                        {
                            errorNum++;
                        }
                    }
                    else
                    {
                       errorNum++;
                    }
                }
                else
                {
                    errorNum++;
                }
            }
            QMessageBox::information(NULL, "Info", "您借阅成功"+QString::number(sucessNum,10)+"本,借阅失败"+QString::number(errorNum,10)+"本", QMessageBox::Yes);
            //借书后,更新图书检索页面
            emit Signal_booksearchwidgetClearAndUpdate();
            //借书后,更新借阅情况页面
            bookborrowqueryUpdate();
        }
        else
        {
            QMessageBox::critical(NULL, "Info", "您没有借书权限,请联系管理员开启", QMessageBox::Yes);
        }
    }
    else
    {
        QMessageBox::critical(NULL, "Info", "您尚未选择任何书籍", QMessageBox::Yes);
    }
}

/****************************************************************************/
/******************************** 借阅情况页面相关 ********************************/
/****************************************************************************/
void MainWindow::bookborrowinfowidgetCreate()
{
    bookborrowinfowidget = new BookBorrowInfoWidget();
    connect(this,SIGNAL(Signal_bookborrowqueryResult(QVector<BorrowBook>,People*)),bookborrowinfowidget,SLOT(SLOT_bookborrowqueryResult(QVector<BorrowBook>,People*)));
    connect(bookborrowinfowidget,SIGNAL(Signal_bookReturn(QVector<QString>)),this,SLOT(SLOT_bookReturn(QVector<QString>)));
}

void MainWindow::bookborrowqueryUpdate()
{
    QSqlQuery query(db);
    QString queryCommand;
    if(people->user_Type == People::USER)
    {
        queryCommand="select * from borrow where user_id='" + people->user_ID +"';";
        query.exec(queryCommand);

        QVector<BorrowBook> Catalog;
        BorrowBook borrowbook;
        while(query.next())
        {
            borrowbook.userID=query.value("user_id").toString();
            borrowbook.book.book_id=query.value("book_id").toString();
            borrowbook.dateBorrow=query.value("borrow_date").toString();
            borrowbook.dateReturn=query.value("return_date").toString();
            Catalog.append(borrowbook);
        }

        for(int i=0;i<Catalog.size();i++)
        {//继续完善Catalog
            queryCommand="select * from book where book_id='" + Catalog[i].book.book_id +"';";
            query.exec(queryCommand);
            if(query.next())
            {
                Catalog[i].book.name=query.value("name").toString();
                Catalog[i].book.author_name=query.value("author_name").toString();
                Catalog[i].book.price=query.value("price").toDouble();
                Catalog[i].book.num=query.value("num").toInt();
                Catalog[i].book.stock=query.value("stock").toInt();
                Catalog[i].book.publisher=query.value("publisher").toString();
                Catalog[i].book.publish_year=query.value("publish_year").toString();
                Catalog[i].book.type=query.value("type").toString();
            }
        }
        emit Signal_bookborrowqueryResult(Catalog,people);
    }
}

void MainWindow::SLOT_bookReturn(QVector<QString> bookreturn)
{
    int sucessNum=0,errorNum=0;
    int returnNum=bookreturn.size();
    QSqlQuery query(db);

    if(returnNum>0)
    {
        for (int i = 0; i < returnNum; i++)
        {
            QString queryCommand="delete from borrow where user_id='"+people->user_ID+"' and book_id='"+
                                 bookreturn[i]+"';";
            if(query.exec(queryCommand) == true)
            {
                //更新book中的剩余量
                queryCommand="select stock from book where book_id='"+bookreturn[i]+"';";
                query.exec(queryCommand);
                if(query.next())
                {
                    int stock=query.value("stock").toInt();
                    stock+=1;
                    queryCommand="update book set stock="+QString::number(stock,10)+" where book_id='"+bookreturn[i]+"';";
                    if(query.exec(queryCommand))
                    {
                        sucessNum++;
                    }
                    else
                    {
                        errorNum++;
                    }
                }
                else
                {
                   errorNum++;
                }
            }
            else
            {
                errorNum++;
            }
        }
        QMessageBox::information(NULL, "Info", "您归还成功"+QString::number(sucessNum,10)+"本,归还失败"+QString::number(errorNum,10)+"本", QMessageBox::Yes);
    }
    else
    {
        QMessageBox::critical(NULL, "Error", "您尚未选择任何书籍", QMessageBox::Yes);
    }

    //还书后,更新图书检索页面
    emit Signal_booksearchwidgetClearAndUpdate();// 释放信号,(图书搜索界面)整个界面恢复初始化
    //还书后,更新借阅情况页面
    bookborrowqueryUpdate();
}

/****************************************************************************/
/******************************** 用户管理页面相关 ********************************/
/****************************************************************************/
void MainWindow::usermanagementwidgetCreate()
{
    usermanagementwidget=new UserManagementWidget();
    connect(this,SIGNAL(Signal_usermanagementResult(QVector<People>)),usermanagementwidget,SLOT(SLOT_usermanagementResult(QVector<People>)));
    connect(usermanagementwidget,SIGNAL(Signal_SearchUserDetailInfo(QString)),this,SLOT(SLOT_SearchUserDetailInfo(QString)));
    connect(this,SIGNAL(Signal_enableButton_SearchUserDetail()),usermanagementwidget,SLOT(SLOT_enableButton_SearchUserDetail()));
    connect(this,SIGNAL(Signal_disableButton_SearchUserDetail()),usermanagementwidget,SLOT(SLOT_disableButton_SearchUserDetail()));
    connect(usermanagementwidget,SIGNAL(Signal_changeUserPri(QVector<QString>)),this,SLOT(SLOT_changeUserPri(QVector<QString>)));
    connect(usermanagementwidget,SIGNAL(Signal_deleteUser(QVector<QString>)),this,SLOT(SLOT_deleteUser(QVector<QString>)));
    connect(usermanagementwidget,SIGNAL(Signal_addUser()),this,SLOT(on_Button_register_clicked()));
}

void MainWindow::usermanagementUpdate()
{
    QSqlQuery query(db);
    QSqlQuery query0(db);

    QString queryCommand;
    if(people->user_Type == People::MANAGER)
    {
        queryCommand="select * from user;";
        query.exec(queryCommand);

        QVector<People> Catalog;
        People user;

        while(query.next())
        {
            user.user_Name=query.value("name").toString();
            user.user_ID=query.value("id").toString();
            user.user_Password=query.value("password").toString();
            user.user_Type=People::USER;
            user.user_canBorrow=query.value("canBorrow").toBool();
            //获取借阅数
            queryCommand="select * from borrow where user_id='"+user.user_ID+"';";
            query0.exec(queryCommand);
            user.booknum=query0.size();
            Catalog.append(user);
        }

        emit Signal_usermanagementResult(Catalog);
    }
}

void MainWindow::SLOT_userdetailwindowClosed()
{
    userdetailwindowClosed();
}

void MainWindow::userdetailwindowClosed()
{
    userdetailwindow->close();
    delete userdetailwindow; //防止内存泄漏和野指针
    userdetailwindow=NULL;
    emit Signal_enableButton_SearchUserDetail();
}

void MainWindow::SLOT_SearchUserDetailInfo(QString userID)
{
    //查询信息
    QSqlQuery query(db);
    QSqlQuery query0(db);
    QString queryCommand;
    UserDetial userdetial;
    BorrowBook borrowbook;

    if(people->user_Type == People::MANAGER)
    {
        queryCommand="select * from user where id='"+userID+"';";
        query.exec(queryCommand);
        if(query.next())
        {
            //(用户详细信息界面),显示出来
            userdetailwindow = new UserDetailWindow();
            userdetailwindow->setWindowTitle("用户详细信息");
            userdetailwindow->show();

            connect(userdetailwindow,SIGNAL(Signal_userdetailwindowClosed()),this,SLOT(SLOT_userdetailwindowClosed()));
            connect(this,SIGNAL(Signal_SearchUserDetailUpdate(UserDetial)),userdetailwindow,SLOT(SLOT_SearchUserDetailUpdate(UserDetial)));
            connect(userdetailwindow,SIGNAL(Signal_changeUserInfo(UserDetial)),this,SLOT(SLOT_changeUserInfo(UserDetial)));
            connect(this,SIGNAL(Signal_OnlyUserDetailUpdate(UserDetial)),userdetailwindow,SLOT(SLOT_OnlyUserDetailUpdate(UserDetial)));
            connect(userdetailwindow,SIGNAL(Signal_deleteUser(UserDetial)),this,SLOT(SLOT_deleteUser(UserDetial)));

            userdetial.user.user_Name=query.value("name").toString();
            userdetial.user.user_ID=query.value("id").toString();
            userdetial.user.user_Password=query.value("password").toString();
            userdetial.user.user_canBorrow=query.value("canBorrow").toBool();
            //获取借阅数
            queryCommand="select book_id from borrow where user_id='"+userdetial.user.user_ID+"';";
            query.exec(queryCommand);
            userdetial.user.booknum=query.size();

            //继续查询借阅书本信息
            while(query.next())
            {
                borrowbook.book.book_id = query.value("book_id").toString();

                queryCommand="select * from book where book_id='" + borrowbook.book.book_id +"';";
                query0.exec(queryCommand);
                if(query0.next())
                {
                    borrowbook.book.name=query0.value("name").toString();
                }

                queryCommand="select * from borrow where user_id='" + userdetial.user.user_ID +
                             "' and book_id='"+borrowbook.book.book_id+"';";
                query0.exec(queryCommand);
                if(query0.next())
                {
                    borrowbook.dateBorrow=query0.value("borrow_date").toString();
                    borrowbook.dateReturn=query0.value("return_date").toString();
                }
                userdetial.borrowbook.append(borrowbook);
            }

            emit Signal_SearchUserDetailUpdate(userdetial);
            emit Signal_disableButton_SearchUserDetail();
        }
        else
        {
            QMessageBox::critical(NULL, "Error", "查询失败,可能没有该用户", QMessageBox::Yes);
        }
    }
}

void MainWindow::SLOT_changeUserInfo(UserDetial userdetialOld)
{
    QSqlQuery query(db);
    QString queryCommand;
    if(people->user_Type == People::MANAGER)
    {
        //更新数据库
        queryCommand = QString("update user set name='%1', password='%2', canBorrow=%3 where id='%4';").arg(userdetialOld.user.user_Name, userdetialOld.user.user_Password,userdetialOld.user.user_canBorrow?"true":"false", userdetialOld.user.user_ID);
        query.exec(queryCommand);

        //从数据中读取新的值
        queryCommand = QString("select name,password,canBorrow from user where id='%1';").arg(userdetialOld.user.user_ID);
        query.exec(queryCommand);

        if(query.next())
        {
            userdetialOld.user.user_Name=query.value("name").toString();
            userdetialOld.user.user_Password=query.value("password").toString();
            userdetialOld.user.user_canBorrow=query.value("canBorrow").toBool();

            emit Signal_OnlyUserDetailUpdate(userdetialOld);
            usermanagementUpdate();
            if(bookdetailwindow!=NULL)
            {
                bookdetailwindow->close();
            }
            QMessageBox::information(NULL, "Info", "用户信息已更新", QMessageBox::Yes);
        }
    }
}

void MainWindow::SLOT_deleteUser(UserDetial userdetialNow)
{
    QSqlQuery query(db);
    QString queryCommand;
    if(people->user_Type == People::MANAGER)
    {
        //删除用户需要用户借阅数量为0
        queryCommand="select * from borrow where user_id='"+userdetialNow.user.user_ID+"';";
        query.exec(queryCommand);
        if(query.size()!=0)
        {
            QMessageBox::critical(NULL, "Error", "用户有借阅,不能删除", QMessageBox::Yes);
        }
        else
        {
            queryCommand = QString("delete from user where id='%1';").arg(userdetialNow.user.user_ID);
            query.exec(queryCommand);

            userdetailwindowClosed();
            usermanagementUpdate();
            QMessageBox::information(NULL, "Info", "用户删除成功", QMessageBox::Yes);
        }
    }
}

void MainWindow::SLOT_changeUserPri(QVector<QString> changepriuser)
{
    int changeNum=changepriuser.size();
    QSqlQuery query(db);
    QString queryCommand;
    bool changeuserPri=false;

    if(changeNum > 0)
    {
        for (int i = 0; i < changeNum; i++)
        {
            queryCommand = QString("select canBorrow from user where id='%1';").arg(changepriuser[i]);
            query.exec(queryCommand);
            if(query.next())
            {
                changeuserPri=query.value("canBorrow").toBool();
            }
            queryCommand = QString("update user set canBorrow=%1 where id='%2';").arg(changeuserPri?"false":"true", changepriuser[i]);
            query.exec(queryCommand);
        }
    }
    else
    {
        QMessageBox::critical(NULL, "Error", "请正确选择需要修改的用户", QMessageBox::Yes);
    }

    //更改后,判断是否有打开了(用户详细信息界面)。若打开则关闭
    if(userdetailwindow!=NULL)
    {
        userdetailwindow->close();
        delete userdetailwindow;
        userdetailwindow=NULL;
    }
    // 更改后,更新(用户管理界面)
    usermanagementUpdate();
}

void MainWindow::SLOT_deleteUser(QVector<QString> deleteuser)
{
    int sucessNum=0;
    int deleteNum=deleteuser.size();
    QSqlQuery query(db);
    QString queryCommand;

    if(deleteNum > 0)
    {
        for (int i = 0; i < deleteNum; i++)
        {
            queryCommand = QString("delete from user where id='%1';").arg(deleteuser[i]);
            if(query.exec(queryCommand) == true)
            {
                sucessNum++;
            }
        }
        if(sucessNum > 0)
        {
            QMessageBox::information(NULL, "Info", "成功删除"+QString::number(sucessNum,10)+"名用户", QMessageBox::Yes);
        }
    }
    else
    {
        QMessageBox::critical(NULL, "Error", "请正确选择需要修改的用户", QMessageBox::Yes);
    }

    //更改后,判断是否有打开了(用户详细信息界面)。若打开则关闭
    if(userdetailwindow!=NULL)
    {
        userdetailwindow->close();
        delete userdetailwindow;
        userdetailwindow=NULL;
    }

    // 更改后,更新(用户管理界面)
    usermanagementUpdate();
}

/****************************************************************************/
/******************************** 书籍管理页面相关 ********************************/
/****************************************************************************/
void MainWindow::bookmanagementwidgetCreate()
{
    bookmanagementwidget = new BookManagementWidget();
    connect(this,SIGNAL(Signal_bookmanagementResult(QVector<Book>)),bookmanagementwidget,SLOT(SLOT_bookmanagementResult(QVector<Book>)));
    connect(bookmanagementwidget,SIGNAL(Signal_SearchBookDetailInfo(QString)),this,SLOT(SLOT_SearchBookDetailInfo(QString)));
    connect(this,SIGNAL(Signal_enableButton_SearchBookDetail()),bookmanagementwidget,SLOT(SLOT_enableButton_SearchBookDetail()));
    connect(this,SIGNAL(Signal_disableButton_SearchBookDetail()),bookmanagementwidget,SLOT(SLOT_disableButton_SearchBookDetail()));
    connect(bookmanagementwidget,SIGNAL(Signal_deleteBook(QVector<QString>)),this,SLOT(SLOT_deleteBook(QVector<QString>)));
    connect(bookmanagementwidget,SIGNAL(Signal_addBook()),this,SLOT(SLOT_addBook()));
    connect(this,SIGNAL(Signal_enableButton_addBook()),bookmanagementwidget,SLOT(SLOT_enableButton_addBook()));
    connect(this,SIGNAL(Signal_disableButton_addBook()),bookmanagementwidget,SLOT(SLOT_disableButton_addBook()));
}

void MainWindow::bookmanagementUpdate()
{
    BookQuery bookquery;
    QVector<Book> Catalog = booksData(bookquery, true);

    emit Signal_bookmanagementResult(Catalog);
}

void MainWindow::SLOT_SearchBookDetailInfo(QString bookID)
{
    QSqlQuery query(db);
    QSqlQuery query0(db);
    QString queryCommand;
    BookDetial bookdetial;
    BorrowUser borrowuser;

    if(people->user_Type == People::MANAGER)
    {
        queryCommand="select * from book where book_id='"+bookID+"';";
        query.exec(queryCommand);
        if(query.next())
        {
            //(书籍详细信息界面),显示出来
            bookdetailwindow = new BookDetailWindow();
            bookdetailwindow->setWindowTitle("书籍详细信息");
            bookdetailwindow->show();

            connect(bookdetailwindow,SIGNAL(Signal_bookdetailwindowClosed()),this,SLOT(SLOT_bookdetailwindowClosed()));
            connect(this,SIGNAL(Signal_SearchBookDetailUpdate(BookDetial)),bookdetailwindow,SLOT(SLOT_SearchBookDetailUpdate(BookDetial)));
            connect(bookdetailwindow,SIGNAL(Signal_changeBookInfo(BookDetial)),this,SLOT(SLOT_changeBookInfo(BookDetial)));
            connect(this,SIGNAL(Signal_OnlyBookDetailUpdate(BookDetial)),bookdetailwindow,SLOT(SLOT_OnlyBookDetailUpdate(BookDetial)));
            connect(bookdetailwindow,SIGNAL(Signal_deleteBook(BookDetial)),this,SLOT(SLOT_deleteBook(BookDetial)));

            bookdetial.book.book_id = query.value("book_id").toString();
            bookdetial.book.name=query.value("name").toString();
            bookdetial.book.author_name=query.value("author_name").toString();
            bookdetial.book.price=query.value("price").toDouble();
            bookdetial.book.num=query.value("num").toInt();
            bookdetial.book.stock=query.value("stock").toInt();
            bookdetial.book.publisher=query.value("publisher").toString();
            bookdetial.book.publish_year=query.value("publish_year").toString();
            bookdetial.book.type=query.value("type").toString();

            //获取借阅人员
            queryCommand="select * from borrow where book_id='"+bookdetial.book.book_id+"';";
            query.exec(queryCommand);
            //继续查询借阅人员信息
            while(query.next())
            {
                borrowuser.user.user_ID = query.value("user_id").toString();
                borrowuser.dateBorrow = query.value("borrow_date").toString();
                borrowuser.dateReturn = query.value("return_date").toString();

                queryCommand="select name from user where id='" + borrowuser.user.user_ID +"';";
                query0.exec(queryCommand);
                if(query0.next())
                {
                    borrowuser.user.user_Name = query0.value("name").toString();
                }
                bookdetial.user.append(borrowuser);
            }

            emit Signal_SearchBookDetailUpdate(bookdetial);
            emit Signal_disableButton_SearchBookDetail();

            //关闭(书籍添加页面)。判断
            if(addbookwindow!=NULL)
            {
                addbookwindow->close();
            }
        }
        else
        {
            QMessageBox::critical(NULL, "Error", "查询失败,可能没有该书籍", QMessageBox::Yes);
        }
    }
}

void MainWindow::SLOT_bookdetailwindowClosed()
{
    bookdetailwindowClosed();
}

void MainWindow::bookdetailwindowClosed()
{
    bookdetailwindow->close();
    delete bookdetailwindow; //防止内存泄漏和野指针
    bookdetailwindow=NULL;
    emit Signal_enableButton_SearchBookDetail();
}

void MainWindow:: SLOT_changeBookInfo(BookDetial bookdetialOld)
{
    QSqlQuery query(db);
    QString queryCommand;
    if(people->user_Type == People::MANAGER)
    {
        //更新数据库
        queryCommand = QString("update book set name='%1', author_name='%2', price=%3, num=%4, stock=%5, publisher='%6', publish_year='%7', type='%8' where book_id='%9';").arg(bookdetialOld.book.name, bookdetialOld.book.author_name, QString::number(bookdetialOld.book.price, 'f', 2), QString::number(bookdetialOld.book.num, 10), QString::number(bookdetialOld.book.stock, 10), bookdetialOld.book.publisher, bookdetialOld.book.publish_year, bookdetialOld.book.type, bookdetialOld.book.book_id);
        query.exec(queryCommand);

        //从数据中读取新的值
        queryCommand = QString("select * from book where book_id='%1';").arg(bookdetialOld.book.book_id);
        query.exec(queryCommand);

        if(query.next())
        {
            bookdetialOld.book.name=query.value("name").toString();
            bookdetialOld.book.author_name=query.value("author_name").toString();
            bookdetialOld.book.price=query.value("price").toDouble();
            bookdetialOld.book.num=query.value("num").toInt();
            bookdetialOld.book.stock=query.value("stock").toInt();
            bookdetialOld.book.publisher=query.value("publisher").toString();
            bookdetialOld.book.publish_year=query.value("publish_year").toString();
            bookdetialOld.book.type=query.value("type").toString();

            emit Signal_OnlyBookDetailUpdate(bookdetialOld);
            bookmanagementUpdate();
            if(userdetailwindow!=NULL)
            {
                userdetailwindow->close();
            }
            QMessageBox::information(NULL, "Info", "书籍信息已更新", QMessageBox::Yes);
        }
    }
}

void MainWindow::SLOT_deleteBook(BookDetial bookdetialNow)
{
    QSqlQuery query(db);
    QString queryCommand;
    if(people->user_Type == People::MANAGER)
    {
        //删除用户需要用户借阅数量为0
        queryCommand="select * from borrow where book_id='"+bookdetialNow.book.book_id+"';";
        query.exec(queryCommand);
        if(query.size()!=0)
        {
            QMessageBox::critical(NULL, "Error", "用户有借阅,不能删除", QMessageBox::Yes);
        }
        else
        {
            queryCommand = QString("delete from book where book_id='%1';").arg(bookdetialNow.book.book_id);
            query.exec(queryCommand);

            bookdetailwindowClosed();
            bookmanagementUpdate();

            QMessageBox::information(NULL, "Info", "书籍删除成功", QMessageBox::Yes);
        }
    }
}

void MainWindow::SLOT_addBook()
{
    if(people->user_Type == People::MANAGER)
    {
        //显示(注册界面)
        addbookwindow = new AddBookWindow();
        addbookwindow->setWindowTitle("书籍添加/更新界面");
        addbookwindow->show();

        connect(addbookwindow,SIGNAL(Signal_addbookwindowClosed()),this,SLOT(SLOT_addbookwindowClosed()));
        connect(addbookwindow,SIGNAL(Signal_addOneBook(Book)),this,SLOT(SLOT_addOneBook(Book)));
        connect(addbookwindow,SIGNAL(Signal_addSomeBooks(QVector<Book>)),this,SLOT(SLOT_addSomeBooks(QVector<Book>)));

        emit Signal_disableButton_addBook();
        //关闭(书籍详细信息页面)。判断
        if(bookdetailwindow!=NULL)
        {
            bookdetailwindow->close();
        }
    }

}

void MainWindow::SLOT_addbookwindowClosed()
{
   addbookwindowClosed();
}

void MainWindow::addbookwindowClosed()
{
    addbookwindow->close();
    delete addbookwindow; //防止内存泄漏和野指针
    addbookwindow=NULL;
    emit Signal_enableButton_addBook();
}

void MainWindow::SLOT_deleteBook(QVector<QString> deletebook)
{
    int sucessNum=0;
    int deleteNum=deletebook.size();
    QSqlQuery query(db);
    QString queryCommand;

    if(deleteNum > 0)
    {
        for (int i = 0; i < deleteNum; i++)
        {
            queryCommand = QString("delete from book where book_id='%1';").arg(deletebook[i]);
            if(query.exec(queryCommand) == true)
            {
                sucessNum++;
            }
        }
        if(sucessNum > 0)
        {
            QMessageBox::information(NULL, "Info", "成功删除"+QString::number(sucessNum,10)+"本书籍", QMessageBox::Yes);
        }
    }
    else
    {
        QMessageBox::critical(NULL, "Error", "请正确选择需要修改的用户", QMessageBox::Yes);
    }

    //更改后,判断是否有打开了(书籍详细信息界面)。若打开则关闭
    if(bookdetailwindow!=NULL)
    {
        bookdetailwindow->close();//自动回收
    }

    // 更改后,更新(书籍管理界面)
    bookmanagementUpdate();
}

void MainWindow::SLOT_addOneBook(Book addbook)
{
    if(people->user_Type == People::MANAGER)
    {
        QSqlQuery query(db);
        QString queryCommand;

        queryCommand="select * from book where book_id='"+addbook.book_id+"';";
        query.exec(queryCommand);

        if(query.size()!=0)
        {
            //已经存在,更新

            if(addbook.num < (query.value("num").toInt() - query.value("stock").toInt()))//更新后的数量小于借出量时,不进行更新
            {
                QMessageBox::critical(NULL, "Error", "请修改书籍数量大于借出量:"+QString::number((query.value("num").toInt() - query.value("stock").toInt()),10), QMessageBox::Yes);
                return ;
            }

            queryCommand=QString("update book set name='%1', author_name='%2', price=%3, num=%4, stock=%5, publisher='%6', publish_year='%7', type='%8' where book_id='%9'").arg(addbook.name, addbook.author_name, QString::number(addbook.price,'f',2), QString::number(addbook.num,10), QString::number(addbook.stock,10), addbook.publisher, addbook.publish_year, addbook.type, addbook.book_id);
            query.exec(queryCommand);
        }
        else
        {
            //新书,添加
            queryCommand=QString("insert into book (book_id, name, author_name, price, num, stock, publisher, publish_year, type) values ('%1', '%2', '%3', %4, %5, %6, '%7', '%8', '%9');").arg(addbook.book_id, addbook.name, addbook.author_name, QString::number(addbook.price,'f',2), QString::number(addbook.num,10), QString::number(addbook.stock,10), addbook.publisher, addbook.publish_year, addbook.type);
            query.exec(queryCommand);
        }

        bookmanagementUpdate();
        if(userdetailwindow!=NULL)
        {
            userdetailwindow->close();
        }
        if(bookdetailwindow!=NULL)
        {
            userdetailwindow->close();
        }

        QMessageBox::information(NULL, "Info", "成功添加/更新书籍", QMessageBox::Yes);
    }
}

void MainWindow::SLOT_addSomeBooks(QVector<Book> addbooks)
{
    if(people->user_Type == People::MANAGER)
    {
        QSqlQuery query(db);
        QString queryCommand;
        int addSucess=0;
        int updateSucess=0;
        int addNum=addbooks.size();
        for(int i=0;i<addNum;i++)
        {
            queryCommand="select * from book where book_id='"+addbooks[i].book_id+"';";
            query.exec(queryCommand);

            if(query.size()!=0)
            {
                //已经存在,更新
                if(addbooks[i].num < (query.value("num").toInt() - query.value("stock").toInt()))//更新后的数量小于借出量时,不进行更新
                {
                    QMessageBox::critical(NULL, "Error", "请修改书籍数量大于借出量:"+QString::number((query.value("num").toInt() - query.value("stock").toInt()),10), QMessageBox::Yes);
                    return ;
                }
                queryCommand=QString("update book set name='%1', author_name='%2', price=%3, num=%4, stock=%5, publisher='%6', publish_year='%7', type='%8' where book_id='%9'").arg(addbooks[i].name, addbooks[i].author_name, QString::number(addbooks[i].price,'f',2), QString::number(addbooks[i].num,10), QString::number(addbooks[i].stock,10), addbooks[i].publisher, addbooks[i].publish_year, addbooks[i].type, addbooks[i].book_id);
                query.exec(queryCommand);
                updateSucess++;
            }
            else
            {
                //新书,添加
                queryCommand=QString("insert into book (book_id, name, author_name, price, num, stock, publisher, publish_year, type) values ('%1', '%2', '%3', %4, %5, %6, '%7', '%8', '%9');").arg(addbooks[i].book_id, addbooks[i].name, addbooks[i].author_name, QString::number(addbooks[i].price,'f',2), QString::number(addbooks[i].num,10), QString::number(addbooks[i].stock,10), addbooks[i].publisher, addbooks[i].publish_year, addbooks[i].type);
                query.exec(queryCommand);
                addSucess++;
            }
        }

        bookmanagementUpdate();
        if(userdetailwindow!=NULL)
        {
            userdetailwindow->close();
        }

        QMessageBox::information(NULL, "Info", "成功添加书籍"+QString::number(addSucess,10)+"本、更新"+QString::number(updateSucess,10)+"本", QMessageBox::Yes);
    }
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237
  • 238
  • 239
  • 240
  • 241
  • 242
  • 243
  • 244
  • 245
  • 246
  • 247
  • 248
  • 249
  • 250
  • 251
  • 252
  • 253
  • 254
  • 255
  • 256
  • 257
  • 258
  • 259
  • 260
  • 261
  • 262
  • 263
  • 264
  • 265
  • 266
  • 267
  • 268
  • 269
  • 270
  • 271
  • 272
  • 273
  • 274
  • 275
  • 276
  • 277
  • 278
  • 279
  • 280
  • 281
  • 282
  • 283
  • 284
  • 285
  • 286
  • 287
  • 288
  • 289
  • 290
  • 291
  • 292
  • 293
  • 294
  • 295
  • 296
  • 297
  • 298
  • 299
  • 300
  • 301
  • 302
  • 303
  • 304
  • 305
  • 306
  • 307
  • 308
  • 309
  • 310
  • 311
  • 312
  • 313
  • 314
  • 315
  • 316
  • 317
  • 318
  • 319
  • 320
  • 321
  • 322
  • 323
  • 324
  • 325
  • 326
  • 327
  • 328
  • 329
  • 330
  • 331
  • 332
  • 333
  • 334
  • 335
  • 336
  • 337
  • 338
  • 339
  • 340
  • 341
  • 342
  • 343
  • 344
  • 345
  • 346
  • 347
  • 348
  • 349
  • 350
  • 351
  • 352
  • 353
  • 354
  • 355
  • 356
  • 357
  • 358
  • 359
  • 360
  • 361
  • 362
  • 363
  • 364
  • 365
  • 366
  • 367
  • 368
  • 369
  • 370
  • 371
  • 372
  • 373
  • 374
  • 375
  • 376
  • 377
  • 378
  • 379
  • 380
  • 381
  • 382
  • 383
  • 384
  • 385
  • 386
  • 387
  • 388
  • 389
  • 390
  • 391
  • 392
  • 393
  • 394
  • 395
  • 396
  • 397
  • 398
  • 399
  • 400
  • 401
  • 402
  • 403
  • 404
  • 405
  • 406
  • 407
  • 408
  • 409
  • 410
  • 411
  • 412
  • 413
  • 414
  • 415
  • 416
  • 417
  • 418
  • 419
  • 420
  • 421
  • 422
  • 423
  • 424
  • 425
  • 426
  • 427
  • 428
  • 429
  • 430
  • 431
  • 432
  • 433
  • 434
  • 435
  • 436
  • 437
  • 438
  • 439
  • 440
  • 441
  • 442
  • 443
  • 444
  • 445
  • 446
  • 447
  • 448
  • 449
  • 450
  • 451
  • 452
  • 453
  • 454
  • 455
  • 456
  • 457
  • 458
  • 459
  • 460
  • 461
  • 462
  • 463
  • 464
  • 465
  • 466
  • 467
  • 468
  • 469
  • 470
  • 471
  • 472
  • 473
  • 474
  • 475
  • 476
  • 477
  • 478
  • 479
  • 480
  • 481
  • 482
  • 483
  • 484
  • 485
  • 486
  • 487
  • 488
  • 489
  • 490
  • 491
  • 492
  • 493
  • 494
  • 495
  • 496
  • 497
  • 498
  • 499
  • 500
  • 501
  • 502
  • 503
  • 504
  • 505
  • 506
  • 507
  • 508
  • 509
  • 510
  • 511
  • 512
  • 513
  • 514
  • 515
  • 516
  • 517
  • 518
  • 519
  • 520
  • 521
  • 522
  • 523
  • 524
  • 525
  • 526
  • 527
  • 528
  • 529
  • 530
  • 531
  • 532
  • 533
  • 534
  • 535
  • 536
  • 537
  • 538
  • 539
  • 540
  • 541
  • 542
  • 543
  • 544
  • 545
  • 546
  • 547
  • 548
  • 549
  • 550
  • 551
  • 552
  • 553
  • 554
  • 555
  • 556
  • 557
  • 558
  • 559
  • 560
  • 561
  • 562
  • 563
  • 564
  • 565
  • 566
  • 567
  • 568
  • 569
  • 570
  • 571
  • 572
  • 573
  • 574
  • 575
  • 576
  • 577
  • 578
  • 579
  • 580
  • 581
  • 582
  • 583
  • 584
  • 585
  • 586
  • 587
  • 588
  • 589
  • 590
  • 591
  • 592
  • 593
  • 594
  • 595
  • 596
  • 597
  • 598
  • 599
  • 600
  • 601
  • 602
  • 603
  • 604
  • 605
  • 606
  • 607
  • 608
  • 609
  • 610
  • 611
  • 612
  • 613
  • 614
  • 615
  • 616
  • 617
  • 618
  • 619
  • 620
  • 621
  • 622
  • 623
  • 624
  • 625
  • 626
  • 627
  • 628
  • 629
  • 630
  • 631
  • 632
  • 633
  • 634
  • 635
  • 636
  • 637
  • 638
  • 639
  • 640
  • 641
  • 642
  • 643
  • 644
  • 645
  • 646
  • 647
  • 648
  • 649
  • 650
  • 651
  • 652
  • 653
  • 654
  • 655
  • 656
  • 657
  • 658
  • 659
  • 660
  • 661
  • 662
  • 663
  • 664
  • 665
  • 666
  • 667
  • 668
  • 669
  • 670
  • 671
  • 672
  • 673
  • 674
  • 675
  • 676
  • 677
  • 678
  • 679
  • 680
  • 681
  • 682
  • 683
  • 684
  • 685
  • 686
  • 687
  • 688
  • 689
  • 690
  • 691
  • 692
  • 693
  • 694
  • 695
  • 696
  • 697
  • 698
  • 699
  • 700
  • 701
  • 702
  • 703
  • 704
  • 705
  • 706
  • 707
  • 708
  • 709
  • 710
  • 711
  • 712
  • 713
  • 714
  • 715
  • 716
  • 717
  • 718
  • 719
  • 720
  • 721
  • 722
  • 723
  • 724
  • 725
  • 726
  • 727
  • 728
  • 729
  • 730
  • 731
  • 732
  • 733
  • 734
  • 735
  • 736
  • 737
  • 738
  • 739
  • 740
  • 741
  • 742
  • 743
  • 744
  • 745
  • 746
  • 747
  • 748
  • 749
  • 750
  • 751
  • 752
  • 753
  • 754
  • 755
  • 756
  • 757
  • 758
  • 759
  • 760
  • 761
  • 762
  • 763
  • 764
  • 765
  • 766
  • 767
  • 768
  • 769
  • 770
  • 771
  • 772
  • 773
  • 774
  • 775
  • 776
  • 777
  • 778
  • 779
  • 780
  • 781
  • 782
  • 783
  • 784
  • 785
  • 786
  • 787
  • 788
  • 789
  • 790
  • 791
  • 792
  • 793
  • 794
  • 795
  • 796
  • 797
  • 798
  • 799
  • 800
  • 801
  • 802
  • 803
  • 804
  • 805
  • 806
  • 807
  • 808
  • 809
  • 810
  • 811
  • 812
  • 813
  • 814
  • 815
  • 816
  • 817
  • 818
  • 819
  • 820
  • 821
  • 822
  • 823
  • 824
  • 825
  • 826
  • 827
  • 828
  • 829
  • 830
  • 831
  • 832
  • 833
  • 834
  • 835
  • 836
  • 837
  • 838
  • 839
  • 840
  • 841
  • 842
  • 843
  • 844
  • 845
  • 846
  • 847
  • 848
  • 849
  • 850
  • 851
  • 852
  • 853
  • 854
  • 855
  • 856
  • 857
  • 858
  • 859
  • 860
  • 861
  • 862
  • 863
  • 864
  • 865
  • 866
  • 867
  • 868
  • 869
  • 870
  • 871
  • 872
  • 873
  • 874
  • 875
  • 876
  • 877
  • 878
  • 879
  • 880
  • 881
  • 882
  • 883
  • 884
  • 885
  • 886
  • 887
  • 888
  • 889
  • 890
  • 891
  • 892
  • 893
  • 894
  • 895
  • 896
  • 897
  • 898
  • 899
  • 900
  • 901
  • 902
  • 903
  • 904
  • 905
  • 906
  • 907
  • 908
  • 909
  • 910
  • 911
  • 912
  • 913
  • 914
  • 915
  • 916
  • 917
  • 918
  • 919
  • 920
  • 921
  • 922
  • 923
  • 924
  • 925
  • 926
  • 927
  • 928
  • 929
  • 930
  • 931
  • 932
  • 933
  • 934
  • 935
  • 936
  • 937
  • 938
  • 939
  • 940
  • 941
  • 942
  • 943
  • 944
  • 945
  • 946
  • 947
  • 948
  • 949
  • 950
  • 951
  • 952
  • 953
  • 954
  • 955
  • 956
  • 957
  • 958
  • 959
  • 960
  • 961
  • 962
  • 963
  • 964
  • 965
  • 966
  • 967
  • 968
  • 969
  • 970
  • 971
  • 972
  • 973
  • 974
  • 975
  • 976
  • 977
  • 978
  • 979
  • 980
  • 981
  • 982
  • 983
  • 984
  • 985
  • 986
  • 987
  • 988
  • 989
  • 990
  • 991
  • 992
  • 993
  • 994
  • 995
  • 996
  • 997
  • 998
  • 999
  • 1000
  • 1001
  • 1002
  • 1003
  • 1004
  • 1005
  • 1006
  • 1007
  • 1008
  • 1009
  • 1010
  • 1011
  • 1012
  • 1013
  • 1014
  • 1015
  • 1016
  • 1017
  • 1018
  • 1019
  • 1020
  • 1021
  • 1022
  • 1023
  • 1024
  • 1025
  • 1026
  • 1027
  • 1028
  • 1029
  • 1030
  • 1031
  • 1032
  • 1033
  • 1034
  • 1035
  • 1036
  • 1037
  • 1038
  • 1039
  • 1040
  • 1041
  • 1042
  • 1043
  • 1044
  • 1045
  • 1046
  • 1047
  • 1048
  • 1049
  • 1050
  • 1051
  • 1052
  • 1053
  • 1054
  • 1055
  • 1056
  • 1057
  • 1058
  • 1059
  • 1060
  • 1061
  • 1062
  • 1063
  • 1064
  • 1065
  • 1066
  • 1067
  • 1068
  • 1069
  • 1070
  • 1071
  • 1072
  • 1073
  • 1074
  • 1075
  • 1076
  • 1077
  • 1078
  • 1079
  • 1080
  • 1081
  • 1082
  • 1083
  • 1084
  • 1085
  • 1086
  • 1087
  • 1088
  • 1089
  • 1090
  • 1091
  • 1092
  • 1093
  • 1094
  • 1095
  • 1096
  • 1097
  • 1098
  • 1099
  • 1100
  • 1101
  • 1102
  • 1103
  • 1104
  • 1105
  • 1106
  • 1107
  • 1108
  • 1109
  • 1110
  • 1111
  • 1112
  • 1113
  • 1114
  • 1115
  • 1116
  • 1117
  • 1118
  • 1119
  • 1120
  • 1121
  • 1122
  • 1123
  • 1124
  • 1125
  • 1126
  • 1127
  • 1128
  • 1129
  • 1130
  • 1131
  • 1132
  • 1133
  • 1134
  • 1135
  • 1136
  • 1137
  • 1138
  • 1139
  • 1140
  • 1141
  • 1142
  • 1143
  • 1144
  • 1145
  • 1146
  • 1147
  • 1148
  • 1149
  • 1150
  • 1151
  • 1152
  • 1153
  • 1154
  • 1155
  • 1156
  • 1157
  • 1158
  • 1159
  • 1160
  • 1161
  • 1162
  • 1163
  • 1164
  • 1165
  • 1166
  • 1167
  • 1168
  • 1169
  • 1170
  • 1171
  • 1172
  • 1173
  • 1174
  • 1175
  • 1176
  • 1177
  • 1178
  • 1179
  • 1180
  • 1181
  • 1182
  • 1183
  • 1184
  • 1185
  • 1186
  • 1187
  • 1188
  • 1189
  • 1190
  • 1191
  • 1192
  • 1193
  • 1194
  • 1195
  • 1196
  • 1197
  • 1198
  • 1199
  • 1200
  • 1201
  • 1202
  • 1203
  • 1204
  • 1205
  • 1206
  • 1207
  • 1208
  • 1209
  • 1210
  • 1211
  • 1212
  • 1213
  • 1214
  • 1215
  • 1216
  • 1217
  • 1218
  • 1219
  • 1220
  • 1221
  • 1222
  • 1223
  • 1224
  • 1225
  • 1226
  • 1227
  • 1228
  • 1229
  • 1230
  • 1231
  • 1232
  • 1233
  • 1234
  • 1235
  • 1236
  • 1237
  • 1238
  • 1239
  • 1240
  • 1241
  • 1242
  • 1243
  • 1244
  • 1245
  • 1246
  • 1247
  • 1248
  • 1249
  • 1250
  • 1251
  • 1252
  • 1253
  • 1254
  • 1255
  • 1256
  • 1257
  • 1258
  • 1259
  • 1260
  • 1261
  • 1262
  • 1263
  • 1264
  • 1265
  • 1266
  • 1267
  • 1268
  • 1269
  • 1270
  • 1271
  • 1272
  • 1273
  • 1274
  • 1275
  • 1276
  • 1277
  • 1278
  • 1279
  • 1280
  • 1281
  • 1282
  • 1283
  • 1284
  • 1285
  • 1286
  • 1287
  • 1288
  • 1289
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/一键难忘520/article/detail/808243
推荐阅读
相关标签
  

闽ICP备14008679号