Esempio n. 1
0
 private bool IsValidItem(HistoryItem item)
 {
     return(item != null && !string.IsNullOrEmpty(item.Code) && !string.IsNullOrEmpty(item.NewPrice));
 }
Esempio n. 2
0
 private void SaveImageToClipboard(HistoryItem item)
 {
     Clipboard.SetImage(ImageHelper.ConvertToBitmapSource(imgPreview));
     AddToHistory(item);
 }
Esempio n. 3
0
 private void SaveImage(HistoryItem item)
 {
     ImageHelper.SaveToPng(imgPreview, DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".png");
     AddToHistory(item);
 }
Esempio n. 4
0
        private DrawingImage DrawPreview(HistoryItem item)
        {
            DrawingGroup drawingGroup = new DrawingGroup();

            // Background: Product image
            BitmapImage  image        = new BitmapImage(new Uri(currentItem.ImageSource, UriKind.Relative));
            ImageDrawing imageDrawing = new ImageDrawing(image, new Rect(0, 0, image.Width, image.Height));

            imageDrawing.Freeze();
            drawingGroup.Children.Add(imageDrawing);

            // Rectangle in the center
            GeometryDrawing rectangle      = new GeometryDrawing();
            double          rectRatio      = 0.5;
            double          rectWidth      = image.Width * rectRatio;
            double          rectHeight     = image.Height * rectRatio;
            double          rectX          = (image.Width - rectWidth) / 2;
            double          rectY          = (image.Height - rectHeight) / 2;
            var             rectangleBrush = new SolidColorBrush(Colors.Gray);

            rectangleBrush.Opacity = 0.7;
            rectangle.Brush        = rectangleBrush;
            rectangle.Geometry     = new RectangleGeometry(new Rect(rectX, rectY, rectWidth, rectHeight));
            drawingGroup.Children.Add(rectangle);

            double fontSize   = image.Width * 0.08;
            double lineHeight = fontSize * 1.2;
            double textX      = rectX + fontSize / 10;
            double textY      = rectY + lineHeight / 10;

            // Text inside rectangle
            DrawingVisual visual = new DrawingVisual();

            using (var context = visual.RenderOpen())
            {
                context.DrawText(new FormattedText(item.TimeStamp.ToString("dd/MM/yyyy")
                                                   , CultureInfo.InvariantCulture
                                                   , FlowDirection.LeftToRight
                                                   , new Typeface("Arial")
                                                   , fontSize
                                                   , Brushes.White
                                                   , VisualTreeHelper.GetDpi(this).PixelsPerDip), new Point(textX, textY));

                context.DrawText(new FormattedText((!string.IsNullOrEmpty(item.OldPrice)? item.OldPrice + " => " : "") + item.NewPrice
                                                   , CultureInfo.InvariantCulture
                                                   , FlowDirection.LeftToRight
                                                   , new Typeface("Arial")
                                                   , fontSize
                                                   , Brushes.White
                                                   , VisualTreeHelper.GetDpi(this).PixelsPerDip), new Point(textX, textY + lineHeight));

                if (!string.IsNullOrEmpty(item.Note))
                {
                    context.DrawText(new FormattedText(item.Note
                                                       , CultureInfo.InvariantCulture
                                                       , FlowDirection.LeftToRight
                                                       , new Typeface("Arial")
                                                       , fontSize
                                                       , Brushes.White
                                                       , VisualTreeHelper.GetDpi(this).PixelsPerDip), new Point(textX, textY + 2 * lineHeight));
                }
            }
            drawingGroup.Children.Add(visual.Drawing);

            DrawingImage drawingImage = new DrawingImage(drawingGroup);

            return(drawingImage);
        }