📄 booksmn.java
字号:
package org.pan.web;
import java.sql.*;
import java.util.Date;
import java.util.Vector;
import java.util.*;
import org.pan.util.*;
import javax.servlet.http.HttpServletRequest;
import org.pan.web.book.books;
/**
* Title: 图书类别列表
* Description:
* Copyright: Copyright (c) 2003
* Company: 多智能网络有限公司
* @author: siny pan
* @version 1.0
*/
public class booksmn extends DataBase {
private books abooks = new books(); //新的图书类
private javax.servlet.http.HttpServletRequest request; //建立页面请求
private boolean sqlflag = true ; //对接收到的数据是否正确
private Vector booklist; //显示图书列表向量数组
private int page = 1; //显示的页码
private int pageSize=5; //每页显示的图书数
private long pageCount =0; //页面总数
private long recordCount =0; //查询的记录总数
public booksmn() throws Exception{
super();
}
public Vector getBooklist() {
return booklist;
}
public boolean getSqlflag() {
return sqlflag;
}
public String getGbk( String str) {
try
{
return new String(str.getBytes("ISO8859-1"));
}
catch (Exception e)
{
return str;
}
}
//将页面表单传来的资料分解
public boolean getRequest(javax.servlet.http.HttpServletRequest newrequest) {
boolean flag = false;
try
{
request = newrequest;
/* String ID = request.getParameter("id");
long bookid = 0;
try
{
bookid = Long.parseLong(ID);
}
catch (Exception e)
{
}*/
long bookid = 0;
try
{
ResultSet rs=stmt.executeQuery("select max(id) from my_Book");
if(rs.next())
{
bookid = rs.getInt(1)+1;
}
else
{
bookid = 0;
}
}catch(SQLException sql)
{
}
abooks.setId(bookid);
String bookname = request.getParameter("bookname");
if (bookname==null || bookname.equals(""))
{
bookname = "";
sqlflag = false;
}
abooks.setBookName(getGbk(bookname));
String author = request.getParameter("author");
if (author==null || author.equals(""))
{
author = "";
sqlflag = false;
}
abooks.setAuthor(getGbk(author));
String publish = request.getParameter("publish");;
if (publish==null)
{
publish = "";
}
abooks.setPublish(getGbk(publish));
String bookclass = request.getParameter("bookclass");
int bc = Integer.parseInt(bookclass);
abooks.setBookClass(bc);
String bookno = request.getParameter("bookno");
if (bookno == null)
{
bookno = "";
}
abooks.setBookNo(getGbk(bookno));
float price;
try {
price =new Float(request.getParameter("price")).floatValue();
}
catch (Exception e)
{
price = 0;
sqlflag = false;
}
abooks.setPrince(price);
int amount;
try
{
amount = new Integer(request.getParameter("amount")).intValue();
}
catch (Exception e)
{
sqlflag = false;
amount = 0;
}
abooks.setAmount(amount);
String path = request.getParameter("imgpath");
//System.out.println("Path测试:"+path);
if(path == null)
{
path = "";
}
//System.out.println("Path测试1:"+path);
abooks.setPath(path);
String content = request.getParameter("content");
if (content == null)
{
content = "";
}
abooks.setContent(getGbk(content));
/* System.out.println(abooks.getId());
System.out.println(abooks.getBookName());
System.out.println(abooks.getBookClass());
System.out.println(abooks.getAuthor());
System.out.println(abooks.getPublish());
System.out.println(abooks.getBookNo());
System.out.println(abooks.getContent());
System.out.println(abooks.getPrince());
System.out.println(abooks.getAmount());
System.out.println(abooks.getAmount());
System.out.println(new Date());*/
if (sqlflag)
{
flag = true;
}
return flag;
}
catch (Exception e)
{
return flag;
}
}
public String getSql() {
sqlStr = "select id,classname from my_Book order by id";
return sqlStr;
}
public boolean execute(HttpServletRequest res) throws Exception {
request = res;
String PAGE = request.getParameter("page");
if(PAGE != null)
{
page = Integer.parseInt(PAGE);
//System.out.println("page11111111:"+page);
}
else
{
page = 1;
}
sqlStr = "select count(*) from My_book";
try
{
rs = stmt.executeQuery(sqlStr);
while(rs.next())
{
recordCount = rs.getInt(1);
}
pageCount = (recordCount+pageSize-1)/pageSize;//页数
//System.out.println("pageCount:"+pageCount);
rs.close();
}
catch(SQLException e)
{
return false;
}
sqlStr = "select a.id,a.bookname,a.bookclass,b.classname,a.author,a.publish,a.bookno,a.content,a.prince,a.amount,a.Leav_number,a.regtime,a.imgpath from My_book a,My_bookclass b where a.Bookclass = b.Id ";
try
{
rs = stmt.executeQuery(sqlStr);
// booklist = new Vector(rscount);
booklist = new Vector();
booklist.removeAllElements();
while (rs.next())
{
int intTemp1 = (page-1)*pageSize;
int intTemp2 = page*pageSize;
//System.out.println("intTemp1:"+intTemp1+" "+"intTemp2:"+intTemp2);
if(intTemp1 < (rs.getRow()+1)&& rs.getRow() <= intTemp2)
{
books book = new books();
book.setId(rs.getInt(1));
book.setBookName(rs.getString(2));
book.setBookClass(rs.getInt(3));
book.setClassname(rs.getString(4));
book.setAuthor(rs.getString(5));
book.setPublish(rs.getString(6));
book.setBookNo(rs.getString(7));
book.setContent(rs.getString(8));
book.setPrince(rs.getFloat(9));
book.setAmount(rs.getInt(10));
book.setLeav_number(rs.getInt(11));
book.setRegTime(rs.getString(12));
String str = rs.getString(13);
str.replace('/','\\');
book.setPath(str);
booklist.addElement(book);
//System.out.println("Size"+booklist.size());
}
}
rs.close();
return true;
}
catch (SQLException e)
{
System.out.println(e);
return false;
}
}
public boolean insert() throws Exception {
/* sqlStr = "insert into my_book (Bookname,Bookclass,Author,Publish,Bookno,Content,Prince,Amount,Leav_number,Regtime) values ('";
sqlStr = sqlStr + strFormat.toSql(abooks.getBookName()) + "','";
sqlStr = sqlStr + abooks.getBookClass() + "','";
sqlStr = sqlStr + strFormat.toSql(abooks.getAuthor()) + "','";
sqlStr = sqlStr + strFormat.toSql(abooks.getPublish()) + "','";
sqlStr = sqlStr + strFormat.toSql(abooks.getBookNo()) + "','";
sqlStr = sqlStr + strFormat.toSql(abooks.getContent()) + "','";
sqlStr = sqlStr + abooks.getPrince() + "','";
sqlStr = sqlStr + abooks.getAmount() + "','";
sqlStr = sqlStr + abooks.getAmount() + "',";
sqlStr = sqlStr + "getdate())";*/
/* System.out.println(abooks.getId());
System.out.println(abooks.getBookName());
System.out.println(abooks.getBookClass());
System.out.println(abooks.getAuthor());
System.out.println(abooks.getPublish());
System.out.println(abooks.getBookNo());
System.out.println(abooks.getContent());
System.out.println(abooks.getPrince());
System.out.println(abooks.getAmount());
System.out.println(abooks.getAmount());
System.out.println(new Date());*/
String s = abooks.getPath();
s = s.replace('\\','/');
System.out.println("Path测试2:"+s);
sqlStr = "INSERT INTO my_book " +"VALUES('"+abooks.getId()+"','"+abooks.getBookName()+"','"+abooks.getBookClass()+"','"+abooks.getAuthor()+"','"+abooks.getPublish()+"','"+abooks.getBookNo()+"','"+abooks.getContent()+"','"+abooks.getPrince()+"','"+abooks.getAmount()+"','"+abooks.getAmount()+"','"+new Date().toLocaleString()+"','"+s+"')";
try
{
stmt.execute(sqlStr);
return true;
}
catch (SQLException sqle)
{
return false;
}
}
public boolean update() throws Exception {
String s = abooks.getPath();
s = s.replace('\\','/');
System.out.println("pathStr:"+s);
sqlStr = "update my_book set ";
sqlStr = sqlStr + "bookname = '" + strFormat.toSql(abooks.getBookName()) + "',";
sqlStr = sqlStr + "bookclass = '" + abooks.getBookClass() + "',";
sqlStr = sqlStr + "Author = '" + strFormat.toSql(abooks.getAuthor()) + "',";
sqlStr = sqlStr + "publish = '" + strFormat.toSql(abooks.getPublish()) + "',";
sqlStr = sqlStr + "bookno = '" + strFormat.toSql(abooks.getBookNo()) + "',";
sqlStr = sqlStr + "content = '" + strFormat.toSql(abooks.getContent()) + "',";
sqlStr = sqlStr + "prince = '" + abooks.getPrince() + "',";
sqlStr = sqlStr + "Amount = '" + abooks.getAmount() + "',";
sqlStr = sqlStr + "leav_number = '" + abooks.getAmount() + "',";
sqlStr = sqlStr + "imgpath = '" + s + "'";
sqlStr = sqlStr + "where id = '" + abooks.getId() + "'";
System.out.println(sqlStr);
try
{
stmt.execute(sqlStr);
return true;
}
catch (SQLException e)
{
return false;
}
}
public boolean delete( int aid ) throws Exception {
sqlStr = "delete from My_book where id = " + aid ;
try
{
stmt.execute(sqlStr);
return true;
}
catch (SQLException e)
{
System.out.println(e);
return false;
}
}
public boolean getOnebook(int newid ) throws Exception {
try
{
sqlStr="select a.id,a.bookname,a.bookclass,b.classname,a.author,a.publish,a.bookno,a.content,a.prince,a.amount,a.Leav_number,a.regtime from My_book a,My_bookclass b where a.Bookclass=b.Id and a.Id = " + newid ;
rs = stmt.executeQuery(sqlStr);
if (rs.next())
{ booklist = new Vector(1);
books book = new books();
book.setId(rs.getLong("id"));
book.setBookName(rs.getString("bookname"));
book.setBookClass(rs.getInt("bookclass"));
book.setClassname(rs.getString("classname"));
book.setAuthor(rs.getString("author"));
book.setPublish(rs.getString("publish"));
book.setBookNo(rs.getString("Bookno"));
book.setContent(rs.getString("content"));
book.setPrince(rs.getFloat("prince"));
book.setAmount(rs.getInt("amount"));
book.setLeav_number(rs.getInt("leav_number"));
book.setRegTime(rs.getString("regtime"));
booklist.addElement(book);
} else {
rs.close();
return false;
}
rs.close();
return true;
}
catch (SQLException e)
{
return false;
}
}
public int getPage() { //显示的页码
return page;
}
public void setPage(int newpage) {
page = newpage;
}
public int getPageSize(){ //每页显示的图书数
return pageSize;
}
public void setPageSize(int newpsize) {
pageSize = newpsize;
}
public long getPageCount() { //页面总数
return pageCount;
}
public void setPageCount(int newpcount) {
pageCount = newpcount;
}
public long getRecordCount() {
return recordCount;
}
public void setRecordCount(long newrcount) {
recordCount= newrcount;
}
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -