-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudentlistdlg.cpp
More file actions
101 lines (97 loc) · 2.86 KB
/
studentlistdlg.cpp
File metadata and controls
101 lines (97 loc) · 2.86 KB
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
/*
* @Author: your name
* @Date: 2020-07-15 16:08:20
* @LastEditTime: 2020-07-16 18:23:38
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: \CodePracticeClassProject\studentlistdlg.cpp
*/
#include "studentlistdlg.h"
#include "ui_studentlistdlg.h"
#include <QApplication>
#include <QtGui>
#include <QMessageBox>
#include <QApplication>
#include <QtSql>
studentlistDlg::studentlistDlg(QWidget *parent) :
QDialog(parent),
ui(new Ui::studentlistDlg)
{
ui->setupUi(this);
ui->lineEdit->clear();
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("list.db");
if(!db.open())
{
close();
}
QSqlTableModel* model=new QSqlTableModel;
model->setTable("student");
model->setFilter(QObject::tr("bookid1 >= 0 and bookid2 >= 0 and bookid3 >= 0 "));
model->select();
model->removeColumn(2);
ui->tableView->setModel(model);
ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
}
studentlistDlg::~studentlistDlg()
{
delete ui;
}
void studentlistDlg::on_returnBtn_clicked()
{
this->hide();
emit returnsignal();
}
//刷新显示
void studentlistDlg::refresh()
{
ui->lineEdit->clear();
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("list.db");
if(!db.open())
{
close();
}
QSqlTableModel* model=new QSqlTableModel;
model->setTable("student");
model->setFilter(QObject::tr("bookid1 >= 0 and bookid2 >= 0 and bookid3 >= 0 "));
model->select();
model->removeColumn(2);
ui->tableView->setModel(model);
ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
}
void studentlistDlg::on_listBtn_clicked()
{
ui->lineEdit->clear();
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("list.db");
if(!db.open())
{
close();
}
QSqlTableModel* model=new QSqlTableModel;
model->setTable("student");
model->setFilter(QObject::tr("bookid1 >= 0 and bookid2 >= 0 and bookid3 >= 0 "));
model->select();
model->removeColumn(2);
ui->tableView->setModel(model);
ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
}
void studentlistDlg::on_searchBtn_clicked()
{
QString bookid;
bookid=ui->lineEdit->text();
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("list.db");
if(!db.open())
{
close();
}
QSqlTableModel* model=new QSqlTableModel;
model->setTable("student");
model->setFilter(QObject::tr("bookid1 = '%1' or bookid2 = '%2' or bookid3 = '%3'").arg(bookid).arg(bookid).arg(bookid));
model->select();
model->removeColumn(2);
ui->tableView->setModel(model);
ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
}