-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsecondwindow.cpp
More file actions
73 lines (61 loc) · 2.08 KB
/
secondwindow.cpp
File metadata and controls
73 lines (61 loc) · 2.08 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
#include "secondwindow.h"
#include "ui_secondwindow.h"
#include "mainwindow.h"
#include <QMessageBox>
secondWindow::secondWindow(QWidget *parent) :
QDialog(parent),
ui(new Ui::secondWindow)
{
ui->setupUi(this);
QSqlDatabase mydb = QSqlDatabase::addDatabase("QSQLITE");
mydb.setDatabaseName("/Users/austinm/Desktop/CustomerInfo.db");
if(!mydb.open())
this->ui->StatusLable->setText("Database Status: Not Connected");
else {
this->ui->StatusLable->setText("Database Status: Connected");
mydb.close();
mydb.removeDatabase(QSqlDatabase::defaultConnection);
}
}
secondWindow::~secondWindow()
{
delete ui;
}
void secondWindow::on_saveInfoButton_clicked()
{
MainWindow conn;
QString customerId, customerName, address, interestLevel, KeyCustomer;
customerId = ui->txt_customerId->text();
customerName = ui->txt_customerName->text();
address = ui->txt_customerAddress->text();
if(ui->radioButton_Low->isCheckable()){
interestLevel = "Low";
}
if(ui->radioButton_Middle->isChecked()){
interestLevel = "Middle";
}
if(ui->radioButton_High->isCheckable()){
interestLevel = "High";
}
if(ui->radioButton_Yes->isCheckable()){
KeyCustomer = "Yes";
}
if(ui->radioButton_No->isChecked()){
KeyCustomer = "No";
}
conn.connOpen();
QSqlQuery qry;
qry.prepare("INSERT INTO CustomerInfo(CustomerID, Name, Address, InterestLevel, KeyCustomer) VALUES(:CustomerID, :Name, :Address, :InterestLevel, :KeyCustomer)");
qry.bindValue(":CustomerID", customerId);
qry.bindValue(":Name", customerName);
qry.bindValue(":Address", address);
qry.bindValue(":InterestLevel", interestLevel);
qry.bindValue(":KeyCustomer", KeyCustomer);
if(qry.exec()){
QMessageBox::critical(this,tr("Save"), tr("Information Saved."));
conn.connClose();
}
else{
QMessageBox::critical(this, tr("error::"), qry.lastError().text());
}
}