From 45c7e62bd8c1aade1899372caad13fd0b8916917 Mon Sep 17 00:00:00 2001 From: Tergel TSAGAAN Date: Mon, 11 Jan 2021 17:56:40 +0100 Subject: [PATCH] Update row header text to slot times Fix movie that appear in wrong slot --- src/main/java/DB/Slot.java | 18 ++++++++++++++++-- src/main/java/GUI/Agenda/Agenda.java | 14 +++++++------- src/main/java/GUI/GUI.java | 10 ++++++---- src/main/java/GUI/Types/CompetType.java | 18 ++++++++++++------ 4 files changed, 41 insertions(+), 19 deletions(-) diff --git a/src/main/java/DB/Slot.java b/src/main/java/DB/Slot.java index 1a4d974..2235cfd 100644 --- a/src/main/java/DB/Slot.java +++ b/src/main/java/DB/Slot.java @@ -57,7 +57,21 @@ public class Slot extends Table { ArrayList list = new ArrayList<>(); try { PreparedStatement ps = DB.getConnection().prepareStatement("SELECT id FROM Slot"); - for (ResultSet rs = ps.executeQuery(); rs.next();) + for (ResultSet rs = ps.executeQuery(); rs.next(); ) + list.add(new Slot(rs.getInt("id"))); + ps.close(); + } catch (SQLException | NullPointerException | NotFoundInTable e) { + return null; + } + return list; + } + + static public ArrayList getAll(Competition competition) { + ArrayList list = new ArrayList<>(); + try { + PreparedStatement ps = DB.getConnection().prepareStatement("SELECT id FROM Slot WHERE CompetitionName = ?"); + ps.setString(1, competition.getName()); + for (ResultSet rs = ps.executeQuery(); rs.next(); ) list.add(new Slot(rs.getInt("id"))); ps.close(); } catch (SQLException | NullPointerException | NotFoundInTable e) { @@ -72,7 +86,7 @@ public class Slot extends Table { PreparedStatement ps = DB.getConnection().prepareStatement("SELECT S.id FROM Slot S INNER JOIN Projection P on S.id = P.SlotId WHERE S.CompetitionName = ? AND P.startDate = ? GROUP BY S.id"); ps.setString(1, competition.getName()); ps.setDate(2, date); - for (ResultSet rs = ps.executeQuery(); rs.next();) + for (ResultSet rs = ps.executeQuery(); rs.next(); ) list.add(new Slot(rs.getInt("id"))); ps.close(); } catch (SQLException | NullPointerException | NotFoundInTable e) { diff --git a/src/main/java/GUI/Agenda/Agenda.java b/src/main/java/GUI/Agenda/Agenda.java index b72229c..337eda3 100644 --- a/src/main/java/GUI/Agenda/Agenda.java +++ b/src/main/java/GUI/Agenda/Agenda.java @@ -2,6 +2,7 @@ package GUI.Agenda; import DB.Competition; import DB.Projection; +import DB.Slot; import Exceptions.ProjectionNotSpecified; import GUI.ProjectionHandler; import GUI.Types.CompetType; @@ -19,16 +20,17 @@ import java.util.Arrays; public class Agenda extends JPanel { private JPanel agendaPanel; - private String headers[]; + private Object headers[]; private int totalDay; private int currentPage; private JTable table; private CompetType competionType; private Agenda agenda; - + private ArrayList slots; public Agenda(JPanel agendaPanel, int currentPage, CompetType competionType) { this.agendaPanel = agendaPanel; - this.headers = competionType.getHeaders(); + this.slots = competionType.getSlots(); + this.headers = slots.toArray(); this.totalDay = 11; this.currentPage = currentPage; this.competionType = competionType; @@ -178,12 +180,10 @@ public class Agenda extends JPanel { private void addMovie(Projection projection) { Date startDate = projection.getStartDate(); Time time = projection.getSlot().getStartTime(); - String movieName = projection.getMovie().getName(); int column = this.table.getColumn(startDate.toString()).getModelIndex(); int row = 0; - String times[] = {"08:30:00", "11:30:00", "15:00:00", "18:00:00", "21:00:00"}; - for (int i = 0; i < times.length; i++) { - if (times[i].equals(time.toString())) { + for (int i = 0; i < slots.size(); i++) { + if (slots.get(i).getStartTime().toString().equals(time.toString())) { row = i; break; } diff --git a/src/main/java/GUI/GUI.java b/src/main/java/GUI/GUI.java index 6417f6f..4d4d07a 100644 --- a/src/main/java/GUI/GUI.java +++ b/src/main/java/GUI/GUI.java @@ -1,5 +1,6 @@ package GUI; +import DB.Slot; import GUI.Agenda.Agenda; import GUI.Types.CompetType; import GUI.Types.ProjectionType; @@ -7,6 +8,7 @@ import GUI.Types.ProjectionType; import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.util.ArrayList; public class GUI extends JFrame implements ActionListener { private JPanel mainPanel; @@ -23,7 +25,7 @@ public class GUI extends JFrame implements ActionListener { private JMenuItem menuItemRemoveProj = new JMenuItem("Remove projection"); private int currentPage; private Agenda agenda; - String headers[] = {"Matin", "Midi", "Milieu
Après-midi", "Fin
Après-midi", "Soirée"}; + private ArrayList slots = new ArrayList(); private CompetType currentCompetition = CompetType.LM; public GUI() { @@ -61,6 +63,9 @@ public class GUI extends JFrame implements ActionListener { setVisible(true); } + private void switchCompetition(CompetType competType) { + } + @Override public void actionPerformed(ActionEvent e) { Object source = e.getSource(); @@ -79,19 +84,16 @@ public class GUI extends JFrame implements ActionListener { this.revalidate(); } else if (source == LMButton) { this.currentCompetition = CompetType.LM; - this.headers = new String[]{"Matin", "Midi", "Milieu
Après-midi", "Fin
Après-midi", "Soirée"}; this.agenda = new Agenda(agendaPanel, 0, this.currentCompetition); this.repaint(); this.revalidate(); } else if (source == HCButton) { - this.headers = new String[]{"Fin
Matinée", "Fin
Après-midi", "Soirée"}; this.currentCompetition = CompetType.HC; this.agenda = new Agenda(agendaPanel, 0, this.currentCompetition); this.repaint(); this.revalidate(); } else if (source == UCRButton) { this.currentCompetition = CompetType.UCR; - this.headers = new String[]{"Matin", "Midi", "Milieu
Après-midi", "Fin
Après-midi", "Soirée"}; this.agenda = new Agenda(agendaPanel, 0, this.currentCompetition); this.repaint(); this.revalidate(); diff --git a/src/main/java/GUI/Types/CompetType.java b/src/main/java/GUI/Types/CompetType.java index aefc382..12567e0 100644 --- a/src/main/java/GUI/Types/CompetType.java +++ b/src/main/java/GUI/Types/CompetType.java @@ -1,5 +1,11 @@ package GUI.Types; +import DB.Competition; +import DB.Slot; +import Exceptions.NotFoundInTable; + +import java.util.ArrayList; + public enum CompetType { LM("Long Métrage"), UCR("Un Certain Regard"), @@ -10,13 +16,13 @@ public enum CompetType { this.competition = competition; } - public String[] getHeaders() { - if (this.competition.equals("Long Métrage") || this.competition.equals("Un Certain Regard")) { - return new String[]{"Matin", "Midi", "Milieu
Après-midi", "Fin
Après-midi", "Soirée"}; - } else if (this.competition.equals("Hors Compétition")) { - return new String[]{"Fin
Matinée", "Fin
Après-midi", "Soirée"}; + public ArrayList getSlots() { + try { + return Slot.getAll(new Competition(competition)); + } catch (NotFoundInTable notFoundInTable) { + notFoundInTable.printStackTrace(); } - return new String[0]; + return null; } public String getCompetition() {