?? staticsrenderbymonth.java
字號:
/*
* 功能描述:酒店的出租收入按月份統計查詢入口
* Author:黃順武
* Time:---
* Last Modified:2007-12-15
* Modify Reason:數據庫連接類DBConnection 的內部結構設計得到優化
*/
import javax.swing.*;
import sun.jdbc.rowset.*;
import java.sql.*;
public class StaticsRenderByMonth extends JPanel {
private String tip = "請輸入要查詢的年月:";
private DateMonthYear dateMonthYear = null;
private String valueGet = null;
private float result = 0;
private CheckYearMonth checkYM = null;
private String[][] numAndPrice = null;
private IdentityDate identityDate=new IdentityDate();//實例化對兩個日期進行相關性判斷的類對象
public StaticsRenderByMonth() {
dateMonthYear = new DateMonthYear();
if (valueGet == null) {
return;
}
checkYM = new CheckYearMonth();
String monthStr = checkYM.check(valueGet);
if (monthStr == null) {
return;
}
try {
DBConnection con = new DBConnection();
String query = "select bookNum,dateOut,Sprice from HUseBook,HGrade where hGrade=grade";
CachedRowSet crs = con.getResultSet(query);
int count = 0;
while (crs.next()) {
String dateOut = crs.getString(2);
crs.getFloat(3);
identityDate.setFirstDate(dateOut.trim());
identityDate.setSecondDate(monthStr);
if (identityDate.isInTheSameMonth()==0) {//兩個日期在同一年份
count++;
}
}
numAndPrice = new String[count][2];
crs.beforeFirst();
count = 0;
while (crs.next()) {
int numTemp = crs.getInt(1);
String dateOut = crs.getString(2);
float price = crs.getFloat(3);
identityDate.setFirstDate(dateOut.trim());
identityDate.setSecondDate(monthStr);
if (identityDate.isInTheSameMonth()==0) {//兩個日期在同一年份
numAndPrice[count][0] = String.valueOf(numTemp);
numAndPrice[count][1] = String.valueOf(price);
count++;
}
}
int temp = count;
count = 0;
for (; count < temp; count++) {
int bNum = Integer.valueOf(numAndPrice[count][0]);
float price = Float.valueOf(numAndPrice[count][1]);
result += (bNum * price);
}
JOptionPane.showMessageDialog(null, "該月客房出租收入為 " + result + " 元!",
"", JOptionPane.INFORMATION_MESSAGE);
} catch (ClassNotFoundException cnfe) {
cnfe.printStackTrace();
return;
} catch (SQLException sqle) {
sqle.printStackTrace();
return;
} catch (NumberFormatException nfe) {
nfe.printStackTrace();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -