X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fscmwidget.cpp;h=07b9cd18f2c41ce13b25b2d16644e2091e2bb115;hb=e2916da12c7309ded63c3d091271ebb2f9123305;hp=78f757fe016bc01965f259d7e086bc6e36b073ac;hpb=6faae8ae2d4575bb03459bd381a5cf8da8044b3c;p=schematic diff --git a/src/scmwidget.cpp b/src/scmwidget.cpp index 78f757f..07b9cd1 100644 --- a/src/scmwidget.cpp +++ b/src/scmwidget.cpp @@ -12,6 +12,7 @@ // #include "scmwidget.h" +#include #include "addresswidget.h" #include "contactwidget.h" @@ -27,6 +28,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 +42,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("Related to this Vendor")), + vidCursor(0) { // Create main page widgets & layout @@ -100,15 +106,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 +167,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 +206,95 @@ 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())); + + 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::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); + } }