Esempio n. 1
0
        private void btnEditCountDown_Click(object sender, EventArgs e)
        {
            bool          openMultStore = SettingsManager.GetMasterSettings().OpenMultStore;
            CountDownInfo countDownInfo = PromoteHelper.GetCountDownInfo(this.countDownId, 0);

            if (countDownInfo == null)
            {
                this.ShowMsg("限时购不存在", false, "CountDowns.aspx");
            }
            else
            {
                if (countDownInfo.StartDate > DateTime.Now && this.productId > 0)
                {
                    countDownInfo.ProductId = this.productId;
                }
                List <CountDownSkuInfo> list = new List <CountDownSkuInfo>();
                for (int i = 0; i < this.rptProductSkus.Items.Count; i++)
                {
                    RepeaterItem repeaterItem = this.rptProductSkus.Items[i];
                    HiddenField  hiddenField  = repeaterItem.FindControl("hfSkuId") as HiddenField;
                    TextBox      textBox      = repeaterItem.FindControl("txtActivityStock") as TextBox;
                    TextBox      textBox2     = repeaterItem.FindControl("txtActivitySalePrice") as TextBox;
                    if (textBox2.Text.Trim().ToDecimal(0) == decimal.Zero)
                    {
                        this.ShowMsg("请完整填写商品规格", false);
                        return;
                    }
                    CountDownSkuInfo item = new CountDownSkuInfo
                    {
                        SalePrice   = textBox2.Text.Trim().ToDecimal(0),
                        TotalCount  = textBox.Text.Trim().ToInt(0),
                        SkuId       = hiddenField.Value,
                        CountDownId = countDownInfo.CountDownId,
                        BoughtCount = new CountDownDao().GetCountDownOrderCount(this.countDownId, hiddenField.Value, -1)
                    };
                    list.Add(item);
                }
                if (this.rptProductSkus.Items.Count == 0)
                {
                    if (this.txtPrice.Text.Trim().ToDecimal(0) == decimal.Zero)
                    {
                        this.ShowMsg("请填写限时抢购价格", false);
                        return;
                    }
                    if (this.txtTotalCount.Text.Trim().ToInt(0) == 0)
                    {
                        this.ShowMsg("请填写活动库存", false);
                        return;
                    }
                }
                if (!this.CPStartTime.SelectedDate.HasValue)
                {
                    this.ShowMsg(Formatter.FormatErrorMessage("请填写活动开始时间"), false);
                }
                else
                {
                    if (countDownInfo.StartDate > DateTime.Now)
                    {
                        countDownInfo.StartDate = this.CPStartTime.SelectedDate.Value;
                    }
                    if (!this.CPEndDate.SelectedDate.HasValue)
                    {
                        this.ShowMsg(Formatter.FormatErrorMessage("请填写活动结束时间"), false);
                    }
                    else
                    {
                        countDownInfo.EndDate = this.CPEndDate.SelectedDate.Value;
                        if (countDownInfo.StartDate >= countDownInfo.EndDate)
                        {
                            this.ShowMsg(Formatter.FormatErrorMessage("活动结束时间要大于活动开始时间"), false);
                        }
                        else if (countDownInfo.EndDate <= DateTime.Now)
                        {
                            this.ShowMsg(Formatter.FormatErrorMessage("活动结束时间要大于当前系统时间"), false);
                        }
                        else if (PromoteHelper.ProductCountDownExist(countDownInfo.ProductId, countDownInfo.StartDate, this.countDownId, countDownInfo.EndDate))
                        {
                            this.ShowMsg("已经存在此商品的限时抢购活动", false);
                        }
                        else if (this.txtMaxCount.Text.Trim().ToInt(0) == 0)
                        {
                            this.ShowMsg("请填写每人限购数量", false);
                        }
                        else
                        {
                            countDownInfo.MaxCount = this.txtMaxCount.Text.ToInt(0);
                            int num = 0;
                            num = ((this.rptProductSkus.Items.Count == 0) ? this.txtTotalCount.Text.Trim().ToInt(0) : list.Sum((CountDownSkuInfo c) => c.TotalCount));
                            if (!openMultStore && countDownInfo.MaxCount > num && list.Count == 0)
                            {
                                this.ShowMsg(Formatter.FormatErrorMessage("每人限购数量不能大于活动库存"), false);
                            }
                            else if (!openMultStore && list.Count > 0 && countDownInfo.MaxCount > (from c in list
                                                                                                   where c.TotalCount > 0
                                                                                                   select c).Min((CountDownSkuInfo c) => c.TotalCount))
                            {
                                this.ShowMsg(Formatter.FormatErrorMessage("每人限购数量不能大于规格的最小活动库存"), false);
                            }
                            else
                            {
                                countDownInfo.Content      = Globals.HtmlEncode(this.txtContent.Text);
                                countDownInfo.ShareTitle   = Globals.HtmlEncode(this.txtShareTitle.Text);
                                countDownInfo.ShareDetails = Globals.HtmlEncode(this.txtShareDetails.Text);
                                countDownInfo.ShareIcon    = Globals.SaveFile("countDown", this.hidUploadLogo.Value, "/Storage/master/", true, false, "");
                                IList <int> list2 = null;
                                Dictionary <int, IList <int> > dictionary = default(Dictionary <int, IList <int> >);
                                ProductInfo productDetails = ProductHelper.GetProductDetails(countDownInfo.ProductId, out dictionary, out list2);
                                if (productDetails != null)
                                {
                                    if (!openMultStore && productDetails.Stock < countDownInfo.MaxCount)
                                    {
                                        this.ShowMsg("库存小于每人限购数量", false);
                                        return;
                                    }
                                    if (!openMultStore && productDetails.Stock < num)
                                    {
                                        this.ShowMsg("库存小于活动库存", false);
                                        return;
                                    }
                                    if (list.Count > 0)
                                    {
                                        foreach (KeyValuePair <string, SKUItem> sku in productDetails.Skus)
                                        {
                                            CountDownSkuInfo countDownSkuInfo = (from s in list
                                                                                 where s.SkuId == sku.Value.SkuId
                                                                                 select s).FirstOrDefault();
                                            if (countDownSkuInfo == null)
                                            {
                                                this.ShowMsg("规格不存在,请重新刷新页面", false);
                                                return;
                                            }
                                            if (!openMultStore && countDownSkuInfo.TotalCount > sku.Value.Stock)
                                            {
                                                this.ShowMsg("商品规格库存不足", false);
                                                return;
                                            }
                                        }
                                    }
                                }
                                if (list.Count == 0)
                                {
                                    DataTable skusByProductId = ProductHelper.GetSkusByProductId((this.productId > 0) ? this.productId : countDownInfo.ProductId);
                                    if (skusByProductId.Rows.Count > 0)
                                    {
                                        DataRow          dataRow = skusByProductId.Rows[0];
                                        CountDownSkuInfo item2   = new CountDownSkuInfo
                                        {
                                            SalePrice   = this.txtPrice.Text.Trim().ToDecimal(0),
                                            TotalCount  = num,
                                            SkuId       = dataRow["SkuId"].ToNullString(),
                                            CountDownId = countDownInfo.CountDownId,
                                            BoughtCount = new CountDownDao().GetCountDownOrderCount(this.countDownId, dataRow["SkuId"].ToNullString(), -1)
                                        };
                                        list.Add(item2);
                                    }
                                }
                                if (openMultStore)
                                {
                                    if (string.IsNullOrEmpty(this.hidStoreIds.Value))
                                    {
                                        this.ShowMsg("请选择门店范围", false);
                                        return;
                                    }
                                    countDownInfo.StoreType = 2;
                                    countDownInfo.StoreIds  = this.hidStoreIds.Value;
                                }
                                else
                                {
                                    countDownInfo.StoreIds  = "";
                                    countDownInfo.StoreType = 0;
                                }
                                PromoteHelper.EditCountDown(countDownInfo, list);
                                if (countDownInfo.StartDate < DateTime.Now && countDownInfo.EndDate > DateTime.Now)
                                {
                                    this.ShowMsg("编辑限时抢购活动成功", true, "countdowns.aspx");
                                }
                                else
                                {
                                    this.ShowMsg("编辑限时抢购活动成功", true, "countdowns.aspx?State=1");
                                }
                            }
                        }
                    }
                }
            }
        }