staticsrenderbyyear.java

来自「JAVA实现的酒店管理系统」· Java 代码 · 共 104 行

JAVA
104
字号
package file1;
/*
 * 功能描述:酒店的总收入按年份统计查询入口
 * @Author:黄顺武
 * Version:1.3
 */
import javax.swing.*;
import sun.jdbc.rowset.*;
import java.util.StringTokenizer;
import java.sql.*;

public class StaticsRenderByYear extends JPanel{

	private String tip="请输入要查询的年份:";
	private DateMonthYear dateMonthYear=null;
	private String valueGet=null;
	private float result=0;
	private String[] bookNum=null;
	private String[] hNoS=null;
	private IdentityDate identityDate=new IdentityDate();//实例化对两个日期进行相关性判断的类对象
	
	public StaticsRenderByYear(){
		dateMonthYear=new DateMonthYear();
		valueGet=dateMonthYear.getValueGet(tip);
		if(valueGet==null){
			return;
		}
		try{
			int year=Integer.valueOf(valueGet);
			DBConnection con=new DBConnection();
			String query="select bookNum,hNo,dateOut from HUseBook";
			CachedRowSet crs=con.getResultSet(query);
			int count=0;
			while(crs.next()){
				crs.getInt(1);
				crs.getString(2);
				String dateOut=crs.getString(3);
				identityDate.setFirstDate(dateOut.trim());
				identityDate.setSecondDate(year+"-01");
				if(identityDate.isInTheSameYear()==0){//两个日期在同一年份
					count++;
				}
			}
			bookNum=new String[count];
			hNoS=new String[count];
			crs.beforeFirst();
			count=0;
			while(crs.next()){
				int numTemp=crs.getInt(1);
				String hNoTemp=crs.getString(2);
				String dateOut=crs.getString(3);
				identityDate.setFirstDate(dateOut.trim());
				identityDate.setSecondDate(year+"-01");
				if(identityDate.isInTheSameYear()==0){//两个日期在同一年份
					bookNum[count]=String.valueOf(numTemp);
					hNoS[count]=hNoTemp;
					count++;
				}
			}
			crs=null;
			int temp=count;
			count=0;
			float price=0;
			int num=0;
			for(;count<temp;count++){
				if(hNoS[count].indexOf(",")==-1){
					query="select Sprice from House,HGrade where HouseNo='"+hNoS[count]+"' and hGrade=grade";
					crs=con.getResultSet(query);
					if(crs.next()){
						price=crs.getFloat(1);
						num=Integer.valueOf(bookNum[count]);
						result+=(num*price);
					}
				}else{
					StringTokenizer st=new StringTokenizer(hNoS[count],",");
					int seed=0;
					String sHNo=null;
					while(st.hasMoreTokens()){
						sHNo=st.nextToken();
						if(seed==0){
							break;
						}
					}
					query="select Sprice from House,HGrade where HouseNo='"+sHNo+"' and hGrade=grade";
					crs=con.getResultSet(query);
					if(crs.next()){
						price=crs.getFloat(1);
						num=Integer.valueOf(bookNum[count]);
						result+=(num*price);
					}
				}
			}
			JOptionPane.showMessageDialog(null, "该年客房出租收入为 "+result+" 元!","",JOptionPane.INFORMATION_MESSAGE);
		}catch(ClassNotFoundException cnfe){
			cnfe.printStackTrace();
		}catch(SQLException sqle){
			sqle.printStackTrace();
		}catch(NumberFormatException nfe){
			JOptionPane.showMessageDialog(null, "输入日期格式必须为如2008的格式!","",JOptionPane.INFORMATION_MESSAGE);
		}
		
	}
}

⌨️ 快捷键说明

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