基于.NET的网上商城系统的分析与设计 第7页
在Web Service的web.config页面进行数据库连接配制:
<connectionStrings>
<add name="DBConnection" connectionString="database=B2CShopDB;server=(local);uid=sa;pwd=sa" providerName="System.Data.SqlClient"/>
</connectionStrings>
Name表示该数据库连接的名字;Database表求要连接的SQL数据库的名字;Server=(local)表求数据库为本地计算机连接;uid是连接数据库使用的用户名,pwd表示连接数据库登录的密码。
商品的类:
public class Products
{
public Products()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
int product_id;
string product_description;
decimal product_price;
int product_num;
DateTime product_pubdate;
public int ProductID
{
get { return product_id; }
set { product_id = value; }
}
public string ProductDescription
{
get { return product_description; }
set { product_description = value; }
}
public decimal ProductPrice
{
get { return product_price; }
set { product_price = value; }
}
public int ProductNum
{
get { return product_num; }
set { product_num = value; }
}
public DateTime ProductPubdate
{
get { return product_pubdate; }
set { product_pubdate = value; }
}
public Products(int productid, string productdescription, decimal productprice, int productnum,DateTime productpubdate)
{
product_id=productid;
product_description=productdescription;
product_price=productprice;
product_num=productnum;
product_pubdate =productpubdate ;
}
}
购物车的类:
public class ShoppingCarts
{
public ShoppingCarts()
{
}
Hashtable productOders = new Hashtable();
public ICollection Product
{
get { return productOders.Values; }
}
public void AddProductOrder(Products order)
{
Products product = (Products)productOders[order.ProductID];
if (product != null)
{
product.ProductNum += 1;
}
else
{
productOders.Add(order.ProductID, order);
}
}
public void RemoveProductOrder(int id)
{
if (productOders[id] != null)
{
productOders.Remove(id);
}
}
public decimal TotalPrice
{
get
{
decimal totalPrice = 0;
foreach (DictionaryEntry entry in productOders)
{
Products product = (Products)entry.Value;
totalPrice = totalPrice + product.ProductPrice * product.ProductNum;
}
return totalPrice;
}
}
public void UpdateProductOrder(int id, Products order)
{
if (productOders[id] != null)
{
productOders[id] = order;
}
}
}
网站首页实现代码(B2Cmain.aspx.cs):
using System.Data.SqlClient;
public partial class B2Cmain : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
GetSourceListData();
上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] ... 下一页 >>