new feature: json export
This commit is contained in:
parent
2795690199
commit
b22c35f841
@ -138,6 +138,15 @@ namespace ApplicationServices
|
|||||||
csv.WriteRecords(dtos);
|
csv.WriteRecords(dtos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void ToJson(string saveFilePath)
|
||||||
|
{
|
||||||
|
using var context = DbContexts.GetContext();
|
||||||
|
var dtos = context.GetLibrary_Flat_NoTracking().ToDtos();
|
||||||
|
|
||||||
|
var json = Newtonsoft.Json.JsonConvert.SerializeObject(dtos, Newtonsoft.Json.Formatting.Indented);
|
||||||
|
System.IO.File.WriteAllText(saveFilePath, json);
|
||||||
|
}
|
||||||
|
|
||||||
public static void ToXlsx(string saveFilePath)
|
public static void ToXlsx(string saveFilePath)
|
||||||
{
|
{
|
||||||
using var context = DbContexts.GetContext();
|
using var context = DbContexts.GetContext();
|
||||||
@ -220,13 +229,5 @@ namespace ApplicationServices
|
|||||||
public bool IsApproved { get; set; }
|
public bool IsApproved { get; set; }
|
||||||
public string Comment { get; set; }
|
public string Comment { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ToJson(string saveFilePath)
|
|
||||||
{
|
|
||||||
using var context = DbContexts.GetContext();
|
|
||||||
|
|
||||||
var library = context.GetLibrary_Flat_NoTracking();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,7 +13,7 @@
|
|||||||
<!-- <PublishSingleFile>true</PublishSingleFile> -->
|
<!-- <PublishSingleFile>true</PublishSingleFile> -->
|
||||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||||
|
|
||||||
<Version>4.0.4.4</Version>
|
<Version>4.0.5.3</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -310,14 +310,18 @@ namespace LibationWinForms
|
|||||||
var saveFileDialog = new SaveFileDialog
|
var saveFileDialog = new SaveFileDialog
|
||||||
{
|
{
|
||||||
Title = "Where to export Library",
|
Title = "Where to export Library",
|
||||||
Filter = "CSV files (*.csv)|*.csv|All files (*.*)|*.*"
|
Filter = "CSV files (*.csv)|*.csv|JSON files (*.json)|*.json|All files (*.*)|*.*"
|
||||||
};
|
};
|
||||||
|
|
||||||
if (saveFileDialog.ShowDialog() != DialogResult.OK)
|
if (saveFileDialog.ShowDialog() != DialogResult.OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// FilterIndex is 1-based, NOT 0-based
|
||||||
switch (saveFileDialog.FilterIndex)
|
switch (saveFileDialog.FilterIndex)
|
||||||
{
|
{
|
||||||
|
case 2: // json
|
||||||
|
LibraryExporter.ToJson(saveFileDialog.FileName);
|
||||||
|
break;
|
||||||
case 1: // csv
|
case 1: // csv
|
||||||
default:
|
default:
|
||||||
LibraryExporter.ToCsv(saveFileDialog.FileName);
|
LibraryExporter.ToCsv(saveFileDialog.FileName);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user