forked from fr830/PrimSCADA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDialogWindowPropertiesDisplay.xaml.cs
206 lines (168 loc) · 8.65 KB
/
DialogWindowPropertiesDisplay.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
// 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.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
namespace SCADA
{
/// <summary>
/// Логика взаимодействия для DialogWindowPropertiesDisplay.xaml
/// </summary>
public partial class DialogWindowPropertiesDisplay : Window
{
GridPropertiesDisplayEthernet PropertiesEthernet;
GridPropertiesDisplayModbus PropertiesModbus;
private Display display;
public Display Display
{
get { return display; }
set { display = value; }
}
public DialogWindowPropertiesDisplay(Display display)
{
InitializeComponent();
PropertiesEthernet = new GridPropertiesDisplayEthernet(display);
PropertiesModbus = new GridPropertiesDisplayModbus(display);
Display = display;
}
private void Apply(object sender, RoutedEventArgs e)
{
TreeViewItem Selected = (TreeViewItem)TreeViewProperties.SelectedItem;
if ((string)Selected.Header == "Ethernet")
{
if (!Display.DisplaySer.IsEthernet)
{
Display.DisplaySer.IsModbus = false;
Display.DisplaySer.IsEthernet = true;
Display.DisplaySer.ModbusID = null;
Display.DisplaySer.ItemModbusID = null;
Display.DisplaySer.ItemModbus = null;
((AppWPF)Application.Current).SaveTabItem(Display.CanvasTab.TabItemParent);
}
if (Display.DisplaySer.ItemEthernet == null && PropertiesEthernet.TVItemNet.ItemEthernet != null)
{
Binding bindingRun = new Binding();
bindingRun.Converter = new ValueItemNetConverter(PropertiesEthernet.TVItemNet.ItemEthernet);
bindingRun.Source = PropertiesEthernet.TVItemNet.ItemEthernet;
bindingRun.Path = new PropertyPath("Value");
Display.RunBinding.SetBinding(Run.TextProperty, bindingRun);
Display.DisplaySer.ItemEthernet = PropertiesEthernet.TVItemNet.ItemEthernet;
Display.DisplaySer.EthernetID = PropertiesEthernet.TVItemNet.EthernetID;
((AppWPF)Application.Current).SaveTabItem(Display.CanvasTab.TabItemParent);
}
else if (Display.DisplaySer.ItemEthernet != null && PropertiesEthernet.TVItemNet.ItemEthernet == null)
{
Display.DisplaySer.ItemEthernet = null;
Display.DisplaySer.EthernetID = null;
((AppWPF)Application.Current).SaveTabItem(Display.CanvasTab.TabItemParent);
}
else if (!object.ReferenceEquals(Display.DisplaySer.ItemEthernet, PropertiesEthernet.TVItemNet.ItemEthernet))
{
Binding bindingRun = new Binding();
bindingRun.Converter = new ValueItemNetConverter(PropertiesEthernet.TVItemNet.ItemEthernet);
bindingRun.Source = PropertiesEthernet.TVItemNet.ItemEthernet;
bindingRun.Path = new PropertyPath("Value");
Display.RunBinding.SetBinding(Run.TextProperty, bindingRun);
Display.DisplaySer.ItemEthernet = PropertiesEthernet.TVItemNet.ItemEthernet;
Display.DisplaySer.EthernetID = PropertiesEthernet.TVItemNet.EthernetID;
((AppWPF)Application.Current).SaveTabItem(Display.CanvasTab.TabItemParent);
}
}
else if ((string)Selected.Header == "Modbus")
{
if (!Display.DisplaySer.IsModbus)
{
Display.DisplaySer.IsModbus = true;
Display.DisplaySer.IsEthernet = false;
Display.DisplaySer.EthernetID = null;
Display.DisplaySer.ItemEthernetID = null;
Display.DisplaySer.ItemEthernet = null;
((AppWPF)Application.Current).SaveTabItem(Display.CanvasTab.TabItemParent);
}
if (Display.DisplaySer.ItemModbus == null && PropertiesModbus.ItemModbus != null)
{
Binding bindingRun = new Binding();
bindingRun.Converter = new ValueItemModbusConverter(PropertiesModbus.ItemModbus);
bindingRun.Source = PropertiesModbus.ItemModbus;
bindingRun.Path = new PropertyPath("Value");
Display.RunBinding.SetBinding(Run.TextProperty, bindingRun);
Display.DisplaySer.ItemModbus = PropertiesModbus.ItemModbus;
Display.DisplaySer.ModbusID = PropertiesModbus.ModbusSearch;
((AppWPF)Application.Current).SaveTabItem(Display.CanvasTab.TabItemParent);
}
else if (Display.DisplaySer.ItemModbus != null && PropertiesModbus.ItemModbus == null)
{
Display.DisplaySer.ItemModbus = null;
Display.DisplaySer.ModbusID = null;
((AppWPF)Application.Current).SaveTabItem(Display.CanvasTab.TabItemParent);
}
else if (!object.ReferenceEquals(Display.DisplaySer.ItemModbus, PropertiesModbus.ItemModbus))
{
Binding bindingRun = new Binding();
bindingRun.Converter = new ValueItemModbusConverter(PropertiesModbus.ItemModbus);
bindingRun.Source = PropertiesModbus.ItemModbus;
bindingRun.Path = new PropertyPath("Value");
Display.RunBinding.SetBinding(Run.TextProperty, bindingRun);
Display.DisplaySer.ItemModbus = PropertiesModbus.ItemModbus;
Display.DisplaySer.ModbusID = PropertiesModbus.ModbusSearch;
((AppWPF)Application.Current).SaveTabItem(Display.CanvasTab.TabItemParent);
}
}
e.Handled = true;
this.Close();
}
private void Close(object sender, RoutedEventArgs e)
{
e.Handled = true;
this.Close();
}
private void WindowLoaded(object sender, RoutedEventArgs e)
{
if (display.DisplaySer.IsModbus)
{
TreeViewItemModbus.IsSelected = true;
}
else if (display.DisplaySer.IsEthernet)
{
TreeViewItemEthernet.IsSelected = true;
}
else
{
TreeViewItemEthernet.IsSelected = true;
}
e.Handled = true;
}
private void TreeViewProperties_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
TreeViewItem Selected = (TreeViewItem)e.NewValue;
if ((string)Selected.Header == "Ethernet")
{
if (PropertiesGrid.Children.Contains(PropertiesModbus))
{
PropertiesGrid.Children.Remove(PropertiesModbus);
}
if (PropertiesGrid.Children.Contains(PropertiesEthernet))
{
PropertiesGrid.Children.Remove(PropertiesEthernet);
}
PropertiesEthernet.SetValue(Grid.ColumnProperty, 1);
PropertiesGrid.Children.Add(PropertiesEthernet);
}
else if ((string)Selected.Header == "Modbus")
{
if (PropertiesGrid.Children.Contains(PropertiesModbus))
{
PropertiesGrid.Children.Remove(PropertiesModbus);
}
if (PropertiesGrid.Children.Contains(PropertiesEthernet))
{
PropertiesGrid.Children.Remove(PropertiesEthernet);
}
PropertiesModbus.SetValue(Grid.ColumnProperty, 1);
PropertiesGrid.Children.Add(PropertiesModbus);
}
e.Handled = true;
}
}
}