您好,登錄后才能下訂單哦!
本文實例為大家分享了java實現酒店管理系統的具體代碼,供大家參考,具體內容如下
編寫環境:MyEclipse2014+sql server2014
系統功能:
1.登錄驗證
2.房態統計顯示
3.預定登記并入庫
4.入住登記并入庫
5.換房登記并入庫
6.客人信息查詢
7.退房并入庫
運行界面如下:
=====登錄界面======
=====主界面=====
=====為每個房間設置彈出菜單======
=====登記界面======
=====換房界面=====
=====退房界面=====
界面之間相關關系:
主界面主要由菜單條,按鈕,標簽等組成,一個JButton是一個房間,其Test從數據庫中獲取,顏色由房態決定。
登記-換房-查看信息-退房等界面皆繼承一個父類而來,簡單快捷。
主要代碼目錄:
1.數據庫操作類
/**====================================================** * 項目名 :酒店管理系統 * 模塊名 :數據庫連接 * 文件名 :DataBaseConnct.java * 相關文件 : * 實現功能 :jdbc連接數據庫 * 函數說明 : * [## public Vector getId(){}]: * 功能:獲取數據庫中系統登錄ID * * [## public void setId() {}]: * 功能:設置數據庫中系統登錄ID * * [## public Vector getPassword(){}]: * 功能:獲取數據庫中系統登錄密碼 * * [## public void setPassword(){}]: * 功能:設置數據庫中系統登錄密碼 * * [## public Vector getRoonnum(){}]: * 功能:獲取數據庫中房間號 * * [## public void setRoonnum() {}]: * 功能:設置數據庫中房間號 * * [## public Vector getRoomtype(){}]: * 功能:獲取數據庫中房間類型 * * [## public void seRoomtype(){}]: * 功能:設置數據庫中房間類型 * * [## public void Sql(String sql){}]: * 功能:執行sql語句進行查詢 * **===================================================**/ package com.common; import java.sql.*; import java.util.Vector; import javax.swing.JOptionPane; import javax.xml.crypto.dsig.keyinfo.RetrievalMethod; public class DataBaseConnect { private String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver"; private String dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=hotel_mangerment_system"; private String userName="sa"; private String userPwd="1451171"; private Connection ct=null; private ResultSet rs=null; private Statement st; private Vector id =new Vector(); private Vector password =new Vector(); /**====================================================** * 獲取數據庫中系統登錄ID **===================================================**/ public Vector getId() { return id; } /**====================================================** * 設置數據庫中系統登錄ID **===================================================**/ public void setId(Vector id) { this.id = id; } /**====================================================** * 獲取數據庫中系統登錄密碼 **===================================================**/ public Vector getPassword() { return password; } /**====================================================** * 設置數據庫中系統登錄ID **===================================================**/ public void setPassword(Vector password) { this.password = password; } /**====================================================** * [## public void Sql(String sql) {}] * 參數 :String sql * 返回值 :無 * 修飾符 :public * 功能 :創建sql查詢,從數據庫里查詢登陸賬號與密碼 **===================================================**/ public void Sql(String sql) throws Exception { Class.forName(driverName); ct=DriverManager.getConnection(dbURL,userName,userPwd); st=ct.createStatement(); rs=st.executeQuery(sql); while(rs.next()) { id.add(rs.getInt(1)); password.add(rs.getInt(2)); } if(rs!=null) rs.close(); if(st!=null) st.close(); if(ct!=null) ct.close(); } /**====================================================** * [## public Vector RoomOperation(int room_num) {}] 查詢房間信息 * 參數 :int room_num * 返回值 :無 * 修飾符 :public * 功能 :創建sql查詢房間號與類型,類外可使用 **===================================================**/ public Vector RoomOperation(int room_num)throws Exception { Vector<Object> data=new Vector<Object>(); Class.forName(driverName); ct=DriverManager.getConnection(dbURL,userName,userPwd); st=ct.createStatement(); rs=st.executeQuery("select * from room_table where roomnum="+room_num); while(rs.next()) { data.add(rs.getInt(1)); data.add(rs.getString(2)); data.add(rs.getInt(3)); data.add(rs.getInt(4)); } if(rs!=null) rs.close(); if(st!=null) st.close(); if(ct!=null) ct.close(); return data; } /**====================================================** * [## public void RoomOperation(String sql) {}] 查詢房間使用狀態 * 參數 :String sql * 返回值 :房間個數 * 修飾符 :public * 功能 :創建sql查詢滿足條件房間使用狀態,類外可使用 **===================================================**/ public int getRow(String sql)throws Exception { Class.forName(driverName); ct=DriverManager.getConnection(dbURL,userName,userPwd); int rowcount=0; st=ct.createStatement(); rs=st.executeQuery(sql); while(rs.next()) { rowcount++; } if(rs!=null) rs.close(); if(st!=null) st.close(); if(ct!=null) ct.close(); return rowcount; } /**====================================================** * [## public void insertData(){}] 插入記錄 * 參數 :String table_name,String str * 返回值 :無 * 修飾符 :public * 功能 :向數據庫中插入記錄 **=================================================== * @throws Exception **/ public void insertData(String table_name,String str) throws Exception { Class.forName(driverName); ct=DriverManager.getConnection(dbURL,userName,userPwd); ct.setAutoCommit(false); st=ct.createStatement(); String sql="insert into"+" "+table_name+" "+"values"+"("+str+")"; st.executeUpdate(sql); ct.commit(); if(st!=null) st.close(); if(ct!=null) ct.close(); } /**====================================================** * [## public void updateData(String str){}] 更新記錄 * 參數 :String sql * 返回值 :無 * 修飾符 :public * 功能 :向數據庫中更新記錄 **===================================================*/ public void updateData(String sql) throws Exception { Class.forName(driverName); ct=DriverManager.getConnection(dbURL,userName,userPwd); ct.setAutoCommit(false); st=ct.createStatement(); st.executeUpdate(sql); ct.commit(); if(st!=null) st.close(); if(ct!=null) ct.close(); } /**====================================================** * [## public void getDataFromCostomer(){}] 從Costomer_table中獲取數據 * 參數 :int room_num * 返回值 :Vector<object> data * 修飾符 :public * 功能 :根據房間號從Costomer_table中獲取數據并返回 **===================================================*/ public Vector getDataFromCostomer(int room_num) throws Exception { Vector<Object> data=new Vector<Object>(); Class.forName(driverName); ct=DriverManager.getConnection(dbURL,userName,userPwd); ct.setAutoCommit(false); st=ct.createStatement(); rs=st.executeQuery("select * from costomer_table where roomnum="+room_num+"and isliving=1"); while(rs.next()) { data.add(rs.getInt(1)); data.add(rs.getString(2)); data.add(rs.getString(3)); data.add(rs.getString(4)); data.add(rs.getString(5)); data.add(rs.getString(6)); data.add(rs.getInt(7)); data.add(rs.getInt(8)); data.add(rs.getInt(9)); } if(rs!=null) rs.close(); if(st!=null) st.close(); if(ct!=null) ct.close(); return data; } /**====================================================** * [## public Vector RoomOperation(int room_num) {}] 查詢房間信息 * 參數 :無 * 返回值 :return returedata; * 修飾符 :public * 功能 :創建sql查詢房間號與類型,與入住狀態并返回,類外可使用 **===================================================**/ public Vector RoomOperation()throws Exception { Vector<Vector> returedata=new Vector<Vector>(); Vector<Object> roomnum=new Vector<Object>(); Vector<Object> roomtype=new Vector<Object>(); Vector<Integer> roomstate=new Vector<Integer>(); Class.forName(driverName); ct=DriverManager.getConnection(dbURL,userName,userPwd); st=ct.createStatement(); rs=st.executeQuery("select roomnum,roomtype,roomatate from room_table"); while(rs.next()) { roomnum.add(rs.getInt(1)); roomtype.add(rs.getString(2)); roomstate.add(rs.getInt(3)); } if(rs!=null) rs.close(); if(st!=null) st.close(); if(ct!=null) ct.close(); returedata.add(roomnum); returedata.add(roomtype); returedata.add(roomstate); return returedata; } }
2.登錄界面類
/**====================================================** * 項目名 :酒店管理系統 * 模塊名 :系統登錄窗口 * 文件名 :HotelLoginGui.java * 相關文件 :DataBaseConnct.java HotelMainGui.java * 實現功能 :系統登錄界面 * 函數說明 : * [## public MyJframe(){}]: * 功能:構造函數 組建登錄窗口 * [## public void enevtOperation(final MyLoginJframe mj){}] * 功能:登錄界面的事件監聽處理 * [## private boolean loginCheck() {}]: * 功能:登錄驗證,僅類內使用 * [## private void quit() {}]: * 功能:關閉系統函數,僅類內使用 **===================================================**/ package com.HotelGui; import com.common.*;//引入包 import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import javax.jws.soap.SOAPBinding.Style; import javax.swing.*; import java.net.*; import java.util.*; public class HotelLoginGui { public static void main(String[] args) { // TODO Auto-generated method stub MyLoginJframe logingui=new MyLoginJframe(); logingui.enevtOperation(logingui); } } //登錄界面MyJframe class MyLoginJframe extends JFrame implements ActionListener { DataBaseConnect dc; JPasswordField passwordnum; JTextField accountnum; JLabel password,account,login,backimg,backimg1; JLabel tiplabel; JComboBox<String> loginchoice; JButton loginbutton,resetbutton,exitbutton; JPanel jp,jp0,jp1,jp2,jp3,jp4,jp5; Vector<String> dept=new Vector<String>(); private String id_now,user_type; /**=======================================================** * 設置當前成功登錄的ID **========================================================*/ public void setId_now(String id_now) { this.id_now = id_now; } /**=======================================================** * 獲得當前成功登錄的ID **========================================================*/ public String getId_now() { return id_now; } /**====================================================** * **[## public MyJframe() {}] 組建登錄窗口 * 參數 :無 * 返回值 :無 * 修飾符 :public * 功能 :組建登錄窗口 **===================================================**/ public MyLoginJframe() { dc=new DataBaseConnect();//連接數據庫實例 jp=new JPanel(); jp.setBounds(0, -5,550, 200); jp0=new JPanel(); jp0.setBounds(0,180,250,250); jp1=new JPanel(); jp1.setBounds(270, 215, 250, 30); jp2=new JPanel(); jp2.setBounds(270, 250, 250, 30); jp3=new JPanel(); jp3.setBounds(270, 280, 250, 30); jp4=new JPanel(); jp4.setBounds(270, 335, 250, 40); jp5=new JPanel(); jp5.setBounds(270, 380, 250, 30); dept.add("經理"); dept.add("部門主管"); dept.add("普通員工"); account=new JLabel("賬 戶"); password=new JLabel("密 碼"); login=new JLabel("用 戶 "); backimg=new JLabel(new ImageIcon("images\\back.jpg")); backimg1=new JLabel(new ImageIcon("images\\back1.jpg")); tiplabel=new JLabel(); tiplabel.setFont(new Font("宋體", Font.PLAIN, 12)); tiplabel.setForeground(Color.red); tiplabel.setVisible(false); passwordnum=new JPasswordField(12); accountnum=new JTextField(12); loginbutton=new JButton("登 錄"); loginbutton.setOpaque(false); loginbutton.setContentAreaFilled(false); resetbutton=new JButton("重 置"); resetbutton.setOpaque(false); resetbutton.setContentAreaFilled(false); exitbutton =new JButton("退 出"); exitbutton.setOpaque(false); exitbutton.setContentAreaFilled(false); loginchoice =new JComboBox(dept); jp.add(backimg); jp0.add(backimg1); jp1.add(account); jp1.add(accountnum); jp2.add(password); jp2.add(passwordnum); jp3.add(login); jp3.add(loginchoice); jp4.add(loginbutton); jp4.add(resetbutton); jp4.add(exitbutton); jp5.add(tiplabel); this.add(jp); this.add(jp0); this.add(jp1); this.add(jp2); this.add(jp3); this.add(jp4); this.add(jp5); this.setTitle("系統登錄"); this.setLayout(null); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setResizable(false); this.setBounds(320, 160, 550, 450); this.setIconImage(new ImageIcon("images\\icon.jpg").getImage()); this.setVisible(true); } /**====================================================** * **[## private void enevtOperation() {}] 事件處理 * 參數 :無 * 返回值 :無 * 修飾符 :public * 功能 :登錄窗口的事件操作 **===================================================**/ public void enevtOperation(final MyLoginJframe mj) { /**=======================================================** * 登錄按鈕監聽事件 **========================================================*/ loginbutton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if(loginCheck()) { tiplabel.setText("正 在 登 錄..."); //記錄當前的操作記錄 id_now=accountnum.getText(); user_type=loginchoice.getSelectedItem().toString(); MyHotelMainGui mm=new MyHotelMainGui(); //登錄到主界面 mj.dispose(); //顯示當前的操作人員信息 mm.setId_now(id_now); mm.setUser_type(user_type); mm.enevtOpration(); mm.updateRoomState(); Thread th=new Thread(mm); th.start(); } else if(accountnum.getText().isEmpty() && passwordnum.getPassword().length==0) tiplabel.setText("密碼與賬號不能為空!"); else if(accountnum.getText().isEmpty() && passwordnum.getPassword().length!=0) tiplabel.setText("請輸入賬號..."); else if(accountnum.getText().isEmpty()==false && passwordnum.getPassword().length==0) tiplabel.setText("請輸入密碼..."); else tiplabel.setText("請檢查后重新輸入!"); tiplabel.setVisible(true); } }); /**=======================================================** * 重置按鈕監聽事件 **========================================================*/ resetbutton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub accountnum.setText(""); passwordnum.setText(""); loginchoice.setSelectedIndex(0); } }); /**=======================================================** * 退出按鈕監聽事件 **========================================================*/ exitbutton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub quit(); } }); } /**====================================================** * **[## private boolean loginCheck() {}] 登陸驗證 * 參數 :無 * 返回值 :flag * 修飾符 :private * 功能 :登錄驗證,僅類內使用 **===================================================**/ public boolean loginCheck() { boolean flag=false; if(loginchoice.getSelectedIndex()==0) { try { dc.Sql("select id,pass_word from mangerers_table"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } if(loginchoice.getSelectedIndex()==1) { try { dc.Sql("select id,pass_word from dept_table"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } if(loginchoice.getSelectedIndex()==2) { try { dc.Sql("select id,pass_word from common_table"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } for(int i=0;i<dc.getId().size();i++) { String password=new String(passwordnum.getPassword()); if(accountnum.getText().equals(dc.getId().get(i).toString()) && password.equals(dc.getPassword().get(i).toString())) { flag=true; break; } } return flag; } /**====================================================** * **[## private void quit() {}] 系統退出 * 參數 :無 * 返回值 :無 * 修飾符 :private * 功能 :關閉系統函數,僅類內使用 **===================================================**/ private void quit() { int flag=0; String msg="你 確 定 要 關 閉 系 統 嗎?"; flag=JOptionPane.showConfirmDialog(null, msg,"提示",JOptionPane.YES_NO_OPTION); if(flag==JOptionPane.YES_OPTION) { this.setVisible(false); System.exit(0); } return; } @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub } }
3.主界面類
/**====================================================** * 項目名 :酒店管理系統 * 模塊名 :系統登錄成功后的主窗口 * 文件名 :HotelMainGui.java * 相關文件 :HotelLoginGui.java DataBaseConnect.java * 實現功能 :系統登錄成功后主界面 * 函數說明 : * [## public MyHotelMainGui(int i){}]: * 功能:構造函數 * [## public MyHotelMainGui(){}]: * 功能:構造函數 組建登陸窗口 * [## private boolean loginCheck() {}]: * 功能:登錄驗證,僅類內使用 * [## private void quit() {}]: * 功能:關閉系統函數,僅類內使用 * [## public void run(){}] * 功能:線程執行刷新界面 * [## public void setLabelText(JLabel jl,int row)] * 功能:為JLabel設置text **===================================================**/ package com.HotelGui; import java.awt.*; import com.common.DataBaseConnect; import com.databasejdbc.*; import javax.swing.*; import java.text.SimpleDateFormat; import java.util.*; import java.awt.event.*; public class MyHotelMainGui extends JFrame implements ActionListener,Runnable { public MyHotelMainGui(int i) { } private static final FocusListener FocusListener = null; String roomnum,roomtype; JPopupMenu popupMenu; JMenuBar jmb; JPanel jp1,jp2,room_jp1; JLabel time_jl,order_jl,login_jl,change_jl,checkout_jl,relogin_jl,money_jl,exit_jl,emploer_jl; JMenu jm1,jm2,jm3,jm4,jm5,jm6,jm7,jm8,bt_jm; JButton time_bt,order_bt,login_bt,change_bt,checkout_bt,relogin_bt,money_bt,exit_bt,emploer_bt,oneF_bt,twoF_bt,threeF_bt,fourF_bt; Vector<JButton> roomjb=new Vector<JButton>(); Vector<JPopupMenu> popupVector=new Vector<JPopupMenu>(); JLabel statelabel,state,staticsstate; JButton jj; JLabel allroom_jl,empty_jl,ordered_jl,isliv_jl,else_jl,allroom_jl1,empty_jl1,ordered_jl1,isliv_jl1,else_jl1; String id_now,user_type; /**=======================================================** * 獲取當前成功登錄的ID **========================================================*/ public String getId_now() { return id_now; } /**=======================================================** * 獲取當前成功登錄的用戶類型 **========================================================*/ public String getUser_type() { return user_type; } /**=======================================================** * 設置當前成功登錄的ID **========================================================*/ public void setId_now(String id_now) { this.id_now = id_now; } /**=======================================================** * 設置當前成功登錄的用戶類型 **========================================================*/ public void setUser_type(String user_type) { this.user_type = user_type; } /**====================================================** * **[## public MyHotelMainGui() {}] 構造函數 * 參數 :無 * 返回值 :無 * 修飾符 :public * 功能 :構造函數,初始化主界面 **===================================================**/ public MyHotelMainGui() { //為每個房間設置點擊事件 for( int i=0;i<32;i++) { final String str; if(i<10) { str="40"+(i+1); } else { str="4"+(i+1); } popupMenu = new JPopupMenu (); popupVector.add(popupMenu); JMenuItem orderMenuItem = new JMenuItem ("新預定") ; orderMenuItem.setFont(new Font("宋體",Font.ITALIC,14)); popupVector.get(i).add ( orderMenuItem ) ; //添加事件 orderMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub CheckIn ck=new CheckIn("預訂登記","images\\checkin_bt.jpg"); ck.room_num_jf.setText(str); ck.cancelButton(); //登記入住 ck.checkinButton(1); updateRoomState(); } }); JMenuItem checkinMenuItem = new JMenuItem ("入住登記") ; checkinMenuItem.setFont(new Font("宋體",Font.ITALIC,14)); popupVector.get(i).add ( checkinMenuItem ) ; checkinMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub CheckIn ck=new CheckIn("入住登記","images\\checkin_bt.jpg"); ck.room_num_jf.setText(str); ck.cancelButton(); //登記入住 ck.checkinButton(2); updateRoomState(); } }); // Separator popupMenu.addSeparator () ; JMenuItem changeMenuItem = new JMenuItem ("客人換房") ; changeMenuItem.setFont(new Font("宋體",Font.ITALIC,14)); popupVector.get(i).add ( changeMenuItem ) ; changeMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub ChangeRoom cr=new ChangeRoom("客人換房","images\\change_bt.jpg"); cr.check_bt.setVisible(false); cr.jtf.setText(str); try { cr.check_Bt("房間未入住!"); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }); JMenuItem msgMenuItem = new JMenuItem ("客人信息") ; msgMenuItem.setFont(new Font("宋體",Font.ITALIC,14)); popupVector.get(i).add ( msgMenuItem ) ; msgMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub CheckMsg cm=new CheckMsg("客人信息","images\\"); cm.check_bt.setVisible(false); cm.jtf.setText(str); try { cm.check_Bt("房間未入住!"); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }); JMenuItem reckMenuItem = new JMenuItem ("客人續住") ; reckMenuItem.setFont(new Font("宋體",Font.ITALIC,14)); popupVector.get(i).add ( reckMenuItem ) ; popupMenu.addSeparator () ; JMenuItem checkoutMenuItem = new JMenuItem ("客人退房") ; checkoutMenuItem.setFont(new Font("宋體",Font.ITALIC,14)); popupVector.get(i).add ( checkoutMenuItem ) ; checkoutMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub CheckOut co=new CheckOut("客人退房","images\\checkout_bt.jpg"); co.check_bt.setVisible(false); co.jtf.setText(str); try { co.check_Bt("房間未入住!"); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }); } oneF_bt=new JButton(new ImageIcon("images\\1F.jpg")); oneF_bt.setBounds(20, 170, 60,50); twoF_bt=new JButton(new ImageIcon("images\\2F.jpg")); twoF_bt.setBounds(20, 250, 60,50); threeF_bt=new JButton(new ImageIcon("images\\3F.jpg")); threeF_bt.setBounds(20, 330, 60,50); fourF_bt=new JButton(new ImageIcon("images\\4F.jpg")); fourF_bt.setBounds(20, 410, 60,50); for(int i=0;i<32;i++) { JButton jb=new JButton(); roomjb.add(jb); if(i<8) roomjb.get(i).setBounds(90*i, 0, 90, 90); else if(i<16) roomjb.get(i).setBounds(90*(i-8), 90, 90, 90); else if(i<24) roomjb.get(i).setBounds(90*(i-16), 180, 90, 90); else roomjb.get(i).setBounds(90*(i-24), 270, 90, 90); roomjb.get(i).setContentAreaFilled(false); roomjb.get(i).setComponentPopupMenu (popupVector.get(i)); } //放置房間的JPanel room_jp1=new JPanel(); room_jp1.setLayout(null); room_jp1.setBounds(120, 150, 730, 367); allroom_jl=new JLabel(new ImageIcon("images\\all.jpg")); allroom_jl1=new JLabel(); allroom_jl.setBounds(950, 150, 75, 30); allroom_jl1.setBounds(1110, 150, 75, 30); empty_jl=new JLabel(new ImageIcon("images\\empty.jpg")); empty_jl1=new JLabel(); empty_jl.setBounds(950, 200, 75, 30); empty_jl1.setBounds(1110, 200, 75, 30); ordered_jl=new JLabel(new ImageIcon("images\\order.jpg")); ordered_jl1=new JLabel(); ordered_jl.setBounds(950, 250, 75, 30); ordered_jl1.setBounds(1110, 250, 75, 30); isliv_jl=new JLabel(new ImageIcon("images\\isliv.jpg")); isliv_jl1=new JLabel(); isliv_jl.setBounds(950, 300, 75, 30); isliv_jl1.setBounds(1110, 300, 75, 30); else_jl=new JLabel(new ImageIcon("images\\else.jpg")); else_jl1=new JLabel(); else_jl1.setBounds(1110, 350, 75, 30); else_jl.setBounds(950, 350, 75, 30); state=new JLabel("實時房態統計"); state.setFont(new Font("宋體",Font.PLAIN,14)); state.setBounds(1000, 90, 100, 40); staticsstate=new JLabel(); staticsstate.setFont(new Font("宋體",Font.PLAIN,25)); staticsstate.setBounds(970, 420, 250, 60); staticsstate.setForeground(Color.red); jp2=new JPanel(); jp2.setBounds(10, 570, 950, 50);//底部登錄狀態顯示 statelabel=new JLabel(); statelabel.setFont(new Font("宋體",Font.CENTER_BASELINE,12)); jp2.add(statelabel); time_jl=new JLabel("實時房態"); time_jl.setFont(new Font("宋體",Font.LAYOUT_NO_LIMIT_CONTEXT,10)); time_jl.setBounds(10, 53, 40, 10); time_bt=new JButton(new ImageIcon("images\\實時房態.jpg")); time_bt.setBounds(10, 10, 40, 40); time_bt.setBorderPainted(false); order_bt=new JButton(new ImageIcon("images\\預定登記.jpg")); order_bt.setBounds(65, 10, 40, 40); order_bt.setBorderPainted(false); order_jl=new JLabel("預定登記"); order_jl.setFont(new Font("宋體",Font.LAYOUT_NO_LIMIT_CONTEXT,10)); order_jl.setBounds(65, 53, 40, 10); login_bt=new JButton(new ImageIcon("images\\入住登記.jpg")); login_bt.setBounds(120, 10, 40, 40); login_bt.setBorderPainted(false); login_jl=new JLabel("入住登記"); login_jl.setFont(new Font("宋體",Font.LAYOUT_NO_LIMIT_CONTEXT,10)); login_jl.setBounds(120, 53, 40, 10); change_bt=new JButton(new ImageIcon("images\\客人換房.jpg")); change_bt.setBounds(175, 10, 40, 40); change_bt.setBorderPainted(false); change_jl=new JLabel("客人換房"); change_jl.setFont(new Font("宋體",Font.LAYOUT_NO_LIMIT_CONTEXT,10)); change_jl.setBounds(175, 53, 40, 10); relogin_bt=new JButton(new ImageIcon("images\\客房續住.jpg")); relogin_bt.setBounds(230, 10, 40, 40); relogin_bt.setBorderPainted(false); relogin_jl=new JLabel("客人續住"); relogin_jl.setFont(new Font("宋體",Font.LAYOUT_NO_LIMIT_CONTEXT,10)); relogin_jl.setBounds(230, 53, 40, 10); checkout_jl=new JLabel("客人退房"); checkout_jl.setFont(new Font("宋體",Font.LAYOUT_NO_LIMIT_CONTEXT,10)); checkout_jl.setBounds(285, 53, 40, 10); checkout_bt=new JButton(new ImageIcon("images\\客人退房.jpg")); checkout_bt.setBounds(285, 10, 40, 40); checkout_bt.setBorderPainted(false); money_bt=new JButton(new ImageIcon("images\\收銀報表.jpg")); money_bt.setBounds(340, 10, 40, 40); money_bt.setBorderPainted(false); money_jl=new JLabel("財務報表"); money_jl.setFont(new Font("宋體",Font.LAYOUT_NO_LIMIT_CONTEXT,10)); money_jl.setBounds(340, 53, 40, 10); exit_bt=new JButton(new ImageIcon("images\\退出系統.png")); exit_bt.setBounds(450, 10, 40, 40); exit_bt.setBorderPainted(false); exit_jl=new JLabel("退出系統"); exit_jl.setFont(new Font("宋體",Font.LAYOUT_NO_LIMIT_CONTEXT,10)); exit_jl.setBounds(450, 53, 40, 10); emploer_bt=new JButton(new ImageIcon("images\\員工管理.jpg")); emploer_bt.setBounds(395, 10, 40, 40); emploer_bt.setBorderPainted(false); emploer_jl=new JLabel("員工管理"); emploer_jl.setFont(new Font("宋體",Font.LAYOUT_NO_LIMIT_CONTEXT,10)); emploer_jl.setBounds(395, 53, 40, 10); jm1=new JMenu("預訂接待(A)"); jm1.setFont(new Font("宋體",Font.LAYOUT_NO_LIMIT_CONTEXT,12)); jm2=new JMenu("前臺營業(B)"); jm2.setFont(new Font("宋體",Font.LAYOUT_NO_LIMIT_CONTEXT,12)); jm3=new JMenu("客戶管理(C)"); jm3.setFont(new Font("宋體",Font.LAYOUT_NO_LIMIT_CONTEXT,12)); jm4=new JMenu("員工管理(D)"); jm4.setFont(new Font("宋體",Font.LAYOUT_NO_LIMIT_CONTEXT,12)); jm5=new JMenu("財務報表(E)"); jm5.setFont(new Font("宋體",Font.LAYOUT_NO_LIMIT_CONTEXT,12)); jm6=new JMenu("綜合查詢(Z)"); jm6.setFont(new Font("宋體",Font.LAYOUT_NO_LIMIT_CONTEXT,12)); jm7=new JMenu("窗口(P)"); jm7.setFont(new Font("宋體",Font.LAYOUT_NO_LIMIT_CONTEXT,12)); jm8=new JMenu("幫助(H)"); jm8.setFont(new Font("宋體",Font.LAYOUT_NO_LIMIT_CONTEXT,12)); jmb=new JMenuBar(); jmb.add(jm1); jmb.add(jm2); jmb.add(jm3); jmb.add(jm4); jmb.add(jm5); jmb.add(jm6); jmb.add(jm7); jmb.add(jm8); for(int i=0;i<32;i++) { room_jp1.add(roomjb.get(i)); } this.add(oneF_bt); this.add(twoF_bt); this.add(threeF_bt); this.add(fourF_bt); this.add(time_bt); this.add(order_bt); this.add(login_bt); this.add(change_bt); this.add(relogin_bt); this.add(change_bt); this.add(checkout_bt); this.add(money_bt); this.add(exit_bt); this.add(emploer_bt); this.add(time_jl); this.add(order_jl); this.add(login_jl); this.add(change_jl); this.add(relogin_jl); this.add(change_jl); this.add(checkout_jl); this.add(money_jl); this.add(exit_jl); this.add(emploer_jl); this.add(jp2); this.add(state); this.add(allroom_jl); this.add(empty_jl); this.add(isliv_jl); this.add(ordered_jl); this.add(else_jl); this.add(allroom_jl1); this.add(empty_jl1); this.add(isliv_jl1); this.add(ordered_jl1); this.add(else_jl1); this.add(staticsstate); this.setResizable(false); this.setIconImage(new ImageIcon("images\\icon.jpg").getImage()); this.setTitle("I酒店管理系統"+"——"+"["+"實時房態"+"]"); this.setFont(new Font("宋體",Font.LAYOUT_NO_LIMIT_CONTEXT,12)); this.setJMenuBar(jmb); this.setLocation(50, 50); this.setLayout(null); this.add(room_jp1); this.setSize(Toolkit.getDefaultToolkit().getScreenSize().width-100,Toolkit.getDefaultToolkit().getScreenSize().height-100); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); } @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub } /**====================================================** * **[## public void enevtOpration {}] 主窗體上的事件監聽 * 參數 :無 * 返回值 :無 * 修飾符 :public * 功能 :監聽用戶在主窗體中的操作 **===================================================**/ public void enevtOpration() { order_bt.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { // TODO Auto-generated method stub CheckIn ck=new CheckIn("預訂登記","images\\checkin_bt.jpg"); ck.cancelButton(); //登記入住 ck.checkinButton(1); updateRoomState(); } @Override public void mousePressed(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseReleased(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseEntered(MouseEvent e) { // TODO Auto-generated method stub order_bt.setBorderPainted(true); } @Override public void mouseExited(MouseEvent e) { // TODO Auto-generated method stub order_bt.setBorderPainted(false); } }); login_bt.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { // TODO Auto-generated method stub CheckIn ck=new CheckIn("入住登記","images\\checkin_bt.jpg"); ck.cancelButton(); //登記入住 ck.checkinButton(2); updateRoomState(); } @Override public void mousePressed(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseReleased(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseEntered(MouseEvent e) { // TODO Auto-generated method stub login_bt.setBorderPainted(true); } @Override public void mouseExited(MouseEvent e) { // TODO Auto-generated method stub login_bt.setBorderPainted(false); } }); change_bt.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { // TODO Auto-generated method stub ChangeRoom cr=new ChangeRoom("客人換房", "images\\change_bt.jpg"); updateRoomState(); repaint(); } @Override public void mousePressed(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseReleased(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseEntered(MouseEvent e) { // TODO Auto-generated method stub change_bt.setBorderPainted(true); } @Override public void mouseExited(MouseEvent e) { // TODO Auto-generated method stub change_bt.setBorderPainted(false); } }); relogin_bt.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mousePressed(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseReleased(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseEntered(MouseEvent e) { // TODO Auto-generated method stub relogin_bt.setBorderPainted(true); } @Override public void mouseExited(MouseEvent e) { // TODO Auto-generated method stub relogin_bt.setBorderPainted(false); } }); checkout_bt.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { // TODO Auto-generated method stub CheckOut co=new CheckOut("客人退房","images\\checkout_bt.jpg"); } @Override public void mousePressed(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseReleased(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseEntered(MouseEvent e) { // TODO Auto-generated method stub checkout_bt.setBorderPainted(true); } @Override public void mouseExited(MouseEvent e) { // TODO Auto-generated method stub checkout_bt.setBorderPainted(false); } }); money_bt.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mousePressed(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseReleased(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseEntered(MouseEvent e) { // TODO Auto-generated method stub money_bt.setBorderPainted(true); } @Override public void mouseExited(MouseEvent e) { // TODO Auto-generated method stub money_bt.setBorderPainted(false); } }); emploer_bt.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mousePressed(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseReleased(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseEntered(MouseEvent e) { // TODO Auto-generated method stub emploer_bt.setBorderPainted(true); } @Override public void mouseExited(MouseEvent e) { // TODO Auto-generated method stub emploer_bt.setBorderPainted(false); } }); exit_bt.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { // TODO Auto-generated method stub quit(); } @Override public void mousePressed(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseReleased(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseEntered(MouseEvent e) { // TODO Auto-generated method stub exit_bt.setBorderPainted(true); } @Override public void mouseExited(MouseEvent e) { // TODO Auto-generated method stub exit_bt.setBorderPainted(false); } }); time_bt.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { // TODO Auto-generated method stub updateRoomState(); } @Override public void mousePressed(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseReleased(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseEntered(MouseEvent e) { // TODO Auto-generated method stub time_bt.setBorderPainted(true); } @Override public void mouseExited(MouseEvent e) { // TODO Auto-generated method stub time_bt.setBorderPainted(false); } }); } /**====================================================** * **[## public void run() {}] 線程執行,隨著系統改變當前時間 * 參數 :無 * 返回值 :無 * 修飾符 :public * 功能 :使用線程使當前界面時間隨著系統改變當 **===================================================**/ public void run() { // TODO Auto-generated method stub SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); while(true) { statelabel.setText("當前時間為:"+df.format(new Date())+" "+"當前登錄的用戶為:"+id_now+" "+"用戶類型為:"+user_type); statelabel.repaint(); this.repaint(); } } /**====================================================** * **[## private void quit() {}] 系統退出 * 參數 :無 * 返回值 :無 * 修飾符 :private * 功能 :關閉系統函數,僅類內使用 **===================================================**/ private void quit() { int flag=0; String msg="你 確 定 要 關 閉 系 統 嗎?"; flag=JOptionPane.showConfirmDialog(null, msg,"提示",JOptionPane.YES_NO_OPTION); if(flag==JOptionPane.YES_OPTION) { this.setVisible(false); System.exit(0); } return; } /**====================================================** * **[## public void setLabelText(JLabel jl,int row) {}] 為JLabel設置text * 返回值 :無 * 修飾符 :public * 功能 :為JLabel設置text **===================================================**/ public void setLabelText(JLabel jl,int row) { try{ jl.setText(Integer.toString(row)+" "+"間"); }catch(Exception e){} } /**====================================================** * **[## public void updateRoomState{}] 更新入住狀態 * 返回值 :無 * 修飾符 :public * 功能 :更新入住統計情況 **=================================================== * @throws Exception **/ public void updateRoomState() { DataBaseConnect ns=new DataBaseConnect(); Vector<Vector> returndata = null; try { setLabelText(allroom_jl1, ns.getRow("select * from room_table")); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } int tol=1; try { tol = ns.getRow("select * from room_table"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } try { setLabelText(empty_jl1, ns.getRow("select * from room_table where roomatate=0")); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } try { setLabelText(ordered_jl1, ns.getRow("select * from room_table where roomatate=1")); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } try { setLabelText(isliv_jl1, ns.getRow("select * from room_table where roomatate=2")); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } int isl=1; try { isl = ns.getRow("select * from room_table where roomatate=2"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } try { setLabelText(else_jl1, ns.getRow("select * from room_table where roomatate=3")); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } try { staticsstate.setText("入 住 率 :"+ " "+(int)(isl*100/tol)+"%"); returndata=ns.RoomOperation(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } for(int i=0;i<returndata.get(0).size();i++) { try{ roomjb.get(i).setText("<html>" +returndata.get(0).get(i)+"<br>"+returndata.get(1).get(i)+"</html>"); }catch(Exception e){} try{ if(returndata.get(2).get(i).equals(0)) roomjb.get(i).setForeground(Color.GREEN); else if(returndata.get(2).get(i).equals(1)) roomjb.get(i).setForeground(Color.pink); else roomjb.get(i).setForeground(Color.red); }catch(Exception e){} repaint(); } } }
4.登記-換房-退房等父類
/**====================================================** * 項目名 :酒店管理系統 * 模塊名 :入住登記窗口與預定登記窗口 * 文件名 :CheckIn.java * 相關文件 :DataBaseConnct.java * 實現功能 :入住登記或預定登記并寫入數據庫 * 函數說明 : * [## public CheckIn(){}]: * 功能:構造函數 組建入住登記窗口 * * [## public void cancelButton(){}] * 功能:取消按鈕的事件監聽處理 * * [## returnButton{}]: * 功能:返回按鈕的事件監聽處理 * * [## public void checkinButton(final int flag){}]: * 功能:確定登記按鈕的事件監聽處理 * **===================================================**/ package com.databasejdbc; import com.HotelGui.MyHotelMainGui; import com.common.*; import java.util.*; import java.awt.*; import java.awt.Event.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import javax.swing.*; public class CheckIn extends JFrame { JLabel name_jl,gender_jl,id_jl,room_num_jl,room_type_jl,checkin_jl,checkout_jl,tital_jl,tip_jl,price_jl,charge_jl,despoit_jl,tip_jl1,tip_jl2; JButton checkin_bt,cancel_bt,return_bt; JComboBox<String> gender_jb,room_type_jb; JTextField name_jf,id_jf; public JTextField room_num_jf; JTextField price_jf; JTextField despoit_jf; JTextField charge_jf; JTextField checkin_jf; JTextField checkout_jf; public static void main(String[] args) { // TODO Auto-generated method stub CheckIn ck=new CheckIn("入住登記","images\\checkin_bt.jpg"); ck.cancelButton(); //ck.checkinButton(); } /**====================================================** * **[## public CheckIn(){}] 構造函數 * 參數 :String str1,String path //界面Tital、按鈕UI地址 * 返回值 :無 * 修飾符 :public * 功能 :構造函數,初始化入住登記界面 **===================================================**/ public CheckIn(String str1,String path) { tital_jl=new JLabel(str1); tital_jl.setBounds(300,20, 100, 60); tital_jl.setFont(new Font("宋體",Font.BOLD,23)); tip_jl=new JLabel("(以下信息請完整填寫)"); tip_jl.setBounds(270,70, 200, 30); tip_jl.setFont(new Font("宋體",Font.HANGING_BASELINE,14)); name_jl=new JLabel("姓 名"); name_jl.setBounds(150, 170, 60, 30); name_jl.setFont(new Font("宋體",Font.HANGING_BASELINE,14)); name_jf=new JTextField(10); name_jf.setBounds(230, 170, 140, 27); id_jl=new JLabel("身份證號"); id_jl.setBounds(450, 170, 60, 30); id_jl.setFont(new Font("宋體",Font.HANGING_BASELINE,14)); id_jf=new JTextField(10); id_jf.setBounds(530, 170, 140, 27); gender_jl=new JLabel("性 別"); gender_jl.setBounds(150, 220, 60, 30); gender_jl.setFont(new Font("宋體",Font.HANGING_BASELINE,14)); gender_jb=new JComboBox<String>(); gender_jb.setBounds(230, 220, 140, 27); gender_jb.addItem("男"); gender_jb.addItem("女"); room_num_jl=new JLabel("房 間 號"); room_num_jl.setBounds(450, 220, 60, 30); room_num_jl.setFont(new Font("宋體",Font.HANGING_BASELINE,14)); room_num_jf=new JTextField(10); room_num_jf.setBounds(530, 220, 140, 27); room_type_jl=new JLabel("房間標準"); room_type_jl.setBounds(150, 270, 60, 30); room_type_jl.setFont(new Font("宋體",Font.HANGING_BASELINE,14)); room_type_jb=new JComboBox<String>(); room_type_jb.setBounds(230, 270, 140, 27); room_type_jb.addItem("商務單間"); room_type_jb.addItem("商務標間"); room_type_jb.addItem("大床房"); room_type_jb.addItem("雜物間"); price_jl=new JLabel("房間價格"); price_jl.setBounds(450, 270, 60, 30); price_jl.setFont(new Font("宋體",Font.HANGING_BASELINE,14)); price_jf=new JTextField(10); price_jf.setBounds(530, 270, 140, 27); charge_jl=new JLabel("實際收費"); charge_jl.setBounds(150, 320, 60, 30); charge_jl.setFont(new Font("宋體",Font.HANGING_BASELINE,14)); charge_jf=new JTextField(10); charge_jf.setBounds(230, 320, 140, 27); despoit_jl=new JLabel("預收押金"); despoit_jl.setBounds(450, 320, 60, 30); despoit_jl.setFont(new Font("宋體",Font.HANGING_BASELINE,14)); despoit_jf=new JTextField(10); despoit_jf.setBounds(530, 320, 140, 27); checkin_jl=new JLabel("入住日期"); tip_jl1=new JLabel("(####-##-##)"); tip_jl1.setBounds(145, 400, 80, 40); checkin_jl.setBounds(150, 370, 60, 40); checkin_jl.setFont(new Font("宋體",Font.HANGING_BASELINE,14)); checkin_jf=new JTextField(10); checkin_jf.setBounds(230, 370, 140, 27); checkout_jl=new JLabel("離店日期"); tip_jl2=new JLabel("(####-##-##)"); tip_jl2.setBounds(445, 400, 80, 40); checkout_jl.setBounds(450, 370, 60, 30); checkout_jl.setFont(new Font("宋體",Font.HANGING_BASELINE,14)); checkout_jf=new JTextField(10); checkout_jf.setBounds(530, 370, 140, 27); checkin_bt=new JButton(new ImageIcon(path)); checkin_bt.setBounds(160, 500, 85, 30); checkin_bt.setOpaque(false); cancel_bt=new JButton(new ImageIcon("images\\cancel_bt.jpg")); cancel_bt.setBounds(345, 500, 85, 30); cancel_bt.setOpaque(false); return_bt=new JButton(new ImageIcon("images\\return_bt.jpg")); return_bt.setBounds(530, 500, 85, 30); return_bt.setOpaque(false); return_bt.setActionCommand("1"); /**========================================** * 返回按鈕注冊監聽 =========================================*/ return_bt.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if(e.getActionCommand().equals("1")) returnButton(); } }); this.setLayout(null); this.add(tital_jl); this.add(tip_jl); this.add(name_jl); this.add(name_jf); this.add(id_jl); this.add(gender_jl); this.add(room_num_jl); this.add(room_type_jl); this.add(price_jl); this.add(charge_jl); this.add(despoit_jl); this.add(checkin_jl); this.add(tip_jl1); this.add(checkout_jl); this.add(tip_jl2); this.add(checkin_bt); this.add(cancel_bt); this.add(return_bt); this.add(id_jf); this.add(gender_jb); this.add(room_num_jf); this.add(room_type_jb); this.add(price_jf); this.add(charge_jf); this.add(despoit_jf); this.add(checkin_jf); this.add(checkout_jf); this.setTitle(str1); this.setIconImage(new ImageIcon("images\\入住登記.jpg").getImage()); this.setBounds(250, 80, Toolkit.getDefaultToolkit().getScreenSize().width-600,Toolkit.getDefaultToolkit().getScreenSize().height-150); this.setResizable(false); this.setVisible(true); } /**====================================================** * **[## public void cancelButton() {}] 取消按鈕操作 * 參數 :無 * 返回值 :無 * 修飾符 :public * 功能 :點擊取消按鈕清空操作 **===================================================**/ public void cancelButton() { cancel_bt.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub name_jf.setText(""); id_jf.setText(""); room_num_jf.setText(""); charge_jf.setText(""); price_jf.setText(""); despoit_jf.setText(""); checkin_jf.setText(""); checkout_jf.setText(""); gender_jb.setSelectedIndex(0); room_type_jb.setSelectedIndex(0); } }); } /**====================================================** * **[## public void returnButton() {}] 返回按鈕操作 * 參數 :無 * 返回值 :無 * 修飾符 :public * 功能 :點擊返回按鈕返回到主界面,入住登記界面釋放 **===================================================**/ public void returnButton() { this.dispose(); } /**====================================================** * **[## public void checkinButton(int flag) {}] 確定按鈕操作 * 參數 :int flag flag==1,則表示入住登記狀態更改 ;flag==2,則表示預訂登記狀態更改 * 返回值 :無 * 修飾符 :public * 功能 :點擊確定按鈕進行入住登記輸入數據庫操作操作 **===================================================**/ public void checkinButton(final int flag) { checkin_bt.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub DataBaseConnect dc=new DataBaseConnect(); String str=new String(Integer.valueOf(room_num_jf.getText())+",\'"+name_jf.getText()+"\',\'"+gender_jb.getSelectedItem().toString()+"\',\'"+ id_jf.getText()+"\',\'"+checkin_jf.getText()+"\',\'"+checkout_jf.getText()+"\',"+Integer.valueOf(charge_jf.getText())+","+Integer.valueOf(despoit_jf.getText())+","+1); try { dc.insertData("costomer_table", str); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } String sql="update room_table set roomatate="+flag+" where roomnum="+Integer.valueOf(room_num_jf.getText()); try { dc.updateData(sql); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } JOptionPane.showConfirmDialog(null, "登記成功!","提示",JOptionPane.CLOSED_OPTION); int option=0; if(option==JOptionPane.YES_OPTION) { try{ MyHotelMainGui hm=new MyHotelMainGui(1); hm.updateRoomState(); Thread th=new Thread(hm); th.start(); } catch(Exception e1) {} } } }); } }
源代碼比較多,就不再上傳了,歡迎交流,共同學習進步。項目全部資源需要可從此下載:java實現酒店管理系統
更多學習資料請關注專題《管理系統開發》。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持億速云。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。