Repository navigation
Expand file tree
/
Copy pathnewbookpage.cpp
More file actions
92 lines (83 loc) · 2.34 KB
/
Copy pathnewbookpage.cpp
File metadata and controls
92 lines (83 loc) · 2.34 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
#include "newbookpage.h"
#include "ui_newbookpage.h"
#include "book.h"
#include "dialog.h"
#include "bookeditpage.h"
extern vector<book> vecbook;
extern book bookCEO;
extern QString DIALOGMSG;
newBookPage::newBookPage(QWidget *parent) :
QWidget(parent),
ui(new Ui::newBookPage)
{
ui->setupUi(this);
}
newBookPage::~newBookPage()
{
delete ui;
}
void newBookPage::on_pushButton_clicked()
{
std::string bookName = ui->lineEditName->text().toStdString();
std::string ISBN = ui->lineEditISBN->text().toStdString();
std::string author = ui->lineEditAuthor->text().toStdString();
std::string type = ui->comboBoxType->currentText().toStdString();
std::string publisher = ui->lineEditPublisher->text().toStdString();
//检查有无空白输入
if(bookName.empty() || ISBN.empty() || author.empty() || type.empty() || publisher.empty()){
DIALOGMSG = "请输入完整的信息";
auto d = new Dialog;
d->show();
}else{
//检查ISBN号格式
int flag = 0;
char temp = ISBN[1];
if(temp != '-')
flag = 1;
temp = ISBN[6];
if(temp != '-')
flag = 1;
temp = ISBN[11];
if(temp != '-')
flag = 1;
if(flag == 1){
DIALOGMSG = "ISBN号格式不正确";
auto d = new Dialog;
d->show();
}else{
flag = bookCEO.add(bookName,author,publisher,ISBN,type,-1);
if(flag == 0){
DIALOGMSG = "该书籍已存在";
auto d = new Dialog;
d->show();
}
else if(flag == 1){
DIALOGMSG = "书籍添加成功";
auto d = new Dialog;
d->show();
}
}
}
}
void newBookPage::on_lineEditISBN_returnPressed()
{
string ISBN = ui->lineEditISBN->text().toStdString();
if(ISBN.empty() || ISBN.size() != 10){
DIALOGMSG = "请输入正确的ISBN号";
auto d = new Dialog;
d->show();
}
else if(ISBN.size() != 13){
ISBN.insert(1,"-");
ISBN.insert(6,"-");
ISBN.insert(11,"-");
QString temp = QString::fromStdString(ISBN);
ui->lineEditISBN->setText(temp);
}
}
void newBookPage::on_pushButton_2_clicked()
{
auto b = new bookEditPage;
b->show();
this->close();
}