Parcourir la source

Добавлена кнопка экспорта в CSV

Ahatov Artur il y a 6 mois
Parent
commit
7b5afeadf9

+ 8 - 0
src/DontHarmDesktop/App.config

@@ -20,4 +20,12 @@
       <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
     </providers>
   </entityFramework>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.4.1" newVersion="4.0.4.1" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
 </configuration>

+ 16 - 0
src/DontHarmDesktop/DontHarmDesktop.csproj

@@ -35,6 +35,9 @@
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <ItemGroup>
+    <Reference Include="CsvHelper, Version=33.0.0.0, Culture=neutral, PublicKeyToken=8c4959082be5c823, processorArchitecture=MSIL">
+      <HintPath>..\packages\CsvHelper.33.0.1\lib\net47\CsvHelper.dll</HintPath>
+    </Reference>
     <Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
       <HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll</HintPath>
     </Reference>
@@ -44,6 +47,9 @@
     <Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
       <HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.8.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
     </Reference>
+    <Reference Include="Microsoft.Bcl.HashCode, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
+      <HintPath>..\packages\Microsoft.Bcl.HashCode.1.1.1\lib\net461\Microsoft.Bcl.HashCode.dll</HintPath>
+    </Reference>
     <Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions, Version=8.0.0.1, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
       <HintPath>..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.8.0.1\lib\net462\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath>
     </Reference>
@@ -57,9 +63,19 @@
       <HintPath>..\packages\Prism.Events.9.0.537\lib\net47\Prism.Events.dll</HintPath>
     </Reference>
     <Reference Include="System" />
+    <Reference Include="System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
+      <HintPath>..\packages\System.Buffers.4.4.0\lib\netstandard2.0\System.Buffers.dll</HintPath>
+    </Reference>
     <Reference Include="System.ComponentModel.DataAnnotations" />
     <Reference Include="System.Data" />
     <Reference Include="System.Drawing" />
+    <Reference Include="System.Memory, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
+      <HintPath>..\packages\System.Memory.4.5.0\lib\netstandard2.0\System.Memory.dll</HintPath>
+    </Reference>
+    <Reference Include="System.Numerics" />
+    <Reference Include="System.Numerics.Vectors, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+      <HintPath>..\packages\System.Numerics.Vectors.4.4.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
+    </Reference>
     <Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
       <HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.3\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
     </Reference>

+ 12 - 5
src/DontHarmDesktop/Pages/Reports/EmployeeCost.xaml

@@ -29,11 +29,18 @@
                 Style="{StaticResource BackButton}"
                 Command="{Binding Source={x:Static root:Navigation.GoBack}}"/>
 
-            <Button 
-                Grid.Row="1"
-                Margin="0,4,0,0"
-                Content="Сформировать"
-                Command="{Binding StartCmd}"/>
+            <StackPanel Grid.Row="1">
+                <Button 
+                    Margin="0,4,0,0"
+                    Content="Сформировать"
+                    Command="{Binding StartCmd}"/>
+                <Button 
+                    Margin="0,4,0,0"
+                    Content="Экспорт в CSV"
+                    Command="{Binding ExportCmd}"/>
+            </StackPanel>
+            
+            
             <Grid
                 Grid.Row="1"
                 Grid.Column="1"

+ 30 - 5
src/DontHarmDesktop/ViewModels/Reports/EmployeeCostVM.cs

@@ -1,15 +1,12 @@
 using Prism.Commands;
 using Prism.Mvvm;
-using System;
 using System.Collections.Generic;
 using System.Data.Entity;
 using System.Linq;
-using System.Runtime.InteropServices;
 using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Controls;
 using System.Windows.Forms.DataVisualization.Charting;
-using System.Windows.Media;
+using CsvHelper;
+using System.IO;
 
 // https://www.c-sharpcorner.com/article/static-and-dynamic-line-chart-in-wpf-with-mvvm-pattern-using-prism-library/
 
@@ -22,6 +19,11 @@ namespace DontHarmDesktop.ViewModels.Reports
         /// </summary>
         public DelegateCommand StartCmd { get; set; }
 
+        /// <summary>
+        /// Команда "Экспортировать"
+        /// </summary>
+        public DelegateCommand ExportCmd { get; set; }
+
         /// <summary>
         /// Даные для графика
         /// </summary>
@@ -48,6 +50,7 @@ namespace DontHarmDesktop.ViewModels.Reports
         public EmployeeCostVM(Series series) 
         {
             StartCmd = new DelegateCommand(StartExecuted);
+            ExportCmd = new DelegateCommand(ExportExecuted);
             Costs = new List<KeyValuePair<string, int>>();
             SeriesInterface = series;
             FilterName = "";
@@ -59,6 +62,28 @@ namespace DontHarmDesktop.ViewModels.Reports
             Refresh();
         }
 
+        public void ExportExecuted()
+        {
+            // 1. Показать диалог выбора файла
+            var ofd = new Microsoft.Win32.OpenFileDialog();
+            ofd.Multiselect = false;
+            ofd.Filter = "CSV файлы (*.csv)|*.csv|Все файлы (*.*)|*.*";
+            bool? selected = ofd.ShowDialog();
+            if (selected == false)
+            {
+                return;
+            }
+            string fileName = ofd.FileName;
+
+            // 2. Сгенерировать CSV
+            var writer = new StreamWriter(fileName);
+            StringBuilder sb = new StringBuilder();
+            Costs.ForEach(c =>
+            {
+                
+            });
+        }
+
         private async void Refresh()
         {
             var db = new Models.Entities();

+ 6 - 0
src/DontHarmDesktop/packages.config

@@ -1,12 +1,18 @@
 <?xml version="1.0" encoding="utf-8"?>
 <packages>
+  <package id="CsvHelper" version="33.0.1" targetFramework="net472" />
   <package id="EntityFramework" version="6.2.0" targetFramework="net472" />
   <package id="EntityFramework.ru" version="6.2.0" targetFramework="net472" />
   <package id="Microsoft.Bcl.AsyncInterfaces" version="8.0.0" targetFramework="net472" />
+  <package id="Microsoft.Bcl.HashCode" version="1.1.1" targetFramework="net472" />
+  <package id="Microsoft.CSharp" version="4.7.0" targetFramework="net472" />
   <package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="8.0.1" targetFramework="net472" />
   <package id="Prism.Container.Abstractions" version="9.0.106" targetFramework="net472" />
   <package id="Prism.Core" version="9.0.537" targetFramework="net472" />
   <package id="Prism.Events" version="9.0.537" targetFramework="net472" />
+  <package id="System.Buffers" version="4.4.0" targetFramework="net472" />
+  <package id="System.Memory" version="4.5.0" targetFramework="net472" />
+  <package id="System.Numerics.Vectors" version="4.4.0" targetFramework="net472" />
   <package id="System.Runtime.CompilerServices.Unsafe" version="4.5.3" targetFramework="net472" />
   <package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net472" />
 </packages>