From 793dad7f05c97e8097f298636e0e4ce9b20cfed6 Mon Sep 17 00:00:00 2001 From: Xiting Qin <13613609611@163.com> Date: Sat, 2 Apr 2022 00:13:40 +0800 Subject: [PATCH 1/2] finalfinal --- data/Seat.csv | 4 ++-- src/MainApp/pages/chooseNormalSeat.java | 27 ++++++++++++++++--------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/data/Seat.csv b/data/Seat.csv index 8a4e3fc..64d0cef 100644 --- a/data/Seat.csv +++ b/data/Seat.csv @@ -1,6 +1,6 @@ id,Interval_id,Ticket_id,price,seatClass,seatNo,type 1,1,1,400,Normal,1A,Normal -2,1,,500.0,Normal,2F,Normal +2,1,1,500.0,Normal,2F,Normal 3,1,,500.0,Normal,3A,Normal 4,1,,500.0,Normal,4A,Aside 5,1,,500.0,Normal,5A,Aside @@ -16,4 +16,4 @@ id,Interval_id,Ticket_id,price,seatClass,seatNo,type 15,1,,500.0,Normal,15A,Normal 16,1,,500.0,Normal,16A,Normal 17,1,,500.0,Normal,17A,Normal -18,1,,500.0,Normal,18A,Normal \ No newline at end of file +18,1,,500.0,Normal,18A,Normal diff --git a/src/MainApp/pages/chooseNormalSeat.java b/src/MainApp/pages/chooseNormalSeat.java index 835b1d0..d38767a 100644 --- a/src/MainApp/pages/chooseNormalSeat.java +++ b/src/MainApp/pages/chooseNormalSeat.java @@ -6,7 +6,6 @@ import java.awt.event.*; import java.util.stream.Stream; import java.awt.Font; import java.awt.*; - import MainApp.GlobalData; import MainApp.models.Models; import MainApp.models.Field.ForeignKey; @@ -14,8 +13,10 @@ import MainApp.models.Model.Exception.FieldNotFoundException; import MainApp.models.Model.Exception.ObjectNotFoundException; import MainApp.models.Model.UserModel.Interval; import MainApp.models.Model.UserModel.Seat; +import MainApp.models.Model.UserModel.Ticket; import MainApp.pages.components.BreadCrumbPanel; import MainApp.pages.components.RoundBorder; +import MainApp.pages.control.FlightInfo; import java.nio.file.Path; @@ -26,8 +27,7 @@ public class chooseNormalSeat extends JFrame{ private int windowRest = 8; private int asideRest = 0; private int extraRest = 3; - private String ticketId = "2"; - + private Ticket ticket; JFrame f = this; { getAllSeat(); @@ -36,11 +36,7 @@ public class chooseNormalSeat extends JFrame{ private JButton window = windowSeat(f); private JButton aside = asideSeat(f); private JButton extra = extraSeat(f); - - Stream seat; - private Path path = Path.of("page1/page2/page3"); - public chooseNormalSeat(){ super("Choose seat"); Pages.bindPage(this.path, this); @@ -407,6 +403,7 @@ public class chooseNormalSeat extends JFrame{ new ActionListener(){ public void actionPerformed(ActionEvent e){ if(e.getSource()==next) { + dataTransfer(); return; } } @@ -426,8 +423,9 @@ public class chooseNormalSeat extends JFrame{ extra.addActionListener(myListener); extra.addMouseListener(myListener2); } - private void getAllSeat(){ + var flightinfo = (FlightInfo)GlobalData.data.get("flight"); + ticket = flightinfo.ticket; try { var normalSeatStream = Seat.queryByProperty(Seat.class, "Interval_id", 1).filter((x)->{ return x.type.getValue().equals("Normal"); @@ -483,7 +481,8 @@ public class chooseNormalSeat extends JFrame{ var seat = seatStream.toArray(); if(seat.length != 0){ var aSeat = (Seat)seat[0]; - aSeat.ticket.setValue(ticketId); + aSeat.ticket.setValue(ticket.id); + aSeat.save(); JOptionPane.showMessageDialog(null, "Select Successfulluy!", "Success", JOptionPane.PLAIN_MESSAGE); }else{ JOptionPane.showMessageDialog(null, "Sorry, there is no seat left.\nPlease choose again.", "Error", JOptionPane.ERROR_MESSAGE); @@ -492,6 +491,16 @@ public class chooseNormalSeat extends JFrame{ e.printStackTrace(); } } + private void dataTransfer(){ + try { + var seatStream = Seat.queryByProperty(Seat.class, "Ticket_id", ticket.id).toArray(); + var seat = seatStream[0]; + GlobalData.data.put("seat",seat); + } catch (FieldNotFoundException e) { + e.printStackTrace(); + } + + } public static void main(String[] args) { GlobalData.init(); Models.init(); -- Gitee From 1b289340278c01f41dec69a54f3f681af5a72c2a Mon Sep 17 00:00:00 2001 From: Xiting Qin <13613609611@163.com> Date: Sat, 2 Apr 2022 00:55:18 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=BF=99=E6=AC=A1=E7=9C=9F=E7=9A=84?= =?UTF-8?q?=E6=98=AFfinal=E4=BA=86=E3=80=82=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/Seat.csv | 36 ++++++++++----------- src/MainApp/pages/FlightInformationFrm.java | 3 +- src/MainApp/pages/chooseNormalSeat.java | 14 ++++---- 3 files changed, 28 insertions(+), 25 deletions(-) diff --git a/data/Seat.csv b/data/Seat.csv index 64d0cef..62a42c2 100644 --- a/data/Seat.csv +++ b/data/Seat.csv @@ -1,19 +1,19 @@ id,Interval_id,Ticket_id,price,seatClass,seatNo,type -1,1,1,400,Normal,1A,Normal -2,1,1,500.0,Normal,2F,Normal -3,1,,500.0,Normal,3A,Normal -4,1,,500.0,Normal,4A,Aside -5,1,,500.0,Normal,5A,Aside -6,1,,500.0,Normal,6A,Window -7,1,,500.0,Normal,7A,Window -8,1,,500.0,Normal,8A,Window -9,1,,500.0,Normal,9A,Window -10,1,,500.0,Normal,10A,Extra -11,1,,500.0,Normal,11A,Aside -12,1,,500.0,Normal,12A,Aside -13,1,,500.0,Normal,13A,Aside -14,1,,500.0,Normal,14A,Aside -15,1,,500.0,Normal,15A,Normal -16,1,,500.0,Normal,16A,Normal -17,1,,500.0,Normal,17A,Normal -18,1,,500.0,Normal,18A,Normal +1,1,1,0,Normal,1A,Normal +2,1,1,0,Normal,2F,Normal +3,1,,0,Normal,3A,Normal +4,1,,0,Normal,4A,Aside +5,1,,0,Normal,5A,Aside +6,1,,0,Normal,6A,Window +7,1,,0,Normal,7A,Window +8,1,,0,Normal,8A,Window +9,1,,0,Normal,9A,Window +10,1,,100.0,Normal,10A,Extra +11,1,,0,Normal,11A,Aside +12,1,,0,Normal,12A,Aside +13,1,,0,Normal,13A,Aside +14,1,,0,Normal,14A,Aside +15,1,,0,Normal,15A,Normal +16,1,,0,Normal,16A,Normal +17,1,,0,Normal,17A,Normal +18,1,,0,Normal,18A,Normal diff --git a/src/MainApp/pages/FlightInformationFrm.java b/src/MainApp/pages/FlightInformationFrm.java index 7be6a8e..db258e1 100644 --- a/src/MainApp/pages/FlightInformationFrm.java +++ b/src/MainApp/pages/FlightInformationFrm.java @@ -287,6 +287,7 @@ public class FlightInformationFrm extends JFrame next.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { if(e.getSource() == next) { + GlobalData.data.put("flight",passData); new chooseNormalSeat(); try { Pages.displayPage(Path.of("page1/page2/page3")); @@ -294,7 +295,7 @@ public class FlightInformationFrm extends JFrame e1.printStackTrace(); } } - GlobalData.data.put("flight",passData); + } }); } diff --git a/src/MainApp/pages/chooseNormalSeat.java b/src/MainApp/pages/chooseNormalSeat.java index d38767a..c4e7454 100644 --- a/src/MainApp/pages/chooseNormalSeat.java +++ b/src/MainApp/pages/chooseNormalSeat.java @@ -23,10 +23,11 @@ import java.nio.file.Path; public class chooseNormalSeat extends JFrame{ public int width = 965; public int height = 550; - private int normalRest = 10; - private int windowRest = 8; + private int normalRest = 0; + private int windowRest = 0; private int asideRest = 0; - private int extraRest = 3; + private int extraRest = 0; + private double extraMoney = 0.0; private Ticket ticket; JFrame f = this; { @@ -181,12 +182,12 @@ public class chooseNormalSeat extends JFrame{ extra.setBorder(new RoundBorder(Color.GRAY)); JLabel extra_text1 = new JLabel("A Seat with", JLabel.CENTER); JLabel extra_text2 = new JLabel("Extra Space", JLabel.CENTER); - JLabel extra_money = new JLabel("$10", JLabel.CENTER); + JLabel extra_money = new JLabel("$"+extraMoney, JLabel.CENTER); JLabel extra_num1 = new JLabel("Remaining", JLabel.CENTER); JLabel extra_num2 = new JLabel(extraRest+"", JLabel.CENTER); extra_text1.setFont(new Font("Arial", Font.BOLD, 32)); extra_text2.setFont(new Font("Arial", Font.BOLD, 32)); - extra_money.setFont(new Font("Arial", Font.PLAIN, 20)); + extra_money.setFont(new Font("Arial", Font.PLAIN, 17)); extra_money.setForeground(new ColorUIResource(Color.red)); extra_num1.setFont(new Font("Microsoft YaHei UI", Font.BOLD, 17)); extra_num2.setFont(new Font("Microsoft YaHei UI", Font.BOLD, 17)); @@ -203,7 +204,7 @@ public class chooseNormalSeat extends JFrame{ extra.setBounds(715,175,195,268); extra_text1.setBounds(719,224,186,42); extra_text2.setBounds(719,266,186,42); - extra_money.setBounds(798,299,34,42); + extra_money.setBounds(780,299,60,42); extra_num1.setBounds(765,341,94,24); extra_num2.setBounds(765,365,94,24); f.add(extra); @@ -462,6 +463,7 @@ public class chooseNormalSeat extends JFrame{ return x.ticket.getValue() == null; }); var allExtraSeat = extraSeatStream.toArray(); + extraMoney = (Double)((Seat)allExtraSeat[0]).price.getValue(); extraRest = allExtraSeat.length; } catch (FieldNotFoundException e) { e.printStackTrace(); -- Gitee