-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDialogWindowPropertiesComControl.xaml.cs
158 lines (126 loc) · 5.88 KB
/
DialogWindowPropertiesComControl.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace SCADA
{
/// <summary>
/// Логика взаимодействия для DialogWindowPropertiesComControl.xaml
/// </summary>
public partial class DialogWindowPropertiesComControl : Window
{
GridPropertiesComGeneral PropertiesGeneral;
Popup Message = new Popup();
string OldComPort;
string OldStopBits;
string OldDescription;
string OldParity;
int OldBaudRate;
int OldReadTimeout;
int OldWriteTimeout;
int OldDataBits;
ComControl ComControl;
public DialogWindowPropertiesComControl(ComControl comControl)
{
InitializeComponent();
Label l = new Label();
l.BorderBrush = Brushes.Red;
l.BorderThickness = new Thickness(3);
l.Background = Brushes.White;
Message.Child = l;
OldComPort = comControl.ComSer.ComPort;
OldStopBits = comControl.ComSer.StopBits;
OldDescription = comControl.ComSer.Description;
OldParity = comControl.ComSer.Parity;
OldBaudRate = comControl.ComSer.BaudRate;
OldReadTimeout = comControl.ComSer.ReadTimeout;
OldWriteTimeout = comControl.ComSer.WriteTimeout;
OldDataBits = comControl.ComSer.DataBits;
ComControl = comControl;
PropertiesGeneral = new GridPropertiesComGeneral(comControl);
}
private void Apply(object sender, RoutedEventArgs e)
{
e.Handled = true;
int readTimeout;
int writeTimeout;
int.TryParse(PropertiesGeneral.TBReadTimeout.Text, out readTimeout);
int.TryParse(PropertiesGeneral.TBWriteTimeout.Text, out writeTimeout);
if (PropertiesGeneral.TBDescriptionCom.Text.Length > 150)
{
PropertiesGeneral.LPopupMessage.Content = "Описание не может быть длинее 150 символов.";
PropertiesGeneral.PopupMessage.PlacementTarget = PropertiesGeneral.TBDescriptionCom;
PropertiesGeneral.PopupMessage.IsOpen = true;
PropertiesGeneral.TBDescriptionCom.SelectAll();
PropertiesGeneral.TBDescriptionCom.Focus();
return;
}
if (readTimeout < 50 || readTimeout > 5000)
{
PropertiesGeneral.LPopupMessage.Content = "Диапазон 50 - 5000";
PropertiesGeneral.PopupMessage.PlacementTarget = PropertiesGeneral.TBReadTimeout;
PropertiesGeneral.PopupMessage.IsOpen = true;
PropertiesGeneral.TBReadTimeout.SelectAll();
PropertiesGeneral.TBReadTimeout.Focus();
return;
}
if (writeTimeout < 50 || writeTimeout > 5000)
{
PropertiesGeneral.LPopupMessage.Content = "Диапазон 50 - 5000";
PropertiesGeneral.PopupMessage.PlacementTarget = PropertiesGeneral.TBWriteTimeout;
PropertiesGeneral.PopupMessage.IsOpen = true;
PropertiesGeneral.TBWriteTimeout.SelectAll();
PropertiesGeneral.TBWriteTimeout.Focus();
return;
}
if (OldComPort != PropertiesGeneral.CBPortName.SelectedItem || OldStopBits != PropertiesGeneral.CBStopBits.SelectedItem || OldDescription != PropertiesGeneral.TBDescriptionCom.Text
|| OldParity != PropertiesGeneral.CBParity.SelectedItem || OldBaudRate != (int)PropertiesGeneral.CBBaudRate.SelectedItem
|| OldReadTimeout != readTimeout || OldWriteTimeout != writeTimeout || OldDataBits != (int)PropertiesGeneral.CBDataBits.SelectedItem)
{
ComControl.ComSer.ComPort = (string)PropertiesGeneral.CBPortName.SelectedItem;
ComControl.ComSer.StopBits = (string)PropertiesGeneral.CBStopBits.SelectedItem;
ComControl.ComSer.Description = PropertiesGeneral.TBDescriptionCom.Text;
ComControl.ComSer.Parity = (string)PropertiesGeneral.CBParity.SelectedItem;
ComControl.ComSer.BaudRate = (int)PropertiesGeneral.CBBaudRate.SelectedItem;
ComControl.ComSer.ReadTimeout = readTimeout;
ComControl.ComSer.WriteTimeout = writeTimeout;
ComControl.ComSer.WriteTimeout = writeTimeout;
ComControl.ComSer.DataBits = (int)PropertiesGeneral.CBDataBits.SelectedItem;
((AppWPF)Application.Current).SaveTabItem(ComControl.CanvasTab.TabItemParent);
}
this.Close();
}
private void TreeViewProperties_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
TreeViewItem Selected = (TreeViewItem)e.NewValue;
if ((string)Selected.Header == "Общие")
{
PropertiesGeneral.SetValue(Grid.ColumnProperty, 1);
PropertiesGrid.Children.Add(PropertiesGeneral);
}
e.Handled = true;
}
private void WindowLoaded(object sender, RoutedEventArgs e)
{
TreeViewItemGeneral.IsSelected = true;
e.Handled = true;
}
private void Close(object sender, RoutedEventArgs e)
{
e.Handled = true;
this.Close();
}
}
}