Setup add projection
This commit is contained in:
parent
d215ea980b
commit
3e70d12bac
7 changed files with 124 additions and 13 deletions
|
@ -2,7 +2,6 @@ package DB;
|
|||
|
||||
import Exceptions.AlreadyOnTable;
|
||||
import Exceptions.NotFoundInTable;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
|
@ -11,6 +10,7 @@ import org.json.simple.parser.ParseException;
|
|||
import java.io.*;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.sql.*;
|
||||
import java.sql.Date;
|
||||
import java.util.*;
|
||||
|
||||
public class DB {
|
||||
|
@ -90,7 +90,7 @@ public class DB {
|
|||
returnValue = rs.getInt(value);
|
||||
else if (cl == Time.class)
|
||||
returnValue = rs.getTime(value);
|
||||
else if (cl == Data.class)
|
||||
else if (cl == Date.class)
|
||||
returnValue = rs.getDate(value);
|
||||
else if (cl == Competition.class)
|
||||
returnValue = new Competition(rs.getString(value));
|
||||
|
|
|
@ -51,7 +51,7 @@ public class Room extends Table {
|
|||
static public ArrayList<Room> getAvailable(Movie movie, Slot slot, Date date) {
|
||||
ArrayList<Room> list = new ArrayList<>();
|
||||
try {
|
||||
PreparedStatement ps = DB.getConnection().prepareStatement("SELECT R.name FROM Room R INNER JOIN CompetitionRoom CR on R.name = CR.RoomName LEFT JOIN Projection P on R.name = P.RoomName LEFT JOIN Slot S on S.id = P.SlotId WHERE CR.CompetitionName = ? AND NOT (S.id = ? AND P.startDate = ?) OR P.id IS NULL");
|
||||
PreparedStatement ps = DB.getConnection().prepareStatement("SELECT R.name FROM Room R INNER JOIN CompetitionRoom CR on R.name = CR.RoomName LEFT JOIN Projection P on R.name = P.RoomName LEFT JOIN Slot S on S.id = P.SlotId WHERE CR.CompetitionName = ? AND NOT (S.id = ? AND P.startDate = ?) OR P.id IS NULL GROUP BY R.name");
|
||||
ps.setString(1, movie.getCompetition().getName());
|
||||
ps.setInt(2, slot.getId());
|
||||
ps.setDate(3, date);
|
||||
|
|
|
@ -69,7 +69,7 @@ public class Slot extends Table {
|
|||
static public ArrayList<Slot> getAvailable(Competition competition, Date date) {
|
||||
ArrayList<Slot> list = new ArrayList<>();
|
||||
try {
|
||||
PreparedStatement ps = DB.getConnection().prepareStatement("SELECT S.id FROM Slot S LEFT JOIN Projection P ON S.id = P.SlotId WHERE S.CompetitionName = ? AND P.startDate != ? OR P.id IS NULL");
|
||||
PreparedStatement ps = DB.getConnection().prepareStatement("SELECT S.id FROM Slot S LEFT JOIN Projection P ON S.id = P.SlotId WHERE S.CompetitionName = ? AND P.id IS NULL OR P.startDate != ?");
|
||||
ps.setString(1, competition.getName());
|
||||
ps.setDate(2, date);
|
||||
for (ResultSet rs = ps.executeQuery(); rs.next();)
|
||||
|
@ -80,4 +80,9 @@ public class Slot extends Table {
|
|||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getStartTime().toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,4 +46,9 @@ public abstract class Table {
|
|||
public boolean delete() {
|
||||
return DB.delete(tableName, check, checkValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return checkValue;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="GUI.ProjectionHandler">
|
||||
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="10" left="10" bottom="10" right="10"/>
|
||||
<constraints>
|
||||
<xy x="48" y="54" width="436" height="297"/>
|
||||
|
@ -82,7 +82,7 @@
|
|||
</grid>
|
||||
<component id="6eea5" class="javax.swing.JButton" binding="cancelButton">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Cancel"/>
|
||||
|
@ -90,7 +90,7 @@
|
|||
</component>
|
||||
<component id="9b61e" class="javax.swing.JButton" binding="confirmButton">
|
||||
<constraints>
|
||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Button"/>
|
||||
|
@ -120,6 +120,30 @@
|
|||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="9763d" binding="roomPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="7c5d6" class="javax.swing.JLabel" binding="roomLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Room"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="68046" class="javax.swing.JComboBox" binding="roomComboBox">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
|
|
|
@ -1,9 +1,15 @@
|
|||
package GUI;
|
||||
|
||||
import DB.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.event.*;
|
||||
import java.sql.Date;
|
||||
import java.time.LocalDate;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ProjectionHandler extends JDialog {
|
||||
private JPanel contentPane;
|
||||
|
@ -21,6 +27,9 @@ public class ProjectionHandler extends JDialog {
|
|||
private JPanel filmPanel;
|
||||
private JLabel filmLabel;
|
||||
private JComboBox filmComboBox;
|
||||
private JPanel roomPanel;
|
||||
private JLabel roomLabel;
|
||||
private JComboBox roomComboBox;
|
||||
private ProjectionType projectionType;
|
||||
|
||||
public ProjectionHandler(ProjectionType projectionType) {
|
||||
|
@ -36,6 +45,13 @@ public class ProjectionHandler extends JDialog {
|
|||
}
|
||||
});
|
||||
setLocationRelativeTo(null);
|
||||
updateCompetitions();
|
||||
competitionComboBox.addActionListener(actionEvent -> updateMovies());
|
||||
filmComboBox.addActionListener(actionEvent -> updateDates());
|
||||
dayComboBox.addActionListener(actionEvent -> updateSlots());
|
||||
slotComboBox.addActionListener(actionEvent -> updateRooms());
|
||||
cancelButton.addActionListener(actionEvent -> dispose());
|
||||
confirmButton.addActionListener(actionEvent -> confirm());
|
||||
}
|
||||
|
||||
private void handleDialogName() {
|
||||
|
@ -59,4 +75,66 @@ public class ProjectionHandler extends JDialog {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateCompetitions() {
|
||||
ArrayList<Competition> competitions = Competition.getAll();
|
||||
if (competitions != null)
|
||||
for (Competition c : competitions)
|
||||
competitionComboBox.addItem(c);
|
||||
}
|
||||
|
||||
private void updateMovies() {
|
||||
filmComboBox.removeAllItems();
|
||||
dayComboBox.removeAllItems();
|
||||
slotComboBox.removeAllItems();
|
||||
roomComboBox.removeAllItems();
|
||||
ArrayList<Movie> movies = Movie.getAvailable((Competition) competitionComboBox.getSelectedItem());
|
||||
if (movies != null)
|
||||
for (Movie m : movies)
|
||||
filmComboBox.addItem(m);
|
||||
}
|
||||
|
||||
private void updateDates() {
|
||||
dayComboBox.removeAllItems();
|
||||
slotComboBox.removeAllItems();
|
||||
roomComboBox.removeAllItems();
|
||||
Competition competition = (Competition) competitionComboBox.getSelectedItem();
|
||||
Set<Date> dates = competition.getProjections().stream().map(p -> p.getStartDate()).collect(Collectors.toSet());
|
||||
LocalDate[] localDates = LocalDate.of(2021, 5, 11).datesUntil(LocalDate.of(2021, 5, 22)).toArray(LocalDate[]::new);
|
||||
if (competition.getDays() != 0 && dates.size() >= competition.getDays())
|
||||
localDates = dates.stream().map(Date::toLocalDate).toArray(LocalDate[]::new);
|
||||
|
||||
for (LocalDate date : localDates)
|
||||
dayComboBox.addItem(date);
|
||||
}
|
||||
|
||||
private void updateSlots() {
|
||||
slotComboBox.removeAllItems();
|
||||
roomComboBox.removeAllItems();
|
||||
if (dayComboBox.getSelectedItem() != null) {
|
||||
ArrayList<Slot> slots = Slot.getAvailable((Competition) competitionComboBox.getSelectedItem(), Date.valueOf((LocalDate) dayComboBox.getSelectedItem()));
|
||||
if (slots != null)
|
||||
for (Slot s : slots)
|
||||
slotComboBox.addItem(s);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateRooms() {
|
||||
roomComboBox.removeAllItems();
|
||||
if (dayComboBox.getSelectedItem() != null) {
|
||||
ArrayList<Room> rooms = Room.getAvailable((Movie) filmComboBox.getSelectedItem(), (Slot) slotComboBox.getSelectedItem(), Date.valueOf((LocalDate) dayComboBox.getSelectedItem()));
|
||||
if (rooms != null)
|
||||
for (Room r : rooms)
|
||||
roomComboBox.addItem(r);
|
||||
}
|
||||
}
|
||||
|
||||
private void confirm() {
|
||||
for (JComboBox comboBox : Arrays.asList(competitionComboBox, filmComboBox, dayComboBox, slotComboBox, roomComboBox))
|
||||
if (comboBox.getSelectedItem() == null)
|
||||
return;
|
||||
if (projectionType == ProjectionType.ADD)
|
||||
new Projection(Date.valueOf((LocalDate) dayComboBox.getSelectedItem()), (Competition) competitionComboBox.getSelectedItem(), (Room) roomComboBox.getSelectedItem(), (Movie) filmComboBox.getSelectedItem(), (Slot) slotComboBox.getSelectedItem());
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
package ProjectionPlanning;
|
||||
|
||||
import DB.*;
|
||||
import Exceptions.*;
|
||||
import java.sql.*;
|
||||
import GUI.GUI;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) throws AlreadyOnTable, NotFoundInTable {
|
||||
//new GUI();
|
||||
public static void main(String[] args) {
|
||||
DB.connect();
|
||||
new GUI();
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue