//±£´æµ½ASPNETDB.mdf Profile.Save();
Response.Redirect(\, true); }
°´Å¥btnComputeAgain±»µ¥»÷ʱִÐеÄʼþ´úÂëÈçÏ£º
protected void btnComputeAgain_Click(object sender, EventArgs e) {
lblError.Text = \;
MyPetShopDataContext db = new MyPetShopDataContext();
//Ñ»·ÀûÓÃFindControl()ÕÒµ½TextBox¿Ø¼þtxtQty£¬È»ºóÅжÏÊÇ·ñΪ¿ÕÖµ£¬Èô·Ç¿Õ£¬ÔòÔÚProduct±íÖвéÕÒtxtQtyËùÔÚÐÐÉÌÆ·±àºÅÈ·¶¨µÄÉÌÆ·£¬´Ó¶ø±È½ÏtxtQtyÖеÄÊäÈëÖµºÍÉÌÆ·µÄ¿â´æÁ¿ for (int {
TextBox txtQty = new TextBox();
txtQty = (TextBox)gvCart.Rows[i].FindControl(\); if (txtQty != null) {
var product = (from p in db.Product where p.ProductId == int.Parse(gvCart.Rows[i].Cells[1].Text)
select p).First();
if (int.Parse(txtQty.Text) > product.Qty) //¿â´æ²»×ã {
lblError.Text += \£º¿â´æ²»×㣬ÉÌÆ·ÃûΪ \ + gvCart.Rows[i].Cells[2].Text + \µÄ¿â´æÊýÁ¿Îª \; } else {
ChangeQty(int.Parse(gvCart.Rows[i].Cells[1].Text), int.Parse(txtQty.Text)); //µ÷ÓÃ×Ô¶¨Òå·½·¨ChangeQty()¸Ä±ä´æ´¢ÔÚProfileÖеĹºÂòÊýÁ¿
} } }
Bind(); //µ÷ÓÃ×Ô¶¨Òå·½·¨Bind()ÏÔʾ¹ºÎï³µÖÐÉÌÆ·
}
×Ô¶¨Òå·½·¨ChangeQty£¨£©µÄ´úÂëÈçÏ£º ///
/// ¸ù¾ÝÖ¸¶¨µÄÉÌÆ·±àºÅ£¬ÐÞ¸ÄProfileÖжÔÓ¦ÉÌÆ·µÄ¿â´æÁ¿ ///
///
/// protected void ChangeQty(int id, int qty)
{
for (int {
if (id == (int {
Profile.Save(); } }
}
°´Å¥btnSettle±»µ¥»÷ʱִÐеÄʼþ´úÂëÈçÏ£º
protected void btnSettle_Click(object sender, EventArgs e) {
Response.Redirect(\, true);
}
°´Å¥btnContinue±»µ¥»÷ʱִÐеÄʼþ´úÂëÈçÏ£º
protected void btnContinue_Click(object sender, EventArgs e) {
Response.Redirect(\);
}
£¨7£©Éè¼ÆSubmitCart.aspx
Èçͼ6-16Ëùʾ£¬ÏòSubmitCart.aspxÒ³ÃæÌí¼Ó1¸öÓÃÓÚ²¼¾ÖµÄ5ÐÐ2Áбí¸ñ£¬ºÏ²¢ÏàÓ¦µÄµ¥Ôª¸ñ£¬ÊäÈë¡°Ìîд·¢»õµØÖ·£º¡±¡¢¡°ËÍ»õµØÖ·£º¡±¡¢¡°Óʱࣺ¡±¡¢¡°ÁªÏµµç»°£º¡±µÈÐÅÏ¢£¬Ìí¼Ó3¸öTextBox¿Ø¼þ¡¢2¸öButton¿Ø¼þºÍ1¸öLabel¿Ø¼þ¡£Êʵ±µ÷Õû¸÷¿Ø¼þµÄ´óСºÍλÖ᣷ֱðÉèÖø÷¿Ø¼þµÄÊôÐÔIDֵΪ£ºtxtGoodsAddress¡¢txtzip¡¢txtPhone¡¢btnContinueºÍbtnSubmit¡£
ͼ6-16 Éè¼Æ½çÃ棨5£©
£¨8£©±àдSubmitCart.aspxʼþ´úÂë
°´Å¥btnContinue±»µ¥»÷ʱִÐеÄʼþ´úÂëÈçÏ£º
protected void btnContinue_Click(object sender, EventArgs e) {
Response.Redirect(\);
}
°´Å¥btnSubmit±»µ¥»÷ʱִÐеÄʼþ´úÂëÈçÏ£º
protected void btnSubmit_Click(object sender, EventArgs e) {
MyPetShopDataContext db = new MyPetShopDataContext(); //ÔÚOrder±íÖÐÌí¼Ó¼Ç¼ Order order = new Order();
//Ä¿Ç°¼ÙÉ趩µ¥µÄÓû§Ãû¶¼Îª¡°ÕÅÈý¡±£¬Êµ¼ÊÇé¿öÓ¦±£´æµÇ¼µÄÓû§Ãû¡£ÈôʹÓÃASP.NET 3.5µÇ¼ϵÁпؼþʵÏÖÓû§¹ÜÀí£¬¿Éͨ¹ý·µ»ØµÇ¼µÄÓû§Ãû order.UserName = \ÕÅÈý\; order.OrderDate = DateTime.Now; order.Status = \δÉóºË\;
//²åÈëʵÌåorder£¬Ìá½»¸ü¸Äºó¼´ÔÚOrder±íÖвåÈëÒ»Ìõ¼Ç¼
db.SubmitChanges(); //ÔÚOrderItemÖÐÌí¼Ó¼Ç¼ int id = order.OrderId; for (int {
OrderItem orderItem = new OrderItem(); orderItem.OrderId = id; orderItem.ProName = (string orderItem.ListPrice = (decimal orderItem.Qty = (int
orderItem.TotalPrice = (intdecimal db.SubmitChanges(); //ÐÞ¸ÄProduct±íµÄÉÌÆ·¿â´æ
var product = (from c in db.Product where c.ProductId == (int select c).First(); product.Qty -= orderItem.Qty; db.SubmitChanges(); }
//Çå¿Õ¸÷Êý×éÁбí¶ÔÏó \;
lblMsg.Text = \ÒѾ³É¹¦½áË㣬лл¹âÁÙ£¡\; }
£¨9£©´Óä¯ÀÀProductShow.aspx¿ªÊ¼¶ÔMyPetShopÍøÕ¾½øÐвâÊÔ¡£ 2.ÀûÓÃDetailsView¿Ø¼þʵÏÖÊý¾Ý²åÈë¡¢±à¼¡¢É¾³ýµÈ²Ù×÷
£¨1£©Éè¼ÆWeb´°Ìå
н¨Ò»¸öWeb´°Ì壬Çл»µ½¡°Éè¼Æ¡±ÊÓͼ¡£Èçͼ6-17Ëùʾ£¬ÏòÒ³ÃæÌí¼Ó1¸öDetailsView¿Ø¼þºÍ3¸öLinqDataSource¿Ø¼þ¡£
ͼ6-17 Éè¼Æ½çÃ棨6£©
£¨2£©ÉèÖÃÊôÐÔ
¢Ù·Ö±ðÉèÖø÷¿Ø¼þµÄÊôÐÔIDֵΪ£ºdvProduct¡¢ldsProduct¡¢ldsCategoryºÍldsSupplier¡£ ¢ÚldsProductµÄÊý¾ÝÑ¡ÔñÅäÖÃÈçͼ6-18Ëùʾ£¬ÅäÖÃÍê³Éºó£¬ÔÙµ¥»÷ldsProductµÄÖÇÄܱê¼Ç£¬Ñ¡ÖС°ÆôÓÃɾ³ý¡±¡¢¡°ÆôÓòåÈ롱ºÍ¡°ÆôÓøüС±¡£
ͼ6-18 ¡°ÅäÖÃÊý¾ÝÑ¡Ôñ¡±½çÃæ
¢ÛÅäÖÃldsCategoryµÄÊý¾ÝԴΪCategory±í£¬Êý¾ÝÑ¡ÔñCategoryIdºÍName¡£ ¢ÜÅäÖÃldsSupplierµÄÊý¾ÝԴΪSupplier±í£¬Êý¾ÝÑ¡ÔñSuppIdºÍName¡£
¢Ýµ¥»÷dvProductµÄÖÇÄܱê¼Ç£¬Ñ¡ÔñÊý¾ÝÔ´ldsProduct£»Ñ¡ÖС°ÆôÓ÷ÖÒ³¡±¡¢¡°ÆôÓòåÈ롱¡¢¡°ÆôÓñ༡±ºÍ¡°ÆôÓÃɾ³ý¡±£»µ¥»÷¡°±à¼×ֶΡ±£¬½«CategoryIdÁкÍSuppIdÁзֱðת»»ÎªTemplateField¡£
¢ÞTemplateField×Ö¶ÎCategoryIdµÄ±à¼½çÃæÈçͼ6-19Ëùʾ£¬ÏòEditItemTemplateºÍInsectItemTemplate·Ö±ðÌí¼Ó1¸öDropDownList¿Ø¼þ£¬²¢°ó¶¨µ½Êý¾ÝÔ´ldsCategory¡£ÀàËƵØÉèÖÃTemplateField×Ö¶ÎSuppId¡£
ͼ6-19 Éè¼Æ½çÃ棨7£©
¢ßä¯ÀÀ½¨Á¢µÄWeb´°Ìå½øÐвâÊÔ¡£
ʵÑéÆß Ö÷Ì⡢ĸ°æºÍÓû§¿Ø¼þ
Ò»£®ÊµÑéÄ¿µÄ
(1) ÕÆÎÕ½¨Á¢ºÍʹÓÃÓû§¿Ø¼þµÄ·½·¨¡£
(2) ÕÆÎÕÀûÓÃĸ°æÒ³ºÍÄÚÈÝÒ³½¨Á¢ÍøÒ³µÄ·½·¨¡£ (3) ÕÆÎÕÖ÷ÌâµÄ½¨Á¢ºÍʹÓ÷½·¨¡£
¶þ.ʵÑéÄÚÈݼ°ÒªÇó
1. Éè¼ÆÓÃÓÚÏÔʾÉÌÆ·Àà±ðºÍÊýÁ¿µÄÓû§¿Ø¼þ ÒªÇóÈçÏ£º
(1) ¿Ø¼þä¯ÀÀЧ¹ûÈçͼ7-1Ëùʾ¡£
ͼ7-1 ¿Ø¼þ²âÊÔÒ³ä¯ÀÀЧ¹û
(2) µ¥»÷·ÖÀàÃû³ÆÔòÌøתµ½ProductShow.aspxÒ³£¬ÏÔʾ¸ÃÀàÉÌÆ·µÄÁÐ±í¡£ (3) ²âÊÔ¸ÃÓû§¿Ø¼þ¡£
2. ÀûÓÃĸ°æÒ³ÖØÐÂÉè¼ÆMyPetShop¸÷Ò³Ãæ ÒªÇóÈçÏ£º
(1) ÔÚ¸ø³öµÄÀý×ÓÉϽøÐÐÐ޸ġ£
(2) ĸ°æÒ³Éè¼ÆЧ¹ûÈçͼ7-2Ëùʾ¡£×ó±ß°üº¬¡°ÊµÑéÄÚÈÝ1¡±½¨Á¢µÄÓû§¿Ø¼þ£¬ÓÒ±ßΪ
ContentPlaceHolder¿Ø¼þContentPlaceHolderRinght¡£
(3)
ͼ7-2 ĸ°æÒ³Éè¼ÆЧ¹û
(4) ÀûÓÃĸ°æÒ³ÖØн¨Á¢ÉÌÆ·²é¿´Ò³ProductShow.aspx£¬ä¯ÀÀЧ¹ûÈçͼ7-3Ëùʾ£¬×ó±ßÊÇÉÌ
Æ·ÁÐ±í£¬µ¥»÷·ÖÀàÃû³ÆÔòÔÚÓұ߷ÖÒ³ÏÔʾ¶ÔÓ¦Àà±ðµÄÉÌÆ·ÐÅÏ¢¡£
ͼ7-3 ¡°ÉÌÆ·²é¿´Ò³¡±ä¯ÀÀЧ¹û
Èý.ʵÑé²½Öè
1. Éè¼ÆÓÃÓÚÏÔʾÉÌÆ·Àà±ðºÍÊýÁ¿µÄÓû§¿Ø¼þ
£¨1£©´ò¿ªÍøÕ¾MyPetShop£¬Ìí¼ÓWebÓû§¿Ø¼þCategory.ascx¡£
£¨2£©Category.ascxµÄ¡°Éè¼Æ¡±ÊÓͼÖÐÌí¼ÓÒ»¸öGridWiew¿Ø¼þ£¬ÉèÖÃÊôÐÔIDÖµgvProduct¡£¿Ø¼þgvProductµÄÊôÐÔColumnsÖµÉèÖÃÈçͼ7-10Ëùʾ£¬²¿Ìí1¸öHyperLinkField×ֶκÍÒ»¸öBoundField×ֶΡ£ÔÚͼ7-10ÖУ¬Ñ¡ÔñHyperLinkField×Ö¶ÎÉèÖÃÆäÊôÐÔ£¬ÊôÐÔÉèÖÃÈç±í7-1Ëùʾ¡£Ñ¡ÔñBoundField×Ö¶Î×Ö¶ÎÉèÖÃÆäÊôÐÔ£¬ÊôÐÔÉèÖÃÈç±í7-2Ëùʾ¡£