-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyStatsPanel.java
More file actions
234 lines (197 loc) · 7.9 KB
/
MyStatsPanel.java
File metadata and controls
234 lines (197 loc) · 7.9 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
/* * * * * * * * * * *\
* MyStatsPanel.java
* Description: This panel is the main menu of the admin GUI, it gives an overview of what is going on in bryant place by providing
* information such as how many guests are currently in house, how many guests are staying overnight, etc. Also
* displays a pie chart showing an average of what trypes of guests are checking in (FSU, Pierpont, Other).
* Date: 4/4/16
* @author Brandon Ballard & Hanif Mirza
\* * * * * * * * * * */
import java.awt.*;
import javax.swing.*;
import static javax.swing.GroupLayout.Alignment.*;
import java.sql.*;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.data.general.DefaultPieDataset;
class MyStatsPanel extends JPanel
{
JPanel clockPanel, northPanel, statsPanel, linePanel, pieChartPanel;
JLabel numGuestsIn, numGuestsOut, checkIns, totalResidents, overnights, lineLabel, pieLabel;
Statement statement;
JComboBox reportCBox;
AdminGUI adminGUI;
String totalGuestsIn, todaysCheckIns, todaysCheckOuts, totalOvernights;
int FSU = 0, PCTC = 0, DL = 0, OTHERS = 0;
ResultSet myResultSet;
//BY BRANDON BALLARD
public MyStatsPanel(AdminGUI adminGUI,Statement statement)
{
this.adminGUI = adminGUI;
this.statement = statement;
pieChartPanel = createPieChartPanel();
pieChartPanel.setBackground(Color.GRAY);
pieChartPanel.setPreferredSize(new Dimension(550, 260));
northPanel = new JPanel(new FlowLayout());
northPanel.setBackground(Color.GRAY);
clockPanel = new MyClock("Advanced");
northPanel.add(clockPanel);
statsPanel = setFields();
add(northPanel, BorderLayout.NORTH);
add(statsPanel, BorderLayout.CENTER);
add(pieChartPanel, BorderLayout.SOUTH);
setUpGUI();
}
// Written by Hanif Mirza, this function will return a pie chart panel with different guest ID types number
JPanel createPieChartPanel()
{
getIDTypesInfo();
DefaultPieDataset dataset = new DefaultPieDataset( );
dataset.setValue( "FSU" , new Double( FSU ) ); // set the value with number of FSU IDs
dataset.setValue( "PCTC" , new Double( PCTC ) ); // set the value with number of PCTC IDs
dataset.setValue( "Driving License" , new Double( DL ) );// set the value with number of Driving License IDs
dataset.setValue( "Other" , new Double( OTHERS ) );// set the value with number of IDs in other category
JFreeChart chart = ChartFactory.createPieChart3D("Guest ID Types",dataset,true,true,false);
return new ChartPanel( chart );
}
//Adds the text that displays information about the resident hall, BY BRANDON BALLARD
JPanel setFields()
{
getDatabaseInfo();
GroupLayout layout;
JPanel p;
numGuestsIn = new JLabel("Total guests in house .............................");
numGuestsIn.setFont(new Font("Courier New", Font.PLAIN,20));
numGuestsIn.setForeground(Color.WHITE);
checkIns = new JLabel("Todays guest check ins ............................");
checkIns.setForeground(Color.WHITE);
checkIns.setFont(new Font("Courier New", Font.PLAIN,20));
numGuestsOut = new JLabel("Todays guest check outs ...........................");
numGuestsOut.setFont(new Font("Courier New", Font.PLAIN,20));
numGuestsOut.setForeground(Color.WHITE);
overnights = new JLabel("Total overnight guests ............................");
overnights.setForeground(Color.WHITE);
overnights.setFont(new Font("Courier New", Font.PLAIN,20));
JLabel n1 = new JLabel(totalGuestsIn);
n1.setForeground(Color.WHITE);
n1.setFont(new Font("Courier New", Font.PLAIN,20));
JLabel n2 = new JLabel(todaysCheckIns);
n2.setForeground(Color.WHITE);
n2.setFont(new Font("Courier New", Font.PLAIN,20));
JLabel n3 = new JLabel(todaysCheckOuts);
n3.setForeground(Color.WHITE);
n3.setFont(new Font("Courier New", Font.PLAIN,20));
JLabel n4 = new JLabel(totalOvernights);
n4.setForeground(Color.WHITE);
n4.setFont(new Font("Courier New", Font.PLAIN,20));
p = new JPanel();
p.setBackground(Color.GRAY);
layout = new GroupLayout(p);
p.setLayout(layout);
layout.setAutoCreateGaps(true);
layout.setAutoCreateContainerGaps(true);
GroupLayout.SequentialGroup hGroup = layout.createSequentialGroup();
hGroup.addGroup(layout.createParallelGroup().addComponent(numGuestsIn)
.addComponent(checkIns).addComponent(numGuestsOut).addComponent(overnights));
hGroup.addGroup(layout.createParallelGroup().addComponent(n1)
.addComponent(n2).addComponent(n3).addComponent(n4));
layout.setHorizontalGroup(hGroup);
GroupLayout.SequentialGroup vGroup = layout.createSequentialGroup();
vGroup.addGroup(layout.createParallelGroup(BASELINE).addComponent(numGuestsIn).addComponent(n1));
vGroup.addGroup(layout.createParallelGroup(BASELINE).addComponent(checkIns).addComponent(n2));
vGroup.addGroup(layout.createParallelGroup(BASELINE).addComponent(numGuestsOut).addComponent(n3));
vGroup.addGroup(layout.createParallelGroup(BASELINE).addComponent(overnights).addComponent(n4));
layout.setVerticalGroup(vGroup);
return(p);
}
// Written by Hanif Mirza, this function will access the database to count the number of FSU, PCTC, DL and Others ID types
void getIDTypesInfo()
{
try
{
String SQL_Query = " Select count(*)"
+ " From Visitation_Detail v"
+ " Where v.guest_ID_type = 'FSU' " ;
myResultSet = statement.executeQuery(SQL_Query);
myResultSet.first();
FSU = myResultSet.getInt(1);
myResultSet.close();
SQL_Query = " Select count(*)"
+ " From Visitation_Detail v"
+ " Where v.guest_ID_type = 'PCTC' " ;
myResultSet = statement.executeQuery(SQL_Query);
myResultSet.first();
PCTC = myResultSet.getInt(1);
myResultSet.close();
SQL_Query = " Select count(*)"
+ " From Visitation_Detail v"
+ " Where v.guest_ID_type = 'DL' " ;
myResultSet = statement.executeQuery(SQL_Query);
myResultSet.first();
DL = myResultSet.getInt(1);
myResultSet.close();
SQL_Query = " Select count(*)"
+ " From Visitation_Detail v"
+ " Where v.guest_ID_type = 'Other' " ;
myResultSet = statement.executeQuery(SQL_Query);
myResultSet.first();
OTHERS = myResultSet.getInt(1);
myResultSet.close();
}
catch ( SQLException sqlException )
{
JOptionPane.showMessageDialog(this, sqlException.getMessage());
}
catch ( Exception exception )
{
JOptionPane.showMessageDialog(this, exception.getMessage());
}
}
// Written by Hanif Mirza, this function will access the database to get different statistical informations about the visitation details
void getDatabaseInfo()
{
try
{
String SQL_Query = " Select count(*)"
+ " From Visitation_Detail v"
+ " Where v.time_out is null " ;
myResultSet = statement.executeQuery(SQL_Query);
myResultSet.first();
totalGuestsIn = myResultSet.getInt(1) + "";
myResultSet.close();
SQL_Query = " Select count(*)"
+ " From Visitation_Detail v"
+ " Where v.visitation_date = curdate() " ;
myResultSet = statement.executeQuery(SQL_Query);
myResultSet.first();
todaysCheckIns = myResultSet.getInt(1) + "";
myResultSet.close();
SQL_Query = " Select count(*)"
+ " From Visitation_Detail v"
+ " Where v.visitation_date = curdate() and v.time_out is not null " ;
myResultSet = statement.executeQuery(SQL_Query);
myResultSet.first();
todaysCheckOuts = myResultSet.getInt(1) + "";
myResultSet.close();
SQL_Query = " Select count(*)"
+ " From Visitation_Detail v"
+ " Where v.time_out is null and v.overnight_status = 'Yes' " ;
myResultSet = statement.executeQuery(SQL_Query);
myResultSet.first();
totalOvernights = myResultSet.getInt(1) + "";
myResultSet.close();
}
catch ( SQLException sqlException )
{
JOptionPane.showMessageDialog(this, sqlException.getMessage());
}
catch ( Exception exception )
{
JOptionPane.showMessageDialog(this, exception.getMessage());
}
}
public void setUpGUI()
{
setBackground(Color.LIGHT_GRAY);
}
}