提交记录修改Core/App.config+8 −0看文件
修改Core/Core.csproj+29 −0看文件
修改Core/Servicers/Instances/Data.cs+58 −0看文件
修改Core/Servicers/Instances/Main.cs+2 −0看文件
修改Core/Servicers/Interfaces/IData.cs+4 −1看文件
修改Core/packages.config+7 −0看文件
修改UI/App.config+8 −0看文件
修改UI/Models/SettingPageModel.cs+6 −0看文件
修改UI/ViewModels/SettingPageVM.cs+25 −1看文件
修改UI/Views/SettingPage.xaml+13 −1看文件
| @@ -22,6 +22,14 @@ | ||
| 22 | 22 | <assemblyIdentity name="System.Data.SQLite" publicKeyToken="db937bc2d44ff139" culture="neutral" /> |
| 23 | 23 | <bindingRedirect oldVersion="0.0.0.0-1.0.115.5" newVersion="1.0.115.5" /> |
| 24 | 24 | </dependentAssembly> |
| 25 | 新增: <dependentAssembly> | |
| 26 | 新增: <assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> | |
| 27 | 新增: <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" /> | |
| 28 | 新增: </dependentAssembly> | |
| 29 | 新增: <dependentAssembly> | |
| 30 | 新增: <assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> | |
| 31 | 新增: <bindingRedirect oldVersion="0.0.0.0-4.0.1.1" newVersion="4.0.1.1" /> | |
| 32 | 新增: </dependentAssembly> | |
| 25 | 33 | </assemblyBinding> |
| 26 | 34 | </runtime> |
| 27 | 35 | </configuration> |
| 文件末尾没有换行 | ||
| @@ -59,18 +59,42 @@ | ||
| 59 | 59 | <ErrorReport>prompt</ErrorReport> |
| 60 | 60 | </PropertyGroup> |
| 61 | 61 | <ItemGroup> |
| 62 | 新增: <Reference Include="BouncyCastle.Crypto, Version=1.8.9.0, Culture=neutral, PublicKeyToken=0e99375e54769942, processorArchitecture=MSIL"> | |
| 63 | 新增: <HintPath>..\packages\Portable.BouncyCastle.1.8.9\lib\net40\BouncyCastle.Crypto.dll</HintPath> | |
| 64 | 新增: </Reference> | |
| 65 | 新增: <Reference Include="CsvHelper, Version=29.0.0.0, Culture=neutral, PublicKeyToken=8c4959082be5c823, processorArchitecture=MSIL"> | |
| 66 | 新增: <HintPath>..\packages\CsvHelper.29.0.0\lib\net45\CsvHelper.dll</HintPath> | |
| 67 | 新增: </Reference> | |
| 62 | 68 | <Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"> |
| 63 | 69 | <HintPath>..\packages\EntityFramework.6.3.0\lib\net45\EntityFramework.dll</HintPath> |
| 64 | 70 | </Reference> |
| 65 | 71 | <Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"> |
| 66 | 72 | <HintPath>..\packages\EntityFramework.6.3.0\lib\net45\EntityFramework.SqlServer.dll</HintPath> |
| 67 | 73 | </Reference> |
| 74 | 新增: <Reference Include="ICSharpCode.SharpZipLib, Version=1.3.3.11, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL"> | |
| 75 | 新增: <HintPath>..\packages\SharpZipLib.1.3.3\lib\net45\ICSharpCode.SharpZipLib.dll</HintPath> | |
| 76 | 新增: </Reference> | |
| 68 | 77 | <Reference Include="Microsoft.Win32.TaskScheduler, Version=2.10.1.0, Culture=neutral, PublicKeyToken=e25603a88b3aa7da, processorArchitecture=MSIL"> |
| 69 | 78 | <HintPath>..\packages\TaskScheduler.2.10.1\lib\net452\Microsoft.Win32.TaskScheduler.dll</HintPath> |
| 70 | 79 | </Reference> |
| 71 | 80 | <Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> |
| 72 | 81 | <HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath> |
| 73 | 82 | </Reference> |
| 83 | 新增: <Reference Include="NPOI, Version=2.5.6.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1, processorArchitecture=MSIL"> | |
| 84 | 新增: <HintPath>..\packages\NPOI.2.5.6\lib\net45\NPOI.dll</HintPath> | |
| 85 | 新增: </Reference> | |
| 86 | 新增: <Reference Include="Npoi.Mapper, Version=4.1.0.0, Culture=neutral, PublicKeyToken=ecb4c11f6eaa0b06, processorArchitecture=MSIL"> | |
| 87 | 新增: <HintPath>..\packages\Npoi.Mapper.4.1.0\lib\net45\Npoi.Mapper.dll</HintPath> | |
| 88 | 新增: </Reference> | |
| 89 | 新增: <Reference Include="NPOI.OOXML, Version=2.5.6.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1, processorArchitecture=MSIL"> | |
| 90 | 新增: <HintPath>..\packages\NPOI.2.5.6\lib\net45\NPOI.OOXML.dll</HintPath> | |
| 91 | 新增: </Reference> | |
| 92 | 新增: <Reference Include="NPOI.OpenXml4Net, Version=2.5.6.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1, processorArchitecture=MSIL"> | |
| 93 | 新增: <HintPath>..\packages\NPOI.2.5.6\lib\net45\NPOI.OpenXml4Net.dll</HintPath> | |
| 94 | 新增: </Reference> | |
| 95 | 新增: <Reference Include="NPOI.OpenXmlFormats, Version=2.5.6.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1, processorArchitecture=MSIL"> | |
| 96 | 新增: <HintPath>..\packages\NPOI.2.5.6\lib\net45\NPOI.OpenXmlFormats.dll</HintPath> | |
| 97 | 新增: </Reference> | |
| 74 | 98 | <Reference Include="PresentationCore" /> |
| 75 | 99 | <Reference Include="SQLitePCLRaw.core, Version=2.0.6.1341, Culture=neutral, PublicKeyToken=1488e028ca7ab535, processorArchitecture=MSIL"> |
| 76 | 100 | <HintPath>..\packages\SQLitePCLRaw.core.2.0.6\lib\netstandard2.0\SQLitePCLRaw.core.dll</HintPath> |
| @@ -100,6 +124,11 @@ | ||
| 100 | 124 | <Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> |
| 101 | 125 | <HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath> |
| 102 | 126 | </Reference> |
| 127 | 新增: <Reference Include="System.ValueTuple, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> | |
| 128 | 新增: <HintPath>..\packages\System.ValueTuple.4.3.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath> | |
| 129 | 新增: <Private>True</Private> | |
| 130 | 新增: <Private>True</Private> | |
| 131 | 新增: </Reference> | |
| 103 | 132 | <Reference Include="System.Windows.Forms" /> |
| 104 | 133 | <Reference Include="System.Xml.Linq" /> |
| 105 | 134 | <Reference Include="System.Data.DataSetExtensions" /> |
| @@ -9,6 +9,10 @@ using System.Data.Entity; | ||
| 9 | 9 | using System.Windows.Threading; |
| 10 | 10 | using Core.Models.Data; |
| 11 | 11 | using Core.Librarys; |
| 12 | 新增:using Npoi.Mapper; | |
| 13 | 新增:using System.IO; | |
| 14 | 新增:using CsvHelper; | |
| 15 | 新增:using System.Globalization; | |
| 12 | 16 | |
| 13 | 17 | namespace Core.Servicers.Instances |
| 14 | 18 | { |
| @@ -569,5 +573,59 @@ namespace Core.Servicers.Instances | ||
| 569 | 573 | db.Database.ExecuteSqlCommand("delete from HoursLogModels where DataTime>='" + start.Date.ToString("yyyy-MM-01 00:00:00") + "' and DataTime<= '" + end.Date.ToString("yyyy-MM-dd 23:59:59") + "'"); |
| 570 | 574 | } |
| 571 | 575 | } |
| 576 | 新增: | |
| 577 | 新增: public void ExportToExcel(string dir, DateTime start, DateTime end) | |
| 578 | 新增: { | |
| 579 | 新增: start = new DateTime(start.Year, start.Month, 1, 0, 0, 0); | |
| 580 | 新增: end = new DateTime(end.Year, end.Month, DateTime.DaysInMonth(end.Year, end.Month), 23, 59, 59); | |
| 581 | 新增: | |
| 582 | 新增: using (var db = new TaiDbContext()) | |
| 583 | 新增: { | |
| 584 | 新增: var day = db.DailyLog.Where(m => m.Date >= start.Date && m.Date <= end.Date) | |
| 585 | 新增: .Select(m => new | |
| 586 | 新增: { | |
| 587 | 新增: 日期 = m.Date, | |
| 588 | 新增: 应用 = m.AppModel != null ? m.AppModel.Name : "未知", | |
| 589 | 新增: 描述 = m.AppModel != null ? m.AppModel.Description : "未知", | |
| 590 | 新增: 时长 = m.Time, | |
| 591 | 新增: 分类 = m.AppModel != null && m.AppModel.Category != null ? m.AppModel.Category.Name : "未知" | |
| 592 | 新增: }) | |
| 593 | 新增: .ToList(); | |
| 594 | 新增: | |
| 595 | 新增: var hours = db.HoursLog.Where(m => m.DataTime >= start && m.DataTime <= end) | |
| 596 | 新增: .Select(m => new | |
| 597 | 新增: { | |
| 598 | 新增: 时段 = m.DataTime, | |
| 599 | 新增: 应用 = m.AppModel != null ? m.AppModel.Name : "未知", | |
| 600 | 新增: 描述 = m.AppModel != null ? m.AppModel.Description : "未知", | |
| 601 | 新增: 时长 = m.Time, | |
| 602 | 新增: 分类 = m.AppModel != null && m.AppModel.Category != null ? m.AppModel.Category.Name : "未知" | |
| 603 | 新增: }) | |
| 604 | 新增: .ToList(); | |
| 605 | 新增: var mapper = new Mapper(); | |
| 606 | 新增: mapper.Put(day, "每日"); | |
| 607 | 新增: mapper.Put(hours, "时段"); | |
| 608 | 新增: | |
| 609 | 新增: string name = $"Tai数据({start.ToString("yyyy年MM月")}-{end.ToString("yyyy年MM月")})"; | |
| 610 | 新增: if (start.Year == end.Year && start.Month == end.Month) | |
| 611 | 新增: { | |
| 612 | 新增: name = $"Tai数据({start.ToString("yyyy年MM月")})"; | |
| 613 | 新增: } | |
| 614 | 新增: mapper.Save(Path.Combine(dir, $"{name}.xlsx")); | |
| 615 | 新增: | |
| 616 | 新增: // 导出csv | |
| 617 | 新增: using (var writer = new StreamWriter(Path.Combine(dir, $"{name}-每日.csv"), false, System.Text.Encoding.UTF8)) | |
| 618 | 新增: using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture)) | |
| 619 | 新增: { | |
| 620 | 新增: csv.WriteRecords(day); | |
| 621 | 新增: } | |
| 622 | 新增: | |
| 623 | 新增: using (var writer = new StreamWriter(Path.Combine(dir, $"{name}-时段.csv"), false, System.Text.Encoding.UTF8)) | |
| 624 | 新增: using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture)) | |
| 625 | 新增: { | |
| 626 | 新增: csv.WriteRecords(hours); | |
| 627 | 新增: } | |
| 628 | 新增: } | |
| 629 | 新增: } | |
| 572 | 630 | } |
| 573 | 631 | } |
| @@ -103,6 +103,8 @@ namespace Core.Servicers.Instances | ||
| 103 | 103 | |
| 104 | 104 | private void DateTimeObserver_OnDateTimeChanging(object sender, DateTime time) |
| 105 | 105 | { |
| 106 | 新增: Logger.Info("[time changed] status:" + sleepStatus + ",process:" + activeProcess + ",start:" + activeStartTime.ToString() + ",end:" + DateTime.Now.ToString() + ",time:" + time.ToString()); | |
| 107 | 新增: | |
| 106 | 108 | if (sleepStatus == SleepStatus.Wake) |
| 107 | 109 | { |
| 108 | 110 | UpdateTime(time); |
| @@ -93,6 +93,9 @@ namespace Core.Servicers.Interfaces | ||
| 93 | 93 | /// <param name="start"></param> |
| 94 | 94 | /// <param name="end"></param> |
| 95 | 95 | void ClearRange(DateTime start, DateTime end); |
| 96 | 删除: | |
| 96 | 新增: /// <summary> | |
| 97 | 新增: /// 导出数据到EXCEL | |
| 98 | 新增: /// </summary> | |
| 99 | 新增: void ExportToExcel(string dir, DateTime start, DateTime end); | |
| 97 | 100 | } |
| 98 | 101 | } |
| @@ -1,7 +1,13 @@ | ||
| 1 | 1 | <?xml version="1.0" encoding="utf-8"?> |
| 2 | 2 | <packages> |
| 3 | 新增: <package id="CsvHelper" version="29.0.0" targetFramework="net461" /> | |
| 3 | 4 | <package id="EntityFramework" version="6.3.0" targetFramework="net461" /> |
| 5 | 新增: <package id="Microsoft.CSharp" version="4.3.0" targetFramework="net461" /> | |
| 4 | 6 | <package id="Newtonsoft.Json" version="13.0.1" targetFramework="net461" /> |
| 7 | 新增: <package id="NPOI" version="2.5.6" targetFramework="net461" /> | |
| 8 | 新增: <package id="Npoi.Mapper" version="4.1.0" targetFramework="net461" /> | |
| 9 | 新增: <package id="Portable.BouncyCastle" version="1.8.9" targetFramework="net461" /> | |
| 10 | 新增: <package id="SharpZipLib" version="1.3.3" targetFramework="net461" /> | |
| 5 | 11 | <package id="SQLitePCLRaw.core" version="2.0.6" targetFramework="net461" /> |
| 6 | 12 | <package id="Stub.System.Data.SQLite.Core.NetFramework" version="1.0.115.5" targetFramework="net461" /> |
| 7 | 13 | <package id="System.Buffers" version="4.4.0" targetFramework="net461" /> |
| @@ -12,5 +18,6 @@ | ||
| 12 | 18 | <package id="System.Memory" version="4.5.3" targetFramework="net461" /> |
| 13 | 19 | <package id="System.Numerics.Vectors" version="4.4.0" targetFramework="net461" /> |
| 14 | 20 | <package id="System.Runtime.CompilerServices.Unsafe" version="4.5.2" targetFramework="net461" /> |
| 21 | 新增: <package id="System.ValueTuple" version="4.3.0" targetFramework="net461" /> | |
| 15 | 22 | <package id="TaskScheduler" version="2.10.1" targetFramework="net461" /> |
| 16 | 23 | </packages> |
| 文件末尾没有换行 | ||
| @@ -13,6 +13,14 @@ | ||
| 13 | 13 | <assemblyIdentity name="System.Data.SQLite" publicKeyToken="db937bc2d44ff139" culture="neutral" /> |
| 14 | 14 | <bindingRedirect oldVersion="0.0.0.0-1.0.115.5" newVersion="1.0.115.5" /> |
| 15 | 15 | </dependentAssembly> |
| 16 | 新增: <dependentAssembly> | |
| 17 | 新增: <assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> | |
| 18 | 新增: <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" /> | |
| 19 | 新增: </dependentAssembly> | |
| 20 | 新增: <dependentAssembly> | |
| 21 | 新增: <assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> | |
| 22 | 新增: <bindingRedirect oldVersion="0.0.0.0-4.0.1.1" newVersion="4.0.1.1" /> | |
| 23 | 新增: </dependentAssembly> | |
| 16 | 24 | </assemblyBinding> |
| 17 | 25 | </runtime> |
| 18 | 26 | </configuration> |
| @@ -41,5 +41,11 @@ namespace UI.Models | ||
| 41 | 41 | |
| 42 | 42 | private DateTime DelDataEndMonthDate_; |
| 43 | 43 | public DateTime DelDataEndMonthDate { get { return DelDataEndMonthDate_; } set { DelDataEndMonthDate_ = value; OnPropertyChanged(); } } |
| 44 | 新增: | |
| 45 | 新增: private DateTime ExportDataStartMonthDate_; | |
| 46 | 新增: public DateTime ExportDataStartMonthDate { get { return ExportDataStartMonthDate_; } set { ExportDataStartMonthDate_ = value; OnPropertyChanged(); } } | |
| 47 | 新增: | |
| 48 | 新增: private DateTime ExportDataEndMonthDate_; | |
| 49 | 新增: public DateTime ExportDataEndMonthDate { get { return ExportDataEndMonthDate_; } set { ExportDataEndMonthDate_ = value; OnPropertyChanged(); } } | |
| 44 | 50 | } |
| 45 | 51 | } |
| @@ -10,6 +10,7 @@ using System.Linq; | ||
| 10 | 10 | using System.Reflection; |
| 11 | 11 | using System.Text; |
| 12 | 12 | using System.Threading.Tasks; |
| 13 | 新增:using System.Windows.Forms; | |
| 13 | 14 | using UI.Controls; |
| 14 | 15 | using UI.Models; |
| 15 | 16 | |
| @@ -24,6 +25,7 @@ namespace UI.ViewModels | ||
| 24 | 25 | public Command OpenURL { get; set; } |
| 25 | 26 | public Command CheckUpdate { get; set; } |
| 26 | 27 | public Command DelDataCommand { get; set; } |
| 28 | 新增: public Command ExportDataCommand { get; set; } | |
| 27 | 29 | |
| 28 | 30 | public SettingPageVM(IAppConfig appConfig, MainViewModel mainVM, IData data) |
| 29 | 31 | { |
| @@ -34,6 +36,7 @@ namespace UI.ViewModels | ||
| 34 | 36 | OpenURL = new Command(new Action<object>(OnOpenURL)); |
| 35 | 37 | CheckUpdate = new Command(new Action<object>(OnCheckUpdate)); |
| 36 | 38 | DelDataCommand = new Command(new Action<object>(OnDelData)); |
| 39 | 新增: ExportDataCommand = new Command(new Action<object>(OnExportData)); | |
| 37 | 40 | |
| 38 | 41 | Init(); |
| 39 | 42 | } |
| @@ -101,8 +104,10 @@ namespace UI.ViewModels | ||
| 101 | 104 | Version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); |
| 102 | 105 | |
| 103 | 106 | DelDataStartMonthDate = DateTime.Now; |
| 104 | 删除: | |
| 105 | 107 | DelDataEndMonthDate = DateTime.Now; |
| 108 | 新增: | |
| 109 | 新增: ExportDataStartMonthDate = DateTime.Now; | |
| 110 | 新增: ExportDataEndMonthDate = DateTime.Now; | |
| 106 | 111 | } |
| 107 | 112 | |
| 108 | 113 | |
| @@ -169,5 +174,24 @@ namespace UI.ViewModels | ||
| 169 | 174 | |
| 170 | 175 | mainVM.Toast("操作已完成", Controls.Window.ToastType.Success); |
| 171 | 176 | } |
| 177 | 新增: | |
| 178 | 新增: private void OnExportData(object obj) | |
| 179 | 新增: { | |
| 180 | 新增: try | |
| 181 | 新增: { | |
| 182 | 新增: FolderBrowserDialog dialog = new FolderBrowserDialog(); | |
| 183 | 新增: dialog.Description = "请选择导出位置"; | |
| 184 | 新增: if (dialog.ShowDialog() == DialogResult.OK) | |
| 185 | 新增: { | |
| 186 | 新增: data.ExportToExcel(dialog.SelectedPath, ExportDataStartMonthDate, ExportDataEndMonthDate); | |
| 187 | 新增: mainVM.Toast("导出数据完成", Controls.Window.ToastType.Success); | |
| 188 | 新增: } | |
| 189 | 新增: } | |
| 190 | 新增: catch (Exception ec) | |
| 191 | 新增: { | |
| 192 | 新增: Logger.Error(ec.ToString()); | |
| 193 | 新增: mainVM.Toast("导出数据失败", Controls.Window.ToastType.Error, Controls.Base.IconTypes.Blocked); | |
| 194 | 新增: } | |
| 195 | 新增: } | |
| 172 | 196 | } |
| 173 | 197 | } |
| @@ -56,7 +56,19 @@ | ||
| 56 | 56 | <Btn:Button Margin="20,0,0,0" Content="执行" Width="80" Background="#f51837" Foreground="White" Command="{Binding DelDataCommand}"/> |
| 57 | 57 | </StackPanel> |
| 58 | 58 | </Border> |
| 59 | 删除: | |
| 59 | 新增: <TextBlock Text="导出数据" FontSize="14" Margin="0,15,0,0"/> | |
| 60 | 新增: <Border Background="White" Padding="20" CornerRadius="6" Margin="0,15,0,0"> | |
| 61 | 新增: <StackPanel> | |
| 62 | 新增: <TextBlock Text="导出为xlsx和csv格式,需要注意:没有设置分类的应用数据不会导出。" Foreground="#989CA1" FontSize="12"/> | |
| 63 | 新增: <StackPanel Orientation="Horizontal" Margin="0,10,0,0"> | |
| 64 | 新增: <TextBlock Text="从" VerticalAlignment="Center"/> | |
| 65 | 新增: <select:DateSelect Date="{Binding ExportDataStartMonthDate,Mode=TwoWay}" Margin="10,0" SelectType="Month"/> | |
| 66 | 新增: <TextBlock Text="到" VerticalAlignment="Center"/> | |
| 67 | 新增: <select:DateSelect Date="{Binding ExportDataEndMonthDate,Mode=TwoWay}" Margin="10,0" SelectType="Month"/> | |
| 68 | 新增: <Btn:Button Margin="20,0,0,0" Content="导出" Width="80" Command="{Binding ExportDataCommand}"/> | |
| 69 | 新增: </StackPanel> | |
| 70 | 新增: </StackPanel> | |
| 71 | 新增: </Border> | |
| 60 | 72 | </StackPanel> |
| 61 | 73 | </TabItem> |
| 62 | 74 | <TabItem> |

