2 // scmwidget.cpp - Main widget container
5 // (C) 2012 Underground Software
7 // JLH = James Hammons <jlhamm@acm.org>
10 // --- ---------- -------------------------------------------------------------
11 // JLH 09/24/2012 Created this file
14 #include "scmwidget.h"
16 #include "addresswidget.h"
17 #include "alertdialog.h"
18 #include "contactwidget.h"
19 #include "notedialog.h"
22 SCMWidget::SCMWidget(QWidget * parent/*= 0*/): QWidget(parent),
23 purchaseOrders(new QTreeView),
24 vendorName(new QLabel),
25 ndaSigned(new QLabel),
26 vendorAddress(new QTabWidget),
27 vendorContact(new QTabWidget),
28 vendorClass(new QListWidget),
30 vendorLevel(new VendorLevelWidget),
31 alerts(new QListWidget),
32 notes(new QListWidget),
33 vaw1(new AddressWidget(this)),
34 vcw1(new ContactWidget(this)),
36 nextVendorButton(new QToolButton),
37 previousVendorButton(new QToolButton),
38 editVendor(new QPushButton("Edit Vendor")),
39 addVendor(new QPushButton("Add Vendor")),
40 addLocation(new QPushButton("Add Location")),
41 addContact(new QPushButton("Add Contact")),
42 createAlert(new QPushButton("Create")),
43 createNote(new QPushButton("Create")),
44 showOpen(new QPushButton("Open")),
45 showClosed(new QPushButton("Closed")),
46 showAll(new QPushButton("All")),
47 createPO(new QPushButton("Create")),
48 vendorRelated(new QCheckBox("Show POs for this Vendor only")),
51 // Create main page widgets & layout
53 purchaseOrders->setRootIsDecorated(false);
54 purchaseOrders->setAlternatingRowColors(true);
56 QAbstractItemModel * model = new QStandardItemModel(0, 7);
57 model->setHeaderData(0, Qt::Horizontal, tr("PO #"));
58 model->setHeaderData(1, Qt::Horizontal, tr("Vendor"));
59 model->setHeaderData(2, Qt::Horizontal, tr("Desc."));
60 model->setHeaderData(3, Qt::Horizontal, tr("OAD"));
61 model->setHeaderData(4, Qt::Horizontal, tr("UAD"));
62 model->setHeaderData(5, Qt::Horizontal, tr("Docs"));
63 model->setHeaderData(6, Qt::Horizontal, tr("FAI"));
66 model->setData(model->index(0, 0), "FE823724");
67 model->setData(model->index(0, 1), "Sanford & Sons");
68 model->setData(model->index(0, 2), "Misc. Junk");
69 model->setData(model->index(0, 3), "09/30/2012");
70 model->setData(model->index(0, 4), "");
71 model->setData(model->index(0, 5), "");
72 model->setData(model->index(0, 6), "");
75 model->setData(model->index(0, 0), "89237923-123");
76 model->setData(model->index(0, 1), "Digikey");
77 model->setData(model->index(0, 2), "Small capacitors");
78 model->setData(model->index(0, 3), "10/08/2012");
79 model->setData(model->index(0, 4), "11/30/2012");
80 model->setData(model->index(0, 5), "1");
81 model->setData(model->index(0, 6), "Yes");
84 model->setData(model->index(0, 0), "T9234CS32");
85 model->setData(model->index(0, 1), "Big, Faceless Company");
86 model->setData(model->index(0, 2), "Important Stuff you need RIGHT NOW");
87 model->setData(model->index(0, 3), "09/28/2012");
88 model->setData(model->index(0, 4), "09/29/2012");
89 model->setData(model->index(0, 5), "5");
90 model->setData(model->index(0, 6), "Yes");
92 purchaseOrders->setModel(model);
94 nextVendorButton->setArrowType(Qt::RightArrow);
95 nextVendorButton->setToolTip(tr("Move to next Vendor in Database."));
96 previousVendorButton->setArrowType(Qt::LeftArrow);
97 previousVendorButton->setToolTip(tr("Move to previous Vendor in Database."));
99 QFont * vendorFont = new QFont;
100 vendorFont->setPointSize(12);
101 vendorName->setFont(*vendorFont);
102 vendorName->setText("Vendor Name");
104 QHBoxLayout * hbox1 = new QHBoxLayout;
105 hbox1->addWidget(previousVendorButton);
106 hbox1->addWidget(nextVendorButton);
107 hbox1->addWidget(vendorName);
109 // Vendor address widgets
111 // vaw1->SetFields("123 Any Street", "Any City", "Anywhere", "USA", "01234");
112 vendorAddress->addTab(vaw1, tr("Primary"));
113 vendorAddress->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
115 // Vendor contact widgets
117 // vcw1->SetFields("Sales", "Joe Blow", "joe.blow@widget.com", "Singapore", "512-222-2222", "", "512-122-2123");
118 vendorContact->addTab(vcw1, tr("Contact #1"));
119 vendorContact->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
123 QVBoxLayout * vbox1 = new QVBoxLayout;
124 vbox1->addWidget(vendorClass);
125 QGroupBox * gb1 = new QGroupBox(tr("Vendor Classes"));
126 gb1->setLayout(vbox1);
128 // Vendor action push buttons
130 QVBoxLayout * vbox4 = new QVBoxLayout;
131 QHBoxLayout * hbox3 = new QHBoxLayout;
132 QGroupBox * gb2 = new QGroupBox(tr("Vendor Actions"));
134 vbox4->addWidget(editVendor);
135 vbox4->addWidget(addVendor);
136 vbox4->addWidget(addLocation);
137 vbox4->addWidget(addContact);
138 gb2->setLayout(vbox4);
140 hbox3->addWidget(vendorLevel);
141 hbox3->addWidget(gb2);
145 QVBoxLayout * vbox5 = new QVBoxLayout;
146 QHBoxLayout * hbox4 = new QHBoxLayout;
147 QHBoxLayout * hbox5 = new QHBoxLayout;
149 QLabel * label1 = new QLabel(tr("Alerts"));
150 QLabel * label2 = new QLabel(tr("Notes"));
151 hbox4->addWidget(label1);
153 hbox4->addWidget(createAlert);
154 hbox5->addWidget(label2);
156 hbox5->addWidget(createNote);
158 vbox5->addLayout(hbox4);
159 vbox5->addWidget(alerts);
160 vbox5->addLayout(hbox5);
161 vbox5->addWidget(notes);
163 // Purchase Order headers
165 QHBoxLayout * hbox6 = new QHBoxLayout;
166 QLabel * label3 = new QLabel(tr("Purchase Orders"));
167 hbox6->addWidget(label3);
168 hbox6->addSpacing(32);
169 hbox6->addWidget(showOpen);
170 hbox6->addWidget(showClosed);
171 hbox6->addWidget(showAll);
172 hbox6->addSpacing(16);
173 hbox6->addWidget(vendorRelated);
175 hbox6->addWidget(createPO);
179 QFrame * hline = new QFrame(this);
180 hline->setFrameShape(QFrame::HLine);
181 hline->setFrameShadow(QFrame::Sunken);
183 QFrame * hline2 = new QFrame(this);
184 hline2->setFrameShape(QFrame::HLine);
185 hline2->setFrameShadow(QFrame::Sunken);
187 QHBoxLayout * hbox2 = new QHBoxLayout;
188 QVBoxLayout * vbox2 = new QVBoxLayout;
189 QVBoxLayout * vbox3 = new QVBoxLayout;
191 vbox3->addWidget(vendorContact);
192 // vbox3->addWidget(vendorLevel);
193 vbox3->addLayout(hbox3);
195 vbox2->addWidget(vendorAddress);
196 vbox2->addWidget(gb1);
198 hbox2->addLayout(vbox2);
199 hbox2->addLayout(vbox3);
200 hbox2->addLayout(vbox5);
202 QVBoxLayout * mainLayout = new QVBoxLayout;
203 mainLayout->addWidget(username);
204 mainLayout->addWidget(hline);
205 mainLayout->addLayout(hbox1);
206 mainLayout->addLayout(hbox2);
207 mainLayout->addWidget(hline2);
208 mainLayout->addLayout(hbox6);
209 mainLayout->addWidget(purchaseOrders);
210 setLayout(mainLayout);
214 connect(nextVendorButton, SIGNAL(clicked()), this, SLOT(GetNextVendor()));
215 connect(previousVendorButton, SIGNAL(clicked()), this, SLOT(GetPreviousVendor()));
216 connect(createNote, SIGNAL(clicked()), this, SLOT(CreateNote()));
217 connect(createAlert, SIGNAL(clicked()), this, SLOT(CreateAlert()));
218 connect(createPO, SIGNAL(clicked()), this, SLOT(CreatePurchaseOrder()));
219 connect(showOpen, SIGNAL(clicked()), this, SLOT(ShowOpenPOs()));
220 connect(showClosed, SIGNAL(clicked()), this, SLOT(ShowClosedPOs()));
221 connect(showAll, SIGNAL(clicked()), this, SLOT(ShowAllPOs()));
222 // connect(addVendor, SIGNAL(clicked()), this, SLOT(AddVendor()));
223 connect(addLocation, SIGNAL(clicked()), this, SLOT(AddLocation()));
224 connect(addContact, SIGNAL(clicked()), this, SLOT(AddContact()));
225 connect(editVendor, SIGNAL(clicked()), this, SLOT(EditVendor()));
228 GetVendor(vendorID[vidCursor]);
232 void SCMWidget::GetNextVendor(void)
234 if (vidCursor < (vendorID.size() - 1))
237 GetVendor(vendorID[vidCursor]);
242 void SCMWidget::GetPreviousVendor(void)
247 GetVendor(vendorID[vidCursor]);
252 void SCMWidget::CreateNote(void)
254 NoteDialog dlg(currentUID);
256 if (dlg.exec() == false)
263 void SCMWidget::CreateAlert(void)
265 AlertDialog dlg(currentUID);
267 if (dlg.exec() == false)
270 QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation");
275 void SCMWidget::CreatePurchaseOrder(void)
277 QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation");
281 void SCMWidget::ShowOpenPOs(void)
283 QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation");
287 void SCMWidget::ShowClosedPOs(void)
289 QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation");
293 void SCMWidget::ShowAllPOs(void)
295 QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation");
299 void SCMWidget::AddVendor(void)
301 QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation");
305 void SCMWidget::AddLocation(void)
307 QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation");
311 void SCMWidget::AddContact(void)
313 QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation");
317 void SCMWidget::EditVendor(void)
319 QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation");
323 void SCMWidget::GetVendorIDs(void)
328 query.prepare("SELECT vid FROM Vendor ORDER BY name");
333 int vid = query.value(0).toInt();
334 vendorID.push_back(vid);
339 void SCMWidget::GetVendor(int key)
341 // Get main vendor data
343 query.prepare("SELECT v.name, signedNDA, l.address, city, state, country, code, "
344 "c.name, email, c.address, phone1, phone2, fax, description, v.vlid FROM "
345 "Vendor AS v LEFT OUTER JOIN Location AS l ON v.vid = l.vid "
346 "LEFT OUTER JOIN (Contact AS c JOIN ContactType AS ct ON c.ctid = ct.ctid) "
347 "ON v.vid = c.vid WHERE v.vid = ?");
348 query.addBindValue(key);
351 // There's a possibility that the query will return multiple rows (which we need
352 // to handle, with multiple tabs), but for now, we ignore any and grab the first.
355 vendorName->setText(query.value(0).toString());
357 vaw1->SetFields(query.value(2).toString(),
358 query.value(3).toString(), query.value(4).toString(),
359 query.value(5).toString(), query.value(6).toString());
360 vcw1->SetFields(query.value(13).toString(),
361 query.value(7).toString(), query.value(8).toString(),
362 query.value(9).toString(), query.value(10).toString(),
363 query.value(11).toString(), query.value(12).toString());
365 int vlid = query.value(14).toInt();
366 vendorLevel->DoQuery(vlid);
369 // Get vendor classes
370 query.prepare("SELECT description FROM VendorSpecificTypes AS vst, VendorType AS vt "
371 "WHERE vst.vid = ? AND vst.vtid = vt.vtid ORDER BY seqNo");
372 query.addBindValue(key);
375 vendorClass->clear();
379 QListWidgetItem * item = new QListWidgetItem(query.value(0).toString());
380 vendorClass->addItem(item);
385 void SCMWidget::UpdateNotes(void)
387 // QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation");
388 //NID (P-key) | UID | POID | Note
391 query.prepare("SELECT note FROM Notes WHERE uid = ?");
392 query.addBindValue(currentUID);
399 QListWidgetItem * item = new QListWidgetItem(query.value(0).toString());
400 notes->addItem(item);
405 void SCMWidget::UpdateAlerts(void)
407 // TODO: Implementation