Пример #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var id = QueryTempOfferRuleId;

            if (string.IsNullOrEmpty(id))
            {
                var guid = Guid.NewGuid().ToString();
                Response.Redirect("/marketing/promo_cart_offer_new.aspx?tempid=" + guid);
            }

            if (OfferUtility.OfferRuleConditions[id] == null)
            {
                OfferUtility.OfferRuleConditions[id] = new OfferCondition {
                    IsAny = false, IsAll = true, Matched = true
                };
                OfferUtility.OfferActionConditions[id] = new OfferCondition {
                    IsAny = false, IsAll = true, Matched = true
                };
            }

            StringBuilder  sb = new StringBuilder();
            StringWriter   tw = new StringWriter(sb);
            HtmlTextWriter hw = new HtmlTextWriter(tw);

            OfferUtility.RenderCondition(OfferUtility.OfferRuleConditions[id], hw, OfferUtility.OfferRenderType.Cart);
            ltlConditions.Text = sb.ToString();

            StringBuilder  sb2 = new StringBuilder();
            StringWriter   tw2 = new StringWriter(sb2);
            HtmlTextWriter hw2 = new HtmlTextWriter(tw2);

            OfferUtility.RenderCondition(OfferUtility.OfferActionConditions[id], hw2, OfferUtility.OfferRenderType.Action);
            ltlActionConditions.Text = sb2.ToString();
        }
        private void LoadCartOfferInfo()
        {
            var rule = OfferService.GetOfferRuleById(QueryOfferRuleId);

            if (rule == null)
            {
                Response.Redirect("/marketing/promo_cart_offer_default.aspx?" + QueryKey.MSG_TYPE + "=" + (int)MessageType.OfferNotFound);
            }

            ltlTitle.Text = string.Format("Offer '{0}' (ID: {1})", rule.Name, rule.Id);

            txtRuleName.Text  = rule.Name;
            txtRuleAlias.Text = rule.Alias;
            if (IsFireFoxBrowser)
            {
                ftbDesc.Visible     = false;
                txtDescription.Text = rule.HtmlMessage;

                ftbLongDesc.Visible = false;
                txtLongDesc.Text    = rule.LongDescription;
            }
            else
            {
                txtDescription.Visible = false;
                ftbDesc.Text           = rule.HtmlMessage;

                txtLongDesc.Visible = false;
                ftbLongDesc.Text    = rule.LongDescription;
            }

            if (IsFireFoxBrowser)
            {
                ftbDesc.Visible     = false;
                txtDescription.Text = rule.HtmlMessage;
            }
            else
            {
                txtDescription.Visible = false;
                ftbDesc.Text           = rule.HtmlMessage;
            }
            if (rule.IsActive)
            {
                rblStatus.SelectedIndex = 0;
            }
            else
            {
                rblStatus.SelectedIndex = 1;
            }

            txtDateFrom.Text = rule.StartDate.HasValue ? rule.StartDate.Value.ToString(AppConstant.DATE_FORM1) : string.Empty;
            txtDateTo.Text   = rule.EndDate.HasValue ? rule.EndDate.Value.ToString(AppConstant.DATE_FORM1) : string.Empty;

            txtPromoCode.Text             = rule.PromoCode;
            txtTestPromoCode.Text         = rule.PromoCode;
            txtUsesPerCust.Text           = rule.UsesPerCustomer.ToString();
            cbOfferedItemIncluded.Checked = rule.OfferedItemIncluded;
            txtPriority.Text          = rule.Priority.ToString();
            chkPointSpendable.Checked = rule.PointSpendable;
            cbUseInitialPrice.Checked = rule.UseInitialPrice;
            cbNewCustomerOnly.Checked = rule.NewCustomerOnly;
            var foundOfferType = ddlOfferTypes.Items.FindByValue(rule.OfferTypeId.ToString());

            if (foundOfferType != null)
            {
                foundOfferType.Selected = true;
            }

            StringBuilder  sb = new StringBuilder();
            StringWriter   tw = new StringWriter(sb);
            HtmlTextWriter hw = new HtmlTextWriter(tw);

            OfferUtility.OfferRuleConditions[rule.Id] = rule.Condition;
            if (rule.Condition != null)
            {
                OfferUtility.RenderCondition(rule.Condition, hw, OfferUtility.OfferRenderType.Cart);
            }
            else
            {
                OfferUtility.OfferRuleConditions[rule.Id] = new OfferCondition {
                    IsAny = false, IsAll = true, Matched = true
                };
                OfferUtility.RenderCondition(OfferUtility.OfferRuleConditions[rule.Id], hw, OfferUtility.OfferRenderType.Cart);
            }

            ltlConditions.Text = sb.ToString();

            ddlAction.Items.FindByValue(rule.Action.OfferActionAttributeId.ToString()).Selected = true;

            if (rule.Action.DiscountAmount.HasValue)
            {
                txtDiscountAmount.Text = rule.Action.DiscountAmount.Value.ToString();
            }
            else
            {
                txtDiscountAmount.Text = string.Empty;
            }

            if (rule.Action.OptionOperator != null)
            {
                ddlOptionOperator.Items.FindByValue(rule.Action.OptionOperatorId.ToString()).Selected = true;
                txtOption.Text = rule.Action.OptionOperand;
            }

            if (rule.ProceedForNext)
            {
                rblProceed.SelectedIndex = 1;
            }
            else
            {
                rblProceed.SelectedIndex = 0;
            }

            if (rule.Action.FreeProductItself.HasValue || rule.Action.FreeProductId.HasValue)
            {
                if (rule.Action.FreeProductItself.HasValue && rule.Action.FreeProductItself.Value)
                {
                    rbFreeItself.Checked = true;
                }
                else
                {
                    rbFreeItem.Checked         = true;
                    txtFreeProductId.Text      = rule.Action.FreeProductId.Value.ToString();
                    txtFreeProductPriceId.Text = rule.Action.FreeProductPriceId.Value.ToString();
                    txtFreeQuantity.Text       = rule.Action.FreeProductQty.Value.ToString();
                }
            }

            txtXValue.Text = rule.Action.XValue.Value.ToString();
            txtYValue.Text = rule.Action.YValue.Value.ToString();

            if (rule.Action.DiscountQtyStep.HasValue)
            {
                txtDiscountQtyStep.Text = rule.Action.DiscountQtyStep.Value.ToString();
            }

            if (rule.Action.MinimumAmount.HasValue)
            {
                txtMinimumAmount.Text = rule.Action.MinimumAmount.Value.ToString();
            }

            txtRewardPoint.Text = rule.Action.RewardPoint.ToString();

            StringBuilder  sb2 = new StringBuilder();
            StringWriter   tw2 = new StringWriter(sb2);
            HtmlTextWriter hw2 = new HtmlTextWriter(tw2);

            OfferUtility.OfferActionConditions[rule.Id] = rule.Action.Condition;
            if (rule.Action.Condition != null)
            {
                OfferUtility.RenderCondition(rule.Action.Condition, hw2, OfferUtility.OfferRenderType.Action);
            }
            else
            {
                OfferUtility.OfferActionConditions[rule.Id] = new OfferCondition {
                    IsAny = false, IsAll = true, Matched = true
                };
                OfferUtility.RenderCondition(OfferUtility.OfferActionConditions[rule.Id], hw2, OfferUtility.OfferRenderType.Action);
            }

            ltlActionCondition.Text = sb2.ToString();

            txtUrlKey.Text           = rule.UrlRewrite;
            txtShortDescription.Text = rule.ShortDescription;
            ltlSmallImage.Text       = string.Format("<img src='/get_image_handler.aspx?" + QueryKey.TYPE + "=" + ImageHandlerType.OFFER + "&img={0}'/><br />", rule.SmallImage);
            //ftbLongDesc.Text = rule.LongDescription;
            ltlLargeImage.Text = string.Format("<img src='/get_image_handler.aspx?" + QueryKey.TYPE + "=" + ImageHandlerType.OFFER + "&img={0}'/><br />", rule.LargeImage);

            chkShowOnOfferPage.Checked      = rule.ShowInOfferPage;
            chkDisplayOnHeaderStrip.Checked = rule.DisplayOnHeaderStrip;
            txtViewOfferURL.Text            = rule.OfferUrl;
            cbShowCountDownTimer.Checked    = rule.ShowCountDown;
            cbDisplayOnProductPage.Checked  = rule.DisplayOnProductPage;
            cbDisableOfferLabel.Checked     = rule.DisableOfferLabel;
            txtOfferLabel.Text = rule.OfferLabel;

            if (rule.RelatedBrands != string.Empty)
            {
                ddlRelatedTypes.Items.FindByValue("brands").Selected = true;
                txtRelatedItems.Text = rule.RelatedBrands;
            }
            else if (rule.RelatedProducts != string.Empty)
            {
                ddlRelatedTypes.Items.FindByValue("products").Selected = true;
                txtRelatedItems.Text = rule.RelatedProducts;
            }
            else if (rule.RelatedCategory != string.Empty)
            {
                ddlRelatedTypes.Items.FindByValue("category").Selected = true;
                txtRelatedItems.Text = rule.RelatedCategory;
            }

            LoadProductsForRelatedProductSelector();
        }
        private void LoadCatalogInfo()
        {
            var rule = OfferService.GetOfferRuleById(QueryOfferRuleId);

            if (rule == null)
            {
                Response.Redirect("/marketing/promo_catalog_offer_default.aspx?" + QueryKey.MSG_TYPE + "=" + (int)MessageType.OfferNotFound);
            }

            ltlTitle.Text = string.Format("Offer '{0}' (ID: {1})", rule.Name, rule.Id);

            txtRuleName.Text  = rule.Name;
            txtRuleAlias.Text = rule.Alias;
            if (rule.IsActive)
            {
                rblStatus.SelectedIndex = 0;
            }
            else
            {
                rblStatus.SelectedIndex = 1;
            }

            txtDateFrom.Text          = rule.StartDate.HasValue ? rule.StartDate.Value.ToString(AppConstant.DATE_FORM1) : string.Empty;
            txtDateTo.Text            = rule.EndDate.HasValue ? rule.EndDate.Value.ToString(AppConstant.DATE_FORM1) : string.Empty;
            txtPriority.Text          = rule.Priority.ToString();
            chkPointSpendable.Checked = rule.PointSpendable;

            var foundOfferType = ddlOfferTypes.Items.FindByValue(rule.OfferTypeId.ToString());

            if (foundOfferType != null)
            {
                foundOfferType.Selected = true;
            }

            #region Conditions
            StringBuilder  sb = new StringBuilder();
            StringWriter   tw = new StringWriter(sb);
            HtmlTextWriter hw = new HtmlTextWriter(tw);

            OfferUtility.OfferRuleConditions[rule.Id] = rule.Condition;
            if (rule.Condition != null)
            {
                OfferUtility.RenderCondition(rule.Condition, hw, OfferUtility.OfferRenderType.Catalog);
            }
            else
            {
                OfferUtility.OfferRuleConditions[rule.Id] = new OfferCondition {
                    IsAny = false, IsAll = true, Matched = true
                };
                OfferUtility.RenderCondition(OfferUtility.OfferRuleConditions[rule.Id], hw, OfferUtility.OfferRenderType.Catalog);
            }
            ltlConditions.Text = sb.ToString();
            #endregion

            ddlAction.Items.FindByValue(rule.Action.OfferActionAttributeId.ToString()).Selected = true;

            txtDiscountAmount.Text = rule.Action.DiscountAmount.Value.ToString();

            if (rule.Action.OptionOperator != null)
            {
                ddlOptionOperator.Items.FindByValue(rule.Action.OptionOperatorId.ToString()).Selected = true;
                txtOption.Text = rule.Action.OptionOperand;
            }

            rblProceed.SelectedIndex        = rule.ProceedForNext ? 1 : 0;
            chkShowOfferTag.Checked         = rule.ShowOfferTag;
            chkShowRRP.Checked              = rule.ShowRRP;
            txtUrlKey.Text                  = rule.UrlRewrite;
            txtShortDescription.Text        = rule.ShortDescription;
            ltlSmallImage.Text              = string.Format("<img src='/get_image_handler.aspx?" + QueryKey.TYPE + "=" + ImageHandlerType.OFFER + "&img={0}'/><br />", rule.SmallImage);
            ftbLongDesc.Text                = rule.LongDescription;
            ltlLargeImage.Text              = string.Format("<img src='/get_image_handler.aspx?" + QueryKey.TYPE + "=" + ImageHandlerType.OFFER + "&img={0}'/><br />", rule.LargeImage);
            chkShowOnOfferPage.Checked      = rule.ShowInOfferPage;
            chkDisplayOnHeaderStrip.Checked = rule.DisplayOnHeaderStrip;
            txtViewOfferURL.Text            = rule.OfferUrl;
            cbShowCountDownTimer.Checked    = rule.ShowCountDown;
            cbDisplayOnProductPage.Checked  = rule.DisplayOnProductPage;
            cbDisableOfferLabel.Checked     = rule.DisableOfferLabel;
            txtOfferLabel.Text              = rule.OfferLabel;

            if (rule.RelatedBrands != string.Empty)
            {
                ddlRelatedTypes.Items.FindByValue("brands").Selected = true;
                txtRelatedItems.Text = rule.RelatedBrands;
            }
            else if (rule.RelatedProducts != string.Empty)
            {
                ddlRelatedTypes.Items.FindByValue("products").Selected = true;
                txtRelatedItems.Text = rule.RelatedProducts;
            }
            else if (rule.RelatedCategory != string.Empty)
            {
                ddlRelatedTypes.Items.FindByValue("category").Selected = true;
                txtRelatedItems.Text = rule.RelatedCategory;
            }

            LoadProductsForRelatedProductSelector();
        }