-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomplaintsform.cpp
More file actions
73 lines (61 loc) · 2.24 KB
/
Copy pathcomplaintsform.cpp
File metadata and controls
73 lines (61 loc) · 2.24 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
#include "complaintsform.h"
#include "ui_complaintsform.h"
ComplaintsForm::ComplaintsForm(Connector *conn, QWidget *parent) : QDialog(parent), ui(new Ui::ComplaintsForm) {
ui->setupUi(this);
ui->roll->setFocus();
this->conn = conn;
// initialize designation combobox
ui->category->addItem("select option");
for (uint i = 0; i < possible_values::no_of_complaint_categories; i++)
ui->category->addItem(possible_values::complaint_categories[i].c_str());
// grey out "select option"
ui->category->setItemData(0, false, Qt::UserRole - 1);
// make error labels red
ui->rollE->setStyleSheet("QLabel {color: red;}");
ui->categoryE->setStyleSheet("QLabel {color: red;}");
ui->complaintE->setStyleSheet("QLabel {color: red;}");
ui->remarkE->setStyleSheet("QLabel {color: red;}");
clearErrorLabels();
}
ComplaintsForm::~ComplaintsForm() {
delete ui;
}
void ComplaintsForm::clearErrorLabels() {
ui->rollE->setText("");
ui->categoryE->setText("");
ui->complaintE->setText("");
ui->remarkE->setText("");
}
void ComplaintsForm::on_ok_clicked() {
clearErrorLabels();
QString roll = ui->roll->text();
QString category = ui->category->currentText();
QString complaint = ui->complaint->text();
QString remark = ui->remark->text();
bool valid = true;
// validate inputs
if (invalid_roll(roll)) {
valid = false;
ui->rollE->setText("invalid roll number !");
} if (invalid_complaint_category(category)) {
valid = false;
ui->categoryE->setText("invalid complaint category !");
} if (invalid_complaint(complaint)) {
valid = false;
ui->complaintE->setText("character limit (50) exceeded !");
} if (invalid_remark(remark)) {
valid = false;
ui->remarkE->setText("character limit (50) exceeded !");
} if (valid) { // insert value
sqlerr::query_err resp = conn->addComplaint(Complaint(roll, category, complaint, remark));
if (resp == sqlerr::NOERR)
this->close();
else if (resp == sqlerr::DUP_PRI)
alert("duplicate Complaint ID !");
else
alert("unknown error occurred !");
}
}
void ComplaintsForm::on_cancel_clicked() {
this->close();
}