头文件
#ifndef TUSHUKU_H#define TUSHUKU_H#include<QtGui>class tushuku:public QWidget{ Q_OBJECTpublic 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();}新闻热点
疑难解答