X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fmainwin.cpp;fp=src%2Fmainwin.cpp;h=fe7931f6e6b7964cda186a3e8d17a187fa23c243;hb=6df1a447a1fa1b9e51fd177a806f910813657b09;hp=44161ba81c6f6deec3bfffd6e7a82c9c21f2f870;hpb=f3116511d09acfd5b32d3412c82c4337d89f2ad9;p=schematic diff --git a/src/mainwin.cpp b/src/mainwin.cpp index 44161ba..fe7931f 100644 --- a/src/mainwin.cpp +++ b/src/mainwin.cpp @@ -20,11 +20,14 @@ #include "configdialog.h" #include "logindialog.h" #include "newvendordialog.h" +#include "scmwidget.h" #include "sqlsettingsdialog.h" #include "vendorclassdialog.h" MainWindow::MainWindow(): aboutWin(new AboutWindow(this)), + scmWidget(new SCMWidget(this)), + boldFont(new QFont), loggedInUID(0) { setWindowIcon(QIcon(":/res/schematic.png")); @@ -99,6 +102,7 @@ MainWindow::MainWindow(): aboutWin(new AboutWindow(this)), statusBar()->showMessage(tr("Ready")); ReadSettings(); + boldFont->setBold(true); // Finally, set up database connection @@ -122,6 +126,9 @@ MainWindow::MainWindow(): aboutWin(new AboutWindow(this)), db.setPassword(dbPassword); ok = db.open(); +//printf("Error: %s\n", db.lastError().databaseText().toAscii().data()); +//printf("Error: %s\n", db.lastError().driverText().toAscii().data()); + // If unsuccessful, run the SQL settings/test dialog if (!ok) { @@ -141,12 +148,12 @@ MainWindow::MainWindow(): aboutWin(new AboutWindow(this)), while (!ok); // Do Login dialog - LoginDialog login; + LoginDialog loginDlg; bool done = false; do { - bool accept = login.exec(); + bool accept = loginDlg.exec(); // Check to see if user cancelled out if (!accept) @@ -154,20 +161,26 @@ MainWindow::MainWindow(): aboutWin(new AboutWindow(this)), else { // Search DB for this username/login pair - QSqlQuery query("SELECT UID FROM User WHERE Login=? AND Password=?"); - query.addBindValue(login.edit1->text()); - query.addBindValue(login.edit2->text()); + QSqlQuery query("SELECT UID, name, login FROM User WHERE Login=? AND Password=?"); + query.addBindValue(loginDlg.edit1->text()); + query.addBindValue(loginDlg.edit2->text()); query.exec(); while (query.next()) { // We have a winner! loggedInUID = query.value(0).toInt(); + fullName = query.value(1).toString(); + login = query.value(2).toString(); done = true; } } } while (!done); + + QString s = QString("User: %1 (%2)").arg(fullName).arg(login); + scmWidget->username->setText(s); + setCentralWidget(scmWidget); } @@ -208,9 +221,97 @@ void MainWindow::HandleVendorClassDialog(void) void MainWindow::HandleNewVendorDialog(void) { NewVendorDialog dialog(this); + FillVendorLevelCombo(dialog.combo1); + FillContactTypeCombo(dialog.contact->field1); + FillVendorClassList(dialog.list); if (!dialog.exec()) return; + + // Presumably, the user has given us good data, so we try to populate the + // database with this new vendor data. + QSqlQuery query1("INSERT INTO VALUES (?, ?, ?)"); + + +} + + +void MainWindow::FillVendorLevelCombo(QComboBox * combo) +{ + QSqlQuery query("SELECT VLID, Description FROM VendorLevel"); + query.exec(); + + while (query.next()) + { + int vlid = query.value(0).toInt(); + QString description = query.value(1).toString(); + + combo->addItem(description, vlid); + } +} + + +void MainWindow::FillContactTypeCombo(QComboBox * combo) +{ + QSqlQuery query("SELECT CTID, Description FROM ContactType"); + query.exec(); + + while (query.next()) + { + int ctid = query.value(0).toInt(); + QString description = query.value(1).toString(); + + combo->addItem(description, ctid); + } +} + + +void MainWindow::FillVendorClassList(QListWidget * list) +{ + std::vector groupList; + + // Pull in definitions from DB for Vendor Classes/Groups + QSqlQuery query1("SELECT vgid, description FROM VendorGroup ORDER BY seqNo"); + query1.exec(); + + while (query1.next()) + { + VendorType v; + v.key = query1.value(0).toInt(); + v.description = query1.value(1).toString(); + groupList.push_back(v); + } + + QSqlQuery query2("SELECT vtid, vgid, description FROM VendorType ORDER BY seqNo"); + query2.exec(); + + int previousID = -1, groupListIndex = 0; + QListWidgetItem * item; + + while (query2.next()) + { +// VendorType v; + int vtid = query2.value(0).toInt(); + int vgid = query2.value(1).toInt(); + QString description = query2.value(2).toString(); + + // Check to see if we need to insert new header yet. + // If we're not still in same group, push the next group header into the list + // and continue + if (previousID != vgid) + { + item = new QListWidgetItem(groupList[groupListIndex].description); + item->setData(Qt::UserRole, groupList[groupListIndex++].key); + item->setFont(*boldFont); + list->addItem(item); + previousID = vgid; + } + + item = new QListWidgetItem(description); + item->setData(Qt::UserRole, vtid); + item->setCheckState(Qt::Unchecked); + list->addItem(item); + } }