Exemplo n.º 1
0
    protected void uxSetAsPrimayImageButton_Click(object sender, EventArgs e)
    {
        string     storeID  = new StoreRetriever().GetCurrentStoreID();
        LinkButton myButton = (LinkButton)sender;
        string     imageID  = myButton.CommandArgument;
        Product    product  = DataAccessContext.ProductRepository.GetOne(Culture.Null, ProductID, storeID);

        string originalFilePath;

        if (ProductID == "0")
        {
            ProductImageData.SetPrimary(imageID);
            ImageItem item = ProductImageData.FindItem(imageID);
            originalFilePath = item.LargeImage;
        }
        else
        {
            ProductImage oldPrimaryImage = new ProductImage();
            ProductImage newPrimaryImage = new ProductImage();
            foreach (ProductImage productImage in product.ProductImages)
            {
                if (productImage.ProductImageID == imageID)
                {
                    newPrimaryImage = productImage;
                }
                if (productImage.SortOrder == 0)
                {
                    oldPrimaryImage = productImage;
                }
            }

            SetProductImageOrder(product, oldPrimaryImage.ProductImageID, newPrimaryImage.SortOrder);
            SetProductImageOrder(product, newPrimaryImage.ProductImageID, 0);

            originalFilePath = newPrimaryImage.LargeImage;
        }

        using (ProductImageFile imageFile = ProductImageFile.Load(new FileManager(), Path.GetFileName(originalFilePath)))
        {
            if (ProductID == "0")
            {
                SaveSecondaryNoProduct(imageFile);
            }
            else
            {
                SaveSecondary(product, imageFile);
            }
        }

        if (!product.IsNull)
        {
            DataAccessContext.ProductRepository.Save(product);
        }

        uxMessage.DisplayMessage(Resources.ProductImageMessages.SetPrimarySuccess);

        uxStatusHidden.Value = "SetPrimary";
    }
Exemplo n.º 2
0
    private void SetNewPrimaryImageAfterDelete(string imageID)
    {
        ProductImageData.SetPrimary(imageID);
        ImageItem item1            = ProductImageData.FindItem(imageID);
        string    originalFilePath = item1.LargeImage;

        using (ProductImageFile imageFile = ProductImageFile.Load(new FileManager(), Path.GetFileName(originalFilePath)))
        {
            SaveSecondaryNoProduct(imageFile);
        }
    }
Exemplo n.º 3
0
 private void DisplayUploadMessage(ProductImageFile imageFile)
 {
     if (IsZoomable(imageFile))
     {
         uxMessage.DisplayMessage(Resources.ProductImageMessages.UploadSuccess);
     }
     else
     {
         uxMessage.DisplayMessage(Resources.ProductImageMessages.UploadSuccessNoZoom);
     }
 }
Exemplo n.º 4
0
    private void SaveSecondaryNoProduct(ProductImageFile imageFile)
    {
        imageFile.SaveSecondary();

        if (!String.IsNullOrEmpty(ProductImageData.SecondaryImagePath) &&
            String.Compare(imageFile.SecondaryFilePath, ProductImageData.SecondaryImagePath, true) != 0)
        {
            DeleteFile(ProductImageData.SecondaryImagePath);
        }

        ProductImageData.SecondaryImagePath = imageFile.SecondaryFilePath;
    }
Exemplo n.º 5
0
    private void SaveSecondary(Product product, ProductImageFile imageFile)
    {
        imageFile.SaveSecondary();

        string secondaryImage = product.ImageSecondary;

        if (!String.IsNullOrEmpty(secondaryImage) &&
            String.Compare(imageFile.SecondaryFilePath, secondaryImage, true) != 0)
        {
            DeleteFile(secondaryImage);
        }
        product.ImageSecondary       = imageFile.SecondaryFilePath;
        uxSecondaryImageHidden.Value = product.ImageSecondary;
    }
Exemplo n.º 6
0
 private void CrateDataSource()
 {
     _imageSource     = CreateTable("ProductImage");
     _tempImageSource = CreateTable("TempProductImage");
     if (ProductID == "0")
     {
         uxSecondaryImageHidden.Value = ProductImageData.SecondaryImagePath;
         foreach (ImageItem item in ProductImageData.GetAllItems())
         {
             CreateRow(
                 _tempImageSource, item.ProductImageID, 0,
                 item.RegularImage, item.LargeImage, item.ThumbnailImage,
                 item.ImageSize, item.SortOrder, item.IsZoom, item.IsEnlarge,
                 item.ImageWidth, item.ImageHeight, item.Locales[CurrentCulture].AltTag, item.Locales[CurrentCulture].TitleTag);
         }
     }
     else
     {
         Product product = DataAccessContext.ProductRepository.GetOne(CurrentCulture, ProductID, new StoreRetriever().GetCurrentStoreID());
         uxSecondaryImageHidden.Value = product.ImageSecondary;
         foreach (ProductImage productImage in product.ProductImages)
         {
             ProductImageLocale locale = productImage.Locales[CurrentCulture];
             using (ProductImageFile imageFile =
                        ProductImageFile.Load(new FileManager(), Path.GetFileName(productImage.LargeImage)))
             {
                 CreateRow(_tempImageSource, productImage.ProductImageID,
                           ConvertUtilities.ToInt32(product.ProductID),
                           productImage.RegularImage,
                           productImage.LargeImage,
                           productImage.ThumbnailImage,
                           ProductImageFile.GetImageSize(new FileManager(), productImage.LargeImage),
                           productImage.SortOrder,
                           productImage.IsZoom,
                           productImage.IsEnlarge,
                           imageFile.LargeImageWidth,
                           imageFile.LargeImageHeight,
                           locale.AltTag,
                           locale.TitleTag);
             }
         }
     }
 }
Exemplo n.º 7
0
    private void RemoveExistingProductImage(Product product, string imageID)
    {
        bool         deletePrimary        = false;
        ProductImage productImageToDelete = new ProductImage();

        foreach (ProductImage productimage in product.ProductImages)
        {
            if (productimage.ProductImageID == imageID)
            {
                DeleteImage(productimage.RegularImage, productimage.LargeImage, productimage.ThumbnailImage);
                if (productimage.SortOrder == 0)
                {
                    DeleteFile(product.ImageSecondary);
                    deletePrimary = true;
                }
                productImageToDelete = productimage;
            }
        }

        product.ProductImages.Remove(productImageToDelete);

        if (deletePrimary)
        {
            foreach (ProductImage productimage in product.ProductImages)
            {
                productimage.SortOrder = productimage.SortOrder - 1;
                if (productimage.SortOrder == 0)
                {
                    using (ProductImageFile imageFile = ProductImageFile.Load(new FileManager(), Path.GetFileName(productimage.LargeImage)))
                    {
                        SaveSecondary(product, imageFile);
                    }
                }
            }
        }
    }
Exemplo n.º 8
0
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Drawing.Image    thumbnail_image = null;
        System.Drawing.Image    original_image  = null;
        System.Drawing.Bitmap   final_image     = null;
        System.Drawing.Graphics graphic         = null;
        String       fileNameInfo   = String.Empty;
        MemoryStream ms             = null;
        bool         errorDuplicate = false;

        try
        {
            // Get the data
            HttpPostedFile jpeg_image_upload = Request.Files["Filedata"];
            fileNameInfo = Path.GetFileName(jpeg_image_upload.FileName);
            using (original_image = System.Drawing.Image.FromStream(jpeg_image_upload.InputStream))
            {
                using (ProductImageFile imageFile = new ProductImageFile(new FileManager(), fileNameInfo, original_image))
                {
                    if (IsUsedByAnotherProduct(imageFile.LargeFilePath))
                    {
                        errorDuplicate = true;
                        Response.End();
                    }

                    imageFile.SaveLargeImage();
                    imageFile.SaveRegular();
                    imageFile.SaveThumbnail();

                    if (ProductID == "0")
                    {
                        int sortOrder = ProductImageData.GetNexOrder();

                        ProductImageData.AddImageItem(
                            imageFile.ThumbnailFilePath,
                            imageFile.RegularFilePath,
                            imageFile.LargeFilePath,
                            ProductImageFile.GetImageSize(new FileManager(), imageFile.LargeFilePath),
                            sortOrder,
                            IsZoomable(imageFile),
                            true,
                            imageFile.LargeImageWidth,
                            imageFile.LargeImageHeight,
                            StoreContext.Culture,
                            "",
                            ""
                            );

                        if (sortOrder == 0)
                        {
                            SaveSecondaryNoProduct(imageFile);
                        }
                    }
                    else
                    {
                        string       storeID      = new StoreRetriever().GetCurrentStoreID();
                        Product      product      = DataAccessContext.ProductRepository.GetOne(StoreContext.Culture, ProductID, storeID);
                        ProductImage productImage = new ProductImage();

                        productImage.RegularImage   = imageFile.RegularFilePath;
                        productImage.LargeImage     = imageFile.LargeFilePath;
                        productImage.ThumbnailImage = imageFile.ThumbnailFilePath;
                        productImage.IsZoom         = IsZoomable(imageFile);
                        productImage.IsEnlarge      = true;

                        if (product.ProductImages.Count == 0)
                        {
                            SaveSecondary(product, imageFile);
                        }

                        productImage.SortOrder = product.ProductImages.Count;

                        product.ProductImages.Add(productImage);

                        DataAccessContext.ProductRepository.Save(product);
                    }
                }
            }
            Response.StatusCode = 200;
            Response.Write("Success");
        }
        catch
        {
            // If any kind of error occurs return a 500 Internal Server error

            if (!errorDuplicate)
            {
                Response.StatusCode = 500;
                Response.Write("An error occured");
            }
            else
            {
                Response.StatusCode = 601;
                Response.Write("Upload Error Duplicated");
            }
            Response.End();
        }
        finally
        {
            // Clean up
            if (final_image != null)
            {
                final_image.Dispose();
            }
            if (graphic != null)
            {
                graphic.Dispose();
            }
            if (original_image != null)
            {
                original_image.Dispose();
            }
            if (thumbnail_image != null)
            {
                thumbnail_image.Dispose();
            }
            if (ms != null)
            {
                ms.Close();
            }
            Response.End();
        }
    }
Exemplo n.º 9
0
 private bool IsZoomable(ProductImageFile imageFile)
 {
     return(IsZoomableSize(imageFile.LargeImageWidth, imageFile.LargeImageHeight));
 }