-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauthpatientdialog.cpp
47 lines (39 loc) · 1.42 KB
/
authpatientdialog.cpp
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
#include "authpatientdialog.h"
AuthPatientDialog::AuthPatientDialog(QWidget *parent)
: QDialog{parent}
{
setWindowTitle("Авторизация");
nameLabel = new QLabel(this);
nameField = new QLineEdit(this);
dialogLayout = new QVBoxLayout(this);
dialogLayout->addWidget(nameLabel);
nameLabel->setText("Фамилия и имя:");
dialogLayout->addWidget(nameField);
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
| QDialogButtonBox::Cancel);
connect(buttonBox, &QDialogButtonBox::accepted, this, &AuthPatientDialog::authorize);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
dialogLayout->addStretch(10);
dialogLayout->addWidget(buttonBox);
connect(nameField, &QLineEdit::textChanged, this, [=](QString value) {
name = value;
});
}
int AuthPatientDialog::getId()
{
return id;
}
void AuthPatientDialog::authorize()
{
QSqlQuery query;
query.prepare("SELECT id, (first_name || ' ' || last_name) AS name FROM patients WHERE name = :name");
query.bindValue(":name", name);
query.exec();
query.next();
id = query.value("id").toInt();
if (query.value("name") == name) {
accept();
} else {
QMessageBox::critical(this,"Ошибка", "ФИО не зарегистрировано в системе.");
}
}