1- using Project1 . UI . Controls . ChartControl . Models ;
1+ using Npoi . Mapper ;
2+ using Project1 . UI . Controls . ChartControl . Models ;
23using Project1 . UI . Cores ;
34using ProjectEye . Core ;
45using ProjectEye . Core . Service ;
@@ -26,6 +27,8 @@ public class StatisticViewModel
2627
2728 public Command CloseOnboardingCommand { get ; set ; }
2829 public Command GenerateMonthlyDataImgCommand { get ; set ; }
30+ public Command exportDataCommand { get ; set ; }
31+
2932
3033 public StatisticViewModel (
3134 StatisticService statistic ,
@@ -40,6 +43,8 @@ public StatisticViewModel(
4043
4144 CloseOnboardingCommand = new Command ( new Action < object > ( OnCloseOnboardingCommand ) ) ;
4245 GenerateMonthlyDataImgCommand = new Command ( new Action < object > ( OnGenerateMonthlyDataImgCommand ) ) ;
46+ exportDataCommand = new Command ( new Action < object > ( OnExportDataCommand ) ) ;
47+
4348 Data = new StatisticModel ( ) ;
4449 Data . Year = DateTime . Now . Year ;
4550 Data . Month = DateTime . Now . Month ;
@@ -65,14 +70,16 @@ public StatisticViewModel(
6570 LoadImages ( ) ;
6671 }
6772
73+
74+
6875 private void LoadImages ( )
6976 {
7077 string worktimeimgpath = string . IsNullOrEmpty ( config . options . Style . DataWindowWorkTimeImagePath ) ? "pack://application:,,,/ProjectEye;component/Resources/web_developer.png" : config . options . Style . DataWindowWorkTimeImagePath ;
7178 string resttimeimgpath = string . IsNullOrEmpty ( config . options . Style . DataWindowRestTimeImagePath ) ? "pack://application:,,,/ProjectEye;component/Resources/coffee_lover.png" : config . options . Style . DataWindowRestTimeImagePath ;
7279 string skipimgpath = string . IsNullOrEmpty ( config . options . Style . DataWindowSkipImagePath ) ? "pack://application:,,,/ProjectEye;component/Resources/office_work_.png" : config . options . Style . DataWindowSkipImagePath ;
7380
7481 Data . WorktimeImageSource = BitmapImager . Load ( worktimeimgpath ) ;
75- Data . ResttimeImageSource = BitmapImager . Load ( resttimeimgpath ) ;
82+ Data . ResttimeImageSource = BitmapImager . Load ( resttimeimgpath ) ;
7683 Data . SkipImageSource = BitmapImager . Load ( skipimgpath ) ;
7784
7885 }
@@ -429,5 +436,41 @@ private void OnGenerateMonthlyDataImgCommand(object obj)
429436 Data . MonthWork ) . Generate ( ) ;
430437 }
431438 }
439+ public struct XlsxData
440+ {
441+
442+ }
443+ private void OnExportDataCommand ( object obj )
444+ {
445+ try
446+ {
447+ Microsoft . Win32 . SaveFileDialog dlg = new Microsoft . Win32 . SaveFileDialog ( ) ;
448+ dlg . FileName = "Project Eye statistic data " + Data . Year + Data . Month ;
449+ dlg . DefaultExt = ".xlsx" ;
450+ dlg . Filter = "(.xlsx)|*.xlsx" ;
451+ Nullable < bool > result = dlg . ShowDialog ( ) ;
452+ if ( result == true )
453+ {
454+ // 获取选择月份的数据
455+ var monthData = statistic . GetData ( Data . Year , Data . Month ) ;
456+
457+ // 重新构建友好结构
458+
459+ var mapper = new Mapper ( ) ;
460+ mapper
461+ . Map < Core . Models . Statistic . StatisticModel > ( "Date 日期" , o => o . Date )
462+ . Map < Core . Models . Statistic . StatisticModel > ( "Work(hours) 工作(小时)" , o => o . WorkingTime )
463+ . Map < Core . Models . Statistic . StatisticModel > ( "Rest(minutes) 休息(分钟)" , o => o . ResetTime )
464+ . Map < Core . Models . Statistic . StatisticModel > ( "Skip 跳过(次)" , o => o . SkipCount )
465+ . Ignore < Core . Models . Statistic . StatisticModel > ( o => o . ID )
466+ . Save ( dlg . FileName , monthData , $ "{ Data . Year } { Data . Month } ", overwrite : true ) ;
467+ }
468+ }
469+ catch ( Exception e )
470+ {
471+ LogHelper . Error ( e . Message ) ;
472+ MessageBox . Show ( "导出数据失败,了解详情请查看错误日志" ) ;
473+ }
474+ }
432475 }
433476}
0 commit comments