《酒店管理系统4905423727.docx》由会员分享,可在线阅读,更多相关《酒店管理系统4905423727.docx(20页珍藏版)》请在三一办公上搜索。
1、自选题目设计一:酒店管理系统程序代码1.数据库的实现创建系统用户表格 Roomtypecreate database hotelgouse hotelgoCREATE TABLE Roomtype (Typeid Varchar (10)primary key,Typename Varchar (16) ,Bednum SMALLINT,Price INT,) insert into Roomtype values(LX0001,标准单人间,1,100)insert into Roomtype values(LX0002,标准双人间,2,160)insert into Roomtype val
2、ues(LX0003,豪华单人间,1,200)insert into Roomtype values(LX0004,豪华双人间,2,360)insert into Roomtype values(LX0005,商务套房,1,1000)insert into Roomtype values(LX0006,总统套房,2,2000)创建客房信息表格RoomsCREATE TABLE Rooms (RoomNOVarchar(10) primary key,Typeid Varchar (10) NOT NULL,RoompositionVarchar(5)NULL,PutupVarchar(5)NO
3、T NULL,FOREIGN KEY(Typeid) REFERENCES Roomtype(Typeid) 2. 登录功能实现该模块只要是为了方便酒店管理员的操作,界面友好,简单易操作。需要有一定的美观性和可操作性。同时为了保证安全性,我们设定了权限功能,管理员可以使用全部功能,而普通用户不能使用系统管理功能,所以普通用户不能增减客房信息,同时,也不能增减系统的用户。图4 主界面主代码如下package UI;import java.awt.*;import java.awt.event.*;import java.sql.*;import java.util.*;import UI.*;p
4、ublic class mainFrame extends JFrameprivate JButton bt1,bt2,bt3,bt4,bt5;private JTextField tf1,tf2;private int wholepart;public mainFrame() super ( 金翎酒店欢迎您!);JPanel panelMain,panelCent,panelNort,panelBottom;panelMain = new JPanel(new BorderLayout();panelNort = buildNorth();panelCent = buildDTM();pan
5、elMain.add(panelNort,BorderLayout.NORTH);panelMain.add(panelCent);setContentPane(panelMain);setSize (780,620);setVisible(true);private JPanel buildNorth() JPanel panelNort1 = new JPanel();Icon bug1= new ImageIcon(pic/m01.gif);Icon bug2= new ImageIcon(pic/m04.gif);Icon bug3= new ImageIcon(pic/m05.gif
6、);Icon bug4= new ImageIcon(pic/m06.gif);Icon bug5= new ImageIcon(pic/m07.gif);bt1 = new JButton ( 客户预定, bug3);bt2 = new JButton ( 入住登记, bug2);bt3 = new JButton ( 客户结账, bug1);bt4 = new JButton ( 营业查询, bug4);bt5 = new JButton ( 系统管理, bug5);panelNort1.add(bt1);panelNort1.add(bt2);panelNort1.add(bt3);pa
7、nelNort1.add(bt4);panelNort1.add(bt5);Buttonhandler handler = new Buttonhandler();bt1.addActionListener(handler);bt2.addActionListener(handler);bt3.addActionListener(handler);bt4.addActionListener(handler);bt5.addActionListener(handler);return panelNort1;private JPanel buildDTM () JPanel panelCent1
8、= new JPanel(new BorderLayout();tf1 = new JTextField(20);tf1.setForeground(Color.yellow);tf1.setBackground(Color.red);tf1.setText(金翎酒店欢迎您!);tf1.setFont( new Font(楷体,Font.BOLD,20);tf1.setHorizontalAlignment (JTextField.CENTER);tf1.setBorder(new LineBorder(new Color(87,87,47);tf1.setEditable(false);pa
9、nelCent1.add(North,tf1);JPanel panelBottom1 = new JPanel(new BorderLayout();final ImageIcon imageIcon = new ImageIcon(pic/jiudian.jpg); JPanel p = new JPanel() / 获取图片 Image image = imageIcon.getImage(); public void paint(Graphics g) / 绘制图片 g.drawImage(image, 0, 0, this.getWidth(), this.getHeight(),t
10、his); JScrollPane scrollPane = new JScrollPane(p); panelBottom1.add(panelCent1,BorderLayout.NORTH); panelBottom1.add(scrollPane,BorderLayout.CENTER);return panelBottom1;public void setwholepart(int a) wholepart = a; private class Buttonhandler implements ActionListener public void actionPerformed( A
11、ctionEvent event ) Object o = event.getSource(); if(o=bt1) new Engage(); /客户预定 else if(o=bt2) new Customer(); /入住登记 else if(o=bt3) new account(); /客户结账 else if(o=bt4) new quarryBussiness(); /营业查询 else if(o=bt5) if (wholepart = 0)JOptionPane.showMessageDialog(null,金翎酒店提示您n非管理员无此权限!);elsenew systemMan
12、ager(); /系统管理 public static void main( String args ) mainFrame application = new mainFrame(); application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); 3. 预定功能实现 此模块主要实现客户的预定功能,包括查询、增加、删除预订信息,并能查询剩余的客房,以便于实现预定功能。图8 客户预定主界面主代码:package UI;import javax.swing.*;import java.awt.*;import java.awt.even
13、t.*;import java.sql.*;import java.util.*;import UI.*;public class Engage extends JFrame private JButton bt1,bt2,bt3,bt4;private JTextField tf1;public Engage() super ( 金翎酒店客户预订);JPanel panelMain,panelCent,panelNort;panelMain = new JPanel(new BorderLayout();panelNort = buildNorth();panelCent = buildDT
14、M();panelMain.add(North,panelNort);panelMain.add(panelCent);setContentPane(panelMain);setSize (500,130);setResizable(false);/不允许改变窗口大小setVisible(true);private JPanel buildNorth() JPanel panelCent1 = new JPanel(new BorderLayout();tf1 = new JTextField(宾客预定信息);tf1.setFont( new Font(楷体,Font.BOLD,15);tf1
15、.setHorizontalAlignment (JTextField.CENTER);tf1.setForeground(Color.yellow);tf1.setBackground(Color.red);tf1.setBorder(new LineBorder(new Color(87,87,47);tf1.setEditable(false);panelCent1.add(North,tf1);panelCent1.setBorder(BorderFactory.createTitledBorder();return panelCent1;private JPanel buildDTM
16、 () JPanel panelNort1 = new JPanel();Icon bug1= new ImageIcon(pic/new.gif);Icon bug2= new ImageIcon(pic/del.gif);Icon bug3= new ImageIcon(pic/find.gif);bt1 = new JButton ( 增加, bug1);bt3 = new JButton ( 删除, bug2);bt2 = new JButton ( 查询预定信息, bug3);bt4 = new JButton ( 查询客房信息, bug3);panelNort1.add(bt1);
17、panelNort1.add(bt3);panelNort1.add(bt2);panelNort1.add(bt4);Buttonhandler handler = new Buttonhandler();bt1.addActionListener(handler);bt2.addActionListener(handler);bt3.addActionListener(handler);bt4.addActionListener(handler);return panelNort1;private class Buttonhandler implements ActionListener
18、public void actionPerformed( ActionEvent event ) Object o = event.getSource(); if(o=bt1) addEngage add = new addEngage(); else if(o=bt3) deleteEngage delete= new deleteEngage(); else if(o=bt2) quaryEngage quary = new quaryEngage(); else if(o=bt4) quaryLeft quary = new quaryLeft(); public static void
19、 main( String args ) Engage application = new Engage(); application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); 增加预定信息图9 增加客户预订信息主代码如下:/addEngage.javapackage UI;import java.awt.event.*;import java.sql.*;import java.util.*;import javax.swing.*;import UI.HotelUI;import UI.ConnectionSql;class add
20、Engage extends JFrame private HotelUI userInterface; private JButton clearButton, writeButton; String sqlString ; String names = 订房编号,姓 名,身份证号,客房编号,联系电话,入住时间; public addEngage() super( 客房预订 ); userInterface = new HotelUI( names ); getContentPane().add( userInterface, BorderLayout.CENTER ); writeButt
21、on = userInterface.getDoTask1Button(); writeButton.setText( 保存 ); writeButton.addActionListener( new ActionListener() public void actionPerformed( ActionEvent event ) addRecord(); ); clearButton = userInterface.getDoTask2Button(); clearButton.setText( 清除 ); clearButton.addActionListener( new ActionL
22、istener() public void actionPerformed( ActionEvent event ) userInterface.clearFields(); ); setSize( 300, 200 ); setBackground(new Color(199,183,143); setVisible( true ); public void addRecord() ConnectionSql tempdb = new ConnectionSql(); String fieldValues = userInterface.getFieldValues(); if ( ! fi
23、eldValues HotelUI.Bookno .equals( ) ) try String sqlInsert1 = INSERT INTO Bookin + VALUES ( + fieldValues0+, +fieldValues1+, +fieldValues2+, +fieldValues3+, +fieldValues4+, +fieldValues5+ );String sqlInsert2 = Update Rooms SET +Putup=1+ WHERE RoomNo=+fieldValues3+; int result1 = tempdb.statement.exe
24、cuteUpdate(sqlInsert1); int result2 = tempdb.statement.executeUpdate(sqlInsert2); if (result1!=0 & result2!=0) userInterface.clearFields(); JOptionPane.showMessageDialog( this, 插入成功, Insert Result, JOptionPane.INFORMATION_MESSAGE ); catch (SQLException ee) System.out.println(ee); else JOptionPane.sh
25、owMessageDialog( this, 错误的编号, Invalid Number Format, JOptionPane.ERROR_MESSAGE ); tempdb.terminate() ; / end method addRecord public static void main( String args ) new addEngage(); 删除预订信息:图5 删除客户预订信息主代码如下:/deleteEngage.javapackage UI;import java.awt.*;import java.sql.*;import java.util.*;import jav
26、ax.swing.*;import UI.*;class deleteEngage extends JFrame private HotelUI userInterface1,userInterface2; private JButton firstButton1,secondButton1, firstButton2,secondButton2; String BooknoUpdate; String sqlString ; public deleteEngage() super( 删除预定信息 ); String names1 = 请输入要删除的预定编号:; userInterface1=
27、 new HotelUI( names1 ); / four textfields String names2 = 订房编号,姓 名,身份证号,客房编号,联系电话,入住日期; userInterface2 = new HotelUI(names2 ); Container c= getContentPane(); Box box = Box.createVerticalBox(); box.add(userInterface1 ); box.add(userInterface2 ); c.add(box); firstButton1 = userInterface1.getDoTask1But
28、ton(); firstButton1.setText( 确认 ); firstButton1.addActionListener( new ActionListener() public void actionPerformed( ActionEvent event ) /initialize(); DisplayRecord(); ); secondButton1 = userInterface1.getDoTask2Button(); secondButton1.setText( 清除 ); secondButton1.addActionListener( new ActionListe
29、ner() public void actionPerformed( ActionEvent event ) userInterface1.clearFields(); ); firstButton2 = userInterface2.getDoTask1Button(); firstButton2.setText( 确认删除 ); firstButton2.addActionListener( new ActionListener() public void actionPerformed( ActionEvent event ) UpdateRecord(); ); secondButto
30、n2 = userInterface2.getDoTask2Button(); secondButton2.setText( 放弃 ); secondButton2.addActionListener( new ActionListener() public void actionPerformed( ActionEvent event ) userInterface2.clearFields(); ); setSize( 400, 300 ); setVisible( true ); public void DisplayRecord() String fieldValues1 = user
31、Interface1.getFieldValues(); ConnectionSql tempdb = new ConnectionSql(); String fieldValues2 =new String6 ; if ( ! fieldValues1 HotelUI.Bookno .equals( ) ) BooknoUpdate=fieldValues10; try String sqlString = select * from Bookin + where Bookno=+fieldValues10 + ; ResultSet resultSet =tempdb.statement.
32、executeQuery( sqlString) ; ResultSetMetaData metaData = resultSet.getMetaData(); int numberOfColumns = metaData.getColumnCount(); if ( resultSet.next() ) fieldValues20=resultSet.getString( 1 ) ; fieldValues21=resultSet.getString( 2 ) ; fieldValues22=resultSet.getString( 3 ) ; fieldValues23=resultSet
33、.getString( 4 ) ; fieldValues24=resultSet.getString( 5 ) ; fieldValues25=resultSet.getString( 6 ) ; userInterface2.setFieldValues(fieldValues2); else userInterface2.clearFields(); JOptionPane.showMessageDialog( this, Not fund this record!, Find Result, JOptionPane.INFORMATION_MESSAGE ); catch ( Numb
34、erFormatException formatException ) JOptionPane.showMessageDialog( this, Bad age number , Invalid Number Format, JOptionPane.ERROR_MESSAGE ); catch (SQLException ee) System.out.println(ee); else JOptionPane.showMessageDialog( this, 错误的预定编号, Invalid Number Format, JOptionPane.ERROR_MESSAGE ); tempdb.
35、terminate() ; public void UpdateRecord() ConnectionSql tempdb = new ConnectionSql(); String fieldValues = userInterface2.getFieldValues(); if ( ! fieldValues HotelUI.Bookno .equals( ) ) try /the string sql statement String sqlString1 = delete from Bookin + where Bookno=+BooknoUpdate + ; String sqlSt
36、ring2 = Update Rooms SET +Putup=0+ WHERE RoomNo=+fieldValues3+; int result1 = tempdb.statement.executeUpdate(sqlString1); int result2 = tempdb.statement.executeUpdate(sqlString2); if (result1!=0 & result2!=0) JOptionPane.showMessageDialog( this, Deleted sucess!, Delete Result, JOptionPane.INFORMATIO
37、N_MESSAGE ); catch ( NumberFormatException formatException ) JOptionPane.showMessageDialog( this, Bad age number , Invalid Number Format, JOptionPane.ERROR_MESSAGE ); catch (SQLException ee) System.out.println(ee); /end of if sno field value is not emptyelse JOptionPane.showMessageDialog( this, 错误的预定编号