1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package Controllers;
21
22 import Utilities.Order;
23 import Utilities.Year;
24 import Utilities.formattedProduct;
25 import Utilities.formattedProductProps;
26 import javafx.collections.FXCollections;
27 import javafx.collections.ObservableList;
28 import javafx.event.ActionEvent;
29 import javafx.fxml.FXML;
30 import javafx.scene.control.Label;
31 import javafx.scene.control.TableColumn;
32 import javafx.scene.control.TableView;
33 import javafx.scene.control.cell.PropertyValueFactory;
34 import javafx.scene.layout.VBox;
35
36 import java.util.ArrayList;
37 import java.util.List;
38 import java.util.Objects;
39
40
41 @SuppressWarnings("WeakerAccess")
42
43 public class YearController {
44
45 public static String year = "2017";
46 @FXML
47 private TableView yearOrders;
48 @FXML
49 private VBox yearInfo;
50 private Boolean columnsFilled = false;
51 private String uName;
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75 public void initYear(String Years) {
76 this.initYear(Years, "");
77 }
78
79
80
81
82 public void initYear(String Years, String userName) {
83 year = Years;
84 uName = userName;
85 Year yearDbInfo = new Year(year, userName);
86 yearInfo.getChildren().removeAll();
87
88
89 VBox East = new VBox();
90 List<infoValPair> yearInfoStrings = new ArrayList<>();
91 yearInfoStrings.add(new infoValPair("Customers", Integer.toString(yearDbInfo.getNoCustomers())));
92
93
94
95
96 yearInfoStrings.add(new infoValPair("Order Total", yearDbInfo.getOT().toPlainString()));
97 yearInfoStrings.add(new infoValPair("Donations", yearDbInfo.getDonations().toPlainString()));
98 yearInfoStrings.add(new infoValPair("Grand Total", yearDbInfo.getGTot().toPlainString()));
99 yearInfoStrings.add(new infoValPair("Commission", yearDbInfo.getCommis().toPlainString()));
100
101
102 yearInfoStrings.forEach((pair) -> {
103 Label keyLabel = new Label(pair.info + ":");
104 Label valLabel = new Label(pair.value);
105 keyLabel.setId("YearDescription");
106 valLabel.setId("YearValue");
107 VBox info = new VBox(keyLabel, valLabel);
108 info.getStyleClass().add("informationPane");
109 yearInfo.getChildren().add(info);
110 });
111
112
113 fillTable();
114 }
115
116 public void initialize() {
117
118 }
119
120 @FXML
121 public void refresh(ActionEvent event) {
122 initialize();
123 }
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141 private void fillTable() {
142 Order.orderArray order;
143 if (Objects.equals(uName, "")) {
144 order = Order.createOrderArray(year, "");
145
146 } else {
147 order = Order.createOrderArray(year, uName);
148
149 }
150 ObservableList<formattedProductProps> data = FXCollections.observableArrayList();
151
152 int i = 0;
153 for (formattedProduct productOrder : order.orderData) {
154
155 formattedProductProps prodProps = new formattedProductProps(productOrder.productKey, productOrder.productID, productOrder.productName, productOrder.productSize, productOrder.productUnitPrice, productOrder.productCategory, productOrder.orderedQuantity, productOrder.extendedCost);
156 data.add(prodProps);
157 i++;
158 }
159 if (!columnsFilled) {
160 String[][] columnNames = {{"Item", "productName"}, {"Size", "productSize"}, {"Price/Item", "productUnitPrice"}, {"Quantity", "orderedQuantity"}, {"Price", "extendedCost"}};
161 for (String[] column : columnNames) {
162 TableColumn<formattedProductProps, String> tbCol = new TableColumn<>(column[0]);
163 tbCol.setCellValueFactory(new PropertyValueFactory<>(column[1]));
164 yearOrders.getColumns().add(tbCol);
165 }
166 }
167 columnsFilled = true;
168
169
170 yearOrders.setItems(data);
171 yearOrders.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
172 }
173
174 private class infoValPair {
175 public String info;
176 public String value;
177
178 public infoValPair(String inf, String val) {
179 this.info = inf;
180 this.value = val;
181 }
182 }
183
184 }
185