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

📄 productcontrollerimpl.java

📁 JSP开发的完整的网络商店.包含源代码和开发文档等
💻 JAVA
字号:
/*
 * Created on 2005-10-29
 * Author 曹汕
 * Version 1.0
 * Copyright by CS.SSPKU Inc. All rights reserved. 
 */
package com.struts.controller.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

import com.struts.utils.*;
import com.struts.business.*;
import com.struts.controller.ProductController;

/**
 * @author cs
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class ProductControllerImpl extends ControllerImpl implements ProductController{
	
	private static ProductControllerImpl _instance;

	/**
	 * 单例模式,只创建唯一一个实例 
	 * @return 返还ProductController 类的惟一实例
	 */
	public static synchronized ProductControllerImpl getInstance() {
		if (_instance == null)
			_instance = new ProductControllerImpl();
		return _instance;
	}
	
	public ProductControllerImpl(){
		}
	/**
	 * 显示产品的详细信息 
	 */
	public Vector getProductInfo(){
		ResultSet rs=null;
		Vector vc=new Vector();
		
		String strSql="select * from vw_product";
		rs=selectRecord(strSql);
		try {
			while(rs.next()){
					Product product=new Product();
					product.setId(rs.getInt("ID"));
					product.setName(rs.getString("PRODUCTNAME"));
					product.setCode(rs.getString("CODE"));
					product.setStandard_price(rs.getDouble("STANDARD_PRICE"));
					product.setBarcode(rs.getString("BARCODE"));
					product.setPic_url(rs.getString("PIC_URL"));
					product.setDescription(rs.getString("DESCRIPTION"));
					product.setProduct_type(rs.getInt("TYPEID"));
					product.setProduct_typename(rs.getString("TYPENAME"));
					product.setStock_quantity(rs.getInt("STOCK_QUANTITY"));
					product.setMember_price(rs.getDouble("MEMEBER_PRICE"));
					vc.add(product);
				}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return vc;
		}
	/**
	 * 显示指定产品的详细信息
	 * @param:产品ID
	 * @return:结果以对象形式返回
	 */
	public Product getProductDetailInfo(int id){
		ResultSet rs=null;
		Product product=new Product();
		String strSql="select * from vw_product where id="+id;
		System.out.println("The SQL String>>>>>>>>>>"+strSql);
		rs=selectRecord(strSql);
		try {
			while(rs.next())
			{
				product.setId(rs.getInt("ID"));
				product.setName(rs.getString("PRODUCTNAME"));
				product.setCode(rs.getString("CODE"));
				product.setStandard_price(rs.getDouble("STANDARD_PRICE"));
				product.setBarcode(rs.getString("BARCODE"));
				product.setPic_url(rs.getString("PIC_URL"));
				product.setDescription(rs.getString("DESCRIPTION"));
				product.setProduct_type(rs.getInt("TYPEID"));
				product.setProduct_typename(rs.getString("TYPENAME"));
				product.setStock_quantity(rs.getInt("STOCK_QUANTITY"));
				product.setMember_price(rs.getDouble("MEMEBER_PRICE"));
				
				}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return product;
		}
	
	/**
	 * 查找产品的详细信息 
	 * @param:产品类别,产品名称
	 * @return:结果集放入Vector返回
	 */
	public Vector getProductSearchResult(int typeId,String name){
		ResultSet rs=null;
		Vector vc=new Vector();
		StringBuffer strSql=new StringBuffer();
		System.out.println("------------------------------------------------------");
		strSql.append("select * from vw_product where 1=1 ");
		if(typeId!=0)strSql.append("and typeid="+typeId);
		if(name!=null&&!name.equals(""))strSql.append("and productname like '%"+name+"%'");
		System.out.println("SQL Query>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"+strSql);
		rs=selectRecord(strSql.toString());
		try {
			while(rs.next()){
					Product product=new Product();
					product.setId(rs.getInt("ID"));
					product.setName(rs.getString("PRODUCTNAME"));
					product.setCode(rs.getString("CODE"));
					product.setStandard_price(rs.getDouble("STANDARD_PRICE"));
					product.setBarcode(rs.getString("BARCODE"));
					product.setPic_url(rs.getString("PIC_URL"));
					product.setDescription(rs.getString("DESCRIPTION"));
					product.setProduct_type(rs.getInt("TYPEID"));
					product.setProduct_typename(rs.getString("TYPENAME"));
					product.setStock_quantity(rs.getInt("STOCK_QUANTITY"));
					product.setMember_price(rs.getDouble("MEMEBER_PRICE"));
					vc.add(product);
				}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return vc;
		}
	
	/**
	 * 录入产品的信息 
	 * @param product对象
	 * @return true or flase
	 */
	public boolean addProduct(Product product){
		int productId=getId("PRODUCTSEQ");
		String strSql;
		strSql = "insert into product() values("
			+productId+",'"
			+product.getName()+"','"
			+product.getCode()+"','"
			+product.getBarcode()+"','"
			+product.getPic_url()+"','"
			+product.getDescription()+"',"
			+product.getProduct_type()+","
			+product.getStandard_price()+","
			+product.getMember_price()+","
			+product.getStock_quantity()+","
			+")";
		if(insertRecord(strSql)){
			return true;
		}
		return false;
	}
	
	/**
	 * 编辑产品的信息 
	 */
	
	/**
	 * 编辑产品价格的信息 
	 */
}

⌨️ 快捷键说明

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