]> Shamusworld >> Repos - schematic/blobdiff - src/scmwidget.cpp
Move DB access to NoteDialog class, new AlertDialog class.
[schematic] / src / scmwidget.cpp
index 78f757fe016bc01965f259d7e086bc6e36b073ac..4c531ad756c58e80967cad14d155021d0fbae1c0 100644 (file)
 //
 
 #include "scmwidget.h"
+#include <QtSql>
 #include "addresswidget.h"
+#include "alertdialog.h"
 #include "contactwidget.h"
+#include "notedialog.h"
 
 
 SCMWidget::SCMWidget(QWidget * parent/*= 0*/): QWidget(parent),
@@ -27,6 +30,9 @@ SCMWidget::SCMWidget(QWidget * parent/*= 0*/): QWidget(parent),
        vendorLevel(new VendorLevelWidget),
        alerts(new QListWidget),
        notes(new QListWidget),
+       vaw1(new AddressWidget(this)),
+       vcw1(new ContactWidget(this)),
+
        nextVendorButton(new QToolButton),
        previousVendorButton(new QToolButton),
        editVendor(new QPushButton("Edit Vendor")),
@@ -38,7 +44,9 @@ SCMWidget::SCMWidget(QWidget * parent/*= 0*/): QWidget(parent),
        showOpen(new QPushButton("Open")),
        showClosed(new QPushButton("Closed")),
        showAll(new QPushButton("All")),
-       createPO(new QPushButton("Create"))
+       createPO(new QPushButton("Create")),
+       vendorRelated(new QCheckBox("Show POs for this Vendor only")),
+       vidCursor(0)
 {
        // Create main page widgets & layout
 
@@ -100,15 +108,13 @@ SCMWidget::SCMWidget(QWidget * parent/*= 0*/): QWidget(parent),
 
        // Vendor address widgets
 
-       AddressWidget * vaw1 = new AddressWidget(this);
-       vaw1->SetFields("123 Any Street", "Any City", "Anywhere", "USA", "01234");
+//     vaw1->SetFields("123 Any Street", "Any City", "Anywhere", "USA", "01234");
        vendorAddress->addTab(vaw1, tr("Primary"));
        vendorAddress->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
 
        // Vendor contact widgets
 
-       ContactWidget * vcw1 = new ContactWidget(this);
-       vcw1->SetFields("Sales", "Joe Blow", "joe.blow@widget.com", "Singapore", "512-222-2222", "", "512-122-2123");
+//     vcw1->SetFields("Sales", "Joe Blow", "joe.blow@widget.com", "Singapore", "512-222-2222", "", "512-122-2123");
        vendorContact->addTab(vcw1, tr("Contact #1"));
        vendorContact->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
 
@@ -163,6 +169,8 @@ SCMWidget::SCMWidget(QWidget * parent/*= 0*/): QWidget(parent),
        hbox6->addWidget(showOpen);
        hbox6->addWidget(showClosed);
        hbox6->addWidget(showAll);
+       hbox6->addSpacing(16);
+       hbox6->addWidget(vendorRelated);
        hbox6->addStretch();
        hbox6->addWidget(createPO);
 
@@ -200,5 +208,202 @@ SCMWidget::SCMWidget(QWidget * parent/*= 0*/): QWidget(parent),
        mainLayout->addLayout(hbox6);
        mainLayout->addWidget(purchaseOrders);
        setLayout(mainLayout);
+
+       // Set up actions
+
+       connect(nextVendorButton, SIGNAL(clicked()), this, SLOT(GetNextVendor()));
+       connect(previousVendorButton, SIGNAL(clicked()), this, SLOT(GetPreviousVendor()));
+       connect(createNote, SIGNAL(clicked()), this, SLOT(CreateNote()));
+       connect(createAlert, SIGNAL(clicked()), this, SLOT(CreateAlert()));
+       connect(createPO, SIGNAL(clicked()), this, SLOT(CreatePurchaseOrder()));
+       connect(showOpen, SIGNAL(clicked()), this, SLOT(ShowOpenPOs()));
+       connect(showClosed, SIGNAL(clicked()), this, SLOT(ShowClosedPOs()));
+       connect(showAll, SIGNAL(clicked()), this, SLOT(ShowAllPOs()));
+//     connect(addVendor, SIGNAL(clicked()), this, SLOT(AddVendor()));
+       connect(addLocation, SIGNAL(clicked()), this, SLOT(AddLocation()));
+       connect(addContact, SIGNAL(clicked()), this, SLOT(AddContact()));
+       connect(editVendor, SIGNAL(clicked()), this, SLOT(EditVendor()));
+
+       GetVendorIDs();
+       GetVendor(vendorID[vidCursor]);
+}
+
+
+void SCMWidget::GetNextVendor(void)
+{
+       if (vidCursor < (vendorID.size() - 1))
+       {
+               vidCursor++;
+               GetVendor(vendorID[vidCursor]);
+       }
+}
+
+
+void SCMWidget::GetPreviousVendor(void)
+{
+       if (vidCursor > 0)
+       {
+               vidCursor--;
+               GetVendor(vendorID[vidCursor]);
+       }
+}
+
+
+void SCMWidget::CreateNote(void)
+{
+       NoteDialog dlg(currentUID);
+
+       if (dlg.exec() == false)
+               return;
+
+       UpdateNotes();
+}
+
+
+void SCMWidget::CreateAlert(void)
+{
+       AlertDialog dlg(currentUID);
+
+       if (dlg.exec() == false)
+               return;
+
+       QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation");
+//     UpdateAlerts();
+}
+
+
+void SCMWidget::CreatePurchaseOrder(void)
+{
+       QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation");
+}
+
+
+void SCMWidget::ShowOpenPOs(void)
+{
+       QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation");
+}
+
+
+void SCMWidget::ShowClosedPOs(void)
+{
+       QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation");
+}
+
+
+void SCMWidget::ShowAllPOs(void)
+{
+       QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation");
+}
+
+
+void SCMWidget::AddVendor(void)
+{
+       QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation");
+}
+
+
+void SCMWidget::AddLocation(void)
+{
+       QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation");
+}
+
+
+void SCMWidget::AddContact(void)
+{
+       QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation");
+}
+
+
+void SCMWidget::EditVendor(void)
+{
+       QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation");
+}
+
+
+void SCMWidget::GetVendorIDs(void)
+{
+       vendorID.clear();
+
+       QSqlQuery query;
+       query.prepare("SELECT vid FROM Vendor ORDER BY name");
+       query.exec();
+
+       while (query.next())
+       {
+               int vid = query.value(0).toInt();
+               vendorID.push_back(vid);
+       }
+}
+
+
+void SCMWidget::GetVendor(int key)
+{
+       // Get main vendor data
+       QSqlQuery query;
+       query.prepare("SELECT v.name, signedNDA, l.address, city, state, country, code, "
+               "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(key);
+       query.exec();
+
+       // There's a possibility that the query will return multiple rows (which we need
+       // to handle, with multiple tabs), but for now, we ignore any and grab the first.
+       if (query.next())
+       {
+               vendorName->setText(query.value(0).toString());
+
+               vaw1->SetFields(query.value(2).toString(),
+                       query.value(3).toString(), query.value(4).toString(),
+                       query.value(5).toString(), query.value(6).toString());
+               vcw1->SetFields(query.value(13).toString(),
+                       query.value(7).toString(), query.value(8).toString(),
+                       query.value(9).toString(), query.value(10).toString(),
+                       query.value(11).toString(), query.value(12).toString());
+
+               int vlid = query.value(14).toInt();
+               vendorLevel->DoQuery(vlid);
+       }
+
+       // Get vendor classes
+       query.prepare("SELECT description FROM VendorSpecificTypes AS vst, VendorType AS vt "
+               "WHERE vst.vid = ? AND vst.vtid = vt.vtid ORDER BY seqNo");
+       query.addBindValue(key);
+       query.exec();
+
+       vendorClass->clear();
+
+       while (query.next())
+       {
+               QListWidgetItem * item = new QListWidgetItem(query.value(0).toString());
+               vendorClass->addItem(item);
+       }
+}
+
+
+void SCMWidget::UpdateNotes(void)
+{
+//             QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation");
+//NID (P-key) | UID | POID | Note
+
+       QSqlQuery query;
+       query.prepare("SELECT note FROM Notes WHERE uid = ?");
+       query.addBindValue(currentUID);
+       query.exec();
+
+       notes->clear();
+
+       while (query.next())
+       {
+               QListWidgetItem * item = new QListWidgetItem(query.value(0).toString());
+               notes->addItem(item);
+       }
+}
+
+
+void SCMWidget::UpdateAlerts(void)
+{
+       // TODO: Implementation
 }