Skip to content

Instantly share code, notes, and snippets.

@scope2229
Created April 18, 2018 17:08
Show Gist options
  • Save scope2229/814db09d06e0e8b55a3b0e2254b44d37 to your computer and use it in GitHub Desktop.
Save scope2229/814db09d06e0e8b55a3b0e2254b44d37 to your computer and use it in GitHub Desktop.
#include "roommanagementdialog.h"
#include "ui_roommanagementdialog.h"
roomManagementDialog::roomManagementDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::roomManagementDialog)
{
ui->setupUi(this);
//For using public slots from mainwindow.h
MainWindow conn;
//set up the top bar clock
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(showTime()));
timer->start(1000);
showTime();
QDateTime dateTime = dateTime.currentDateTime();
QString dateTimeString = dateTime.toString("dddd dd/MM/yyyy");
ui->showDateLabel->setText(dateTimeString);
//set up database connection for room management tableview
if(conn.openDB())
{
qDebug() << "DB Open";
ui->createRoomStatusBar->setText("[+] Room database opened and displaying in table view!");
QSqlQueryModel * model=new QSqlQueryModel();
QSqlQuery* qry=new QSqlQuery(conn.myDB);
qry->prepare("SELECT * from RoomManagement");
if(qry->exec()){
model->setQuery(*qry);
ui->tableView->setModel(model);
conn.closeDB();
qDebug() << "tableview set no errors";
qDebug() << (model->rowCount());
}else{
qDebug() << "ERROR:: You have a problem with the qry";
}
}else{
qDebug() << "ERROR:: Database not open check code";
}
}
roomManagementDialog::~roomManagementDialog()
{
delete ui;
}
void roomManagementDialog::showTime()
{
QTime time = QTime::currentTime();
QString text = time.toString("hh:mm");
if ((time.second() % 2) == 0)
text[2] = ' ';
ui->showTimeLabel->setText(text);
}
void roomManagementDialog::on_loadImageButton_clicked()
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
"/home",
tr("Images (*.png *.xpm *.jpg)"));
ui->viewImageLabel->setPixmap(QPixmap(fileName));
ui->viewImageLabel->setScaledContents( true );
QFileInfo fi(fileName);
ui->fileNameLabel->setText(fi.fileName());
QApplication::processEvents();
this->adjustSize();
}
void roomManagementDialog::on_InsertRecord_clicked()
{
MainWindow conn;
QString RID, RoomName, RoomDesc, RoomKey, Occupied, RoomNotes;
int RoomNum, HSPrice, LSPrice, SPrice, Discount, Pax;
//String
RID = ui->createRoomID->text();
RoomName = ui->createRoomName->text();
RoomDesc = ui->createRoomDes->toPlainText();
RoomKey = ui->createRoomKey->text();
Occupied = ui->createOccupied->text();
RoomNotes = ui->createRoomNotes->toPlainText();
//Int
RoomNum = ui->createRoomNumber->text().toInt();
HSPrice = ui->createHSPrice->text().toInt();
LSPrice = ui->createLSPrice->text().toInt();
SPrice = ui->createStPrice->text().toInt();
Discount = ui->createDiscount->text().toInt();
Pax = ui->createPax->text().toInt();
//Blob
//DB QRY
if(!conn.openDB())
{
qDebug() << "error connecting to DB";
ui->createRoomStatusBar->setText("[+] You must be connected to the database to create a Room!");
return;
}
qDebug() << "Ready to QRY";
QSqlQuery qry;
qry.prepare("insert into RoomManagement (RID, RoomNum) values ('"+RID+"', '"+RoomNum+"')");
if(qry.exec()){
qDebug() << "Created a new Room";
QMessageBox::critical(this, tr("Room creation"),tr("added to database."));
conn.closeDB();
}else{
qDebug() << "if it fails here its your sql query not the application connection to"
" db no need to check if the db is open it is 1122" << qry.lastError().text();
QMessageBox::warning(this, tr("ERROR"),qry.lastError().text(),tr("Please check logs and try again"));
conn.closeDB();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment