Example #1
0
        public void AddFile()
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            if (openFileDialog.ShowDialog().Value)
            {
                NameItemDialog nameDialog   = new NameItemDialog(DialogOwner, "New File");
                bool?          dialogResult = nameDialog.ShowDialog();
                if (dialogResult.HasValue && dialogResult.Value)
                {
                    FileBlob file = new FileBlob(UniverseVm.Model.Connection);
                    file.Name       = nameDialog.UserInput;
                    file.FileName   = Path.GetFileName(openFileDialog.FileName);
                    file.UniverseId = UniverseVm.Model.id;

                    string extension = Path.GetExtension(openFileDialog.FileName).ToLower();

                    if (extension == ".png")
                    {
                        file.FileType = FileBlob.FILE_TYPE_PNG;
                    }
                    else if (extension == ".jpg" || extension == ".jpeg")
                    {
                        file.FileType = FileBlob.FILE_TYPE_JPEG;
                    }
                    else if (extension == ".dotx")
                    {
                        file.FileType = FileBlob.FILE_TYPE_TEMPLATE;
                    }
                    else
                    {
                        file.FileType = FileBlob.FILE_TYPE_OTHER;
                    }

                    if (Files.Count > 0)
                    {
                        file.SortIndex = Files.Max(i => i.Model.SortIndex) + 1;
                    }
                    file.Create();
                    file.LoadFile(openFileDialog.FileName);

                    FileBlobViewModel vm = new FileBlobViewModel(file, this);
                    Files.Add(vm);
                }
            }
        }
Example #2
0
        public void Load()
        {
            Files.Clear();

            var files = FileBlob.GetAllFileBlobs(UniverseVm.Model.Connection).Where(i => i.UniverseId == UniverseVm.Model.id);

            foreach (var f in files)
            {
                FileBlobViewModel vm = new FileBlobViewModel(f, this);
                Files.Add(vm);
            }
            if (Files.Count > 0)
            {
                SelectedFile = Files[0];
            }
            else
            {
                SelectedFile = null;
            }
        }
Example #3
0
        public void ExportToWord()
        {
            IExportToWordDocument item = SelectedTreeViewItem as IExportToWordDocument;

            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter = "Word Document (*.docx)|*.docx";
            bool?result = saveFileDialog.ShowDialog();

            if (!result.Value)
            {
                return;
            }

            var templates = FileBrowserViewModel.Files.Where(i => i.Model.FileType == FileBlob.FILE_TYPE_TEMPLATE).ToList();

            if (templates.Count > 0)
            {
                FileBlobViewModel defaultTemplate = templates.SingleOrDefault(i => i.Model.id == Model.DefaultTemplateId);

                SelectDocTemplateDialog dialog = new SelectDocTemplateDialog(DialogOwner, templates, defaultTemplate);
                result = dialog.ShowDialog();
                if (result.HasValue && result.Value)
                {
                    defaultTemplate = dialog.SelectedTemplate;
                    string templatePath = null;

                    // Save selected template as default.
                    if (defaultTemplate != null)
                    {
                        Model.DefaultTemplateId = defaultTemplate.Model.id;
                        Model.Save();

                        // Save template to a temp file.
                        templatePath = Path.GetTempFileName();
                        defaultTemplate.Model.ExportToFile(templatePath);
                    }

                    FlowDocumentExporter.ExportItem(item, saveFileDialog.FileName, templatePath);

                    if (templatePath != null)
                    {
                        File.Delete(templatePath);
                    }

                    MessageBoxResult msgResult = MessageBox.Show("Export complete. Open file now?", "Export Completed", MessageBoxButton.YesNo, MessageBoxImage.Question);
                    if (msgResult == MessageBoxResult.Yes)
                    {
                        Process.Start(new ProcessStartInfo(saveFileDialog.FileName)
                        {
                            UseShellExecute = true
                        });
                    }
                }
            }
            else
            {
                FlowDocumentExporter.ExportItem(item, saveFileDialog.FileName, null);
                MessageBoxResult msgResult = MessageBox.Show("Export complete. Open file now?", "Export Completed", MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (msgResult == MessageBoxResult.Yes)
                {
                    Process.Start(new ProcessStartInfo(saveFileDialog.FileName)
                    {
                        UseShellExecute = true
                    });
                }
            }
        }