ASP.NET StartKit Commerce简单,容易理解。
我认为是初次学习.NET代码的首选,不怕各位笑话,我曾经完整阅读该项目代码3次。
那么,通过阅读我们能学习到什么知识呢?请看我下面的总结:
依我见是2层结构:PL层和BLL层(没有明显的DAL层,DAL和BLL共同组成BLL层)。但是我们可以学习到Db过程的调用方法。
<asp:HyperLink cssclass="MenuSelected" id="HyperLink2" Text='<%# DataBinder.Eval(Container.DataItem, "CategoryName") %>' NavigateUrl='<%# "productslist.aspx?CategoryID=" + DataBinder.Eval(Container.DataItem, "CategoryID") + "&selection=" +
Container.ItemIndex %>' runat="server" />
(2)特别注意属性:Container.ItemIndex,它生成的是每一项的ID,它是从零开始的。功能类似MS SQL的IDENTITY(0,1).想想我以前的项目为了展现每一行的索引,往往利用在DB中创建临时表生成行索引,再绑定数据的做法真愚。
在Web.config文件中,我们可以看到如下2段代码:
<authentication mode="Forms">
<forms name="CommerceAuth" loginUrl="login.aspx" protection="All" path="/" />
<location path="OrderDetails.aspx">
说明:这样就禁止未通过登陆验证的用户访问页面:OrderDetails.aspx,自动将未登陆用户引导到页面login.aspx进行登陆验证
购物车是电子商务站的典型功能。在此项目中我们可以看到购物车的增加,删除和修改功能的典型操作。同时也学习控件的一些经典使用方法
<asp:DataGrid id=MyList runat="server" BorderColor="black" GridLines="Vertical" cellpadding="4" cellspacing="0"
DataKeyField="Quantity" AutoGenerateColumns="false">
利用DataKeyField属性绑定数据源的字段Quantity,也就是此项目中每个商品的购买数量。
类System.Web.UI.WebControls.BaseDataList的属性DataKeyField是获取或设置由 DataSource 属性指定的数据源中的键字段。
同时DataGrid和DataList都是BaseDataList的子类。
让我们再看下面代码:此代码是购物车的修改方法实现。
void UpdateShoppingCartDatabase() {
ASPNET.StarterKit.Commerce.ShoppingCartDB cart = new ASPNET.StarterKit.Commerce.ShoppingCartDB();
// Obtain current user's shopping cart ID
String cartId = cart.GetShoppingCartId();
// Iterate through all rows within shopping cart list
for (int i=0; i < MyList.Items.Count; i++) {
// Obtain references to row's controls
TextBox quantityTxt = (TextBox) MyList.Items[i].FindControl("Quantity");
CheckBox remove = (CheckBox) MyList.Items[i].FindControl("Remove");
// Wrap in try/catch block to catch errors in the event that someone types in
// an invalid value for quantity
quantity = Int32.Parse(quantityTxt.Text);
// If the quantity field is changed or delete is checked
if (quantity != (int)MyList.DataKeys[i] || remove.Checked == true) {
Label lblProductID = (Label) MyList.Items[i].FindControl("ProductID");
if (quantity == 0 || remove.Checked == true) {
cart.RemoveItem(cartId, Int32.Parse(lblProductID.Text));
cart.UpdateItem(cartId, Int32.Parse(lblProductID.Text),quantity);
MyError.Text = "There has been a problem with one or more of your inputs.";
(1)我们利用(int)MyList.DataKeys[i]取出绑定在每一行的商品购买数量值
(2)利用方法FindControl()在当前的命名容器中搜索指定的服务器控件。
利用MS SQL的JOB功能实现在特定时间时自动运行过程ShoppingCartRemoveAbandoned,以删除购物车表(CMRC_ShoppingCart)中的多余数据。
protected void Application_BeginRequest(Object sender, EventArgs e)
if (Request.UserLanguages != null)
Thread.CurrentThread.CurrentCulture =
CultureInfo.CreateSpecificCulture(Request.UserLanguages[0]);
// Default to English if there are no user languages
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-us");
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-us");
说明:全球化是为多种文化用户支持地方化用户界面和地方性数据应用程序的设计和开发过程。在.NET 构架中,CultureInfo 类体现了一个特
定文化的信息。这个信息包括书写系统、所使用的历法、日期和时间格式风格、数字和货币风格以及分类原则。地方化是为应用程序支持的每
种文化将应用程序资源转变为本地化版本的过程。当前文化在每次用户向应用程序请求页面时根据浏览器设置修改。
(2)Web.config文件中自定义节点的设置和读取
本人第一次写阅读总结,由于水平有效可能有误,希望大家多多指出。谢谢。
下次将分类总结ASP.NET StartKit TimeTracker的阅读心得。
A.Sql Server2005 Transact-SQL 新兵器学习
FlexAir开源版-全球免费多人视频聊天室,免费网络远程多人视频会议系统((Flex,Fms3联合开发))<视频聊天,会议开发实例8>
Sql Server2005 Transact-SQL 新兵器学习总结之-总结
sql server中分布式查询随笔(链接服务器(sp_addlinkedserver)和远程登录映射(sp_addlinkedsrvlogin)使用小总结)
ASP.NET2.0国际化/本地化应用程序的实现总结(多语言,多文化页面的实现)
自定义格式字符串随笔 (IFormattable,IFormatProvider,ICustomFormatter三接口的实现)
Mcad学习笔记之异步编程(AsyncCallback 委托,IAsyncResult接口,BeginInvoke方法,EndInvoke方法的使用小总结)
Mcad学习笔记之通过反射调用類的方法,屬性,字段,索引器(2種方法)
Mcad学习笔记之序列化(2进制和Soap序列 化)
Mcad学习笔记之委托再理解(delegate的构造器,BeginInvoke,EndInvoke,Invoke4个方法的探讨)
本文转自aierong博客园博客,原文链接:http://www.cnblogs.com/aierong/archive/2004/12/20/79623.html,如需转载请自行联系原作者