コード例 #1
0
        private void GetCurrentBlock(TermsAndConditionsCategory category, string sKey, bool secondLevelMenu = false)
        {
            ScrollViewer sv = GetScrollviewer();

            sv.ScrollToVerticalOffset(0);
            FlowDocument fldX = new FlowDocument();

            foreach (var dHeading in category.Headings)
            {
                if (!secondLevelMenu && dHeading.Key == sKey)
                {
                    System.Windows.Documents.Paragraph pX = new System.Windows.Documents.Paragraph(new System.Windows.Documents.Run(dHeading.Key));
                    pX.FontFamily = new System.Windows.Media.FontFamily("Helvetica Neue");
                    pX.FontSize   = 28;
                    pX.FontWeight = FontWeights.Bold;
                    pX.Foreground = (SolidColorBrush)(new BrushConverter().ConvertFrom("#D6AC0A"));
                    fldX.Blocks.Add(pX);
                }
                else
                {
                    if (!secondLevelMenu)
                    {
                        continue;
                    }
                }

                var sectionX = category.Headings[dHeading.Key];

                foreach (var sX in sectionX)
                {
                    if ((!secondLevelMenu && sX.Key != "") || (secondLevelMenu && sX.Key != sKey))
                    {
                        continue;
                    }

                    if (secondLevelMenu)
                    {
                        System.Windows.Documents.Paragraph pX = new System.Windows.Documents.Paragraph(new System.Windows.Documents.Run(sKey));
                        pX.FontFamily = new System.Windows.Media.FontFamily("Helvetica Neue");
                        pX.FontSize   = 24;
                        pX.FontWeight = FontWeights.Bold;
                        pX.Foreground = (SolidColorBrush)(new BrushConverter().ConvertFrom("#D6AC0A"));
                        fldX.Blocks.Add(pX);
                    }

                    foreach (var tX in sX.Value)
                    {
                        string[] arrVals = tX.Split('|');

                        if (arrVals[0] != "LP")
                        {
                            System.Windows.Documents.Paragraph ptX = new System.Windows.Documents.Paragraph(new System.Windows.Documents.Run(arrVals[1]));
                            ptX.FontFamily = new System.Windows.Media.FontFamily("Helvetica Neue");
                            switch (arrVals[0])
                            {
                            default:
                                ptX.FontSize   = 20;
                                ptX.FontWeight = FontWeights.Normal;
                                ptX.Foreground = (SolidColorBrush)(new BrushConverter().ConvertFrom("#E4E4E4"));
                                break;

                            case "H3":
                                ptX.FontSize   = 20;
                                ptX.FontWeight = FontWeights.Bold;
                                ptX.Foreground = (SolidColorBrush)(new BrushConverter().ConvertFrom("#D6AC0A"));
                                break;

                            case "H4":
                                ptX.FontSize   = 20;
                                ptX.FontWeight = FontWeights.Bold;
                                ptX.Foreground = (SolidColorBrush)(new BrushConverter().ConvertFrom("#E4E4E4"));
                                break;

                            case "B":
                                ptX.FontSize   = 20;
                                ptX.FontWeight = FontWeights.Bold;
                                ptX.Foreground = (SolidColorBrush)(new BrushConverter().ConvertFrom("#E4E4E4"));
                                break;
                            }

                            fldX.Blocks.Add(ptX);
                        }
                        else
                        {
                            List l = new List();
                            l.MarkerStyle = TextMarkerStyle.Disc;
                            l.FontFamily  = new System.Windows.Media.FontFamily("Helvetica Neue");
                            l.FontSize    = 20;
                            l.FontWeight  = FontWeights.Normal;
                            l.Foreground  = (SolidColorBrush)(new BrushConverter().ConvertFrom("#E4E4E4"));

                            l.ListItems.Add(new System.Windows.Documents.ListItem(new System.Windows.Documents.Paragraph(new System.Windows.Documents.Run(arrVals[1]))));
                            fldX.Blocks.Add(l);
                        }
                    }
                }
            }
            CurrentBlock = fldX;
        }
コード例 #2
0
        private void GetRulesFromFiles()
        {
            foreach (var folder in GetFolders())
            {
                string fileX = GetFileInFolderByLanguage(folder);
                if (fileX == null)
                {
                    continue;
                }
                var category = new TermsAndConditionsCategory(folder);

                using (WordprocessingDocument xmlX = WordprocessingDocument.Open(fileX, false))
                {
                    int iX = 0;

                    string        sCurH1    = "";
                    string        sCurH2    = "";
                    List <string> lstTexts  = new List <string>();
                    int?          iParCount = xmlX.MainDocumentPart.Document.Body.Descendants <Paragraph>().Count();

                    foreach (var descendant in xmlX.MainDocumentPart.Document.Body.Descendants <Paragraph>())
                    {
                        iX++;
                        if ((descendant.ParagraphProperties != null && descendant.ParagraphProperties.ParagraphStyleId != null) || iX == iParCount)
                        {
                            string sHeading;
                            try
                            {
                                sHeading = descendant.ParagraphProperties.ParagraphStyleId.Val.Value;
                            }
                            catch (Exception)
                            {
                                sHeading = "";
                            }

                            if (sHeading == "Heading1" || iX == iParCount)
                            {
                                if (lstTexts.Count > 0)
                                {
                                    category.Texts.Add(sCurH2, lstTexts);
                                    lstTexts = new List <string>();

                                    category.Headings.Add(sCurH1, category.Texts);
                                    category.Texts = new Dictionary <string, List <string> >();
                                }
                                sCurH1 = descendant.InnerText;
                                sCurH2 = "";
                            }
                            else if (sHeading == "Heading2")
                            {
                                var text = descendant.InnerText;
                                //if (!SkipVflOrVhc(text))
                                //    text = text.Replace("#VFL#", "").Replace("#VHC#", ""); //have to save those somehow...
                                if (lstTexts.Count > 0)
                                {
                                    category.Texts.Add(sCurH2, lstTexts);
                                    lstTexts = new List <string>();
                                }
                                sCurH2 = text;
                            }
                            else if (sHeading != "Title")
                            {
                                if (sHeading == "Heading3")
                                {
                                    lstTexts.Add("H3|" + descendant.InnerText);
                                }
                                else if (sHeading == "Heading4")
                                {
                                    lstTexts.Add("H4|" + descendant.InnerText);
                                }
                                else if (sHeading == "ListParagraph")
                                {
                                    lstTexts.Add("LP|" + descendant.InnerText);
                                }
                                else
                                {
                                    lstTexts.Add(descendant.InnerText);
                                }

                                //Debug.WriteLine(descendant.InnerText);
                            }
                            //Debug.WriteLine(sHeading + " - " + descendant.InnerText);
                        }
                        else
                        {
                            if (descendant.ParagraphProperties != null &&
                                descendant.ParagraphProperties.ParagraphMarkRunProperties != null &&
                                descendant.ParagraphProperties.ParagraphMarkRunProperties.Any(p => p is Bold))
                            {
                                lstTexts.Add("B|" + descendant.InnerText);
                            }
                            else
                            {
                                //usual paragraph
                                lstTexts.Add("|" + descendant.InnerText);
                            }
                            //Debug.WriteLine(descendant.InnerText);
                        }
                    }
                }
                _categories.Add(category);
            }
        }