Background
Public partial class _ Default: System. Web. UI. Page
{
CommonClass ccObj = new CommonClass ();
GoodsClass gcObj = new GoodsClass ();
Protected void Page_Load (object sender, EventArgs e)
{
If (! IsPostBack)
{
RefineBind (); three bindings
HotBind ();
DiscountBind ();
/// * Determine whether to log on */
// ST_check_Login ();
}
}
Public void ST_check_Login ()
{
If (Session ["UserName"] = null ))
{
Response. Write ("<script> alert ('Sorry! You are not a member. Please register first! '); Location = 'default. aspx' </script> ");
Response. End ();
}
}
// Bind the market price
Public string GetVarMKP (string strMarketPrice)
{
Return ccObj. VarStr (strMarketPrice, 2 );
}
// Bind the selling price
Public string GetVarHot (string strHotPrice)
{
Return ccObj. VarStr (strHotPrice, 2 );
}
Protected void RefineBind ()
{
GcObj. DLDeplayGI (1, this. dLRefine, "Refine ");
}
Protected void HotBind ()
{
GcObj. DLDeplayGI (3, this. dlHot, "Hot ");
}
Protected void DiscountBind ()
{
GcObj. DLDeplayGI (2, this. dlDiscount, "Discount ");
}
Public void AddressBack (DataListCommandEventArgs e)
{
Session ["address"] = "";
Session ["address"] = "Default. aspx ";
Response. Redirect ("~ /ShowInfo. aspx? Id = "+ Convert. ToInt32 (e. CommandArgument. ToString (); jump to and pass the id Parameter
}
Protected void dLRefine_ItemCommand (object source, DataListCommandEventArgs e)
{
If (e. CommandName = "detailSee ")
{
AddressBack (e );
}
Else if (e. CommandName = "buy ")
{
AddShopCart (e );
}
}
Protected void dlDiscount_ItemCommand (object source, DataListCommandEventArgs e)
{
If (e. CommandName = "detailSee ")
{
AddressBack (e );
}
Else if (e. CommandName = "buy ")
{
AddShopCart (e );
}
}
Protected void dlHot_ItemCommand (object source, DataListCommandEventArgs e)
{
If (e. CommandName = "detailSee ")
{
AddressBack (e );
}
Else if (e. CommandName = "buy ")
{
AddShopCart (e );
}
}
/// <Summary>
/// Add a new item to the shopping cart
/// </Summary>
/// <Param name = "e">
/// Obtain or set optional parameters,
/// CommandName associated with this parameter
/// The event is passed to the Command together.
/// </Param>
Public void AddShopCart (DataListCommandEventArgs e)
{
// If (Session ["UserName"] = null)
//{
// Response. Redirect ("Default. aspx ");
//}
/* Determine whether to log on */
ST_check_Login ();
Hashtable hashCar; use a hash table as the shopping cart.
If (Session ["ShopCart"] = null)
{
// If the user has not assigned a shopping cart
HashCar = new Hashtable (); // generate one
HashCar. Add (e. CommandArgument, 1); // Add a commodity
Session ["ShopCart"] = hashCar; // assigned to the user
}
Else
{
// The user has a shopping cart.
HashCar = (Hashtable) Session ["ShopCart"]; // obtain the hash table of the shopping cart.
If (hashCar. Contains (e. CommandArgument) // This item already exists in the shopping cart, and the number of items plus 1
{
Int count = Convert. ToInt32 (hashCar [e. CommandArgument]. ToString (); // obtain the quantity of this item
HashCar [e. CommandArgument] = (count + 1); // Add 1 to the number of items
}
Else
HashCar. Add (e. CommandArgument, 1); // if this item is not available, Add a new item
}
}
}