diff --git a/src/DataAccess/SmartThermo.DataAccess.Sqlite/Context.cs b/src/DataAccess/SmartThermo.DataAccess.Sqlite/Context.cs index e41acf3..325e581 100644 --- a/src/DataAccess/SmartThermo.DataAccess.Sqlite/Context.cs +++ b/src/DataAccess/SmartThermo.DataAccess.Sqlite/Context.cs @@ -1,5 +1,7 @@ using Microsoft.EntityFrameworkCore; using SmartThermo.DataAccess.Sqlite.Models; +using System; +using System.Collections.Generic; namespace SmartThermo.DataAccess.Sqlite { @@ -11,6 +13,28 @@ public class Context : DbContext public DbSet SensorInformations { get; set; } + public DbSet Settings { get; set; } + + public DbSet SelectModes { get; set; } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity().HasData(new Setting + { + Id = 1, + }); + + modelBuilder.Entity().HasData(new SelectMode[] + { + new SelectMode { Id = 1, SettingId = 1, Stage = false }, + new SelectMode { Id = 2, SettingId = 1, Stage = false }, + new SelectMode { Id = 3, SettingId = 1, Stage = false }, + new SelectMode { Id = 4, SettingId = 1, Stage = false }, + new SelectMode { Id = 5, SettingId = 1, Stage = false }, + new SelectMode { Id = 6, SettingId = 1, Stage = false } + }); + } + protected override void OnConfiguring(DbContextOptionsBuilder options) => options.UseSqlite(@"Data Source=app.db"); } diff --git a/src/DataAccess/SmartThermo.DataAccess.Sqlite/Models/SelectMode.cs b/src/DataAccess/SmartThermo.DataAccess.Sqlite/Models/SelectMode.cs new file mode 100644 index 0000000..939fa93 --- /dev/null +++ b/src/DataAccess/SmartThermo.DataAccess.Sqlite/Models/SelectMode.cs @@ -0,0 +1,13 @@ +namespace SmartThermo.DataAccess.Sqlite.Models +{ + public class SelectMode + { + public int Id { get; set; } + + public bool Stage { get; set; } + + public int SettingId { get; set; } + + public Setting Setting { get; set; } + } +} diff --git a/src/DataAccess/SmartThermo.DataAccess.Sqlite/Models/Setting.cs b/src/DataAccess/SmartThermo.DataAccess.Sqlite/Models/Setting.cs new file mode 100644 index 0000000..fa5db2c --- /dev/null +++ b/src/DataAccess/SmartThermo.DataAccess.Sqlite/Models/Setting.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; + +namespace SmartThermo.DataAccess.Sqlite.Models +{ + public class Setting + { + public int Id { get; set; } + + public List SelectModes { get; set; } + } +} diff --git a/src/Modules/SmartThermo.Modules.DataViewer/ViewModels/Represent/LoadDataViewerWindowViewModel.cs b/src/Modules/SmartThermo.Modules.DataViewer/ViewModels/Represent/LoadDataViewerWindowViewModel.cs index 141c3c9..a98b335 100644 --- a/src/Modules/SmartThermo.Modules.DataViewer/ViewModels/Represent/LoadDataViewerWindowViewModel.cs +++ b/src/Modules/SmartThermo.Modules.DataViewer/ViewModels/Represent/LoadDataViewerWindowViewModel.cs @@ -151,6 +151,13 @@ public LoadDataViewerWindowViewModel(IDeviceConnector deviceConnector, INotifica SelectMode[(int)i - 1] = !SelectMode[(int)i - 1]; RaisePropertyChanged(nameof(SelectMode)); + + using var context = new Context(); + var selectMode = context.SelectModes + .Where(x => x.Id == i) + .FirstOrDefault(); + selectMode.Stage = _selectMode[(int)i - 1]; + context.SaveChanges(); }); } @@ -251,12 +258,13 @@ private void InitCharts() ChartValues.AddRange(Enumerable.Range(0, 36) .Select(x => new ChartValues()) .ToList()); + Temperature.AddRange(Enumerable.Range(0,36) + .Select(x => 0) + .ToList()); LimitRelayItems.AddRange(Enumerable.Range(0, 6) .Select(x => new LimitRelay()) .ToList()); - SelectMode.AddRange(Enumerable.Range(0, 6) - .Select(x => false) - .ToList()); + GetSelectMode(); XFormatter = value => new DateTime((long)value).ToString("mm:ss"); YFormatter = value => Math.Round(value, 1).ToString(CultureInfo.InvariantCulture); @@ -267,6 +275,12 @@ private void InitCharts() SetRelayLimits(); } + private void GetSelectMode() + { + using var context = new Context(); + SelectMode.AddRange(context.SelectModes.Select(x => x.Stage).ToList()); + } + private void SetRelayLimits() { var data = _deviceConnector.SettingDevice; diff --git a/src/Modules/SmartThermo.Modules.DataViewer/Views/Charts/CustomersTooltip.xaml b/src/Modules/SmartThermo.Modules.DataViewer/Views/Charts/CustomersTooltip.xaml new file mode 100644 index 0000000..9f3d4df --- /dev/null +++ b/src/Modules/SmartThermo.Modules.DataViewer/Views/Charts/CustomersTooltip.xaml @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Modules/SmartThermo.Modules.DataViewer/Views/Charts/CustomersTooltip.xaml.cs b/src/Modules/SmartThermo.Modules.DataViewer/Views/Charts/CustomersTooltip.xaml.cs new file mode 100644 index 0000000..9e44565 --- /dev/null +++ b/src/Modules/SmartThermo.Modules.DataViewer/Views/Charts/CustomersTooltip.xaml.cs @@ -0,0 +1,40 @@ +using LiveCharts; +using LiveCharts.Wpf; +using System.ComponentModel; + +namespace SmartThermo.Modules.DataViewer.Views.Charts +{ + /// + /// Interaction logic for CustomersTooltip.xaml + /// + public partial class CustomersTooltip : IChartTooltip + { + public event PropertyChangedEventHandler PropertyChanged; + + private TooltipData _data; + + public CustomersTooltip() + { + InitializeComponent(); + DataContext = this; + } + + public TooltipData Data + { + get { return _data; } + set + { + _data = value; + OnPropertyChanged("Data"); + } + } + + public TooltipSelectionMode? SelectionMode { get; set; } + + protected virtual void OnPropertyChanged(string propertyName = null) + { + if (PropertyChanged != null) + PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + } +} diff --git a/src/Modules/SmartThermo.Modules.DataViewer/Views/Represent/LoadDataViewerWindow.xaml b/src/Modules/SmartThermo.Modules.DataViewer/Views/Represent/LoadDataViewerWindow.xaml index d03ecb0..b99e5a3 100644 --- a/src/Modules/SmartThermo.Modules.DataViewer/Views/Represent/LoadDataViewerWindow.xaml +++ b/src/Modules/SmartThermo.Modules.DataViewer/Views/Represent/LoadDataViewerWindow.xaml @@ -3,7 +3,7 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:local="clr-namespace:SmartThermo.Modules.DataViewer.Views.Represent" + xmlns:local="clr-namespace:SmartThermo.Modules.DataViewer.Views.Charts" xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:prism="http://prismlibrary.com/" @@ -145,7 +145,7 @@ - +