⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 managerproduct.java

📁 用jsp实现的大型商城源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
package myshop.product_sys;

import myshop.*;
import myshop.catalog_sys.*;
import java.sql.*;
import java.util.*;
import javax.servlet.http.*;

public class  ManagerProduct {
	Handle handle;
	DBconn dbconn;
	ManagerCatalog managercatalog;
	Config config;
	String SystemURL;

	public ManagerProduct() throws Exception {
		dbconn = new DBconn();
		handle = new Handle();
		config = new Config();
		managercatalog = new ManagerCatalog();
		SystemURL = config.systemURL + config.systemFolder;
	}

	//--- 插入商品数据 --- 
	public void AddProduct(HttpServletRequest request,String tb_shop_product_info,String img_path) throws Exception {
		HttpSession ses = request.getSession(true);
		if ( ses.getAttribute("administratorBean") != null )
		{
			String name = handle.GBK2ISO(request.getParameter("name"));
			String description = handle.GBK2ISO(request.getParameter("description"));
			String keywords = handle.GBK2ISO(request.getParameter("keywords"));
			description = handle.ConvertChar(description);
			float price = Float.parseFloat(request.getParameter("price"));
			float member_price = Float.parseFloat(request.getParameter("member_price"));
			int catalog_id = Integer.parseInt(request.getParameter("catalog_id"));
			int show_out = Integer.parseInt(request.getParameter("show_out"));
	
			String SqlStr = "INSERT INTO " + tb_shop_product_info + "(catalog_id,name,description,keywords,img_path,show_out,price,member_price,date_time) VALUES(" + catalog_id + ",'" + name + "','" + description + "','" + keywords + "','" + img_path + "'," + show_out + "," + price + "," + member_price + ",sysdate())";
			dbconn.ExeUpdate(SqlStr);
			dbconn.CloseConn();
		}
	}


	//--- 修改商品数据 --- 
	public void Modify(HttpServletRequest request,String tb_shop_product_info) throws Exception {
		HttpSession ses = request.getSession(true);
		if ( ses.getAttribute("administratorBean") != null )
		{
			String name = handle.GBK2ISO(request.getParameter("name"));
			String description = handle.GBK2ISO(request.getParameter("description"));
			String keywords = handle.GBK2ISO(request.getParameter("keywords"));
			description = handle.ConvertChar(description);
			float price = Float.parseFloat(request.getParameter("price"));
			float member_price = Float.parseFloat(request.getParameter("member_price"));
			int catalog_id = Integer.parseInt(request.getParameter("catalog_id"));
			int Pid = Integer.parseInt(request.getParameter("Pid"));
	
			String SqlStr = "UPDATE " + tb_shop_product_info + " SET name='" + name + "',description='" + description + "',keywords='" + keywords + "',price=" + price + ",member_price=" + member_price + ",catalog_id=" + catalog_id + " WHERE id=" + Pid;
			dbconn.ExeUpdate(SqlStr);
			dbconn.CloseConn();
		}
	}

	//--- 删除商品 ---
	public void Del(HttpServletRequest request,String tb_shop_product_info,String tb_gbook_info) throws Exception {
		HttpSession ses = request.getSession(true);
		if ( ses.getAttribute("administratorBean") != null )
		{
			ResultSet rs;
			String SqlStr;
			int Pid = Integer.parseInt(request.getParameter("Pid"));
	
			try {
				SqlStr = "SELECT * FROM " + tb_shop_product_info + " WHERE id=" + Pid;
				rs = dbconn.ExeQuery(SqlStr);
				if (rs.next()) handle.Del(request,"..\\..\\" + rs.getString("img_path"));
				dbconn.CloseConn();
			}
			catch (SQLException ex) {
				System.err.println("aq.executeQuery:"+ex.getMessage());
			}
	
			SqlStr = "DELETE FROM " + tb_shop_product_info + " WHERE id=" + Pid;
			dbconn.ExeUpdate(SqlStr);
			SqlStr = "DELETE FROM " + tb_gbook_info + " WHERE product_id=" + Pid;
			dbconn.ExeUpdate(SqlStr);
	
			dbconn.CloseConn();
		}
	}

	//--- 列表最新商品 ---
	//action=new,显示最新假如商品。
	//action=其他,显示推介商品。
	public String ListProducts(String tb_shop_catalog,String tb_shop_product_info,int rows_num,int column_num,int img_width,int img_height,String action) throws Exception {
		String SqlStr;
		ResultSet rs;
		String TableStr = "";
		String Description = "";
		int i,j;
		
		TableStr += "<table width=100% border=0 cellspacing=3 cellpadding=3>\n";
		try {
			if (action.equals("new")) SqlStr = "SELECT * FROM " + tb_shop_product_info + " ORDER BY id DESC";
			else SqlStr = "SELECT * FROM " + tb_shop_product_info + " WHERE show_out=1 ORDER BY id DESC";
			rs = dbconn.ExeQuery(SqlStr);
			for (i=0; i<rows_num; i++) {
				TableStr += "<tr>\n";
				for (j=0; j<column_num; j++) {
					if (!rs.next()) break;
					if (rs.getString("img_path").indexOf(".") != -1) TableStr += "<td align=center valign=middle><a href=DetailProInfo.jsp?Pid=" + rs.getInt("id") + "><img src=" + rs.getString("img_path") + " border=1 width=" + img_width + " height=" + img_height + "></a></td>\n";
					else TableStr += "<td align=center valign=middle><a href=DetailProInfo.jsp?Pid=" + rs.getInt("id") + "><img src=img/que.gif border=1 width=" + img_width + " height=" + img_height + "></a></td>\n";
					TableStr += "<td align=left valign=middle>" + rs.getString("name") + "<br><font color=red>¥<span class=xiexian>" + rs.getFloat("price") + "</span></font><br><font color=red>¥" + rs.getFloat("member_price") + "</font></td>\n";
				}
				TableStr += "</tr>\n";
			}
			dbconn.CloseConn();
		}
		catch (SQLException ex) {
			System.err.println("aq.executeQuery:"+ex.getMessage());
		}
		TableStr += "</table>";

		return (TableStr);
	}

	//--- 根据货架ID找到货架名称 ---
	public String InTheCatalog(String tb_shop_catalog,int id) throws Exception {
		String SqlStr;
		String titleC = "",titleP = "",titleP2 = "";
		ResultSet rs;
		int parentid=0;

		try {
			SqlStr = "SELECT title,parentid FROM " + tb_shop_catalog + " WHERE id=" + id;
			rs = dbconn.ExeQuery(SqlStr);
			if (rs.next()) {
				parentid = rs.getInt("parentid");
				titleC = rs.getString("title");
			}
			SqlStr = "SELECT title FROM " + tb_shop_catalog + " WHERE id=" + parentid;
			rs = dbconn.ExeQuery(SqlStr);
			if (rs.next()) titleP = rs.getString("title");
			dbconn.CloseConn();
		}
		catch (SQLException ex) {
			System.err.println("aq.executeQuery:"+ex.getMessage());
		}
		titleP2 = titleP;
		titleP = "<a href=admin/catalog_sys/ListDetailType.jsp?catalogName=" + titleP + ">" + titleP + "</a>";
		titleC = "<a href=admin/product_sys/DetailCatalog.jsp?Cid=" + id + "&Catalog_f=" + titleP2 + "&Catalog_s=" + titleC + ">" + titleC + "</a>";
		return (titleP + " &gt; " + titleC);
	}

	//--- 热卖商品 ---
	public String HotSell(String tb_shop_product_info) throws Exception {
		String SqlStr;
		String TableStr = "";
		ResultSet rs;
		float i;
		
		try {
			SqlStr = "SELECT id,name FROM " + tb_shop_product_info + " ORDER BY purchase_num DESC";
			rs = dbconn.ExeQuery(SqlStr);
			TableStr += "<table width=100% border=0 cellspacing=0 cellpadding=3>";
			for (i=0; i<10; i++) {
				if (!rs.next()) break;
				int t1 = (int)(i + 1);
				if (i/2 == (int)i/2) TableStr += "<tr>";
				else TableStr += "<tr bgcolor=#ffffFF>";
				TableStr += "<td width=82%><a href=" + SystemURL + "DetailProInfo.jsp?Pid=" + rs.getInt("id") + ">" + rs.getString("name") + "</a></td>";
				TableStr += "</tr>";
			}
			TableStr += "</table>";
			dbconn.CloseConn();
		}
		catch (SQLException ex) {
			System.err.println("aq.executeQuery:"+ex.getMessage());
		}

		return (TableStr);
	}

	//--- 读取首页数据 ---
	public Hashtable ReadDataAdmin(String page,int pagesize,String SelfPage,String keywords,String type,String tb_name) throws Exception {
		String qry_string;
		String HtmlStr="";
		String str_rows_count;
		int rows_count = 0;
		float i=0;
		int z;
		int ii=0;
		Statement stmt;
		ResultSet rs;
		Hashtable APageParam = new Hashtable();
		Hashtable AOutParam = new Hashtable();

		try {
			keywords = handle.GBK2ISO(keywords);

			if (type.equals("name")) qry_string = "SELECT * FROM " + tb_name + " WHERE name LIKE '%" + keywords + "%' ORDER BY id DESC";
			else if (type.equals("description")) qry_string = "SELECT * FROM " + tb_name + " WHERE description LIKE '%" + keywords + "%' ORDER BY id DESC";
			else qry_string = "SELECT * FROM " + tb_name + " ORDER BY id DESC";

			rs = dbconn.ExeQuery(qry_string);
			rs.last();
			rows_count = rs.getRow();

			APageParam = turn_page(page, pagesize, rows_count);

			int pt_st = Integer.parseInt(java.lang.String.valueOf(APageParam.get("pt_st"))) + 1;
			int pt_en = Integer.parseInt(java.lang.String.valueOf(APageParam.get("pt_en"))) + 1;

			rs.absolute(pt_st);
			for (ii=pt_st; ii<pt_en; ii++) {
				i++;
				int id = rs.getInt("id");
				int show_out = rs.getInt("show_out");
				int absence = rs.getInt("absence");
				int importance_show = rs.getInt("importance_show");
				String name = rs.getString("name");
	
				String td_bg_color;
				if ((i / 2) == (int)(i / 2))  td_bg_color = "f1f1f1";
				else  td_bg_color = "ffffff";
	
				String ShowOutStr;
				if (show_out == 0) ShowOutStr = " <a href=DealWithCenter.jsp?action=show_out&Pid=" + id + "><font color=red>推介</font></a>";
				else ShowOutStr = " <a href=DealWithCenter.jsp?action=unshow_out&Pid=" + id + ">还原</a>";

				String ShowOutStr2;
				if (absence == 0) ShowOutStr2 = " <a href=DealWithCenter.jsp?action=mark_absence&Pid=" + id + "><font color=black>缺货</font></a>";
				else ShowOutStr2 = " <a href=DealWithCenter.jsp?action=unmark_absence&Pid=" + id + ">有货</a>";

				String ShowOutStr3;
				if (importance_show == 0) ShowOutStr3 = "[<a href=DealWithCenter.jsp?action=importanceshow&Pid=" + id + ">重点推荐</a>]";
				else ShowOutStr3 = "[<a href=DealWithCenter.jsp?action=unimportanceshow&Pid=" + id + "><font color=#FF33CC>撤消重点</font></a>]";

				HtmlStr += "  <tr align=center valign=middle bgcolor=" + td_bg_color + "> ";
				HtmlStr += "    <td><input type=checkbox name=checkbox value=" + id + "></td>";
				HtmlStr += "    <td>" + (int)i + "-" + id + "</td>";
				HtmlStr += "    <td><a href=detail.jsp?Pid=" + id + ">" + rs.getString("name") + "</a></td>";
				HtmlStr += "    <td><font color=red>" + rs.getString("price") + "</font></td>";
				HtmlStr += "    <td>" + rs.getInt("click") + "</td>";
				HtmlStr += "    <td>" + rs.getInt("purchase_num") + "</td>";
				HtmlStr += "    <td>" + rs.getString("keywords") + "</td>";
				HtmlStr += "    <td>" + rs.getString("date_time") + "</td>";
				HtmlStr += "    <td><a href=DealWithCenter.jsp?Pid=" + id + "><font color=blue>修改</font></a> <a href=DealWithCenter.jsp?action=del&Pid=" + id + " onclick=\"return (AlertDel('" + rs.getString("name") + "'));\"><font color=red>删除</font></a><br>" + ShowOutStr + " " + ShowOutStr2 + "<br>" + ShowOutStr3 + "</td>";
				HtmlStr += "  </tr>";

				if (!rs.next()) break;
			}
			dbconn.CloseConn();
		}
		catch(SQLException ex) {
			System.err.println("aq.executeQuery:"+ex.getMessage());
		}

		String turnpage_str = search_turn(APageParam, SelfPage, keywords, type);
		
		AOutParam.put("RecordCount",java.lang.String.valueOf(rows_count));
		AOutParam.put("HtmlStr",HtmlStr);
		AOutParam.put("TurpageStr",turnpage_str);

		return(AOutParam);
	}

	//--- 翻页函数 ---
	public Hashtable turn_page(String page,int pagesize,int rows_count) {
		//int APageParam[] = new int[10];
		int pagecount;
		int pagecount2;
		int page1=0;
		int page2;
		int pt_st;
		int pt_en;
		int nextpage;
		int prevpage;
		int out_page;
		Hashtable APageParam = new Hashtable();

		if (!page.equals("")) page1 = Integer.parseInt(page);
		pagecount = rows_count / pagesize;
		if (pagesize * pagecount < rows_count) pagecount++;
		if (Integer.parseInt(page) > pagecount) page1 = pagecount - 1;
		else if (Integer.parseInt(page) < 0) page1 = 0;
		pagecount2 = pagecount - 1;
		page2 = page1 + 1;
		pt_st = page1 * pagesize;
		pt_en = pt_st + pagesize;
		nextpage = page1 + 1;
		prevpage = page1 - 1;

		APageParam.put("pt_st",new Integer(pt_st));
		APageParam.put("pt_en",new Integer(pt_en));
		APageParam.put("nextpage",new Integer(nextpage));
		APageParam.put("prevpage",new Integer(prevpage));
		APageParam.put("pagesize",new Integer(pagesize));
		APageParam.put("pagecount",new Integer(pagecount));
		APageParam.put("pagecount2",new Integer(pagecount2));
		APageParam.put("page1",new Integer(page1));
		APageParam.put("page2",new Integer(page2));
		

		return(APageParam);
	}

	public String search_turn(Hashtable APageParam,String SelfPage,String keywords,String type) throws Exception {
		String turnpage_str="";

⌨️ 快捷键说明

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