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

📄 product.java

📁 这是一个网上卖衣服的网站项目
💻 JAVA
字号:



package mylib;


public class Product {
	
	/*构造一个指定属性的产品*/
	public Product(String productId,
					String productName,
					String sexType,
					String category,
					String brand,
					String size,
					java.sql.Date sDate,
					double price,
					double costPrice,
					int stock,
					int commend,
					javax.swing.ImageIcon[] images) {
	//------------------------------
		setProductId(productId);
		setProductName(productName);
		setSexType(sexType);
		setCategory(category);
		setBrand(brand);
		setSize(size);
		setStockDate(sDate);
		setPrice(price);
		setCostPrice(costPrice);
		setStock(stock);
		setCommend(commend);
		for(int i=0;i<this.images.length;i++)
			this.images[i] = images[i];
	}
	
	
	/*构造一个产品,从数据库中一个指定名称的产品加载*/
	public Product(String productName) {
		load(productName);
	}
	
	
	
	
	
	/********************************
	 *从数据库加载指定name产品
	 ********************************/
	public void load(String productName) {
		
		ConnectionDB condb = new ConnectionDB();
		String sqlstr = "Select * from tb_Product where Product_Name=\'" + productName + "\'";
		java.sql.ResultSet rs = condb.executeQuery(sqlstr);
		try{
			if(rs.next()) {
				this.productId = (String)rs.getObject("ISDN");
				System.out.println(this.productId);
				this.productName = (String)rs.getObject("Product_Name");
				System.out.println(this.productName);

				this.sexType = (String)rs.getObject("SexType");
				System.out.println(this.sexType);
				
				this.category = (String)rs.getObject("Category");
				System.out.println(this.category);
				
				this.brand = (String)rs.getObject("Brand");
				System.out.println(this.brand);
				
				this.size = (String)rs.getObject("Product_Size");
				System.out.println(this.size);
				
				this.stockDate = rs.getDate("Stock_Date");
				System.out.println(this.stockDate);
				
				this.price = new Double(rs.getDouble("Price"));
				System.out.println(this.price);
				
				this.costPrice = new Double(rs.getDouble("CostPrice"));
				System.out.println(this.costPrice);
				
				this.stock = new Integer(rs.getInt("Stock"));
				System.out.println(this.stock);
				
				this.commend = new Integer(rs.getInt("Commend"));
				System.out.println(this.commend);
				
				for(int i=1;i<=images.length;i++) {
					byte[] bImage = rs.getBytes("Image"+i);
					if(bImage!=null)
						images[i-1] = new javax.swing.ImageIcon(bImage);
				}
				
			}
			rs.close();
			condb.close();
			condb = null;
		}
		catch(Exception ex) {
			System.out.println("***ResultSet.next()中异常***");
			System.out.println("************************************");
			ex.printStackTrace();
			System.out.println("************************************");
		}
	}
	

	
	/*****************************************************
	 *更新数据库,把当前实例更新数据库中对应isdn的产品
	 *****************************************************/
	 public void update() {
	 	int rows = 0;
	 	if(productId!=null) {
	 		ConnectionDB condb = new ConnectionDB();
	 		String sqlstr = "update tb_Product set Product_Name=?,SexType=?,Category=?,Brand=?,Product_Size=?"+
	 						",Stock_Date=getDate(),Price=?,CostPrice=?,Stock=?,Commend=?,Image1=?,Image2=? where ISDN=?";
	 		
	 		java.util.ArrayList parameters = new java.util.ArrayList();
	 		
			parameters.add(this.productName);
			parameters.add(this.sexType);
			parameters.add(this.category);
			parameters.add(this.brand);
			parameters.add(this.size);
			parameters.add(this.price);
			parameters.add(this.costPrice);
			parameters.add(this.stock);
			parameters.add(this.commend);
			
			if(this.fileImages!=null) {
				for(int i=0;i<this.fileImages.length;i++)	
					parameters.add(this.fileImages[i]);
			}
			
			parameters.add(this.productId);
			
			rows = condb.executeUpdate(sqlstr,parameters.toArray());
			
			condb.close();
			condb = null;
			
			if(rows==1)
				System.out.println("更新成功,影响行数: "+rows+"行。");
			else
				System.out.println("更新失败!影响行数"+rows+"行。");
	 	}
	 }
	
	
	/*从数据库删除该产品*/
	public int delete() {
		ConnectionDB condb = new ConnectionDB();
		String sqlstr = "Delete from tb_Product where ISDN = \'" + this.productId + "\'";
		
		int i = condb.executeUpdate(sqlstr);
		
		condb.close();
		
		return i;
	}
	
	
	/*********************************
	 *获取产品属性
	 ********************************/
	public String getProductId() {
		return this.productId;
	}
	public String getProductName() {
		return this.productName;
	}
	public String getSexType() {
		return this.sexType;
	}
	public String getCategory() {
		return this.category;
	}
	public String getBrand() {
		return this.brand;
	}
	public String getSize() {
		return this.size;
	}
	public java.sql.Date getStockDate() {
		return this.stockDate;
	}
	public double getPrice() {
		return this.price.doubleValue();
	}
	public double getCostPrice() {
		return this.costPrice.doubleValue();
	}
	public int getStock() {
		return this.stock.intValue();
	}
	public int getCommend() {
		return this.commend.intValue();
	}
	public javax.swing.ImageIcon[] getImages() {
		return this.images;
	}
	
	/********************************
	 *设置产品属性
	 ********************************/
	public void setProductId(String id) {
		this.productId = id;
	}
	public void setProductName(String name) {
		this.productName = name;
	}
	public void setSexType(String sexType) {
		this.sexType = sexType;
	}
	public void setCategory(String category) {
		this.category = category;
	}
	public void setBrand(String brand) {
		this.brand = brand;
	}
	public void setSize(String size) {
		this.size = size;
	}
	public void setStockDate(java.sql.Date sDate) {
		this.stockDate = sDate;
	}
	public void setPrice(double price) {
		this.price = new Double(price);
	}
	public void setCostPrice(double costPrice) {
		this.costPrice = new Double(costPrice);
	}
	public void setStock(int stock) {
		this.stock = new Integer(stock);
	}
	public void setCommend(int commend) {
		this.commend = new Integer(commend);
	}
	public void setImage(java.io.File[] images) {
		for(int i=0;i<images.length;i++) {
			this.fileImages[i] = images[i];
		}
	}
	
	
	
	/********************************************
	 *
	 *产品的属性
	 *
	 *********************************************/
	private String productId = null;		//产品条形码
	private String productName = null;		//产品名称
	private String sexType = null;			//产品性别类型
	private String category = null;			//产品种类
	private String brand = null;			//产品商标
	private String size = null;				//产品尺寸
	private java.sql.Date stockDate = null;		//产品出产日期
	private Double price = null;			//产品单价
	private Double costPrice = null;		//产品进货价
	private Integer stock = null;			//产品库存量
	private Integer commend = null;			//产品推荐度
	private java.io.File[] fileImages = {null,null};	//产品图抽象路径,用于把图片存进数据库	
	private javax.swing.ImageIcon[] images = {null,null}; //产品图对象,用于从数据库中读取图片


/*********************************************************
 *测试main()
 *********************************************************/
 
	public static void main(String[] args) {
		
		
		Product p = new Product("衣服AAA");
		//java.io.File[] imageFile = {new java.io.File("D:\\workspace\\aClothingShop\\image\\dialog00.JPG"),
		//							new java.io.File("D:\\workspace\\aClothingShop\\image\\login00.gif")};
		//p.setImage(imageFile);
		//p.update();
		
		javax.swing.ImageIcon[] icon = p.getImages();
		System.out.println(p.getProductId());
		
		for(int i=0;i<icon.length;i++) {
			javax.swing.JFrame f = new javax.swing.JFrame();
			javax.swing.JPanel pan = new javax.swing.JPanel();
			javax.swing.JLabel lbl = new javax.swing.JLabel();
			System.out.println(icon[i]);
			lbl.setIcon(icon[i]);
			pan.add(lbl);
			f.setContentPane(pan);
			f.setSize(200,200);
			f.setVisible(true);
		}
		//p.delete();

		
//		java.io.File[] image = {new java.io.File("D:\\workspace\\aClothingShop\\image\\dialog00.JPG"),
//								new java.io.File("D:\\workspace\\aClothingShop\\image\\login00.gif")};
//		p.setProductImage(image);
//		p.update();
	}
}

⌨️ 快捷键说明

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