提交记录修改Core/Librarys/Time.cs+13 −0看文件
修改Core/Servicers/Instances/Data.cs+80 −68看文件
修改Core/Servicers/Interfaces/IData.cs+8 −0看文件
修改UI/Models/ChartPageModel.cs+9 −0看文件
修改UI/Views/ChartPage.xaml+114 −7看文件
| @@ -8,6 +8,19 @@ namespace Core.Librarys | ||
| 8 | 8 | { |
| 9 | 9 | public class Time |
| 10 | 10 | { |
| 11 | 新增: public static string ToHoursString(double seconds) | |
| 12 | 新增: { | |
| 13 | 新增: double hours = seconds / 60 / 60; | |
| 14 | 新增: | |
| 15 | 新增: if (hours > 0.1) | |
| 16 | 新增: { | |
| 17 | 新增: return hours.ToString("f2"); | |
| 18 | 新增: } | |
| 19 | 新增: else | |
| 20 | 新增: { | |
| 21 | 新增: return "0"; | |
| 22 | 新增: } | |
| 23 | 新增: } | |
| 11 | 24 | public static string ToString(int seconds) |
| 12 | 25 | { |
| 13 | 26 | if (seconds < 60) |
| @@ -19,102 +19,99 @@ namespace Core.Servicers.Instances | ||
| 19 | 19 | public class Data : IData |
| 20 | 20 | { |
| 21 | 21 | private readonly IAppData appData; |
| 22 | 删除: private readonly object setLock = new object(); | |
| 23 | 22 | public Data(IAppData appData) |
| 24 | 23 | { |
| 25 | 24 | this.appData = appData; |
| 26 | 25 | } |
| 27 | 26 | public void Set(string processName, int seconds, DateTime? time_ = null) |
| 28 | 27 | { |
| 29 | 删除: lock (setLock) | |
| 28 | 新增: | |
| 29 | 新增: DateTime time = !time_.HasValue ? DateTime.Now : time_.Value; | |
| 30 | 新增: var today = time.Date; | |
| 31 | 新增: | |
| 32 | 新增: // 当前时段 | |
| 33 | 新增: var nowtime = new DateTime(today.Year, today.Month, today.Day, time.Hour, 0, 0); | |
| 34 | 新增: | |
| 35 | 新增: if (string.IsNullOrEmpty(processName) || seconds <= 0) | |
| 30 | 36 | { |
| 31 | 删除: DateTime time = !time_.HasValue ? DateTime.Now : time_.Value; | |
| 32 | 删除: var today = time.Date; | |
| 37 | 新增: return; | |
| 38 | 新增: } | |
| 33 | 39 | |
| 34 | 删除: // 当前时段 | |
| 35 | 删除: var nowtime = new DateTime(today.Year, today.Month, today.Day, time.Hour, 0, 0); | |
| 40 | 新增: AppModel app = appData.GetApp(processName); | |
| 41 | 新增: | |
| 42 | 新增: if (app == null) | |
| 43 | 新增: { | |
| 44 | 新增: return; | |
| 45 | 新增: } | |
| 36 | 46 | |
| 37 | 删除: if (string.IsNullOrEmpty(processName) || seconds <= 0) | |
| 38 | 删除: { | |
| 39 | 删除: return; | |
| 40 | 删除: } | |
| 41 | 47 | |
| 42 | 删除: AppModel app = appData.GetApp(processName); | |
| 43 | 48 | |
| 44 | 删除: if (app == null) | |
| 49 | 新增: using (var db = new TaiDbContext()) | |
| 50 | 新增: { | |
| 51 | 新增: var res = db.DailyLog.SingleOrDefault(m => m.Date == today && m.AppModelID == app.ID); | |
| 52 | 新增: if (res == null) | |
| 45 | 53 | { |
| 46 | 删除: return; | |
| 54 | 新增: //数据库中没有时则创建 | |
| 55 | 新增: db.DailyLog.Add(new Models.DailyLogModel() | |
| 56 | 新增: { | |
| 57 | 新增: Date = today, | |
| 58 | 新增: AppModelID = app.ID, | |
| 59 | 新增: Time = seconds, | |
| 60 | 新增: }); | |
| 61 | 新增: } | |
| 62 | 新增: else | |
| 63 | 新增: { | |
| 64 | 新增: res.Time += seconds; | |
| 47 | 65 | } |
| 48 | 66 | |
| 67 | 新增: // 分时段记录数据 | |
| 49 | 68 | |
| 50 | 删除: | |
| 51 | 删除: using (var db = new TaiDbContext()) | |
| 69 | 新增: var hourslog = db.HoursLog.SingleOrDefault( | |
| 70 | 新增: m => | |
| 71 | 新增: m.DataTime == nowtime | |
| 72 | 新增: && m.AppModelID == app.ID | |
| 73 | 新增: ); | |
| 74 | 新增: if (hourslog == null) | |
| 52 | 75 | { |
| 53 | 删除: var res = db.DailyLog.SingleOrDefault(m => m.Date == today && m.AppModelID == app.ID); | |
| 54 | 删除: if (res == null) | |
| 76 | 新增: // 没有时创建 | |
| 77 | 新增: | |
| 78 | 新增: if (seconds > 3600) | |
| 55 | 79 | { |
| 56 | 删除: //数据库中没有时则创建 | |
| 57 | 删除: db.DailyLog.Add(new Models.DailyLogModel() | |
| 58 | 删除: { | |
| 59 | 删除: Date = today, | |
| 60 | 删除: AppModelID = app.ID, | |
| 61 | 删除: Time = seconds, | |
| 62 | 删除: }); | |
| 80 | 新增: int overflowSeconds = seconds - 3600; | |
| 81 | 新增: Set(processName, overflowSeconds, nowtime.AddHours(1)); | |
| 82 | 新增: | |
| 83 | 新增: seconds = 3600; | |
| 63 | 84 | } |
| 64 | 删除: else | |
| 85 | 新增: | |
| 86 | 新增: db.HoursLog.Add(new Models.HoursLogModel() | |
| 65 | 87 | { |
| 66 | 删除: res.Time += seconds; | |
| 67 | 删除: } | |
| 88 | 新增: DataTime = nowtime, | |
| 89 | 新增: AppModelID = app.ID, | |
| 90 | 新增: Time = seconds | |
| 91 | 新增: }); | |
| 92 | 新增: } | |
| 93 | 新增: else | |
| 94 | 新增: { | |
| 95 | 新增: if (hourslog.Time + seconds > 3600) | |
| 96 | 新增: { | |
| 97 | 新增: hourslog.Time = 3600; | |
| 68 | 98 | |
| 69 | 删除: // 分时段记录数据 | |
| 99 | 新增: int overflowSeconds = hourslog.Time + seconds - 3600; | |
| 70 | 100 | |
| 71 | 删除: var hourslog = db.HoursLog.SingleOrDefault( | |
| 72 | 删除: m => | |
| 73 | 删除: m.DataTime == nowtime | |
| 74 | 删除: && m.AppModelID == app.ID | |
| 75 | 删除: ); | |
| 76 | 删除: if (hourslog == null) | |
| 77 | 删除: { | |
| 78 | 删除: // 没有时创建 | |
| 79 | 删除: | |
| 80 | 删除: if (seconds > 3600) | |
| 81 | 删除: { | |
| 82 | 删除: int overflowSeconds = seconds - 3600; | |
| 83 | 删除: Set(processName, overflowSeconds, nowtime.AddHours(1)); | |
| 84 | 删除: | |
| 85 | 删除: seconds = 3600; | |
| 86 | 删除: } | |
| 87 | 删除: | |
| 88 | 删除: db.HoursLog.Add(new Models.HoursLogModel() | |
| 89 | 删除: { | |
| 90 | 删除: DataTime = nowtime, | |
| 91 | 删除: AppModelID = app.ID, | |
| 92 | 删除: Time = seconds | |
| 93 | 删除: }); | |
| 101 | 新增: Set(processName, overflowSeconds, nowtime.AddHours(1)); | |
| 94 | 102 | } |
| 95 | 103 | else |
| 96 | 104 | { |
| 97 | 删除: if (hourslog.Time + seconds > 3600) | |
| 98 | 删除: { | |
| 99 | 删除: hourslog.Time = 3600; | |
| 100 | 删除: | |
| 101 | 删除: int overflowSeconds = hourslog.Time + seconds - 3600; | |
| 102 | 删除: | |
| 103 | 删除: Set(processName, overflowSeconds, nowtime.AddHours(1)); | |
| 104 | 删除: } | |
| 105 | 删除: else | |
| 106 | 删除: { | |
| 107 | 删除: hourslog.Time += seconds; | |
| 108 | 删除: } | |
| 105 | 新增: hourslog.Time += seconds; | |
| 109 | 106 | } |
| 107 | 新增: } | |
| 110 | 108 | |
| 111 | 删除: // 统计使用时长 | |
| 112 | 删除: app.TotalTime += seconds; | |
| 109 | 新增: // 统计使用时长 | |
| 110 | 新增: app.TotalTime += seconds; | |
| 113 | 111 | |
| 114 | 删除: appData.UpdateApp(app); | |
| 112 | 新增: appData.UpdateApp(app); | |
| 115 | 113 | |
| 116 | 删除: db.SaveChanges(); | |
| 117 | 删除: } | |
| 114 | 新增: db.SaveChanges(); | |
| 118 | 115 | } |
| 119 | 116 | } |
| 120 | 117 | |
| @@ -627,5 +624,20 @@ namespace Core.Servicers.Instances | ||
| 627 | 624 | } |
| 628 | 625 | } |
| 629 | 626 | } |
| 627 | 新增: | |
| 628 | 新增: public int GetDateRangeAppCount(DateTime start, DateTime end) | |
| 629 | 新增: { | |
| 630 | 新增: IEnumerable<AppModel> apps = appData.GetAllApps(); | |
| 631 | 新增: | |
| 632 | 新增: using (var db = new TaiDbContext()) | |
| 633 | 新增: { | |
| 634 | 新增: var res = db.DailyLog | |
| 635 | 新增: .Where(m => m.Date >= start && m.Date <= end && m.AppModelID != 0) | |
| 636 | 新增: .GroupBy(m => m.AppModelID) | |
| 637 | 新增: .Count(); | |
| 638 | 新增: | |
| 639 | 新增: return res; | |
| 640 | 新增: } | |
| 641 | 新增: } | |
| 630 | 642 | } |
| 631 | 643 | } |
| @@ -97,5 +97,13 @@ namespace Core.Servicers.Interfaces | ||
| 97 | 97 | /// 导出数据到EXCEL |
| 98 | 98 | /// </summary> |
| 99 | 99 | void ExportToExcel(string dir, DateTime start, DateTime end); |
| 100 | 新增: /// <summary> | |
| 101 | 新增: /// 获取指定日期范围使用应用量 | |
| 102 | 新增: /// </summary> | |
| 103 | 新增: /// <param name="start"></param> | |
| 104 | 新增: /// <param name="end"></param> | |
| 105 | 新增: /// <returns></returns> | |
| 106 | 新增: int GetDateRangeAppCount(DateTime start, DateTime end); | |
| 107 | 新增: | |
| 100 | 108 | } |
| 101 | 109 | } |
| @@ -84,5 +84,14 @@ namespace UI.Models | ||
| 84 | 84 | |
| 85 | 85 | private ContextMenu AppContextMenu_; |
| 86 | 86 | public ContextMenu AppContextMenu { get { return AppContextMenu_; } set { AppContextMenu_ = value; OnPropertyChanged(); } } |
| 87 | 新增: | |
| 88 | 新增: private string TotalHours_; | |
| 89 | 新增: public string TotalHours { get { return TotalHours_; } set { TotalHours_ = value; OnPropertyChanged(); } } | |
| 90 | 新增: | |
| 91 | 新增: private string TopHours_; | |
| 92 | 新增: public string TopHours { get { return TopHours_; } set { TopHours_ = value; OnPropertyChanged(); } } | |
| 93 | 新增: private string AppCount_; | |
| 94 | 新增: public string AppCount { get { return AppCount_; } set { AppCount_ = value; OnPropertyChanged(); } } | |
| 95 | 新增: | |
| 87 | 96 | } |
| 88 | 97 | } |
| @@ -37,15 +37,122 @@ | ||
| 37 | 37 | </base:View> |
| 38 | 38 | </Grid> |
| 39 | 39 | </Border> |
| 40 | 删除: <TextBlock Text="分类" Foreground="#5c5c5c" FontSize="15" Margin="0,20,0,5"/> | |
| 40 | 新增: <Grid Width="680" HorizontalAlignment="Left" Margin="0,20,0,0"> | |
| 41 | 新增: <Grid.ColumnDefinitions> | |
| 42 | 新增: <ColumnDefinition Width="*"/> | |
| 43 | 新增: <ColumnDefinition Width="*"/> | |
| 44 | 新增: <ColumnDefinition Width="*"/> | |
| 45 | 新增: </Grid.ColumnDefinitions> | |
| 46 | 新增: <Border Margin="0,5,0,0" Background="White" Padding="10" CornerRadius="10"> | |
| 47 | 新增: <Grid> | |
| 48 | 新增: <Grid.ColumnDefinitions> | |
| 49 | 新增: <ColumnDefinition Width="auto"/> | |
| 50 | 新增: <ColumnDefinition Width="*"/> | |
| 51 | 新增: </Grid.ColumnDefinitions> | |
| 52 | 新增: <Border Background="#2b20d9" Width="40" Height="40" CornerRadius="6"> | |
| 41 | 53 | |
| 42 | 删除: <Border Margin="0,15,0,0" Height="360" Width="680" HorizontalAlignment="Left" Background="White" Padding="20" CornerRadius="10"> | |
| 43 | 删除: <charts:Charts DataMaximum="{Binding DataMaximum}" NameIndexStart="{Binding NameIndexStart}" ChartsType="Column" Data="{Binding Data}"/> | |
| 54 | 新增: <base:Icon IconType="SkypeCircleClock" Foreground="White"/> | |
| 55 | 新增: </Border> | |
| 56 | 新增: <Grid Grid.Column="1" Margin="10,0,0,0" VerticalAlignment="Center"> | |
| 57 | 新增: <Grid.RowDefinitions> | |
| 58 | 新增: <RowDefinition Height="auto"/> | |
| 59 | 新增: <RowDefinition Height="auto"/> | |
| 60 | 新增: </Grid.RowDefinitions> | |
| 61 | 新增: <TextBlock > | |
| 62 | 新增: <Run Text="{Binding TotalHours}" FontSize="20"/> | |
| 63 | 新增: <Run Text="小时" FontSize="12" Foreground="#5c5c5c"/> | |
| 64 | 新增: </TextBlock> | |
| 65 | 新增: <TextBlock Grid.Row="1" Margin="0,3,0,0" Text="总计" Foreground="#5c5c5c"/> | |
| 66 | 新增: | |
| 67 | 新增: </Grid> | |
| 68 | 新增: </Grid> | |
| 69 | 新增: </Border> | |
| 70 | 新增: <Border Grid.Column="1" Margin="20,5,0,0" Background="White" Padding="10" CornerRadius="10"> | |
| 71 | 新增: <Grid> | |
| 72 | 新增: <Grid.ColumnDefinitions> | |
| 73 | 新增: <ColumnDefinition Width="auto"/> | |
| 74 | 新增: <ColumnDefinition Width="*"/> | |
| 75 | 新增: </Grid.ColumnDefinitions> | |
| 76 | 新增: <Border Background="#ff305b" Width="40" Height="40" CornerRadius="6"> | |
| 77 | 新增: | |
| 78 | 新增: <base:Icon IconType="FlameSolid" Foreground="White"/> | |
| 79 | 新增: </Border> | |
| 80 | 新增: <Grid Grid.Column="1" Margin="10,0,0,0" VerticalAlignment="Center"> | |
| 81 | 新增: <Grid.RowDefinitions> | |
| 82 | 新增: <RowDefinition Height="auto"/> | |
| 83 | 新增: <RowDefinition Height="auto"/> | |
| 84 | 新增: </Grid.RowDefinitions> | |
| 85 | 新增: <TextBlock > | |
| 86 | 新增: <Run Text="{Binding TopHours}" FontSize="20"/> | |
| 87 | 新增: <Run Text="小时" FontSize="12" Foreground="#5c5c5c"/> | |
| 88 | 新增: </TextBlock> | |
| 89 | 新增: <TextBlock Grid.Row="1" Margin="0,3,0,0" Text="最长使用" Foreground="#5c5c5c"/> | |
| 90 | 新增: | |
| 91 | 新增: </Grid> | |
| 92 | 新增: </Grid> | |
| 93 | 新增: </Border> | |
| 94 | 新增: <Border Grid.Column="2" Margin="20,5,0,0" Background="White" Padding="10" CornerRadius="10"> | |
| 95 | 新增: <Grid> | |
| 96 | 新增: <Grid.ColumnDefinitions> | |
| 97 | 新增: <ColumnDefinition Width="auto"/> | |
| 98 | 新增: <ColumnDefinition Width="*"/> | |
| 99 | 新增: </Grid.ColumnDefinitions> | |
| 100 | 新增: <Border Background="#cccccc" Width="40" Height="40" CornerRadius="6"> | |
| 101 | 新增: | |
| 102 | 新增: <base:Icon IconType="MSNVideosSolid" Foreground="White"/> | |
| 103 | 新增: </Border> | |
| 104 | 新增: <Grid Grid.Column="1" Margin="10,0,0,0" VerticalAlignment="Center"> | |
| 105 | 新增: <Grid.RowDefinitions> | |
| 106 | 新增: <RowDefinition Height="auto"/> | |
| 107 | 新增: <RowDefinition Height="auto"/> | |
| 108 | 新增: </Grid.RowDefinitions> | |
| 109 | 新增: <TextBlock > | |
| 110 | 新增: <Run Text="{Binding AppCount}" FontSize="20"/> | |
| 111 | 新增: <Run Text="个" FontSize="12" Foreground="#5c5c5c"/> | |
| 112 | 新增: </TextBlock> | |
| 113 | 新增: <TextBlock Grid.Row="1" Margin="0,3,0,0" Text="应用量" Foreground="#5c5c5c"/> | |
| 114 | 新增: | |
| 115 | 新增: </Grid> | |
| 116 | 新增: </Grid> | |
| 117 | 新增: </Border> | |
| 118 | 新增: </Grid> | |
| 119 | 新增: | |
| 120 | 新增: <TextBlock Text="时段" Foreground="#5c5c5c" FontSize="15" Margin="0,20,0,5"/> | |
| 121 | 新增: | |
| 122 | 新增: <Border Margin="0,5,0,0" Height="360" Width="680" HorizontalAlignment="Left" Background="White" Padding="20" CornerRadius="10"> | |
| 123 | 新增: <charts:Charts IsShowTotal="False" DataMaximum="{Binding DataMaximum}" NameIndexStart="{Binding NameIndexStart}" ChartsType="Column" Data="{Binding Data}"/> | |
| 44 | 124 | |
| 45 | 125 | </Border> |
| 46 | 删除: <TextBlock Text="最为频繁的应用" Foreground="#5c5c5c" FontSize="15" Margin="0,20,0,5"/> | |
| 47 | 删除: <Border Margin="0,10,0,0" Width="680" HorizontalAlignment="Left" Background="White" Padding="20" CornerRadius="10"> | |
| 48 | 删除: <charts:Charts Height="300" ItemMenu="{Binding AppContextMenu}" Data="{Binding TopData}" ChartsType="HorizontalA" ClickCommand="{Binding ToDetailCommand}"/> | |
| 49 | 删除: </Border> | |
| 126 | 新增: | |
| 127 | 新增: <Grid Width="680" HorizontalAlignment="Left"> | |
| 128 | 新增: <Grid.ColumnDefinitions> | |
| 129 | 新增: <ColumnDefinition Width="*"/> | |
| 130 | 新增: <ColumnDefinition Width="*"/> | |
| 131 | 新增: </Grid.ColumnDefinitions> | |
| 132 | 新增: <Grid > | |
| 133 | 新增: <Grid.RowDefinitions> | |
| 134 | 新增: <RowDefinition Height="auto"/> | |
| 135 | 新增: <RowDefinition Height="*"/> | |
| 136 | 新增: </Grid.RowDefinitions> | |
| 137 | 新增: <TextBlock Text="分类" Foreground="#5c5c5c" FontSize="15" Margin="0,20,0,5"/> | |
| 138 | 新增: <Border Margin="0,5,0,0" Grid.Row="1" Background="White" Padding="20" CornerRadius="10"> | |
| 139 | 新增: <charts:Charts Margin="10,20,10,10" Height="230" Width="230" ChartsType="Radar" Data="{Binding Data}"/> | |
| 140 | 新增: | |
| 141 | 新增: </Border> | |
| 142 | 新增: </Grid> | |
| 143 | 新增: <Grid Grid.Column="1" Margin="20,0,0,0"> | |
| 144 | 新增: <Grid.RowDefinitions> | |
| 145 | 新增: <RowDefinition Height="auto"/> | |
| 146 | 新增: <RowDefinition Height="auto"/> | |
| 147 | 新增: </Grid.RowDefinitions> | |
| 148 | 新增: <TextBlock Text="最为频繁" Foreground="#5c5c5c" FontSize="15" Margin="0,20,0,5"/> | |
| 149 | 新增: <Border Grid.Row="1" Margin="0,5,0,0" Background="White" Padding="20" CornerRadius="10"> | |
| 150 | 新增: <charts:Charts ItemMenu="{Binding AppContextMenu}" Data="{Binding TopData}" ChartsType="HorizontalA" ClickCommand="{Binding ToDetailCommand}" IsCanScroll="False"/> | |
| 151 | 新增: </Border> | |
| 152 | 新增: </Grid> | |
| 153 | 新增: </Grid> | |
| 154 | 新增: | |
| 155 | 新增: | |
| 156 | 新增: | |
| 50 | 157 | </StackPanel> |
| 51 | 158 | </Page> |

