⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addreservationframe.java

📁 这个一个餐厅预定系统,可实现查询目前餐厅预订情况,实现餐桌预订以及就餐时为顾客调节餐桌的情况.
💻 JAVA
字号:
package bookingsystem;

import java.awt.*;

import javax.swing.*;
import java.awt.BorderLayout;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Vector;
import java.sql.SQLException;
import java.util.Date;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2007</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class AddreservationFrame extends myFrame {

    private ReservationFrame resFrame;
    String tempArrivalDate = null;
    String tempArrivalTime = null;
    XYLayout xYLayout1 = new XYLayout();
    JLabel jLabel1 = new JLabel();
    JLabel jLabel2 = new JLabel();
    JTextField RCOVERS = new JTextField();
    JLabel jLabel3 = new JLabel();
    JLabel jLabel4 = new JLabel();
    JLabel jLabel5 = new JLabel();
    JTextField RCUSTOMERNAME = new JTextField();
    JButton jButton1 = new JButton();
    JButton jButton2 = new JButton();
    JComboBox RARRIVALDATE = new JComboBox();
    JComboBox RTABLENO = new JComboBox();
    JComboBox RARRIVALTIME = new JComboBox();
    JButton inqury = new JButton();
    JLabel jLabel6 = new JLabel();
    JTextField RCUSTOMERPHONE = new JTextField();

    public AddreservationFrame(ReservationFrame resFrame) {
        super();
        this.resFrame = resFrame;
        try {
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    private void jbInit() throws Exception {

        String arrivalDate[] = {"today", "tomorrow", "the day after tomorrow"};
        String arrivalTime[] = {"10:00-12:00", "18:00-20:00", "20:00-22:00"};

        this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        for (int i = 0; i < 3; i++) {
            RARRIVALDATE.addItem(arrivalDate[i]);
            RARRIVALTIME.addItem(arrivalTime[i]);
        }

        getContentPane().setLayout(xYLayout1);
        jLabel2.setText("人数");
        jLabel3.setText("预约时间");
        jLabel4.setText("可用餐桌");
        jLabel5.setText("顾客姓名");
        jButton1.setText("添加");
        jButton1.addActionListener(new
                                   AddreservationFrame_jButton1_actionAdapter(this));
        jButton2.setText("取消");
        jButton2.addActionListener(new
                                   AddreservationFrame_jButton2_actionAdapter(this));
        RARRIVALDATE.setToolTipText("");
        RARRIVALDATE.setSelectedItem(RARRIVALTIME);
        inqury.setText("查询");
        inqury.addActionListener(new AddreservationFrame_inqury_actionAdapter(this));
        xYLayout1.setWidth(400);
        xYLayout1.setHeight(390);
        jLabel6.setText("顾客电话");
        this.getContentPane().add(jLabel1, new XYConstraints(148, 25, 103, 42));
        jLabel1.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
        jLabel1.setText("添加预约");
        this.getContentPane().add(jButton1, new XYConstraints(57, 329, 71, -1));
        this.getContentPane().add(jButton2, new XYConstraints(237, 327, 70, -1));
        this.getContentPane().add(jLabel3, new XYConstraints(63, 180, -1, -1));
        this.getContentPane().add(jLabel4, new XYConstraints(63, 229, -1, -1));
        this.getContentPane().add(RARRIVALTIME,
                                  new XYConstraints(216, 175, 104, 22));
        this.getContentPane().add(RARRIVALDATE,
                                  new XYConstraints(138, 175, 60, -1));
        this.getContentPane().add(RCUSTOMERNAME,
                                  new XYConstraints(138, 86, 131, -1));
        this.getContentPane().add(jLabel5, new XYConstraints(62, 88, -1, -1));
        this.getContentPane().add(RTABLENO, new XYConstraints(138, 225, 127, -1));
        this.getContentPane().add(inqury, new XYConstraints(279, 225, 62, -1));
        this.getContentPane().add(RCUSTOMERPHONE,
                                  new XYConstraints(138, 117, 131, -1));
        this.getContentPane().add(jLabel2, new XYConstraints(69, 149, -1, -1));
        this.getContentPane().add(jLabel6, new XYConstraints(60, 121, -1, -1));
        this.getContentPane().add(RCOVERS, new XYConstraints(138, 144, 114, -1));
    }

    public void fillFreeTables() {
        Reservation tempRes = new Reservation();
        int tablePlaces = 0;
        tablePlaces = Integer.parseInt(RCOVERS.getText());


        long nCurrentTime = System.currentTimeMillis();
        java.util.Date ArrivalDate = new java.util.Date(nCurrentTime);
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        String tempPreDate = df.format(ArrivalDate);
        String tempArrivalTime = RARRIVALTIME.getSelectedItem().toString();
        String arrivalDate = RARRIVALDATE.getSelectedItem().toString();
       if (arrivalDate.equals("today")) {
           tempArrivalDate = tempPreDate;

       } else if (arrivalDate.equals("tomorrow")) {
           Date tomorrow = new Date(nCurrentTime + 1 * 24 * 60 * 60 * 1000);
           tempArrivalDate = df.format(tomorrow);

       } else {
           Date twoDateLater = new Date(nCurrentTime + 2 * 24 * 60 * 60 * 1000);
           tempArrivalDate = df.format(twoDateLater);
       }



        tempRes.setarrivaldate(tempArrivalDate);
        tempRes.setarrivaltime(tempArrivalTime);

        Vector freeTables = tempRes.getfreetables(tempArrivalDate,tempArrivalTime);
        for (int i = 0; i < freeTables.size(); i++) {
            Table tempTable = (Table) freeTables.get(i);
           //if(tempTable.getplaces()>= tablePlaces)
           //{
               RTABLENO.addItem(tempTable.gettalno());
           //}
        }

    }

    public void inqury_actionPerformed(ActionEvent e) {
        RTABLENO.removeAllItems();

        fillFreeTables();
    }

    public void jButton1_actionPerformed(ActionEvent e) {


        long nCurrentTime = System.currentTimeMillis();
        java.util.Date date = new java.util.Date(nCurrentTime);
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        String tempPredate = df.format(date);

        String tempCustomerName = RCUSTOMERNAME.getText().trim();
        String tempCustomerPhone = RCUSTOMERPHONE.getText().trim();


        Customer tempCustomer = null;
        try {
            tempCustomer = new Customer(tempCustomerName,
                                        tempCustomerPhone);
        } catch (SQLException ex) {
        }

        int tempCovers = Integer.parseInt(RCOVERS.getText());

        String arrivalDate = RARRIVALDATE.getSelectedItem().toString();
        if (arrivalDate.equals("today")) {
            tempArrivalDate = tempPredate;

        } else if (arrivalDate.equals("tomorrow")) {
            Date tomorrow = new Date(nCurrentTime + 1 * 24 * 60 * 60 * 1000);
            tempArrivalDate = df.format(tomorrow);

        } else {
            Date twoDateLater = new Date(nCurrentTime + 2 * 24 * 60 * 60 * 1000);
            tempArrivalDate = df.format(twoDateLater);
        }

         tempArrivalTime = RARRIVALTIME.getSelectedItem().toString();

        String tempTalno = RTABLENO.getSelectedItem().toString();
        Table tempTable = new Table(tempTalno);

        Reservation tempReservation = new Reservation(tempCovers, tempPredate,
                tempTable, tempCustomer, tempArrivalDate, tempArrivalTime);
        tempReservation.addBooking();

        this.resFrame.jButton5_actionPerformed(e);
        this.resFrame.setEnabled(true);
        this.dispose();
    }

    public void jButton2_actionPerformed(ActionEvent e) {
        this.resFrame.setEnabled(true);
        this.dispose();
    }
}


class AddreservationFrame_jButton2_actionAdapter implements ActionListener {
    private AddreservationFrame adaptee;
    AddreservationFrame_jButton2_actionAdapter(AddreservationFrame adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButton2_actionPerformed(e);
    }
}


class AddreservationFrame_jButton1_actionAdapter implements ActionListener {
    private AddreservationFrame adaptee;
    AddreservationFrame_jButton1_actionAdapter(AddreservationFrame adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        try{

            adaptee.jButton1_actionPerformed(e);
        }catch(Exception ex)
        {
            ex.printStackTrace();
        }
    }
}


class AddreservationFrame_inqury_actionAdapter implements ActionListener {
    private AddreservationFrame adaptee;
    AddreservationFrame_inqury_actionAdapter(AddreservationFrame adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.inqury_actionPerformed(e);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -