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

📄 xp_hotelbill.java

📁 这是一个酒店管理系统!很经典的哟~~~~初学者可以拿去看看
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
									if(select1.equals(rs.getString("Name")))
									{
										J_id.setText(rs.getString("ID"));
										J_name.setText(select1);
										J_price.setText(rs.getString("Price"));
										J_leibie.setText(rs.getString("Sort"));									
									}
							}
							stmt.close();
							con.close();
					}
					catch(Exception ex){JOptionPane.showMessageDialog(new JFrame(),"xian");}
         }
      }
      if (e.getSource() == List_caidan2)
    	{
    		
       if(e.getClickCount() == 1)
       {
       		int index = List_caidan2.locationToIndex(e.getPoint());//记住鼠标的当前坐标
        	List_caidan2.setSelectedIndex(index);  //找到当前你所选择的项
      		select2 =(String) List_caidan2.getSelectedValue();
					
      	}
      	if(e.getClickCount() == 2)
      	{
      		int index = List_caidan2.locationToIndex(e.getPoint());//记住鼠标的当前坐标
        	List_caidan2.setSelectedIndex(index);  //找到当前你所选择的项
      		select2 =(String) List_caidan2.getSelectedValue();
      		ResultSet rs = null;
					try
					{
							Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
							//Connection con =DriverManager.getConnection("jdbc:odbc:GUKE","Test","1234");
							Connection con =DriverManager.getConnection("jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=F:\\java-test\\hotel-panxianyu-zonghe\\GKcaidan.mdb");
							Statement stmt=con.createStatement();
							rs=stmt.executeQuery("Select*From GUKE");				
							while(rs.next())
							{
									if(select2.equals(rs.getString("Gfoodname")))
									{
										List_caidan2.setToolTipText("你已有"+" "+rs.getString("Gpart")+" "+"份");									
									}									
							}
							stmt.close();
							con.close();
					}
					catch(Exception ex){}
         }
   	 }		
	}
	public int X_getbillnum(int i)
	{
		int k=0;
		String filename="F:\\caidannum.dat";
		try
		{
			//输出流
				DataOutputStream out = new DataOutputStream(new FileOutputStream(filename));
				out.writeInt(i+1);
				out.close();
				//输入流				
				DataInputStream in = new DataInputStream(new FileInputStream(filename));
				k= in.readInt();
				in.close();			
		}
		catch(IOException e)
		{
		}
		return(k);
	}
	public  void actionPerformed(ActionEvent e)
	{	
			int a1,a2,a3,a5,a6;
			String a4;
			int Spend_price=0;//当前消费
			String cmd = e.getActionCommand();
			ResultSet rs = null;					
			if(cmd.equals(" 吃 这 个>>"))
			{			
					a1=Integer.parseInt(J_desknum.getSelectedItem().toString());//顾客的桌号
					if(flag)
					{
						GUKE_billnum = X_getbillnum(GUKE_billnum);
					}	
					a3=Integer.parseInt(J_id.getText());//顾客的菜号
					a4=J_name.getText().toString();//顾客的菜名
					a5=Integer.parseInt(J_price.getText());//顾客的菜的价格
					a6=Integer.parseInt(S1.getValue().toString());//顾客的菜的份数
					J_desknum.setEnabled(false);//桌号只能选一次
					try
					{
							Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
						//	Connection con =DriverManager.getConnection("jdbc:odbc:GUKE","Test","1234");
							Connection con =DriverManager.getConnection("jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=F:\\java-test\\hotel-panxianyu-zonghe\\GKcaidan.mdb");
							Statement stmt=con.createStatement();							
							String SQL = "INSERT INTO GUKE VALUES("+a1+","+GUKE_billnum+","+a3+",'"+a4+"',"+a5+","+a6+")";
							//为何加下面的一段话就不行了?
							/*if(a4.equals(rs.getString("Gfoodname")))	
							{
								JOptionPane.showMessageDialog(J,"sdf");
							}*/				
							stmt.executeUpdate(SQL);										
							int k = 0;
							rs=stmt.executeQuery("Select*From GUKE");
							while(rs.next())
							{								
									int i = Integer.parseInt(rs.getString("Gfoodprice"));
									int	j = Integer.parseInt(rs.getString("Gpart"));
									Spend_price = Spend_price+i*j;	
									List2[k]=rs.getString("Gfoodname");
									k++;																	
							}
							List_caidan2.setListData(List2);						 
							
							stmt.close();
							con.close();
					}
					catch(Exception ex){}					
					String Sp = Integer.toString(Spend_price);
					Spend.setText(Sp+" "+"元");
					flag=false;							
			}
			else if(cmd.equals("<<下 次 吃 "))
			{	
				try
				{
						Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
						//Connection con =DriverManager.getConnection("jdbc:odbc:GUKE","Test","1234");
						Connection con =DriverManager.getConnection("jdbc:odbc:driver={Microsoft Access Driver (*.mdb);DBQ=F:\\java-test\\hotel-panxianyu-zonghe\\GKcaidan.mdb");
						Statement stmt = con.createStatement();	
						stmt.executeUpdate("DELETE FROM GUKE WHERE Gfoodname="+"'"+select2+"'");//正确删除
						rs=stmt.executeQuery("Select*From GUKE");
						
						int j = 0;								
						while(rs.next())
						{
										List2[j]=rs.getString("Gfoodname");	
										j++;
						}
						for(;j<20;j++)
						{
							List2[j]=" ";
						}
						//List_caidan2.											
						List_caidan2.setListData(List2);						
						stmt.close();
						con.close();
				}
				catch(Exception ex){}//SQLException
			}	
			else if(cmd.equals(" 确 定 "))
			{
					new XP_wait(J);	
					flag=true;				
			}
			else if(cmd.equals(" 取 消 "))
			{
				try
				{
						Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
						//Connection con =DriverManager.getConnection("jdbc:odbc:GUKE","Test","1234");
						Connection con =DriverManager.getConnection("jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=F:\\java-test\\hotel-panxianyu-zonghe\\GKcaidan.mdb");
						Statement stmt=con.createStatement();
						String SQL = "DELETE FROM GUKE";
						stmt.executeUpdate(SQL);		
						stmt.close();
						con.close();
				}
				catch(Exception ex){}
					J.dispose();//退回主页面
			}
		}
}
class XP_wait 
{
			int LISTCONTENS = 20;
			JDialog W;
			String G_billnum = "0";//顾客的菜单号
			ResultSet rs = null;
			String G_jiechangcaidan[] = new String[LISTCONTENS];//顾客的结账菜单
			XP_wait(JFrame F)
			{
				W=new JDialog(F,"福佑饭店欢迎你!",true);				
				Container contentPane = W.getContentPane();//获得内容面板
				contentPane.setLayout(new GridLayout(2,1));
				JPanel Pane_wodebill = new JPanel();
				JPanel Pane_caidanxuhao = new JPanel();
				JPanel Pane_wait = new JPanel();
				JPanel Pane_list = new JPanel();
				//设置我的结账菜单的边框			
				Pane_wodebill.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.blue,2),"你的菜单",TitledBorder.CENTER,TitledBorder.TOP));
				//连接数据库把我所选择的菜列出来
				try
				{
									Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
									//Connection con =DriverManager.getConnection("jdbc:odbc:GUKE","Test","1234");
									Connection con =DriverManager.getConnection("jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=F:\\java-test\\hotel-panxianyu-zonghe\\GKcaidan");
									Statement stmt=con.createStatement();
									rs=stmt.executeQuery("Select*From GUKE");	
									int j=0;
									while(rs.next())
									{
											G_jiechangcaidan[j]=rs.getString("Gfoodname");
											G_billnum=rs.getString("Gbillnum");
											j++;
									}										
									stmt.close();
									con.close();
				}
				catch(Exception ex){}
				//进行排版
				JList List_guke_caidan = new JList(G_jiechangcaidan);				
				Pane_caidanxuhao.setLayout(new GridLayout(1,2));
				Pane_caidanxuhao.add(new JLabel("你 的 菜 单 号 是 :",SwingConstants.CENTER));
				Pane_caidanxuhao.add(new JLabel(G_billnum,SwingConstants.CENTER));
				Pane_wodebill.add(Pane_caidanxuhao);
				Pane_list.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.red,1),"菜名",TitledBorder.LEFT,TitledBorder.TOP));
				Pane_list.setLayout(new GridLayout(1,1));
				Pane_list.add(new JScrollPane(List_guke_caidan));
				Pane_wodebill.setLayout(new GridLayout(1,2));
				Pane_wodebill.add(Pane_list);			
				Pane_wait.setLayout(new GridLayout(1,1));
				JLabel Wait = new JLabel("请稍等......",SwingConstants.CENTER);
				Pane_wait.add(Wait);			
				
				contentPane.add(Pane_wodebill);//添加列表菜单
				contentPane.add(Pane_wait);//添加等候信息		
				W.setBounds(200,200,300,400);
				W.pack();
				W.setVisible(true);
			}	
}
class CellRenderer extends JLabel implements ListCellRenderer
{
   //让JList中的每个项目都视为是一个JLabel
    CellRenderer()
    {
        setOpaque(true);
    }
    /*从这里到结束:实作getListCellRendererComponent()方法*/
    public Component getListCellRendererComponent(JList list,
                                                  Object value,
                                                  int index,
                                                  boolean isSelected,
                                                  boolean cellHasFocus)
    {   
        //我们判断list.getModel().getElementAt(index)所返回的值是否为null
        if (value != null)
        {
        		setIcon(new ImageIcon((index+1)+".jpg"));
            setText(value.toString());
            
        }
        if (isSelected) 
        {
        	//设置选取的前景与背景颜色
            setBackground(Color.pink);
            setForeground(Color.red);
        }
        else {
            //设置选取与取消选取的前景与背景颜色.
            setBackground(list.getBackground());
            setForeground(Color.magenta);
        }
        return this;
    }    
}

⌨️ 快捷键说明

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