shopping cart

xiaoxiao2021-03-06  109

/ ** *

Title: Shopping Cart *

Description: Implement the operation of the mall shopping cart *

Copyright: CopyRight (C) 2004 *

Company: Company * @Author Network Information Department Fan Qingfeng * @version 1.0 * /

Package cartbean; import java.util. *; import java.sql. *; import sqlbean. *; public class cartbean {protected haShtable itemhashtable = new hashtable ();

Public CartBean () {} public void setItemHashtable (Hashtable HT) {itemHashtable = Ht;} public hashtable getItemHashTable () {returniTeMhashtable;}

/ ** * Add goods to cart * @Param ID int product ID * @Param Desc string Product ISBN number * @Param Price Double Product Unit * @Param Qty Int Quantity * / Public Void AddITEM (int ID, String ISBN, String Desc, Double Price, INT Qty) {String [] Item = {Integer.Tostring (ID), ISBN, DESC, DOUBLE.TOSTRING (Price), Integer.Tostring (Qty)}; if (ItemHashTable.Containskey) Tostring (ID))) {string [] WorkItem = (String []) ItemHashTable.get (Integer.tostring (ID)); int Workqty = INTEGER.PARSEINT (WorkItem [4]); Qty = Qty WorkqTy; WorkItem [ 4] = integer.tostring (qty);} else itemhashtable.put (Integer.toTString (ID), Item);

}

/ ** * Modify the number of shopping carts * @Param ID INT Product ID * @Param Desc String Products ISBN number * @Param Price Double Product Unit * @Param qty Int Quantity * / Public Void ChangeItem (int ID, int Qty) {if (ItemHashTable.Containskey (Integer.Tostring (ID))) {string [] WorkItem = (String []) ItemHashTable.Get (Integer.Tostring (ID)); WorkItem [4] = Integer.tostring (Qty }}

/ ** * Delete some of the item in the shopping cart * @Param ID INT * / Public Void RemoveItem (ITEGER.TOSTRING (ID)) {ItemHashTable.Remove (Integer.toString ID));}} public enumeration genumeration () {return itemhashtable.elements ();} / ** * Total amount of shopping cart * @return double * / public double getcost () {enumeration enum = itemhashtable.eferences (); String [] WorkItem; Double Totalcost = 0.00; while (enum.hasmoreElements ()) {workItem = (String []) Enum.nexTelement (); totalcost = totalcost (Integer.Parseint (WorkItem [4]) * double.parsedouble WorkItem [3]));} Return Totalcost;

/ ** * Shopping cart Product Class * @Return Int * / Public INT GetNumofItem () {ENUMERATION ENUM = iTemHashTable.Elements (); string [] WorkItem; int Num = 0; while (enum.hasmorelements ()) {WorkItem = (String []) enum.nextelement (); Num = Num Integer.Parseint (WorkItem [4]);} return num;}

/ ** * Empty shopping cart record * / public void clearItem () {itemhashtable.clear ();

Public void insertcart (CARTBEAN A, INT PPUSERID) {Connection Conn = New conn (); con = conn.getconn (); statement statement = con.createstatement (); enumeration b = a.GetenuMeration (); String C []; while (b.haASMoreElements ()) {c = (String []) B.NexTelement (); string value; value: value = ppuserid "," C [0] "," C [3] "," C [4]; Statement.executeUpdate ("INSERT INTO CART (Userid, ProductID, Price, Num) Values ​​(" VALUES ")");} CONN.FREECONN ();} // Try catch Exception e) {system.out.println (E.GetMessage ());} // catch}}

转载请注明原文地址:https://www.9cbs.com/read-101508.html

New Post(0)