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 "contactwidget.h"
20 SCMWidget::SCMWidget(QWidget * parent/*= 0*/): QWidget(parent),
21 purchaseOrders(new QTreeView),
22 vendorName(new QLabel),
23 ndaSigned(new QLabel),
24 vendorAddress(new QTabWidget),
25 vendorContact(new QTabWidget),
26 vendorClass(new QListWidget),
28 vendorLevel(new VendorLevelWidget),
29 alerts(new QListWidget),
30 notes(new QListWidget),
31 vaw1(new AddressWidget(this)),
32 vcw1(new ContactWidget(this)),
34 nextVendorButton(new QToolButton),
35 previousVendorButton(new QToolButton),
36 editVendor(new QPushButton("Edit Vendor")),
37 addVendor(new QPushButton("Add Vendor")),
38 addLocation(new QPushButton("Add Location")),
39 addContact(new QPushButton("Add Contact")),
40 createAlert(new QPushButton("Create")),
41 createNote(new QPushButton("Create")),
42 showOpen(new QPushButton("Open")),
43 showClosed(new QPushButton("Closed")),
44 showAll(new QPushButton("All")),
45 createPO(new QPushButton("Create")),
46 vendorRelated(new QCheckBox("Show POs for this Vendor only")),
49 // Create main page widgets & layout
51 purchaseOrders->setRootIsDecorated(false);
52 purchaseOrders->setAlternatingRowColors(true);
54 QAbstractItemModel * model = new QStandardItemModel(0, 7);
55 model->setHeaderData(0, Qt::Horizontal, tr("PO #"));
56 model->setHeaderData(1, Qt::Horizontal, tr("Vendor"));
57 model->setHeaderData(2, Qt::Horizontal, tr("Desc."));
58 model->setHeaderData(3, Qt::Horizontal, tr("OAD"));
59 model->setHeaderData(4, Qt::Horizontal, tr("UAD"));
60 model->setHeaderData(5, Qt::Horizontal, tr("Docs"));
61 model->setHeaderData(6, Qt::Horizontal, tr("FAI"));
64 model->setData(model->index(0, 0), "FE823724");
65 model->setData(model->index(0, 1), "Sanford & Sons");
66 model->setData(model->index(0, 2), "Misc. Junk");
67 model->setData(model->index(0, 3), "09/30/2012");
68 model->setData(model->index(0, 4), "");
69 model->setData(model->index(0, 5), "");
70 model->setData(model->index(0, 6), "");
73 model->setData(model->index(0, 0), "89237923-123");
74 model->setData(model->index(0, 1), "Digikey");
75 model->setData(model->index(0, 2), "Small capacitors");
76 model->setData(model->index(0, 3), "10/08/2012");
77 model->setData(model->index(0, 4), "11/30/2012");
78 model->setData(model->index(0, 5), "1");
79 model->setData(model->index(0, 6), "Yes");
82 model->setData(model->index(0, 0), "T9234CS32");
83 model->setData(model->index(0, 1), "Big, Faceless Company");
84 model->setData(model->index(0, 2), "Important Stuff you need RIGHT NOW");
85 model->setData(model->index(0, 3), "09/28/2012");
86 model->setData(model->index(0, 4), "09/29/2012");
87 model->setData(model->index(0, 5), "5");
88 model->setData(model->index(0, 6), "Yes");
90 purchaseOrders->setModel(model);
92 nextVendorButton->setArrowType(Qt::RightArrow);
93 nextVendorButton->setToolTip(tr("Move to next Vendor in Database."));
94 previousVendorButton->setArrowType(Qt::LeftArrow);
95 previousVendorButton->setToolTip(tr("Move to previous Vendor in Database."));
97 QFont * vendorFont = new QFont;
98 vendorFont->setPointSize(12);
99 vendorName->setFont(*vendorFont);
100 vendorName->setText("Vendor Name");
102 QHBoxLayout * hbox1 = new QHBoxLayout;
103 hbox1->addWidget(previousVendorButton);
104 hbox1->addWidget(nextVendorButton);
105 hbox1->addWidget(vendorName);
107 // Vendor address widgets
109 // vaw1->SetFields("123 Any Street", "Any City", "Anywhere", "USA", "01234");
110 vendorAddress->addTab(vaw1, tr("Primary"));
111 vendorAddress->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
113 // Vendor contact widgets
115 // vcw1->SetFields("Sales", "Joe Blow", "joe.blow@widget.com", "Singapore", "512-222-2222", "", "512-122-2123");
116 vendorContact->addTab(vcw1, tr("Contact #1"));
117 vendorContact->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
121 QVBoxLayout * vbox1 = new QVBoxLayout;
122 vbox1->addWidget(vendorClass);
123 QGroupBox * gb1 = new QGroupBox(tr("Vendor Classes"));
124 gb1->setLayout(vbox1);
126 // Vendor action push buttons
128 QVBoxLayout * vbox4 = new QVBoxLayout;
129 QHBoxLayout * hbox3 = new QHBoxLayout;
130 QGroupBox * gb2 = new QGroupBox(tr("Vendor Actions"));
132 vbox4->addWidget(editVendor);
133 vbox4->addWidget(addVendor);
134 vbox4->addWidget(addLocation);
135 vbox4->addWidget(addContact);
136 gb2->setLayout(vbox4);
138 hbox3->addWidget(vendorLevel);
139 hbox3->addWidget(gb2);
143 QVBoxLayout * vbox5 = new QVBoxLayout;
144 QHBoxLayout * hbox4 = new QHBoxLayout;
145 QHBoxLayout * hbox5 = new QHBoxLayout;
147 QLabel * label1 = new QLabel(tr("Alerts"));
148 QLabel * label2 = new QLabel(tr("Notes"));
149 hbox4->addWidget(label1);
151 hbox4->addWidget(createAlert);
152 hbox5->addWidget(label2);
154 hbox5->addWidget(createNote);
156 vbox5->addLayout(hbox4);
157 vbox5->addWidget(alerts);
158 vbox5->addLayout(hbox5);
159 vbox5->addWidget(notes);
161 // Purchase Order headers
163 QHBoxLayout * hbox6 = new QHBoxLayout;
164 QLabel * label3 = new QLabel(tr("Purchase Orders"));
165 hbox6->addWidget(label3);
166 hbox6->addSpacing(32);
167 hbox6->addWidget(showOpen);
168 hbox6->addWidget(showClosed);
169 hbox6->addWidget(showAll);
170 hbox6->addSpacing(16);
171 hbox6->addWidget(vendorRelated);
173 hbox6->addWidget(createPO);
177 QFrame * hline = new QFrame(this);
178 hline->setFrameShape(QFrame::HLine);
179 hline->setFrameShadow(QFrame::Sunken);
181 QFrame * hline2 = new QFrame(this);
182 hline2->setFrameShape(QFrame::HLine);
183 hline2->setFrameShadow(QFrame::Sunken);
185 QHBoxLayout * hbox2 = new QHBoxLayout;
186 QVBoxLayout * vbox2 = new QVBoxLayout;
187 QVBoxLayout * vbox3 = new QVBoxLayout;
189 vbox3->addWidget(vendorContact);
190 // vbox3->addWidget(vendorLevel);
191 vbox3->addLayout(hbox3);
193 vbox2->addWidget(vendorAddress);
194 vbox2->addWidget(gb1);
196 hbox2->addLayout(vbox2);
197 hbox2->addLayout(vbox3);
198 hbox2->addLayout(vbox5);
200 QVBoxLayout * mainLayout = new QVBoxLayout;
201 mainLayout->addWidget(username);
202 mainLayout->addWidget(hline);
203 mainLayout->addLayout(hbox1);
204 mainLayout->addLayout(hbox2);
205 mainLayout->addWidget(hline2);
206 mainLayout->addLayout(hbox6);
207 mainLayout->addWidget(purchaseOrders);
208 setLayout(mainLayout);
212 connect(nextVendorButton, SIGNAL(clicked()), this, SLOT(GetNextVendor()));
213 connect(previousVendorButton, SIGNAL(clicked()), this, SLOT(GetPreviousVendor()));
214 connect(createNote, SIGNAL(clicked()), this, SLOT(CreateNote()));
215 connect(createAlert, SIGNAL(clicked()), this, SLOT(CreateAlert()));
216 connect(createPO, SIGNAL(clicked()), this, SLOT(CreatePurchaseOrder()));
217 connect(showOpen, SIGNAL(clicked()), this, SLOT(ShowOpenPOs()));
218 connect(showClosed, SIGNAL(clicked()), this, SLOT(ShowClosedPOs()));
219 connect(showAll, SIGNAL(clicked()), this, SLOT(ShowAllPOs()));
220 connect(addVendor, SIGNAL(clicked()), this, SLOT(AddVendor()));
221 connect(addLocation, SIGNAL(clicked()), this, SLOT(AddLocation()));
222 connect(addContact, SIGNAL(clicked()), this, SLOT(AddContact()));
223 connect(editVendor, SIGNAL(clicked()), this, SLOT(EditVendor()));
226 GetVendor(vendorID[vidCursor]);
230 void SCMWidget::GetNextVendor(void)
232 if (vidCursor < (vendorID.size() - 1))
235 GetVendor(vendorID[vidCursor]);
240 void SCMWidget::GetPreviousVendor(void)
245 GetVendor(vendorID[vidCursor]);
250 void SCMWidget::CreateNote(void)
252 QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation");
256 void SCMWidget::CreateAlert(void)
258 QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation");
262 void SCMWidget::CreatePurchaseOrder(void)
264 QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation");
268 void SCMWidget::ShowOpenPOs(void)
270 QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation");
274 void SCMWidget::ShowClosedPOs(void)
276 QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation");
280 void SCMWidget::ShowAllPOs(void)
282 QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation");
286 void SCMWidget::AddVendor(void)
288 QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation");
292 void SCMWidget::AddLocation(void)
294 QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation");
298 void SCMWidget::AddContact(void)
300 QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation");
304 void SCMWidget::EditVendor(void)
306 QMessageBox::warning(this, "Approaching Singularity!", "TODO: Implementation");
310 void SCMWidget::GetVendorIDs(void)
315 query.prepare("SELECT vid FROM Vendor ORDER BY name");
320 int vid = query.value(0).toInt();
321 vendorID.push_back(vid);
326 void SCMWidget::GetVendor(int key)
328 // Get main vendor data
330 query.prepare("SELECT v.name, signedNDA, l.address, city, state, country, code, "
331 "c.name, email, c.address, phone1, phone2, fax, description, v.vlid FROM "
332 "Vendor AS v LEFT OUTER JOIN Location AS l ON v.vid = l.vid "
333 "LEFT OUTER JOIN (Contact AS c JOIN ContactType AS ct ON c.ctid = ct.ctid) "
334 "ON v.vid = c.vid WHERE v.vid = ?");
335 query.addBindValue(key);
338 // There's a possibility that the query will return multiple rows (which we need
339 // to handle, with multiple tabs), but for now, we ignore any and grab the first.
342 vendorName->setText(query.value(0).toString());
344 vaw1->SetFields(query.value(2).toString(),
345 query.value(3).toString(), query.value(4).toString(),
346 query.value(5).toString(), query.value(6).toString());
347 vcw1->SetFields(query.value(13).toString(),
348 query.value(7).toString(), query.value(8).toString(),
349 query.value(9).toString(), query.value(10).toString(),
350 query.value(11).toString(), query.value(12).toString());
352 int vlid = query.value(14).toInt();
353 vendorLevel->DoQuery(vlid);
356 // Get vendor classes
357 query.prepare("SELECT description FROM VendorSpecificTypes AS vst, VendorType AS vt "
358 "WHERE vst.vid = ? AND vst.vtid = vt.vtid ORDER BY seqNo");
359 query.addBindValue(key);
362 vendorClass->clear();
366 QListWidgetItem * item = new QListWidgetItem(query.value(0).toString());
367 vendorClass->addItem(item);