197 lines
5.8 KiB
Java
197 lines
5.8 KiB
Java
import javax.swing.JButton;
|
|
import javax.swing.JFrame;
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JOptionPane;
|
|
import java.awt.event.ActionListener;
|
|
import java.awt.event.ActionEvent;
|
|
import javax.swing.JPasswordField;
|
|
import javax.swing.JTextField;
|
|
import java.awt.event.FocusAdapter;
|
|
import java.awt.event.FocusEvent;
|
|
import java.awt.*;
|
|
import javax.swing.SwingConstants;
|
|
import java.sql.Connection;
|
|
import java.sql.PreparedStatement;
|
|
import java.sql.ResultSet;
|
|
import javax.swing.ImageIcon;
|
|
import gnu.io.CommPortIdentifier;
|
|
import java.util.Enumeration;
|
|
|
|
|
|
public class StolowkaZPM {
|
|
|
|
private JFrame frmStolowkaZpm;
|
|
private JLabel lblNewLabel;
|
|
protected String Dalej;
|
|
protected String imie;
|
|
protected static int IDuzytkownika;
|
|
|
|
public void list() {
|
|
@SuppressWarnings("rawtypes")
|
|
Enumeration ports = CommPortIdentifier.getPortIdentifiers();
|
|
|
|
while(ports.hasMoreElements())
|
|
System.out.println(((CommPortIdentifier)ports.nextElement()).getName());
|
|
}
|
|
|
|
/**
|
|
* Launch the application.
|
|
*/
|
|
public static void main(String[] args) {
|
|
new StolowkaZPM().list();
|
|
EventQueue.invokeLater(new Runnable() {
|
|
public void run() {
|
|
try {
|
|
//DrukujBilet one = new DrukujBilet();
|
|
//one.setName(IDuzytkownika);
|
|
StolowkaZPM window = new StolowkaZPM();
|
|
window.frmStolowkaZpm.setVisible(true);
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
|
|
Connection conn=null;
|
|
|
|
|
|
public StolowkaZPM() {
|
|
initialize1();
|
|
}
|
|
|
|
private void initialize1() {
|
|
|
|
//**************************************
|
|
conn=SQLiteConnection.dbConnector();
|
|
//**************************************
|
|
frmStolowkaZpm = new JFrame();
|
|
frmStolowkaZpm.addFocusListener(new FocusAdapter() {
|
|
@Override
|
|
public void focusGained(FocusEvent arg0) {
|
|
}
|
|
});
|
|
|
|
|
|
|
|
frmStolowkaZpm.setTitle("Sto\u0142\u00F3wka ZPM");
|
|
frmStolowkaZpm.setBounds(1, 1, 499, 356);
|
|
frmStolowkaZpm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
frmStolowkaZpm.getContentPane().setLayout(new GridLayout(0, 1, 0, 0));
|
|
frmStolowkaZpm.setResizable(false);
|
|
Toolkit tk = Toolkit.getDefaultToolkit();
|
|
int xsize = (int) tk.getScreenSize().getWidth();
|
|
int ysize = (int) tk.getScreenSize().getHeight();
|
|
frmStolowkaZpm.setSize(xsize, ysize);
|
|
|
|
JLabel lblNewLabel_1 = new JLabel("");
|
|
lblNewLabel_1.setHorizontalAlignment(SwingConstants.CENTER);
|
|
lblNewLabel_1.setIcon(new ImageIcon("C:\\myGo\\icon.png"));
|
|
frmStolowkaZpm.getContentPane().add(lblNewLabel_1);
|
|
|
|
|
|
lblNewLabel = new JLabel("\"Sto\u0142\u00F3wka ZPM\"");
|
|
lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 70));
|
|
lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
|
frmStolowkaZpm.getContentPane().add(lblNewLabel);
|
|
|
|
JLabel lblZbliKartDo = new JLabel("Zbli\u017C kart\u0119 do czytnika RFID");
|
|
lblZbliKartDo.setHorizontalAlignment(SwingConstants.CENTER);
|
|
frmStolowkaZpm.getContentPane().add(lblZbliKartDo);
|
|
lblZbliKartDo.setFont(new Font("Tahoma", Font.PLAIN, 40));
|
|
|
|
JTextField rfidView = new JTextField();
|
|
rfidView.setHorizontalAlignment(SwingConstants.CENTER);
|
|
frmStolowkaZpm.getContentPane().add(rfidView);
|
|
rfidView.setFont(new Font("Tahoma", Font.PLAIN, 50));
|
|
rfidView.setToolTipText("numer karty");
|
|
|
|
JLabel podajPINlabel = new JLabel("PODAJ PIN (4 CYFRY)");
|
|
podajPINlabel.setHorizontalAlignment(SwingConstants.CENTER);
|
|
frmStolowkaZpm.getContentPane().add(podajPINlabel);
|
|
podajPINlabel.setFont(new Font("Tahoma", Font.PLAIN, 40));
|
|
|
|
JPasswordField pinView = new JPasswordField();
|
|
pinView.setHorizontalAlignment(SwingConstants.CENTER);
|
|
frmStolowkaZpm.getContentPane().add(pinView);
|
|
pinView.setFont(new Font("Tahoma", Font.PLAIN, 50));
|
|
pinView.setToolTipText("PIN");
|
|
|
|
JButton btnZaloguj = new JButton("Zaloguj");
|
|
btnZaloguj.setBackground(Color.GREEN);
|
|
btnZaloguj.setFont(new Font("Tahoma", Font.PLAIN, 50));
|
|
btnZaloguj.setBounds(724, 298, 213, 69);
|
|
frmStolowkaZpm.getContentPane().add(btnZaloguj);
|
|
|
|
JLabel lblNewLabel_2 = new JLabel("");
|
|
frmStolowkaZpm.getContentPane().add(lblNewLabel_2);
|
|
|
|
rfidView.addActionListener(new ActionListener() {
|
|
@SuppressWarnings("deprecation")
|
|
public void actionPerformed(ActionEvent e) {
|
|
//String RFIDfromApp = rfidView.getText();
|
|
//**************************************
|
|
try {
|
|
|
|
String query = "SELECT * FROM users WHERE RFID=? AND Blokada=?";
|
|
PreparedStatement pst = conn.prepareStatement(query);
|
|
pst.setString(1, rfidView.getText());
|
|
pst.setString(2, "false");
|
|
ResultSet rFID = pst.executeQuery();
|
|
String Dalej = rFID.getString("PIN");
|
|
imie = rFID.getString("User");
|
|
IDuzytkownika = rFID.getInt("IDusers");
|
|
|
|
//JOptionPane.showMessageDialog(null, IDuzytkownika);
|
|
int count = 0;
|
|
while (rFID.next()) {
|
|
count=count+1;
|
|
}
|
|
if (count == 1) {
|
|
|
|
rfidView.setText(imie);
|
|
|
|
btnZaloguj.addActionListener(new ActionListener() {
|
|
@SuppressWarnings("deprecation")
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
try {
|
|
String Dalej1 = pinView.getText();
|
|
|
|
rfidView.setText("");
|
|
pinView.setText("");
|
|
|
|
if(Dalej.equals(Dalej1)){
|
|
|
|
rFID.close();
|
|
pst.close();
|
|
DrukujBilet wybierzMenu = new DrukujBilet();
|
|
wybierzMenu.oknoDrukujBilet();
|
|
|
|
}else{
|
|
|
|
}
|
|
} catch (Exception e1){
|
|
JOptionPane.showMessageDialog(null, e1);
|
|
pinView.setText("");
|
|
}
|
|
|
|
}});
|
|
|
|
} else {
|
|
rfidView.setText("");
|
|
pinView.setText("");
|
|
//JOptionPane.showMessageDialog(frmStolowkaZpm, "NIE Zalogowano!");
|
|
}
|
|
rFID.close();
|
|
pst.close();
|
|
|
|
} catch (Exception e1){
|
|
//JOptionPane.showMessageDialog(null, e1);
|
|
rfidView.setText("");
|
|
}
|
|
}});
|
|
}
|
|
} |