Skip to content

Commit 771d967

Browse files
committed
Feat: implement template download
1 parent 098a516 commit 771d967

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed

DebitExpress.VatRelief/DebitExpress.VatRelief.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
<ItemGroup>
2020
<Resource Include="favicon.png" />
21+
<None Remove="template.xlsx" />
22+
<EmbeddedResource Include="template.xlsx" />
2123
</ItemGroup>
2224

2325
</Project>

DebitExpress.VatRelief/MainWindow.xaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,21 @@
9292
Style="{StaticResource MaterialDesignFlatMidBgButton}"
9393
Content="Generate" />
9494
</StackPanel>
95+
<StackPanel
96+
Margin="10,40,10,10"
97+
Orientation="Horizontal"
98+
VerticalAlignment="Top"
99+
HorizontalAlignment="Right">
100+
<Button
101+
x:Name="DownloadButton"
102+
ToolTip="Download excel template"
103+
Style="{StaticResource MaterialDesignFlatButton}">
104+
<materialDesign:PackIcon
105+
Kind="Download"
106+
Height="20"
107+
Width="20"
108+
Foreground="{StaticResource PrimaryHueMidBrush}"/>
109+
</Button>
110+
</StackPanel>
95111
</Grid>
96112
</ctrl:Window>

DebitExpress.VatRelief/MainWindow.xaml.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Diagnostics;
33
using System.IO;
44
using System.Linq;
5+
using System.Reflection;
56
using System.Windows;
67
using DebitExpress.VatRelief.Models;
78
using DebitExpress.VatRelief.Utils;
@@ -31,6 +32,7 @@ public MainWindow()
3132
ErrorSnackBar.MessageQueue = _errorQueue;
3233

3334
GenerateButton.Click += OnGenerate;
35+
DownloadButton.Click += OnDownload;
3436
}
3537

3638
#region Drag and drop
@@ -75,6 +77,8 @@ private void OnDragOver(object sender, DragEventArgs e)
7577

7678
#endregion
7779

80+
#region Generate
81+
7882
private async void OnGenerate(object sender, RoutedEventArgs e)
7983
{
8084
try
@@ -138,6 +142,8 @@ private void OpenFolder(string path)
138142
Process.Start(startInfo);
139143
}
140144

145+
#endregion
146+
141147
private void NotifyErrorResult(string message)
142148
{
143149
_messageQueue.Clear();
@@ -149,4 +155,42 @@ private void NotifyResult(string message)
149155
_errorQueue.Clear();
150156
_messageQueue.Enqueue(message, "×", () => { });
151157
}
158+
159+
#region download template
160+
161+
private void OnDownload(object sender, RoutedEventArgs e)
162+
{
163+
DownloadButton.IsEnabled = false;
164+
165+
try
166+
{
167+
var path = Path.Combine(Path.GetTempPath(), "vat-relief");
168+
Directory.CreateDirectory(path);
169+
170+
var assembly = Assembly.GetExecutingAssembly();
171+
using var stream = assembly.GetManifestResourceStream("DebitExpress.VatRelief.template.xlsx");
172+
173+
if (stream == null) return;
174+
175+
var filePath = Path.Combine(path, "template.xlsx");
176+
using var fileStream = File.Create(Path.Combine(filePath));
177+
stream.Seek(0, SeekOrigin.Begin);
178+
stream.CopyTo(fileStream);
179+
fileStream.Close();
180+
181+
NotifyResult("Template downloaded successfully");
182+
OpenExcelFile(filePath);
183+
}
184+
finally
185+
{
186+
DownloadButton.IsEnabled = true;
187+
}
188+
}
189+
190+
private static void OpenExcelFile(string excelFile)
191+
{
192+
new Process { StartInfo = new ProcessStartInfo(excelFile) { UseShellExecute = true } }.Start();
193+
}
194+
195+
#endregion
152196
}
16.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)