From 83b9c871148f01ee15671b08dc807bd8901c8b22 Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Thu, 13 Dec 2012 15:41:48 -0600 Subject: [PATCH] Move DB access to NoteDialog class, new AlertDialog class. --- docs/README | 4 +-- schematic.pro | 2 ++ src/alertdialog.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++++ src/alertdialog.h | 34 +++++++++++++++++++++++++ src/notedialog.cpp | 30 +++++++++++++++++------ src/notedialog.h | 9 ++++--- src/scmwidget.cpp | 35 +++++++++++++------------- src/scmwidget.h | 1 + 8 files changed, 144 insertions(+), 31 deletions(-) create mode 100644 src/alertdialog.cpp create mode 100644 src/alertdialog.h diff --git a/docs/README b/docs/README index 1ea1a15..63b33ad 100644 --- a/docs/README +++ b/docs/README @@ -1,3 +1,3 @@ -When installing on Windows client machines, be sure to install the *32-bit* version of the -MyODBC connector, otherwise it won't work! +When installing on Windows client machines, be sure to install the *32-bit* +version of the MyODBC connector, otherwise it won't work! diff --git a/schematic.pro b/schematic.pro index 1344544..2ff5a0d 100644 --- a/schematic.pro +++ b/schematic.pro @@ -25,6 +25,7 @@ RESOURCES += schematic.qrc HEADERS += src/about.h \ src/addresseditwidget.h \ src/addresswidget.h \ + src/alertdialog.h \ src/configdialog.h \ src/contacteditwidget.h \ src/contactwidget.h \ @@ -42,6 +43,7 @@ HEADERS += src/about.h \ SOURCES += src/about.cpp \ src/addresseditwidget.cpp \ src/addresswidget.cpp \ + src/alertdialog.cpp \ src/configdialog.cpp \ src/contacteditwidget.cpp \ src/contactwidget.cpp \ diff --git a/src/alertdialog.cpp b/src/alertdialog.cpp new file mode 100644 index 0000000..d748c1f --- /dev/null +++ b/src/alertdialog.cpp @@ -0,0 +1,60 @@ +// +// alertdialog.cpp: Dialog for creating & editing alerts +// +// Part of the SCheMatic Project +// (C) 2012 Underground Software +// +// JLH = James Hammons +// +// WHO WHEN WHAT +// --- ---------- ------------------------------------------------------------ +// JLH 12/13/2012 Created this file +// + +#include "alertdialog.h" +#include + + +AlertDialog::AlertDialog(int uidToUse, QWidget * parent/*= 0*/): QDialog(parent), uid(uidToUse) +{ + note = new QTextEdit; + buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + + connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); + connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); + + QVBoxLayout * mainLayout = new QVBoxLayout; + mainLayout->addWidget(note); + mainLayout->addWidget(buttonBox); + setLayout(mainLayout); + + setWindowTitle(tr("Alert")); +} + + +AlertDialog::~AlertDialog() +{ +} + + +void AlertDialog::accept(void) +{ + // Call base class version, so things work right + QDialog::accept(); + +#if 0 + // Add note to DB for this user + QString noteText = note->document()->toPlainText(); + + if (noteText.isEmpty()) + return; + + QSqlQuery query; + query.prepare("INSERT INTO Notes VALUES ('', ?, NULL, ?)"); + query.addBindValue(uid); +// query.addBindValue(NULL); + query.addBindValue(noteText.toAscii()); + query.exec(); +#endif +} + diff --git a/src/alertdialog.h b/src/alertdialog.h new file mode 100644 index 0000000..560318e --- /dev/null +++ b/src/alertdialog.h @@ -0,0 +1,34 @@ +// +// alertdialog.h: Alert entry/editing +// +// by James Hammons +// (C) 2012 Underground Software +// + +#ifndef __ALERTDIALOG_H__ +#define __ALERTDIALOG_H__ + +#include + + +class AlertDialog: public QDialog +{ + Q_OBJECT + + public: + AlertDialog(int uidToUse, QWidget * parent = 0); + ~AlertDialog(); + + public slots: + virtual void accept(void); + + private: + QDialogButtonBox * buttonBox; + + public: + QTextEdit * note; + int uid; +}; + +#endif // __ALERTDIALOG_H__ + diff --git a/src/notedialog.cpp b/src/notedialog.cpp index c91b5bf..0b2fbf9 100644 --- a/src/notedialog.cpp +++ b/src/notedialog.cpp @@ -12,17 +12,12 @@ // #include "notedialog.h" +#include -NoteDialog::NoteDialog(QWidget * parent/*= 0*/): QDialog(parent) +NoteDialog::NoteDialog(int uidToUse, QWidget * parent/*= 0*/): QDialog(parent), uid(uidToUse) { -// tabWidget = new QTabWidget; -// generalTab = new GeneralTab(this); -// tabWidget->addTab(generalTab, tr("General")); -// tabWidget->addTab(new PermissionsTab(fileInfo), tr("Permissions")); -// tabWidget->addTab(new ApplicationsTab(fileInfo), tr("Applications")); note = new QTextEdit; - buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); @@ -36,7 +31,28 @@ NoteDialog::NoteDialog(QWidget * parent/*= 0*/): QDialog(parent) setWindowTitle(tr("Note")); } + NoteDialog::~NoteDialog() { } + +void NoteDialog::accept(void) +{ + // Call base class version, so things work right + QDialog::accept(); + + // Add note to DB for this user + QString noteText = note->document()->toPlainText(); + + if (noteText.isEmpty()) + return; + + QSqlQuery query; + query.prepare("INSERT INTO Notes VALUES ('', ?, NULL, ?)"); + query.addBindValue(uid); +// query.addBindValue(NULL); + query.addBindValue(noteText.toAscii()); + query.exec(); +} + diff --git a/src/notedialog.h b/src/notedialog.h index ada9970..533f841 100644 --- a/src/notedialog.h +++ b/src/notedialog.h @@ -10,23 +10,24 @@ #include -//class GeneralTab; class NoteDialog: public QDialog { Q_OBJECT public: - NoteDialog(QWidget * parent = 0); + NoteDialog(int uidToUse, QWidget * parent = 0); ~NoteDialog(); + public slots: + virtual void accept(void); + private: -// QTabWidget * tabWidget; QDialogButtonBox * buttonBox; public: QTextEdit * note; -// GeneralTab * generalTab; + int uid; }; #endif // __NOTEDIALOG_H__ diff --git a/src/scmwidget.cpp b/src/scmwidget.cpp index a04e894..4c531ad 100644 --- a/src/scmwidget.cpp +++ b/src/scmwidget.cpp @@ -14,6 +14,7 @@ #include "scmwidget.h" #include #include "addresswidget.h" +#include "alertdialog.h" #include "contactwidget.h" #include "notedialog.h" @@ -250,28 +251,24 @@ void SCMWidget::GetPreviousVendor(void) void SCMWidget::CreateNote(void) { - NoteDialog dlg; - - if (dlg.exec() == true) - { - // Add note to DB for this user - QString note = dlg.note->document()->toPlainText(); + NoteDialog dlg(currentUID); - QSqlQuery query; - query.prepare("INSERT INTO Notes VALUES ('', ?, NULL, ?)"); - query.addBindValue(currentUID); -// query.addBindValue(NULL); - query.addBindValue(note.toAscii()); - query.exec(); + if (dlg.exec() == false) + return; - UpdateNotes(); - } + UpdateNotes(); } void SCMWidget::CreateAlert(void) { + AlertDialog dlg(currentUID); + + if (dlg.exec() == false) + return; + QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation"); +// UpdateAlerts(); } @@ -392,10 +389,6 @@ void SCMWidget::UpdateNotes(void) QSqlQuery query; query.prepare("SELECT note FROM Notes WHERE uid = ?"); -// "c.name, email, c.address, phone1, phone2, fax, description, v.vlid FROM " -// "Vendor AS v LEFT OUTER JOIN Location AS l ON v.vid = l.vid " -// "LEFT OUTER JOIN (Contact AS c JOIN ContactType AS ct ON c.ctid = ct.ctid) " -// "ON v.vid = c.vid WHERE v.vid = ?"); query.addBindValue(currentUID); query.exec(); @@ -408,3 +401,9 @@ void SCMWidget::UpdateNotes(void) } } + +void SCMWidget::UpdateAlerts(void) +{ + // TODO: Implementation +} + diff --git a/src/scmwidget.h b/src/scmwidget.h index e9edd01..9dddfcf 100644 --- a/src/scmwidget.h +++ b/src/scmwidget.h @@ -42,6 +42,7 @@ class SCMWidget: public QWidget void GetVendorIDs(void); void GetVendor(int); void UpdateNotes(void); + void UpdateAlerts(void); public: QTreeView * purchaseOrders; -- 2.37.2