diff --git a/Core/Servicers/Instances/Data.cs b/Core/Servicers/Instances/Data.cs index 97b8ec6876dbd9b9e37221f0afa0390fda665bc7..16489f94940f61dc5c5e519a25a72db2606f1ec3 100644 --- a/Core/Servicers/Instances/Data.cs +++ b/Core/Servicers/Instances/Data.cs @@ -67,7 +67,7 @@ namespace Core.Servicers.Instances { res.Time += seconds; } - + db.SaveChanges(); transcation.Commit(); } @@ -101,7 +101,7 @@ namespace Core.Servicers.Instances return; } - + using (var db = new TaiDbContext()) { @@ -686,5 +686,21 @@ namespace Core.Servicers.Instances return res; } } + + public IEnumerable GetTimeRangelogList(DateTime time) + { + time = new DateTime(time.Year, time.Month, time.Day, time.Hour, 0, 0); + using (var db = new TaiDbContext()) + { + var res = db.HoursLog.Where(m => m.DataTime == time).ToList(); + + foreach (var log in res) + { + log.AppModel = appData.GetApp(log.AppModelID); + } + + return res; + } + } } } diff --git a/Core/Servicers/Interfaces/IData.cs b/Core/Servicers/Interfaces/IData.cs index 6753d0f1e77bc6e9ef35a8fe65c71e98ce35c6d1..20ddd2d8607fc7a5618e2681a4850805649c2607 100644 --- a/Core/Servicers/Interfaces/IData.cs +++ b/Core/Servicers/Interfaces/IData.cs @@ -104,6 +104,12 @@ namespace Core.Servicers.Interfaces /// /// int GetDateRangeAppCount(DateTime start, DateTime end); + /// + /// 获取指定时间(小时)所有使用app数据 + /// + /// + /// + IEnumerable GetTimeRangelogList(DateTime time); } } diff --git a/UI/Controls/Charts/Charts.cs b/UI/Controls/Charts/Charts.cs index 46345c8f787d7d2a6ad26133918e840c63ddf7c1..667d973bdefebfb26f1099562ba96b585afd1ac1 100644 --- a/UI/Controls/Charts/Charts.cs +++ b/UI/Controls/Charts/Charts.cs @@ -310,6 +310,39 @@ namespace UI.Controls.Charts new PropertyMetadata(true)); + #endregion + #region 是否允许选择项(仅柱状图有效,默认不允许) + /// + /// 是否允许选择项(仅柱状图有效,默认不允许) + /// + public bool IsCanColumnSelect + { + get { return (bool)GetValue(IsCanColumnSelectProperty); } + set { SetValue(IsCanColumnSelectProperty, value); } + } + public static readonly DependencyProperty IsCanColumnSelectProperty = + DependencyProperty.Register("IsCanColumnSelect", + typeof(bool), + typeof(Charts), + new PropertyMetadata(false)); + + + #endregion + #region 选中列索引(仅柱状图有效) + /// + /// 选中列索引(仅柱状图有效) + /// + public int ColumnSelectedIndex + { + get { return (int)GetValue(ColumnSelectedIndexProperty); } + set { SetValue(ColumnSelectedIndexProperty, value); } + } + public static readonly DependencyProperty ColumnSelectedIndexProperty = + DependencyProperty.Register("ColumnSelectedIndex", + typeof(int), + typeof(Charts), new PropertyMetadata(-1, new PropertyChangedCallback(OnPropertyChanged))); + + #endregion public bool IsShowValuesPopup { @@ -386,6 +419,10 @@ namespace UI.Controls.Charts charts.RenderLoadingPlaceholder(); } } + if (e.Property == ColumnSelectedIndexProperty && e.OldValue != e.NewValue) + { + charts.CheckColumnItem((int)e.OldValue, (int)e.NewValue); + } } @@ -873,6 +910,29 @@ namespace UI.Controls.Charts #endregion #region 渲染柱形图 + private void CheckColumnItem(int oldIndex, int newIndex) + { + if (!IsCanColumnSelect || ColumnContainer.Children.Count == 0) + { + return; + } + + if (oldIndex >= 0 && oldIndex < ColumnContainer.Children.Count) + { + var oldItem = ColumnContainer.Children[oldIndex] as Grid; + oldItem.Background = new SolidColorBrush(Colors.Transparent); + } + if (newIndex >= 0 && newIndex < ColumnContainer.Children.Count) + { + var background = Application.Current.Resources["ThemeBrush"] as SolidColorBrush; + + var checkItem = ColumnContainer.Children[newIndex] as Grid; + checkItem.Background = new SolidColorBrush(background.Color) { Opacity = .1 }; + } + } + /// + /// 渲染柱形图 + /// private void RenderColumnStyle() { ColumnContainer.Children.Clear(); @@ -997,6 +1057,12 @@ namespace UI.Controls.Charts { IsShowValuesPopup = false; }; + + var index = i; + valueContainer.MouseLeftButtonDown += (e, c) => + { + ColumnSelectedIndex = index; + }; } var infoList = new List(); diff --git a/UI/Models/ChartPageModel.cs b/UI/Models/ChartPageModel.cs index 443125a453e497cf9723c94c9d5f5be55355697b..82d2b62931d354725ccf9e8af8f67fd295d8f5bc 100644 --- a/UI/Models/ChartPageModel.cs +++ b/UI/Models/ChartPageModel.cs @@ -81,7 +81,7 @@ namespace UI.Models private double DataMaximum_ = 0; public double DataMaximum { get { return DataMaximum_; } set { DataMaximum_ = value; OnPropertyChanged(); } } - + private ContextMenu AppContextMenu_; public ContextMenu AppContextMenu { get { return AppContextMenu_; } set { AppContextMenu_ = value; OnPropertyChanged(); } } @@ -93,5 +93,29 @@ namespace UI.Models private string AppCount_; public string AppCount { get { return AppCount_; } set { AppCount_ = value; OnPropertyChanged(); } } + private int ColumnSelectedIndex_ = -1; + /// + /// 柱状图选中列索引 + /// + public int ColumnSelectedIndex { get { return ColumnSelectedIndex_; } set { ColumnSelectedIndex_ = value; OnPropertyChanged(); } } + private List DayHoursData_; + /// + /// 指定时段app数据 + /// + public List DayHoursData + { + get { return DayHoursData_; } + set { DayHoursData_ = value; OnPropertyChanged(); } + } + private string DayHoursSelectedTime_; + /// + /// 选中时段 + /// + public string DayHoursSelectedTime { get { return DayHoursSelectedTime_; } set { DayHoursSelectedTime_ = value; OnPropertyChanged(); } } + private bool IsCanColumnSelect_ = true; + /// + /// 是否允许选择 + /// + public bool IsCanColumnSelect { get { return IsCanColumnSelect_; } set { IsCanColumnSelect_ = value; OnPropertyChanged(); } } } } diff --git a/UI/Servicers/AppContextMenuServicer.cs b/UI/Servicers/AppContextMenuServicer.cs index ee7a023c3c3321d93d25cfbadcd157f77e66aff4..96fff6b099c788bf40d57e2edf8545e98b989434 100644 --- a/UI/Servicers/AppContextMenuServicer.cs +++ b/UI/Servicers/AppContextMenuServicer.cs @@ -93,7 +93,13 @@ namespace UI.Servicers { var data = menu.Tag as ChartsDataModel; var log = data.Data as DailyLogModel; - var app = log.AppModel; + var app = log != null ? log.AppModel : null; + + if (log == null) + { + app = (data.Data as HoursLogModel).AppModel; + } + var config = appConfig.GetConfig(); if (config.Behavior.IgnoreProcessList.Contains(app.Name)) @@ -117,7 +123,12 @@ namespace UI.Servicers var data = menu.Tag as ChartsDataModel; var log = data.Data as DailyLogModel; - var app = log.AppModel; + var app = log != null ? log.AppModel : null; + + if (log == null) + { + app = (data.Data as HoursLogModel).AppModel; + } var categories = categorys.GetCategories(); foreach (var category in categories) @@ -140,7 +151,12 @@ namespace UI.Servicers var data = menu.Tag as ChartsDataModel; var log = data.Data as DailyLogModel; - var app = log.AppModel; + var app = log != null ? log.AppModel : null; + + if (log == null) + { + app = (data.Data as HoursLogModel).AppModel; + } var config = appConfig.GetConfig(); var links = config.Links; @@ -199,8 +215,12 @@ namespace UI.Servicers var data = menu.Tag as ChartsDataModel; var log = data.Data as DailyLogModel; + var app = log != null ? log.AppModel : null; - var app = log.AppModel; + if (log == null) + { + app = (data.Data as HoursLogModel).AppModel; + } if (File.Exists(app.File)) { @@ -217,8 +237,12 @@ namespace UI.Servicers var data = menu.Tag as ChartsDataModel; var log = data.Data as DailyLogModel; + var app = log != null ? log.AppModel : null; - var app = log.AppModel; + if (log == null) + { + app = (data.Data as HoursLogModel).AppModel; + } if (File.Exists(app.File)) { diff --git a/UI/ViewModels/ChartPageVM.cs b/UI/ViewModels/ChartPageVM.cs index 079803ee2437cbf0b4902b0496c6bb1d1fd35717..9c4baaad227459518964e0563142581e7a3a1b9e 100644 --- a/UI/ViewModels/ChartPageVM.cs +++ b/UI/ViewModels/ChartPageVM.cs @@ -73,7 +73,7 @@ namespace UI.ViewModels AppContextMenu = appContextMenuServicer.GetContextMenu(); } - + public override void Dispose() { base.Dispose(); @@ -88,9 +88,16 @@ namespace UI.ViewModels if (data != null) { var model = data.Data as DailyLogModel; - if (model != null && model.AppModel != null) + var app = model != null ? model.AppModel : null; + + if (model == null) + { + app = (data.Data as HoursLogModel).AppModel; + } + + if (app != null) { - mainVM.Data = model.AppModel; + mainVM.Data = app; mainVM.Uri = nameof(DetailPage); } @@ -99,13 +106,21 @@ namespace UI.ViewModels private void OnRefreshCommand(object obj) { LoadData(); + if (TabbarSelectedIndex == 0) + { + LoadDayHoursData(); + } } private void InputServicer_OnKeyUpInput(object sender, System.Windows.Forms.Keys key) { - if(key== System.Windows.Forms.Keys.F5) + if (key == System.Windows.Forms.Keys.F5) { LoadData(); + if (TabbarSelectedIndex == 0) + { + LoadDayHoursData(); + } } } @@ -118,7 +133,7 @@ namespace UI.ViewModels } if (e.PropertyName == nameof(TabbarSelectedIndex)) { - + IsCanColumnSelect = TabbarSelectedIndex == 0; LoadData(); } if (e.PropertyName == nameof(SelectedWeek)) @@ -133,6 +148,13 @@ namespace UI.ViewModels { LoadYearData(); } + if (e.PropertyName == nameof(ColumnSelectedIndex)) + { + if (TabbarSelectedIndex == 0) + { + LoadDayHoursData(); + } + } } @@ -165,6 +187,7 @@ namespace UI.ViewModels /// private void LoadDayData() { + ColumnSelectedIndex = -1; DataMaximum = 3600; Task.Run(() => { @@ -440,5 +463,37 @@ namespace UI.ViewModels return resData; } + + private void LoadDayHoursData() + { + if (ColumnSelectedIndex < 0) + { + DayHoursSelectedTime = String.Empty; + return; + } + Task.Run(() => + { + // 加载选中时段的所有app数据 + var time = new DateTime(Date.Year, Date.Month, Date.Day, ColumnSelectedIndex, 0, 0); + DayHoursSelectedTime = time.ToString("yyyy年MM月dd日 HH点"); + var list = data.GetTimeRangelogList(time); + + var chartsDatas = new List(); + + foreach (var item in list) + { + var bindModel = new ChartsDataModel(); + bindModel.Data = item; + bindModel.Name = string.IsNullOrEmpty(item.AppModel?.Description) ? item.AppModel.Name : item.AppModel.Description; + bindModel.Value = item.Time; + bindModel.Tag = Time.ToString(item.Time); + bindModel.PopupText = item.AppModel?.File; + bindModel.Icon = item.AppModel?.IconFile; + chartsDatas.Add(bindModel); + } + + DayHoursData = chartsDatas; + }); + } } } diff --git a/UI/Views/ChartPage.xaml b/UI/Views/ChartPage.xaml index 1abbeabc6169ad40855e5c1ffa79caa26f28fdd8..4515ad558f97c83178c48da7ab68e164ffcd80de 100644 --- a/UI/Views/ChartPage.xaml +++ b/UI/Views/ChartPage.xaml @@ -41,6 +41,7 @@ + @@ -137,42 +138,103 @@ - + + + + + + + + + - - + + + + + + + + + + + + + - + + + + + + + + + + + + + - - - - - - + + + + + + - + + + - + + - + - + +