Example #1
0
        private async Task GenerateReport(Patient patient, string templatePath, string reportDir)
        {
            var report = new WordAPI(templatePath, reportDir + "/" + patient.Name.Replace(" ", "-") + ".docx", readOnly: false);

            report.GenerateReport(patient, reportDir);
            report.Close();
        }
 public void ReplaceTextExistsAfterReplace()
 {
     WordInterface = new WordAPI(TemplatePath, false);
     WordInterface.FindAndReplace(FindAndReplacePairs, false);
     foreach (var pair in FindAndReplacePairs)
     {
         Assert.IsTrue(WordInterface.ContainsText(pair.Value, false));
     }
     WordInterface.Close();
 }
        public void SearchTextExistsBeforeReplace()
        {
            var templateApi = new WordAPI(TemplatePath);

            foreach (var pair in FindAndReplacePairs)
            {
                Assert.IsTrue(templateApi.ContainsText(pair.Key, false), templatePreconditionError + TemplatePath);
            }
            templateApi.Close();
        }
 public void SearchTextDoesNotExistAfterReplace()
 {
     WordInterface = new WordAPI(TemplatePath, false);
     WordInterface.FindAndReplace(FindAndReplacePairs, false);
     foreach (var pair in FindAndReplacePairs)
     {
         Assert.IsFalse(WordInterface.ContainsText(pair.Key, false));
     }
     WordInterface.Close();
 }
        public void ReplaceTextDoesNotExistBeforeReplace()
        {
            var templateApi = new WordAPI(TemplatePath);

            foreach (var pair in FindAndReplacePairs)
            {
                Assert.IsFalse(templateApi.ContainsText(pair.Value, false), templatePreconditionError + TemplatePath);
            }
            templateApi.Close();
        }
Example #6
0
 void Start()
 {
     answerField        = guessGameplay.transform.GetChild(0).gameObject.transform;
     imageField         = guessGameplay.transform.GetChild(1).gameObject;
     currentLevelObject = guessGameplay.transform.GetChild(5).GetChild(0).gameObject;
     coinField          = guessGameplay.transform.GetChild(4).gameObject;
     bonusField         = guessGameplay.transform.GetChild(5).gameObject.transform.GetChild(2).gameObject.transform.GetChild(0).gameObject;
     coinText           = coinField.transform.GetChild(0).gameObject.transform.GetChild(0).GetComponent <TextMeshProUGUI>();
     bonusText          = bonusField.transform.GetComponent <TextMeshProUGUI>();
     uIComplete         = uICompleteScreen.transform.GetChild(1).gameObject;
     uIDescription      = uICompleteScreen.transform.GetChild(2).gameObject;
     wordAPI            = GetComponent <WordAPI>();
 }
Example #7
0
        private MemoryStream GeneratePatientReport(Patient patient, ReportTemplate template)
        {
            var reportTemplatePath = template.FilePath;

            MemoryStream docStream = new MemoryStream(System.IO.File.ReadAllBytes(reportTemplatePath));

            using (var docEditor = new WordAPI(docStream, readOnly: false))
            {
                docEditor.GenerateReport(patient);
            }

            return(docStream);
        }
Example #8
0
 /// <summary>
 /// 打开文件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnOpenFile_Click(object sender, EventArgs e)
 {
     openFileDialog1.Filter      = "Doc Files(*.Docx)|*.Docx";
     openFileDialog1.Multiselect = false;
     if (openFileDialog1.ShowDialog() == DialogResult.OK)
     {
         string[] kStrings = null;
         string   paths    = @"E:\1.docx";
         string   fileName = openFileDialog1.FileName; //文件名称
         textBox1.Text = fileName;
         kStrings      = WordAPI.GetDocxDocumentBuilder(fileName);
         Ds            = ImpExp.Import.ImpCatalog(kStrings);
         CreateCategory(Ds.Tables[1]);
         DtChapt = Ds.Tables[2];
     }
 }
        public void ReadOnlySearchAndReplaceFails()
        {
            Exception failedEx = null;

            try
            {
                WordInterface = new WordAPI(TemplatePath, true);
                WordInterface.FindAndReplace(FindAndReplacePairs, false);
            }
            catch (Exception e)
            {
                failedEx = e;
            }
            WordInterface.Close();
            Assert.IsNotNull(failedEx);
        }
Example #10
0
    private void ShowSynounyms(object sender, EventArgs e)
    {
        WordMeuItem MI = (WordMeuItem)sender;

        MI.Word = MI.Word.ToLower();
        string TL = DownloadTranslation(MI.Word).ToLower();
        bool   CanGiveSynounyms = !string.IsNullOrEmpty(TL);

        if (CanGiveSynounyms)
        {
            string cnt = Engine.LoadTranslation(Engine.TLID.LoadingSuggetionsPlzWait);
            //Asyc Download Suggestions
            BallonToolTip Ballon = new BallonToolTip();

            bool   IsFromInputLang = TL != MI.Word;
            string Word            = MI.Word;
            if (IsFromInputLang && InputLang != "EN")
            {
                Word = DownloadTranslation(Word, InputLang, "EN");
            }
            if (!IsFromInputLang && TargetLang != "EN")
            {
                Word = DownloadTranslation(Word, TargetLang, "EN");
            }

            if (Word.Contains(" "))
            {
                foreach (string w in Word.Split(' '))
                {
                    string TTL = string.Empty;
                    if (IsFromInputLang && InputLang != "EN")
                    {
                        TTL = DownloadTranslation(w, "EN", InputLang);
                    }
                    if (!IsFromInputLang && TargetLang != "EN")
                    {
                        TTL = DownloadTranslation(w, "EN", TargetLang);
                    }
                    if (MI.Word.ToLower().StartsWith(Word.ToLower()))
                    {
                        Word = TTL;
                    }
                }
            }


            string[] Suggestions           = new string[0];
            System.Threading.Thread Thread = new System.Threading.Thread(() => {
                try {
                    Suggestions = WordAPI.DownloadSynonyms(Word);
                } catch { }
                if (Suggestions == null)
                {
                    Suggestions = new string[0];
                }
                if (!IsFromInputLang)
                {
                    for (int i = 0; i < Suggestions.Length; i++)
                    {
                        Suggestions[i] = DownloadTranslation(Suggestions[i], "EN", TargetLang);
                    }
                }
            });

            Timer ti = new Timer();
            ti.Interval = 500;
            ti.Tick    += (sdr, ev) => {
                if (Thread.ThreadState == System.Threading.ThreadState.Stopped)
                {
                    ti.Enabled = false;
                    string WordList = string.Empty;
                    if (Suggestions == null)
                    {
                        Ballon         = new BallonToolTip();
                        Ballon.Title   = Engine.LoadTranslation(Engine.TLID.NoSynonymsFound);
                        Ballon.Message = Engine.LoadTranslation(Engine.TLID.TryManuallySearch);
                        Engine.UpdateToolTip(Ballon, true);
                        return;
                    }
                    foreach (string Suggestion in Suggestions)
                    {
                        if (!string.IsNullOrWhiteSpace(Suggestion))
                        {
                            WordList += Suggestion + ", ";
                        }
                    }
                    if (string.IsNullOrWhiteSpace(WordList))
                    {
                        WordList = @"  ";
                    }
                    WordList       = WordList.Substring(0, WordList.Length - 2);
                    Ballon         = new BallonToolTip();
                    Ballon.Title   = string.IsNullOrWhiteSpace(WordList) ? Engine.LoadTranslation(Engine.TLID.NoSynonymsFound) : string.Format(Engine.LoadTranslation(Engine.TLID.SynonymsFor), MI.Word);
                    Ballon.Message = string.IsNullOrWhiteSpace(WordList) ? Engine.LoadTranslation(Engine.TLID.TryManuallySearch) : WordList;
                    Engine.UpdateToolTip(Ballon, true);
                }
            };

            Engine.ShowToolTip(MI.Location, cnt, string.Format(Engine.LoadTranslation(Engine.TLID.SynonymsFor), MI.Word), Ballon, true, this);
            Thread.Start();
            ti.Enabled = true;
        }
        else
        {
            if (MessageBox.Show(Engine.LoadTranslation(Engine.TLID.FailedToDetectWordLang), "VNXTLP", MessageBoxButtons.RetryCancel, MessageBoxIcon.Information) == DialogResult.Retry)
            {
                ShowSynounyms(sender, e);
            }
            return;
        }
    }
Example #11
0
 public void getAndParseTestDock()
 {
     Word.Document documetn = WordAPI.GetDocument("C://Users//Nikita//source//repos//document-creator//DocumentCreator//DocumentCreator//FilesAPI//Doc.docx");
     documetn.Content.Text += "Hello worldddd!!!!!!";
     WordAPI.saveFile(documetn, "C://Users//Nikita//newDoc.docx");
 }
Example #12
0
        static void Main(string[] args)
        {
            Random            random  = new Random();
            List <TestResult> results = new List <TestResult>();

            for (int i = 0; i < 21; i++)
            {
                double r = random.NextDouble() * 6 - 3;
                results.Add(new TestResult()
                {
                    RelatedTest = new Test()
                    {
                        Name = "LD" + i.ToString()
                    },
                    ZScore     = (int)(random.NextDouble() * 6 - 3),
                    Percentile = (int)(random.NextDouble() * 100)
                });
            }

            List <TestResultGroup> resultGroups = new List <TestResultGroup>(new TestResultGroup[] {
                new TestResultGroup()
                {
                    TestGroupInfo = new TestGroup()
                    {
                        Name = "Symptom Checklist - 90 - Revised"
                    },
                    Tests = results
                }
            });

            Patient johnDoe = new Patient()
            {
                Name                = "John Doe",
                PreferredName       = "Johnny",
                DateOfBirth         = new DateTime(628243894905389400),
                DateOfTesting       = new DateTime(628243894905389400),
                MedicalRecordNumber = 123456,
                ResultGroups        = resultGroups
            };

            Patient patient = johnDoe;

            Console.WriteLine(patient.DateOfBirth);


            string templatePath = @"Reports\ReportTemplate\Report_Template.dotx";
            string newfilePath  = @"Reports\GeneratedReports\" + patient.Name + ".docx";
            string vizPath      = @"Reports\GeneratedReports\Visualization.docx";
            string imagePath    = @"Reports\GeneratedReports\renderedVisualization2.png";

            if (File.Exists(newfilePath))
            {
                File.Delete(newfilePath);
            }

            File.Copy(templatePath, newfilePath);

            var entries = new List <Entry>();

            int[]  green  = new int[] { 0, 255, 0 };
            int[]  yellow = new int[] { 255, 255, 0 };
            int[]  red    = new int[] { 255, 0, 0 };
            double interp;
            string hexcol;
            int    percentile;

            using (WordprocessingDocument myDoc = WordprocessingDocument.Open(newfilePath, true)){
                myDoc.ChangeDocumentType(DocumentFormat.OpenXml.WordprocessingDocumentType.Document);
                var wordAPI = new WordAPI(myDoc);
                wordAPI.InsertPatientData(patient);
                foreach (TestResultGroup testResultGroup in patient.ResultGroups)
                {
                    wordAPI.DisplayTestGroup(testResultGroup);

                    foreach (TestResult result in testResultGroup.Tests)
                    {
                        interp = 2 * Math.Abs(0.01 * (double)result.Percentile - 0.5);
                        if (interp < 0.5)
                        {
                            hexcol = ColToHex(ColorInterpolation(green, yellow, 2 * interp));
                        }
                        else
                        {
                            hexcol = ColToHex(ColorInterpolation(yellow, red, 2 * (interp - 0.5)));
                        }
                        if (result.Percentile == 0)
                        {
                            percentile = 1;
                        }
                        else
                        {
                            percentile = result.Percentile;
                        }
                        entries.Add(new Entry(percentile)
                        {
                            Label      = result.RelatedTest.Name,
                            ValueLabel = result.Percentile.ToString(),
                            Color      = SKColor.Parse(hexcol)
                        });
                    }
                }
                wordAPI.PageBreak();
                //InsertPicturePng(myDoc, imagePath,7,1.2);
                //JoinFile(myDoc,vizPath);
            }

            var chart = new BarChart()
            {
                Entries          = entries,
                MaxValue         = 100,
                MinValue         = 0,
                LabelOrientation = Microcharts.Orientation.Vertical
            };

            int width  = 800;
            int height = 300;

            SKImageInfo info    = new SKImageInfo(width, height);
            SKSurface   surface = SKSurface.Create(info);

            SKCanvas canvas = surface.Canvas;

            chart.Draw(canvas, width, height);

            // create an image and then get the PNG (or any other) encoded data
            using (var data = surface.Snapshot().Encode(SKEncodedImageFormat.Png, 80)) {
                // save the data to a stream
                using (var stream = File.OpenWrite("one.png")) {
                    data.SaveTo(stream);
                }
            }

            using (WordprocessingDocument myDoc = WordprocessingDocument.Open(newfilePath, true)){
                var wordAPI = new WordAPI(myDoc);
                wordAPI.InsertPicturePng("one.png", 6, 3);
            }

            //Console.WriteLine("Modified");
        }
Example #13
0
        private void updatePlan(Dictionary <string, Object> keyValuePairs)
        {
            //
            Word.Application wordApp = new Word.Application();
            Word.Document    doc     = wordApp.Documents.Open(documentPathPlan, ReadOnly: false);
            try {
                doc.Activate();
                if (((string)(keyValuePairs["{id:kind}"])).Contains("Тренировк") || ((string)(keyValuePairs["{id:kind}"])).Contains("Самостояте") || ((string)(keyValuePairs["{id:kind}"])).Contains("Практическо"))
                {
                    int countQuestions = 0;
                    Dictionary <string, string> questions = (Dictionary <string, string>)(keyValuePairs["{id:questions}"]);
                    for (int e = 1; e <= doc.Paragraphs.Count; e++)
                    {
                        if (doc.Paragraphs[e].Range.Text.Contains("{id:adjunct}"))
                        {
                            FindAndReplace(wordApp, "{id:adjunct}", "ПРИЛОЖЕННИЯ");
                            Word.Paragraph p = doc.Paragraphs[e];
                            p.Range.InsertParagraphAfter();
                            p = doc.Paragraphs.Add(p.Range);
                            for (int i = 0; i < questions.Count; i++)
                            {
                                int a = i + 1;
                                p.Range.Text = "Карточка - задание на изучение " + a + "-го вопроса.^l";
                                p.Range.InsertParagraphAfter();
                                p = doc.Paragraphs.Add(p.Range);
                            }
                            for (int i = 0; i < questions.Count; i++)
                            {
                                int counter = doc.Paragraphs.Count - 5 + i;
                                doc.Paragraphs[counter].Range.InsertFile(Path.GetFullPath(Path.Combine(System.Reflection.Assembly.GetExecutingAssembly().Location, @"../../../../../Resources/AdditionalDocs/Spravochnik.docx")));
                                KeyValuePair <string, string> question = questions.ElementAt(i);
                                FindAndReplace(wordApp, "{id:questionName}", question.Key);
                                FindAndReplace(wordApp, "{id:countAjunct}", i + 1);
                                FindAndReplace(wordApp, "{id:questionDuration}", question.Value.Split(separator)[0]);
                                if (questions.Count > 1)
                                {
                                    countQuestions = 1;
                                    break;
                                }
                            }
                        }
                        //if(doc.Paragraphs[e].Range.Text.Trim().Replace("\r","").Replace("\a","").Replace("\n","").Equals("")&&countQuestions>0&&(countQuestions< questions.Count))
                        //{
                        //    doc.Paragraphs[e].Range.InsertFile(Path.GetFullPath(Path.Combine(System.Reflection.Assembly.GetExecutingAssembly().Location, @"../../../../../Resources/AdditionalDocs/Spravochnik.docx")));
                        //    KeyValuePair<string, string> question = questions.ElementAt(countQuestions);
                        //    FindAndReplace(wordApp, "{id:questionName}", question.Key);
                        //    FindAndReplace(wordApp, "{id:countAjunct}", countQuestions + 1);
                        //    FindAndReplace(wordApp, "{id:questionDuration}", question.Value);
                        //    countQuestions++;
                        //}
                        //int q = 1;
                    }
                }
                if (((string)(keyValuePairs["{id:kind}"])).ToLower().Contains("полувз") || ((string)(keyValuePairs["{id:kind}"])).ToLower().Contains("ПРО 3 ЧЕЛОВЕК СПРОСИТЬ КАК НАЗЫВАЕТСЯ"))
                {
                    foreach (Word.Paragraph paragraph in doc.Paragraphs)
                    {
                        if (paragraph.Range.Text.Contains("{id:image}"))
                        {
                            if (((string)(keyValuePairs["{id:kind}"])).ToLower().Contains("ПРО 3 ЧЕЛОВЕК СПРОСИТЬ КАК НАЗЫВАЕТСЯ"))
                            {
                                paragraph.Range.InsertFile(Path.GetFullPath(Path.Combine(System.Reflection.Assembly.GetExecutingAssembly().Location, @"../../../../../Resources/AdditionalDocs/image2.docx")));
                            }
                            else
                            {
                                paragraph.Range.InsertFile(Path.GetFullPath(Path.Combine(System.Reflection.Assembly.GetExecutingAssembly().Location, @"../../../../../Resources/AdditionalDocs/image1.docx")));
                            }
                        }
                    }
                }

                FindAndReplace(wordApp, "{id:image}", "");
                FindAndReplace(wordApp, "{id:adjunct}", "");
                FindAndReplace(wordApp, "{id:name}", keyValuePairs["{id:name}"]);
                FindAndReplace(wordApp, "{id:theme}", keyValuePairs["{id:theme}"]);
                FindAndReplace(wordApp, "{id:themeName}", keyValuePairs["{id:themeName}"]);
                FindAndReplace(wordApp, "{id:lesson}", keyValuePairs["{id:lesson}"]);
                FindAndReplace(wordApp, "{id:lessonName}", keyValuePairs["{id:lessonName}"]);
                FindAndReplace(wordApp, "{id:kind}", keyValuePairs["{id:kind}"]);
                FindAndReplace(wordApp, "{id:method}", keyValuePairs["{id:method}"]);
                FindAndReplace(wordApp, "{id:duration}", keyValuePairs["{id:duration}"]);
                FindAndReplace(wordApp, "{id:place}", keyValuePairs["{id:place}"]);

                string methodical = (string)keyValuePairs["{id:methodical}"];
                int    k          = 0;
                for (int i = 0; i < methodical.Length; i += 30)
                {
                    if (i > 0)
                    {
                        try
                        {
                            FindAndReplace(wordApp, "{id:methodical}", methodical.Substring(i + 1, 30) + "{id:methodical}");
                        }
                        catch (Exception e)
                        {
                            break;
                        }
                    }
                    else
                    {
                        FindAndReplace(wordApp, "{id:methodical}", methodical.Substring(i, 30) + "{id:methodical}");
                    }
                    k = i;
                }
                k += 30;
                FindAndReplace(wordApp, "{id:methodical}", methodical.Substring(k + 1));
                string literature = (string)keyValuePairs["{id:literature}"];
                int    l          = 0;
                for (int i = 0; i < literature.Length; i += 30)
                {
                    if (i > 0)
                    {
                        try
                        {
                            FindAndReplace(wordApp, "{id:literature}", literature.Substring(i + 1, 30) + "{id:literature}");
                        }
                        catch (Exception e)
                        {
                            break;
                        }
                    }
                    else
                    {
                        FindAndReplace(wordApp, "{id:literature}", literature.Substring(i, 30) + "{id:literature}");
                    }
                    l = i;
                }
                l += 30;
                FindAndReplace(wordApp, "{id:literature}", literature.Substring(l + 1));
                FindAndReplace(wordApp, "{id:technicalMeans}", keyValuePairs["{id:technicalMeans}"]);
                FindAndReplace(wordApp, "{id:intro}", keyValuePairs["{id:intro}"].ToString().Split(separator)[0]);
                FindAndReplace(wordApp, "{id:material}", keyValuePairs["{id:material}"]);
                FindAndReplace(wordApp, "{id:educationalQuestions}", keyValuePairs["{id:educationalQuestions}"]);
                FindAndReplace(wordApp, "{id:conclution}", keyValuePairs["{id:conclution}"].ToString().Split(separator)[0]);
                foreach (Word.Table table in doc.Tables)
                {
                    Word.Range rangeTable = table.Range;
                    foreach (Word.Row row in rangeTable.Rows)
                    {
                        foreach (Word.Cell cell in row.Cells)
                        {
                            Word.Range range = cell.Range;
                            if (range.Text.Contains("{id:questions}"))
                            {
                                FindAndReplace(wordApp, "{id:questions}", "");
                                Word.Row temporary = row;
                                int      count     = 1;
                                foreach (KeyValuePair <string, string> question in (Dictionary <string, string>)keyValuePairs["{id:questions}"])
                                {
                                    Object   oMissing = System.Reflection.Missing.Value;
                                    Word.Row newRow   = table.Rows.Add(ref oMissing);
                                    newRow.Cells[1].Range.Text = "2." + count;
                                    newRow.Cells[2].Range.Text = question.Key;
                                    newRow.Cells[3].Range.Text = question.Value.Split(separator)[0];
                                    Regex  regex        = new Regex("^ ?[1-9].*$");
                                    string questionFull = "";
                                    if (regex.IsMatch(question.Key))
                                    {
                                        questionFull = "Учебный вопрос. " + question.Key + " " + question.Value.Split(separator)[0] + "\r\n";
                                    }
                                    else
                                    {
                                        questionFull = "Учебный вопрос " + count + ". " + question.Key + " " + question.Value.Split(separator)[0] + "\r\n";
                                    }
                                    int r = 0;
                                    for (int e = 0; e < questionFull.Length; e += 30)
                                    {
                                        if (e > 0)
                                        {
                                            try
                                            {
                                                FindAndReplace(wordApp, "{id:questionOfLesson}", questionFull.Substring(e, 30) + "{id:questionOfLesson}");
                                            }
                                            catch (Exception q)
                                            {
                                                break;
                                            }
                                        }
                                        else
                                        {
                                            FindAndReplace(wordApp, "{id:questionOfLesson}", questionFull.Substring(e, 30) + "{id:questionOfLesson}");
                                        }
                                        r = e;
                                    }
                                    r += 30;
                                    FindAndReplace(wordApp, "{id:questionOfLesson}", questionFull.Substring(r) + "{id:questionOfLesson}");
                                    temporary = newRow;
                                    count++;
                                }
                                Object   missing   = System.Reflection.Missing.Value;
                                Word.Row newRowENd = table.Rows.Add(ref missing);
                                newRowENd.Cells[1].Range.Text = "3";
                                newRowENd.Cells[2].Range.Text = "Заключение";
                                newRowENd.Cells[3].Range.Text = (string)keyValuePairs["{id:conclution}"].ToString().Split(separator)[0] + " мин";
                            }
                            else if (range.Text.Contains("{id:goal}"))
                            {
                                FindAndReplace(wordApp, "{id:goal}", "");
                                int count = 1;
                                foreach (string goal in (List <string>)keyValuePairs["{id:goal}"])
                                {
                                    Object   oMissing = System.Reflection.Missing.Value;
                                    Word.Row newRow   = table.Rows.Add(ref oMissing);
                                    newRow.Cells[1].Range.Text = count + "";
                                    newRow.Cells[2].Range.Text = goal;
                                    count++;
                                }
                            }
                        }
                    }
                }
                FindAndReplace(wordApp, "{id:questionOfLesson}", "");
                WordAPI.SaveFile(doc);
                WordAPI.Close(doc);
            }
            catch (Exception e)
            {
                doc.Close();
                new ExceptionWindow()
                .Show();
            }
        }
Example #14
0
 public void updateDoc(Dictionary <string, Object> keyValuePairs)
 {
     Word.Application wordApp = new Word.Application();
     Word.Document    doc     = wordApp.Documents.Open(documentPath, ReadOnly: false);
     try {
         doc.Activate();
         if (((string)(keyValuePairs["{id:kind}"])).Contains("Тренировк") || ((string)(keyValuePairs["{id:kind}"])).Contains("Самостояте") || ((string)(keyValuePairs["{id:kind}"])).Contains("Практическо"))
         {
             int countQuestions = 0;
             for (int e = 1; e <= doc.Paragraphs.Count; e++)
             {
                 if (doc.Paragraphs[e].Range.Text.Contains("{id:adjunct}"))
                 {
                     Dictionary <string, string> questions = (Dictionary <string, string>)(keyValuePairs["{id:questions}"]);
                     FindAndReplace(wordApp, "{id:adjunct}", "ПРИЛОЖЕНИЯ");
                     countQuestions = questions.Count;
                     Word.Paragraph p = doc.Paragraphs[e];
                     p.Range.InsertParagraphAfter();
                     p = p.Next();
                     for (int i = 0; i < questions.Count; i++)
                     {
                         p.Range.Text = (i + 1) + ". Карточка - задание на изучение " + (i + 1) + "-го вопроса.";
                         p.Range.InsertParagraphAfter();
                         p = p.Next();
                     }
                 }
                 int q           = 1;
                 int countTables = doc.Tables.Count;
                 if (doc.Paragraphs[e].Range.Text.Contains("{id:file"))
                 {
                     Word.Paragraph p = doc.Paragraphs[e];
                     p.Range.InsertParagraphAfter();
                     p.Next();
                     Dictionary <string, string> questions = (Dictionary <string, string>)(keyValuePairs["{id:questions}"]);
                     int temp = Int32.Parse(doc.Paragraphs[e].Range.Text.Trim().Replace("\r", "").Replace("\a", "").Replace("\n", "").Substring(8, 1));
                     KeyValuePair <string, string> question;
                     try
                     {
                         question = questions.ElementAt(temp - 1);
                     }
                     catch (Exception exception)
                     {
                         break;
                     }
                     p.Range.InsertFile(Path.GetFullPath(Path.Combine(System.Reflection.Assembly.GetExecutingAssembly().Location, @"../../../../../Resources/AdditionalDocs/Spravochnik.docx")));
                     int z = 0;
                     for (int i = 0; i < question.Key.Length; i += 30)
                     {
                         if (i > 0)
                         {
                             try
                             {
                                 FindAndReplace(wordApp, "{id:questionName}", question.Key.Substring(i + 1, 30) + "{id:questionName}");
                             }
                             catch (Exception qq)
                             {
                                 break;
                             }
                         }
                         else
                         {
                             FindAndReplace(wordApp, "{id:questionName}", question.Key.Substring(i, 30) + "{id:questionName}");
                         }
                         z = i;
                     }
                     z += 30;
                     FindAndReplace(wordApp, "{id:questionName}", question.Key.Substring(z + 1));
                     FindAndReplace(wordApp, "{id:countAjunct}", temp);
                     FindAndReplace(wordApp, "{id:questionDuration}", question.Value.Split(separator)[0]);
                 }
                 int afterInsert = doc.Tables.Count;
             }
         }
         if (((string)(keyValuePairs["{id:kind}"])).ToLower().Contains("полувз") || ((string)(keyValuePairs["{id:kind}"])).ToLower().Contains("ПРО 3 ЧЕЛОВЕК СПРОСИТЬ КАК НАЗЫВАЕТСЯ"))
         {
             foreach (Word.Paragraph paragraph in doc.Paragraphs)
             {
                 if (paragraph.Range.Text.Contains("{id:image}"))
                 {
                     if (((string)(keyValuePairs["{id:kind}"])).ToLower().Contains("ПРО 3 ЧЕЛОВЕК СПРОСИТЬ КАК НАЗЫВАЕТСЯ"))
                     {
                         paragraph.Range.InsertFile(Path.GetFullPath(Path.Combine(System.Reflection.Assembly.GetExecutingAssembly().Location, @"../../../../../Resources/AdditionalDocs/image2.docx")));
                     }
                     else
                     {
                         paragraph.Range.InsertFile(Path.GetFullPath(Path.Combine(System.Reflection.Assembly.GetExecutingAssembly().Location, @"../../../../../Resources/AdditionalDocs/image1.docx")));
                     }
                 }
             }
         }
         FindAndReplace(wordApp, "{id:cardOfTask}", "");
         FindAndReplace(wordApp, "{id:file1}", "");
         FindAndReplace(wordApp, "{id:file2}", "");
         FindAndReplace(wordApp, "{id:file3}", "");
         FindAndReplace(wordApp, "{id:file4}", "");
         FindAndReplace(wordApp, "{id:file5}", "");
         FindAndReplace(wordApp, "{id:file6}", "");
         FindAndReplace(wordApp, "{id:image}", "");
         FindAndReplace(wordApp, "{id:name}", keyValuePairs["{id:name}"]);
         FindAndReplace(wordApp, "{id:theme}", keyValuePairs["{id:theme}"]);
         FindAndReplace(wordApp, "{id:themeName}", keyValuePairs["{id:themeName}"]);
         FindAndReplace(wordApp, "{id:lesson}", keyValuePairs["{id:lesson}"]);
         FindAndReplace(wordApp, "{id:lessonName}", keyValuePairs["{id:lessonName}"]);
         FindAndReplace(wordApp, "{id:kind}", keyValuePairs["{id:kind}"]);
         FindAndReplace(wordApp, "{id:method}", keyValuePairs["{id:method}"]);
         FindAndReplace(wordApp, "{id:duration}", keyValuePairs["{id:duration}"]);
         FindAndReplace(wordApp, "{id:place}", keyValuePairs["{id:place}"]);
         string methodical = (string)keyValuePairs["{id:methodical}"];
         int    k          = 0;
         for (int i = 0; i < methodical.Length; i += 30)
         {
             if (i > 0)
             {
                 try
                 {
                     FindAndReplace(wordApp, "{id:methodical}", methodical.Substring(i + 1, 30) + "{id:methodical}");
                 }
                 catch (Exception e)
                 {
                     break;
                 }
             }
             else
             {
                 FindAndReplace(wordApp, "{id:methodical}", methodical.Substring(i, 30) + "{id:methodical}");
             }
             k = i;
         }
         k += 30;
         FindAndReplace(wordApp, "{id:methodical}", methodical.Substring(k + 1));
         string literature = (string)keyValuePairs["{id:literature}"];
         int    l          = 0;
         for (int i = 0; i < literature.Length; i += 30)
         {
             if (i > 0)
             {
                 try
                 {
                     FindAndReplace(wordApp, "{id:literature}", literature.Substring(i + 1, 30) + "{id:literature}");
                 }
                 catch (Exception e)
                 {
                     break;
                 }
             }
             else
             {
                 FindAndReplace(wordApp, "{id:literature}", literature.Substring(i, 30) + "{id:literature}");
             }
             l = i;
         }
         l += 30;
         FindAndReplace(wordApp, "{id:literature}", literature.Substring(l + 1));
         FindAndReplace(wordApp, "{id:technicalMeans}", keyValuePairs["{id:technicalMeans}"]);
         string introTime = (keyValuePairs["{id:intro}"]).ToString().Split(separator)[0];
         FindAndReplace(wordApp, "{id:intro}", introTime);
         string[] introQuestions = (keyValuePairs["{id:intro}"]).ToString().Split(separator)[1].Split(';');
         for (int e = 0; e < introQuestions.Length - 1; e++)
         {
             FindAndReplace(wordApp, "{id:introQuestions}", introQuestions[e] + ";\r\n{id:introQuestions}");
         }
         FindAndReplace(wordApp, "{id:introQuestions}", "");
         FindAndReplace(wordApp, "{id:material}", keyValuePairs["{id:material}"]);
         FindAndReplace(wordApp, "{id:educationalQuestions}", keyValuePairs["{id:educationalQuestions}"]);
         string conclusionTime = (keyValuePairs["{id:conclution}"]).ToString().Split(separator)[0];
         FindAndReplace(wordApp, "{id:conclution}", conclusionTime);
         string[] conclusionQuestions = (keyValuePairs["{id:conclution}"]).ToString().Split(separator)[1].Split(';');
         for (int e = 0; e < conclusionQuestions.Length - 1; e++)
         {
             FindAndReplace(wordApp, "{id:conclutionsQuestions}", conclusionQuestions[e] + ";\r\n{id:conclutionsQuestions}");
         }
         FindAndReplace(wordApp, "{id:conclutionsQuestions}", "");
         foreach (Word.Table table in doc.Tables)
         {
             Word.Range rangeTable = table.Range;
             foreach (Word.Row row in rangeTable.Rows)
             {
                 foreach (Word.Cell cell in row.Cells)
                 {
                     Word.Range range = cell.Range;
                     if (range.Text.Contains("{id:questions}"))
                     {
                         FindAndReplace(wordApp, "{id:questions}", "");
                         Word.Row temporary = row;
                         int      count     = 1;
                         foreach (KeyValuePair <string, string> question in (Dictionary <string, string>)keyValuePairs["{id:questions}"])
                         {
                             Object   oMissing = System.Reflection.Missing.Value;
                             Word.Row newRow   = table.Rows.Add(ref oMissing);
                             newRow.Cells[1].Range.Text = "2." + count;
                             newRow.Cells[2].Range.Text = question.Key;
                             newRow.Cells[3].Range.Text = question.Value.Split(separator)[0];
                             Regex  regex        = new Regex("^ ?[1-9].*$");
                             string questionFull = "";
                             if (regex.IsMatch(question.Key))
                             {
                                 questionFull = "Учебный вопрос. " + question.Key + " " + question.Value.Split(separator)[0] + ".\r\n";
                             }
                             else
                             {
                                 questionFull = "Учебный вопрос " + count + ". " + question.Key + " " + question.Value.Split(separator)[0] + ".\r\n";
                             }
                             int r = 0;
                             for (int e = 0; e < questionFull.Length; e += 30)
                             {
                                 if (e > 0)
                                 {
                                     try
                                     {
                                         FindAndReplace(wordApp, "{id:questionOfLesson}", questionFull.Substring(e, 30) + "{id:questionOfLesson}");
                                     }
                                     catch (Exception q)
                                     {
                                         break;
                                     }
                                 }
                                 else
                                 {
                                     FindAndReplace(wordApp, "{id:questionOfLesson}", questionFull.Substring(e, 30) + "{id:questionOfLesson}");
                                 }
                                 r = e;
                             }
                             r += 30;
                             FindAndReplace(wordApp, "{id:questionOfLesson}", questionFull.Substring(r) + "\r\n{id:contentOfQuestion}");
                             int    w    = 0;
                             string temp = question.Value.Split(separator)[1];
                             if (temp.Length > 30)
                             {
                                 for (int z = 0; z < temp.Length; z += 30)
                                 {
                                     if (z > 0)
                                     {
                                         try
                                         {
                                             FindAndReplace(wordApp, "{id:contentOfQuestion}", temp.Substring(z, 30) + "{id:contentOfQuestion}");
                                         }
                                         catch (Exception q)
                                         {
                                             break;
                                         }
                                     }
                                     else
                                     {
                                         FindAndReplace(wordApp, "{id:contentOfQuestion}", temp.Substring(z, 30) + "{id:contentOfQuestion}");
                                     }
                                     w = z;
                                 }
                                 FindAndReplace(wordApp, "{id:contentOfQuestion}", temp.Substring(w) + "\r\n{id:questionOfLesson}\r\n");
                                 temporary = newRow;
                                 count++;
                             }
                             else
                             {
                                 FindAndReplace(wordApp, "{id:contentOfQuestion}", temp.Substring(w) + "\r\n{id:questionOfLesson}\r\n");
                                 count++;
                             }
                         }
                         Object   missing   = System.Reflection.Missing.Value;
                         Word.Row newRowENd = table.Rows.Add(ref missing);
                         newRowENd.Cells[1].Range.Text = "3";
                         newRowENd.Cells[2].Range.Text = "Заключение";
                         newRowENd.Cells[3].Range.Text = (string)keyValuePairs["{id:conclution}"].ToString().Split(separator)[0] + " мин";
                     }
                     else if (range.Text.Contains("{id:goal}"))
                     {
                         FindAndReplace(wordApp, "{id:goal}", "");
                         int count = 1;
                         foreach (string goal in (List <string>)keyValuePairs["{id:goal}"])
                         {
                             Object   oMissing = System.Reflection.Missing.Value;
                             Word.Row newRow   = table.Rows.Add(ref oMissing);
                             newRow.Cells[1].Range.Text = count + "";
                             newRow.Cells[2].Range.Text = goal;
                             count++;
                         }
                     }
                 }
             }
         }
         FindAndReplace(wordApp, "{id:adjunct}", "");
         FindAndReplace(wordApp, "{id:questionOfLesson}", "");
         WordAPI.SaveFile(doc);
         WordAPI.Close(doc);
         updatePlan(keyValuePairs);
     }
     catch (Exception e)
     {
         doc.Close();
         new ExceptionWindow()
         .Show();
     }
 }
        public List <Discipline> ParsePlan()
        {
            List <Discipline> disciplinesCopy = new List <Discipline>(disciplenes);

            //try {
            for (int j = 1; j < table.Count; j++)
            {
                Word.Range range = table[j].Range;
                Word.Cells cells = range.Cells;
                string     key   = "Знать";
                Dictionary <string, List <string> > requirementsForStudent = new Dictionary <string, List <string> >();
                requirementsForStudent.Add("Знать", new List <string>());
                requirementsForStudent.Add("Уметь", new List <string>());
                requirementsForStudent.Add("Владеть", new List <string>());
                string cell1 = cells[1].Range.Text.Trim();
                if (cell1.StartsWith("В результате изучения"))
                {
                    foreach (Discipline disciplene in disciplenes)
                    {
                        if (cells[1].Range.Text.Contains(disciplene.Name))
                        {
                            string temporary = "";
                            for (int i = 1; i <= cells.Count; i++)
                            {
                                Word.Cell  cell        = cells[i];
                                Word.Range updateRange = cell.Range;
                                string     text        = updateRange.Text;
                                text = text.Replace("\v", "");
                                text = text.Replace("\r", "");
                                text = text.Replace("\a", "");
                                text = text.Trim();
                                if (text.ToLower().Equals("знать:"))
                                {
                                    temporary = "знать:";
                                    continue;
                                }
                                else if (text.ToLower().Equals("уметь:"))
                                {
                                    temporary = "уметь:";
                                    continue;
                                }
                                else if (text.ToLower().Equals("владеть:"))
                                {
                                    temporary = "владеть:";
                                    continue;
                                }
                                text = text.Replace(";", "");
                                text = text.Replace(".", "");
                                if (temporary.Equals("знать:"))
                                {
                                    disciplinesCopy.Find(x => x.Name.Equals(disciplene.Name)).RequirementsForStudent["Знать:"].Add(text);
                                }
                                else if (temporary.Equals("уметь:"))
                                {
                                    disciplinesCopy.Find(x => x.Name.Equals(disciplene.Name)).RequirementsForStudent["Уметь:"].Add(text);
                                }
                                else if (temporary.Equals("владеть:"))
                                {
                                    disciplinesCopy.Find(x => x.Name.Equals(disciplene.Name)).RequirementsForStudent["Владеть:"].Add(text);
                                }
                            }
                        }
                    }
                }
            }
            disciplenes = getMethodicalInstructionsForRest(disciplinesCopy);

            WordAPI.Close(doc);
            //}
            //catch (Exception e)
            //{
            //    doc.Close();
            //    new ExceptionWindow()
            //        .Show();
            //}
            return(disciplenes);
        }