Example #1
0
        private void nextButton_Click(object sender, RoutedEventArgs e)
        {
            // TODO: Use binding instead.
            projectModel.name             = projectNameTextBox.Text.Trim();
            projectModel.templatePathText = templatePathTextBox.Text.Trim();
            projectModel.templatePaths    = new HashSet <string>(
                !projectModel.templatePathText.Equals(string.Empty)? projectModel.templatePathText.Split(';') : new string[0]);
            projectModel.templateGroups = new List <string>()
            {
                "Общие закладки"
            };
            projectModel.templateMarkSpecGroup = new Dictionary <string, string>();
            projectModel.templateMarks         = new Dictionary <string, string>();

            // TODO: Use another way for validation.
            List <string> errorEntries = new List <string>();

            if (projectModel.name.Length == 0)
            {
                errorEntries.Add("Имя проекта не указано.");
            }

            if (projectModel.templatePaths.Count == 0)
            {
                errorEntries.Add("Должен быть указан хотя бы один файл шаблона с закладками.");
            }

            try
            {
                if (errorEntries.Count != 0)
                {
                    InformDialogUtil.ShowErrorWithEntries(string.Empty, errorEntries);
                }
                else
                {
                    MicrosoftOfficeWrapper.ReadAllBookmarks(projectModel);

                    // Proceed to the next step.
                    Window nextWindow = new Step2Window(projectModel)
                    {
                        Owner = this
                    };
                    nextWindow.Show();

                    Hide();
                }
            }
            catch (FormatException f)
            {
                InformDialogUtil.ShowError(f.Message);
            }
            catch (Exception)
            {
                InformDialogUtil.ShowError("Ошибка при открытии файла шаблона.");
            }
        }
Example #2
0
        private void createDocumentButton_Click()
        {
            try
            {
                TabItem selectedItem = ((TabItem)openedProjectTabControl.SelectedItem);
                Dictionary <string, TextBox>          markValueRefs;
                Dictionary <string, FrameworkElement> auxiliaryRefs;
                openedProjectMarkStorage.TryGetValue(selectedItem.Uid, out markValueRefs);
                openedProjectAuxiliaryStorage.TryGetValue(selectedItem.Uid, out auxiliaryRefs);
                FrameworkElement outputDocPath;
                auxiliaryRefs.TryGetValue("outputDocPath", out outputDocPath);
                FrameworkElement projectFilePath;
                auxiliaryRefs.TryGetValue("projectFilePath", out projectFilePath);

                if (((TextBox)outputDocPath).Text.Length == 0)
                {
                    InformDialogUtil.ShowError("Не указан путь сохранения.");

                    return;
                }

                List <string> outputFilePaths = ZipWrapper.ExtractTemplateAndGetResultFilePaths(((TextBox)projectFilePath).Text, ((TextBox)outputDocPath).Text, selectedItem.Header.ToString());

                MicrosoftOfficeWrapper.UpdateBookmarkValuesAndSaveDocument(outputFilePaths, markValueRefs);

                // Clear TextBox Elements.
                foreach (var mvr in markValueRefs)
                {
                    bool?isChecked = ((CheckBox)auxiliaryRefs[mvr.Key]).IsChecked;
                    if (isChecked.Value == false)
                    {
                        mvr.Value.Text = string.Empty;
                    }
                }

                InformDialogUtil.ShowInfoWithEntries("Создание документа(ов) выполнено успешно:", outputFilePaths);
            }
            catch (Exception ex)
            {
                InformDialogUtil.ShowError("Ошибка на этапе создания документа: \r\n" + ex.ToString());
            }
        }