Skip to content

Commit b149b7a

Browse files
committed
Fix: improve output location
1 parent 5c9188b commit b149b7a

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

DebitExpress.VatRelief/MainWindow.xaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
xmlns:ctrl="http://debitexpress.com/winfx/xaml/controls"
88
xmlns:attached="http://debitexpress.com/winfx/xaml/attached-properties"
99
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
10-
xmlns:dialogs="http://debitexpress.com/winfx/xaml/dialogs"
1110
mc:Ignorable="d"
1211
ResizeMode="NoResize"
1312
Title="DebitExpress VAT Relief"

DebitExpress.VatRelief/MainWindow.xaml.cs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
2+
using System.Diagnostics;
23
using System.IO;
34
using System.Linq;
5+
using System.Reflection;
46
using System.Windows;
57
using DebitExpress.VatRelief.Models;
68
using DebitExpress.VatRelief.Utils;
@@ -93,9 +95,9 @@ private async void OnGenerate(object sender, RoutedEventArgs e)
9395
return;
9496
}
9597

96-
const string loc = @"%USERPROFILE%\Desktop";
97-
var path = Environment.ExpandEnvironmentVariables(loc);
9898
ExcelData data = result;
99+
var path = Path.Combine(Path.GetTempPath(), "vat-relief", Guid.NewGuid().ToString().Replace("-", string.Empty));
100+
Directory.CreateDirectory(path);
99101

100102
var generator = new DatFileGenerator();
101103
var generateResult = await generator.GenerateAsync(data, path);
@@ -108,17 +110,34 @@ private async void OnGenerate(object sender, RoutedEventArgs e)
108110
var reconWriter = new ExcelReconWriter();
109111
var writeResult = reconWriter.WriteReconciliationReport(data, path);
110112

111-
if (writeResult.IsSuccess)
112-
NotifyResult("Files generated successfully");
113-
else
113+
if (writeResult.IsFaulted)
114+
{
114115
NotifyErrorResult(writeResult.ToString());
116+
return;
117+
}
118+
119+
NotifyResult("Files generated successfully");
120+
OpenFolder(path);
115121
}
116122
finally
117123
{
118124
GenerateButton.IsEnabled = true;
119125
}
120126
}
121127

128+
private void OpenFolder(string path)
129+
{
130+
if (!Directory.Exists(path)) return;
131+
132+
var startInfo = new ProcessStartInfo
133+
{
134+
Arguments = path,
135+
FileName = "explorer.exe"
136+
};
137+
138+
Process.Start(startInfo);
139+
}
140+
122141
private void NotifyErrorResult(string message)
123142
{
124143
_messageQueue.Clear();

DebitExpress.VatRelief/Utils/DatFileGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public async Task<Result> GenerateAsync(ExcelData data, string path)
5656

5757
private async Task GenerateSalesAsync(Info info, DateTime month, IReadOnlyCollection<Sales> items, string path)
5858
{
59-
var datFileFolder = Path.Combine(path, "DAT FILES");
59+
var datFileFolder = Path.Combine(path, "DAT Files");
6060
Directory.CreateDirectory(datFileFolder);
6161

6262
var fileName = $"{info.Tin}S{month:MM}{month:yyyy}.DAT";

DebitExpress.VatRelief/Utils/ExcelReconWriter.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ public Result WriteReconciliationReport(ExcelData data, string path)
1313
{
1414
try
1515
{
16-
var fileFolder = Path.Combine(path, "EXCEL");
17-
Directory.CreateDirectory(fileFolder);
16+
Directory.CreateDirectory(path);
1817

1918
var fileName = $"{Extensions.QuarterRangeString(data.Info.Month, data.Info.Year)}.xlsx";
20-
var fullPath = Path.Combine(fileFolder, fileName);
19+
var fullPath = Path.Combine(path, fileName);
2120

2221
var workbook = new XLWorkbook();
2322
var salesSheet = workbook.Worksheets.Add("SALES");

0 commit comments

Comments
 (0)