. Net public class design 4

Source: Internet
Author: User

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
}

}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.