CD在线商店销售系统设计
}
acds.setPublish(to_String(publish));
String cdclass = request.getParameter("cdclass");
int bc = Integer.parseInt(cdclass);
acds.setcdClass(bc);
String cdno = request.getParameter("cdno");
if (cdno == null)
{
cdno = "";
}
acds.setcdNo(to_String(cdno));
String picture = request.getParameter("picture");
if (picture == null)
{
picture = "images/01.gif";
}
acds.setPicture(to_String(picture));
float price;
try {
price =new Float(request.getParameter("price")).floatValue();
} catch (Exception e){
price = 0;
sqlflag = false;
}
acds.setPrice(price);
int amount;
try{
amount = new Integer(request.getParameter("amount")).intValue();
}catch (Exception e){
sqlflag = false;
amount = 0;
}
acds.setAmount(amount);
String musiclist = request.getParameter("musiclist");
if (musiclist == null)
{
musiclist = "";
}
acds.setmusiclist(to_String(musiclist));
if (sqlflag)
{
flag = true;
}
return flag;
}catch (Exception e){
return flag;
}
}
/**
* 获得查询CD类别的sql语句
* @return
*/
public String getSql() {
sqlStr = "select id,classname from cd order by id";
return sqlStr;
}
/**
* 完成CD查询,包括分类,分页查询
* @param res
* @return
* @throws java.lang.Exception
*/
public boolean cd_search(HttpServletRequest res) throws Exception {
DataBase db = new DataBase();
db.connect();
stmt = db.conn.createStatement ();
request = res;
String PAGE = request.getParameter("page"); //页码
String classid = request.getParameter("classid"); //分类ID号
String keyword = request.getParameter("keyword"); //查询关键词
if (classid==null) classid="";
if (keyword==null) keyword = "";
keyword = to_String(keyword).toUpperCase();
try {
page = Integer.parseInt(PAGE);
}catch (NumberFormatException e){
page = 1;
}
//取出记录数
if (!classid.equals("") && keyword.equals("") ) {
sqlStr = "select count(*) from cd where cdclass='"+classid + "'";
}
else if (!keyword.equals("")) {
if (classid.equals("")){
sqlStr = "select count(*) from cd where upper(cdname) like '%" +
keyword+ "%' or musiclist like '%" + keyword + "%'";
} else {
sqlStr = "select count(*) from cd where cdclass='" + classid
+ "' and (upper(cdname) like '%" +keyword+ "%' or "+
"musiclist like '%" + keyword + "%')";
}
} else {
sqlStr = "select count(*) from cd";
}
int rscount = pageSize;
try {
ResultSet rs1 = stmt.executeQuery(sqlStr);
if (rs1.next()) recordCount = rs1.getInt(1);
rs1.close();
}catch (SQLException e){
System.out.println(e.getMessage());
return false;
}
//设定有多少pageCount
if (recordCount < 1)
pageCount = 0;
else
pageCount = (int)(recordCount - 1) / pageSize + 1;
//检查查看的页面数是否在范围内
if (page < 1)
page = 1;
else if (page > pageCount)
page = pageCount;
rscount = (int) recordCount % pageSize; // 最后一页记录数
//sql为倒序取值
sqlStr = "select a.id,a.cdname,a.cdclass,b.classname,"+
"a.Singer,a.publish,a.cdno,a.musiclist,a.Price,a.amount,"+
"a.Leav_number,a.regtime,a.picture from cd a,cdclass b"+
" where a.cdclass = b.Id ";
if (!classid.equals("") && keyword.equals("") ){ //如果类别不为空,非查询
if (page == 1)
{
sqlStr = sqlStr + " and a.cdclass='" + classid + "' "+
"order by a.Id desc";
} else {
sqlStr = "select top "+ pageSize+" from (select top "+(recordCount-pageSize * (page-1)) +"from ("+sqlStr + " and a.cdclass='" + classid + "'))";
}
} else if (!keyword.equals("")) { //如果是查询资料
if (page == 1){
if (!classid.equals("")) {//查询某一类
sqlStr = sqlStr + "and a.cdclass='" +
classid + "' and (upper(a.cdname) like '%" +
keyword+ "%' or a.musiclist like '%" +
keyword + "%') order by a.Id desc";
} else { //查询所有类
sqlStr = sqlStr + " and (upper(a.cdname) like '%" +
keyword+ "%' or a.musiclist like '%" +
keyword + "%') order by a.Id desc";
}
} else {
if (!classid.equals("")){
sqlStr = "select top "+ pageSize+" from (select top "+(recordCount-pageSize * (page-1)) +"from ("+sqlStr + " and a.cdclass='" +
classid + "' and (upper(a.cdname) like '%" +
keyword+ "%' or a.musiclist like '%" +
keyword + "%') ))";
} else {
sqlStr = "select top "+ pageSize+" from (select top "+(recordCount-pageSize * (page-1)) +"from ("+sqlStr + " and (upper(a.cdname) like '%" +
keyword+ "%' or a.musiclist like '%" +
keyword + "%') ))";
}
}
} else {//非查询,也非分类浏览
if (page == 1) {
sqlStr = sqlStr + " order by a.Id desc ";
}
else {
sqlStr = "select top " + pageSize + " from (select top " +
(recordCount - pageSize * (page - 1)) + "from (" + sqlStr + "))";
}
}
try {
// System.out.println(sqlStr);
rs = stmt.executeQuery(sqlStr);
<< 上一页 [11] [12] [13] [14] [15] [16] [17] [18] [19] 下一页
电子商务毕业论文 第12页下载如图片无法显示或论文不完整,请联系qq752018766