private void btnWriteToFile_Queries_Click(object sender, EventArgs e) { try { if (bCheckConnection) { CItemsForWriteToFile cItemsForWriteToFile = new CItemsForWriteToFile(); cItemsForWriteToFile.testCaseList = testCaseListFor_clbQueriesTestCases; cItemsForWriteToFile.checkedListBox = clbQueriesTestCases; Thread thread = new Thread(new ParameterizedThreadStart(WriteToFile)); thread.Start(cItemsForWriteToFile); } else { MessageBox.Show("Подключение не установлено!"); } } catch (NullReferenceException ex) { MessageBox.Show(ex.Message); } }
int nToolTipIndex; // Выбранный элемент в CheckedListBox #endregion Variables #region Functions /// <summary> /// Функция для записи списка тест кейсов в Word /// </summary> private void WriteToFile(object objectClass) { try { CItemsForWriteToFile cItemsForWriteToFile = (CItemsForWriteToFile)objectClass; // Пока идет запись тест кейсов в файл Word // отключить кнопки btnWriteInFile.Invoke((MethodInvoker) delegate { btnWriteInFile.Enabled = false; }); btnWriteToFile_Queries.Invoke((MethodInvoker) delegate { btnWriteToFile_Queries.Enabled = false; }); progressBar2.Invoke((MethodInvoker) delegate { progressBar2.Show(); progressBar2.Minimum = 0; progressBar2.Maximum = 100; progressBar2.Value = 0; }); Word.Application application = new Word.Application(); Word.Document document = application.Documents.Add(); Word.Range range = document.Range(); Word.Paragraph paragraph = document.Paragraphs.Add(); progressBar2.Invoke((MethodInvoker) delegate { progressBar2.Value = 30; }); Word.ListGallery listGallery = application.ListGalleries[WdListGalleryType.wdOutlineNumberGallery]; Word.ListTemplate listTemplate = listGallery.ListTemplates[5]; listTemplate.ListLevels[1].NumberPosition = application.CentimetersToPoints(0f); listTemplate.ListLevels[1].Font.Size = 11f; progressBar2.Invoke((MethodInvoker) delegate { progressBar2.Value = 40; }); listTemplate.ListLevels[2].NumberPosition = application.CentimetersToPoints(0.63f); listTemplate.ListLevels[2].Font.Size = 11f; progressBar2.Invoke((MethodInvoker) delegate { progressBar2.Value = 50; progressBar2.Step = cItemsForWriteToFile.testCaseList.Count; }); // Выполнить запись в файл Word для выбранных элементов из clbTestCases foreach (int Index in cItemsForWriteToFile.checkedListBox.CheckedIndices) { wordFileClass.CreateMultiLevelList(paragraph, listTemplate, cItemsForWriteToFile.testCaseList, Index); progressBar2.Invoke((MethodInvoker) delegate { progressBar2.PerformStep(); }); } paragraph.Range.SetListLevel(1); progressBar2.Invoke((MethodInvoker) delegate { progressBar2.Value = 100; }); // Показать результат записи в файл progressBar2.Invoke((MethodInvoker) delegate { progressBar2.Hide(); application.Visible = true; }); // Активировать кнопки в конце выполнения записи в файл btnWriteInFile.Invoke((MethodInvoker) delegate { btnWriteInFile.Enabled = true; }); btnWriteToFile_Queries.Invoke((MethodInvoker) delegate { btnWriteToFile_Queries.Enabled = true; }); } catch { // Показать результат записи в файл progressBar2.Invoke((MethodInvoker) delegate { progressBar2.Value = 0; progressBar2.Hide(); progressBar2.Hide(); }); // Активировать кнопки в конце выполнения записи в файл btnWriteInFile.Invoke((MethodInvoker) delegate { btnWriteInFile.Enabled = true; }); btnWriteToFile_Queries.Invoke((MethodInvoker) delegate { btnWriteToFile_Queries.Enabled = true; }); } }