-
Notifications
You must be signed in to change notification settings - Fork 0
/
GymPanel.java
91 lines (73 loc) · 2.14 KB
/
GymPanel.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
// AUTHENTICATION PANEL
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.ResultSet;
import java.sql.Statement;
public class GymPanel extends JPanel {
private JLabel greeting;
private JTextField entry;
private ResultSet possible;
private int recid = 0;
private String url;
public GymPanel(String u) {
url = u;
setLayout(new FlowLayout());
greeting = new JLabel("Welcome! Please enter your RecID:");
entry = new JTextField(3);
entry.addActionListener(new EntryListener());
add(greeting);
add(entry);
setPreferredSize(new Dimension(300, 50));
setBackground(Color.gray);
}
private class EntryListener implements ActionListener { // a RecID is entered
@Override
public void actionPerformed(ActionEvent e) {
int entryint, inst;
String text = entry.getText();
boolean isIt = false;
Connection conn = null;
entryint = Integer.parseInt(text);
try {
conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
String SQL = "SELECT * FROM receptionist";
possible = stmt.executeQuery(SQL);
isIt = false;
// checks for a match
while ((possible.next()) && (isIt == false)) {
inst = possible.getInt("recid");
if (entryint == inst) {
recid = entryint;
isIt = true;
}
}
} catch (SQLException e1) {
e1.printStackTrace();
}
if (isIt == true) {
try {
// gets the full name from the successful recid match
possible.previous();
String fname = possible.getString("fname");
String lname = possible.getString("lname");
// proceeds to the main panel
GymPOS.nextPanel(fname, lname, recid);
} catch (SQLException e1) {
e1.printStackTrace();
}
} else
JOptionPane.showMessageDialog(null, "Invalid RecID");
if (conn != null)
try {
conn.close();
} catch (SQLException e1) {
e1.printStackTrace();
}
}
}
}