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

📄 tuipiao.java

📁 一般的延时子程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
//package flight.tuipiao;

//import flight.assist.*;

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.border.*;
import java.io.*;
import java.util.*;
import java.sql.*;

public class TuiPiao extends JFrame implements ActionListener
{
	private JTextField jtfDingDan = new JTextField(12),jtfID = new JTextField(15),
	                   jtfName = new JTextField(7),jtfFlightInfo = new JTextField(20),
	                   jtfChildNum = new JTextField(5),jtfAdultNum = new JTextField(5),
	                   jtfOriginCost = new JTextField(9),jtfTuiPiaoCost = new JTextField(9),
	                   jtfTime1 = new JTextField(7),
	                   jtfTime2 = new JTextField(7),
	                   jtfChildTuiPiaoShu = new JTextField("0",5),
	                   jtfAdultTuiPiaoShu = new JTextField("0",5);
	                   
	private JButton jbQuery = new JButton("查询"),jbOK = new JButton("退票"),
	                jbCancel = new JButton("退出"),jbRewrite = new JButton("重填");
	                
	private Object[] items = {"15位身份证","18位身份证"	};
	private JComboBox jcb = new JComboBox(items);
	
	private JLabel jlTime1 = new JLabel("出发时间"),jlTime2 = new JLabel("            ");
	
	private String dingdanNum,name,idNum,flight1,flight2,ticketType,leaveTime1,leaveTime2,
	               childNum,adultNum,cost,year,month,day,hour;
	               
	private File file ;
	
	private long locationOfRecord;
	
	private SeatInfo seatInfo = new SeatInfo();
	private SqlBean sqlBean = new SqlBean();
	
	public TuiPiao()
	{
		//arrange the panel
		File f = new File(".","data");
    	f.mkdir();
    	file = new File(f,"ClientInfo.txt");
    	    	
    	//set the textfields for querying uneditable 
    	jtfName.setEditable(false);
		jtfFlightInfo.setEditable(false);
		jtfChildNum.setEditable(false);
		jtfAdultNum.setEditable(false);
		jtfOriginCost.setEditable(false);
		jtfTuiPiaoCost.setEditable(false);
		jtfTime1.setEditable(false);
		jtfTime2.setEditable(false);
    	        
        //******************************************************************
        JLabel jlDingdan = new JLabel("订 单 号 ");
       // jlDingdan.setFont(new Font("Times",Font.PLAIN,12));
        JLabel jlID = new JLabel("   身份证号");
       // jlID.setFont(new Font("Times",Font.PLAIN,12));
        
        JPanel jpInput = new JPanel(new FlowLayout(FlowLayout.LEFT));
        jpInput.setBorder(new TitledBorder("输入信息"));
        
        jpInput.add(jlDingdan);
        jpInput.add(jtfDingDan);
        jpInput.add(jlID);
        jpInput.add(jtfID);      
                
        //****************************************************************
        
        JLabel jlName = new JLabel("客户姓名");
        JLabel jlFlight = new JLabel("  航班信息");
        JLabel jlChild = new JLabel("儿童票数");
        JLabel jlAdult = new JLabel("成人票数");
        JLabel jlOriCost = new JLabel("原  票  价");
        JLabel jlTuiCost = new JLabel("退  票  价");     
        
        JPanel jpTop = new JPanel(new FlowLayout(FlowLayout.LEFT));
        jpTop.add(jlName);
        jpTop.add(jtfName);
        jpTop.add(jlFlight);
        jpTop.add(jtfFlightInfo);
        
        JPanel jpNum = new JPanel();
        jpNum.setLayout(new GridLayout(2,1));
	        JPanel jp1 = new JPanel();
	        jp1.add(jlChild);
	        jp1.add(jtfChildNum);
	        JPanel jp2 = new JPanel();
	        jp2.add(jlAdult);
	        jp2.add(jtfAdultNum);    
        jpNum.add(jp1);
        jpNum.add(jp2);        
        
        JPanel jpCost = new JPanel();
        jpCost.setLayout(new GridLayout(2,1));
	        JPanel jp3 = new JPanel();
	        jp3.add(jlOriCost);
	        jp3.add(jtfOriginCost);
	        JPanel jp4 = new JPanel();
	        jp4.add(jlTuiCost);
	        jp4.add(jtfTuiPiaoCost);
        jpCost.add(jp3);
        jpCost.add(jp4);
      
        
        JPanel jpTime = new JPanel();
        jpTime.setLayout(new GridLayout(2,1));
	        JPanel jp5 = new JPanel();
	        jp5.add(jlTime1);
	        jp5.add(jtfTime1);
	        JPanel jp6 = new JPanel();
	        jp6.add(jlTime2);
	        jp6.add(jtfTime2);
        jpTime.add(jp5);
        jpTime.add(jp6);
       
        
        JPanel jpCenter = new JPanel();
        jpCenter.setLayout(new BorderLayout());
        jpCenter.add(jpNum,BorderLayout.WEST);
        jpCenter.add(jpCost,BorderLayout.CENTER);
        jpCenter.add(jpTime,BorderLayout.EAST);   
        
        JPanel jpInfo = new JPanel();
        jpInfo.setBorder(new TitledBorder("基本信息"));
        jpInfo.setLayout(new BorderLayout()); 
        jpInfo.add(jpTop,BorderLayout.NORTH);
        jpInfo.add(jpCenter,BorderLayout.CENTER);       
        
        jlTime2.setVisible(false);
		jtfTime2.setVisible(false);
		
		
		JPanel jpTuiPiao = new JPanel(new FlowLayout(FlowLayout.CENTER));
		jpTuiPiao.setBorder(new TitledBorder("退票"));
		jpTuiPiao.add(new JLabel("退票数:"));
		jpTuiPiao.add(new JLabel("儿童票"));
		jpTuiPiao.add(jtfChildTuiPiaoShu);
		jpTuiPiao.add(new JLabel("成人票:"));
		jpTuiPiao.add(jtfAdultTuiPiaoShu);
			
		
		
		JPanel jpButtons = new JPanel(new FlowLayout(FlowLayout.CENTER));
		jpButtons.setBorder(new TitledBorder("操作"));
		jpButtons.add(jbQuery);
		jpButtons.add(jbRewrite);
		jpButtons.add(jbOK);
		jpButtons.add(jbCancel);
		
		JPanel jp = new JPanel();
		jp.setLayout(new BorderLayout());
		jp.add(jpInput,BorderLayout.NORTH);
		jp.add(jpInfo,BorderLayout.CENTER);
		jp.add(jpTuiPiao,BorderLayout.SOUTH);
		
		JPanel jpTotal = new JPanel();
		jpTotal.setBorder(new MatteBorder(new ImageIcon("f.gif")));
		jpTotal.setLayout(new BorderLayout());
		jpTotal.add(jp,BorderLayout.CENTER);
		jpTotal.add(jpButtons,BorderLayout.SOUTH);
       
        //******************************************************************
               
		this.getContentPane().add(jpTotal);		
		
		//add actionListener for the buttons
		jbQuery.addActionListener(this);
		jbRewrite.addActionListener(this);
		jbOK.addActionListener(this);
		jbCancel.addActionListener(this);
		
		//add actionListener for the window
		this.addWindowListener(new WindowAdapter()
	                          {
	                          	public void windowClosing(WindowEvent e)
	                          	{
	                          		TuiPiao.this.setVisible(false);
	                          		TuiPiao.this.dispose();
	                          	}
	                          }
	                      );		
	}
	//********************************************************************
	
	//the buttons' action
	public void actionPerformed(ActionEvent e)
	{
		if (e.getSource() == jbQuery)
		   query();
		else if (e.getSource() == jbRewrite)
		   rewrite();
		else if (e.getSource() == jbOK)
		   tuiPiao();
		else if (e.getSource() == jbCancel)
		{
			//set the frame unvisible
			this.setVisible(false);
			//close the window
			this.dispose();
		}   
	}
	//********************************************************************
	
	//operations for query
	private void query()
	{
		String  dingdan = jtfDingDan.getText().trim();
	    //if dingdan is wrong,display the error message
	    if (dingdan.length() == 0)
	    {
	    	JOptionPane.showMessageDialog(null,"订单号不能为空",
	    	                              "错误信息",JOptionPane.ERROR_MESSAGE);
	    	return;
	    }
	    
	    String id = jtfID.getText().trim();
	    //if dingdan is wrong,display the error message
	    if (id.length() == 0)
	    {
	    	JOptionPane.showMessageDialog(null,"身份证号不能为空",
	    	                              "错误信息",JOptionPane.ERROR_MESSAGE);
	    	return;
	    }
	    
	    //find the message of passenger
	    boolean isValid = getClientInfo(dingdan,id);
	    
	    if (isValid == false)
	    {
	    	rewrite();
	    	return;
	    }
	       
	       
	    //display the message of passenger
	    else
	    {
	    	jtfName.setText(name);
	    	jtfChildNum.setText(childNum);
	    	jtfAdultNum.setText(adultNum);
	    	jtfOriginCost.setText("  "+cost+"元");
	    	
	    	int sign=returnTime();
	    	//if the time for return ticket is over,display the error message 
	    	if(sign==0)
			  JOptionPane.showMessageDialog(null,"抱歉,退票时间已过,您现在不能退票!","错误信息",JOptionPane.ERROR_MESSAGE);
	    	//display the returning money across the current time and the flight time 
	    	if(sign==1)
	    	  jtfTuiPiaoCost.setText("退还65%价钱");
	    	if(sign==1)
	    	  jtfTuiPiaoCost.setText("退还70%价钱");
	    	  
	    	
	    	//compute the returning money  
	    	if (Integer.parseInt(childNum) == 0)
		       jtfChildTuiPiaoShu.setEditable(false);
	        if (Integer.parseInt(adultNum) == 0)
	           jtfAdultTuiPiaoShu.setEditable(false);
	           
	        if (ticketType.equals("单程"))
	        {
	        	jlTime1.setText("出发时间");
	        	jtfTime1.setText(leaveTime1);
	        	
	        	jlTime2.setVisible(false);
	        	jtfTime2.setVisible(false);
	        	
	        	jtfFlightInfo.setText("(单程机票)" + "航班号:" + flight1);
	        } 
	        
	        else if (ticketType.equals("往返"))
	        {
	        	jlTime1.setText("出发时间");
	        	jtfTime1.setText(leaveTime1);
	        	
	        	jlTime2.setText("返回时间");
	        	jlTime2.setVisible(true);
	        	
	        	jtfTime2.setText(leaveTime2);
	        	jtfTime2.setVisible(true);
	        	
	        	jtfFlightInfo.setText("(往返机票) " + " 去: " + flight1 +  "; 返: " + flight2);
	        }  
	        
	        else if (ticketType.equals("联程"))
	        {
	        	jlTime1.setText("第一出发时间");
	        	jtfTime1.setText(leaveTime1);
	        	
	        	jlTime2.setText("第二出发时间");
	        	jlTime2.setVisible(true);
	        	jtfTime2.setText(leaveTime2);
	        	jtfTime2.setVisible(true);
	        	
	        	jtfFlightInfo.setText("(联程机票) " + "航班1: " + flight1 +  "; 航班2: " + flight2);
	        }  	    	
	    }		
	}
	//********************************************************************
	
	//clean the textFilds
	private void rewrite()
	{
	    jtfDingDan.setText("");
	    jtfID.setText("");
		jtfName.setText("");
		jtfFlightInfo.setText("");
		
    	jtfChildNum.setText("");
    	jtfAdultNum.setText("");
    	jtfOriginCost.setText("");
    	jtfTuiPiaoCost.setText("");
    	
    	jtfTime1.setText("");
    	jtfTime2.setText("");
    	
    	jtfChildTuiPiaoShu.setText("0");
    	jtfAdultTuiPiaoShu.setText("0"); 
    	
    	jlTime1.setText("出发时间");   
    
    	jlTime2.setVisible(false);
    	jtfTime2.setVisible(false);
	}
	//********************************************************************
	
	//determine wether can return ticket and performs
	private void tuiPiao()
	{
	    String  dingdan = jtfDingDan.getText().trim();
	    if (dingdan.length() == 0)
	    {
	    	JOptionPane.showMessageDialog(null,"订单号不能为空",
	    	                              "错误信息",JOptionPane.ERROR_MESSAGE);
	    	return;
	    }
	    
	    String id = jtfID.getText().trim();
	    if (id.length() == 0)
	    {
	    	JOptionPane.showMessageDialog(null,"身份证号不能为空",
	    	                              "错误信息",JOptionPane.ERROR_MESSAGE);
	    	return;
	    }
	    
	    boolean isValid = getClientInfo(dingdan,id);
	    
	    if (isValid == false)
	    {
	    	rewrite();
	    	return;
	    }	       
	       
	    else
	    {
	    	//when the tuipiaoshu is null,display the error message
	    	String childTuiPiaoShu = jtfChildTuiPiaoShu.getText().trim();
	    	String adultTuiPiaoShu = jtfAdultTuiPiaoShu.getText().trim();
	    	
	    	int cTuiPiaoShu = Integer.parseInt(childTuiPiaoShu);
	    	int aTuiPiaoShu = Integer.parseInt(adultTuiPiaoShu);
	    	
	    	if (cTuiPiaoShu == 0 && aTuiPiaoShu == 0)
	    	{

⌨️ 快捷键说明

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