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

📄 resturant.java

📁 餐厅管理系统毕业设计
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.util.Calendar;
import java.util.Date;

import javax.swing.*;
public class Resturant {
	String username = "root";
    String password = "right";
    String jdbcDriver="com.mysql.jdbc.Driver";
    String url="jdbc:mysql://localhost:3306/resturant"; 
    Connection con = null;
    Statement stmt = null;
    ResultSet rSet=null;
	JFrame f=new JFrame();
	Container contentPane=f.getContentPane();
	JLabel jLabel1=new JLabel("预定号码   ");
	JLabel jLabel2=new JLabel("桌号");
	JLabel jLabel3=new JLabel("人数  ");
	JLabel jLabel4=new JLabel("预约时间  ");
	JLabel jLabel5=new JLabel("月  ");
	JLabel jLabel6=new JLabel("日  ");
	JLabel jLabel7=new JLabel("时   ");
	JLabel jLabel8=new JLabel("分   ");
	JLabel jLabel9=new JLabel("姓名   ");
	JLabel jLabel10=new JLabel("电话   ");
	JTextField jTextField1=new JTextField(2);
	JTextField jTextField2=new JTextField(2);
	JTextField jTextField3=new JTextField(2);
	JTextField jTextField4=new JTextField(2);
	JTextField jTextField5=new JTextField(2);
	JTextField jTextField6=new JTextField(8);
	JTextField jTextField7=new JTextField(8);
	//位置数
	String [] data1 = {"1","2","3","4","5","6","7","8"};
	//桌号
	String [] data2 = {"1","2","3","4","5"};
	JComboBox jComboBox1 = new JComboBox(data1);
	JComboBox jComboBox2 = new JComboBox(data2);
    JButton jButton1=new JButton("预定");
	JButton jButton2=new JButton("退出");
	JScrollPane listScroll1=new JScrollPane(jComboBox1);
	JScrollPane listScroll2=new JScrollPane(jComboBox2);
        public Resturant(){
        	contentPane.setLayout(new FlowLayout(FlowLayout.LEFT));
            contentPane.add(jLabel1);
        	contentPane.add(jTextField1);
        	contentPane.add(jLabel2);
        	contentPane.add( listScroll2);
        	contentPane.add(jLabel3);
        	contentPane.add( listScroll1);
        	contentPane.add(jLabel4);
        	contentPane.add(jTextField2);
        	contentPane.add(jLabel5);
        	contentPane.add(jTextField3);
        	contentPane.add(jLabel6);
        	contentPane.add(jTextField4);
        	contentPane.add(jLabel7);
        	contentPane.add(jTextField5);
        	contentPane.add(jLabel8);
        	contentPane.add(jLabel9);
        	contentPane.add(jTextField6);
        	contentPane.add(jLabel10);
        	contentPane.add(jTextField7);
        	contentPane.add(jButton1);
        	contentPane.add(jButton2);
        	f.setSize(300,280);
        	f.setVisible(true);
        	
            jButton1.addActionListener(new ActionListener() {
        	     public void actionPerformed(ActionEvent e) {
        	    	 String id=jTextField1.getText();
        	    	 String covers=(String)jComboBox1.getSelectedItem();
        	    	 String name=jTextField6.getText();
        	    	 String tno=(String)jComboBox2.getSelectedItem();
        	    	 String tel=jTextField7.getText(); 
        	    	 JOptionPane.showConfirmDialog(null,  "确定OID为"+id+","+"桌号为"+tno+","+"人数为"+covers+"'"+"姓名为"+name+","+"电话为"+tel+"的预约?", "取消", JOptionPane.YES_NO_OPTION);
                     makeReservation();
        	    	} 
             });
            jButton2.addActionListener(new ActionListener() {
          	     public void actionPerformed(ActionEvent e) {
          	    	JOptionPane.showConfirmDialog(null,  "确定要退出?", "退出", JOptionPane.YES_NO_OPTION);
          	        f.dispose();
          	    	} 
             });
         }//
        void makeReservation(){
        	 String id=jTextField1.getText();
        	 if(id.equals("")){
 	    		JOptionPane.showMessageDialog(null, "OID不能为空!", "错误!", JOptionPane.ERROR_MESSAGE);
 	    	    f.dispose();
 	    	 }
        	 int oid=Integer.parseInt(id);
	    	 String covers=(String)jComboBox1.getSelectedItem();
	    	 String month=jTextField2.getText();
	    	 int m2=Integer.parseInt(month);
	    	 int m1=getmonth();
	    	 if(m2<1||m2>12||(m2<m1&&m2>0)){
	    		 JOptionPane.showMessageDialog(null, "无效月份", "错误!", JOptionPane.ERROR_MESSAGE);
	    		 f.dispose();
	    	 }
	    	 String day=jTextField3.getText();
	    	 int d2=Integer.parseInt(day);
	    	 int d1=getday();
	    	 if((m2==4||m2==6||m2==9||m2==11)&&d2==31){
	    		 JOptionPane.showMessageDialog(null, "无效日期", "错误!", JOptionPane.ERROR_MESSAGE);
	    	     f.dispose();
	    	 }
	    	 if(d2<1||d2>31){
	    		 JOptionPane.showMessageDialog(null, "无效日期", "错误!", JOptionPane.ERROR_MESSAGE);
	    	     f.dispose(); 
	    	 }
	    	 String hour=jTextField4.getText();
	    	 int h2=Integer.parseInt(hour);
	    	 if(h2<1||h2>24){
	    		 JOptionPane.showMessageDialog(null, "无效时间", "错误!", JOptionPane.ERROR_MESSAGE);
	    	     f.dispose(); 
	    	 }
	    	 String minute=jTextField5.getText();
	    	 int mm=Integer.parseInt(minute);
	    	 if(mm<0||mm>59){
	    		 JOptionPane.showMessageDialog(null, "无效时间", "错误!", JOptionPane.ERROR_MESSAGE);
	    	     f.dispose(); 
	    	 }
	    	 String date=""+month+"."+day;
	    	 String time=""+hour+":"+minute;
	    	 String name=jTextField6.getText();
	    	 if(name.equals("")){
	    		 JOptionPane.showMessageDialog(null, "姓名不能为空!", "错误!", JOptionPane.ERROR_MESSAGE);
	    	     f.dispose();
	    	 }
	    	 String tno=(String)jComboBox2.getSelectedItem();
	    	 String tel=jTextField7.getText(); 
	    	 if(tel.equals("")){
	    		 JOptionPane.showMessageDialog(null, "电话不能为空!", "错误!", JOptionPane.ERROR_MESSAGE);
	    	     f.dispose();
	    	 }
	    	 String arrivetime=null;
        	 try{
    	          Class.forName(jdbcDriver);
    	          }
    	     catch(ClassNotFoundException se){
    	          System.err.print(se.getMessage());
    	       }
	         try{
	        	     con=DriverManager.getConnection(url,username,password);
	                 stmt=con.createStatement();
	                 String reserch="SELECT * FROM reservation where oid="+oid+";";
	                 String AddReservation="INSERT INTO Reservation values (" +"'"+ oid +"'"+"," +"'"+ covers +"'"+"," + "'"+ date +"'" +","+"'"+time+"'"+","+"'"+tno+"'"+","+"'"+name+"'"+","+"'"+arrivetime+"'"+");";
	                 String AddCustomer="INSERT INTO Customer values ("+"'"+oid+"'"+","+"'"+name+"'"+","+"'"+tel+"'"+");";
	                 String AddTable="INSERT INTO Tableinfo values ("+"'"+oid+"'"+","+"'"+tno+"'"+","+"'"+covers+"'"+");";
	                 rSet=stmt.executeQuery(reserch);
	                 if(rSet.next()==true){
	                	 JOptionPane.showMessageDialog(null, "预约号码重复", "错误!", JOptionPane.ERROR_MESSAGE);
	                	 f.dispose();
	                 }
	                 stmt.executeUpdate(AddReservation);
	                 stmt.executeUpdate(AddCustomer);
	                 stmt.executeUpdate(AddTable);
	                 jTextField1.setText("");
	                 jTextField2.setText("");
	                 jTextField3.setText("");
	                 jTextField4.setText("");
	                 jTextField5.setText("");
	                 jTextField6.setText("");
	                 jTextField7.setText("");
	                 con.close();
                }
            catch(SQLException se){
                System.err.println(se.getMessage());
                 }
            finally{
                try{
                    if(con!=null){
                                   con.close();
                                   }
                    if(stmt!=null){
                                   stmt.close();
                                   }
                    }catch(Exception ex){}          //忽略
                   }
        }
        public int getmonth(){
        	Calendar calendar=Calendar.getInstance();
            calendar.setTime(new Date());
            int month=calendar.get(Calendar.MONTH)+1;   
            return month;
        }
        public int getday(){
        	Calendar calendar=Calendar.getInstance();
            calendar.setTime(new Date());
            int day=calendar.get(Calendar.DAY_OF_MONTH);  
            return day;
        }
}//

⌨️ 快捷键说明

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