protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            offerOperator = new OfferDAL();
            categoryOperator = new CategoryDAL();

            if (!IsPostBack)
            {
                if (Request.QueryString[CommonStrings.ID] != null)
                {
                    Offer info
                        = offerOperator.SelectByID(Convert.ToInt32(Request.QueryString[CommonStrings.ID]), (bool?)IsArabic);

                    if (info != null)
                    {
                        offerOperator.View(Convert.ToInt32(Request.QueryString[CommonStrings.ID]));

                        imgOffer.ImageUrl = GetSmallImage(info.Image);
                        ltrlID.Text = hiddenOfferID.Value = Convert.ToString(info.ID);
                        ltrlViews.Text = Convert.ToString(info.Views);
                        ltrlLikes.Text = Convert.ToString(info.Likes);
                        supplierAnch.HRef = Utility.AppendQueryString(PagesPathes.ViewSupplierDetails, new KeyValue(CommonStrings.ID, Convert.ToString(info.SupplierID)));

                        if (info.Rate != 0)
                            ratingCtrl.CurrentRating = info.Rate / 20;
                        else
                            ratingCtrl.CurrentRating = 0;

                        if (HasUserRated(info.ID))
                            ratingCtrl.ReadOnly = true;
                        else
                            ratingCtrl.ReadOnly = false;

                        if (info.IsProduct)
                        {
                            newPriceSpan.Visible = true;
                            oldPriceSpan.Visible = true;

                            ltrlNewPrice.Text = info.NewPrice.ToString();
                            ltrlOldPrice.Text = info.OldPrice.ToString();

                            if (IsArabic)
                                ltrlNewCurrency.Text = ltrlOldCurrency.Text = info.CurrencyInfo.UnitAr;
                            else
                                ltrlNewCurrency.Text = ltrlOldCurrency.Text = info.CurrencyInfo.UnitEn;
                        }
                        else
                        {
                            newPriceSpan.Visible = false;
                            oldPriceSpan.Visible = false;
                        }

                        if (info.IsSale)
                        {
                            saleSpan.Visible = true;
                            ltrlSale.Text = string.Concat(Convert.ToString(info.SaleUpTo), "%");
                        }
                        else
                        {
                            saleSpan.Visible = false;
                        }

                        if (info.IsPackage)
                        {
                            packageSpan.Visible = true;

                            if (IsArabic)
                                ltrlPackage.Text = info.PackageDescriptionAr;
                            else
                                ltrlPackage.Text = info.PackageDescriptionEn;
                        }
                        else
                        {
                            packageSpan.Visible = false;
                        }

                        if (info.BrandID.HasValue)
                        {
                            brandAnch.Visible = true;
                            brandAnch.HRef = Utility.AppendQueryString(PagesPathes.ViewBrandDetails, new KeyValue(CommonStrings.ID, Convert.ToString(info.BrandID.Value)));
                        }
                        else
                        {
                            brandAnch.Visible = false;
                        }

                        if (info.StartDate.HasValue)
                        {
                            startDateSpan.Visible = true;
                            ltrlStartDate.Text = Convert.ToDateTime(info.StartDate.Value).ToShortDateString();
                        }
                        else
                        {
                            startDateSpan.Visible = false;
                        }

                        if (info.EndDate.HasValue)
                        {
                            endDateSpan.Visible = true;
                            ltrlEndDate.Text = Convert.ToDateTime(info.EndDate.Value).ToShortDateString();
                        }
                        else
                        {
                            endDateSpan.Visible = false;
                        }

                        if (info.IsBestDeal)
                        {
                            bestDealSpan.Visible = true;
                            ltrlBestDeal.Text = Resources.Literals.BestDeal;
                        }
                        else
                        {
                            bestDealSpan.Visible = false;
                        }

                        if (info.IsFeaturedOffer)
                        {
                            featuredSpan.Visible = true;
                            ltrlFeatured.Text = Resources.Literals.FeaturedOffer;
                        }
                        else
                        {
                            featuredSpan.Visible = false;
                        }

                        if (IsArabic)
                        {
                            imgOffer.AlternateText = info.TitleAr;
                            imgOffer.ToolTip = info.TitleAr;
                            ratingCtrl.RatingDirection = AjaxControlToolkit.RatingDirection.RightToLeftBottomToTop;

                            ltrlSupplier.Text = new SupplierDAL().SelectByID(info.SupplierID, IsArabic).NameAr;

                            if (info.BrandID.HasValue)
                                ltrlBrand.Text = new BrandDAL().SelectByID(info.BrandID.Value, IsArabic).NameAr;

                            ltrlTitle.Text = info.TitleAr;

                            if (string.IsNullOrEmpty(info.DescriptionAr))
                                ltrlDescription.Text = info.ShortDescriptionAr;
                            else
                                ltrlDescription.Text = info.DescriptionAr;
                        }
                        else
                        {
                            imgOffer.AlternateText = info.TitleEn;
                            imgOffer.ToolTip = info.TitleEn;
                            ratingCtrl.RatingDirection = AjaxControlToolkit.RatingDirection.LeftToRightTopToBottom;

                            ltrlSupplier.Text = new SupplierDAL().SelectByID(info.SupplierID, IsArabic).NameEn;

                            if (info.BrandID.HasValue)
                                ltrlBrand.Text = new BrandDAL().SelectByID(info.BrandID.Value, IsArabic).NameEn;

                            ltrlTitle.Text = info.TitleEn;

                            if (string.IsNullOrEmpty(info.DescriptionEn))
                                ltrlDescription.Text = info.ShortDescriptionEn;
                            else
                                ltrlDescription.Text = info.DescriptionEn;
                        }

                        List<KeyValue> categoryList = new List<KeyValue>();
                        GetCategories(info.CategoryID, categoryList);
                        AddCategories(categoryList);

                        emptyDataDiv.Visible = false;
                    }
                    else
                    {
                        emptyDataDiv.Visible = true;
                    }
                }
            }
        }
        catch
        {
            Response.Redirect(Utility.AppendQueryString(PagesPathes.ErrorPage, new KeyValue(CommonStrings.BackUrl, "ListOffers")));
        }
    }
示例#2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            offerOperator = new OfferDAL();

            if (!IsPostBack)
            {
                FillCategoryDrpMenu();
                FillSuppliersDrpMenu();
                FillBrandsDrpMenu();
                FillCurrencyDrpMenu();

                if (Request.QueryString[CommonStrings.ID] != null)
                {
                    Offer info
                        = offerOperator.SelectByID(Convert.ToInt32(Request.QueryString[CommonStrings.ID]), null);

                    if (info != null)
                    {
                        txtTitleAr.Text = info.TitleAr;
                        txtTitleEn.Text = info.TitleEn;
                        txtNameAr.Text = info.NameAr;
                        txtNameEn.Text = info.NameEn;
                        txtShortDescriptionAr.Value = info.ShortDescriptionAr;
                        txtShortDescriptionEn.Value = info.ShortDescriptionEn;
                        txtDescriptionAr.Value = info.DescriptionAr;
                        txtDescriptionEn.Value = info.DescriptionEn;

                        if (info.StartDate.HasValue)
                            txtStartDate.Text = string.Concat(Convert.ToString(info.StartDate.Value.Day), '/', Convert.ToString(info.StartDate.Value.Month), '/', Convert.ToString(info.StartDate.Value.Year));

                        if (info.EndDate.HasValue)
                            txtEndDate.Text = string.Concat(Convert.ToString(info.EndDate.Value.Day), '/', Convert.ToString(info.EndDate.Value.Month), '/', Convert.ToString(info.EndDate.Value.Year));

                        if (info.IsProduct)
                        {
                            rblType.ClearSelection();
                            rblType.Items.FindByValue("IsProduct").Selected = true;
                            txtOldPrice.Text = info.OldPrice.Value.ToString();
                            txtNewPrice.Text = info.NewPrice.Value.ToString();
                            txtDiscountPercentage.Text = info.DiscountPercentage.Value.ToString();
                            txtSaleUpTo.Text = string.Empty;
                            txtPackageDesccriptionAr.Text = string.Empty;
                            txtPackageDesccriptionEn.Text = string.Empty;
                        }
                        else if (info.IsSale)
                        {
                            rblType.ClearSelection();
                            rblType.Items.FindByValue("IsSale").Selected = true;
                            txtOldPrice.Text = string.Empty;
                            txtNewPrice.Text = string.Empty;
                            txtDiscountPercentage.Text = string.Empty;
                            txtPackageDesccriptionAr.Text = string.Empty;
                            txtPackageDesccriptionEn.Text = string.Empty;
                            txtSaleUpTo.Text = info.SaleUpTo.Value.ToString();
                        }
                        else if (info.IsPackage)
                        {
                            rblType.ClearSelection();
                            rblType.Items.FindByValue("IsPackage").Selected = true;
                            txtOldPrice.Text = string.Empty;
                            txtNewPrice.Text = string.Empty;
                            txtDiscountPercentage.Text = string.Empty;
                            txtSaleUpTo.Text = string.Empty;
                            txtPackageDesccriptionAr.Text = info.PackageDescriptionAr;
                            txtPackageDesccriptionEn.Text = info.PackageDescriptionEn;
                        }

                        txtRate.Text = info.Rate.ToString();
                        txtRateCount.Text = info.RateCount.ToString();
                        txtRateTotal.Text = info.RateTotal.ToString();
                        txtLikes.Text = info.Likes.ToString();
                        txtViews.Text = info.Views.ToString();

                        if (info.IsActive)
                        {
                            chkIsActive.Checked = true;
                            chkIsFeatured.Enabled = true;
                            chkIsBestDeal.Enabled = true;
                        }
                        else
                        {
                            chkIsActive.Checked = false;
                            chkIsFeatured.Enabled = false;
                            chkIsBestDeal.Enabled = false;
                        }

                        if (info.IsFeaturedOffer)
                        {
                            chkIsFeatured.Checked = true;
                            chkIsFeatured.Enabled = true;
                        }
                        else
                        {
                            chkIsFeatured.Checked = false;
                        }

                        if (info.IsBestDeal)
                        {
                            chkIsBestDeal.Checked = true;
                            chkIsBestDeal.Enabled = true;
                        }
                        else
                        {
                            chkIsBestDeal.Checked = false;
                        }

                        if (info.ActivationDate.HasValue)
                            txtActivationDate.Text = info.ActivationDate.Value.ToShortDateString();

                        if (info.ActivatedBy.HasValue)
                            txtActivatedBy.Text = info.ActivatedBy.Value.ToString();

                        if (info.DeactivationDate.HasValue)
                            txtDeactivationDate.Text = info.DeactivationDate.Value.ToShortDateString();

                        if (info.DeactivatedBy.HasValue)
                            txtDeactivatedBy.Text = info.DeactivatedBy.Value.ToString();

                        txtCreationDate.Text = info.CreationDate.ToShortDateString();

                        if (info.CreatedBy.HasValue)
                            txtCreatedBy.Text = info.CreatedBy.Value.ToString();

                        if (info.ModificationDate.HasValue)
                            txtModificationDate.Text = info.ModificationDate.Value.ToShortDateString();

                        if (info.ModifiedBy.HasValue)
                            txtModifiedBy.Text = info.ModifiedBy.Value.ToString();

                        if (drpCategory.Items.FindByValue(info.CategoryID.ToString()) != null)
                            drpCategory.Items.FindByValue(info.CategoryID.ToString()).Selected = true;

                        if (drpSupplier.Items.FindByValue(info.SupplierID.ToString()) != null)
                            drpSupplier.Items.FindByValue(info.SupplierID.ToString()).Selected = true;

                        if (info.BrandID.HasValue && drpBrand.Items.FindByValue(info.BrandID.Value.ToString()) != null)
                            drpBrand.Items.FindByValue(info.BrandID.Value.ToString()).Selected = true;

                        if (drpCurrency.Items.FindByValue(info.CurrencyInfo.ID.ToString()) != null)
                            drpCurrency.Items.FindByValue(info.CurrencyInfo.ID.ToString()).Selected = true;

                        imgPicture.ImageUrl = GetSmallImage(info.Image);
                        ViewState.Add("OfferImage", info.Image);
                        divPicture.Style[CommonStrings.HTMLDisplay] = CommonStrings.HTMLBlock;
                        divPathHeader.Style[CommonStrings.HTMLDisplay] = CommonStrings.HTMLNone;
                        divUploader.Style[CommonStrings.HTMLDisplay] = CommonStrings.HTMLNone;
                    }

                    hidImageFlag.Value = CommonStrings.OldImage;
                }
                else
                {
                    divPicture.Style[CommonStrings.HTMLDisplay] = CommonStrings.HTMLNone;
                    divPathHeader.Style[CommonStrings.HTMLDisplay] = CommonStrings.HTMLBlock;
                    divUploader.Style[CommonStrings.HTMLDisplay] = CommonStrings.HTMLBlock;
                }
            }
            #region Offer Type JS Script

            String csOfferType = "OfferTypeScript";
            Type csType = this.GetType();
            ClientScriptManager clientScript = Page.ClientScript;
            if (!clientScript.IsStartupScriptRegistered(csType, csOfferType))
            {
                clientScript.RegisterStartupScript(csType, csOfferType, "javascript:rblSelectedValue();", true);
            }

            #endregion
        }
        catch
        {
            Response.Redirect(Utility.AppendQueryString(PagesPathes.ErrorPage, new KeyValue(CommonStrings.BackUrl, "AdminDefault")));
        }
    }