diff --git a/DEV 3.1/Victoire/RefreshListener.class b/DEV 3.1/Victoire/RefreshListener.class new file mode 100644 index 0000000..3de3218 Binary files /dev/null and b/DEV 3.1/Victoire/RefreshListener.class differ diff --git a/DEV 3.1/Victoire/RefreshListener.java b/DEV 3.1/Victoire/RefreshListener.java new file mode 100644 index 0000000..722071b --- /dev/null +++ b/DEV 3.1/Victoire/RefreshListener.java @@ -0,0 +1,56 @@ +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import java.sql.*; + +public class RefreshListener implements ActionListener { + public RefreshListener() { + try { + Class.forName("org.mariadb.jdbc.Driver"); + } catch (ClassNotFoundException ex) { + System.err.println("MariaDB driver not found"); + return; + } + + Connection cnx; + try { + cnx = DriverManager.getConnection("jdbc:mariadb://dwarves.iut-fbleau.fr/horville", "horville", "a5gc95"); + } catch (SQLException ex) { + System.err.println("Unable to access Database."); + return; + } + + try { + PreparedStatement req = cnx.prepareStatement("SELECT Competiteur, SUM(Points) FROM Vote GROUP BY Competiteur;"); + req.executeUpdate(); + + int maxPoints = 0; + String country; + ResultSet rs = req.executeQuery(); + while (rs.next()) { + int score = rs.getInt(2); + if (score > maxPoints) { + country = rs.getString(1); + maxPoints = score; + } + } + + rs.close(); + req.close(); + + } catch (SQLException ex) { + System.err.println("SQL Request exception."); + System.err.println (ex); + } + + try { + cnx.close(); + } catch (SQLException ex) { + System.err.println("Unable to close connection."); + } + } + + public void actionPerformed(ActionEvent e) { + Victoire.refresh(); + } +} diff --git a/DEV 3.1/Victoire/Victoire.class b/DEV 3.1/Victoire/Victoire.class new file mode 100644 index 0000000..4ef2794 Binary files /dev/null and b/DEV 3.1/Victoire/Victoire.class differ diff --git a/DEV 3.1/Victoire/Victoire.java b/DEV 3.1/Victoire/Victoire.java new file mode 100644 index 0000000..c95cff4 --- /dev/null +++ b/DEV 3.1/Victoire/Victoire.java @@ -0,0 +1,33 @@ +import java.sql.*; +import javax.swing.*; +import java.awt.*; + +public class Victoire { + + public static JLabel scoreLabel; + public static JLabel countryLabel; + + public static void refresh() { + + } + + public static void main(String[] args) { + JFrame window = new JFrame("Victoire"); + window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + window.setSize(300, 300); + window.setLocation(200, 200); + + JButton refreshBT = new JButton("⟳"); + refreshBT.addActionListener(new RefreshListener()); + window.add(refreshBT, BorderLayout.SOUTH); + window.setVisible(true); + + countryLabel = new JLabel("...", JLabel.CENTER); + scoreLabel = new JLabel("0", JLabel.CENTER); + + window.add(countryLabel, BorderLayout.NORTH); + window.add(scoreLabel, BorderLayout.CENTER); + + Victoire.refresh(); + } +} \ No newline at end of file diff --git a/DEV 3.1/Vote/Vote.class b/DEV 3.1/Vote/Vote.class new file mode 100644 index 0000000..8534ac6 Binary files /dev/null and b/DEV 3.1/Vote/Vote.class differ diff --git a/DEV 3.1/Vote/Vote.java b/DEV 3.1/Vote/Vote.java new file mode 100644 index 0000000..11cade7 --- /dev/null +++ b/DEV 3.1/Vote/Vote.java @@ -0,0 +1,58 @@ +import java.sql.*; + +public class Vote { + public static void main(String[] args) { + if (args.length < 1) { + System.err.println("No country given."); + return; + } + + try { + Class.forName("org.mariadb.jdbc.Driver"); + } catch (ClassNotFoundException ex) { + System.err.println("MariaDB driver not found"); + return; + } + + Connection cnx; + try { + cnx = DriverManager.getConnection("jdbc:mariadb://dwarves.iut-fbleau.fr/horville", "horville", "a5gc95"); + } catch (SQLException ex) { + System.err.println("Unable to access Database."); + return; + } + + try { + PreparedStatement req = cnx.prepareStatement("SELECT Votants, Points FROM Vote WHERE Competiteur = (?);"); + req.setString(1, args[0]); + req.executeUpdate(); + + int total = 0; + ResultSet rs = req.executeQuery(); + while (rs.next()) { + String country = rs.getString(1); + int score = rs.getInt(2); + + total += score; + + System.out.println(country + " " + score); + } + + System.out.println(" ---"); + System.out.println("Total " + total); + + rs.close(); + req.close(); + + } catch (SQLException ex) { + System.err.println("SQL Request exception."); + System.err.println (ex); + } + + try { + cnx.close(); + } catch (SQLException ex) { + System.err.println("Unable to close connection."); + } + } +} \ No newline at end of file