2
2
using System . Diagnostics ;
3
3
using System . IO ;
4
4
using System . Linq ;
5
+ using System . Reflection ;
5
6
using System . Windows ;
6
7
using DebitExpress . VatRelief . Models ;
7
8
using DebitExpress . VatRelief . Utils ;
@@ -31,6 +32,7 @@ public MainWindow()
31
32
ErrorSnackBar . MessageQueue = _errorQueue ;
32
33
33
34
GenerateButton . Click += OnGenerate ;
35
+ DownloadButton . Click += OnDownload ;
34
36
}
35
37
36
38
#region Drag and drop
@@ -75,6 +77,8 @@ private void OnDragOver(object sender, DragEventArgs e)
75
77
76
78
#endregion
77
79
80
+ #region Generate
81
+
78
82
private async void OnGenerate ( object sender , RoutedEventArgs e )
79
83
{
80
84
try
@@ -138,6 +142,8 @@ private void OpenFolder(string path)
138
142
Process . Start ( startInfo ) ;
139
143
}
140
144
145
+ #endregion
146
+
141
147
private void NotifyErrorResult ( string message )
142
148
{
143
149
_messageQueue . Clear ( ) ;
@@ -149,4 +155,42 @@ private void NotifyResult(string message)
149
155
_errorQueue . Clear ( ) ;
150
156
_messageQueue . Enqueue ( message , "×" , ( ) => { } ) ;
151
157
}
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
152
196
}
0 commit comments