Example #1
0
        private void SaveWrapStyle()
        {
            WrapStyle style = WrapStyleDataSource.Load(WrapStyleId);

            style.Name         = Name.Text;
            style.ThumbnailUrl = ThumbnailUrl.Text;
            style.ImageUrl     = ImageUrl.Text;
            style.Price        = AlwaysConvert.ToDecimal(Price.Text);
            style.TaxCodeId    = AlwaysConvert.ToInt(TaxCode.SelectedValue);
            style.Save();
        }
        protected void WrapStylesGrid_RowEditing(object sender, GridViewEditEventArgs e)
        {
            int       wrapStyleId = (int)WrapStylesGrid.DataKeys[e.NewEditIndex].Value;
            WrapStyle style       = WrapStyleDataSource.Load(wrapStyleId);

            if (style != null)
            {
                AddPanel.Visible  = false;
                EditPanel.Visible = true;
                EditCaption.Text  = string.Format(EditCaption.Text, style.Name);
                EditWrapStyleDialog editDialog = EditPanel.FindControl("EditWrapStyleDialog1") as EditWrapStyleDialog;
                if (editDialog != null)
                {
                    editDialog.WrapStyleId = wrapStyleId;
                }
            }
        }
Example #3
0
        protected void Page_PreRender(object sender, EventArgs e)
        {
            WrapStyle style = WrapStyleDataSource.Load(WrapStyleId);

            if (style != null)
            {
                Name.Text             = style.Name;
                ThumbnailUrl.Text     = style.ThumbnailUrl;
                ImageUrl.Text         = style.ImageUrl;
                Price.Text            = string.Format("{0:F2}", style.Price);
                TaxCode.SelectedIndex = -1;
                ListItem item = TaxCode.Items.FindByValue(style.TaxCodeId.ToString());
                if (item != null)
                {
                    item.Selected = true;
                }
            }
        }
Example #4
0
        private void DoneEditing()
        {
            UpdatePanel stylesAjax = AbleCommerce.Code.PageHelper.RecursiveFindControl(this.Page, "WrapStylesAjax") as UpdatePanel;

            if (stylesAjax != null)
            {
                GridView stylesGrid = AbleCommerce.Code.PageHelper.RecursiveFindControl(stylesAjax, "WrapStylesGrid") as GridView;
                if (stylesGrid != null)
                {
                    stylesGrid.EditIndex = -1;
                    stylesGrid.DataBind();
                }
                Panel addPanel = AbleCommerce.Code.PageHelper.RecursiveFindControl(stylesAjax, "AddPanel") as Panel;
                if (addPanel != null)
                {
                    addPanel.Visible = true;
                }
                Panel editPanel = AbleCommerce.Code.PageHelper.RecursiveFindControl(stylesAjax, "EditPanel") as Panel;
                if (editPanel != null)
                {
                    editPanel.Visible = false;
                }
                Notification savedMessage = AbleCommerce.Code.PageHelper.RecursiveFindControl(stylesAjax, "SavedWrapStyleMessage") as Notification;
                if (savedMessage != null)
                {
                    savedMessage.Visible = false;
                    string    name  = string.Empty;
                    WrapStyle style = WrapStyleDataSource.Load(WrapStyleId);
                    if (style != null)
                    {
                        name = style.Name;
                    }
                    savedMessage.Text = string.Format(savedMessage.Text, name);
                }
            }
        }
 protected int CountWrapStyles(object dataItem)
 {
     return(WrapStyleDataSource.CountForWrapGroup(((WrapGroup)dataItem).Id));
 }
        /// <summary>
        /// Prepare list of used images
        /// Many be associated with products, as thumbnail, icon, or std. images
        /// or as additional images
        /// or to option swathces
        /// </summary>
        private void InitAssociatedImageUrls()
        {
            associatedImages = new List <string>();

            // ADD PRODUCT IMAGES
            ICriteria criteria = NHibernateHelper.CreateCriteria <Product>();

            criteria.Add(Restrictions.Eq("Store", AbleContext.Current.Store));
            criteria.Add(Restrictions.Disjunction()
                         .Add(Restrictions.Like("ImageUrl", "~/Assets/ProductImages/%"))
                         .Add(Restrictions.Like("ThumbnailUrl", "~/Assets/ProductImages/%"))
                         .Add(Restrictions.Like("IconUrl", "~/Assets/ProductImages/%")));

            IList <Product> products = ProductDataSource.LoadForCriteria(criteria);

            foreach (Product product in products)
            {
                if (product.ImageUrl.StartsWith("~/Assets/ProductImages/"))
                {
                    associatedImages.Add(product.ImageUrl);
                }
                if (product.ThumbnailUrl.StartsWith("~/Assets/ProductImages/"))
                {
                    associatedImages.Add(product.ThumbnailUrl);
                }
                if (product.IconUrl.StartsWith("~/Assets/ProductImages/"))
                {
                    associatedImages.Add(product.IconUrl);
                }
            }

            // ADDITIONAL IMAGES
            ICriteria imageCriteria = NHibernateHelper.CreateCriteria <ProductImage>();

            imageCriteria.Add(Restrictions.Like("ImageUrl", "~/Assets/ProductImages/%"));
            IList <ProductImage> images = ProductImageDataSource.LoadForCriteria(imageCriteria);

            foreach (ProductImage image in images)
            {
                associatedImages.Add(image.ImageUrl);
            }

            // OPTION SWATCHES
            ICriteria choicesCriteria = NHibernateHelper.CreateCriteria <OptionChoice>();

            choicesCriteria.Add(Restrictions.Disjunction()
                                .Add(Restrictions.Like("ImageUrl", "~/Assets/ProductImages/%"))
                                .Add(Restrictions.Like("ThumbnailUrl", "~/Assets/ProductImages/%")));

            IList <OptionChoice> choices = OptionChoiceDataSource.LoadForCriteria(choicesCriteria);

            foreach (OptionChoice choice in choices)
            {
                if (choice.ImageUrl.StartsWith("~/Assets/ProductImages/"))
                {
                    associatedImages.Add(choice.ImageUrl);
                }
                if (choice.ThumbnailUrl.StartsWith("~/Assets/ProductImages/"))
                {
                    associatedImages.Add(choice.ThumbnailUrl);
                }
            }

            // ADD CATEGORY IMAGES
            ICriteria categoryCriteria = NHibernateHelper.CreateCriteria <Category>();

            categoryCriteria.Add(Restrictions.Eq("Store", AbleContext.Current.Store));
            categoryCriteria.Add(Restrictions.Like("ThumbnailUrl", "~/Assets/ProductImages/%"));
            IList <Category> categories = CategoryDataSource.LoadForCriteria(categoryCriteria);

            foreach (Category category in categories)
            {
                if (category.ThumbnailUrl.StartsWith("~/Assets/ProductImages/"))
                {
                    associatedImages.Add(category.ThumbnailUrl);
                }
            }

            // ADD LINK IMAGES
            ICriteria linksCriteria = NHibernateHelper.CreateCriteria <Link>();

            linksCriteria.Add(Restrictions.Eq("Store", AbleContext.Current.Store));
            linksCriteria.Add(Restrictions.Like("ThumbnailUrl", "~/Assets/ProductImages/%"));
            IList <Link> links = LinkDataSource.LoadForCriteria(linksCriteria);

            foreach (Link link in links)
            {
                if (link.ThumbnailUrl.StartsWith("~/Assets/ProductImages/"))
                {
                    associatedImages.Add(link.ThumbnailUrl);
                }
            }

            // ADD GIFT WRAPING IMAGES
            ICriteria wrapstylesCriteria = NHibernateHelper.CreateCriteria <WrapStyle>();

            wrapstylesCriteria.Add(Restrictions.Like("ImageUrl", "~/Assets/ProductImages/%"));

            IList <WrapStyle> wrapStyles = WrapStyleDataSource.LoadForCriteria(wrapstylesCriteria);

            foreach (WrapStyle ws in wrapStyles)
            {
                if (ws.ImageUrl.StartsWith("~/Assets/ProductImages/"))
                {
                    associatedImages.Add(ws.ImageUrl);
                }
                if (ws.ThumbnailUrl.StartsWith("~/Assets/ProductImages/"))
                {
                    associatedImages.Add(ws.ThumbnailUrl);
                }
            }

            // ADD VARIANT IMAGES
            ICriteria variantsCriteria = NHibernateHelper.CreateCriteria <ProductVariant>();

            criteria.Add(Restrictions.Disjunction()
                         .Add(Restrictions.Like("ImageUrl", "~/Assets/ProductImages/%"))
                         .Add(Restrictions.Like("ThumbnailUrl", "~/Assets/ProductImages/%"))
                         .Add(Restrictions.Like("IconUrl", "~/Assets/ProductImages/%")));

            int variantsCount      = ProductVariantDataSource.CountForCriteria(variantsCriteria.Clone() as ICriteria);
            int maxVariantsToCache = 500;

            // avoid loading all variants at same time
            for (int index = 0; index < variantsCount; index += maxVariantsToCache)
            {
                variantsCriteria.SetMaxResults(maxVariantsToCache);
                variantsCriteria.SetFirstResult(index);
                IList <ProductVariant> productVariants = ProductVariantDataSource.LoadForCriteria(variantsCriteria);
                foreach (ProductVariant productVariant in productVariants)
                {
                    if (productVariant.ImageUrl.StartsWith("~/Assets/ProductImages/"))
                    {
                        associatedImages.Add(productVariant.ImageUrl);
                    }
                    if (productVariant.ThumbnailUrl.StartsWith("~/Assets/ProductImages/"))
                    {
                        associatedImages.Add(productVariant.ThumbnailUrl);
                    }
                    if (productVariant.IconUrl.StartsWith("~/Assets/ProductImages/"))
                    {
                        associatedImages.Add(productVariant.IconUrl);
                    }
                }
            }
        }
Example #7
0
        /// <summary>
        /// Saves this WrapStyle object to the database.
        /// </summary>
        /// <returns><b>SaveResult</b> enumeration that represents the result of the save operation.</returns>
        public virtual SaveResult Save()
        {
            if (this.IsDirty)
            {
                Database database     = Token.Instance.Database;
                bool     recordExists = true;

                if (this.WrapStyleId == 0)
                {
                    recordExists = false;
                }

                if (this.OrderBy < 0)
                {
                    this.OrderBy = WrapStyleDataSource.GetNextOrderBy(this.WrapGroupId);
                }

                if (recordExists)
                {
                    //verify whether record is already present
                    StringBuilder selectQuery = new StringBuilder();
                    selectQuery.Append("SELECT COUNT(*) As RecordCount FROM ac_WrapStyles");
                    selectQuery.Append(" WHERE WrapStyleId = @WrapStyleId");
                    using (DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString()))
                    {
                        database.AddInParameter(selectCommand, "@WrapStyleId", System.Data.DbType.Int32, this.WrapStyleId);
                        if ((int)database.ExecuteScalar(selectCommand) == 0)
                        {
                            recordExists = false;
                        }
                    }
                }

                int result = 0;
                if (recordExists)
                {
                    //UPDATE
                    StringBuilder updateQuery = new StringBuilder();
                    updateQuery.Append("UPDATE ac_WrapStyles SET ");
                    updateQuery.Append("WrapGroupId = @WrapGroupId");
                    updateQuery.Append(", Name = @Name");
                    updateQuery.Append(", TaxCodeId = @TaxCodeId");
                    updateQuery.Append(", Price = @Price");
                    updateQuery.Append(", ThumbnailUrl = @ThumbnailUrl");
                    updateQuery.Append(", ImageUrl = @ImageUrl");
                    updateQuery.Append(", OrderBy = @OrderBy");
                    updateQuery.Append(" WHERE WrapStyleId = @WrapStyleId");
                    using (DbCommand updateCommand = database.GetSqlStringCommand(updateQuery.ToString()))
                    {
                        database.AddInParameter(updateCommand, "@WrapStyleId", System.Data.DbType.Int32, this.WrapStyleId);
                        database.AddInParameter(updateCommand, "@WrapGroupId", System.Data.DbType.Int32, this.WrapGroupId);
                        database.AddInParameter(updateCommand, "@Name", System.Data.DbType.String, this.Name);
                        database.AddInParameter(updateCommand, "@TaxCodeId", System.Data.DbType.Int32, NullableData.DbNullify(this.TaxCodeId));
                        database.AddInParameter(updateCommand, "@Price", System.Data.DbType.Decimal, this.Price);
                        database.AddInParameter(updateCommand, "@ThumbnailUrl", System.Data.DbType.String, NullableData.DbNullify(this.ThumbnailUrl));
                        database.AddInParameter(updateCommand, "@ImageUrl", System.Data.DbType.String, NullableData.DbNullify(this.ImageUrl));
                        database.AddInParameter(updateCommand, "@OrderBy", System.Data.DbType.Int16, this.OrderBy);
                        //RESULT IS NUMBER OF RECORDS AFFECTED
                        result = database.ExecuteNonQuery(updateCommand);
                    }
                }
                else
                {
                    //INSERT
                    StringBuilder insertQuery = new StringBuilder();
                    insertQuery.Append("INSERT INTO ac_WrapStyles (WrapGroupId, Name, TaxCodeId, Price, ThumbnailUrl, ImageUrl, OrderBy)");
                    insertQuery.Append(" VALUES (@WrapGroupId, @Name, @TaxCodeId, @Price, @ThumbnailUrl, @ImageUrl, @OrderBy)");
                    insertQuery.Append("; SELECT Scope_Identity()");
                    using (DbCommand insertCommand = database.GetSqlStringCommand(insertQuery.ToString()))
                    {
                        database.AddInParameter(insertCommand, "@WrapStyleId", System.Data.DbType.Int32, this.WrapStyleId);
                        database.AddInParameter(insertCommand, "@WrapGroupId", System.Data.DbType.Int32, this.WrapGroupId);
                        database.AddInParameter(insertCommand, "@Name", System.Data.DbType.String, this.Name);
                        database.AddInParameter(insertCommand, "@TaxCodeId", System.Data.DbType.Int32, NullableData.DbNullify(this.TaxCodeId));
                        database.AddInParameter(insertCommand, "@Price", System.Data.DbType.Decimal, this.Price);
                        database.AddInParameter(insertCommand, "@ThumbnailUrl", System.Data.DbType.String, NullableData.DbNullify(this.ThumbnailUrl));
                        database.AddInParameter(insertCommand, "@ImageUrl", System.Data.DbType.String, NullableData.DbNullify(this.ImageUrl));
                        database.AddInParameter(insertCommand, "@OrderBy", System.Data.DbType.Int16, this.OrderBy);
                        //RESULT IS NEW IDENTITY;
                        result            = AlwaysConvert.ToInt(database.ExecuteScalar(insertCommand));
                        this._WrapStyleId = result;
                    }
                }
                this.SaveChildren();

                //OBJECT IS DIRTY IF NO RECORDS WERE UPDATED OR INSERTED
                this.IsDirty = (result == 0);
                if (this.IsDirty)
                {
                    return(SaveResult.Failed);
                }
                else
                {
                    return(recordExists ? SaveResult.RecordUpdated : SaveResult.RecordInserted);
                }
            }

            //SAVE IS SUCCESSFUL IF OBJECT IS NOT DIRTY
            return(SaveResult.NotDirty);
        }