/// <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); } }
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(); }
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(); }
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); }
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()); }
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); } } }
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; } }
public void Export() { SaveFileDialogService.Filter = "PDF files (*.pdf)|*.pdf"; if (SaveFileDialogService.ShowDialog()) { IsBusy = true; ExportToPdf(serverConnection, SaveFileDialogService.GetFullFileName(), SelectedReportObject.Id); } }
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); } }
public void Export() { SaveFileDialogService.Filter = "PDF files (*.pdf)|*.pdf"; if (SaveFileDialogService.ShowDialog()) { IsBusy = true; ExportReport(new PdfExportOptions()) .ContinueWith(ExportToPdfCompleted, TaskScheduler.FromCurrentSynchronizationContext()); } }
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); } }
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); } }
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); } } }
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()); } } }
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); } } }
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; } }
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); } } }