package com.csust.frame;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.swing.ButtonGroup;
import javax.swing.DefaultCellEditor;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
import javax.swing.table.TableModel;
import com.csust.business.BookingBussinessHandle;
import com.csust.entity.Flight;
import com.csust.entity.FlightSchedular;
public class BookingMgrPanel extends JPanel {
public BookingMgrPanel() {
bbh = new BookingBussinessHandle();
tabbedPane = new JTabbedPane(JTabbedPane.LEFT);
flightInfSearchPanel = new JPanel();
ticketingPanel = new JPanel();
bookingInfMgrPanel = new JPanel();
//航班信息查询界面构建
flightInfSearchPanel.setLayout(new GridBagLayout());
JLabel flightNumLabel = new JLabel("航班编号");
JLabel flightDateLabel = new JLabel("航班日期");
JLabel departureCityLabel = new JLabel("出发城市");
JLabel arrivalCityLabel = new JLabel("目的城市");
flightNumText = new JTextField();
flightDateText = new JTextField();
departureCityText = new JTextField();
arrivalCityText = new JTextField();
flightNumText.setColumns(12);
flightDateText.setColumns(12);
departureCityText.setColumns(12);
arrivalCityText.setColumns(12);
JButton queryButton1 = new JButton("查询");
final GridBagConstraints gbc1 = new GridBagConstraints();
gbc1.gridx = 1;
gbc1.gridy = 1;
flightInfSearchPanel.add(flightNumLabel, gbc1);
gbc1.gridy = 2;
flightInfSearchPanel.add(departureCityLabel,gbc1);
final GridBagConstraints gbc2 = new GridBagConstraints();
gbc2.gridx = 3;
gbc2.gridy = 1;
flightInfSearchPanel.add(flightDateLabel, gbc2);
gbc2.gridy = 2;
flightInfSearchPanel.add(arrivalCityLabel, gbc2);
final GridBagConstraints gbc3 = new GridBagConstraints();
gbc3.gridx = 2;
gbc3.gridy = 1;
flightInfSearchPanel.add(flightNumText, gbc3);
gbc3.gridy = 2;
flightInfSearchPanel.add(departureCityText,gbc3);
final GridBagConstraints gbc4 = new GridBagConstraints();
gbc4.gridx = 4;
gbc4.gridy = 1;
flightInfSearchPanel.add(flightDateText, gbc4);
gbc4.gridy = 2;
flightInfSearchPanel.add(arrivalCityText, gbc4);
final GridBagConstraints gbc5 = new GridBagConstraints();
gbc5.gridy = 3;
gbc5.gridwidth = GridBagConstraints.REMAINDER;
flightInfSearchPanel.add(queryButton1, gbc5);
queryButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
FlightSchedular fs = new FlightSchedular();
fs.setStartPlace(departureCityText.getText());
fs.setArrivePlace(arrivalCityText.getText());
fs.setStrStartTime(flightDateText.getText());
Flight flight = new Flight();
flight.setFlightId(Integer.parseInt(flightNumText.getText()));
flight.setFlightSchedular(fs);
bbh.query(flight);
}
});
//机票订购界面构建
// JLabel flightBookingInfLabel = new JLabel("航班订票信息");
// JLabel clientInfLabel = new JLabel("客户信息");
// JLabel bookingInfLabel = new JLabel("订票信息");
//
// JLabel clientIdLabel = new JLabel("客户编号");
// JLabel clientNameLabel = new JLabel("客户姓名");
// JLabel flightIdLabel = new JLabel("航班编号");
// JLabel IDLabel = new JLabel("身份证号码");
// JLabel telephoneLabel = new JLabel("联系电话");
// JLabel cientTypeNameLabel = new JLabel("客户类型名称");
// JLabel sexLabel = new JLabel("性别");
//
// JTextField clientIdText = new JTextField();
// JTextField clientNameText = new JTextField();
// JTextField flightIdText = new JTextField();
// JTextField IDText = new JTextField();
// JTextField telephoneText = new JTextField();
//
// JComboBox clientTypeNameBox = new JComboBox(new Object[]{
// "普通","学生","军人","残疾人"});
// ButtonGroup group = new ButtonGroup();
// JRadioButton boyButton= new JRadioButton("男");
// boyButton.setSelected(true);
// JRadioButton girlButton = new JRadioButton("女");
// group.add(boyButton);
// group.add(girlButton);
JLabel flightDateLabel1 = new JLabel("航班日期");
JLabel departureCityLabel1 = new JLabel("出发城市");
JLabel arrivalCityLabel1 = new JLabel("目的城市");
flightDateText1 = new JTextField();
departureCityText1 = new JTextField();
arrivalCityText1 = new JTextField();
flightDateText1.setColumns(12);
departureCityText1.setColumns(12);
arrivalCityText1.setColumns(12);
JButton queryButton3 = new JButton(" 查询");
final GridBagConstraints gbc6 = new GridBagConstraints();
ticketingPanel.setLayout(new GridBagLayout());
ticketingPanel.add(flightDateLabel1, gbc6);
ticketingPanel.add(flightDateText1, gbc6);
ticketingPanel.add(departureCityLabel1, gbc6);
ticketingPanel.add(departureCityText1, gbc6);
ticketingPanel.add(arrivalCityLabel1, gbc6);
ticketingPanel.add(arrivalCityText1, gbc6);
gbc6.gridwidth = GridBagConstraints.REMAINDER;
ticketingPanel.add(queryButton3, gbc6);
model0 = new TicketingTableModel();
tabel0 = new JTable(model0);
ticketingPanel.add(new JScrollPane(tabel0),gbc6);
//事件处理
queryButton3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String flightDate = flightDateText1.getText();
String departureCity = departureCityText1.getText();
String arrivalCity = arrivalCityText1.getText();
List list = bbh.query(flightDate,departureCity,arrivalCity);
model0 = new TicketingTableModel(list);
tabel0.setModel(model0);
// tabel0.setDefaultRenderer(JbuttonCellRender.class, new JbuttonCellRender());
tabel0.setDefaultEditor(JbuttonCellEditor.class, new JbuttonCellEditor());
}
});
//订票信息管理界面构建
bookingInfMgrPanel.setLayout(new GridBagLayout());
JLabel customerNameLabel = new JLabel("客户姓名");
JLabel flightOrDateLabel = new JLabel("航班/日期");
customerNameText = new JTextField();
flightOrDateText = new JTextField();
customerNameText.setColumns(12);
flightOrDateText.setColumns(12);
JButton queryButton = new JButton("查询");
JButton delButton = new JButton("删除记录");
final GridBagConstraints gbc = new GridBagConstraints();
bookingInfMgrPanel.add(customerNameLabel,gbc);
bookingInfMgrPanel.add(customerNameText,gbc);
bookingInfMgrPanel.add(flightOrDateLabel,gbc);
bookingInfMgrPanel.add(flightOrDateText,gbc);
bookingInfMgrPanel.add(queryButton,gbc);
gbc.gridwidth = GridBagConstraints.REMAINDER;
bookingInfMgrPanel.add(delButton,gbc);
model = new BookingInfTableModel();
table = new JTable(model);
bookingInfMgrPanel.add(new JScrollPane(table),gbc);
queryButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
// ResultSet rs;
Map map = null;
map = bbh.query(customerNameText.getText(), flightOrDateText.getText());
model = new BookingInfTableModel(map);
table.setModel(model);
}
});
tabbedPane.add("订票信息管理",null);
tabbedPane.add("机票订购",null);
tabbedPane.add("航班信息查询",null);