Example #1
0
 public void btnCreateOrder_Click(object sender, System.EventArgs e)
 {
     if (this.ValidateCreateOrder())
     {
         OrderInfo orderInfo = this.GetOrderInfo(this.shoppingCart);
         if (this.shoppingCart.GetQuantity() > 1)
         {
             this.isSignBuy = false;
         }
         if (orderInfo == null)
         {
             this.ShowMessage("购物车中已经没有任何商品", false);
         }
         else
         {
             if (orderInfo.GetTotal() < 0m)
             {
                 this.ShowMessage("订单金额不能为负", false);
             }
             else
             {
                 if (!Hidistro.Membership.Context.HiContext.Current.User.IsAnonymous)
                 {
                     int totalNeedPoint = this.shoppingCart.GetTotalNeedPoint();
                     int points         = ((Hidistro.Membership.Context.Member)Hidistro.Membership.Context.HiContext.Current.User).Points;
                     if (points >= 0 && totalNeedPoint > points)
                     {
                         this.ShowMessage("您当前的积分不够兑换所需积分!", false);
                         return;
                     }
                 }
                 if (this.isCountDown)
                 {
                     CountDownInfo countDownInfo = ProductBrowser.GetCountDownInfo(this.shoppingCart.LineItems[this.productSku].ProductId);
                     if (countDownInfo.EndDate < System.DateTime.Now)
                     {
                         this.ShowMessage("此订单为抢购订单,但抢购时间已到!", false);
                         return;
                     }
                     if (this.shoppingCart.LineItems[this.productSku].Quantity > countDownInfo.MaxCount)
                     {
                         this.ShowMessage("你购买的数量超过限购数量:" + countDownInfo.MaxCount.ToString(), false);
                         return;
                     }
                     int num = ShoppingProcessor.CountDownOrderCount(this.shoppingCart.LineItems[this.productSku].ProductId);
                     if (num + this.shoppingCart.LineItems[this.productSku].Quantity > countDownInfo.MaxCount)
                     {
                         this.ShowMessage(string.Format("你已经抢购过该商品{0}件,每个用户只允许抢购{1}件,如果你有未付款的抢购单,请及时支付!", num, countDownInfo.MaxCount), false);
                         return;
                     }
                 }
                 try
                 {
                     if (ShoppingProcessor.CreatOrder(orderInfo))
                     {
                         Messenger.OrderCreated(orderInfo, Hidistro.Membership.Context.HiContext.Current.User);
                         orderInfo.OnCreated();
                         if (this.shoppingCart.GetTotalNeedPoint() > 0)
                         {
                             ShoppingProcessor.CutNeedPoint(this.shoppingCart.GetTotalNeedPoint(), orderInfo.OrderId);
                         }
                         if (!this.isCountDown && !this.isGroupBuy && !this.isSignBuy && !this.isBundling)
                         {
                             ShoppingCartProcessor.ClearShoppingCart();
                         }
                         if (!Hidistro.Membership.Context.HiContext.Current.User.IsAnonymous && PersonalHelper.GetShippingAddressCount(Hidistro.Membership.Context.HiContext.Current.User.UserId) == 0)
                         {
                             PersonalHelper.CreateShippingAddress(new ShippingAddressInfo
                             {
                                 UserId    = Hidistro.Membership.Context.HiContext.Current.User.UserId,
                                 ShipTo    = Globals.HtmlEncode(this.txtShipTo.Text),
                                 RegionId  = this.dropRegions.GetSelectedRegionId().Value,
                                 Address   = Globals.HtmlEncode(this.txtAddress.Text),
                                 Zipcode   = this.txtZipcode.Text,
                                 CellPhone = this.txtCellPhone.Text,
                                 TelPhone  = this.txtTelPhone.Text
                             });
                         }
                         this.Page.Response.Redirect(Globals.GetSiteUrls().UrlData.FormatUrl("FinishOrder", new object[]
                         {
                             orderInfo.OrderId
                         }));
                     }
                 }
                 catch (System.Exception ex)
                 {
                     this.ShowMessage(ex.ToString(), false);
                 }
             }
         }
     }
 }