Example #1
0
        public static FlowDocument BuildFlowDoc(Waybill waybill, IList <WaybillLine> lines, WaybillSettings settings, Func <WaybillLine, FrameworkElement> map, double borderThickness)
        {
            var document = new FlowDocument();

            document.PagePadding = new Thickness(0, 0, 0, 0);
            var left = lines.Count;

            while (left > 0)
            {
                var border = new Border {
                    Margin = new Thickness(1)
                };
                var section = new Section();
                section.BreakPageBefore = true;
                var leftSize = new Size(pageSize.Width - border.Margin.Left - border.Margin.Right,
                                        pageSize.Height - border.DesiredSize.Height - border.Margin.Top - border.Margin.Bottom);
                var grid = new BlockUIContainer(BuildMapGrid(i => map(lines[i]), lines.Count, leftSize, ref left, borderThickness));
                section.Blocks.Add(grid);
                document.Blocks.Add(section);
            }
            return(document);
        }
Example #2
0
        private List <Image> GetImages(RichTextBox rtb)
        {
            List <Image> images = new List <Image>();

            foreach (Block block in rtb.Document.Blocks)
            {
                if (block is BlockUIContainer)
                {
                    BlockUIContainer blockui = (BlockUIContainer)block;
                    if (blockui.Child is Image)
                    {
                        Image img = (Image)blockui.Child;
                        Dispatcher.BeginInvoke(new ThreadStart(delegate
                        {
                            blockui.Child = null;
                        }));
                        images.Add(img);
                    }
                }
            }
            return(images);
        }
Example #3
0
        private void Block(List <Grid> items)
        {
            var bodyBlock = new BlockUIContainer();

            bodyBlock.Child = new Grid
            {
                HorizontalAlignment = HorizontalAlignment.Left,
                Margin = new Thickness(0, 0, 0, 0),
                Width  = 1069,
            };
            doc.Blocks.Add(bodyBlock);
            var grid   = (Grid)bodyBlock.Child;
            var column = 0;

            foreach (var item in items)
            {
                grid.Cell(0, column, item);
                grid.ColumnDefinitions[column].Width = GridLength.Auto;
                column++;
            }
            grid.ColumnDefinitions[column - 1].Width = GridLength.Auto;
        }
        private BlockUIContainer GetSatinLabel(Label label)
        {
            StackPanel stackPanel = new StackPanel
            {
                Margin = new Thickness(ConvertMmToPixel(3), ConvertMmToPixel(7), ConvertMmToPixel(3), ConvertMmToPixel(6))
            };

            for (int i = 0; i < 9; i++)
            {
                WrapPanel wrapPanel = new WrapPanel
                {
                    Margin = new Thickness(0)
                };

                wrapPanel.Children.Add(GetLabel(label, 10, 2, 29.5, 1.5));
                wrapPanel.Children.Add(GetBorder(0.5, 20));
                wrapPanel.Children.Add(GetLabel(label, 29.5, 2, 29.5, 1.5));
                wrapPanel.Children.Add(GetBorder(0.5, 20));
                wrapPanel.Children.Add(GetLabel(label, 29.5, 2, 10, 1.5));

                stackPanel.Children.Add(wrapPanel);

                WrapPanel wrapPanel1 = new WrapPanel
                {
                    Margin = new Thickness(0)
                };

                wrapPanel1.Children.Add(GetBorder(4, 0.5, 0, 0, 42, 1.5));
                wrapPanel1.Children.Add(GetBorder(4, 0.5, 41.5, 0, 53, 1.5));
                wrapPanel1.Children.Add(GetBorder(4, 0.5, 52.5, 0, 42, 1.5));
                wrapPanel1.Children.Add(GetBorder(4, 0.5, 42, 0, 0, 1.5));

                stackPanel.Children.Add(wrapPanel1);
            }
            BlockUIContainer container = new BlockUIContainer(stackPanel);

            return(container);
        }
Example #5
0
        private void UpdateUIChildrenInstancesInternal(ViewNode root)
        {
            InlineUIContainer inlineUIContainerInstance = root.Instance as InlineUIContainer;

            if (inlineUIContainerInstance != null && inlineUIContainerInstance.Child != null)
            {
                this.UpdateUIChildInstance((DocumentCompositeNode)root.DocumentNode, inlineUIContainerInstance);
            }
            BlockUIContainer blockUIContainerInstance = root.Instance as BlockUIContainer;

            if (blockUIContainerInstance != null && blockUIContainerInstance.Child != null)
            {
                this.UpdateUIChildInstance((DocumentCompositeNode)root.DocumentNode, blockUIContainerInstance);
            }
            foreach (ViewNode root1 in (IEnumerable <ViewNode>)root.Children)
            {
                this.UpdateUIChildrenInstancesInternal(root1);
            }
            foreach (ViewNode root1 in (IEnumerable <ViewNode>)root.Properties.Values)
            {
                this.UpdateUIChildrenInstancesInternal(root1);
            }
        }
Example #6
0
        private Block RuleEvaluator(Match match)
        {
            if (match == null)
            {
                throw new ArgumentNullException("match");
            }

            Line line = new Line();

            if (SeparatorStyle == null)
            {
                line.X2 = 1;
                line.StrokeThickness = 1.0;
            }
            else
            {
                line.Style = SeparatorStyle;
            }

            var container = new BlockUIContainer(line);

            return(container);
        }
        private void setTextStory(string txt)
        {
            //BlockUIContainer blockC = new BlockUIContainer();
            //blockC.Child = myBrush2;
            FlowDocument doc     = new FlowDocument();
            Paragraph    p       = new Paragraph();
            Image        sideImg = new Image();

            sideImg.Source =
                //    new BitmapImage(new Uri("C:/Users/monstrengo/Desktop/StoryTelling1/StoryTelling1/GUI/image/" + imgNumber + ".jpg", UriKind.Relative));
                new BitmapImage(new Uri("C:/Users/parad/Desktop/StoryTelling1/StoryTelling1/GUI/image/" + imgNumber + ".jpg", UriKind.Relative));
            //new BitmapImage(new Uri(@"pack://application:,,,/image/" + imgNumber + ".jpg", UriKind.Relative));
            //new BitmapImage(new Uri("C:/Users/parad/Documents/Visual Studio 2015/Projects/StoryTelling1/StoryTelling1/GUI/image/" + imgNumber + ".jpg", UriKind.Relative));
            sideImg.Width = 600;

            BlockUIContainer blockC = new BlockUIContainer();

            blockC.Child = sideImg;
            Floater floater = new Floater(blockC);

            floater.Width = 620;
            floater.HorizontalAlignment = HorizontalAlignment.Left;
            floater.Margin = new Thickness(0, 0, 5, 5);


            //p.Inlines.Add(txt);
            p.Inlines.Clear();
            p.Inlines.Add(floater);
            //p.TextAlignment = TextAlignment.Justify;
            //p.FontSize = 22;
            //p.FontFamily = new FontFamily("Comic Sans MS");
            doc.Blocks.Add(p);
            fdViewer.Document = doc;
            doc.Blocks.Remove(blockC);

            createDocStory.createDocument(storyPlayer, text, numberDP);
        }
Example #8
0
        // Adds a horizontal line to the document
        private void AddHorizontalLine()
        {
            double pageWidth = mDocument.PageWidth - mDocument.PagePadding.Left - mDocument.PagePadding.Right;

            try
            {
                Line line = new Line();
                line.Stroke             = Brushes.DarkGray;
                line.StrokeThickness    = 2;
                line.Height             = 10;
                line.StrokeStartLineCap = PenLineCap.Round;
                line.StrokeEndLineCap   = PenLineCap.Round;
                line.X1 = 4;
                line.X2 = pageWidth - 4;
                line.Y1 = line.Height / 2;
                line.Y2 = line.Height / 2;
                BlockUIContainer container = new BlockUIContainer(line);
                mDocument.Blocks.Add(container);
            }
            catch (Exception ex)
            {
                Log.GetInstance().LogError("Error in creating horizontal line for the printout.", ex);
            }
        }
Example #9
0
        private FlowDocument CreateDocument(List <BarcodeInfo> barcodes)
        {
            var document = new FlowDocument();

            var table = new Table();

            for (var i = 0; i < 4; i++)
            {
                table.Columns.Add(new TableColumn());
            }

            var rowGroup = new TableRowGroup();

            table.RowGroups.Add(rowGroup);
            table.RowGroups[0].Rows.Add(new TableRow());

            var currentRow = table.RowGroups[0].Rows[0];

            foreach (var barcode in barcodes)
            {
                var qrCodeGenerator = new QRCodeGenerator();
                var qrCodeData      = qrCodeGenerator.CreateQrCode(JsonConvert.SerializeObject(barcode), QRCodeGenerator.ECCLevel.Q);
                var qrCode          = new QRCode(qrCodeData);
                var bitmap          = qrCode.GetGraphic(20);

                var image = new System.Windows.Controls.Image()
                {
                    Source = BitmapToImageSource(bitmap)
                };
                var block = new BlockUIContainer(image);
                currentRow.Cells.Add(new TableCell(block));
            }

            document.Blocks.Add(table);
            return(document);
        }
        private BlockUIContainer GetTitleBlockContainer()
        {
            BlockUIContainer titleBlockContainer = new BlockUIContainer();

            StackPanel stackPanel = new StackPanel {
                Orientation = Orientation.Vertical, Width = 1000
            };

            Label   testLabel          = new Label();
            Binding reportTitleBinding = new Binding
            {
                Source = this,
                Path   = new PropertyPath("ReportTitle"),
                Mode   = BindingMode.OneWay,
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
            };

            BindingOperations.SetBinding(testLabel, ContentControl.ContentProperty, reportTitleBinding);

            stackPanel.Children.Add(testLabel);

            titleBlockContainer.Child = stackPanel;
            return(titleBlockContainer);
        }
Example #11
0
        private void BlocksToXamlInner(FlowDocument parent, Block block, CommonMarkSettings settings)
        {
            _checkBoxNumber = 0;
            var  stack          = new Stack <BlockStackEntry>();
            var  inlineStack    = new Stack <InlineStackEntry>();
            bool stackTight     = false;
            bool tight          = false;
            bool trackPositions = settings.TrackSourcePosition;
            int  x;

            IAddChild blockParent = parent;

            while (block != null)
            {
                var       visitChildren = false;
                IAddChild lastParent    = null;

                switch (block.Tag)
                {
                case BlockTag.Document:
                    stackTight    = false;
                    visitChildren = true;
                    lastParent    = parent;
                    break;

                case BlockTag.Paragraph:
                    if (tight)
                    {
                        InlinesToXaml(blockParent, block.InlineContent, settings, inlineStack);
                    }
                    else
                    {
                        Paragraph paragraph = new Paragraph();
                        if (trackPositions)
                        {
                            PrintPosition(paragraph, block);
                        }
                        InlinesToXaml(paragraph, block.InlineContent, settings, inlineStack);
                        blockParent.AddChild(paragraph);
                    }
                    break;

                case BlockTag.BlockQuote:
                    Section blockquoteParagraph = new Section();
                    if (trackPositions)
                    {
                        PrintPosition(blockquoteParagraph, block);
                    }

                    if (QuoteStyle != null)
                    {
                        blockquoteParagraph.Style = QuoteStyle;
                    }

                    blockParent.AddChild(blockquoteParagraph);
                    lastParent  = blockParent;
                    blockParent = blockquoteParagraph;

                    stackTight    = true;
                    visitChildren = true;
                    break;

                case BlockTag.ListItem:

                    stackTight = tight;

                    if (block.ListData != null && block.ListData.ListType == ListType.TaskList)
                    {
                        BlockUIContainer ctnr = (BlockUIContainer)blockParent;
                        StackPanel       sp   = (StackPanel)ctnr.Child;

                        visitChildren = false;
                        TextBlock spcb = new TextBlock();
                        spcb.Style = TodoTextStyle;
                        Inline checkBoxInline = block.FirstChild?.InlineContent;
                        if (checkBoxInline != null)
                        {
                            InlinesToXaml(spcb, checkBoxInline, settings, inlineStack);
                        }

                        CheckBox bt = new CheckBox
                        {
                            IsChecked = block.TaskListItemIsChecked,
                            Content   = spcb,
                            Tag       = _checkBoxNumber
                        };
                        bt.CommandParameter = bt;
                        bt.Command          = CheckBoxCheckedCommand;
                        bt.Style            = TodoCheckBoxStyle;

                        sp.Children.Add(bt);

                        //TODO: Add child stack panel and add block.FirstChild.NextSibling

                        _checkBoxNumber++;
                    }
                    else
                    {
                        ListItem listItem = new ListItem();
                        if (ListItemStyle != null)
                        {
                            listItem.Style = ListItemStyle;
                        }

                        if (trackPositions)
                        {
                            PrintPosition(listItem, block);
                        }

                        blockParent.AddChild(listItem);

                        lastParent    = blockParent;
                        blockParent   = listItem;
                        visitChildren = true;
                    }

                    break;

                case BlockTag.List:
                    var       data = block.ListData;
                    IAddChild list;
                    if (data.ListType == ListType.TaskList)
                    {
                        StackPanel sp = new StackPanel();
                        list = new BlockUIContainer(sp);
                    }
                    else
                    {
                        List theList = new List();
                        list = theList;
                        theList.MarkerStyle = data.ListType == ListType.Bullet ? TextMarkerStyle.Disc : TextMarkerStyle.Decimal;

                        if (ListStyle != null)
                        {
                            theList.Style = ListStyle;
                        }
                    }

                    if (trackPositions)
                    {
                        PrintPosition((FrameworkContentElement)list, block);
                    }

                    // TODO: Check if first child starts with [ ] then it is a todo-list item
                    // TODO: Set list.StartIndex if > 1

                    blockParent.AddChild(list);
                    lastParent  = blockParent;
                    blockParent = list;

                    stackTight    = data.IsTight;
                    visitChildren = true;
                    break;

                case BlockTag.AtxHeading:
                case BlockTag.SetextHeading:
                    Paragraph headerParagraph = new Paragraph();
                    if (trackPositions)
                    {
                        PrintPosition(headerParagraph, block);
                    }

                    InlinesToXaml(headerParagraph, block.InlineContent, settings, inlineStack);

                    x = block.Heading.Level;

                    switch (x)
                    {
                    case 1:
                        headerParagraph.Style = Heading1Style;
                        break;

                    case 2:
                        headerParagraph.Style = Heading2Style;
                        break;

                    case 3:
                        headerParagraph.Style = Heading3Style;
                        break;

                    case 4:
                        headerParagraph.Style = Heading4Style;
                        break;

                    default:
                        headerParagraph.Style = Heading1Style;
                        break;
                    }

                    blockParent.AddChild(headerParagraph);

                    break;

                case BlockTag.IndentedCode:
                case BlockTag.FencedCode:
                    Paragraph codeblockParagraph = new Paragraph();

                    if (trackPositions)
                    {
                        PrintPosition(codeblockParagraph, block);
                    }

                    if (CodeBlockStyle != null)
                    {
                        codeblockParagraph.Style = CodeBlockStyle;
                    }

                    var info = block.FencedCodeData == null ? null : block.FencedCodeData.Info;
                    if (info != null && info.Length > 0)
                    {
                        //x = info.IndexOf(' ');
                        //if (x == -1)
                        //	x = info.Length;

                        //parent.WriteConstant(" class=\"language-");
                        //EscapeHtml(new StringPart(info, 0, x), parent);
                        //parent.Write('\"');
                    }

                    EscapeHtml(block.StringContent, codeblockParagraph);

                    blockParent.AddChild(codeblockParagraph);
                    break;

                case BlockTag.HtmlBlock:
                    // cannot output source position for HTML blocks
                    // block.StringContent.WriteTo(parent);

                    //TODO: Unable to convert html to

                    break;

                case BlockTag.ThematicBreak:
                    var line = new Line()
                    {
                        X2 = 1, StrokeThickness = 1.0
                    };
                    var container = new BlockUIContainer(line);
                    if (trackPositions)
                    {
                        PrintPosition(container, block);
                    }

                    if (LineStyle != null)
                    {
                        line.Style = LineStyle;
                    }

                    blockParent.AddChild(container);
                    break;

                case BlockTag.Table:
                    WriteTable(block, blockParent, settings, inlineStack);
                    break;

                case BlockTag.ReferenceDefinition:
                    break;

                default:
                    throw new CommonMarkException("Block type " + block.Tag + " is not supported.", block);
                }

                if (visitChildren)
                {
                    stack.Push(new BlockStackEntry(lastParent, block.NextSibling, tight));

                    tight = stackTight;
                    block = block.FirstChild;
                }
                else if (block.NextSibling != null)
                {
                    block = block.NextSibling;
                }
                else
                {
                    block = null;
                }

                while (block == null && stack.Count > 0)
                {
                    var entry = stack.Pop();

                    blockParent = entry.Parent;
                    tight       = entry.IsTight;
                    block       = entry.Target;
                }
            }
        }
Example #12
0
        private FlowDocument GenerateEncyclopediaDocument(IEncyclopediaEntry entry)
        {
            if (entry == null)
            {
                return(new FlowDocument());
            }

            var design              = entry as TechObjectDesign;
            var doc                 = new FlowDocument();
            var imageConverter      = new EncyclopediaImageConverter();
            var fiendImageConverter = new ResearchFieldImageConverter();

            var headerRun   = new Run(entry.EncyclopediaHeading);
            var headerBlock = new Paragraph(headerRun)
            {
                FontFamily = FindResource(ClientResources.DefaultFontFamilyKey) as FontFamily,
                FontSize   = 16d * 96d / 72d,
                Foreground = FindResource(ClientResources.HeaderTextForegroundBrushKey) as Brush
            };

            doc.Blocks.Add(headerBlock);

            doc.FontFamily    = FindResource(ClientResources.DefaultFontFamilyKey) as FontFamily;
            doc.FontSize      = 12d * 96d / 72d;
            doc.Foreground    = FindResource(ClientResources.DefaultTextForegroundBrushKey) as Brush;
            doc.TextAlignment = TextAlignment.Left;

            // EncyclopediaImage
            var image       = new Border();
            var imageSource = imageConverter.Convert(
                entry.EncyclopediaImage,
                typeof(BitmapImage),
                null,
                null) as BitmapImage;

            var paragraphs = TextHelper.TrimParagraphs(entry.EncyclopediaText).Split(
                new[] { Environment.NewLine },
                StringSplitOptions.RemoveEmptyEntries).Select(o => new Paragraph(new Run(o))).ToList();

            var firstParagraph = paragraphs.FirstOrDefault();

            if (firstParagraph == null)
            {
                firstParagraph = new Paragraph();
                doc.Blocks.Add(firstParagraph);
            }

            if (imageSource != null)
            {
                var imageWidth  = imageSource.Width;
                var imageHeight = imageSource.Height;

                var imageRatio = imageWidth / imageHeight;
                if (imageRatio >= 1.0)
                {
                    imageWidth  = Math.Max(200, Math.Min(imageWidth, 270));
                    imageHeight = imageWidth / imageRatio;
                }
                else
                {
                    imageHeight = Math.Max(200, Math.Min(imageHeight, 270));
                    imageWidth  = imageHeight * imageRatio;
                }

                image.Width           = imageWidth;
                image.Height          = imageHeight;
                image.BorderBrush     = Brushes.White;
                image.BorderThickness = new Thickness(2.0);
                image.CornerRadius    = new CornerRadius(14.0);
                image.Background      = new ImageBrush(imageSource)
                {
                    Stretch = Stretch.UniformToFill
                };

                var imageMargin  = new Thickness(14, 0, 0, 14);
                var imageFloater = new Floater
                {
                    Blocks = { new BlockUIContainer(image) },
                    Margin = imageMargin,
                    Width  = image.Width,
                    HorizontalAlignment = HorizontalAlignment.Right,
                    Padding             = new Thickness(0)
                };

                if (firstParagraph.Inlines.Any())
                {
                    firstParagraph.Inlines.InsertBefore(firstParagraph.Inlines.First(), imageFloater);
                }
                else
                {
                    firstParagraph.Inlines.Add(imageFloater);
                }
            }

            doc.Blocks.AddRange(paragraphs);

            if (design != null)
            {
                var statsControl = new ContentControl
                {
                    Margin  = new Thickness(0, 14, 0, 0),
                    Width   = 320,
                    Content = new TechObjectDesignViewModel
                    {
                        Design       = design,
                        Civilization = AppContext.LocalPlayer.Empire
                    },
                    Style = FindResource("TechObjectInfoPanelStyle") as Style
                };

                var statsBlock = new Paragraph(new InlineUIContainer(statsControl))
                {
                    TextAlignment = TextAlignment.Center,
                    Margin        = new Thickness(0)
                };

                doc.Blocks.Add(statsBlock);

                var techTable = new Table();
                techTable.RowGroups.Add(new TableRowGroup());
                techTable.RowGroups[0].Rows.Add(new TableRow());
                foreach (var field in GameContext.Current.ResearchMatrix.Fields)
                {
                    var techCategory   = field.TechCategory;
                    var column         = new TableColumn();
                    var techIcon       = new Border();
                    var techTextShadow = new TextBlock {
                        Effect = new BlurEffect {
                            Radius = 6
                        }
                    };
                    var techText = new TextBlock();

                    if (design.TechRequirements[techCategory] < 1)
                    {
                        techIcon.Opacity = 0.25;
                    }

                    var imageBrush = new ImageBrush(
                        fiendImageConverter.Convert(field, typeof(BitmapImage), null, null)
                        as ImageSource)
                    {
                        Stretch = Stretch.Uniform
                    };

                    techIcon.Width           = 54;
                    techIcon.Height          = 45;
                    techIcon.Padding         = new Thickness(4);
                    techIcon.BorderBrush     = Brushes.White;
                    techIcon.BorderThickness = new Thickness(2.0);
                    techIcon.CornerRadius    = new CornerRadius(7.0);
                    techIcon.Background      = imageBrush;

                    techTextShadow.Text       = design.TechRequirements[techCategory].ToString();
                    techTextShadow.Foreground = Brushes.Black;
                    techTextShadow.SetResourceReference(TextBlock.FontFamilyProperty, ClientResources.DefaultFontFamilyKey);
                    techTextShadow.FontWeight          = FontWeights.Bold;
                    techTextShadow.FontSize            = 16 * (96d / 72d);
                    techTextShadow.HorizontalAlignment = HorizontalAlignment.Right;
                    techTextShadow.VerticalAlignment   = VerticalAlignment.Bottom;

                    techText.Text       = design.TechRequirements[techCategory].ToString();
                    techText.Foreground = Brushes.White;
                    techText.SetResourceReference(TextBlock.FontFamilyProperty, ClientResources.DefaultFontFamilyKey);
                    techText.FontWeight          = FontWeights.Normal;
                    techText.FontSize            = 16 * (96d / 72d);
                    techText.HorizontalAlignment = HorizontalAlignment.Right;
                    techText.VerticalAlignment   = VerticalAlignment.Bottom;

                    techIcon.Child = new Grid {
                        Children = { techTextShadow, techText }
                    };
                    techIcon.ToolTip = String.Format(
                        "{0} Level {1}",
                        ResourceManager.GetString(field.Name),
                        design.TechRequirements[techCategory]);

                    techIcon.UseLayoutRounding = true;
                    techIcon.CacheMode         = new BitmapCache {
                        SnapsToDevicePixels = true
                    };

                    BindingOperations.SetBinding(
                        techIcon.CacheMode,
                        BitmapCache.RenderAtScaleProperty,
                        new Binding
                    {
                        Source = Application.Current.MainWindow,
                        Path   = new PropertyPath(ClientProperties.ScaleFactorProperty),
                        Mode   = BindingMode.OneWay
                    });

                    var techIconContainer = new BlockUIContainer(techIcon);

                    techTable.Columns.Add(column);
                    techTable.RowGroups[0].Rows[0].Cells.Add(new TableCell(techIconContainer));
                }

                techTable.ClearFloaters = WrapDirection.Both;
                techTable.Margin        = new Thickness(0, 14, 0, 0);
                techTable.CellSpacing   = 7.0;

                doc.Blocks.Add(techTable);
            }

            return(doc);
        }
Example #13
0
        private void Generate_HeadText(BlockUIContainer blkHeadText, OrderForPrint order)
        {
            // Main stackPanel in Head Text
            StackPanel stpHeadText = new StackPanel();

            StackPanel stpTime = new StackPanel()
            {
                Orientation = Orientation.Horizontal,
                Margin      = new Thickness(0, 0, 0, 10)
            };
            TextBlock tbDate = new TextBlock()
            {
                Text              = order.Date.ToShortDateString(),
                Width             = 120,
                VerticalAlignment = VerticalAlignment.Stretch,
                TextAlignment     = TextAlignment.Left,
                FontFamily        = new FontFamily("Century Gothic"),
                FontSize          = 18,
                FontWeight        = FontWeights.UltraBold,
            };
            TextBlock tbTime = new TextBlock()
            {
                Text              = order.Date.ToShortTimeString(),
                Width             = 150,
                VerticalAlignment = VerticalAlignment.Stretch,
                TextAlignment     = TextAlignment.Right,
                FontFamily        = new FontFamily("Century Gothic"),
                FontSize          = 18,
                FontWeight        = FontWeights.UltraBold,
            };

            stpTime.Children.Add(tbDate);
            stpTime.Children.Add(tbTime);


            StackPanel stpTableNumber = new StackPanel()
            {
                Orientation = Orientation.Horizontal
            };
            TextBlock tbTableNumberLabel = new TextBlock()
            {
                Text       = "Table:    ",
                FontFamily = new FontFamily("Century Gothic"),
                FontSize   = 18,
                FontWeight = FontWeights.UltraBold,
            };
            TextBlock tbTableNumber = new TextBlock()
            {
                Text       = order.Table.ToString(),
                FontFamily = new FontFamily("Century Gothic"),
                FontSize   = 18,
                Width      = 30,
                FontWeight = FontWeights.UltraBold,
            };
            TextBlock tbPaxLable = new TextBlock()
            {
                Text       = "Pax:    ",
                FontFamily = new FontFamily("Century Gothic"),
                FontSize   = 18,
                Width      = 40,
                Margin     = new Thickness(95, 0, 0, 0),
                FontWeight = FontWeights.UltraBold,
            };
            TextBlock tbPaxValue = new TextBlock()
            {
                Text          = order.Pax.ToString(),
                FontFamily    = new FontFamily("Century Gothic"),
                FontSize      = 18,
                Width         = 35,
                TextAlignment = TextAlignment.Right,
                FontWeight    = FontWeights.UltraBold,
            };

            stpTableNumber.Children.Add(tbTableNumberLabel);
            stpTableNumber.Children.Add(tbTableNumber);
            stpTableNumber.Children.Add(tbPaxLable);
            stpTableNumber.Children.Add(tbPaxValue);


            StackPanel stpPageName = new StackPanel();
            TextBlock  tbPageName  = new TextBlock()
            {
                Text = "BAR",
                HorizontalAlignment = HorizontalAlignment.Center,
                FontSize            = 20,
                Margin     = new Thickness(0, 10, 0, 0),
                FontFamily = new FontFamily("Century Gothic"),
                FontWeight = FontWeights.UltraBold,
            };

            stpPageName.Children.Add(tbPageName);

            stpHeadText.Children.Add(stpTime);
            stpHeadText.Children.Add(stpTableNumber);
            stpHeadText.Children.Add(stpPageName);

            blkHeadText.Child = stpHeadText;
        }
Example #14
0
        public void Generate_TableText(BlockUIContainer blkTableText, string[] gridMeta, Dictionary <string, Dictionary <int, List <OrderDetailsForPrint> > > listData)
        {
            // Main stackPanel in Table Text
            StackPanel stpTableText = new StackPanel()
            {
                Margin = new Thickness(0, 0, 0, 10)
            };

            bool isShowMeta = false;

            // Data for each Product Status
            foreach (var dataInStatus in listData)
            {
                Grid dgDataTable = new Grid();
                dgDataTable.Width = 300;
                // set Columns
                for (int i = 0; i < 3; i++)
                {
                    if (i == 0)
                    {
                        ColumnDefinition firstCol = new ColumnDefinition();
                        firstCol.Width = new GridLength(75);
                        dgDataTable.ColumnDefinitions.Add(firstCol);
                        continue;
                    }
                    if (i == 1)
                    {
                        ColumnDefinition secondCol = new ColumnDefinition();
                        secondCol.Width = new GridLength(50);
                        dgDataTable.ColumnDefinitions.Add(secondCol);
                        continue;
                    }
                    if (i == 2)
                    {
                        ColumnDefinition otherCol = new ColumnDefinition();
                        otherCol.Width = new GridLength(160);
                        dgDataTable.ColumnDefinitions.Add(otherCol);
                        continue;
                    }
                }
                // set Rows
                dgDataTable.RowDefinitions.Add(new RowDefinition());    // extra row for meta
                foreach (var orderDetailInChair in dataInStatus.Value.Values)
                {
                    foreach (var orderDetails in orderDetailInChair)
                    {
                        dgDataTable.RowDefinitions.Add(new RowDefinition());
                    }
                }


                // add Meta
                if (!isShowMeta)
                {
                    for (int i = 0; i < 3; i++)
                    {
                        TextBlock txtMeta = new TextBlock();
                        txtMeta.Text              = gridMeta[i];
                        txtMeta.FontSize          = 15;
                        txtMeta.FontWeight        = FontWeights.Bold;
                        txtMeta.VerticalAlignment = VerticalAlignment.Stretch;
                        Grid.SetRow(txtMeta, 0);
                        Grid.SetColumn(txtMeta, i);

                        dgDataTable.Children.Add(txtMeta);
                    }
                }
                isShowMeta = true;


                // Status
                StackPanel stpStatus = new StackPanel();
                TextBlock  tbStatus  = new TextBlock()
                {
                    Text = dataInStatus.Key,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    FontSize            = 18,
                    FontWeight          = FontWeights.Bold
                };
                stpStatus.Children.Add(tbStatus);


                // Data
                int bigRowIndex = 1;
                foreach (var chairInStatus in dataInStatus.Value)
                {
                    if (chairInStatus.Value.Count == 0)
                    {
                        continue;
                    }

                    // CHAIR
                    StackPanel stpChair = new StackPanel()
                    {
                        Orientation = Orientation.Horizontal
                    };
                    TextBlock tbChairNumber = new TextBlock()
                    {
                        Text       = chairInStatus.Key.ToString(),
                        FontFamily = new FontFamily("Century Gothic"),
                        FontWeight = FontWeights.Bold,
                        Margin     = new Thickness(0, 0, 10, 0)
                    };
                    stpChair.Children.Add(tbChairNumber);
                    Grid.SetRow(stpChair, bigRowIndex);
                    Grid.SetColumn(stpChair, 0);
                    Grid.SetRowSpan(stpChair, chairInStatus.Value.Count);
                    dgDataTable.Children.Add(stpChair);

                    int smallRowIndex = bigRowIndex;
                    foreach (var orderDetailsInChair in chairInStatus.Value)
                    {
                        // QUANTITY
                        TextBlock tbQuan = new TextBlock()
                        {
                            Text       = orderDetailsInChair.Quan.ToString(),
                            FontSize   = 16,
                            FontFamily = new FontFamily("Century Gothic"),
                        };
                        Grid.SetRow(tbQuan, smallRowIndex);
                        Grid.SetColumn(tbQuan, 1);
                        dgDataTable.Children.Add(tbQuan);

                        // INFO
                        StackPanel stpInfo = new StackPanel()
                        {
                            Orientation = Orientation.Vertical
                        };
                        TextBlock tbProductName = new TextBlock()
                        {
                            Text       = "- " + seperateLongProductName(orderDetailsInChair.ProductName),
                            FontSize   = 16,
                            FontFamily = new FontFamily("Century Gothic"),
                        };
                        TextBlock tbNote = new TextBlock()
                        {
                            Inlines  = { new Italic(new Run(orderDetailsInChair.Note)) },
                            FontSize = 12
                        };
                        stpInfo.Children.Add(tbProductName);
                        stpInfo.Children.Add(tbNote);
                        Grid.SetRow(stpInfo, smallRowIndex);
                        Grid.SetColumn(stpInfo, 2);
                        dgDataTable.Children.Add(stpInfo);

                        smallRowIndex++;
                    }


                    bigRowIndex += chairInStatus.Value.Count;
                }


                // Seperate Line
                var separator = new Rectangle();
                separator.Stroke          = new SolidColorBrush(Colors.Black);
                separator.StrokeThickness = 3;
                separator.Height          = 3;
                separator.Width           = double.NaN;

                stpTableText.Children.Add(stpStatus);
                stpTableText.Children.Add(dgDataTable);
                stpTableText.Children.Add(separator);
            }


            blkTableText.Child = stpTableText;
        }
        public FrameworkContentElementSeekExample()
        {
            // Create a name scope for the page.
            NameScope.SetNameScope(this, new NameScope());

            this.Background = Brushes.White;

            BlockUIContainer controlsContainer = new BlockUIContainer();

            StackPanel myStackPanel = new StackPanel();

            myStackPanel.Margin = new Thickness(20);

            // Create a rectangle.
            myRectangle        = new Rectangle();
            myRectangle.Width  = 100;
            myRectangle.Height = 20;
            myRectangle.Margin = new Thickness(12, 0, 0, 5);
            myRectangle.Fill   = new SolidColorBrush(Color.FromArgb(170, 51, 51, 255));
            myRectangle.HorizontalAlignment = HorizontalAlignment.Left;
            myStackPanel.Children.Add(myRectangle);

            // Assign the rectangle a name by
            // registering it with the page, so that
            // it can be targeted by storyboard
            // animations.
            this.RegisterName("myRectangle", myRectangle);

            //
            // Create an animation and a storyboard to animate the
            // rectangle.
            //
            DoubleAnimation myDoubleAnimation =
                new DoubleAnimation(100, 500, new Duration(TimeSpan.FromSeconds(60)));

            Storyboard.SetTargetName(myDoubleAnimation, "myRectangle");
            Storyboard.SetTargetProperty(myDoubleAnimation, new PropertyPath(Rectangle.WidthProperty));
            myStoryboard = new Storyboard();
            myStoryboard.Children.Add(myDoubleAnimation);

            //
            // Create some buttons to control the storyboard
            // and a panel to contain them.
            //
            StackPanel buttonPanel = new StackPanel();
            Button     beginButton = new Button();

            beginButton.Content = "Begin";
            beginButton.Click  += new RoutedEventHandler(beginButton_Clicked);
            buttonPanel.Children.Add(beginButton);
            Button pauseButton = new Button();

            pauseButton.Content = "Pause";
            pauseButton.Click  += new RoutedEventHandler(pauseButton_Clicked);
            buttonPanel.Children.Add(pauseButton);
            Button resumeButton = new Button();

            resumeButton.Content = "Resume";
            resumeButton.Click  += new RoutedEventHandler(resumeButton_Clicked);
            buttonPanel.Children.Add(resumeButton);
            Button skipToFillButton = new Button();

            skipToFillButton.Content = "Skip to Fill";
            skipToFillButton.Click  += new RoutedEventHandler(skipToFillButton_Clicked);
            buttonPanel.Children.Add(skipToFillButton);
            Button setSpeedRatioButton = new Button();

            setSpeedRatioButton.Content = "Triple Speed";
            setSpeedRatioButton.Click  += new RoutedEventHandler(setSpeedRatioButton_Clicked);
            buttonPanel.Children.Add(setSpeedRatioButton);
            Button stopButton = new Button();

            stopButton.Content = "Stop";
            stopButton.Click  += new RoutedEventHandler(stopButton_Clicked);
            buttonPanel.Children.Add(stopButton);
            Button removeButton = new Button();

            removeButton.Content = "Remove";
            removeButton.Click  += new RoutedEventHandler(removeButton_Clicked);
            buttonPanel.Children.Add(removeButton);

            myStackPanel.Children.Add(buttonPanel);

            // Create some controls to display the
            // storyboard's current time and the
            // current width of the rectangle.
            StackPanel seekPanel = new StackPanel();

            seekPanel.Margin = new Thickness(10);
            StackPanel aPanel = new StackPanel();
            Label      aLabel = new Label();

            aPanel.Orientation = Orientation.Horizontal;
            aLabel.Content     = "Current Time: ";
            aPanel.Children.Add(aLabel);
            currentTimeIndicator = new TextBlock();
            aPanel.Children.Add(currentTimeIndicator);
            seekPanel.Children.Add(aPanel);

            aPanel             = new StackPanel();
            aPanel.Orientation = Orientation.Horizontal;
            aLabel             = new Label();
            aLabel.Content     = "Rectangle Width: ";
            aPanel.Children.Add(aLabel);
            rectangleWidthIndicator      = new TextBlock();
            rectangleWidthIndicator.Text = myRectangle.Width.ToString();
            aPanel.Children.Add(rectangleWidthIndicator);
            seekPanel.Children.Add(aPanel);


            // Create some controls to enable the
            // user to specify a seek position.

            aPanel             = new StackPanel();
            aPanel.Orientation = Orientation.Horizontal;
            aLabel             = new Label();
            aLabel.Content     = "Seek Offset: ";
            aPanel.Children.Add(aLabel);
            seekDestination      = new TextBox();
            seekDestination.Text = "0";
            aPanel.Children.Add(seekDestination);
            seekPanel.Children.Add(aPanel);


            Button seekButton = new Button();

            seekButton.Content = "Seek";
            seekButton.Click  += new RoutedEventHandler(seekButton_Clicked);
            seekPanel.Children.Add(seekButton);
            Button seekAlignedToLastTickButton = new Button();

            seekAlignedToLastTickButton.Content = "Seek Aligned to Last Tick";
            seekAlignedToLastTickButton.Click  += new RoutedEventHandler(seekAlignedToLastTickButton_Clicked);
            seekPanel.Children.Add(seekAlignedToLastTickButton);

            myStackPanel.Children.Add(seekPanel);

            controlsContainer.Child = myStackPanel;
            this.Blocks.Add(controlsContainer);

            myStoryboard.CurrentTimeInvalidated += new EventHandler(myStoryboard_CurrentTimeInvalidated);
        }
Example #16
0
        private static void FormatText(TextBlock ptb, TextBlock tb, BlockUIContainer buic, Tag tag)
        {
            switch (tag.TagName)
            {
            case "W":
                try
                {
                    if (!string.IsNullOrEmpty(tag.TagValue))
                    {
                        tb.Width = Convert.ToDouble(tag.TagValue);
                    }
                }
                catch { }
                break;

            case "L":
                try
                {
                    if (!string.IsNullOrEmpty(tag.TagValue))
                    {
                        tb.Margin = new System.Windows.Thickness(0)
                        {
                            Left = Convert.ToDouble(tag.TagValue)
                        }
                    }
                    ;
                }
                catch { }
                break;

            case "R":
                try
                {
                    if (!string.IsNullOrEmpty(tag.TagValue))
                    {
                        tb.Margin = new System.Windows.Thickness(0)
                        {
                            Right = Convert.ToDouble(tag.TagValue)
                        }
                    }
                    ;
                }
                catch { }
                break;

            case "F":
                try
                {
                    if (!string.IsNullOrEmpty(tag.TagValue))
                    {
                        tb.FontSize = Convert.ToDouble(tag.TagValue);
                    }
                }
                catch { }
                break;

            case "B":
                try
                {
                    tb.FontWeight = FontWeights.Bold;
                }
                catch { }
                break;
            }
        }
        /// <summary>
        /// Create a complete Receipt
        /// </summary>
        /// <returns></returns>
        public FlowDocument CreateReceiptDocument()
        {
            // Create a FlowDocument
            FlowDocument doc = new FlowDocument();

            // Set Margin
            doc.PagePadding = new Thickness(0);


            // Set PageHeight and PageWidth to "Auto".
            doc.PageHeight = Double.NaN;
            doc.PageWidth  = 290;

            // Create a Section
            Section sec = new Section();


            // Head Text
            BlockUIContainer blkHeadText = new BlockUIContainer();

            if (Owner != null)
            {
                Generate_HeadText(blkHeadText, Owner);
            }


            // Info Text
            BlockUIContainer blkInfoText = new BlockUIContainer();

            Generate_InfoText(blkInfoText, Order.getMetaReceiptInfo());

            // Table Text
            BlockUIContainer blkTableText = new BlockUIContainer()
            {
                Margin = new Thickness(0, 10, 0, 0)
            };

            Generate_TableText(blkTableText, Order.getMetaReceiptTable(), Order.GetOrderDetailsForReceipt());

            // Summary Text
            BlockUIContainer blkSummaryText = new BlockUIContainer()
            {
                Margin = new Thickness(0, 10, 0, 0)
            };

            Generate_SummaryText(blkSummaryText, Order, "vnd");


            // Food Text
            BlockUIContainer blkFootText = new BlockUIContainer()
            {
                Margin = new Thickness(0, 20, 0, 0)
            };

            Generate_FootText(blkFootText);

            //// Add Paragraph to Section
            //sec.Blocks.Add(p1);
            sec.Blocks.Add(blkHeadText);
            sec.Blocks.Add(blkInfoText);
            sec.Blocks.Add(blkTableText);
            sec.Blocks.Add(blkSummaryText);
            sec.Blocks.Add(blkFootText);

            // Add Section to FlowDocument
            doc.Blocks.Add(sec);


            return(doc);
        }
        public FrameworkContentElementControlStoryboardExample()
        {
            // Create a name scope for the document.
            NameScope.SetNameScope(this, new NameScope());
            this.Background = Brushes.White;

            // Create a run of text.
            Run theText = new Run(
                "Lorem ipsum dolor sit amet, consectetuer adipiscing elit." +
                "Ut non lacus. Nullam a ligula id leo adipiscing ornare." +
                " Duis mattis. ");

            // Create a TextEffect
            TextEffect animatedSpecialEffect = new TextEffect();

            animatedSpecialEffect.Foreground    = Brushes.OrangeRed;
            animatedSpecialEffect.PositionStart = 0;
            animatedSpecialEffect.PositionCount = 0;

            // Assign the TextEffect a name by
            // registering it with the page, so that
            // it can be targeted by storyboard
            // animations
            this.RegisterName("animatedSpecialEffect", animatedSpecialEffect);

            // Apply the text effect to the run.
            theText.TextEffects = new TextEffectCollection();
            theText.TextEffects.Add(animatedSpecialEffect);

            // Create a paragraph to contain the run.
            Paragraph animatedParagraph = new Paragraph(theText);

            animatedParagraph.Background = Brushes.LightGray;
            animatedParagraph.Padding    = new Thickness(20);

            this.Blocks.Add(animatedParagraph);
            BlockUIContainer controlsContainer = new BlockUIContainer();

            //
            // Create an animation and a storyboard to animate the
            // text effect.
            //
            Int32Animation countAnimation =
                new Int32Animation(0, 127, TimeSpan.FromSeconds(10));

            Storyboard.SetTargetName(countAnimation, "animatedSpecialEffect");
            Storyboard.SetTargetProperty(countAnimation,
                                         new PropertyPath(TextEffect.PositionCountProperty));
            myStoryboard = new Storyboard();
            myStoryboard.Children.Add(countAnimation);

            //
            // Create some buttons to control the storyboard
            // and a panel to contain them.
            //
            StackPanel buttonPanel = new StackPanel();

            buttonPanel.Orientation = Orientation.Vertical;
            Button beginButton = new Button();

            beginButton.Content = "Begin";
            beginButton.Click  += new RoutedEventHandler(beginButton_Clicked);
            buttonPanel.Children.Add(beginButton);
            Button pauseButton = new Button();

            pauseButton.Content = "Pause";
            pauseButton.Click  += new RoutedEventHandler(pauseButton_Clicked);
            buttonPanel.Children.Add(pauseButton);
            Button resumeButton = new Button();

            resumeButton.Content = "Resume";
            resumeButton.Click  += new RoutedEventHandler(resumeButton_Clicked);
            buttonPanel.Children.Add(resumeButton);
            Button skipToFillButton = new Button();

            skipToFillButton.Content = "Skip to Fill";
            skipToFillButton.Click  += new RoutedEventHandler(skipToFillButton_Clicked);
            buttonPanel.Children.Add(skipToFillButton);
            Button setSpeedRatioButton = new Button();

            setSpeedRatioButton.Content = "Triple Speed";
            setSpeedRatioButton.Click  += new RoutedEventHandler(setSpeedRatioButton_Clicked);
            buttonPanel.Children.Add(setSpeedRatioButton);
            Button stopButton = new Button();

            stopButton.Content = "Stop";
            stopButton.Click  += new RoutedEventHandler(stopButton_Clicked);
            buttonPanel.Children.Add(stopButton);
            Button removeButton = new Button();

            removeButton.Content = "Remove";
            removeButton.Click  += new RoutedEventHandler(removeButton_Clicked);
            buttonPanel.Children.Add(removeButton);

            controlsContainer.Child = buttonPanel;
            this.Blocks.Add(controlsContainer);
        }
Example #19
0
        /// <summary>
        /// Returns TextContentRange for the content of the paragraph.
        /// </summary>
        internal override TextContentRange GetTextContentRange()
        {
            BlockUIContainer elementOwner = (BlockUIContainer)Paragraph.Element;

            return(TextContainerHelper.GetTextContentRangeForTextElement(elementOwner));
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //First part
            Run runFirst = new Run
            {
                Text = "Hello world "
            };

            //Text with bold font
            Bold bold    = new Bold();
            Run  runBold = new Run
            {
                Text = "dynamicaly generated"
            };

            bold.Inlines.Add(runBold);

            // Second part
            Run runLast = new Run
            {
                Text = " document"
            };

            // Add to paragraph
            Paragraph paragraph = new Paragraph();

            paragraph.Inlines.Add(runFirst);
            paragraph.Inlines.Add(bold);
            paragraph.Inlines.Add(runLast);

            // Create doc and add paragraph


            FlowDocument document = new FlowDocument();

            document.Blocks.Add(paragraph);

            Paragraph p = new Paragraph(new Run("Hello, world!"))
            {
                FontSize = 36
            };

            document.Blocks.Add(p);


            p = new Paragraph(new Run("The ultimate programming greeting!"))
            {
                FontSize      = 14,
                FontStyle     = FontStyles.Italic,
                TextAlignment = TextAlignment.Left,
                Foreground    = Brushes.Gray
            };
            document.Blocks.Add(p);

            OldDocument = docViewer.Document;
            // View doc


            BlockUIContainer block = new BlockUIContainer();
            Button           btn   = new Button
            {
                Name    = "myButton",
                Content = "Restore old Document"
            };

            btn.Click  += Button_ReturnOld;
            block.Child = btn;
            document.Blocks.Add(block);

            docViewer.Document = document;
        }
Example #21
0
        public static FlowDocument Render(Term term, DictionaryEngine engine, bool minimal = false)
        {
            FlowDocument doc = new FlowDocument();

            Paragraph headword = ParseLinks(term.Traditional);

            headword.Style = (Style)rd["HeadwordStyle"];

            if (!minimal && term.Traditional.Length == 1 && StrokeDisplay.hasStrokeFile(term.Traditional[0]))
            {
                var strokeOrderButton = new Button();
                strokeOrderButton.Content  = "Stroke Order";
                strokeOrderButton.Margin   = new Thickness(25, 5, 5, 1);
                strokeOrderButton.Padding  = new Thickness(4);
                strokeOrderButton.FontSize = 12;
                strokeOrderButton.Click   += ((obj, e) => { new StrokeDisplay(term.Traditional[0]).Show(); });
                headword.Inlines.Add(new InlineUIContainer(strokeOrderButton));
            }

            doc.Blocks.Add(headword);

            Paragraph pinyin = new Paragraph(new Run(term.Pinyin));

            pinyin.Style = (Style)rd["PinyinStyle"];
            doc.Blocks.Add(pinyin);


            if (term.CedictEntryId != 0)
            {
                doc.Blocks.Add(new BlockUIContainer(new Separator()
                {
                    Margin = new Thickness(-3, 3, -3, 3)
                }));

                var       entry   = ((Cedict)engine["cedict"]).LookupEntry(term.CedictEntryId).Result;
                Paragraph heading = new Paragraph(new Run("CC"));
                heading.Style = (Style)rd["HeadingStyle"];
                doc.Blocks.Add(heading);

                List list = new List();
                list.MarkerStyle = TextMarkerStyle.Decimal;

                foreach (CedictDefinition d in entry.Definitions)
                {
                    ListItem listItem = new ListItem(new Paragraph(new Run(d.Definition))
                    {
                        Style = (Style)rd["EnglishParagraph"]
                    });
                    list.ListItems.Add(listItem);
                }
                doc.Blocks.Add(list);
                if (list.ListItems.Count == 1)
                {
                    list.MarkerStyle = TextMarkerStyle.None;
                    list.Padding     = new Thickness(0, 0, 0, 0);
                }
                else
                {
                    list.MarkerStyle = TextMarkerStyle.Decimal;
                }
            }


            if (term.MoedictHeteronymId != 0)
            {
                doc.Blocks.Add(new BlockUIContainer(new Separator()
                {
                    Margin = new Thickness(-3, 3, -3, 3)
                }));

                var       heteronym = ((Moedict)engine["moedict"]).LookupHeteronym(term.MoedictHeteronymId).Result;
                Paragraph heading   = new Paragraph(new Run("MOE"));
                heading.Style = (Style)rd["HeadingStyle"];
                doc.Blocks.Add(heading);
                Paragraph type;
                string    currentType = heteronym.Definitions[0].Type;
                if (currentType != null)
                {
                    type = ParseLinks(currentType, "TypeStyle", true);
                    var uic = new BlockUIContainer()
                    {
                    };
                    uic.Child = new Border()
                    {
                        BorderThickness = new Thickness(1), BorderBrush = System.Windows.Media.Brushes.Gray, Padding = new Thickness(2, 2, 2, 0), CornerRadius = new CornerRadius(2), HorizontalAlignment = HorizontalAlignment.Left
                    };
                    ((Border)uic.Child).Child = new TextBlock(type.Inlines.FirstInline)
                    {
                        HorizontalAlignment = HorizontalAlignment.Left, Margin = new Thickness(0), Foreground = System.Windows.Media.Brushes.Gray
                    };
                    doc.Blocks.Add(uic);
                }

                List list = new List();
                list.MarkerStyle = TextMarkerStyle.Decimal;

                foreach (MoedictDefinition d in heteronym.Definitions)
                {
                    string newType = d.Type;
                    if (currentType != null && !currentType.Equals(newType))
                    {
                        if (list.ListItems.Count == 1)
                        {
                            list.MarkerStyle = TextMarkerStyle.None;
                            list.Padding     = new Thickness(0, 0, 0, 0);
                        }
                        else
                        {
                            list.MarkerStyle = TextMarkerStyle.Decimal;
                        }
                        doc.Blocks.Add(list);
                        doc.Blocks.Add(new BlockUIContainer(new Separator()
                        {
                            Margin = new Thickness(10, 6, 10, 6)
                        }));
                        list        = new List();
                        currentType = newType;
                        type        = ParseLinks(currentType, "TypeStyle", true);
                        var uic = new BlockUIContainer()
                        {
                        };
                        uic.Child = new Border()
                        {
                            BorderThickness = new Thickness(1), BorderBrush = System.Windows.Media.Brushes.Gray, Padding = new Thickness(2, 2, 2, 0), CornerRadius = new CornerRadius(2), HorizontalAlignment = HorizontalAlignment.Left
                        };
                        ((Border)uic.Child).Child = new TextBlock(type.Inlines.FirstInline)
                        {
                            HorizontalAlignment = HorizontalAlignment.Left, Margin = new Thickness(0), Foreground = System.Windows.Media.Brushes.Gray
                        };
                        doc.Blocks.Add(uic);
                    }

                    ListItem listItem = new ListItem(ParseLinks(d.Definition));
                    if (d.Examples != null)
                    {
                        foreach (var e in d.Examples)
                        {
                            listItem.Blocks.Add(ParseLinks(e.Example, "ExampleStyle"));
                        }
                    }
                    if (d.Quotes != null)
                    {
                        foreach (var q in d.Quotes)
                        {
                            listItem.Blocks.Add(ParseLinks(q.Quote, "QuoteStyle"));
                        }
                    }
                    list.ListItems.Add(listItem);
                }
                doc.Blocks.Add(list);
                if (list.ListItems.Count == 1)
                {
                    list.MarkerStyle = TextMarkerStyle.None;
                    list.Padding     = new Thickness(0, 0, 0, 0);
                }
                else
                {
                    list.MarkerStyle = TextMarkerStyle.Decimal;
                }
                //list.MarkerStyle = list.ListItems.Count > 1 ? TextMarkerStyle.Decimal : TextMarkerStyle.None;
            }

            //doc.FontSize = 24;

            //foreach (Moedict.Heteronym h in entry.Heteronyms)
            //{
            //    Paragraph headword = ParseLinks(entry.Title);
            //    headword.Style = (Style)rd["HeadwordStyle"];
            //    doc.Blocks.Add(headword);
            //    Paragraph pinyin = new Paragraph(new Run(h.Pinyin));
            //    pinyin.Style = (Style)rd["PinyinStyle"];
            //    doc.Blocks.Add(pinyin);

            //    Paragraph type;
            //    string currentType = h.Definitions[0].Type;
            //    if (currentType != null)
            //    {
            //        type = ParseLinks(currentType, "TypeStyle");
            //        doc.Blocks.Add(type);
            //    }

            //    List list = new List();
            //    list.MarkerStyle = TextMarkerStyle.Decimal;

            //    foreach (Moedict.Definition d in h.Definitions)
            //    {
            //        string newType = d.Type;
            //        if (currentType != null && !currentType.Equals(newType))
            //        {
            //            doc.Blocks.Add(list);
            //            list = new List();
            //            currentType = newType;
            //            type = ParseLinks(currentType, "TypeStyle");
            //            doc.Blocks.Add(type);
            //        }

            //        ListItem listItem = new ListItem(ParseLinks(d.Gloss));
            //        if (d.Examples != null)
            //        {
            //            foreach (string e in d.Examples)
            //            {
            //                listItem.Blocks.Add(ParseLinks(e, "ExampleStyle"));
            //            }
            //        }
            //        if (d.Quotes != null)
            //        {
            //            foreach (string q in d.Quotes)
            //            {
            //                listItem.Blocks.Add(ParseLinks(q, "QuoteStyle"));
            //            }
            //        }

            //        list.ListItems.Add(listItem);
            //    }
            //    doc.Blocks.Add(list);
            //    list.MarkerStyle = list.ListItems.Count > 1 ? TextMarkerStyle.Decimal : TextMarkerStyle.None;
            //}

            return(doc);
        }
        public StockPrintFlowDocument(IList <Product> products)
        {
            InitializeComponent();
            this.PagePadding = new Thickness(50);

            foreach (var product in products)
            {
                Floater   floater = new Floater();
                Paragraph item    = new Paragraph(floater);
                item.KeepTogether = true;
                item.LineHeight   = 4;

                Table         table    = new Table();
                TableRowGroup rowGroup = new TableRowGroup();

                var title = new Paragraph(new Run(product.Name));
                title.FontWeight = FontWeights.Bold;
                var cell1 = new TableCell(title);

                var conseignmentsTitle = new Paragraph(new Run("Lieferungen:"));
                conseignmentsTitle.FontWeight = FontWeights.Bold;
                var cell2 = new TableCell(conseignmentsTitle);

                var row1 = new TableRow();
                row1.Cells.Add(cell1);
                row1.Cells.Add(cell2);
                rowGroup.Rows.Add(row1);

                var price = new Paragraph();
                if (!product.HasConsignmentPrice)
                {
                    price = new Paragraph(new Run(string.Format("Aktueller Preis: {0:0.00} CHF", product.Price)));
                }

                Barcode barcode = new Barcode();
                barcode.Data   = product.Barcode;
                barcode.Height = 90;
                barcode.Width  = 200;
                barcode.HorizontalAlignment = HorizontalAlignment.Left;
                var barcodeUiContainer = new BlockUIContainer(barcode);
                var barcodeSection     = new Section(barcodeUiContainer);

                var cell3 = new TableCell();
                cell3.Blocks.Add(price);
                cell3.Blocks.Add(barcodeSection);


                //Lieferungen
                var tableConsignments         = new Table();
                var tableRowGroupConsingments = new TableRowGroup();

                var tableRowHeader = new TableRow();
                tableRowHeader.Cells.Add(new TableCell(new Paragraph(new Run("Anzahl"))));
                tableRowHeader.Cells.Add(new TableCell((product.HasExpirationDate) ? new Paragraph(new Run("Ablaufdatum")) : new Paragraph()));
                tableRowHeader.Cells.Add(new TableCell((product.HasConsignmentPrice) ? new Paragraph(new Run("Preis"))
                {
                    TextAlignment = System.Windows.TextAlignment.Right
                } : new Paragraph()));

                tableRowGroupConsingments.Rows.Add(tableRowHeader);

                foreach (var consingment in product.Consignments)
                {
                    var tableRowItem = new TableRow();
                    tableRowItem.Cells.Add(new TableCell(new Paragraph(new Run(consingment.NumberOfContent.ToString()))));
                    tableRowItem.Cells.Add(new TableCell((product.HasExpirationDate) ? new Paragraph(new Run(consingment.ExpirationDateString)) : new Paragraph()));
                    tableRowItem.Cells.Add(new TableCell((product.HasConsignmentPrice) ? new Paragraph(new Run(string.Format("{0:0.00} CHF", consingment.Price)))
                    {
                        TextAlignment = System.Windows.TextAlignment.Right
                    } : new Paragraph()));

                    tableRowGroupConsingments.Rows.Add(tableRowItem);
                }

                var tableRowSeparator = new TableRow();
                tableRowSeparator.Cells.Add(new TableCell(new BlockUIContainer(new Separator()
                {
                    HorizontalAlignment = HorizontalAlignment.Stretch
                }))
                {
                    ColumnSpan = 3
                });
                tableRowGroupConsingments.Rows.Add(tableRowSeparator);

                var tableRowLast = new TableRow();
                tableRowLast.Cells.Add(new TableCell(new Paragraph(new Run(product.Stock.ToString())
                {
                    FontWeight = FontWeights.Bold
                })));
                tableRowLast.Cells.Add(new TableCell(new Paragraph()));
                tableRowLast.Cells.Add(new TableCell(new Paragraph(new Run(string.Format("{0:0.00} CHF", product.TotalPrice))
                {
                    FontWeight = FontWeights.Bold
                })
                {
                    TextAlignment = System.Windows.TextAlignment.Right
                }));
                tableRowGroupConsingments.Rows.Add(tableRowLast);

                tableConsignments.RowGroups.Add(tableRowGroupConsingments);

                var cell4 = new TableCell(tableConsignments);

                var row2 = new TableRow();
                row2.Cells.Add(cell3);
                row2.Cells.Add(cell4);
                rowGroup.Rows.Add(row2);

                table.RowGroups.Add(rowGroup);
                floater.Blocks.Add(table);
                floater.Blocks.Add(new BlockUIContainer(new Separator()
                {
                    HorizontalAlignment = HorizontalAlignment.Stretch
                }));

                ListSection.Blocks.Add(item);
            }
        }
Example #23
0
        private FlowDocument SimpleFlowExample()
        {
            // Add some Bold text to the paragraph
            Paragraph myParagraph = new Paragraph();



            myParagraph.FontSize   = 12;
            myParagraph.FontFamily = new FontFamily("Arial");
            myParagraph.Inlines.Add(new Bold(new Run("\t\tHimayath Nagar" + "\r\n\b")));
            myParagraph.Inlines.Add(new Run("Order ID : " + lblOrderID.Content.ToString() + "\r\n"));
            myParagraph.Inlines.Add(new Bold(new Run(lblCustName.Content.ToString() + "\r\n")));
            myParagraph.Inlines.Add(new Run("Phone : " + lblCustPhone.Content.ToString() + "  " + lblAddress.Content.ToString() + "\r\n"));
            myParagraph.Inlines.Add(new Run("Items " + lblItems.Content.ToString() + "  Total Amount : Rs." + lblGrandTotal.Content.ToString() + "\r\n"));

            // Create a FlowDocument and add the paragraph to it.
            FlowDocument myFlowDocument = new FlowDocument();

            myFlowDocument.Blocks.Add(myParagraph);

            Line pLine = new Line();

            pLine.Stretch         = Stretch.Fill;
            pLine.Stroke          = Brushes.Black;
            pLine.X2              = 1;
            pLine.StrokeThickness = 1;
            myParagraph.Inlines.Add(pLine);
            // Add some plain text to the paragraph

            // Create a List and populate with three list items.

            //   myParagraph.Inlines.Add(new Run(" Customer Name : " + lblCustName.Content.ToString()));
            myParagraph.Inlines.Add(new Run("Code".PadLeft(2) + string.Format("{0}", "\t") + "Dish".PadLeft(5) + string.Format("{0}", "\t") + string.Format("{0}", "\t") + "Qty".PadLeft(5) + string.Format("{0}", "\t") + "Price".PadLeft(5) + string.Format("{0}", "\t") + "Total".PadLeft(5) + "\r\n"));
            // myParagraph.Inlines.Add(pLine);
            int ordercount = lvOrders.Items.Count;

            for (int i = 0; i < ordercount; i++)
            {
                TableRow  tblRow   = new TableRow();
                TableCell tblCell1 = new TableCell();
                TableCell tblCell2 = new TableCell();
                //     myParagraph.Inlines.Add(new Run("Cell ID1" + i + "\r\n"));

                tblRow.Cells.Add(tblCell1);
                tblRow.Cells.Add(tblCell2);
                string pname;
                //if (dSet.Rows[i]["ProductName"].ToString().Length > 10) { pname = dSet.Rows[i]["ProductName"].ToString().Substring(0, 10).Trim();
                //pname  = $"{pname,10}";
                //}
                //else pname = dSet.Rows[i]["ProductName"].ToString();//.Substring(0, 5).Trim();
                pname = dSet.Rows[i]["ProductName"].ToString();
                if (pname.Length > 10)
                {
                    pname = pname.Substring(0, 10).PadRight(20);
                }
                else
                {
                    int pLen = pname.Length;
                    pname = pname.PadRight(20 - pLen);
                }
                string Pid   = dSet.Rows[i]["ProductId"].ToString();
                string qty   = dSet.Rows[i]["Quantity"].ToString();
                string Price = dSet.Rows[i]["Price"].ToString();
                string Total = dSet.Rows[i]["Total"].ToString();


                myParagraph.Inlines.Add(new Run(Pid.PadLeft(2) + (pname.PadLeft(2)) + string.Format("{0}", "\t") + qty.PadLeft(2) + string.Format("{0}", "\t") + Price.PadLeft(2) + string.Format("{0}", "\t") + Total.PadLeft(2) + "\r\n"));

                //  myFlowDocument.Blocks.Add(myParagraph + "\n");
            }
            //  myParagraph.Inlines.Add(pLine);
            myFlowDocument.ColumnWidth = 999999;


            //  myParagraph.Inlines.Add(image);


            BlockUIContainer uiCont = new BlockUIContainer();

            Label myButton = new Label
            {
                Width  = 200,
                Height = 100,
                HorizontalAlignment = HorizontalAlignment.Left,
                Background          = new SolidColorBrush(Colors.White),
                Content             = new Image
                {
                    Source            = new BitmapImage(new Uri(@"C:\Users\venkat\Documents\Visual Studio 2015\Projects\Project3\AnkapurProject\Anakapur\Images\AC.jpg", UriKind.Relative)),
                    VerticalAlignment = VerticalAlignment.Center
                }
            };

            //  b.Content = "Click me";
            uiCont.Child = (myButton);
            myFlowDocument.Blocks.Add(uiCont);
            myFlowDocument.Blocks.Add(myParagraph);
            // myFlowDocument.Blocks.Add(myList);



            // Add the FlowDocument to a FlowDocumentReader Control
            FlowDocumentReader myFlowDocumentReader = new FlowDocumentReader();

            myFlowDocumentReader.Document = myFlowDocument;
            //FlowDocument fp = new FlowDocument();

            this.Content = myFlowDocumentReader;

            return(myFlowDocument);
        }
        /// <summary>
        /// Create the Head section of Receipt
        /// </summary>
        /// <param name="blkHeadText"></param>
        private void Generate_HeadText(BlockUIContainer blkHeadText, Owner owner)
        {
            // Main stackPanel of Head Text
            StackPanel stpHeadText = new StackPanel()
            {
                Orientation = Orientation.Vertical
            };

            StackPanel  stpLogo  = new StackPanel();
            Image       imgOwner = new Image();
            BitmapImage bimg     = new BitmapImage();

            bimg.BeginInit();
            bimg.UriSource = new Uri(startupProjectPath + "\\Images\\" + owner.ImgName, UriKind.Absolute);
            bimg.EndInit();
            imgOwner.Source = bimg;
            imgOwner.HorizontalAlignment = HorizontalAlignment.Center;
            imgOwner.Margin = new Thickness(85, 0, 0, 0);
            stpLogo.Children.Add(imgOwner);



            string address = "";

            // modify the long address
            if (owner.Address.Length > 54)
            {
                string address1st = owner.Address.Substring(0, 53);
                string address2nd = owner.Address.Substring(53);
                address = address1st + "\n\t" + address2nd;
            }
            else
            {
                address = owner.Address;
            }



            TextBlock txtAddress = new TextBlock()
            {
                Text       = "ADDRESS:  " + address,
                FontFamily = new FontFamily("Century Gothic"),
                FontSize   = 10,
                FontWeight = FontWeights.UltraBold,
            };
            TextBlock txtPhone = new TextBlock()
            {
                Text       = "PHONE:  " + owner.Phone,
                FontFamily = new FontFamily("Century Gothic"),
                FontSize   = 10,
                Margin     = new Thickness(0, 0, 0, 5),
                FontWeight = FontWeights.UltraBold,
            };
            StackPanel stpPageName = new StackPanel();
            TextBlock  txtPageName = new TextBlock()
            {
                Text                = owner.PageName,
                FontSize            = 13,
                FontFamily          = new FontFamily("Century Gothic"),
                FontWeight          = FontWeights.UltraBold,
                HorizontalAlignment = HorizontalAlignment.Center,
                Margin              = new Thickness(0, 0, 0, 10)
            };

            stpPageName.Children.Add(txtPageName);


            stpHeadText.Children.Add(stpLogo);
            //stpHeadText.Children.Add(txtOwnerName);
            stpHeadText.Children.Add(txtAddress);
            stpHeadText.Children.Add(txtPhone);
            stpHeadText.Children.Add(stpPageName);

            blkHeadText.Child = stpHeadText;
        }
Example #25
0
        public List <Block> RunFullSchema(UserInputItem userInput, string[] installations)
        {
            List <Block> elementList = new List <Block>();

            // Insert the page header
            Paragraph pageHeaderText = new Paragraph(new Run("REPORT FOR ENGINEER: " + userInput.Engineer));

            pageHeaderText.FontSize   = 35;
            pageHeaderText.FontWeight = FontWeights.Bold;
            pageHeaderText.FontFamily = new System.Windows.Media.FontFamily("Verdana");

            elementList.Add(pageHeaderText);

            // Insert Installation Block
            //  * Installation Title
            //  * Data Section
            //  * Notes Section

            foreach (string installation in installations)
            {
                InstallationDataItem[] dataItems = DataBase.BuildInstallationData(installation, userInput.Engineer).ToArray();
                InstallationNote[]     noteItems = DataBase.BuildInstallationNotes(installation).ToArray();

                InstallationPrintable installationPrintable = new InstallationPrintable(installation, dataItems, noteItems);

                elementList.Add(installationPrintable.GetSection());
            }

            // Add images to our elementList
            foreach (string installation in installations)
            {
                ObservableCollection <InstallationDataItem> imageDataItems = DataBase.BuildInstallationData(installation, userInput.Engineer);

                // List filed with FileInfo types
                ArrayList installationImages = DocumentStore.ObtainInstallationImages(installation, userInput.Program, userInput.Truck, imageDataItems);

                if (installationImages.ToArray().Length > 0)
                {
                    foreach (FileInfo fileInfo in installationImages)
                    {
                        // Rotating our image in place
                        RotateTransform transform = new RotateTransform(90);


                        // Create the image file

                        Image installationImage = new Image();

                        BitmapImage       bitmap  = new BitmapImage();
                        TransformedBitmap tbitmap = new TransformedBitmap();


                        bitmap.BeginInit();
                        bitmap.UriSource = new Uri(fileInfo.FullName);
                        bitmap.EndInit();

                        tbitmap.BeginInit();
                        tbitmap.Source    = bitmap;
                        tbitmap.Transform = transform;
                        tbitmap.EndInit();

                        installationImage.Source = tbitmap;

                        // Applying transforms
                        //transform.CenterX = installationImage.ActualWidth / 2;
                        //transform.CenterY = installationImage.ActualHeight / 2;


                        BlockUIContainer uiContainer = new BlockUIContainer();
                        uiContainer.BreakPageBefore = true;
                        uiContainer.Child           = installationImage;

                        elementList.Add(uiContainer);
                    }
                }
            }

            return(elementList);
        }
Example #26
0
        public static Block GameMessageToBlock(IGameMessage m)
        {
            if (m == null)
            {
                return(null);
            }

            if (m is PlayerEventMessage)
            {
                if (m.IsMuted)
                {
                    return(null);
                }
                var b    = new GameMessageBlock(m);
                var p    = new Paragraph();
                var prun = new Run(m.From + " ");
                prun.Foreground = m.From.Color.CacheToBrush();
                prun.FontWeight = FontWeights.Bold;
                p.Inlines.Add(prun);

                var chatRun = MergeArgsv2(m.Message, m.Arguments);
                chatRun.Foreground = new SolidColorBrush(m.From.Color);
                //chatRun.FontWeight = FontWeights.Bold;
                p.Inlines.Add(chatRun);

                b.Blocks.Add(p);

                return(b);
            }
            else if (m is ChatMessage)
            {
                if (m.IsMuted)
                {
                    return(null);
                }

                var p = new Paragraph();
                var b = new GameMessageBlock(m);

                var inline = new Span();

                inline.Foreground = m.From.Color.CacheToBrush();
                var chatRun = new Run("<" + m.From + "> ");
                chatRun.Foreground = m.From.Color.CacheToBrush();
                chatRun.FontWeight = FontWeights.Bold;
                inline.Inlines.Add(chatRun);

                inline.Inlines.Add(MergeArgsv2(m.Message, m.Arguments));

                p.Inlines.Add(inline);

                b.Blocks.Add(p);

                return(b);
            }
            else if (m is WarningMessage)
            {
                if (m.IsMuted)
                {
                    return(null);
                }

                var b      = new GameMessageBlock(m);
                var block  = new BlockUIContainer();
                var border = new Border()
                {
                    CornerRadius    = new CornerRadius(4),
                    BorderBrush     = Brushes.Gray,
                    BorderThickness = new Thickness(1),
                    Padding         = new Thickness(5),
                    Background      = Brushes.LightGray,
                };
                var tb = new TextBlock(MergeArgsv2(m.Message, m.Arguments));
                tb.Foreground   = m.From.Color.CacheToBrush();
                tb.TextWrapping = TextWrapping.Wrap;

                border.Child = tb;
                block.Child  = border;

                b.Blocks.Add(block);

                return(b);
            }
            else if (m is SystemMessage)
            {
                if (m.IsMuted)
                {
                    return(null);
                }

                var p       = new Paragraph();
                var b       = new GameMessageBlock(m);
                var chatRun = MergeArgsv2(m.Message, m.Arguments);
                chatRun.Foreground = m.From.Color.CacheToBrush();
                p.Inlines.Add(chatRun);
                b.Blocks.Add(p);
                return(b);
            }
            else if (m is NotifyMessage)
            {
                if (m.IsMuted)
                {
                    return(null);
                }

                var p       = new Paragraph();
                var b       = new GameMessageBlock(m);
                var chatRun = MergeArgsv2(m.Message, m.Arguments);
                chatRun.Foreground = m.From.Color.CacheToBrush();
                b.Blocks.Add(p);
                p.Inlines.Add(chatRun);
                return(b);
            }
            else if (m is TurnMessage)
            {
                if (m.IsMuted)
                {
                    return(null);
                }

                var brush = m.From.Color.CacheToBrush();

                var p = new Paragraph();
                var b = new GameMessageBlock(m);
                b.TextAlignment = TextAlignment.Center;
                b.Margin        = new Thickness(2);

                p.Inlines.Add(
                    new Line
                {
                    X1 = 0,
                    X2 = 40,
                    Y1 = -4,
                    Y2 = -4,
                    StrokeThickness = 2,
                    Stroke          = brush
                });

                var chatRun = new Run(string.Format(m.Message, m.Arguments));
                chatRun.Foreground = brush;
                chatRun.FontWeight = FontWeights.Bold;
                p.Inlines.Add(chatRun);

                var prun = new Run(" " + (m as TurnMessage).TurnPlayer + " ");
                prun.Foreground = (m as TurnMessage).TurnPlayer.Color.CacheToBrush();
                prun.FontWeight = FontWeights.Bold;
                p.Inlines.Add(prun);

                p.Inlines.Add(
                    new Line
                {
                    X1 = 0,
                    X2 = 40,
                    Y1 = -4,
                    Y2 = -4,
                    StrokeThickness = 2,
                    Stroke          = brush
                });

                b.Blocks.Add(p);

                //if (((Paragraph)output.Document.Blocks.LastBlock).Inlines.Count == 0)
                //    output.Document.Blocks.Remove(output.Document.Blocks.LastBlock);

                return(b);

                //output.Document.Blocks.Add(new Paragraph { Margin = new Thickness() });
            }
            else if (m is DebugMessage)
            {
                if (m.IsMuted)
                {
                    return(null);
                }
                var p       = new Paragraph();
                var b       = new GameMessageBlock(m);
                var chatRun = MergeArgsv2(m.Message, m.Arguments);
                chatRun.Foreground = m.From.Color.CacheToBrush();
                p.Inlines.Add(chatRun);
                b.Blocks.Add(p);
                return(b);
            }
            else if (m is NotifyBarMessage)
            {
                if (m.IsMuted)
                {
                    return(null);
                }
                var p       = new Paragraph();
                var b       = new GameMessageBlock(m);
                var chatRun = MergeArgsv2(m.Message, m.Arguments);
                chatRun.Foreground = (m as NotifyBarMessage).MessageColor.CacheToBrush();
                p.Inlines.Add(chatRun);
                b.Blocks.Add(p);
                return(b);
            }
            return(null);
        }
        /// <summary>
        /// Create the summary section of Receipt
        /// </summary>
        /// <param name="blkTableText"></param>
        /// <param name="order">the order data for filling the receip</param>
        /// <param name="moneyUnit"></param>
        private void Generate_SummaryText(BlockUIContainer blkSummaryText, OrderForPrint order, string moneyUnit)
        {
            StackPanel stpSummary = new StackPanel()
            {
                Orientation = Orientation.Vertical
            };


            // Sale Value
            StackPanel stpSaleValue = new StackPanel()
            {
                Orientation = Orientation.Horizontal
            };
            TextBlock tbSaleValueLable = new TextBlock()
            {
                Text       = "Sale Value:",
                FontFamily = new FontFamily("Century Gothic"),
                FontSize   = 12,
                FontWeight = FontWeights.UltraBold,
                Margin     = new Thickness(90, 0, 0, 0),
                Width      = 120
            };
            TextBlock tbSaleValueValue = new TextBlock()
            {
                Text          = String.Format("{0:0.000}", order.SaleValue),
                FontFamily    = new FontFamily("Century Gothic"),
                FontSize      = 11,
                Width         = 60,
                TextAlignment = TextAlignment.Right
            };

            stpSaleValue.Children.Add(tbSaleValueLable);
            stpSaleValue.Children.Add(tbSaleValueValue);


            // Service Charge
            StackPanel stpSVC = new StackPanel()
            {
                Orientation = Orientation.Horizontal
            };
            TextBlock tbSVCLable = new TextBlock()
            {
                Text       = "SVC (5%):",
                FontFamily = new FontFamily("Century Gothic"),
                FontSize   = 12,
                FontWeight = FontWeights.UltraBold,
                Margin     = new Thickness(90, 0, 0, 0),
                Width      = 120
            };
            TextBlock tbSVCValue = new TextBlock()
            {
                Text          = String.Format("{0:0.000}", order.Svc),
                FontFamily    = new FontFamily("Century Gothic"),
                FontSize      = 11,
                Width         = 60,
                TextAlignment = TextAlignment.Right
            };

            stpSVC.Children.Add(tbSVCLable);
            stpSVC.Children.Add(tbSVCValue);


            // VAT
            StackPanel stpVAT = new StackPanel()
            {
                Orientation = Orientation.Horizontal
            };
            TextBlock tbVATLable = new TextBlock()
            {
                Text       = "VAT (10%):",
                FontFamily = new FontFamily("Century Gothic"),
                FontSize   = 12,
                FontWeight = FontWeights.UltraBold,
                Margin     = new Thickness(90, 0, 0, 0),
                Width      = 120
            };
            TextBlock tbVATValue = new TextBlock()
            {
                Text          = String.Format("{0:0.000}", order.Vat),
                FontFamily    = new FontFamily("Century Gothic"),
                FontSize      = 11,
                Width         = 60,
                TextAlignment = TextAlignment.Right
            };

            stpVAT.Children.Add(tbVATLable);
            stpVAT.Children.Add(tbVATValue);



            // Total Price
            StackPanel stpTotalPrice = new StackPanel()
            {
                Orientation = Orientation.Horizontal
            };
            TextBlock tbTotalPriceLable = new TextBlock()
            {
                Text       = "Total Amount " + "(" + moneyUnit + "):",
                FontFamily = new FontFamily("Century Gothic"),
                FontSize   = 12,
                FontWeight = FontWeights.UltraBold,
                Margin     = new Thickness(90, 0, 0, 0),
                Width      = 120
            };
            TextBlock tbTotalPriceValue = new TextBlock()
            {
                Text          = String.Format("{0:0.000}", order.TotalPrice),
                FontFamily    = new FontFamily("Century Gothic"),
                FontSize      = 11,
                Width         = 60,
                TextAlignment = TextAlignment.Right
            };

            stpTotalPrice.Children.Add(tbTotalPriceLable);
            stpTotalPrice.Children.Add(tbTotalPriceValue);

            // Customer Pay
            StackPanel stpCustomerPay = new StackPanel()
            {
                Orientation = Orientation.Horizontal
            };
            TextBlock tbCustomerPayLable = new TextBlock()
            {
                Text       = "Customer Pay:",
                FontFamily = new FontFamily("Century Gothic"),
                FontSize   = 12,
                FontWeight = FontWeights.UltraBold,
                Margin     = new Thickness(90, 0, 0, 0),
                Width      = 120
            };
            TextBlock tbCustomerPayValue = new TextBlock()
            {
                Text          = String.Format("{0:0.000}", order.CustomerPay),
                FontFamily    = new FontFamily("Century Gothic"),
                FontSize      = 11,
                Width         = 60,
                TextAlignment = TextAlignment.Right
            };

            stpCustomerPay.Children.Add(tbCustomerPayLable);
            stpCustomerPay.Children.Add(tbCustomerPayValue);

            // Pay Back
            StackPanel stpPayBack = new StackPanel()
            {
                Orientation = Orientation.Horizontal
            };
            TextBlock tbPayBackLable = new TextBlock()
            {
                Text       = "Change:",
                FontFamily = new FontFamily("Century Gothic"),
                FontSize   = 12,
                FontWeight = FontWeights.UltraBold,
                Margin     = new Thickness(90, 0, 0, 0),
                Width      = 120
            };
            TextBlock tbPayBackValue = new TextBlock()
            {
                Text          = String.Format("{0:0.000}", order.PayBack),
                FontFamily    = new FontFamily("Century Gothic"),
                FontSize      = 11,
                Width         = 60,
                TextAlignment = TextAlignment.Right
            };

            stpPayBack.Children.Add(tbPayBackLable);
            stpPayBack.Children.Add(tbPayBackValue);


            stpSummary.Children.Add(stpSaleValue);
            stpSummary.Children.Add(stpSVC);
            stpSummary.Children.Add(stpVAT);
            stpSummary.Children.Add(stpTotalPrice);
            stpSummary.Children.Add(stpCustomerPay);
            stpSummary.Children.Add(stpPayBack);


            blkSummaryText.Child = stpSummary;
        }
Example #28
0
        private static bool TagFormat(Paragraph block, Tag tag, IEnumerable <Tag> tags)
        {
            var result = false;

            switch (tag.TagName)
            {
            case "BR":
                if (!string.IsNullOrEmpty(tag.TagValue))
                {
                    block.Margin = new System.Windows.Thickness(0, Convert.ToDouble(tag.TagValue), 0, 0);
                }
                break;

            case "BMP":
                if (!string.IsNullOrEmpty(tag.TagValue))
                {
                    Figure figure = new Figure();
                    figure.Margin = new Thickness(0);
                    var bitmap = new BitmapImage(new Uri(tag.TagValue, UriKind.RelativeOrAbsolute));
                    var image  = new Image {
                        Source = bitmap, Stretch = Stretch.Fill
                    };

                    BlockUIContainer imgBlock = new BlockUIContainer(image);
                    if (tag.SettingTags != null && tag.SettingTags.Count > 0)
                    {
                        foreach (var imgSetting in tag.SettingTags)
                        {
                            FormatImg(image, imgBlock, imgSetting);
                        }
                    }
                    figure.Blocks.Add(imgBlock);
                    block.Inlines.Add(figure);
                    result = true;
                }
                break;

            case "T":
                if (!string.IsNullOrEmpty(tag.TagValue))
                {
                    Figure    figure = new Figure();
                    TextBlock tb     = new TextBlock();
                    figure.Margin = new Thickness(0);

                    BlockUIContainer tBlock = new BlockUIContainer(tb);
                    tBlock.Margin = new Thickness(0);

                    foreach (var tempTag in tags)
                    {
                        var ctb = new TextBlock();
                        ctb.Text = tempTag.TagValue;
                        foreach (var imgSetting in tempTag.SettingTags)
                        {
                            FormatText(tb, ctb, tBlock, imgSetting);
                        }
                        tb.Inlines.Add(ctb);
                    }
                    figure.Blocks.Add(tBlock);
                    block.Inlines.Add(figure);
                    result = true;
                }
                break;
            }
            return(result);
        }
        private FlowDocument SimpleFlowExample()
        {
            try
            {
                // Add some Bold text to the paragraph
                Paragraph myParagraph = new Paragraph();
                myParagraph.FontSize = 33;//hn
                // myParagraph.FontSize = 11;//asr,kp

                myParagraph.FontFamily = new FontFamily("Arial");
                myParagraph.Inlines.Add(new Bold(new Run("\t\tHimayath Nagar" + "\r\n\b")));//hn
                //  myParagraph.Inlines.Add(new Bold(new Run("\t\tA.S.Rao Nagar" + "\r\n\b"))); //asrao
                //   myParagraph.Inlines.Add(new Bold(new Run("\t\tKukatpally" + "\r\n\b"))); //kp
                myParagraph.Inlines.Add(new Run("\r\n"));
                myParagraph.Inlines.Add(new Run("Order ID : " + lblOrderID.Content.ToString().PadRight(5) + "\r\n"));
                myParagraph.Inlines.Add(new Bold(new Run(lblCustName.Content.ToString().PadRight(5) + "\r\n")));
                myParagraph.Inlines.Add(new Run("Phone : " + lblCustPhone.Content.ToString().PadRight(5) + "  " + lblAddress.Content.ToString() + "\r\n"));
                myParagraph.Inlines.Add(new Run("Items " + lblItems.Content.ToString().PadRight(5) + "  Total Amount : Rs." + lblactamount.Content.ToString() + "\r\n"));

                // Create a FlowDocument and add the paragraph to it.
                FlowDocument myFlowDocument = new FlowDocument();
                myFlowDocument.Blocks.Add(myParagraph);

                Line pLine = new Line();
                pLine.Stretch         = Stretch.Fill;
                pLine.Stroke          = Brushes.Black;
                pLine.X2              = 1;
                pLine.StrokeThickness = 1;
                myParagraph.Inlines.Add(pLine);
                // Add some plain text to the paragraph

                // Create a List and populate with three list items.

                //   myParagraph.Inlines.Add(new Run(" Customer Name : " + lblCustName.Content.ToString()));
                myParagraph.Inlines.Add(new Run("Code".PadLeft(2) + string.Format("{0}", "\t") + "Dish".PadLeft(5) + string.Format("{0}", "\t") + string.Format("{0}", "\t") + "Qty".PadLeft(5) + string.Format("{0}", "\t") + "Price".PadLeft(5) + string.Format("{0}", "\t") + "Total".PadLeft(5) + "\r\n"));
                // myParagraph.Inlines.Add(pLine);
                int ordercount = lvOrders.Items.Count;
                for (int i = 0; i < ordercount; i++)
                {
                    TableRow  tblRow   = new TableRow();
                    TableCell tblCell1 = new TableCell();
                    TableCell tblCell2 = new TableCell();
                    //     myParagraph.Inlines.Add(new Run("Cell ID1" + i + "\r\n"));

                    tblRow.Cells.Add(tblCell1);
                    tblRow.Cells.Add(tblCell2);
                    string pname;

                    pname = dSet.Rows[i]["ProductName"].ToString();
                    if (pname.Length > 13)
                    {
                        pname = pname.Substring(0, 13).PadRight(23);
                    }
                    else
                    {
                        int pLen = pname.Length;
                        pname = pname.PadRight(23 - pLen);
                    }
                    string Pid   = dSet.Rows[i]["ProductId"].ToString();
                    string qty   = dSet.Rows[i]["Quantity"].ToString();
                    string Price = dSet.Rows[i]["Price"].ToString();
                    string Total = dSet.Rows[i]["Total"].ToString();


                    myParagraph.Inlines.Add(new Run(Pid.PadLeft(2) + (pname.PadLeft(2)) + string.Format("{0}", "\t") + qty.PadLeft(2) + string.Format("{0}", "\t") + Price.PadLeft(2) + string.Format("{0}", "\t") + Total.PadLeft(2) + "\r\n"));

                    //  myFlowDocument.Blocks.Add(myParagraph + "\n");
                }
                //myParagraph.Inlines.Add(new Run("\r\r\n\n"));
                //myParagraph.Inlines.Add(new Run("  Total Amount : Rs." + lblactamount.Content.ToString() + "\r\n"));
                //myParagraph.Inlines.Add(new Run("\r\n"));
                //myParagraph.Inlines.Add(new Run("  GST 12% :" + lblgst.Content.ToString() + "\r\n"));
                //myParagraph.Inlines.Add(new Run("\r\n"));
                //myParagraph.Inlines.Add(new Run("  Delivery Charge : Rs." + lbldelcharges.Content.ToString() + "\r\n"));
                //myParagraph.Inlines.Add(new Run("\r\n"));
                //myParagraph.Inlines.Add(new Run("  Grand Total : Rs." + lblGrandTotal.Content.ToString() + "\r\n"));
                //myParagraph.Inlines.Add(new Run("\r\n"));
                //myParagraph.Inlines.Add(new Run("Thank You visit again  040-69006900"));
                myParagraph.Inlines.Add(new Run("\r\n"));

                myParagraph.Inlines.Add(new Bold(new Run("  Total Amount " + lblactamount.Content.ToString().PadLeft(48) + "\r\n")));
                // myParagraph.Inlines.Add(new Run("\r\n"));
                //  myParagraph.Inlines.Add((new Run("  CGST " + lblcgst.Content.ToString().PadLeft(56) + "\r\n")));
                // myParagraph.Inlines.Add(new Run("\r\n"));
                //  myParagraph.Inlines.Add((new Run("  SGST " + lblsgst.Content.ToString().PadLeft(56) + "\r\n")));
                // myParagraph.Inlines.Add(new Run("\r\n"));
                myParagraph.Inlines.Add(new Bold(new Run("  Delivery Charge " + lbldelcharges.Content.ToString().PadLeft(45) + "\r\n")));
                //myParagraph.Inlines.Add(new Run("\r\n"));
                myParagraph.Inlines.Add(new Bold(new Run("  Grand Total" + lblGrandTotal.Content.ToString().PadLeft(52) + "\r\n")));

                myParagraph.Inlines.Add(new Bold(new Run("\r\n")));
                myParagraph.Inlines.Add(new Bold(new Run("  (GST Inclusive) \r\n")));

                myParagraph.Inlines.Add(new Bold(new Run("\r\n")));
                myParagraph.Inlines.Add(new Bold(new Run("  GSTIN:" + lblGSTIN.Content.ToString().PadLeft(15) + "\r\n")));
                myParagraph.Inlines.Add(new Bold(new Run("\r\n")));
                myParagraph.Inlines.Add(new Bold(new Run("Thank You visit again 7306544444")));
                //  myParagraph.Inlines.Add(pLine);
                myFlowDocument.ColumnWidth = 999999;
                myFlowDocument.PagePadding = new Thickness(10);
                // Padding is 5 pixels on the right and left, and 10 pixels on the top and botton.
                myFlowDocument.PagePadding = new Thickness(40, 10, 5, 10);

                //  myParagraph.Inlines.Add(image);


                BlockUIContainer uiCont = new BlockUIContainer();

                Label myButton = new Label
                {
                    //Width = 350,
                    //Height = 250,
                    Width  = 200,
                    Height = 100,
                    //  HorizontalAlignment = HorizontalAlignment.Left,//kp,an
                    HorizontalAlignment = HorizontalAlignment.Center,//hn
                    Background          = new SolidColorBrush(Colors.White),
                    Content             = new Image
                    {
                        Source = new BitmapImage(new Uri(@"C:\Users\user\Downloads\AC.png", UriKind.Relative)),//hn
                        //  Source = new BitmapImage(new Uri(@"C:\Users\Public\Pictures\Sample Pictures\AC.png", UriKind.Relative)),//asr
                        //  Source = new BitmapImage(new Uri(@"D:\AC.png", UriKind.Relative)),//kp

                        VerticalAlignment = VerticalAlignment.Center
                    }
                };

                //  b.Content = "Click me";
                uiCont.Child = (myButton);
                myFlowDocument.Blocks.Add(uiCont);
                myFlowDocument.Blocks.Add(myParagraph);
                // myFlowDocument.Blocks.Add(myList);



                // Add the FlowDocument to a FlowDocumentReader Control
                FlowDocumentReader myFlowDocumentReader = new FlowDocumentReader();

                myFlowDocumentReader.Document = myFlowDocument;
                //FlowDocument fp = new FlowDocument();

                this.Content = myFlowDocumentReader;

                return(myFlowDocument);
            }
            catch (Exception ex)
            { throw ex; }

            //    SqlConnection connection;
            //    connection = new SqlConnection(connStr);
            //    if (connection.State.ToString() == "open") { connection.Close(); }
            //    connection.Open();
            //    SqlCommand cmd = new SqlCommand("[PrintorderStatusByOrderId]", connection);
            //    cmd.Parameters.Add(new SqlParameter("OrderId", orderID));
            //    cmd.CommandType = CommandType.StoredProcedure;

            //    //  @Categorytype = N'Break Fast'

            //    SqlDataAdapter dAd = new SqlDataAdapter(cmd);

            //    dAd.Fill(dSet);
            //    // sda.Fill(dt);

            //    int ItemsCount = 0;
            //    lvOrders.Items.Clear();
            //    if (dSet.Rows.Count > 0) {
            //        lvOrders.ItemsSource = dSet.DefaultView;
            //        lblOrderID.Content = dSet.Rows[0][0].ToString();
            //        lblCustName.Content= dSet.Rows[0][2].ToString() +" "+ dSet.Rows[0][3].ToString();
            //        lblAddress.Content= dSet.Rows[0][4].ToString();
            //        lblCustPhone.Content= dSet.Rows[0][1].ToString();
            //        lblOrderDate.Content =     dSet.Rows[0]["OrderDate"].ToString().Substring(0,10) ;



            //        lblOrderTime.Content = dSet.Rows[0]["OrderTime"].ToString();
            //        ItemsCount = int.Parse(dSet.Rows.Count.ToString());
            //        int sum = Convert.ToInt32(dSet.Compute("SUM(Total)", string.Empty));
            //        lblItems.Content = ItemsCount;
            //        lblGrandTotal.Content = sum.ToString();
            //        lblStatus.Content="Order Status: " + dSet.Rows[0]["StatusDescription"].ToString();
            //    }

            //    if (connection.State.ToString() == "open") { connection.Close(); }

            //}

            //private void Button_Click(object sender, RoutedEventArgs e)
            //{
            //    if (lvOrders.Items.Count > 0)
            //    {
            //        PrintDialog printDlg = new PrintDialog();

            //        // Create a FlowDocument dynamically.
            //        //   FlowDocument doc = CreateFlowDocument();
            //        FlowDocument doc = SimpleFlowExample();
            //        doc.Name = "FlowDoc";

            //        // Create IDocumentPaginatorSource from FlowDocument
            //        IDocumentPaginatorSource idpSource = doc;

            //        // Call PrintDocument method to send document to printer
            //        printDlg.PrintDocument(idpSource.DocumentPaginator, "Hello WPF Printing.");
            //       // printDlg.ShowDialog = false;
            //    }

            //    else { MessageBox.Show("Nothing to print !!!"); }
            //}



            //private FlowDocument SimpleFlowExample()
            //{



            //    // Add some Bold text to the paragraph
            //    Paragraph myParagraph = new Paragraph();

            //    myParagraph.FontSize = 33;
            //    myParagraph.FontFamily = new FontFamily("Arial");
            //    myParagraph.Inlines.Add(new Bold(new Run("\t\tHimayath Nagar" + "\r\n\b")));
            //    myParagraph.Inlines.Add(new Run("Order ID : " + lblOrderID.Content.ToString().PadLeft(0) + "\r\n"));
            //    myParagraph.Inlines.Add(new Bold(new Run(lblCustName.Content.ToString().PadLeft(0) + "\r\n")));
            //    myParagraph.Inlines.Add(new Run("Phone : " + lblCustPhone.Content.ToString().PadLeft(0) + "  " + lblAddress.Content.ToString() + "\r\n"));
            //    myParagraph.Inlines.Add(new Run("Items " + lblItems.Content.ToString().PadLeft(0) + "  Total Amount : Rs." + lblGrandTotal.Content.ToString() + "\r\n"));

            //    // Create a FlowDocument and add the paragraph to it.
            //    FlowDocument myFlowDocument = new FlowDocument();
            //    myFlowDocument.Blocks.Add(myParagraph);

            //    Line pLine = new Line();
            //    pLine.Stretch = Stretch.Fill;
            //    pLine.Stroke = Brushes.Black;
            //    pLine.X2 = 1;
            //    pLine.StrokeThickness = 1;
            //    myParagraph.Inlines.Add(pLine);
            //    // Add some plain text to the paragraph

            //    // Create a List and populate with three list items.

            //    //   myParagraph.Inlines.Add(new Run(" Customer Name : " + lblCustName.Content.ToString()));
            //    myParagraph.Inlines.Add(new Run("Code".PadLeft(0) + string.Format("{0}", "\t") + "Dish".PadLeft(3) + string.Format("{0}", "\t") + string.Format("{0}", "\t") + "Qty".PadLeft(3) + string.Format("{0}", "\t") + "Price".PadLeft(3) + string.Format("{0}", "\t") + "Total".PadLeft(3) + "\r\n"));
            //    // myParagraph.Inlines.Add(pLine);
            //    int ordercount = lvOrders.Items.Count;
            //    for (int i = 0; i < ordercount; i++)
            //    {
            //        TableRow tblRow = new TableRow();
            //        TableCell tblCell1 = new TableCell();
            //        TableCell tblCell2 = new TableCell();
            //        //     myParagraph.Inlines.Add(new Run("Cell ID1" + i + "\r\n"));

            //        tblRow.Cells.Add(tblCell1);
            //        tblRow.Cells.Add(tblCell2);
            //        string pname;

            //        pname = dSet.Rows[i]["ProductName"].ToString();
            //        if (pname.Length > 10) { pname = pname.Substring(0, 10).PadRight(20); }
            //        else
            //        {
            //            int pLen = pname.Length;
            //            pname = pname.PadRight(20 - pLen);
            //        }
            //        string Pid = dSet.Rows[i]["ProductId"].ToString();
            //        string qty = dSet.Rows[i]["Quantity"].ToString();
            //        string Price = dSet.Rows[i]["Price"].ToString();
            //        string Total = dSet.Rows[i]["Total"].ToString();


            //        myParagraph.Inlines.Add(new Run(Pid.PadLeft(1) + (pname.PadLeft(1)) + string.Format("{0}", "\t") + qty.PadLeft(1) + string.Format("{0}", "\t") + Price.PadLeft(1) + string.Format("{0}", "\t") + Total.PadLeft(1) + "\r\n"));

            //        //  myFlowDocument.Blocks.Add(myParagraph + "\n");
            //    }
            //    //  myParagraph.Inlines.Add(pLine);
            //    myFlowDocument.ColumnWidth = 999999;


            //    //  myParagraph.Inlines.Add(image);


            //    BlockUIContainer uiCont = new BlockUIContainer();

            //    Label myButton = new Label
            //    {
            //        Width = 400,
            //        Height = 300,
            //        HorizontalAlignment = HorizontalAlignment.Center,
            //        Background = new SolidColorBrush(Colors.White),
            //        Content = new Image
            //        {
            //            Source = new BitmapImage(new Uri(@"C:\Users\venkat\Documents\Visual Studio 2015\Projects\Project3\AnkapurProject\Anakapur\Images\AC.jpg", UriKind.Relative)),
            //            VerticalAlignment = VerticalAlignment.Center
            //        }
            //    };

            //    //  b.Content = "Click me";
            //    uiCont.Child = (myButton);
            //    myFlowDocument.Blocks.Add(uiCont);
            //    myFlowDocument.Blocks.Add(myParagraph);
            //    // myFlowDocument.Blocks.Add(myList);



            //    // Add the FlowDocument to a FlowDocumentReader Control
            //    FlowDocumentReader myFlowDocumentReader = new FlowDocumentReader();
            //    myFlowDocumentReader.Document = myFlowDocument;

            //    this.Content = myFlowDocumentReader;

            //    return myFlowDocument;
        }
        /// <summary>
        /// Create the table section of Receipt
        /// </summary>
        /// <param name="blkTableText"></param>
        /// <param name="gridMeta">The meta header of the table</param>
        /// <param name="listData">The data source for table</param>
        private void Generate_TableText(BlockUIContainer blkTableText, string[] gridMeta, List <OrderDetailsForPrint> listData)
        {
            Grid dgDataTable = new Grid();

            dgDataTable.Width = 300;
            // set Columns
            for (int i = 0; i < 4; i++)
            {
                if (i == 0)
                {
                    ColumnDefinition firstCol = new ColumnDefinition();
                    firstCol.Width = new GridLength(120);
                    dgDataTable.ColumnDefinitions.Add(firstCol);
                    continue;
                }
                if (i == 1)
                {
                    ColumnDefinition secondCol = new ColumnDefinition();
                    secondCol.Width = new GridLength(30);
                    dgDataTable.ColumnDefinitions.Add(secondCol);
                    continue;
                }
                if (i == 2)
                {
                    ColumnDefinition otherCol = new ColumnDefinition();
                    otherCol.Width = new GridLength(55);
                    dgDataTable.ColumnDefinitions.Add(otherCol);
                    continue;
                }
                else
                {
                    ColumnDefinition otherCol = new ColumnDefinition();
                    otherCol.Width = new GridLength(65);
                    dgDataTable.ColumnDefinitions.Add(otherCol);
                    continue;
                }
            }
            // set Rows
            for (int i = 0; i < listData.Count + 1; i++)
            {
                dgDataTable.RowDefinitions.Add(new RowDefinition());
            }


            // add Meta
            for (int i = 0; i < 4; i++)
            {
                TextBlock txtMeta = new TextBlock();
                if (i == 2 || i == 3)
                {
                    txtMeta.Text              = gridMeta[i];
                    txtMeta.FontSize          = 11;
                    txtMeta.FontWeight        = FontWeights.Bold;
                    txtMeta.VerticalAlignment = VerticalAlignment.Stretch;
                    txtMeta.TextAlignment     = TextAlignment.Right;
                    Grid.SetRow(txtMeta, 0);
                    Grid.SetColumn(txtMeta, i);
                }
                else
                {
                    txtMeta.Text              = gridMeta[i];
                    txtMeta.FontSize          = 11;
                    txtMeta.FontWeight        = FontWeights.Bold;
                    txtMeta.VerticalAlignment = VerticalAlignment.Stretch;
                    Grid.SetRow(txtMeta, 0);
                    Grid.SetColumn(txtMeta, i);
                }

                dgDataTable.Children.Add(txtMeta);
            }

            int rowIndex = 1;

            foreach (var orderItem in listData)
            {
                TextBlock txtProductName = new TextBlock();
                txtProductName.Width               = 115;
                txtProductName.Text                = seperateLongProductName(orderItem.ProductName);
                txtProductName.FontSize            = 11;
                txtProductName.VerticalAlignment   = VerticalAlignment.Top;
                txtProductName.HorizontalAlignment = HorizontalAlignment.Left;
                txtProductName.Margin              = new Thickness(0, 0, 0, 5);
                Grid.SetRow(txtProductName, rowIndex);
                Grid.SetColumn(txtProductName, 0);
                dgDataTable.Children.Add(txtProductName);

                TextBlock txtQuan = new TextBlock();
                txtQuan.Text              = orderItem.Quan.ToString();
                txtQuan.FontSize          = 11;
                txtQuan.VerticalAlignment = VerticalAlignment.Top;
                txtQuan.Margin            = new Thickness(0, 0, 0, 5);
                Grid.SetRow(txtQuan, rowIndex);
                Grid.SetColumn(txtQuan, 1);
                dgDataTable.Children.Add(txtQuan);

                TextBlock txtPrice = new TextBlock();
                txtPrice.Text                = String.Format("{0:0.000}", orderItem.ProductPrice);
                txtPrice.FontSize            = 11;
                txtPrice.VerticalAlignment   = VerticalAlignment.Stretch;
                txtPrice.HorizontalAlignment = HorizontalAlignment.Right;
                txtPrice.Margin              = new Thickness(0, 0, 0, 5);
                Grid.SetRow(txtPrice, rowIndex);
                Grid.SetColumn(txtPrice, 2);
                dgDataTable.Children.Add(txtPrice);

                TextBlock txtAmt = new TextBlock();
                txtAmt.Text              = String.Format("{0:0.000}", orderItem.Amt);
                txtAmt.FontSize          = 11;
                txtAmt.VerticalAlignment = VerticalAlignment.Stretch;
                txtAmt.TextAlignment     = TextAlignment.Right;
                txtAmt.Margin            = new Thickness(0, 0, 0, 5);
                Grid.SetRow(txtAmt, rowIndex);
                Grid.SetColumn(txtAmt, 3);
                dgDataTable.Children.Add(txtAmt);

                rowIndex++;
            }

            blkTableText.Child = dgDataTable;
        }