diff --git a/src/Local/ProjectEye/ProjectEye.csproj b/src/Local/ProjectEye/ProjectEye.csproj index ab73bee..49d8f01 100644 --- a/src/Local/ProjectEye/ProjectEye.csproj +++ b/src/Local/ProjectEye/ProjectEye.csproj @@ -470,6 +470,9 @@ 12.0.2 + + 3.5.1 + 1.5.3.29 diff --git a/src/Local/ProjectEye/Resources/Language/en.xaml b/src/Local/ProjectEye/Resources/Language/en.xaml index 3690961..8f5399a 100644 --- a/src/Local/ProjectEye/Resources/Language/en.xaml +++ b/src/Local/ProjectEye/Resources/Language/en.xaml @@ -208,5 +208,6 @@ Rest time placeholder image Skip placeholder image Statistics window + Export month data \ No newline at end of file diff --git a/src/Local/ProjectEye/Resources/Language/zh.xaml b/src/Local/ProjectEye/Resources/Language/zh.xaml index 6fbc2c2..531c9f2 100644 --- a/src/Local/ProjectEye/Resources/Language/zh.xaml +++ b/src/Local/ProjectEye/Resources/Language/zh.xaml @@ -214,5 +214,6 @@ 休息时间占位图片 跳过次数占位图片 数据统计窗口 + 导出本月数据 \ No newline at end of file diff --git a/src/Local/ProjectEye/ViewModels/StatisticViewModel.cs b/src/Local/ProjectEye/ViewModels/StatisticViewModel.cs index e8fdc86..c57f9f2 100644 --- a/src/Local/ProjectEye/ViewModels/StatisticViewModel.cs +++ b/src/Local/ProjectEye/ViewModels/StatisticViewModel.cs @@ -1,4 +1,5 @@ -using Project1.UI.Controls.ChartControl.Models; +using Npoi.Mapper; +using Project1.UI.Controls.ChartControl.Models; using Project1.UI.Cores; using ProjectEye.Core; using ProjectEye.Core.Service; @@ -26,6 +27,8 @@ public class StatisticViewModel public Command CloseOnboardingCommand { get; set; } public Command GenerateMonthlyDataImgCommand { get; set; } + public Command exportDataCommand { get; set; } + public StatisticViewModel( StatisticService statistic, @@ -40,6 +43,8 @@ public StatisticViewModel( CloseOnboardingCommand = new Command(new Action(OnCloseOnboardingCommand)); GenerateMonthlyDataImgCommand = new Command(new Action(OnGenerateMonthlyDataImgCommand)); + exportDataCommand = new Command(new Action(OnExportDataCommand)); + Data = new StatisticModel(); Data.Year = DateTime.Now.Year; Data.Month = DateTime.Now.Month; @@ -65,6 +70,8 @@ public StatisticViewModel( LoadImages(); } + + private void LoadImages() { string worktimeimgpath = string.IsNullOrEmpty(config.options.Style.DataWindowWorkTimeImagePath) ? "pack://application:,,,/ProjectEye;component/Resources/web_developer.png" : config.options.Style.DataWindowWorkTimeImagePath; @@ -72,7 +79,7 @@ private void LoadImages() string skipimgpath = string.IsNullOrEmpty(config.options.Style.DataWindowSkipImagePath) ? "pack://application:,,,/ProjectEye;component/Resources/office_work_.png" : config.options.Style.DataWindowSkipImagePath; Data.WorktimeImageSource = BitmapImager.Load(worktimeimgpath); - Data.ResttimeImageSource= BitmapImager.Load(resttimeimgpath); + Data.ResttimeImageSource = BitmapImager.Load(resttimeimgpath); Data.SkipImageSource = BitmapImager.Load(skipimgpath); } @@ -429,5 +436,41 @@ private void OnGenerateMonthlyDataImgCommand(object obj) Data.MonthWork).Generate(); } } + public struct XlsxData + { + + } + private void OnExportDataCommand(object obj) + { + try + { + Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog(); + dlg.FileName = "Project Eye statistic data " + Data.Year + Data.Month; + dlg.DefaultExt = ".xlsx"; + dlg.Filter = "(.xlsx)|*.xlsx"; + Nullable result = dlg.ShowDialog(); + if (result == true) + { + // 获取选择月份的数据 + var monthData = statistic.GetData(Data.Year, Data.Month); + + // 重新构建友好结构 + + var mapper = new Mapper(); + mapper + .Map("Date 日期", o => o.Date) + .Map("Work(hours) 工作(小时)", o => o.WorkingTime) + .Map("Rest(minutes) 休息(分钟)", o => o.ResetTime) + .Map("Skip 跳过(次)", o => o.SkipCount) + .Ignore(o => o.ID) + .Save(dlg.FileName, monthData, $"{Data.Year}{Data.Month}", overwrite: true); + } + } + catch (Exception e) + { + LogHelper.Error(e.Message); + MessageBox.Show("导出数据失败,了解详情请查看错误日志"); + } + } } } diff --git a/src/Local/ProjectEye/Views/StatisticWindow.xaml b/src/Local/ProjectEye/Views/StatisticWindow.xaml index b8896f9..485a2af 100644 --- a/src/Local/ProjectEye/Views/StatisticWindow.xaml +++ b/src/Local/ProjectEye/Views/StatisticWindow.xaml @@ -31,7 +31,7 @@ VerticalAlignment="{TemplateBinding VerticalContentAlignment}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" />--> - + @@ -39,7 +39,7 @@ - + @@ -217,14 +217,14 @@ - - + + - + @@ -250,8 +250,8 @@ - - + + @@ -272,13 +272,24 @@ - + - + +