您好,登錄后才能下訂單哦!
本文實例為大家分享了java實現客房管理系統的具體代碼,供大家參考,具體內容如下
AddClient.java
import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import java.awt.FlowLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import java.util.Calendar; import javax.naming.spi.DirStateFactory.Result; import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.ButtonGroup; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JTextField; import javax.swing.UIManager; import javax.swing.UIManager.LookAndFeelInfo; public class AddClient extends JFrame implements ActionListener{ JTextField sname,ID,age,home_addr,employer,phone,cno,rno,intime,outtime,days,cashpledge; JButton save,cancel,save1; JPanel pl,pl1,pl2,pl3,pl4,pl5,pl6,pl7,pl8,pl9,pl10,pl11,pl12,pl13,pl14,pl15,pl16; JRadioButton man,wuman,yes,no; ButtonGroup group,group1; String sex,vip; int k,k1,k2; public AddClient(){ pl=new JPanel(); pl1=new JPanel(); pl2=new JPanel(); pl3=new JPanel(); pl4=new JPanel(); pl5=new JPanel(); pl6=new JPanel(); pl7=new JPanel(); pl8=new JPanel(); pl9=new JPanel(); pl10=new JPanel(); pl11=new JPanel(); pl12=new JPanel(); pl13=new JPanel(); pl14=new JPanel(); pl15=new JPanel(); pl16=new JPanel(new FlowLayout(FlowLayout.CENTER,20,20)); sname=new JTextField(15); ID=new JTextField(15); age=new JTextField(15); home_addr=new JTextField(15); employer=new JTextField(15); phone=new JTextField(15); cno=new JTextField(15); rno=new JTextField(15); intime=new JTextField(15); outtime=new JTextField(15); days=new JTextField(15); cashpledge=new JTextField(15); group=new ButtonGroup(); group1=new ButtonGroup(); man=new JRadioButton("男",true); wuman=new JRadioButton("女",false); yes=new JRadioButton("是",true); no=new JRadioButton("否",false); group.add(man); group.add(wuman); group1.add(yes); group1.add(no); pl1.add(new JLabel("姓名: ",JLabel.RIGHT)); pl1.add(sname); pl2.add(new JLabel("身份證號:",JLabel.RIGHT)); pl2.add(ID); pl3.add(new JLabel("性別: ",JLabel.RIGHT)); pl3.add(man); pl3.add(wuman); pl4.add(new JLabel("VIP客戶:")); pl4.add(yes); pl4.add(no); pl5.add(new JLabel("年齡: ",JLabel.RIGHT)); pl5.add(age); pl6.add(new JLabel("家庭地址:",JLabel.RIGHT)); pl6.add(home_addr); pl7.add(new JLabel("工作單位:",JLabel.RIGHT)); pl7.add(employer); pl8.add(new JLabel("手機號: ",JLabel.RIGHT)); pl8.add(phone); pl.setBorder(BorderFactory.createTitledBorder("客戶 信息")); pl.setLayout(new GridLayout(4,2,10,10)); pl.add(pl1); pl.add(pl2); pl.add(pl3); pl.add(pl4); pl.add(pl5); pl.add(pl8); pl.add(pl7); pl.add(pl6); pl9.add(new JLabel("房號: ",JLabel.RIGHT)); pl9.add(rno); pl10.add(new JLabel("入住時間:",JLabel.RIGHT)); pl10.add(intime); pl11.add(new JLabel("預離店時間",JLabel.RIGHT)); pl11.add(outtime); pl12.add(new JLabel("入住天數:",JLabel.RIGHT)); pl12.add(days); pl13.add(new JLabel("預交押金:",JLabel.RIGHT)); pl13.add(cashpledge); pl14.add(new JLabel("入住序號:",JLabel.RIGHT)); pl14.add(cno); pl15.setBorder(BorderFactory.createTitledBorder("客戶入住 信息")); pl15.setLayout(new GridLayout(3,2,15,15)); pl15.add(pl14); pl15.add(pl9); pl15.add(pl10); pl15.add(pl11); pl15.add(pl12); pl15.add(pl13); save=new JButton("登記入住"); cancel=new JButton("取消"); save1=new JButton("添加家屬"); save.addActionListener(this); cancel.addActionListener(this); save1.addActionListener(this); pl16.add(save); pl16.add(save1); pl16.add(cancel); add(pl,BorderLayout.NORTH); add(pl15,BorderLayout.CENTER); add(pl16,BorderLayout.SOUTH); setBounds(600,300,600,600); setTitle("客戶入住信息"); setVisible(true); } @Override public void actionPerformed(ActionEvent e) { if(e.getSource()==save){ int result=JOptionPane.showConfirmDialog(null, "確認提交嗎", "溫馨提示", JOptionPane.YES_NO_OPTION); if (result==0) { if(man.isSelected()){ sex="男"; } else{ sex="女"; } if(yes.isSelected()){ vip="是"; } else{ vip="否"; } try { Class.forName(Url.driver); Connection con=DriverManager.getConnection(Url.url,Url.username,Url.userpwd); Statement sql=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY); k=sql.executeUpdate("insert into Client values('"+sname.getText()+"','"+ID.getText()+"','"+sex+"','"+age.getText()+"','"+home_addr.getText()+"','"+employer.getText()+"','"+vip+"','"+phone.getText()+"')"); k1=sql.executeUpdate("insert into Check_in(Cno,Rno,Intime,Outtime,Dayss,Cashpledge) values('"+cno.getText()+"','"+rno.getText()+"','"+intime.getText()+"','"+outtime.getText()+"','"+days.getText()+"','"+cashpledge.getText()+"')"); k2=sql.executeUpdate("insert into Type_in values('"+cno.getText()+"','"+ID.getText()+"')"); if (k==1&&k1==1&&k2==1) { int result1=JOptionPane.showConfirmDialog(null, "入住成功!是否添加家屬信息?", "溫馨提示", JOptionPane.YES_NO_OPTION); if(result1==0){ ID.setText(""); sname.setText(""); age.setText(""); home_addr.setText(""); phone.setText(""); employer.setText(""); } else { dispose(); } } }catch(Exception e1){ JOptionPane.showMessageDialog(this, "入住失敗"); } } } if(e.getSource()==cancel){ dispose(); } if(e.getSource()==save1){ int result=JOptionPane.showConfirmDialog(null, "確認提交嗎", "溫馨提示", JOptionPane.YES_NO_OPTION); if (result==0) { if(man.isSelected()){ sex="男"; } else{ sex="女"; } if(yes.isSelected()){ vip="是"; } else{ vip="否"; } try { Class.forName(Url.driver); Connection con=DriverManager.getConnection(Url.url,Url.username,Url.userpwd); Statement sql=con.createStatement(); k=sql.executeUpdate("insert into Client values('"+sname.getText()+"','"+ID.getText()+"','"+sex+"','"+age.getText()+"','"+home_addr.getText()+"','"+employer.getText()+"','"+vip+"','"+phone.getText()+"')"); k2=sql.executeUpdate("insert into Type_in values('"+cno.getText()+"','"+ID.getText()+"')"); if (k==1&&k2==1) { int result1=JOptionPane.showConfirmDialog(null, "入住成功!是否繼續添加家人信息?", "溫馨提示", JOptionPane.YES_NO_OPTION); if(result1==0){ ID.setText(""); sname.setText(""); age.setText(""); home_addr.setText(""); phone.setText(""); employer.setText(""); } else { dispose(); } } }catch(Exception e1){ JOptionPane.showMessageDialog(this, "添加失敗"); } } } } }
AdminFrame.java
import java.awt.BorderLayout; import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.ImageIcon; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JPanel; class AdminFrame extends JDialog implements ActionListener{ JLabel label = new JLabel(); JMenuBar mBar= new JMenuBar(); private JMenu Quarto,message,Clinet; private JMenuItem item1,item2,item3,item4,item5,item6,item7,item8,item9; JPanel pl1; Container con; AdminFrame(){ pl1=new JPanel(); setJMenuBar(mBar); ImageIcon icon = new ImageIcon("src/picture/1.jpg"); label.setIcon(icon); label.setBounds(0,0, 600, 500); pl1.add(label); add(pl1); setBounds(600,300,600,500); Quarto=new JMenu("客房操作"); message=new JMenu("信息查詢"); Clinet=new JMenu("統計客房相關信息"); mBar.add(Quarto); mBar.add(message); mBar.add(Clinet); item3=new JMenuItem("查詢客房"); item1=new JMenuItem("入住登記"); item2=new JMenuItem("退房操作"); Quarto.add(item1); Quarto.addSeparator(); Quarto.add(item2); Quarto.addSeparator(); Quarto.add(item3); item4=new JMenuItem("客人信息查詢"); item5=new JMenuItem("客房時間查詢"); item6=new JMenuItem("客人費用查詢"); message.add(item4); message.addSeparator(); message.add(item5); message.addSeparator(); message.add(item6); item7=new JMenuItem("各類房型入住情況"); item8=new JMenuItem("各月份客房收入"); Clinet.add(item7); Clinet.addSeparator(); Clinet.add(item8); item1.addActionListener(this); item2.addActionListener(this); item3.addActionListener(this); item4.addActionListener(this); item5.addActionListener(this); item6.addActionListener(this); item7.addActionListener(this); item8.addActionListener(this); setVisible(false); setTitle("客房管理系統"); validate(); } @Override public void actionPerformed(ActionEvent e) { if(e.getSource()==item1){ AddClient stu=new AddClient(); stu.setVisible(true); } if(e.getSource()==item2){ Left left=new Left(); left.setVisible(true); } if (e.getSource()==item3) { QueryRoom qr=new QueryRoom(); qr.setVisible(true); } if (e.getSource()==item4) { QueryClient qc=new QueryClient(); qc.setVisible(true); } if(e.getSource()==item5){ QueryTime qt=new QueryTime(); qt.setVisible(true); } if(e.getSource()==item6){ QueryCost qc=new QueryCost(); qc.setVisible(true); } if(e.getSource()==item7){ StatisticsInformation si=new StatisticsInformation(); si.setVisible(true); } if(e.getSource()==item8){ Income income=new Income(); income.setVisible(true); } } }
完整代碼:java實現客房管理系統
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持億速云。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。