图书管理系统图书信息界面

头文件

#ifndef TUSHUKU_H
#define TUSHUKU_H
#include<QtGui>
class tushuku:public QWidget
{
    Q_OBJECT
public slots:
    void input1(void);
    void change1(void);
    void dele1(void);
public:
    tushuku(QWidget *parent=0);
public:
    QLabel name,no,author,publ,year,status;
    QPushButton input,change,dele;
    QLineEdit nameline,noline,authorline,publine,yearline,statusline;
};
#endif

实现

#include "myWeiget.h"
#include "studentinfo.h"
#include "studentwin.h"
#include "dbawin.h"
#include "tushuku.h"
#include <QSqlDriver>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QtSql>

tushuku::tushuku(QWidget *parent)
    :QWidget(parent),name(QObject::tr("书名"),this),no(QObject::tr("书号"),this),
      author(QObject::tr("作者"),this),publ(QObject::tr("出版社"),this),
      year(QObject::tr("出版年份"),this),status(QObject::tr("借阅状态"),this),
      input(QObject::tr("入库"),this),change(QObject::tr("修改"),this),
      dele(QObject::tr("删除"),this),nameline(this),noline(this),authorline(this),publine(this),yearline(this),
      statusline(this)
{
    name.setGeometry(20,20,60,30);
    no.setGeometry(100,20,60,30);
    author.setGeometry(180,20,60,30);
    publ.setGeometry(260,20,60,30);
    year.setGeometry(340,20,60,30);
    status.setGeometry(410,20,60,30);

    nameline.setGeometry(20,70,60,30);
    noline.setGeometry(100,70,60,30);
    authorline.setGeometry(180,70,60,30);
    publine.setGeometry(260,70,60,30);
    yearline.setGeometry(340,70,60,30);
    statusline.setGeometry(410,70,60,30);

    input.setGeometry(QRect(30,200,100,40));
    change.setGeometry(QRect(370,200,100,40));
    dele.setGeometry(QRect(200,200,100,40));


    connect(&input,SIGNAL(clicked(void)),this,SLOT(input1(void)));
    connect(&change,SIGNAL(clicked(void)),this,SLOT(change1(void)));
    connect(&dele,SIGNAL(clicked(void)),this,SLOT(dele1(void)));
}

void tushuku::input1()
{
    QString bname=nameline.text().trimmed();
    QString bno=noline.text().trimmed();
    QString bauthor=authorline.text().trimmed();
    QString bpubl=publine.text().trimmed();
    QString byear=yearline.text().trimmed();
    QString bstatus=statusline.text().trimmed();
    if(bstatus=="in"||bstatus=="out")
    {QSqlQuery query;
    query.prepare("INSERT INTO book values(:bname,:bno,:bauthor,:bpubl,:byear,:bstatus)");
    query.bindValue(":bnname",bname);
    query.bindValue(":bno",bno);
    query.bindValue(":bauthor",bauthor);
    query.bindValue(":bpubl",bpubl);
    query.bindValue(":byear",byear);
    query.bindValue(":bstatus",bstatus);
    query.exec();

    QSqlQuery query2;
    query2.exec("select * from book");
    QSqlQueryModel *model = new QSqlQueryModel;
    model->setQuery(query2);
    QTableView *view = new QTableView;
    view->setModel(model);
    view->show();}
}
void tushuku::change1()
{
    QString bname=nameline.text().trimmed();
    QString bno=noline.text().trimmed();
    QString bauthor=authorline.text().trimmed();
    QString bpubl=publine.text().trimmed();
    QString byear=yearline.text().trimmed();
    QString bstatus=statusline.text().trimmed();
    if(bstatus=="in"||bstatus=="out")
    {
    QSqlQuery query;
    query.prepare("DELETE from book where 书号=:bno");
    query.bindValue(":bnname",bname);
    query.bindValue(":bno",bno);
    query.bindValue(":bauthor",bauthor);
    query.bindValue(":bpubl",bpubl);
    query.bindValue(":byear",byear);
    query.bindValue(":bstatus",bstatus);
    query.exec();

    query.prepare("INSERT INTO book values(:bname,:bno,:bauthor,:bpubl,:byear,:bstatus)");
    query.bindValue(":bnname",bname);
    query.bindValue(":bno",bno);
    query.bindValue(":bauthor",bauthor);
    query.bindValue(":bpubl",bpubl);
    query.bindValue(":byear",byear);
    query.bindValue(":bstatus",bstatus);
    query.exec();
    query.exec();

    QSqlQuery query2;
    query2.exec("select * from book");
    QSqlQueryModel *model = new QSqlQueryModel;
    model->setQuery(query2);
    QTableView *view = new QTableView;
    view->setModel(model);
    view->show();
    }
}

void tushuku::dele1()
{
    QString bname=nameline.text().trimmed();
    QString bno=noline.text().trimmed();
    QString bauthor=authorline.text().trimmed();
    QString bpubl=publine.text().trimmed();
    QString byear=yearline.text().trimmed();
    QString bstatus=statusline.text().trimmed();

    QSqlQuery query;
    query.prepare("DELETE from book where 书号=:bno");
    query.bindValue(":bnname",bname);
    query.bindValue(":bno",bno);
    query.bindValue(":bauthor",bauthor);
    query.bindValue(":bpubl",bpubl);
    query.bindValue(":byear",byear);
    query.bindValue(":bstatus",bstatus);
    query.exec();

    QSqlQuery query2;
    query2.exec("select * from book");
    QSqlQueryModel *model = new QSqlQueryModel;
    model->setQuery(query2);
    QTableView *view = new QTableView;
    view->setModel(model);
    view->show();
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值