Skip to content

Commit d2f77fd

Browse files
committed
Added legends chart and check current active com ports.
1 parent baaaa89 commit d2f77fd

File tree

10 files changed

+61
-20
lines changed

10 files changed

+61
-20
lines changed

src/Modules/SmartThermo.Modules.Analytics/Dialogs/ViewModels/SessionDialogViewModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ private bool CheckSessionItemsForZero()
124124

125125
private async void GetSessionInfo()
126126
{
127+
// TODO: Зарефакторить.
127128
var sessionInfoTask = Task.Run(() =>
128129
{
129130
using var context = new Context();

src/Modules/SmartThermo.Modules.Analytics/Dialogs/Views/SessionDialog.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@
101101
Grid.Row="1"
102102
Width="150"
103103
Command="{Binding CancelCommand}"
104-
Content="Отмена" />
104+
Content="Отмена"
105+
Style="{DynamicResource AccentButtonStyle}" />
105106
</Grid>
106107
</GroupBox>
107108
</Grid>

src/Modules/SmartThermo.Modules.Analytics/ViewModels/AnalyticsWindowViewModel.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ private void InitChart()
114114
tick: Color.FromArgb(170, 170, 170));
115115
_plot.XAxis.TickLabelStyle(fontSize: 12);
116116
_plot.YAxis.TickLabelStyle(fontSize: 12);
117+
118+
var legend = _plot.Legend();
119+
legend.Padding = 8;
120+
legend.FontSize = 12;
117121
}
118122

119123
private async void InitChartValueAsync()
@@ -191,17 +195,23 @@ private async Task GetSensorDataAsync()
191195
var result = getItemsTask.Result;
192196

193197
if (GroupCheckItems[0].Value)
194-
_plot.AddSignal(result.Select(x => (double)x.Value1).ToArray(), color: Color.FromArgb(0x00, 0x3f, 0x5c));
198+
_plot.AddSignal(result.Select(x => (double) x.Value1).ToArray(),
199+
color: Color.FromArgb(0x00, 0x3f, 0x5c), label: "Датчик №1");
195200
if (GroupCheckItems[1].Value)
196-
_plot.AddSignal(result.Select(x => (double)x.Value2).ToArray(), color: Color.FromArgb(0x44, 0x4e, 0x86));
201+
_plot.AddSignal(result.Select(x => (double) x.Value2).ToArray(),
202+
color: Color.FromArgb(0x44, 0x4e, 0x86), label: "Датчик №2");
197203
if (GroupCheckItems[2].Value)
198-
_plot.AddSignal(result.Select(x => (double)x.Value3).ToArray(), color: Color.FromArgb(0x95, 0x51, 0x96));
204+
_plot.AddSignal(result.Select(x => (double) x.Value3).ToArray(),
205+
color: Color.FromArgb(0x95, 0x51, 0x96), label: "Датчик №3");
199206
if (GroupCheckItems[3].Value)
200-
_plot.AddSignal(result.Select(x => (double)x.Value4).ToArray(), color: Color.FromArgb(0xdd, 0x51, 0x82));
207+
_plot.AddSignal(result.Select(x => (double) x.Value4).ToArray(),
208+
color: Color.FromArgb(0xdd, 0x51, 0x82), label: "Датчик №4");
201209
if (GroupCheckItems[4].Value)
202-
_plot.AddSignal(result.Select(x => (double)x.Value5).ToArray(), color: Color.FromArgb(0xff, 0x6e, 0x54));
210+
_plot.AddSignal(result.Select(x => (double) x.Value5).ToArray(),
211+
color: Color.FromArgb(0xff, 0x6e, 0x54), label: "Датчик №5");
203212
if (GroupCheckItems[5].Value)
204-
_plot.AddSignal(result.Select(x => (double)x.Value6).ToArray(), color: Color.FromArgb(0xff, 0xa6, 0x00));
213+
_plot.AddSignal(result.Select(x => (double) x.Value6).ToArray(),
214+
color: Color.FromArgb(0xff, 0xa6, 0x00), label: "Датчик №6");
205215

206216
_plot.AxisAutoX();
207217
_plot.SetAxisLimitsY(0, 165);

src/Modules/SmartThermo.Modules.Analytics/Views/AnalyticsWindow.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
<ColumnDefinition Width="auto" />
2121
</Grid.ColumnDefinitions>
2222

23-
<ContentControl Margin="0,8,8,0" Content="{Binding PlotControl}" />
23+
<ContentControl Margin="0,16,16,0" Content="{Binding PlotControl}" />
2424

2525
<Border
2626
Grid.Column="1"
27-
Margin="0,8,0,0"
27+
Margin="0,16,0,0"
2828
Background="{DynamicResource SystemControlBackgroundBaseMediumLowBrush}" />
2929

30-
<Grid Grid.Column="2" Margin="8,8,0,8">
30+
<Grid Grid.Column="2" Margin="16,8,0,8">
3131
<ui:SimpleStackPanel Spacing="16">
3232
<GroupBox Padding="0,-8,0,0" Header="Сессии">
3333
<ui:SimpleStackPanel Orientation="Vertical" Spacing="8">

src/Modules/SmartThermo.Modules.DataViewer/Views/Represent/LoadDataViewerWindow.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<ColumnDefinition Width="Auto" />
2424
</Grid.ColumnDefinitions>
2525

26-
<Grid Margin="0,0,8,0">
26+
<Grid Margin="0,8,8,0">
2727
<Grid.ColumnDefinitions>
2828
<ColumnDefinition />
2929
<ColumnDefinition />
@@ -784,11 +784,11 @@
784784

785785
<Border
786786
Grid.Column="1"
787-
Margin="0,8,0,0"
787+
Margin="0,16,0,0"
788788
Background="{DynamicResource SystemControlBackgroundBaseMediumLowBrush}" />
789789
<DataGrid
790790
Grid.Column="2"
791-
Padding="8,8,0,0"
791+
Padding="16,16,0,0"
792792
AutoGenerateColumns="False"
793793
Background="Transparent"
794794
CanUserResizeColumns="False"

src/Modules/SmartThermo.Modules.Dialog.SettingsPort/ViewModels/SettingsPortDialogViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ private void UploadingDataSources()
159159

160160
private void SetDefaultSettings()
161161
{
162-
AddressDeviceSelected = 3;
163162
PortNameSelected = PortName[0];
163+
AddressDeviceSelected = 3;
164164
BaudRateSelected = BaudRate.S9600;
165165
StopBitsSelected = StopBits.One;
166166
ParitySelected = Parity.None;

src/SmartThermo/App.xaml.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using Prism.Ioc;
1+
using Microsoft.AppCenter;
2+
using Microsoft.AppCenter.Analytics;
3+
using Microsoft.AppCenter.Crashes;
4+
using Prism.Ioc;
25
using Prism.Modularity;
36
using SmartThermo.Modules.Analytics;
47
using SmartThermo.Modules.DataViewer;
@@ -15,13 +18,27 @@
1518
using ToastNotifications.Lifetime;
1619
using ToastNotifications.Position;
1720

21+
1822
namespace SmartThermo
1923
{
2024
/// <summary>
2125
/// Interaction logic for App.xaml
2226
/// </summary>
2327
public partial class App
2428
{
29+
public App()
30+
{
31+
AppDomain.CurrentDomain.UnhandledException += (sender, e)
32+
=> MessageBox.Show(e.ExceptionObject.ToString());
33+
}
34+
35+
protected override void OnStartup(StartupEventArgs e)
36+
{
37+
base.OnStartup(e);
38+
AppCenter.Start("3fb4a695-2ae6-4663-9878-d0fa3ada2d1e",
39+
typeof(Analytics), typeof(Crashes));
40+
}
41+
2542
protected override Window CreateShell()
2643
{
2744
return Container.Resolve<MainWindow>();
@@ -60,7 +77,6 @@ protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
6077
}
6178

6279
// -Tooltip и легенда для аналитики.
63-
// -Margin для всех.
6480
// -Перевод графика во дата.
6581
// -Запись null значений.
6682
// -Выбор сессию (нет значений, если count ==0).

src/SmartThermo/SmartThermo.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15+
<PackageReference Include="Microsoft.AppCenter.Analytics" Version="4.2.0" />
16+
<PackageReference Include="Microsoft.AppCenter.Crashes" Version="4.2.0" />
1517
<PackageReference Include="ModernWpfUI" Version="0.9.4" />
1618
<PackageReference Include="NModbus" Version="3.0.62" />
1719
<PackageReference Include="NModbus.Serial" Version="3.0.62" />

src/SmartThermo/ViewModels/MainWindowViewModel.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using SmartThermo.Services.Notifications;
1414
using System;
1515
using System.Collections.Generic;
16+
using System.IO.Ports;
1617
using System.Threading.Tasks;
1718
using System.Windows;
1819
using ToastNotifications.Core;
@@ -98,7 +99,6 @@ public MainWindowViewModel(IRegionManager regionManager, IDeviceConnector device
9899

99100
private async void CreateSession()
100101
{
101-
// TODO: Возможно убрать в StartOn.
102102
CheckDatabaseCreate();
103103

104104
await using var context = new Context();
@@ -147,11 +147,19 @@ private void ChangeConnectDeviceExecute()
147147
Notifications.ShowWarning("Не удалось закрыть соединение.\n" + ex.Message, new MessageOptions());
148148
}
149149
else
150+
{
151+
if (SerialPort.GetPortNames().Length == 0)
152+
{
153+
Notifications.ShowError("В компьютере найдены активные COM порты.");
154+
return;
155+
}
150156
DialogService.ShowNotification("SettingsPortDialog", r =>
151157
{
152158
if (r.Result == ButtonResult.Cancel)
153159
Notifications.ShowInformation("Операция прервана пользователем.");
154160
});
161+
}
162+
155163
}
156164

157165
private void SettingDeviceExecute()

src/SmartThermo/Views/MainWindow.xaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
55
xmlns:core="clr-namespace:SmartThermo.Core;assembly=SmartThermo.Core"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
67
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
78
xmlns:prism="http://prismlibrary.com/"
89
xmlns:ui="http://schemas.modernwpf.com/2019"
9-
Width="1366"
10-
Height="768"
10+
Title="SmartThermo"
11+
MinWidth="1280"
12+
MinHeight="720"
1113
prism:ViewModelLocator.AutoWireViewModel="True"
1214
ui:ThemeManager.RequestedTheme="Dark"
1315
ui:WindowHelper.UseModernWindowStyle="True"
1416
Background="{DynamicResource SystemControlPageBackgroundChromeMediumLowBrush}"
15-
WindowStartupLocation="CenterScreen">
17+
WindowStartupLocation="CenterScreen"
18+
WindowState="Maximized">
1619

1720
<Grid>
1821
<Grid.RowDefinitions>

0 commit comments

Comments
 (0)