示例#1
0
        protected void ddlQty_SelectedIndexChanged(object sender, EventArgs e)
        {
            DropDownList ddl = sender as DropDownList;
            int          selectedQty;

            if (Int32.TryParse(ddl.SelectedValue, out selectedQty))
            {
                RepeaterItem item  = (RepeaterItem)ddl.NamingContainer;
                HiddenField  field = (HiddenField)item.FindControl("ProdAttrID");
                int          prodAttrId;
                if (Int32.TryParse(field.Value, out prodAttrId))
                {
                    SHOPPING_CART cart;
                    if ((cart = CartSession.Where(c => c.ID == CartID && c.ProdAttrID == prodAttrId).FirstOrDefault()) != null)
                    {
                        // we already have the right version in the session variable cartsession
                        int      oldQuantity = cart.Quantity;
                        DateTime oldDate     = cart.DateAdded;
                        cart.Quantity  = selectedQty;
                        cart.DateAdded = DateTime.Now;
                        try
                        {
                            ApplicationContext.Current.Carts.Update(cart, oldQuantity);
                        }
                        catch (Exception ex)
                        {
                            OrderNew parent = this.Page as OrderNew;
                            parent.writeResult(ex.Message, true);

                            // reverse situation because of optimistic error
                            cart.Quantity  = oldQuantity;
                            cart.DateAdded = oldDate;
                        }
                        // refresh session, optional
                        //CartSession = ApplicationContext.Current.Carts.GetShoppingCartItems(CartID);
                        DataBind(CartSession);
                        // notify parent for a partial refresh
                        NeedRefresh(sender, e);
                        ddl.Enabled = false;
                        LinkButton lnk = (LinkButton)item.FindControl("lnkEdit");
                        lnk.Enabled = false;
                    }
                }
            }
        }