Example #1
0
        private void OpenProjectMethod(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            bool?result = dlg.ShowDialog();

            try
            {
                if (!(result.HasValue && result == true))
                {
                    InformDialogUtil.ShowWarning("Файл проекта не выбран.");
                }
                else if (!dlg.FileName.EndsWith(ZipWrapper.ProgramArhiveExtension))
                {
                    InformDialogUtil.ShowError("Данный файл не является файлом проекта.");
                }
                else if (openedProjectMarkStorage.ContainsKey(dlg.FileName))
                {
                    InformDialogUtil.ShowError("Данный файл проекта уже открыт в программе.");
                }
                else
                {
                    openProjectFunction(dlg.FileName);
                }
            }
            catch (Exception)
            {
                openedProjectMarkStorage.Remove(dlg.FileName);
                openedProjectAuxiliaryStorage.Remove(dlg.FileName);
                openedProjectDictWordStorage.Remove(dlg.FileName);

                InformDialogUtil.ShowError("Файл проекта повреждён.");
            }
        }
Example #2
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 #3
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());
            }
        }
Example #4
0
        private void СloseCurrentProjectMethod(object sender, RoutedEventArgs e)
        {
            TabItem selectedItem = (TabItem)openedProjectTabControl.SelectedItem;

            if (selectedItem != null)
            {
                openedProjectMarkStorage.Remove(selectedItem.Uid);
                openedProjectAuxiliaryStorage.Remove(selectedItem.Uid);
                openedProjectDictWordStorage.Remove(selectedItem.Uid);
                openedProjectTabControl.Items.Remove(openedProjectTabControl.SelectedItem);

                if (openedProjectTabControl.Items.Count == 0)
                {
                    openedProjectTabControl.Visibility = Visibility.Hidden;
                }
            }
            else
            {
                InformDialogUtil.ShowWarning("Нет открытого проекта.");
            }
        }
Example #5
0
        private void SaveProjectMethod(object sender, RoutedEventArgs e)
        {
            TabItem selectedItem = (TabItem)openedProjectTabControl.SelectedItem;

            if (selectedItem == null)
            {
                InformDialogUtil.ShowWarning("Нет открытого проекта.");

                return;
            }

            Dictionary <string, ObservableCollection <string> > dictWord;

            openedProjectDictWordStorage.TryGetValue(selectedItem.Uid, out dictWord);
            if (dictWord != null)
            {
                ZipWrapper.UpdateDictWordInProjectFileArchive(selectedItem.Uid, dictWord);

                InformDialogUtil.ShowInfo("Cловари для закладок успешно сохранены в файле проекта: " + selectedItem.Uid);
            }
        }
Example #6
0
        private void documentPathBrowseButton_Click()
        {
            TabItem selectedItem = ((TabItem)openedProjectTabControl.SelectedItem);
            Dictionary <string, FrameworkElement> auxiliaryRefs;

            openedProjectAuxiliaryStorage.TryGetValue(selectedItem.Uid, out auxiliaryRefs);

            var dlg = new System.Windows.Forms.FolderBrowserDialog();

            System.Windows.Forms.DialogResult result = dlg.ShowDialog();

            if (result == System.Windows.Forms.DialogResult.OK && !string.IsNullOrWhiteSpace(dlg.SelectedPath))
            {
                FrameworkElement outputDocPath;
                auxiliaryRefs.TryGetValue("outputDocPath", out outputDocPath);
                ((TextBox)outputDocPath).Text = dlg.SelectedPath;
            }
            else
            {
                InformDialogUtil.ShowWarning("Путь не указан.");
            }
        }
Example #7
0
        private void createProjectButton_Click(object sender, RoutedEventArgs e)
        {
            var fbd = new System.Windows.Forms.FolderBrowserDialog();

            System.Windows.Forms.DialogResult result = fbd.ShowDialog();

            if (result == System.Windows.Forms.DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath))
            {
                string projectArchiveName = ZipWrapper.CreateProjectFileArchiveAndGetResultFilePath(projectModel, fbd.SelectedPath);

                InformDialogUtil.ShowInfo("Файл проекта создан:  \r\n" + projectArchiveName);

                Close();
                Owner.Close();
                Owner.Owner.Close();
                projectModel.openProjectDelegate(projectArchiveName);
            }
            else
            {
                InformDialogUtil.ShowWarning("Не указана директория для сохранения файла проекта.");
            }
        }