📄 receivemespagebean.java
字号:
package edu.scfc;
import java.sql.*;
import java.util.*;
public class ReceiveMesPageBean {
private int curPage = 1;//当前是第几页
private int maxPage; //一共多少页
private int maxRowCount; //一共有多少行
public int rowsPerpage = 5; //每页多少行
Connection con = null;
public java.util.Vector data;
public ReceiveMesPageBean() throws Exception {
//this.setPageBean();
}
public void setMaxPage(int maxPage){
this.maxPage = maxPage;
}
public int getMaxPage(){
return this.maxPage;
}
public void setCurPage(int curPage){
this.curPage=curPage;
}
public int getCurPage(){
return this.curPage;
}
public void setMaxRowCount(int maxRowCount){
this.maxRowCount=maxRowCount;
}
public int getMaxRowCount(){
return this.maxRowCount;
}
public ReceiveMesPageBean getResult(String page,String realName){
//得到要显示在本页显示的数据
try{
ReceiveMesPageBean objpageBean = new ReceiveMesPageBean();
Vector vc = new Vector();
int pageNum = Integer.parseInt(page);
ConnDB objConnDB = new ConnDB();
con = objConnDB.getConnection();
Statement stmt = con.createStatement();
String strSql="select top " + pageNum * objpageBean.rowsPerpage + " * from TB_ReceiveMes where ReceiveUName='"+realName+"' order by ReceiveTime DESC";
ResultSet rs = stmt.executeQuery(strSql);
int i=0;
while(rs.next()){
if(i>(pageNum-1)*objpageBean.rowsPerpage-1){
Object[] obj = new Object[7];
obj[0] = rs.getString("Title");
obj[1] = rs.getString("Content");
obj[2] = rs.getString("ReceiveUName");
obj[3] = rs.getString("ReceiveTime").substring(0,19);
obj[4] = rs.getString("ReadOnly").trim();
obj[5] = rs.getString("SendDept");
obj[6] = rs.getString("SendUName");
vc.add(obj);
}
i++;
}
rs.close();
stmt.close();
objpageBean.setCurPage(pageNum);
objpageBean.data=vc;
return objpageBean;
}catch(Exception ex){
ex.printStackTrace();
}
return null;
}
public int getAvailableCount(String realName) throws Exception {
int ret = 0;
ConnDB objConnDB = new ConnDB();
con = objConnDB.getConnection();
Statement stmt = con.createStatement();
String strSql = "Select * from TB_ReceiveMes where ReceiveUName = '"+realName+"'";
ResultSet rs = stmt.executeQuery(strSql);
while(rs.next()){
ret++;
}
return ret;
}
public void setReceiveMesPageBean(String realName) {
//得到总行数
try {
this.setMaxRowCount(this.getAvailableCount(realName));
} catch (Exception ex) {
}
if(this.maxRowCount % this.rowsPerpage==0){
//根据总行数计算总页数
this.maxPage = this.maxRowCount / this.rowsPerpage;
}else{
this.maxPage = this.maxRowCount / this.rowsPerpage + 1;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -