/// <summary>
        /// Export Grid
        /// </summary>
        /// <param name="fileType"></param>
        public void ExportGrid(ExportType fileType)
        {
            try
            {
                switch (fileType)
                {
                case ExportType.XLSX:
                    SaveFileDialogService.DefaultExt = "xlsx";
                    SaveFileDialogService.Filter     = "Excel 2007+|*.xlsx";
                    break;

                case ExportType.PDF:
                    SaveFileDialogService.DefaultExt = "pdf";
                    SaveFileDialogService.Filter     = "PDF|*.pdf";
                    break;
                }

                if (SaveFileDialogService.ShowDialog())
                {
                    var fileName = SaveFileDialogService.GetFullFileName();
                    ExportGridService.ExportTo(fileType, fileName);
                    if (MessageBoxService.ShowMessage("¿Desea abrir el archivo?", "Operación Exitosa", MessageButton.YesNo) == MessageResult.Yes)
                    {
                        var process = new Process();
                        process.StartInfo.UseShellExecute = true;
                        process.StartInfo.FileName        = fileName;
                        process.Start();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBoxService.ShowMessage(GetStringValue(Next.Enums.Enums.MessageError.ExportError), ex.Message);
            }
        }
コード例 #2
0
        public async Task Export(ProgressDialogController progress)
        {
            if (!Exists)
            {
                return;
            }

            await Task.Run(() =>
            {
                // export bacpac
                var bacpacName = $"{DateTime.Now:yyyyMMdd_HHmm}.bacpac";
                _dacService.ProgressChanged += (sender, args) => progress.SetMessage($"{args.Status} : {args.Message}");
                _dacService.ExportBacpac(bacpacName, _databaseName);

                // save file
                var filePath = Path.Combine(Directory.GetCurrentDirectory(), bacpacName);
                var result   = new SaveFileDialogService().Show(
                    bacpacName
                    , fileName =>
                {
                    if (!File.Exists(fileName))
                    {
                        File.Move(filePath, fileName);
                    }
                }
                    , () => File.Delete(filePath)
                    );
                progress.SetMessage(result ? "Success" : "Fail");
            });

            await progress.CloseAsync();
        }
コード例 #3
0
ファイル: App.xaml.cs プロジェクト: sschottler/MVVMSample
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            MainWindowView view = new MainWindowView();

            //inject dependencies (could use a dependency injection framework for this, but not strictly necessary):
            ICustomerRepository    customerRepository    = new CustomerRepository();
            IProductRepository     productRepository     = new ProductRepository();
            ILocalizationService   localizationService   = new LocalizationService();
            IUpdateService         updateService         = new UpdateService();
            IMessageBoxService     messageBoxService     = new MessageBoxService();
            IDialogService         dialogService         = new DialogService();
            IAppDialogService      appDialogService      = new AppDialogService(dialogService, localizationService, () => new LanguageSelectionView(), () => new AboutView());
            IOpenFileDialogService openFileDialogService = new OpenFileDialogService();
            ISaveFileDialogService saveFileDialogService = new SaveFileDialogService();

            MainWindowViewModel viewModel = new MainWindowViewModel(
                customerRepository,
                productRepository,
                updateService,
                messageBoxService,
                appDialogService,
                openFileDialogService,
                saveFileDialogService,
                localizationService);

            //could also be wired up and handled in MainWindow.xaml.cs code behind (maybe in DataContextChanged override for example)
            //also could have a controller class listening to this event
            viewModel.RequestClose += (s, args) => view.Close();

            view.DataContext = viewModel;
            view.Show();
        }
コード例 #4
0
ファイル: MainWindowViewModel.cs プロジェクト: jp2masa/Movere
        public MainWindowViewModel(
            Func <Task> avaloniaOpenFile,
            Func <Task> avaloniaSaveFile,
            MessageDialogService messageDialogService,
            ContentDialogService <CustomContentViewModel> contentDialogService,
            OpenFileDialogService openFileDialogService,
            SaveFileDialogService saveFileDialogService,
            PrintDialogService printDialogService)
        {
            _messageDialogService = messageDialogService;
            _contentDialogService = contentDialogService;

            _openFileDialogService = openFileDialogService;
            _saveFileDialogService = saveFileDialogService;

            _printDialogService = printDialogService;

            ShowMessageCommand       = ReactiveCommand.Create(ShowMessageAsync);
            ShowCustomContentCommand = ReactiveCommand.Create(ShowCustomContentAsync);

            OpenFileCommand = ReactiveCommand.Create(OpenFileAsync);
            SaveFileCommand = ReactiveCommand.Create(SaveFileAsync);

            PrintCommand = ReactiveCommand.Create(PrintAsync);

            AvaloniaOpenFileCommand = ReactiveCommand.Create(avaloniaOpenFile);
            AvaloniaSaveFileCommand = ReactiveCommand.Create(avaloniaSaveFile);
        }
コード例 #5
0
        public void DefaultValues()
        {
            SaveFileDialogService service = new SaveFileDialogService();

            Assert.AreEqual(true, service.AddExtension);
            Assert.AreEqual(true, service.AutoUpgradeEnabled);
            Assert.AreEqual(false, service.CheckFileExists);
            Assert.AreEqual(true, service.CheckPathExists);
            Assert.AreEqual(false, service.CreatePrompt);
            Assert.AreEqual(true, service.DereferenceLinks);
            Assert.AreEqual(string.Empty, service.InitialDirectory);
            Assert.AreEqual(true, service.OverwritePrompt);
            Assert.AreEqual(false, service.RestoreDirectory);
            Assert.AreEqual(false, service.ShowHelp);
            Assert.AreEqual(false, service.SupportMultiDottedExtensions);
            Assert.AreEqual(string.Empty, service.Title);
            Assert.AreEqual(true, service.ValidateNames);
            Assert.AreEqual(string.Empty, service.DefaultExt);
            Assert.AreEqual(string.Empty, service.DefaultFileName);
            Assert.AreEqual(string.Empty, service.Filter);
            Assert.AreEqual(1, service.FilterIndex);

            ISaveFileDialogService iService = service;

            Assert.IsNull(iService.File);
            Assert.AreEqual(string.Empty, iService.SafeFileName());
        }
コード例 #6
0
        public void ExportGrid(ExportType fileType)
        {
            switch (fileType)
            {
            case ExportType.XLSX:
                SaveFileDialogService.DefaultExt = "xlsx";
                SaveFileDialogService.Filter     = "Excel 2007+|*.xlsx";
                break;

            case ExportType.PDF:
                SaveFileDialogService.DefaultExt = "pdf";
                SaveFileDialogService.Filter     = "PDF|*.pdf";
                break;
            }

            if (SaveFileDialogService.ShowDialog())
            {
                var fileName = SaveFileDialogService.GetFullFileName();
                ExportService.ExportTo(fileType, fileName);
                if (MessageBoxService.ShowMessage("Would you like to open the file?", "Export finished",
                                                  MessageButton.YesNo) == MessageResult.Yes)
                {
                    Process.Start(fileName);
                }
            }
        }
コード例 #7
0
        public override void OnFrameworkInitializationCompleted()
        {
            base.OnFrameworkInitializationCompleted();

            if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
            {
                var mainWindow = new MainWindow();

                var messageDialogService = new MessageDialogService(mainWindow);

                var contentDialogService = new ContentDialogService <CustomContentViewModel>(
                    mainWindow,
                    new CustomContentViewResolver());

                var openFileDialogService = new OpenFileDialogService(mainWindow);
                var saveFileDialogService = new SaveFileDialogService(mainWindow);

                var printDialogService = new PrintDialogService(mainWindow);

                mainWindow.DataContext = new MainWindowViewModel(
                    () => AvaloniaOpenFile(mainWindow),
                    () => AvaloniaSaveFile(mainWindow),
                    messageDialogService,
                    contentDialogService,
                    openFileDialogService,
                    saveFileDialogService,
                    printDialogService);

                desktop.MainWindow = mainWindow;
            }
        }
コード例 #8
0
 public void Export()
 {
     SaveFileDialogService.Filter = "PDF files (*.pdf)|*.pdf";
     if (SaveFileDialogService.ShowDialog())
     {
         IsBusy = true;
         ExportToPdf(serverConnection, SaveFileDialogService.GetFullFileName(), SelectedReportObject.Id);
     }
 }
コード例 #9
0
        private void SaveToFile(List <string> list)
        {
            var dialog   = new SaveFileDialogService(".txt", "Text documents (.txt)|*.txt");
            var filePath = dialog.CreateAndOpenFile();

            if (!string.IsNullOrEmpty(filePath))
            {
                TextFile.WriteToFile(list, filePath);
            }
        }
コード例 #10
0
 public void Export()
 {
     SaveFileDialogService.Filter = "PDF files (*.pdf)|*.pdf";
     if (SaveFileDialogService.ShowDialog())
     {
         IsBusy = true;
         ExportReport(new PdfExportOptions())
         .ContinueWith(ExportToPdfCompleted, TaskScheduler.FromCurrentSynchronizationContext());
     }
 }
コード例 #11
0
        public void ExportToExcel()
        {
            SaveFileDialogService.Filter = "Excel files (*.xlsx)|*.xlsx";
            if (SaveFileDialogService.ShowDialog())
            {
                IXlExporter exporter    = XlExport.CreateExporter(XlDocumentFormat.Xlsx);
                string[]    columnNames = new string[] { "Word", "Definition" };
                string      fileName    = SaveFileDialogService.GetFullFileName();

                using (FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite))
                {
                    using (IXlDocument document = exporter.CreateDocument(stream))
                    {
                        using (IXlSheet sheet = document.CreateSheet())
                        {
                            sheet.Name = "Dictionary";

                            using (IXlColumn column = sheet.CreateColumn())
                            {
                                column.WidthInCharacters    = 25;
                                column.Formatting           = new XlCellFormatting();
                                column.Formatting.Alignment = new XlCellAlignment();
                                column.Formatting.Alignment.VerticalAlignment = XlVerticalAlignment.Center;
                            }

                            using (IXlColumn column = sheet.CreateColumn())
                            {
                                column.WidthInCharacters             = 100;
                                column.Formatting                    = new XlCellFormatting();
                                column.Formatting.Alignment          = new XlCellAlignment();
                                column.Formatting.Alignment.WrapText = true;
                            }

                            IXlTable table;
                            using (IXlRow row = sheet.CreateRow())
                                table = row.BeginTable(columnNames, true);

                            foreach (DictionaryBookmark bookmark in DictionaryBookmarksView)
                            {
                                using (IXlRow row = sheet.CreateRow())
                                    row.BulkCells(new string[] { bookmark.Word, bookmark.Definition }, null);
                            }

                            using (IXlRow row = sheet.CreateRow())
                                row.EndTable(table, false);

                            table.Style.ShowFirstColumn = true;
                        }
                    }
                }

                Process.Start(fileName);
            }
        }
コード例 #12
0
 void ExportToPdfCompleted(Task <byte[]> task)
 {
     IsBusy = false;
     if (TaskIsFauledOrCancelled(task, "Export"))
     {
         return;
     }
     using (Stream stream = SaveFileDialogService.OpenFile()) {
         stream.Write(task.Result, 0, task.Result.Length);
     }
 }
コード例 #13
0
        public void SaveImage(BitmapImage image, object item)
        {
            SaveFileDialogService.Filter          = "Image File (.jpg)|*.jpg";
            SaveFileDialogService.DefaultFileName = Regex.Replace(item.ToString(), InvalidFileNameChars, "");

            if (SaveFileDialogService.ShowDialog())
            {
                BitmapEncoder encoder = new JpegBitmapEncoder();
                encoder.Frames.Add(BitmapFrame.Create(image));

                using (Stream stream = SaveFileDialogService.OpenFile())
                {
                    encoder.Save(stream);
                }
            }
        }
コード例 #14
0
        public void ExportToPdf(IPrintableControl control)
        {
            PrintableControlLink link = new PrintableControlLink(control);

            link.Margins = new Margins(50, 50, 50, 50);

            if (ExportHelper.Export(ExportFormat.Pdf, link.PrintingSystem) == true)
            {
                SaveFileDialogService.Filter = "PDF File (.pdf)|*.pdf";

                if (SaveFileDialogService.ShowDialog())
                {
                    link.ExportToPdf(SaveFileDialogService.GetFullFileName());
                    OpenExternalApplication(SaveFileDialogService.GetFullFileName());
                }
            }
        }
コード例 #15
0
 public void Save()
 {
     SaveFileDialogService.DefaultExt      = DefaultExt;
     SaveFileDialogService.DefaultFileName = DefaultFileName;
     SaveFileDialogService.Filter          = Filter;
     SaveFileDialogService.FilterIndex     = FilterIndex;
     DialogResult = SaveFileDialogService.ShowDialog();
     if (!DialogResult)
     {
         ResultFileName = string.Empty;
     }
     else
     {
         using (var stream = new StreamWriter(SaveFileDialogService.OpenFile())) {
             stream.Write(FileBody);
         }
     }
 }
コード例 #16
0
        public void Export(ExportType type)
        {
            switch (type)
            {
            case ExportType.PDF:
                SaveFileDialogService.Filter = "PDF files|*.pdf";
                if (SaveFileDialogService.ShowDialog())
                {
                    ExportService.ExportToPDF(SaveFileDialogService.GetFullFileName());
                }
                break;

            case ExportType.XLSX:
                SaveFileDialogService.Filter = "Excel 207 files|*.xlsx";
                if (SaveFileDialogService.ShowDialog())
                {
                    ExportService.ExportToPDF(SaveFileDialogService.GetFullFileName());
                }
                break;
            }
        }
コード例 #17
0
        public async Task Download(Subtitle subtitle)
        {
            string path = null;

            if (!String.IsNullOrWhiteSpace(FilePath))
            {
                string folderPath = Path.GetDirectoryName(FilePath);
                if (Directory.Exists(folderPath))
                {
                    path = folderPath;
                }
            }
            else if (!String.IsNullOrWhiteSpace(LocalPath))
            {
                if (Directory.Exists(LocalPath))
                {
                    path = LocalPath;
                }
            }

            SaveFileDialogService.Filter = SubtitleFilter;
            if (SaveFileDialogService.ShowDialog(null, path, subtitle.SubtitleFileName))
            {
                try
                {
                    await SubtitleClient.DownloadSubtitleToPath(SaveFileDialogService.File.DirectoryName, subtitle, SaveFileDialogService.SafeFileName());
                }
                catch (Exception e)
                {
                    Journal.WriteError(e);

                    MessageViewModel viewModel = MessageViewModel.FromException(e);
                    Messenger.Default.Send(viewModel);
                }
            }
        }