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

📄 hotelmanageframe.java~23~

📁 Java+SQL2000宾馆管理系统,可实现简单的管理操作。
💻 JAVA~23~
📖 第 1 页 / 共 3 页
字号:
import java.sql.*;
import java.util.*;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;

import com.borland.dbswing.*;
import com.borland.dx.sql.dataset.*;

/**
 * <p>Title: 宾馆官理系统</p>
 * <p>Description: 第七章实例</p>
 * <p>Copyright: Copyright (c) 2006</p>
 * <p>Company: </p>
 * @author 苏年乐
 * @version 1.0
 */

public class HotelManageFrame
    extends JFrame {
  private final static int PRICE_EACH_DAY_SINGLE_ROOM = 100;
  private final static int PRICE_EACH_DAY_DOUBLE_ROOM = 150;
  JButton addGuestButton = new JButton();
  JPanel functionPanel = new JPanel();
  JButton deleteGuestButton = new JButton();
  JButton guestQueryButton = new JButton();
  JButton emptyRoomSearchButton = new JButton();
  JPanel guestInfoPanel = new JPanel();
  JPanel clockPanel = new JPanel();
  JLabel nameLabel = new JLabel();
  JLabel sexLabel = new JLabel();
  Connection connect;
  String url;
  boolean roomordered;
  int priceEachday;

  JButton clearButton = new JButton();
  String Slected[] = {
      "男", "女"};
  JMenuBar jMenuBar1 = new JMenuBar();
  JMenu jMenu1 = new JMenu();
  JMenuItem aboutMenuItem = new JMenuItem();
  JLabel ageLabel = new JLabel();
  JLabel roomLabel = new JLabel();
  JLabel moneyLabel = new JLabel();
  JLabel idLabel = new JLabel();
  JMenuItem helpMenuItem = new JMenuItem();
  JTextField roomTextField = new JTextField();
  JTextField nameTextField = new JTextField();
  JComboBox sexComboBox = new JComboBox(Slected);
  JTextField moneyTextField = new JTextField();
  JTextField idTextField = new JTextField();
  JTextField ageTextField = new JTextField();
  Clocklabel clockLabel = new Clocklabel();
  JScrollPane operInfoScrollPane = new JScrollPane();
  JTextArea operInfoTextArea = new JTextArea();
  Database database = new Database();
  QueryDataSet queryDataSet = new QueryDataSet();
  TableScrollPane gusetTableScrollPane = new TableScrollPane();
  JdbTable guestTable = new JdbTable();
  JdbNavToolBar jdbcNavToolBar = new JdbNavToolBar();
  JdbStatusLabel jdbcStatusLabel = new JdbStatusLabel();

  public HotelManageFrame() {
    try {

      jbInit();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }

  private void jbInit() throws Exception {
    titledBorder1 = new TitledBorder(BorderFactory.createEtchedBorder(Color.
        white, new Color(165, 163, 151)), "旅客列表");
    titledBorder2 = new TitledBorder(BorderFactory.createEtchedBorder(Color.
        white, new Color(165, 163, 151)), "系统管理");
    titledBorder3 = new TitledBorder(BorderFactory.createEtchedBorder(Color.
        white, new Color(165, 163, 151)), "功能选择");
    titledBorder4 = new TitledBorder(BorderFactory.createEtchedBorder(Color.
        white, new Color(165, 163, 151)), "旅客信息");
    titledBorder5 = new TitledBorder(BorderFactory.createEtchedBorder(Color.
        white, new Color(165, 163, 151)), "操作信息");
    border1 = BorderFactory.createEmptyBorder();
    titledBorder6 = new TitledBorder(border1, "时间");
    titledBorder7 = new TitledBorder(BorderFactory.createEtchedBorder(Color.
        white, new Color(165, 163, 151)), "时间");
    this.setTitle("宾馆管理系统");
    addGuestButton.setFont(new java.awt.Font("Dialog", 0, 12));
    addGuestButton.setText("添加旅客");
    addGuestButton.addActionListener(new HotelManageFrame_addGuestButton_actionAdapter(this));
    this.getContentPane().setLayout(gridBagLayout2);
    functionPanel.setLayout(gridLayout1);
    deleteGuestButton.setFont(new java.awt.Font("Dialog", 0, 12));
    deleteGuestButton.setToolTipText("");
    deleteGuestButton.setActionCommand("旅客退房");
    deleteGuestButton.setText("旅客退房");
    deleteGuestButton.addActionListener(new
                                        HotelManageFrame_deleteGuestButton_actionAdapter(this));
    guestQueryButton.setFont(new java.awt.Font("Dialog", 0, 12));
    guestQueryButton.setText("旅客查寻");
    guestQueryButton.addActionListener(new
                                       HotelManageFrame_guestQueryButton_actionAdapter(this));
    emptyRoomSearchButton.setFont(new java.awt.Font("Dialog", 0, 12));
    emptyRoomSearchButton.setText("空房查寻");
    emptyRoomSearchButton.addActionListener(new
                                            HotelManageFrame_emptyRoomSearchButton_actionAdapter(this));
    guestInfoPanel.setLayout(gridBagLayout3);
    nameLabel.setFont(new java.awt.Font("Dialog", 0, 12));
    nameLabel.setToolTipText("");
    nameLabel.setText("姓名");
    sexLabel.setFont(new java.awt.Font("Dialog", 0, 12));
    sexLabel.setText("性别");
    clockPanel.setLayout(borderLayout2);

    clearButton.setFont(new java.awt.Font("Dialog", 0, 12));
    clearButton.setText("清空");
    clearButton.addActionListener(new HotelManageFrame_clearButton_actionAdapter(this));
    this.setLocale(java.util.Locale.getDefault());
    this.setJMenuBar(null);
    this.setState(Frame.NORMAL);
    jMenu1.setText("关于");
    aboutMenuItem.setText("作者及版权");
    aboutMenuItem.addActionListener(new HotelManageFrame_aboutMenuItem_actionAdapter(this));
    clockPanel.setFont(new java.awt.Font("Dialog", 0, 12));
    clockPanel.setBorder(titledBorder7);
    clockPanel.setDebugGraphicsOptions(0);
    clockPanel.setMinimumSize(new Dimension(10, 10));
    clockPanel.setPreferredSize(new Dimension(60, 20));
    ageLabel.setFont(new java.awt.Font("Dialog", 0, 12));
    ageLabel.setText("年龄");
    roomLabel.setFont(new java.awt.Font("Dialog", 0, 12));
    roomLabel.setText("房号");
    moneyLabel.setFont(new java.awt.Font("Dialog", 0, 12));
    moneyLabel.setText("当前金额");
    idLabel.setFont(new java.awt.Font("Dialog", 0, 12));
    idLabel.setText("身份证号");
    guestInfoPanel.setEnabled(true);
    guestInfoPanel.setBorder(titledBorder4);
    guestInfoPanel.setDebugGraphicsOptions(0);
    helpMenuItem.setText("帮助");
    helpMenuItem.addActionListener(new HotelManageFrame_helpMenuItem_actionAdapter(this));
    sexComboBox.setFont(new java.awt.Font("Dialog", 0, 12));
    sexComboBox.setDebugGraphicsOptions(0);
    sexComboBox.setToolTipText("");
    sexComboBox.setEditable(false);
    sexComboBox.setSelectedIndex( -1);
    //sexComboBox.setSelectedItem(this);
    moneyTextField.setFont(new java.awt.Font("Dialog", 0, 12));
    moneyTextField.setEditable(false);
    moneyTextField.setText("");
    operInfoScrollPane.setHorizontalScrollBarPolicy(JScrollPane.
        HORIZONTAL_SCROLLBAR_ALWAYS);
    operInfoScrollPane.setBorder(titledBorder5);
    operInfoScrollPane.setPreferredSize(new Dimension(62, 150));
    operInfoTextArea.setFont(new java.awt.Font("Dialog", 0, 12));
    operInfoTextArea.setText("");
    //jTextArea1.setLineWrap(true);

    database.setConnection(new com.borland.dx.sql.dataset.ConnectionDescriptor(
        "jdbc:odbc:hotel", "", "", false, "sun.jdbc.odbc.JdbcOdbcDriver"));
    String sql="select name AS 姓名,sex AS 性别,age AS 年龄,idnumber AS 身份证号,room AS 房间号,in_date AS 入住时间 from hotel";
    queryDataSet.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(
        database, sql, null, true, Load.ALL));
    guestTable.setFont(new java.awt.Font("Dialog", 0, 12));
    guestTable.setMinimumSize(new Dimension(512, 84));
    guestTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
    guestTable.setDataSet(queryDataSet);
    guestTable.setEditable(false);
    jdbcStatusLabel.setAlignmentY( (float) 0.5);
    managementPanel.setLayout(gridBagLayout1);
    managementPanel.setBorder(titledBorder2);
    managementPanel.setPreferredSize(new Dimension(512, 768));
    guestListPanel.setBorder(titledBorder1);
    guestListPanel.setPreferredSize(new Dimension(512, 768));
    guestListPanel.setRequestFocusEnabled(true);
    guestListPanel.setToolTipText("");
    guestListPanel.setLayout(borderLayout1);
    functionPanel.setBorder(titledBorder3);
    functionPanel.setMinimumSize(new Dimension(385, 25));
    functionPanel.setOpaque(true);
    functionPanel.setPreferredSize(new Dimension(385, 25));
    functionPanel.setToolTipText("");
    gusetTableScrollPane.setHorizontalScrollBarPolicy(JScrollPane.
        HORIZONTAL_SCROLLBAR_AS_NEEDED);
    gusetTableScrollPane.setMinimumSize(new Dimension(300, 27));
    gusetTableScrollPane.setPreferredSize(new Dimension(512, 440));
    clockLabel.setFont(new java.awt.Font("Dialog", 0, 25));
    clockLabel.setHorizontalAlignment(SwingConstants.CENTER);
    nameTextField.setFont(new java.awt.Font("Dialog", 0, 12));
    nameTextField.setText("");
    ageTextField.setFont(new java.awt.Font("Dialog", 0, 12));
    ageTextField.setText("");
    idTextField.setFont(new java.awt.Font("Dialog", 0, 12));
    idTextField.setText("");
    roomTextField.setFont(new java.awt.Font("Dialog", 0, 12));
    roomTextField.setText("");
    functionPanel.add(addGuestButton, null);
    functionPanel.add(deleteGuestButton, null);
    functionPanel.add(guestQueryButton, null);
    functionPanel.add(emptyRoomSearchButton, null);
    functionPanel.add(clearButton, null);
    managementPanel.add(guestInfoPanel,
                        new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0
                                               , GridBagConstraints.CENTER,
                                               GridBagConstraints.NONE,
                                               new Insets(0, 0, 0, 0), 40, 0));
    managementPanel.add(clockPanel, new GridBagConstraints(0, 3, 1, 1, 1.0, 1.0
        , GridBagConstraints.CENTER, GridBagConstraints.NONE,
        new Insets(0, 0, 0, 0), 300, 50));
    clockPanel.add(clockLabel, BorderLayout.CENTER);
    this.getContentPane().add(guestListPanel,
                              new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0
        , GridBagConstraints.CENTER, GridBagConstraints.BOTH,
        new Insets(0, 0, 0, 0), 0, 0));

    jdbcNavToolBar.getDeleteButton().setToolTipText("删除当前行");
    jdbcNavToolBar.getCancelButton().setToolTipText("撤销对当前行的修改");
    jdbcNavToolBar.getDittoButton().setToolTipText("拷贝前一行");
    jdbcNavToolBar.getFirstButton().setToolTipText("移动到首行");
    jdbcNavToolBar.getInsertButton().setToolTipText("增加一行");
    jdbcNavToolBar.getLastButton().setToolTipText("移动到末行");
    jdbcNavToolBar.getNextButton().setToolTipText("移动到下一行");
    jdbcNavToolBar.getPostButton().setToolTipText("提交对当前行的修改");
    jdbcNavToolBar.getPriorButton().setToolTipText("移动到前一行");
    jdbcNavToolBar.getRefreshButton().setToolTipText("刷新数据");
    jdbcNavToolBar.getSaveButton().setToolTipText("保存修改");

    guestListPanel.add(jdbcNavToolBar, BorderLayout.NORTH);
    guestListPanel.add(gusetTableScrollPane, BorderLayout.CENTER);
    this.getContentPane().add(managementPanel,
                              new GridBagConstraints(1, 0, 1, 1, 1.0, 1.0
        , GridBagConstraints.CENTER, GridBagConstraints.BOTH,
        new Insets(0, 0, 0, 0), 0, 35));
    gusetTableScrollPane.getViewport().add(guestTable, null);
    jdbcNavToolBar.add(jdbcStatusLabel, null);
    guestInfoPanel.add(nameLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
        , GridBagConstraints.WEST, GridBagConstraints.NONE,
        new Insets(5, 10, 5, 10), 8, 13));
    guestInfoPanel.add(nameTextField,
                       new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0
                                              , GridBagConstraints.CENTER,
                                              GridBagConstraints.HORIZONTAL,
                                              new Insets(5, 20, 5, 20), 30, 11));
    guestInfoPanel.add(sexLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
        , GridBagConstraints.WEST, GridBagConstraints.NONE,
        new Insets(5, 10, 5, 10), 8, 13));
    guestInfoPanel.add(sexComboBox, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0
        , GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
        new Insets(5, 20, 5, 20), 30, 11));
    guestInfoPanel.add(idLabel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0
        , GridBagConstraints.WEST, GridBagConstraints.NONE,
        new Insets(5, 10, 5, 10), 8, 13));
    guestInfoPanel.add(idTextField, new GridBagConstraints(1, 3, 1, 1, 1.0, 0.0
        , GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
        new Insets(5, 20, 5, 20), 30, 11));
    guestInfoPanel.add(roomLabel, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0
        , GridBagConstraints.WEST, GridBagConstraints.NONE,
        new Insets(5, 10, 5, 10), 8, 13));
    guestInfoPanel.add(roomTextField,
                       new GridBagConstraints(1, 4, 1, 1, 1.0, 0.0
                                              , GridBagConstraints.CENTER,
                                              GridBagConstraints.HORIZONTAL,
                                              new Insets(5, 20, 5, 20), 30, 11));
    guestInfoPanel.add(moneyLabel, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0
        , GridBagConstraints.WEST, GridBagConstraints.NONE,
        new Insets(5, 10, 5, 10), 8, 13));
    guestInfoPanel.add(moneyTextField,
                       new GridBagConstraints(1, 5, 1, 1, 1.0, 0.0
                                              , GridBagConstraints.CENTER,
                                              GridBagConstraints.HORIZONTAL,
                                              new Insets(5, 20, 5, 20), 30, 11));
    guestInfoPanel.add(ageLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
        , GridBagConstraints.WEST, GridBagConstraints.NONE,
        new Insets(5, 10, 5, 10), 8, 13));
    guestInfoPanel.add(ageTextField,
                       new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0
                                              , GridBagConstraints.CENTER,
                                              GridBagConstraints.HORIZONTAL,
                                              new Insets(5, 20, 5, 20), 30, 11));
    managementPanel.add(operInfoScrollPane,
                        new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
                                               , GridBagConstraints.CENTER,
                                               GridBagConstraints.NONE,
                                               new Insets(0, 0, 0, 0), 360, 79));
    operInfoScrollPane.getViewport().add(operInfoTextArea, null);
    managementPanel.add(functionPanel,
                        new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
                                               , GridBagConstraints.CENTER,
                                               GridBagConstraints.NONE,
                                               new Insets(15, 10, 0, 10), 29,
                                               33));
    jMenuBar1.add(jMenu1);
    jMenu1.add(aboutMenuItem);
    jMenu1.add(helpMenuItem);
    setJMenuBar(jMenuBar1);

    try {
      url = "jdbc:odbc:hotel";
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      connect = DriverManager.getConnection(url);
      operInfoTextArea.append("Connection Successful!");
    }
    catch (ClassNotFoundException cnfex) {
      // process ClassNotFoundExceptions here
      cnfex.printStackTrace();

    }
    catch (SQLException sqlex) {
      // process SQLExceptions here
      sqlex.printStackTrace();

    }
    catch (Exception ex) {
      // process remaining Exceptions here
      ex.printStackTrace();

    }

  }

  void addGuestButton_actionPerformed(ActionEvent e) {
    try {
      roomwithpeople(roomTextField.getText());
      if (roomordered) {
        JOptionPane.showMessageDialog(null,
                                      roomTextField.getText() +
                                      "房间已经有客人,请您另选一间");
        roomTextField.setText("");
      }
      else {
        // boolean judge=false;
        Statement statement = connect.createStatement();
        Calendar cal = Calendar.getInstance();
        String c = cal.get(Calendar.YEAR) + "-" + (cal.get(Calendar.MONTH) + 1) +
            "-" + cal.get(Calendar.DATE);
        if (judgeName() && judgeAge() && judgeRoomNum() && judgeSex() &&
            judgeIdnum()) {
          String query = "INSERT INTO hotel (" +
              " name,sex,age,idnumber,room ,in_date" +
              ") VALUES ('" +
              nameTextField.getText() + "', '" +
              sexComboBox.getSelectedItem() + "', '" +
              ageTextField.getText() + "', '" +
              idTextField.getText() + "', '" +

⌨️ 快捷键说明

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