MainWindow::MainWindow(): aboutWin(new AboutWindow(this)),
- scmWidget(new SCMWidget(this)),
boldFont(new QFont),
loggedInUID(0)
{
// Finally, set up database connection
-// db = QSqlDatabase::addDatabase("QMYSQL");
db = QSqlDatabase::addDatabase("QODBC");
bool ok = false;
sqlSettings.edit4->setText(dbUserName);
sqlSettings.edit5->setText(dbPassword);
-#if 0
-db = QSqlDatabase::addDatabase("QODBC");
-db.setDatabaseName("Driver={MySQL ODBC 5.1 Driver};DATABASE=agp-dbserver01;");
-db.setUserName("xcdr");
-db.setPassword("xcdr");
-#endif
do
{
- // Set up the DB connection with saved settings
- QString odbc = QString("DRIVER={%1};DATABASE=%2;").arg(dbDriver).arg(dbName);
- db.setHostName(dbHostName);
+ // Set up the ODBC DB connection with saved settings
+ // NB: For this to work properly on 64-bit Windows, you need to use the 32-bit driver!
+ QString odbc = QString("DRIVER={%1};DATABASE=%2;SERVER=%3;UID=%4;PASSWORD=%5")
+ .arg(dbDriver).arg(dbName).arg(dbHostName).arg(dbUserName).arg(dbPassword);
db.setDatabaseName(odbc);
- db.setUserName(dbUserName);
- 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)
{
+ sqlSettings.error1->setText(db.lastError().databaseText());
+ sqlSettings.error2->setText(db.lastError().driverText());
+
if (sqlSettings.exec())
{
// User thinks this will work (hit OK button), so prime the variables
if (query.value(0).toInt() > 1)
{
- // Do Login dialog
- LoginDialog loginDlg;
- bool done = false;
-
- do
- {
- bool accept = loginDlg.exec();
+ // Do Login dialog
+ LoginDialog loginDlg;
+ bool done = false;
- // Check to see if user cancelled out
- if (!accept)
- done = true;
- else
+ do
{
-#if 0
- // Search DB for this username/login pair
- QSqlQuery query("SELECT UID, name, login FROM User WHERE Login=? AND Password=?");
- query.addBindValue(loginDlg.edit1->text());
- query.addBindValue(loginDlg.edit2->text());
- query.exec();
-#else
- // Search DB for this username/login pair
- QSqlQuery query;
- query.prepare("SELECT UID, name, login FROM User WHERE Login=? AND Password=?");
- query.addBindValue(loginDlg.edit1->text());
- query.addBindValue(loginDlg.edit2->text());
- query.exec();
-#endif
+ bool accept = loginDlg.exec();
- while (query.next())
- {
- // We have a winner!
- loggedInUID = query.value(0).toInt();
- fullName = query.value(1).toString();
- login = query.value(2).toString();
+ // Check to see if user cancelled out
+ if (!accept)
done = true;
+ else
+ {
+ // Search DB for this username/login pair
+ QSqlQuery query;
+ query.prepare("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);
+ while (!done);
}
else
{
loggedInUID = 1;
}
+ scmWidget = new SCMWidget(this);
QString s = QString("User: %1 (%2)").arg(fullName).arg(login);
scmWidget->username->setText(s);
+ scmWidget->currentUID = loggedInUID;
+ scmWidget->UpdateNotes();
setCentralWidget(scmWidget);
}
// Presumably, the user has given us good data, so we try to populate the
// database with this new vendor data.
- QSqlQuery query;
- query.prepare("INSERT INTO VALUES (?, ?, ?)");
+ // First, see if there is anything missing from the dialog...
+
+ // Create new vendor entry...
+ int vid = -1;
+ bool hasNDA = (dialog.checkbox1->checkState() == Qt::Checked ? true : false);
+ int vlid = dialog.combo1->itemData(dialog.combo1->currentIndex()).toInt();
+ QSqlQuery query;
+ query.prepare("INSERT INTO Vendor VALUES ('', ?, ?, ?)");
+ query.addBindValue(vlid);
+ query.addBindValue(hasNDA);
+ query.addBindValue(dialog.edit1->text());
+ query.exec();
+
+ // Get VID from record just inserted
+ query.prepare("SELECT vid FROM Vendor WHERE vlid=? AND signedNDA=? AND name=?");
+ query.addBindValue(vlid);
+ query.addBindValue(hasNDA);
+ query.addBindValue(dialog.edit1->text());
+ query.exec();
+ query.next();
+ vid = query.value(0).toInt();
+//printf("NVD: New Vendor VID=%i\n", vid);
+
+ // Add primary address...
+ query.prepare("INSERT INTO Location VALUES ('', ?, ?, ?, ?, ?, ?)");
+ query.addBindValue(vid);
+ query.addBindValue(dialog.address->field1->text());
+ query.addBindValue(dialog.address->field2->text());
+ query.addBindValue(dialog.address->field3->text());
+ query.addBindValue(dialog.address->field4->text());
+ query.addBindValue(dialog.address->field5->text());
+ query.exec();
+
+ // Fix up primary contact type
+ int ctid = -1;
+
+ // -1 in currentIndex() means nothing was selected, so create new entry
+//NOT SO FAST: Seems it defaults to whatever is found there. So need to fix that. >:-(
+// if (dialog.contact->field1->currentIndex() == -1)
+ if (dialog.contact->newContactType)
+ {
+ query.prepare("INSERT INTO ContactType VALUES ('', ?)");
+ query.addBindValue(dialog.contact->field1->currentText());
+ query.exec();
+
+ query.prepare("SELECT ctid FROM ContactType WHERE description=?");
+ query.addBindValue(dialog.contact->field1->currentText());
+ query.exec();
+ query.next();
+ ctid = query.value(0).toInt();
+ }
+ else
+ {
+ ctid = dialog.contact->field1->itemData(dialog.contact->field1->currentIndex()).toInt();
+ }
+
+ // Add primary contact...
+ query.prepare("INSERT INTO Contact VALUES ('', ?, ?, ?, ?, ?, ?, ?, ?)");
+ query.addBindValue(vid);
+ query.addBindValue(ctid);
+ query.addBindValue(dialog.contact->field2->text());
+ query.addBindValue(dialog.contact->field3->text());
+ query.addBindValue(dialog.contact->field4->text());
+ query.addBindValue(dialog.contact->field5->text());
+ query.addBindValue(dialog.contact->field6->text());
+ query.addBindValue(dialog.contact->field7->text());
+ query.exec();
+
+ // Add vendor classes...
+ for(int i=0; i<dialog.list->count(); i++)
+ {
+ QListWidgetItem * item = dialog.list->item(i);
+
+ if (item->checkState() == Qt::Checked)
+ {
+ int vtid = item->data(Qt::UserRole).toInt();
+ query.prepare("INSERT INTO VendorSpecificTypes VALUES (?, ?)");
+ query.addBindValue(vid);
+ query.addBindValue(vtid);
+ query.exec();
+ }
+ }
+
+ // Update UI
+ scmWidget->GetVendorIDs();
+ scmWidget->GetVendor(vid);
+
+//printf("NVD: Contact Type index = %i\n", dialog.contact->field1->currentIndex());
+//printf("NVD: Contact type ='%s'\n", dialog.contact->field1->currentText().toAscii().data());
+//-1 means no contact selected; check currentText() to see if it has anything in it or not
+
+ // Tables to fill:
+#if 0
+Vendor
+VID (P-key) | VLID | signedNDA | Name
+CREATE TABLE Vendor (vid INT NOT NULL PRIMARY KEY AUTO_INCREMENT, vlid INT, signedNDA TINYINT(1) NOT NULL DEFAULT 0, name VARCHAR(100), FOREIGN KEY (vlid) REFERENCES VendorLevel(vlid)) ENGINE=INNODB;
+
+VendorType
+VTID (P-key) | VGID | SeqNo | Description
+CREATE TABLE VendorType (vtid INT NOT NULL PRIMARY KEY AUTO_INCREMENT, vgid INT, seqNo INT(4) NOT NULL, description VARCHAR(100), FOREIGN KEY (vgid) REFERENCES VendorGroup(vgid)) ENGINE=INNODB;
+
+VendorSpecificTypes
+VID (multi) | VTID (multi)
+CREATE TABLE VendorSpecificTypes (vid INT, vtid INT, FOREIGN KEY (vid) REFERENCES Vendor(vid), FOREIGN KEY (vtid) REFERENCES VendorType(vtid)) ENGINE=INNODB;
+
+Location
+LID (P-key) | VID | Address | City | State | Country | Code
+CREATE TABLE Location (lid INT NOT NULL PRIMARY KEY AUTO_INCREMENT, vid INT, address VARCHAR(100), city VARCHAR(64), state VARCHAR(64), country VARCHAR(64), code VARCHAR(32), FOREIGN KEY (vid) REFERENCES Vendor(vid)) ENGINE=INNODB;
+
+Contact
+CID (P-key) | VID | CTID | Name | Email | Address | Phone1 | Phone2 | Fax
+CREATE TABLE Contact (cid INT NOT NULL PRIMARY KEY AUTO_INCREMENT, vid INT, CTID int, name VARCHAR(64), email VARCHAR(64), address VARCHAR(200), phone1 VARCHAR(32), phone2 VARCHAR(32), fax VARCHAR(32), FOREIGN KEY (vid) REFERENCES Vendor(vid), FOREIGN KEY (ctid) REFERENCES ContactType(ctid)) ENGINE=INNODB;
+
+ContactType
+CTID (P-key) | Description
+CREATE TABLE ContactType (ctid INT NOT NULL PRIMARY KEY AUTO_INCREMENT, description VARCHAR(100)) ENGINE=INNODB;
+#endif
}