-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStockGUI.java
More file actions
1039 lines (976 loc) · 48.4 KB
/
StockGUI.java
File metadata and controls
1039 lines (976 loc) · 48.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package PAT;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.DefaultTableModel;
import javax.swing.JOptionPane;
/*
Class StockGUI
Front end for the stock class and provides an interface for the user to manage
the inventory and pending orders
*/
public class StockGUI extends javax.swing.JFrame {
String userWelcome = ""; //welcome message displayed in main GUI
String userType = ""; //Type of the current user
String foundID = ""; //ID of the item found
Stock sto = new Stock(); //Isntance of the stock class
ResultSet rs; //Resultset to store all the data retrieved from the stock class
/*
Constructor Method #1
Used when a new instance of the StockGUI is created without a item needed to be preloaded
@parameters: String userType, String user welcome message
@return: none
*/
public StockGUI(String _userType, String _userWelcome) {
userType = _userType;
userWelcome = _userWelcome;
initComponents();
updateTableInventory(); //enter item details into the table
}
/*
Constructor Method #2
Used when item is found in the search GUI and the found item is preloaded into the data fields
@parameters: String cureent user's type, String User welcome message, String ID of the item found
@return: none
*/
public StockGUI(String _userType, String _userWelcome, String _foundID) {
userType = _userType;
userWelcome = _userWelcome;
foundID = _foundID;
initComponents();
updateTableInventory(); //enter item details into the table
insertFoundID(foundID); //Preload the details of the found item
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
typeRadButtons = new javax.swing.ButtonGroup();
btnBack = new javax.swing.JButton();
lblInventoryGUI = new javax.swing.JLabel();
lblInventoryHelp = new javax.swing.JButton();
jTabbedPane1 = new javax.swing.JTabbedPane();
jPanel1 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
tblInventory = new javax.swing.JTable();
lblItemID = new javax.swing.JLabel();
txtFieldItemID = new javax.swing.JTextField();
lblItemName = new javax.swing.JLabel();
txtFieldItemName = new javax.swing.JTextField();
lblItemQuantity = new javax.swing.JLabel();
spinItemQuantity = new javax.swing.JSpinner();
btnInventorySearch = new javax.swing.JButton();
btnManage = new javax.swing.JButton();
jPanel2 = new javax.swing.JPanel();
btnOrderSearch = new javax.swing.JButton();
jScrollPane2 = new javax.swing.JScrollPane();
tblOrders = new javax.swing.JTable();
btnReceived = new javax.swing.JButton();
jSeparator1 = new javax.swing.JSeparator();
lblNewOrder = new javax.swing.JLabel();
jScrollPane3 = new javax.swing.JScrollPane();
tblItems = new javax.swing.JTable();
lblOrderType = new javax.swing.JLabel();
radBtnCredit = new javax.swing.JRadioButton();
radBtnCash = new javax.swing.JRadioButton();
spinOrderQuantity = new javax.swing.JSpinner();
lblOrderAmount = new javax.swing.JLabel();
btnPlaceOrder = new javax.swing.JButton();
lblOrderID = new javax.swing.JLabel();
txtFieldOrderID = new javax.swing.JTextField();
txtFieldOrderItemID = new javax.swing.JTextField();
lblOrderItemID = new javax.swing.JLabel();
lblOrderName = new javax.swing.JLabel();
txtFieldOrderName = new javax.swing.JTextField();
btnGetOrderItemName = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
btnBack.setFont(new java.awt.Font("Tahoma", 1, 16)); // NOI18N
btnBack.setText("BACK");
btnBack.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2));
btnBack.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnBackActionPerformed(evt);
}
});
lblInventoryGUI.setBackground(new java.awt.Color(255, 255, 255));
lblInventoryGUI.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
lblInventoryGUI.setText(" Stock");
lblInventoryGUI.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 3));
lblInventoryHelp.setFont(new java.awt.Font("Tahoma", 1, 16)); // NOI18N
lblInventoryHelp.setText("Help");
lblInventoryHelp.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2));
lblInventoryHelp.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
lblInventoryHelpActionPerformed(evt);
}
});
jTabbedPane1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jTabbedPane1MouseClicked(evt);
}
});
tblInventory.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null}
},
new String [] {
"itemID", "itemName", "itemQuanitity"
}
) {
Class[] types = new Class [] {
java.lang.Integer.class, java.lang.String.class, java.lang.Integer.class
};
boolean[] canEdit = new boolean [] {
false, false, false
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
tblInventory.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
tblInventoryMouseClicked(evt);
}
});
jScrollPane1.setViewportView(tblInventory);
lblItemID.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
lblItemID.setText("ID:");
txtFieldItemID.setEditable(false);
txtFieldItemID.setBackground(new java.awt.Color(255, 255, 255));
lblItemName.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
lblItemName.setText("Name:");
txtFieldItemName.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtFieldItemNameActionPerformed(evt);
}
});
lblItemQuantity.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
lblItemQuantity.setText("Quantity");
spinItemQuantity.setModel(new javax.swing.SpinnerNumberModel(0, 0, 2000, 1));
btnInventorySearch.setText("Search");
btnInventorySearch.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnInventorySearchActionPerformed(evt);
}
});
btnManage.setText("Manage");
btnManage.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnManageActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(107, 107, 107)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblItemID)
.addComponent(btnInventorySearch))
.addGap(89, 89, 89)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtFieldItemID, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnManage)))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblItemQuantity, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblItemName, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(83, 83, 83)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtFieldItemName, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(spinItemQuantity, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE))))))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(22, 22, 22)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 239, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(61, 61, 61)
.addComponent(lblItemID))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtFieldItemID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblItemName)
.addComponent(txtFieldItemName, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblItemQuantity)
.addComponent(spinItemQuantity, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(26, 26, 26)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnInventorySearch)
.addComponent(btnManage))
.addContainerGap(92, Short.MAX_VALUE))
);
jTabbedPane1.addTab("Inventory", jPanel1);
btnOrderSearch.setText("Search for Order");
btnOrderSearch.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnOrderSearchActionPerformed(evt);
}
});
tblOrders.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null}
},
new String [] {
"OrderID", "itemID", "Quantity"
}
) {
Class[] types = new Class [] {
java.lang.Integer.class, java.lang.String.class, java.lang.Integer.class
};
boolean[] canEdit = new boolean [] {
false, false, false
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
tblOrders.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
tblOrdersMouseClicked(evt);
}
});
jScrollPane2.setViewportView(tblOrders);
btnReceived.setText("Received");
btnReceived.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnReceivedActionPerformed(evt);
}
});
jSeparator1.setBackground(new java.awt.Color(0, 0, 0));
lblNewOrder.setBackground(new java.awt.Color(255, 255, 255));
lblNewOrder.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
lblNewOrder.setText("New Order");
lblNewOrder.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 3));
tblItems.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null},
{null, null},
{null, null},
{null, null},
{null, null},
{null, null},
{null, null},
{null, null}
},
new String [] {
"itemID", "itemName"
}
) {
Class[] types = new Class [] {
java.lang.Integer.class, java.lang.String.class
};
boolean[] canEdit = new boolean [] {
false, false
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
tblItems.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
tblItemsMouseClicked(evt);
}
});
jScrollPane3.setViewportView(tblItems);
lblOrderType.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
lblOrderType.setText("Type:");
typeRadButtons.add(radBtnCredit);
radBtnCredit.setText("Credit");
radBtnCredit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
radBtnCreditActionPerformed(evt);
}
});
typeRadButtons.add(radBtnCash);
radBtnCash.setText("Cash");
radBtnCash.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
radBtnCashActionPerformed(evt);
}
});
spinOrderQuantity.setModel(new javax.swing.SpinnerNumberModel(0, 0, 2000, 1));
lblOrderAmount.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
lblOrderAmount.setText("Amount");
btnPlaceOrder.setText("Place Order");
btnPlaceOrder.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnPlaceOrderActionPerformed(evt);
}
});
lblOrderID.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
lblOrderID.setText("Order ID:");
txtFieldOrderID.setEditable(false);
txtFieldOrderID.setBackground(new java.awt.Color(255, 255, 255));
txtFieldOrderID.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtFieldOrderIDActionPerformed(evt);
}
});
txtFieldOrderID.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
public void propertyChange(java.beans.PropertyChangeEvent evt) {
txtFieldOrderIDPropertyChange(evt);
}
});
txtFieldOrderItemID.setEditable(false);
txtFieldOrderItemID.setBackground(new java.awt.Color(255, 255, 255));
lblOrderItemID.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
lblOrderItemID.setText("Item ID");
lblOrderName.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
lblOrderName.setText("Item Name:");
txtFieldOrderName.setEditable(false);
txtFieldOrderName.setBackground(new java.awt.Color(255, 255, 255));
btnGetOrderItemName.setText("-->");
btnGetOrderItemName.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnGetOrderItemNameActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(75, 75, 75)
.addComponent(lblOrderID)
.addGap(27, 27, 27)
.addComponent(txtFieldOrderID, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnGetOrderItemName, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lblOrderName)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtFieldOrderName, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(188, 188, 188)
.addComponent(btnReceived))
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(85, 85, 85)
.addComponent(lblOrderType)
.addGap(32, 32, 32)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(radBtnCredit)
.addGap(72, 72, 72)
.addComponent(radBtnCash))
.addComponent(lblNewOrder, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(188, 188, 188)
.addComponent(btnPlaceOrder))
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(171, 171, 171)
.addComponent(btnOrderSearch)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblOrderAmount)
.addComponent(lblOrderItemID))
.addGap(29, 29, 29)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtFieldOrderItemID, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(spinOrderQuantity, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(159, 159, 159))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(22, 22, 22)
.addComponent(btnOrderSearch)
.addGap(18, 18, 18)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtFieldOrderID, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblOrderID)
.addComponent(lblOrderName)
.addComponent(txtFieldOrderName, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnGetOrderItemName))
.addGap(18, 18, 18)
.addComponent(btnReceived)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lblNewOrder, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(20, 20, 20)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblOrderType)
.addComponent(radBtnCredit)
.addComponent(radBtnCash))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(12, 12, 12)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblOrderItemID)
.addComponent(txtFieldOrderItemID, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(spinOrderQuantity, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblOrderAmount))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE)
.addComponent(btnPlaceOrder)
.addContainerGap())
);
jTabbedPane1.addTab("Order", jPanel2);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTabbedPane1)
.addGroup(layout.createSequentialGroup()
.addComponent(btnBack, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lblInventoryGUI, javax.swing.GroupLayout.PREFERRED_SIZE, 288, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lblInventoryHelp, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblInventoryHelp, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblInventoryGUI, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnBack, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(2, 2, 2)
.addComponent(jTabbedPane1))
);
pack();
}// </editor-fold>//GEN-END:initComponents
/*
Method of the back button
Returns to the main GUI and closes the stock GUI
*/
private void btnBackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBackActionPerformed
dispose();
MainGUI mai = new MainGUI(userType, userWelcome);
mai.setVisible(true);
}//GEN-LAST:event_btnBackActionPerformed
/*
Method of the Help button
Opens the help text
*/
private void lblInventoryHelpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_lblInventoryHelpActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_lblInventoryHelpActionPerformed
/*
Method of the search button
Opens the InventorySearchGUI to find the item the user wants
*/
private void btnInventorySearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnInventorySearchActionPerformed
InventorySearchGUI search = new InventorySearchGUI(userType, userWelcome);
search.setVisible(true);
dispose();
}//GEN-LAST:event_btnInventorySearchActionPerformed
/*
Method of the manage buttons
Used to update the items with their new details
*/
private void btnManageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnManageActionPerformed
if(txtFieldItemID.getText().isEmpty() == false ){ //Check that an item has been selected
//check that the item name is filled in
if(txtFieldItemName.getText().isEmpty() == false ){
//Extract data from the data fields
String ID = txtFieldItemID.getText();
String name = txtFieldItemName.getText();
int quantity = (Integer)spinItemQuantity.getValue();
//Update the stock item with extracted info from the data fields
sto.updateStockItem(ID, name, quantity);
//Repopulate table with updated information
updateTableInventory();
//clear the data fields of existing info
clearFields();
//Notify the user that the item has been updated
JOptionPane.showMessageDialog(null, "Stock Item has been updated");
}else{
//advise user to fill out the name of the stock item
JOptionPane.showMessageDialog(null, "Name of the stock Item is empty");
}
}else{
//Advise user to first select a stock item
JOptionPane.showMessageDialog(null, "No stock item has been selected");
}
}//GEN-LAST:event_btnManageActionPerformed
// ignore the following method
private void txtFieldItemNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtFieldItemNameActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_txtFieldItemNameActionPerformed
/*
Method tblInventoryMouseClicked
Populates the data fields with the information of the row
that the user has selected in the table
*/
private void tblInventoryMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblInventoryMouseClicked
int row = tblInventory.rowAtPoint(evt.getPoint()); //get selected row
//populate the data fields with the selected row's information
populateFields(row);
}//GEN-LAST:event_tblInventoryMouseClicked
//ignore the following method
private void radBtnCashActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radBtnCashActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_radBtnCashActionPerformed
//Ignore the following method
private void radBtnCreditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radBtnCreditActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_radBtnCreditActionPerformed
/*
tblItemsMouseClicked
Populates the data fields with the information of the row
that the user has selected in the table
*/
private void tblItemsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblItemsMouseClicked
int row = tblItems.rowAtPoint(evt.getPoint());
txtFieldOrderItemID.setText((String)tblItems.getValueAt(row, 0));
}//GEN-LAST:event_tblItemsMouseClicked
/*
Method of the receive button
Adds the item amount of an order to the item and then deletes the order
*/
private void btnReceivedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnReceivedActionPerformed
String orderID = txtFieldOrderID.getText(); //get the order's OD
//If their is an order selected
if(orderID.length() > 0){
try {
//get the order's details
String itemID = sto.getOrderItem(orderID);
int amount = sto.getOrderAmount(orderID);
sto.addStock(itemID, amount);
sto.deleteOrder(orderID);
//Repopulate the orders table with new info
updateTableOrders();
//Repopulate the inventory table with new info
updateTableInventory();
//clear the data fields
txtFieldOrderName.setText("");
txtFieldOrderID.setText("");
//Notify the user that the order has been received
JOptionPane.showMessageDialog(null, "Order has been received.");
} catch (SQLException ex) {
Logger.getLogger(StockGUI.class.getName()).log(Level.SEVERE, null, ex);
}
}else{
//advise the user to select an order first
JOptionPane.showMessageDialog(null, "No order is selected.");
}
}//GEN-LAST:event_btnReceivedActionPerformed
/*
Method of the search button
Allows user to search for an order and then populates the data field
with order ID
*/
private void btnOrderSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOrderSearchActionPerformed
//User input with order ID amount
String orderIDInput = JOptionPane.showInputDialog("Enter desired order ID.");
//check that user actually entered an ID
if(orderIDInput.length() > 0){
//Checks that their are no letters in the order ID
if(hasLetters(orderIDInput) == false){
//populates the fields with the correct order
selectOrder(orderIDInput);
txtFieldOrderName.setText("");
}else{
//Notify the user that the given order ID is not valid
JOptionPane.showMessageDialog(null, "Invalid OrderID");
}
}else{
// Advise the user that they must enter an Order ID
JOptionPane.showMessageDialog(null, "No order ID was entered.");
}
}//GEN-LAST:event_btnOrderSearchActionPerformed
/*
Method tblOrdersMouseClicked
Populates the data fields with the selected order
*/
private void tblOrdersMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblOrdersMouseClicked
int row = tblOrders.rowAtPoint(evt.getPoint());
txtFieldOrderID.setText((String)tblOrders.getValueAt(row, 0));
txtFieldOrderName.setText(""); //Clear the item name that was previously there
}//GEN-LAST:event_tblOrdersMouseClicked
/*
Method of the place order button
Checks what type of order the user selected
if credit, it makes a new order record for the order table
if cash it adds the quantity of the specified item diretly to the item table
*/
private void btnPlaceOrderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPlaceOrderActionPerformed
//Check that an item ID has been given and that the item amount is not zero
if(txtFieldOrderItemID.equals("")== false && (Integer)spinOrderQuantity.getValue() > 0){
if(radBtnCredit.isSelected()){ //if order is credit
//add order to the database
sto.insertOrder(txtFieldOrderItemID.getText(),(Integer)spinOrderQuantity.getValue());
updateTableOrders();
//Clear data fields of the placed order
clearPlacedOrder();
//notify user that the order has been placed
JOptionPane.showMessageDialog(null, "Order has been placed.");
}else if(radBtnCash.isSelected()){ //If order is cash
try {
//add stock directly to the inventory database
sto.addStock(txtFieldOrderItemID.getText(),(Integer)spinOrderQuantity.getValue());
//Notify the user that the stock has been added
JOptionPane.showMessageDialog(null, "Stock has been added.");
clearPlacedOrder();
updateTableInventory();
} catch (SQLException ex) {
Logger.getLogger(StockGUI.class.getName()).log(Level.SEVERE, null, ex);
}
}
}else{
//Advise user to fill in the missing information
JOptionPane.showMessageDialog(null, "No item was selected and/or a zero amount was sepcified.");
}
}//GEN-LAST:event_btnPlaceOrderActionPerformed
/*
Method jTabbedPane1MousClicked
When the tab is switched it should update the two tables of the GUI
*/
private void jTabbedPane1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTabbedPane1MouseClicked
updateTableOrders();
updateTableItems();
}//GEN-LAST:event_jTabbedPane1MouseClicked
/*
Ignore the following method
*/
private void txtFieldOrderIDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtFieldOrderIDActionPerformed
}//GEN-LAST:event_txtFieldOrderIDActionPerformed
/*
Ignore the following method
*/
private void txtFieldOrderIDPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_txtFieldOrderIDPropertyChange
}//GEN-LAST:event_txtFieldOrderIDPropertyChange
/*
Method of the getOrderItemName button
Converts the item ID of the order into the name of the item
*/
private void btnGetOrderItemNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGetOrderItemNameActionPerformed
int row = tblOrders.getSelectedRow(); //get selected row
String ID = (String)tblOrders.getValueAt(row, 1); //retrieve item ID in row
try {
//Convert item ID into item name
String itemName = sto.getItemName(ID);
//display on GUI
txtFieldOrderName.setText(itemName);
} catch (SQLException ex) {
Logger.getLogger(StockGUI.class.getName()).log(Level.SEVERE, null, ex);
}
}//GEN-LAST:event_btnGetOrderItemNameActionPerformed
/*
Method updateTableInventory
populates the inventory table with item info from the database
@parameters: none
@return: none
*/
private void updateTableInventory(){
clearTableInventory(); //clear current info in table
try {
rs = sto.getStockInfo(); //get new info
while(rs.next()){
//extract info from resultset
String ID = rs.getString("itemID");
String name = rs.getString("itemName");
String quantity = rs.getString("itemQuantity");
String data[] = {ID, name, quantity};
DefaultTableModel model = (DefaultTableModel)tblInventory.getModel();
//add new info to the GUI table
model.addRow(data);
}
} catch (SQLException ex) {
Logger.getLogger(StockGUI.class.getName()).log(Level.SEVERE, null, ex);
}
}
/*
Method updateTableOrders
populates the order table with order info from the database
@parameters: none
@return: none
*/
private void updateTableOrders(){
clearTableOrder(); //clear old info
try {
rs = sto.getOrderInfo(); //get new info
while(rs.next()){
//extract info from the resultset
String ID = rs.getString("orderID");
String name = rs.getString("itemID");
String quantity = rs.getString("orderQuantity");
String data[] = {ID, name, quantity};
DefaultTableModel model = (DefaultTableModel)tblOrders.getModel();
//add new info to the table in the GUI
model.addRow(data);
}
} catch (SQLException ex) {
Logger.getLogger(StockGUI.class.getName()).log(Level.SEVERE, null, ex);
}
}
/*
Method updateTableItems
populates the item table with corresponding info from the database
@parameters: none
@return: none
*/
private void updateTableItems(){
clearTableItems(); //clear current info
try {
rs = sto.getItemNames(); //get new info
while(rs.next()){
//extract info from resultset
String ID = rs.getString("itemID");
String name = rs.getString("itemName");
String data[] = {ID, name};
DefaultTableModel model = (DefaultTableModel)tblItems.getModel();
//add to the table in the GUI
model.addRow(data);
}
} catch (SQLException ex) {
Logger.getLogger(StockGUI.class.getName()).log(Level.SEVERE, null, ex);
}
}
/*
Method clearTableInventory
Clears the Inventory table in the GUI of it's current contents
@parameters: none
@return: none
*/
private void clearTableInventory(){
DefaultTableModel model = (DefaultTableModel)tblInventory.getModel();
while(model.getRowCount()> 0){
model.removeRow(0);
}
}
/*
Method clearTableOrder
Clears the Order table in the GUI of it's current contents
@parameters: none
@return: none
*/
private void clearTableOrder(){
DefaultTableModel model = (DefaultTableModel)tblOrders.getModel();
while(model.getRowCount()> 0){
model.removeRow(0);
}
}
/*
Method clearTableInems
Clears the Items table in the GUI of it's current contents
@parameters: none
@return: none
*/
private void clearTableItems(){
DefaultTableModel model = (DefaultTableModel)tblItems.getModel();
while(model.getRowCount()> 0){
model.removeRow(0);
}
}
private void populateFields(int row){
txtFieldItemID.setText((String)tblInventory.getValueAt(row, 0));
txtFieldItemName.setText((String)tblInventory.getValueAt(row, 1));
spinItemQuantity.setValue(Integer.parseInt((String)tblInventory.getValueAt(row, 2)));
}
/*
Method clearFields
Empties all the data fields
@parameters: none
@return: none
*/
private void clearFields(){
txtFieldItemID.setText("");
txtFieldItemName.setText("");
spinItemQuantity.setValue(0);
}
/*
Method clearPlacedOrder
Clears the order details in the place order section
@parameters: none
@return: none
*/
private void clearPlacedOrder(){
txtFieldOrderItemID.setText("");
radBtnCredit.setSelected(false);
radBtnCash.setSelected(false);
spinOrderQuantity.setValue(0);
}
/*
Method insertFoundID
Populates the data fields with the info of the stock item found in
the InventorySearchGUI
@parameters: ID of the found item
@return: nothing
*/
private void insertFoundID(String _foundID){
int row = 0;
boolean rowFound = false;
while(rowFound == false){
//check which row has the found item in it
if(_foundID.equalsIgnoreCase((String)tblInventory.getValueAt(row, 0))){
rowFound = true;
}else{
row++;
}
}
//Populate the fields with that row's information
populateFields(row);
}
/*
Method hasLetters
Checks if a string contains any letters
@parameters: String input string
@return: boolean true or false
*/
private boolean hasLetters(String s){
int len = s.length();
for(int i =0; i< len; i++){
//Checks for any letters
if(Character.isLetter(s.charAt(i)) == true) {
return true;
}
}
return false;
}
/*
Method selectOrder
Populates the data fields with the order that the user searched for
@parameters: ID of the order
@return nothing
*/
private void selectOrder(String ID){
try {
rs = sto.findOrder(ID);
if(rs.next()){
//populate data fields with this order
txtFieldOrderID.setText(rs.getString("orderID"));
}else{
//if resultset empty it means the order was not found
//notify the user that orderID is not correct
JOptionPane.showMessageDialog(null, "Order ID not found");
}
} catch (SQLException ex) {
Logger.getLogger(StockGUI.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(StockGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(StockGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(StockGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(StockGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new StockGUI("","").setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnBack;