示例#1
0
        /// <summary>
        /// Lấy danh sách hình ảnh của sản phẩm
        /// </summary>
        /// <param name="productID"></param>
        /// <returns></returns>
        public List <string> getImageListByProduct(int productID, Thumbnail.Size size = Thumbnail.Size.Source)
        {
            using (var con = new inventorymanagementEntities())
            {
                // Lấy hình ảnh của sản phẩm cha
                var imageProduct = con.tbl_Product
                                   .Where(x => x.ID == productID)
                                   .Where(x => !String.IsNullOrEmpty(x.ProductImage))
                                   .Select(x => new { image = x.ProductImage })
                                   .ToList();
                // Lấy hình anh trong bảng image
                var imageSource = con.tbl_ProductImage.Where(x => x.ProductID == productID)
                                  .Select(x => new { image = x.ProductImage })
                                  .ToList();

                var images = imageProduct
                             .Union(imageSource)
                             .Select(x => x.image)
                             .Distinct()
                             .ToList();

                if (images.Count == 0)
                {
                    return(new List <string>()
                    {
                        Thumbnail.getURL(String.Empty, size)
                    });
                }
                else
                {
                    return(images.Select(x => Thumbnail.getURL(x, size)).ToList());
                }
            }
        }
        private Thumbnail.Rectangle CalculatePhysicalDestination(Thumbnail.Size size)
        {
            var controlToTaskview    = TransformToVisual(taskview);
            var placeholderToControl = Placeholder.TransformToVisual(this);
            var placeholderLeft      = placeholderToControl.Transform(new Point(0, 0)).X;
            var placeholderTop       = placeholderToControl.Transform(new Point(0, 0)).Y;
            var placeholderRight     = placeholderToControl.Transform(new Point(Placeholder.ActualWidth, 0)).X;
            var placeholderBottom    = placeholderToControl.Transform(new Point(0, Placeholder.ActualHeight)).Y;

            var physicalBounds = new Thumbnail.Rectangle
            {
                Left   = (int)Math.Round(this.TransformToPhysical(controlToTaskview.Transform(new Point(placeholderLeft, 0)).X, 0).X),
                Top    = (int)Math.Round(this.TransformToPhysical(0, controlToTaskview.Transform(new Point(0, placeholderTop)).Y).Y),
                Right  = (int)Math.Round(this.TransformToPhysical(controlToTaskview.Transform(new Point(placeholderRight, 0)).X, 0).X),
                Bottom = (int)Math.Round(this.TransformToPhysical(0, controlToTaskview.Transform(new Point(0, placeholderBottom)).Y).Y)
            };

            var scaleFactor      = default(double);
            var thumbnailHeight  = default(double);
            var thumbnailWidth   = default(double);
            var maxWidth         = (double)physicalBounds.Right - physicalBounds.Left;
            var maxHeight        = (double)physicalBounds.Bottom - physicalBounds.Top;
            var placeholderRatio = maxWidth / maxHeight;
            var windowRatio      = (double)size.X / size.Y;

            if (windowRatio < placeholderRatio)
            {
                thumbnailHeight = maxHeight;
                scaleFactor     = thumbnailHeight / size.Y;
                thumbnailWidth  = size.X * scaleFactor;
            }
            else
            {
                thumbnailWidth  = maxWidth;
                scaleFactor     = thumbnailWidth / size.X;
                thumbnailHeight = size.Y * scaleFactor;
            }

            var widthDifference  = maxWidth - thumbnailWidth;
            var heightDifference = maxHeight - thumbnailHeight;

            return(new Thumbnail.Rectangle
            {
                Left = (int)Math.Round(physicalBounds.Left + (widthDifference / 2)),
                Top = (int)Math.Round(physicalBounds.Top + (heightDifference / 2)),
                Right = (int)Math.Round(physicalBounds.Right - (widthDifference / 2)),
                Bottom = (int)Math.Round(physicalBounds.Bottom - (heightDifference / 2))
            });
        }