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

📄 managercatalog.java

📁 cwc 源码 非常好的代码 大家可以学习学习
💻 JAVA
字号:
package myshop.catalog_sys;

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

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

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

	//--- 显示主要货架 ---
	public String ShowMainCatalog(String tb_shop_catalog) throws Exception {
		String SqlStr,SqlStr1;
		String TableStr = "";
		ResultSet rs,rs1;
		float i = 0;

		try {
			SqlStr = "SELECT * FROM " + tb_shop_catalog + " WHERE parentid=0 ORDER BY id DESC";
			rs = dbconn.ExeQuery(SqlStr);
			TableStr += "<table width=100% border=0 cellspacing=0 cellpadding=3>";
			while (rs.next()) {
				TableStr += "<tr>";
				int id = rs.getInt("id");
				TableStr += "<td width=100%>" + rs.getString("title") + "</td>";
				TableStr += "</tr>";
				//--- 搜索子分类 ---
				SqlStr1 = "SELECT * FROM " + tb_shop_catalog + " WHERE parentid=" + id + " ORDER BY id DESC";
				rs1 = dbconn.ExeQuery(SqlStr1);
				TableStr += "<tr><td width=100% style=\"word-break:break-all;\">";
				while (rs1.next()) {
					//i++;
					TableStr += "<a href=" + SystemURL + "admin/product_sys/DetailCatalog.jsp?Cid=" + rs1.getInt("id") + "&Catalog_f=" + rs.getString("title") + "&Catalog_s=" +  rs1.getString("title") + ">" + rs1.getString("title") + "</a> ";
					//if (i/3 == (int)i/3) TableStr += "<br>";
				}
				//i = 0;
				TableStr += "</td></tr>";
			}
			TableStr += "</table>";
			dbconn.CloseConn();
		}
		catch (SQLException ex) {
			System.err.println("aq.executeQuery:"+ex.getMessage());
		}

		return (TableStr);
	}

	//--- 列举所有货架名称 ---
	public String ListCatalog(String tb_catalog) throws Exception {
		String SqlStr;
		String SqlStr2;
		ResultSet rs = null;
		ResultSet rs2 = null;
		String OptionStr = "";
		
		try {
			SqlStr = "SELECT * FROM " + tb_catalog + " WHERE parentid=0 ORDER BY id DESC";
			rs = dbconn.ExeQuery(SqlStr);
			while (rs.next()) {
				int id = rs.getInt("id");
				OptionStr += "<option value=" + id + ">" + rs.getString("title") + "</option>\n";
				SqlStr2 = "SELECT * FROM " + tb_catalog + " WHERE parentid=" + id + " ORDER BY id DESC";
				rs2 = dbconn.ExeQuery(SqlStr2);
				while (rs2.next()) OptionStr += "<option value=" + rs2.getInt("id") + "> ├" + rs2.getString("title") + "</option>\n";
			}
			dbconn.CloseConn();
		}
		catch (SQLException ex) {
			System.err.println("aq.executeQuery:"+ex.getMessage());
		}

		return (OptionStr);
	}

	public String ListCatalog(String tb_catalog,int Cid) throws Exception {
		String SqlStr;
		String SqlStr2;
		ResultSet rs = null;
		ResultSet rs2 = null;
		String OptionStr = "";
		
		try {
			SqlStr = "SELECT * FROM " + tb_catalog + " WHERE parentid=0 ORDER BY id DESC";
			rs = dbconn.ExeQuery(SqlStr);
			while (rs.next()) {
				int id = rs.getInt("id");
				OptionStr += "<option value=" + id + ">" + rs.getString("title") + "</option>\n";
				SqlStr2 = "SELECT * FROM " + tb_catalog + " WHERE parentid=" + id + " ORDER BY id DESC";
				rs2 = dbconn.ExeQuery(SqlStr2);
				while (rs2.next()) {
					if (rs2.getInt("id") == Cid) OptionStr += "<option value=" + rs2.getInt("id") + " selected> ├" + rs2.getString("title") + "</option>\n";
					else OptionStr += "<option value=" + rs2.getInt("id") + "> ├" + rs2.getString("title") + "</option>\n";
				}
			}
			dbconn.CloseConn();
		}
		catch (SQLException ex) {
			System.err.println("aq.executeQuery:"+ex.getMessage());
		}

		return (OptionStr);
	}

	//--- 输出检测归类的JS代码 ---
	public String CheckPareid(String tb_catalog) throws Exception {
		String HtmlStr = "";
		String SqlStr;
		int id,parentid;
		ResultSet rs = null;		
		
		try {
			SqlStr = "SELECT * FROM " + tb_catalog;
			rs = dbconn.ExeQuery(SqlStr);
			HtmlStr += "function CheckParentid(Cid) {\n";
			HtmlStr += "	var ParentId;\n";
			while (rs.next()) {
				id = rs.getInt("id");
				parentid = rs.getInt("parentid");
				HtmlStr += "if (Cid == " + id + ") ParentId = " + parentid + ";\n";
			}
			HtmlStr += "	if (ParentId == 0) alert('不能把商品归类到主类货架,请归类到子类货架!');\n";
			HtmlStr += "}\n";
			dbconn.CloseConn();
		}
		catch (SQLException ex) {
			System.err.println("aq.executeQuery:"+ex.getMessage());
		}

		return (HtmlStr);
	}

	//--- 列举所有主货架名称 ---
	public String ListMainCatalog(String tb_catalog) throws Exception {
		String SqlStr;
		ResultSet rs;
		String OptionStr = "";
		
		try {
			SqlStr = "SELECT * FROM " + tb_catalog + " WHERE parentid=0 ORDER BY id DESC";
			rs = dbconn.ExeQuery(SqlStr);
			while (rs.next()) OptionStr += "<option value=" + rs.getInt("id") + ">" + rs.getString("title") + "</option>\n";
			dbconn.CloseConn();
		}
		catch (SQLException ex) {
			System.err.println("aq.executeQuery:"+ex.getMessage());
		}

		return (OptionStr);
	}


	//--- 添加货架 ---
	public void AddCatalog(String tb_shop_catalog,HttpServletRequest request) throws Exception {
		HttpSession ses = request.getSession(true);
		if ( ses.getAttribute("administratorBean") != null )
		{
			String title = handle.getString(request,"title");
			int parentid = handle.getInt(request,"parentid");
	
			title = handle.GBK2ISO(title);
			String SqlStr = "INSERT INTO " + tb_shop_catalog + "(title,parentid) VALUES('" + title + "'," + parentid + ")";
			dbconn.ExeUpdate(SqlStr);
			dbconn.CloseConn();
		}
	}

	//--- 修改货架 ---
	public void ModCatalog(String tb_shop_catalog,HttpServletRequest request) throws Exception {
		HttpSession ses = request.getSession(true);
		if ( ses.getAttribute("administratorBean") != null )
		{
			String title = handle.getString(request,"title");
			int catalog_id = handle.getInt(request,"catalog_id");
	
			title = handle.GBK2ISO(title);
			String SqlStr = "UPDATE " + tb_shop_catalog + " SET title='" + title + "' WHERE id=" + catalog_id;
			dbconn.ExeUpdate(SqlStr);
			dbconn.CloseConn();
		}
	}

	//--- 删除货架 ---
	public void DelCatalog(String tb_shop_catalog,String tb_shop_product_info,HttpServletRequest request) throws Exception {
		HttpSession ses = request.getSession(true);
		if ( ses.getAttribute("administratorBean") != null )
		{
			ResultSet rs;
			int catalog_id = handle.getInt(request,"catalog_id");
	
			String SqlStr = "DELETE FROM " + tb_shop_catalog + " WHERE id=" + catalog_id;
			dbconn.ExeUpdate(SqlStr);
			
			SqlStr = "DELETE FROM " + tb_shop_catalog + " WHERE parentid=" + catalog_id;
			dbconn.ExeUpdate(SqlStr);
	
			try {
				SqlStr = "SELECT * FROM " + tb_shop_product_info + " WHERE catalog_id=" + catalog_id;
				rs = dbconn.ExeQuery(SqlStr);
				while (rs.next()) handle.Del(request,"..\\..\\" + rs.getString("img_path"));
			}
			catch (SQLException ex) {
				System.err.println("aq.executeQuery:"+ex.getMessage());
			}
	
			SqlStr = "DELETE FROM " + tb_shop_product_info + " WHERE catalog_id=" + catalog_id;
			dbconn.ExeUpdate(SqlStr);
			dbconn.CloseConn();
		}
	}

	//--- 列举某大类下的子类和其下的所有商品 ---
	public String ListDetailType(HttpServletRequest request,String tb_shop_catalog,String tb_shop_product_info) throws Exception {
		int Cid=0,SubCid,pid;
		float price=0;
		ResultSet rs1,rs2,rs3;
		String SqlStr1,SqlStr2,SqlStr3,HtmlStr="";
		String ParCataName,SubCataName,ProName,catalogName;

		catalogName = handle.getString(request,"catalogName");
		ParCataName = catalogName;
		catalogName = handle.GBK2ISO(catalogName);

		try {
			SqlStr1 = "SELECT * FROM " + tb_shop_catalog + " WHERE title = '" + catalogName + "'";
			rs1 = dbconn.ExeQuery(SqlStr1);
			if (rs1.next()) Cid = rs1.getInt("id");
			
			SqlStr2= "SELECT * FROM " + tb_shop_catalog + " WHERE parentid = " + Cid + " ORDER BY id DESC";
			rs2 = dbconn.ExeQuery(SqlStr2);
			while (rs2.next()) {
				SubCid = rs2.getInt("id");
				SubCataName = rs2.getString("title");

				HtmlStr += "<table width=97% border=0 cellspacing=0 cellpadding=4>\n";
				HtmlStr += "<tr>\n";
				HtmlStr += "<td colspan=2 bgcolor=ccccff class=line1>" + ParCataName + " -&gt; <a href=../product_sys/DetailCatalog.jsp?Cid=" + SubCid + "&Catalog_f=" + ParCataName + "&Catalog_s=" + SubCataName + ">" + SubCataName + "</a></td>\n";
				HtmlStr += "</tr>\n";
				
				SqlStr3= "SELECT * FROM " + tb_shop_product_info + " WHERE catalog_id = " + SubCid + " ORDER BY id DESC";
				rs3 = dbconn.ExeQuery(SqlStr3);
				while (rs3.next()) {
					ProName = rs3.getString("name");
					price = rs3.getFloat("price");
					pid = rs3.getInt("id");

					HtmlStr += "<tr bgcolor=eeeeee>\n";
					HtmlStr += "<td><a href=../../DetailProInfo.jsp?Pid=" + pid + ">" + ProName + "</a></td><td align=center valign=middle>市场价:<font color=red>¥<span class=xiexian>" + price + "</span></font> 会员价:<font color=red>¥" + rs3.getFloat("member_price") + "</font></td>\n";
					HtmlStr += "</tr>\n";
				}
				HtmlStr += "</table>\n";
				HtmlStr += "<br>\n";
			}
			dbconn.CloseConn();
		}
		catch (SQLException ex) {
			System.err.println("aq.executeQuery:"+ex.getMessage());
		}

		return(HtmlStr);
	}

}

⌨️ 快捷键说明

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