Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.teipir.softeng;
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.border.EmptyBorder;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.JTextField;
- import javax.swing.JPasswordField;
- import javax.swing.JButton;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import java.io.File;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.Statement;
- import javax.swing.JComboBox;
- public class Football extends JFrame {
- private JPanel contentPane;
- private JTextField nametextField;
- private JTextField surNametextField;
- private JTextField emailtextField;
- private JTextField datetextField;
- private JTextField pricetextField;
- private JTextField positiontextField;
- private JPasswordField passwordField;
- private JPasswordField confirmField;
- private JComboBox comboBox;
- private String name;
- private String surName;
- private String email;
- private String password;
- private String confirm;
- private String iD;
- private int price;
- private String [] myArray=new String[100];
- private String emails;
- private int test;
- private int totalTickets=0;
- private int availableTickets=10;
- private int totalVip;
- private int totalPrice=0;
- int index=0;
- int i=0;
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- Football frame = new Football();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- public void CheckSeats(JComboBox comboBox)
- {
- try
- {
- // Load the JDBC driver
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- String connectionUrl = "jdbc:mysql://localhost:3306/mydatabase?useSSL=false";
- String connectionUser = "root";
- String connectionPassword = "test12345";
- Connection myConn = DriverManager.getConnection(connectionUrl, connectionUser,
- connectionPassword);
- Statement myStmt=myConn.createStatement();
- String query="SELECT Status,iD FROM football1 where Status=1";
- ResultSet rs=myStmt.executeQuery(query);
- while (rs.next())
- {
- iD=rs.getString("iD");
- myArray[i]=iD;
- i++;
- index++;
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- public void GetData()
- {
- try
- {
- // Load the JDBC driver
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- String connectionUrl = "jdbc:mysql://localhost:3306/mydatabase?useSSL=false";
- String connectionUser = "root";
- String connectionPassword = "test12345";
- Connection myConn = DriverManager.getConnection(connectionUrl, connectionUser,
- connectionPassword);
- Statement myStmt=myConn.createStatement();
- String query="SELECT Status,iD,name,email,price FROM football1 where Status=0";
- ResultSet rs=myStmt.executeQuery(query);
- while (rs.next())
- {
- iD=rs.getString("iD");
- name=rs.getString("name");
- email=rs.getString("email");
- price=rs.getInt("price");
- if (price==100)
- {
- totalVip++;
- }
- totalTickets++;
- availableTickets--;
- totalPrice+=price;
- }
- if (totalPrice==0)
- {
- JOptionPane.showMessageDialog(null, "No Tickets Sold at FootballMatch 1");
- }
- else
- {
- try
- {
- File file = new File("DataFootBaLL1.txt");
- if(!file.exists())
- {
- file.createNewFile();
- }
- PrintWriter pw=new PrintWriter(file);
- pw.println("Football Statistics\n");
- pw.println("totalTickets:"+totalTickets+" totalVip Tickets:" +totalVip+" availableTickets:"+availableTickets+" totalPrice:"+totalPrice+ "\n"+"\n");
- pw.close();
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- //System.out.println("FoottBall Statistics\n");
- //System.out.println("iD:"+iD+" name:"+name+" email:"+email+ " price:"+price+ "\n");
- //System.out.println("totalTickets:"+totalTickets+" totalVip Tickets:" +totalVip+" availableTickets:"+availableTickets+" totalPrice:"+totalPrice+ "\n");
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- public int MySqlSetValues(String gName,String gSurName,String gEmail,String gPassword,String gID)
- {
- try
- {
- // Load the JDBC driver
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- String connectionUrl = "jdbc:mysql://localhost:3306/mydatabase?useSSL=false";
- String connectionUser = "root";
- String connectionPassword = "test12345";
- Connection myConn = DriverManager.getConnection(connectionUrl, connectionUser,
- connectionPassword);
- Statement myStmt=myConn.createStatement();
- String query="SELECT Status,email FROM football1 where Status=0";
- ResultSet rs=myStmt.executeQuery(query);
- while (rs.next())
- {
- emails=rs.getString("email");
- if (emails.equals(gEmail))
- {
- JOptionPane.showMessageDialog(null, "email already in use");
- return -1;
- }
- }
- String sql="UPDATE football1 SET name=? WHERE iD=?";
- PreparedStatement statement = myConn.prepareStatement(sql);
- statement.setString(1,gName);
- statement.setString(2,gID);
- String sql2="UPDATE football1 SET surName=? WHERE iD=?";
- PreparedStatement statement2 = myConn.prepareStatement(sql2);
- statement2.setString(1,gSurName);
- statement2.setString(2,gID);
- String sql3="UPDATE football1 SET password=? WHERE iD=?";
- PreparedStatement statement3 = myConn.prepareStatement(sql3);
- statement3.setString(1,gSurName);
- statement3.setString(2,gID);
- String sql4="UPDATE football1 SET email=? WHERE iD=?";
- PreparedStatement statement4 = myConn.prepareStatement(sql4);
- statement4.setString(1,gEmail);
- statement4.setString(2,gID);
- String sql5="UPDATE football1 SET Status=? WHERE iD=?";
- PreparedStatement statement5 = myConn.prepareStatement(sql5);
- statement5.setInt(1,0);
- statement5.setString(2,gID);
- statement.executeUpdate();
- statement2.executeUpdate();
- statement3.executeUpdate();
- statement4.executeUpdate();
- statement5.executeUpdate();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- return 1;
- }
- public void ClearData()
- {
- try
- {
- // Load the JDBC driver
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- String connectionUrl = "jdbc:mysql://localhost:3306/mydatabase?useSSL=false";
- String connectionUser = "root";
- String connectionPassword = "test12345";
- Connection myConn = DriverManager.getConnection(connectionUrl, connectionUser,
- connectionPassword);
- Statement myStmt=myConn.createStatement();
- String query="SELECT Status,email,name,password,surName FROM football1 where Status=0";
- ResultSet rs=myStmt.executeQuery(query);
- PreparedStatement statement;
- PreparedStatement statement2;
- PreparedStatement statement3;
- PreparedStatement statement4;
- PreparedStatement statement5;
- while (rs.next())
- {
- String sql="UPDATE football1 SET name=?";
- statement = myConn.prepareStatement(sql);
- statement.setString(1,null);
- String sql2="UPDATE football1 SET surName=?";
- statement2 = myConn.prepareStatement(sql2);
- statement2.setString(1,null);
- String sql3="UPDATE football1 SET password=?";
- statement3 = myConn.prepareStatement(sql3);
- statement3.setString(1,null);
- String sql4="UPDATE football1 SET email=?";
- statement4 = myConn.prepareStatement(sql4);
- statement4.setString(1,null);
- String sql5="UPDATE football1 SET Status=?";
- statement5 = myConn.prepareStatement(sql5);
- statement5.setInt(1,1);
- statement.executeUpdate();
- statement2.executeUpdate();
- statement3.executeUpdate();
- statement4.executeUpdate();
- statement5.executeUpdate();
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- public Football() {
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 600, 480);
- contentPane = new JPanel();
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
- JLabel namelabel = new JLabel("Όνομα");
- namelabel.setBounds(160, 11, 86, 27);
- contentPane.add(namelabel);
- JLabel surnameLabel = new JLabel("Επώνυμο");
- surnameLabel.setBounds(160, 49, 86, 27);
- contentPane.add(surnameLabel);
- JLabel emailLabel = new JLabel("email");
- emailLabel.setBounds(160, 99, 86, 27);
- contentPane.add(emailLabel);
- JLabel passwordLabel = new JLabel("Κωδικός");
- passwordLabel.setBounds(160, 149, 86, 27);
- contentPane.add(passwordLabel);
- JLabel positionLabel = new JLabel("Θέση");
- positionLabel.setBounds(160, 237, 86, 27);
- contentPane.add(positionLabel);
- JLabel priceLabel = new JLabel("Τιμή");
- priceLabel.setBounds(160, 275, 86, 27);
- contentPane.add(priceLabel);
- JLabel dateLabel = new JLabel("Ημερομηνία");
- dateLabel.setBounds(160, 313, 86, 27);
- contentPane.add(dateLabel);
- nametextField = new JTextField();
- nametextField.setColumns(10);
- nametextField.setBounds(284, 14, 126, 20);
- contentPane.add(nametextField);
- surNametextField = new JTextField();
- surNametextField.setColumns(10);
- surNametextField.setBounds(284, 52, 126, 20);
- contentPane.add(surNametextField);
- emailtextField = new JTextField();
- emailtextField.setColumns(10);
- emailtextField.setBounds(284, 102, 126, 20);
- contentPane.add(emailtextField);
- positiontextField = new JTextField();
- positiontextField.setColumns(10);
- positiontextField.setBounds(284, 240, 126, 20);
- contentPane.add(positiontextField);
- positiontextField.setEditable(false);
- pricetextField = new JTextField();
- pricetextField.setColumns(10);
- pricetextField.setBounds(284, 278, 126, 20);
- contentPane.add(pricetextField);
- pricetextField.setEditable(false);
- datetextField = new JTextField();
- datetextField.setColumns(10);
- datetextField.setBounds(284, 320, 126, 20);
- contentPane.add(datetextField);
- datetextField.setText("2/2/2018");
- datetextField.setEditable(false);
- passwordField = new JPasswordField();
- passwordField.setBounds(283, 152, 127, 20);
- contentPane.add(passwordField);
- confirmField = new JPasswordField();
- confirmField.setBounds(284, 202, 127, 20);
- contentPane.add(confirmField);
- CheckSeats(comboBox);
- JButton btnNewButton = new JButton("Καταχώρηση");
- btnNewButton.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent arg0)
- {
- name=nametextField.getText();
- surName=surNametextField.getText();
- email=emailtextField.getText();
- password=passwordField.getText();
- confirm=confirmField.getText();
- iD=positiontextField.getText();
- if (password.equals(confirm))
- {
- test=MySqlSetValues(name,surName,email,password,iD);
- if (test==1)
- {
- JOptionPane.showMessageDialog(null, "Successfully Registered");
- dispose();
- MainWindow window=new MainWindow();
- window.getFrame().setVisible(true);
- }
- }
- else
- {
- JOptionPane.showMessageDialog(null, "password does not match");
- }
- }
- });
- btnNewButton.setBounds(36, 374, 250, 40);
- contentPane.add(btnNewButton);
- JComboBox comboBox = new JComboBox();
- comboBox.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent arg0)
- {
- String value=comboBox.getSelectedItem().toString();
- positiontextField.setText(value);
- value=value.replaceAll("\\D+","");
- if(value.equals("1") || value.equals("2"))
- {
- pricetextField.setText("100");
- }
- else
- {
- pricetextField.setText("30");
- }
- }
- });
- comboBox.setBounds(10, 11, 93, 20);
- contentPane.add(comboBox);
- JButton button = new JButton("Πίσω");
- button.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent arg0)
- {
- dispose();
- FootBallMatch myFootballMatch=new FootBallMatch();
- myFootballMatch.setVisible(true);
- }
- });
- button.setBounds(309, 374, 250, 40);
- contentPane.add(button);
- JLabel label = new JLabel("Επιβεβαίωση");
- label.setBounds(160, 199, 86, 27);
- contentPane.add(label);
- for (i=0; i<index; i++)
- {
- comboBox.addItem(myArray[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement