-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdateFacilityView.java
186 lines (142 loc) · 4.79 KB
/
UpdateFacilityView.java
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
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import Basic.Facility;
import Basic.Member;
import Basic.TimeSlot;
public class UpdateFacilityView extends JFrame{
private Admin admin;
//private AdminController controller;
private JPanel panel;
private JButton submitButton, cancelButton;
private JLabel label0, label1;
private JTextField input0, input1;
private AdminView controller;
private DataPool dp;
private JTextField facilityName;
private JTextField priceAtNonPeak;
JComboBox facilityType;
private JTextField priceAtPeak;
private JTextField capacity;
private int idToUpdate;
private Facility fToUpdate;
public UpdateFacilityView(AdminView controller, int idToUpdate){
this.idToUpdate = idToUpdate;
//
dp = new DataPool();
ArrayList<Facility> listOfAllFacilities = dp.getFacilityList();
for(Facility f: listOfAllFacilities){
if (f.getId() == this.idToUpdate) {
fToUpdate = f;
break;
}
}
ArrayList<String> listOfType = new ArrayList<String>();
listOfType.add("Restaurant");
listOfType.add("Ktv");
listOfType.add("Billiard");
listOfType.add("Bbq pit");
setBounds(100, 100, 450, 300);
this.controller=controller;
panel = new JPanel();
panel.setBorder(new EmptyBorder(5, 5, 5, 5));
panel.setLayout(null);
//panel.setLayout(null);
JLabel lblFacilityName = new JLabel("Facility Name");
lblFacilityName.setBounds(6, 31, 142, 16);
panel.add(lblFacilityName);
facilityName = new JTextField();
facilityName.setText(fToUpdate.getName());
facilityName.setBounds(193, 26, 151, 26);
panel.add(facilityName);
facilityName.setColumns(10);
JLabel lblFacility = new JLabel("Facility Type");
lblFacility.setBounds(6, 56, 117, 16);
panel.add(lblFacility);
facilityType = new JComboBox();
for(String f: listOfType){
facilityType.addItem(f);
}
facilityType.setSelectedIndex(typeToIndex(fToUpdate.getType()));
facilityType.setBounds(193, 52, 151, 27);
panel.add(facilityType);
JLabel lblSlot = new JLabel("Price at Peak");
lblSlot.setBounds(6, 84, 130, 16);
panel.add(lblSlot);
JLabel lblNumberOfPax = new JLabel("Price At Non Peak");
lblNumberOfPax.setBounds(6, 124, 142, 16);
panel.add(lblNumberOfPax);
priceAtNonPeak = new JTextField();
priceAtNonPeak.setText(""+(fToUpdate.getNonPeakPrice()));
priceAtNonPeak.setBounds(193, 119, 151, 26);
panel.add(priceAtNonPeak);
priceAtNonPeak.setColumns(10);
JButton btnSubmit = new JButton("Submit");
btnSubmit.setBounds(193, 191, 117, 29);
btnSubmit.addActionListener(new SubmitButtonListener());
panel.add(btnSubmit);
//panel.setLayout(new BoxLayout(panel,BoxLayout.Y_AXIS));
panel.setBorder(BorderFactory.createTitledBorder("Update Facility"));
//panel.setLayout(new GridLayout(3,2));
panel.setBackground(Color.white);
JButton btnCancel = new JButton("Cancel");
btnCancel.setBounds(81, 192, 100, 26);
btnCancel.addActionListener(new ButtonListener());
panel.add(btnCancel);
getContentPane().add(panel);
priceAtPeak = new JTextField();
priceAtPeak.setText(""+fToUpdate.getPeakPrice());
priceAtPeak.setBounds(193, 79, 151, 26);
panel.add(priceAtPeak);
priceAtPeak.setColumns(10);
JLabel lblCapacity = new JLabel("Capacity");
lblCapacity.setBounds(6, 161, 117, 16);
panel.add(lblCapacity);
capacity = new JTextField();
capacity.setText(""+fToUpdate.getCapacity());
capacity.setBounds(193, 153, 151, 26);
panel.add(capacity);
capacity.setColumns(10);
}
private class ButtonListener implements ActionListener{
public void actionPerformed(ActionEvent e){
controller.frameSearchFacility();
}
}
private class SubmitButtonListener implements ActionListener{
public void actionPerformed(ActionEvent e){
// try {
//runAddTransactionSQL(int member, int facility, int timeSlot, int paxCount)
String name = facilityName.getText();
String facility = (String) facilityType.getSelectedItem();
int pricePeak = Integer.parseInt(priceAtPeak.getText());
int priceNonPeak = Integer.parseInt(priceAtNonPeak.getText());
int cap = Integer.parseInt(capacity.getText());
controller.updateFacility(idToUpdate, name, facility, pricePeak, priceNonPeak, cap);
JOptionPane.showMessageDialog(panel, "Facility Updated","Information", JOptionPane.PLAIN_MESSAGE);
// } catch (CreateMemberException e1) {
// JOptionPane.showMessageDialog(panel, e1.getMessage(),"Information", JOptionPane.PLAIN_MESSAGE);
// }
}
}
public int typeToIndex(String type){
int index = 0;
switch (type){
case "Restaurant":
index = 0;
break;
case "Ktv":
index = 1;
break;
case "Billiard":
index = 2;
break;
case "Bbq pit":
index = 3;
break;
}
return index;
}
}