50 lines
1.3 KiB
C#
50 lines
1.3 KiB
C#
using ApplicationServices;
|
|
using LibationWinForms.AvaloniaUI.Views.Dialogs;
|
|
using System;
|
|
using System.Linq;
|
|
|
|
namespace LibationWinForms.AvaloniaUI.Views
|
|
{
|
|
//DONE
|
|
public partial class MainWindow
|
|
{
|
|
private void Configure_Export() { }
|
|
|
|
public async void exportLibraryToolStripMenuItem_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
var saveFileDialog = new System.Windows.Forms.SaveFileDialog
|
|
{
|
|
Title = "Where to export Library",
|
|
Filter = "Excel Workbook (*.xlsx)|*.xlsx|CSV files (*.csv)|*.csv|JSON files (*.json)|*.json" // + "|All files (*.*)|*.*"
|
|
};
|
|
|
|
if (saveFileDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
|
|
return;
|
|
|
|
// FilterIndex is 1-based, NOT 0-based
|
|
switch (saveFileDialog.FilterIndex)
|
|
{
|
|
case 1: // xlsx
|
|
default:
|
|
LibraryExporter.ToXlsx(saveFileDialog.FileName);
|
|
break;
|
|
case 2: // csv
|
|
LibraryExporter.ToCsv(saveFileDialog.FileName);
|
|
break;
|
|
case 3: // json
|
|
LibraryExporter.ToJson(saveFileDialog.FileName);
|
|
break;
|
|
}
|
|
|
|
await MessageBox.Show("Library exported to:\r\n" + saveFileDialog.FileName);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBoxLib.ShowAdminAlert(null, "Error attempting to export your library.", "Error exporting", ex);
|
|
}
|
|
}
|
|
}
|
|
}
|