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

📄 ticketordersystem.java

📁 java写的订票系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
       	  	
       	  }
           
       }
   }
   private class OrderAction  implements ActionListener
   {    
       public void actionPerformed(ActionEvent event)
       {
       	   try
       	   {
       	   	   String name=orderName.getText();
               String card=orderCardId.getText();
               String num=orderAmount.getText();
               String fid=orderFlightId.getText();
               String remark=orderRemark.getText();
               
               StringBuffer s = new StringBuffer();
               
               RandomAccessFile out = new RandomAccessFile("FormId.txt", "rw");  
               int id=Integer.parseInt(out.readLine());
               out.close();
               TicketOrderInformation toi= new TicketOrderInformation(name,card,Integer.parseInt(num),fid,remark);
               toi.setOrderFormId(id+1);
               Node toiNode = new Node(toi,null); 
               s.append(toi.getOrderFormId()+" "+name+" "+card+" "+num+" "+fid+" "+remark+"\r\n");
               DataOutputStream outs = new DataOutputStream(new FileOutputStream("TicketOrderInformation.txt",true));
               outs.write(s.toString().getBytes());
               outs.close();
               
               RandomAccessFile out2 = new RandomAccessFile("FormId.txt", "rw"); 
               Integer i=99;               
               out2.writeBytes(i.toString(id+1)); 
               out2.close();
               
               orderName.setText(null);
               orderCardId.setText(null);
               orderAmount.setText(null);
               orderFlightId.setText(null);
               orderRemark.setText(null);
               
              
               String[] str=new String[9]; //用来装一条信息
               String temp=null;
               boolean tag=true;
               BufferedReader buffer=new BufferedReader(new FileReader("AirlineInformation.txt")); 
   			   Node head = new Node();
   			   Node p = head; 
               while((temp=buffer.readLine())!=null)
               {
                	str =temp.split(" ");
                	if(str[0].equals(fid))
                   	{
               	       Integer left=Integer.parseInt(str[8]);
               	       if(left<Integer.parseInt(num))
               	       {
               	       	   tag=false;
               	       	   JOptionPane.showMessageDialog(null, "没有足够得票,请选择其它航班。","抱歉!" , JOptionPane.ERROR_MESSAGE);
               	       	   break;
               	       }
               	        	   
               	       left-=Integer.parseInt(num);	
               	      
                	   AirlineInformation ali= new AirlineInformation(str[0],str[1],str[2],str[3],str[4],
                                                              Double.parseDouble(str[5]),Double.parseDouble(str[6]),
                                                              Integer.parseInt(str[7]),left);
                     	Node  aliNode = new Node(ali,null);  
                        p.setNext(aliNode);
                        p=p.getNext();                                                    
                	 }
                	 else 
                	 {
                	 	AirlineInformation ali= new AirlineInformation(str[0],str[1],str[2],str[3],str[4],
                                                              Double.parseDouble(str[5]),Double.parseDouble(str[6]),
                                                              Integer.parseInt(str[7]),Integer.parseInt(str[8]));
                     	Node  aliNode = new Node(ali,null);  
                        p.setNext(aliNode);
                        p=p.getNext();            
                	 }
                }
                if(tag)
                {
                	StringBuffer ss = new StringBuffer();
                    for(p=head;p.getNext()!=null;p=p.getNext())
                    {     
                	    ss.append(((AirlineInformation)p.getNext().getElem()).toStr()+"\r\n");
                    }
                    DataOutputStream outss = new DataOutputStream(new FileOutputStream("AirlineInformation.txt"));
                    outss.write(ss.toString().getBytes());
                    outss.close(); 
                	
                    OrderDialog odialog;	
                    TicketOrderFrame frame=new TicketOrderFrame();
                    String result=null;
                    result="姓名:"+name+"\n"+
                	     "证件号"+card+"\n"+
                	     "数量:"+name+"\n"+
                	     "航班号"+card+"\n"+
                	     "附言:"+name+"\n"+
                	     "订单号"+toi.getOrderFormId()+"\n";
                
                    //弹出查询结果对话框                    
                    odialog = new OrderDialog(frame,result);                    	
                    odialog.setVisible(true); 
                   
                }                

       	  }
       	  catch(Exception e)
       	  {
       	  	
       	  }           
       }
   }
   
   private class ReturnAction  implements ActionListener
   {      
       public void actionPerformed(ActionEvent event)
       {
       	   try
       	   {
       	   	   String s=null; 
       	   	   String temp=null; 
       	   	   String id=returnOrderFormId.getText();
       	   	   RandomAccessFile out = new RandomAccessFile("TicketOrderInformation.txt", "rw");  
       	   	        
               TicketOrderInformation toi = new TicketOrderInformation("","",0,"","");
               toi.setOrderFormId(0);
               s=toi.toString();
               for(int i=1;i<Integer.parseInt(id)&&temp!=null;i++)
                    temp=out.readLine();
               if(temp==null)
               	   JOptionPane.showMessageDialog(null, "该订单不存在。","抱歉!" , JOptionPane.ERROR_MESSAGE);
               else if(temp.charAt(0)=='0')
               	   JOptionPane.showMessageDialog(null, "该订单已经被别人退了。","抱歉!" , JOptionPane.ERROR_MESSAGE);
               else
               	   JOptionPane.showMessageDialog(null, "该订单已经成功地退掉。","成功!" , JOptionPane.ERROR_MESSAGE);
               out.writeBytes(s);
               out.close();
               returnOrderFormId.setText(null);
          }
          
          catch(Exception e)
          {  
        
          }       
      }
      
   }
   
   private class SearchAction  implements ActionListener
   {
       public void actionPerformed(ActionEvent event)
       {
       	   try
       	   {
       	   	   //获取客户输入
       	   	   String id=searchFlightId.getText();
               String start=inputStart.getText();
               String dest=inputDestination.getText();
               
               //都不为空,代表输入有效
               if(!id.equals("")||!start.equals("")||!dest.equals(""))
               {
               	    SearchDialog sdialog;
               	    boolean idTag=true,startTag=true,destTag=true;               	    
               	    String temp=null;
               	    String result="";
                    String[] str=new String[9]; //用来装一条信息
                    Node head = new Node();     //链表首地址
                    Node p = head; 
                    int number = 0;             //查询结果条数
               	    if(id.equals(""))
               	    	idTag=false;
               	    if(start.equals(""))
               	    	startTag=false;
               	    if(dest.equals(""))
               	    	destTag=false;
               	    BufferedReader buffer=new BufferedReader(new FileReader("AirlineInformation.txt")); 
                    while((temp=buffer.readLine())!=null)
                    {
                        str =temp.split(" ");
                        
                        if(!idTag)
                        	id=str[0];	
                        if(!startTag)
                        	start=str[1];
                        if(!destTag)
                        	dest=str[2];
                        
                        if(str[0].equals(id)&&str[1].equals(start)&&str[2].equals(dest))
                        {
                        	AirlineInformation ali= new AirlineInformation(str[0],str[1],str[2],str[3],str[4],
                                                              Double.parseDouble(str[5]),Double.parseDouble(str[6]),
                                                              Integer.parseInt(str[7]),Integer.parseInt(str[8]));
                            Node aliNnde = new Node(ali,null); 
                            p.setNext(aliNnde);
                            p=p.getNext();
                            number++;     
            
                        }
                        
                    }
                    TicketOrderFrame frame=new TicketOrderFrame();
                    String s="一共查到"+number+"条相关信息:"+"\r\n";
                    for(p=head;p.getNext()!=null;p=p.getNext())
                    result+=(p.getNext().getElem().toString()+"\n\r");
                    //弹出查询结果对话框                    
                    sdialog = new SearchDialog(frame,s,result);                    	
                    sdialog.setVisible(true);
                                        
               }
                                        
               searchFlightId.setText(null);
               searchStart.setText(null);
               searchDestination.setText(null);               
       	  }
       	  catch(Exception e)
       	  {
       	  	
       	  }
           
       }
   }
  
  
   private class ChangeAction  implements ActionListener
   {     
       public void actionPerformed(ActionEvent event)
       {
       	   try
       	   {
       	   	   String id=changeFlightId.getText();
               String start=changeStart.getText();
               String dest=changeDestination.getText();
               String timeBegin=changeBeginTime.getText();
               String timeEnd=changeArriveTime.getText();
               String price=changePrice.getText();
               String discount=changeDiscount.getText();
               String ticketNum=changeTicketSum.getText();
               String ticketLeft=changeTicketLeft.getText();
               
               ChangeDialog cdialog;
               String result=null;
               String[] str=new String[9]; //用来装一条信息
               String temp=null;
               boolean tag=true;
               BufferedReader buffer=new BufferedReader(new FileReader("AirlineInformation.txt")); 
   			   Node head = new Node();
   			   Node p = head; 
   			   AirlineInformation past=null,now=null;
               while((temp=buffer.readLine())!=null)
               {
                	str =temp.split(" ");
                	if(str[0].equals(id))
                   	{
               	       past=new AirlineInformation(str[0],str[1],str[2],str[3],str[4],
                                                              Double.parseDouble(str[5]),Double.parseDouble(str[6]),
                                                              Integer.parseInt(str[7]),Integer.parseInt(str[8]));
               	       
                	   AirlineInformation ali= new AirlineInformation(id,start,dest,timeBegin,timeEnd,
                                                              Double.parseDouble(price),Double.parseDouble(discount),
                                                              Integer.parseInt(ticketNum),Integer.parseInt(ticketLeft));
                        now=ali;
                     	Node  aliNode = new Node(ali,null);  
                        p.setNext(aliNode);
                        p=p.getNext();                                                    
                	 }
                	 else 
                	 {
                	 	AirlineInformation ali= new AirlineInformation(str[0],str[1],str[2],str[3],str[4],
                                                              Double.parseDouble(str[5]),Double.parseDouble(str[6]),
                                                              Integer.parseInt(str[7]),Integer.parseInt(str[8]));
                     	Node  aliNode = new Node(ali,null);  
                        p.setNext(aliNode);
                        p=p.getNext();            
                	 }
                }
               
                StringBuffer ss = new StringBuffer();
                for(p=head;p.getNext()!=null;p=p.getNext())
                {     
                	ss.append(((AirlineInformation)p.getNext().getElem()).toStr()+"\r\n");
                }
                DataOutputStream outss = new DataOutputStream(new FileOutputStream("AirlineInformation.txt"));
                outss.write(ss.toString().getBytes());
                outss.close();                
                
                TicketOrderFrame frame=new TicketOrderFrame();
                result="原航班"+"\n"+past.toString()+"\n"+
                	   "修改后"+"\n"+now.toString()+"\n";
                //弹出查询结果对话框                    
                cdialog = new ChangeDialog(frame,result);                    	
                cdialog.setVisible(true);
                changeFlightId.setText(null);
                changeStart.setText(null);
                changeDestination.setText(null);
                changeBeginTime.setText(null);
                changeArriveTime.setText(null);
                changePrice.setText(null);
                changeDiscount.setText(null);
                changeTicketSum.setText(null);
                changeTicketLeft.setText(null);
       	   }
       	   catch(Exception e)
       	   {
       	  	
       	   }
           
       }
   }	
}

⌨️ 快捷键说明

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