Système de réservation

  1. /*
  2.  * SelectPanel.java
  3.  * The package panels contains the different class executing the different windows of each function of the FlightSystem Reservation.
  4.  */
  5. package reservation.system.panels;
  6.  
  7. import reservation.system.functions.Functions;
  8. import reservation.system.Profile;
  9. import reservation.system.Flight;
  10. import reservation.system.Person;
  11. import reservation.system.Pos;
  12. import reservation.CustomDialog;
  13.  
  14. import javax.swing.*;
  15. import javax.swing.border.*;
  16. import javax.swing.table.*;
  17. import java.awt.event.*;
  18. import java.util.Vector;
  19. import java.awt.Dimension;
  20. import java.util.StringTokenizer;
  21.  
  22. /**
  23.  * This class hold Select structure. This object allows to see the persons who have got a same bookingNumber or the persons present in a same flight.
  24.  * It use a GUI that contains a form with the several field to fill.
  25.  * @author Texier Mathieu and Frederic Bidon
  26.  */
  27. public class SelectPanel extends Panels {
  28.    
  29.     /** Creates new form SelectPanel */
  30.     public SelectPanel() {
  31.         flightSelect = new JComboBox();
  32.         bookingSelect = new JComboBox();
  33.         personNameInput = new JTextField();
  34.         colInput = new JTextField();
  35.         flightLabel = new JLabel();
  36.         personNameLabel = new JLabel();
  37.         bookingLabel = new JLabel();
  38.         colLabel = new JLabel();
  39.         rowLabel = new JLabel();
  40.         rowInput = new JTextField();
  41.         searchButton = new JButton();
  42.         jScrollPane = new JScrollPane();
  43.         bookingTable = new JTable();
  44.        
  45.         add(flightSelect);
  46.         add(bookingSelect);
  47.         add(personNameInput);
  48.         add(colInput);
  49.        
  50.         flightLabel.setText("Flight");
  51.         add(flightLabel);
  52.        
  53.         personNameLabel.setText("Person");
  54.         add(personNameLabel);
  55.        
  56.         bookingLabel.setText("Booking");
  57.         add(bookingLabel);
  58.        
  59.         colLabel.setText("Seat col");
  60.         add(colLabel);
  61.        
  62.         rowLabel.setText("row");
  63.         add(rowLabel);
  64.        
  65.         add(rowInput);
  66.        
  67.         searchButton.setText("Search");
  68.         searchButton.addActionListener(new ActionListener() {
  69.             public void actionPerformed(ActionEvent evt) {
  70.                 searchAction(evt);
  71.             }
  72.         });
  73.         add(searchButton);
  74.        
  75.         jScrollPane.setBorder(new SoftBevelBorder(BevelBorder.RAISED));
  76.         bookingTable.setRowSelectionAllowed(false);
  77.         jScrollPane.setViewportView(bookingTable);
  78.        
  79.         add(jScrollPane);
  80.     }
  81.    
  82.     /**
  83.      * Create the button of validation to search in the database the persons who have the same bookingNumber or who are registered in the same flight.
  84.      */
  85.     private void searchAction(ActionEvent evt) {
  86.         Vector groupePersonVector = null;
  87.         try {
  88.             Profile profile = new Profile();
  89.            
  90.             String personName = (String) personNameInput.getText();
  91.             if (personName != null)
  92.                 if (!personName.equals(""))
  93.                     profile.setPersonName(personName);
  94.            
  95.            
  96.             String flightName = (String) flightSelect.getSelectedItem();
  97.             if (flightName != null)
  98.                 if (!flightName.equals(""))
  99.                     profile.setFlight(fs.selectFlight(flightName));
  100.            
  101.            
  102.             Integer bookingNumber = (Integer) bookingSelect.getSelectedItem();
  103.             if (bookingNumber != null) {
  104.                 profile.setBookingNumber(bookingNumber.intValue());
  105.             }
  106.            
  107.             String colString = colInput.getText();
  108.             String rowString = rowInput.getText();
  109.            
  110.             if ((colString != null) && (rowString != null)) {
  111.                 if (colString.equals("") ^ rowString.equals("")) {
  112.                     throw new Exception("Both col and row have to be either null or non null");
  113.                 }
  114.                 if (!colString.equals("") && !rowString.equals(""))
  115.                     if (Functions.checkInteger(colString, 1, Flight.ROWS_MAX)
  116.                     && Functions.checkInteger(rowString, 1, Flight.ROW_LENGTH_MAX)) {
  117.                        
  118.                         short col = (short) Integer.parseInt(colString);
  119.                         short row = (short) Integer.parseInt(rowString);
  120.                         Pos pos = new Pos(row,col);
  121.                         profile.setPos(pos);
  122.                     }
  123.                     else {
  124.                         colInput.setText("");
  125.                         rowInput.setText("");
  126.                         throw new Exception("Col or Row have incorect value");
  127.                     }
  128.             }
  129.             groupePersonVector = fs.search(profile);
  130.         } catch (Exception e) {
  131.             CustomDialog.alert(e);
  132.         }
  133.        
  134.         if (groupePersonVector != null) {
  135.             int groupePersonSize = groupePersonVector.size();
  136.             String listData[][] = new String[groupePersonSize][4];
  137.             String title[] = {"Name", "Booking number", "flight name", "seat"};
  138.             for (int i=0; i< groupePersonSize; i++) {
  139.                 try {
  140.                     Person person = (Person) groupePersonVector.get(i);
  141.                     listData[i][0] = person.getPersonName();
  142.                     listData[i][1] = new Integer(person.getBookingNumber()).toString();
  143.                     listData[i][2] = person.getFlight().getFlightName();
  144.                     listData[i][3] = person.getPos().toString();
  145.                 } catch (Exception e) {CustomDialog.alert(e);}
  146.             }
  147.            
  148.             bookingTable.setModel(new DefaultTableModel(listData,title));
  149.         }
  150.        
  151.     }
  152.    
  153.     /**
  154.      * Causes this container to lay out its components.
  155.      */
  156.     public void doLayout() {
  157.         flightSelect.setBounds(20, 40, 90, 20);
  158.         bookingSelect.setBounds(210, 40, 80, 20);
  159.         personNameInput.setBounds(130, 40, 60, 20);
  160.         colInput.setBounds(310, 40, 40, 20);
  161.         flightLabel.setBounds(20, 10, 40, 20);
  162.         personNameLabel.setBounds(130, 10, 40, 20);
  163.         bookingLabel.setBounds(210, 10, 40, 20);
  164.         colLabel.setBounds(310, 10, 40, 20);
  165.         rowLabel.setBounds(360, 10, 40, 20);
  166.         rowInput.setBounds(360, 40, 40, 20);
  167.         searchButton.setBounds(420, 40, 70, 20);
  168.         jScrollPane.setBounds(20, 90, 500, 120);
  169.         bookingTable.setBounds(20, 90, 500, 120);
  170.     }
  171.    
  172.     /**
  173.      * Set the size of the panel
  174.      * @return an instance of Dimension that represents the minimum size of this container.
  175.      */
  176.     public Dimension getMinimumSize() {
  177.         return new Dimension(550,220);
  178.     }
  179.    
  180.     /**
  181.      * Set the size of the panel
  182.      * @return an instance of Dimension that represents the preferred size of this container.
  183.      */
  184.     public Dimension getPreferredSize() {
  185.         return new Dimension(550,220);
  186.     }
  187.    
  188.     /**
  189.      * Initialize the number of the field and fill them with default values.
  190.      * Dispaly the label of the Window.
  191.      */
  192.     public void init() {
  193.         bookingSelect.addItem(null);
  194.         flightSelect.addItem(null);
  195.         try {
  196.             String [] flightList = fs.getFlightList();
  197.             if (flightList != null) {
  198.                 for (int i=0;i< flightList.length;i++) {
  199.                     flightSelect.addItem(flightList[i]);
  200.                 }
  201.             }
  202.             Integer [] bookingtList = fs.getBookingList();
  203.             if (bookingtList != null) {
  204.                 for (int i=0;i< bookingtList.length;i++) {
  205.                     bookingSelect.addItem(bookingtList[i]);
  206.                 }
  207.             }
  208.         } catch (Exception e) {
  209.             CustomDialog.alert(e);
  210.         }
  211.         searchAction(null);
  212.     }
  213.    
  214.     /**
  215.      * Proceed the execution of the action
  216.      * @return the result of the request.
  217.      * @param unUsed not used
  218.      * @throws Exception if the command is not executed.
  219.      */
  220.     public String execute(String[] unUsed) throws Exception {
  221.         return "";
  222.     }
  223.    
  224.    
  225.     private JLabel bookingLabel;
  226.     private JComboBox bookingSelect;
  227.     private JTable bookingTable;
  228.     private JTextField colInput;
  229.     private JLabel colLabel;
  230.     private JLabel flightLabel;
  231.     private JComboBox flightSelect;
  232.     private JScrollPane jScrollPane;
  233.     private JTextField personNameInput;
  234.     private JLabel personNameLabel;
  235.     private JTextField rowInput;
  236.     private JLabel rowLabel;
  237.     private JButton searchButton;
  238.    
  239. }
  240.  

contact - faire un lien