-
Notifications
You must be signed in to change notification settings - Fork 1
/
GridProperties.cs
11397 lines (9555 loc) · 490 KB
/
GridProperties.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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// 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 Microsoft.Win32;
using Modbus.Device;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Ports;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;
namespace SCADA
{
static class StaticValue
{
public static string SPeriodSaveDB = "Период сохранения в БД";
public static string SPeriodSaveSetDB = "Период сохранения уставки";
public static string SRange1_86400 = "Диапазон 1 - 86400";
public static string SRangePort = "Диапазон порта 0 - 65535";
public static string SRange1_102400000 = "Диапазон буфера 1 - 102400000";
public static string SRange0 = "Диапазон 0";
public static string SRange1 = "Диапазон 1";
public static string SSetUp = "Значение уставки верх";
public static string SSetDown = "Значение уставки низ";
public static string SSetMessage = "Уставка вверх не может быть меньше низа или равно";
public static string SDescription = "Описание";
public static string STableName = "Имя таблицы в БД";
public static string SFormula = "Формула";
public static string SText = "Текст";
public static string SDescriptionMessage = "Описание не может быть длинее 200 символов.";
public static string STableNameDescription = "Имя таблицы не может быть длинее 100 символов.";
public static string SFormulaDescription = "Формула не может быть длинее 300 символов.";
public static string STextDescription = "Текст не может быть длинее 100 символов.";
public static string SAddress = "Адрес регистра";
public static string SRange1_255 = "Диапазон 1 - 255";
public static string SRange0_65535 = "Диапазон 0 - 65535";
public static string SRange_32768_32767 = "Диапазон -32768 - 32767";
public static string SRange_2147483648_2147483647 = "Диапазон -2147483648 - 2147483647";
public static string SIsSaveBD = "Сохранять в БД";
public static string SIsSaveSetDB = "Сохранять уставки в БД";
public static string SIsSetUp = "Уставка верх";
public static string SIsSetDown = "Уставка низ";
public static Visual GetDescendantByType(Visual element, Type type)
{
if (element == null)
{
return null;
}
if (element.GetType() == type)
{
return element;
}
Visual foundElement = null;
if (element is FrameworkElement)
{
(element as FrameworkElement).ApplyTemplate();
}
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(element); i++)
{
Visual visual = VisualTreeHelper.GetChild(element, i) as Visual;
foundElement = GetDescendantByType(visual, type);
if (foundElement != null)
{
break;
}
}
return foundElement;
}
}
class ModbusSendConnect
{
public string ComPort;
public byte Slave;
public bool IsReverse;
public bool IsUS800;
public string Protocol;
}
class GridPropertiesModbusGeneral : Grid
{
public static readonly DependencyProperty IsBindingStartProperty =
DependencyProperty.Register(
"IsBindingStart",
typeof(bool),
typeof(GridPropertiesModbusGeneral),
new FrameworkPropertyMetadata(false));
public bool IsBindingStart
{
get { return (bool)GetValue(GridPropertiesModbusGeneral.IsBindingStartProperty); }
set { SetValue(GridPropertiesModbusGeneral.IsBindingStartProperty, value); }
}
public Popup PopupMessage = new Popup();
public Label LPopupMessage = new Label();
SerialPort SerialPort;
public TextBox TBIDModbus = new TextBox();
public TextBox TBDescriptionModbus = new TextBox();
public TextBox TBTime = new TextBox();
public TextBox TBAddressSlave = new TextBox();
public DataGrid DG = new DataGrid();
public ComboBox CBProtocol = new ComboBox();
public ComboBox CBSerialPort = new ComboBox();
public CheckBox CHReverseRegister = new CheckBox();
public CheckBox CHUS800 = new CheckBox();
Button RemoveNetButton;
Button AddNetButton;
public Button Start;
Button Stop;
ModbusControl ModbusControl;
public ModbusSer NewModbusSer;
TextBox TBStatus;
TextBox TBTableName;
TextBox TBDescriptionItemNet;
TextBox TBPeriodTimeSaveDB;
TextBox TBAddress;
TextBox TBFormula;
TextBox TBText;
TextBox TBEmergencyUp;
TextBox TBEmergencyDown;
TextBox TBEmergencySaveBD;
ItemModbus Item;
int PeriodTime;
volatile bool IsStop;
string EscText;
float EscDigital;
public GridPropertiesModbusGeneral(ModbusControl modbusControl)
{
LPopupMessage = new Label();
LPopupMessage.BorderThickness = new Thickness(1);
LPopupMessage.BorderBrush = Brushes.Red;
LPopupMessage.Background = Brushes.White;
PopupMessage.AllowsTransparency = true;
PopupMessage.Child = LPopupMessage;
PopupMessage.PopupAnimation = PopupAnimation.Fade;
PopupMessage.StaysOpen = false;
this.Unloaded += GridPropertiesEthernetGeneral_Unloaded;
this.MaxWidth = 1000;
this.MaxHeight = 800;
ModbusControl = modbusControl;
ModbusSer copyModbusSer = null;
using (MemoryStream ms = new MemoryStream())
{
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(ms, modbusControl.ModbusSer);
ms.Position = 0;
copyModbusSer = (ModbusSer)bf.Deserialize(ms);
}
NewModbusSer = copyModbusSer;
foreach(ComSer comSer in ((AppWPF)Application.Current).CollectionComSers)
{
if(comSer.ComPort != null)
{
if(CBSerialPort.Items.Count != 0)
{
foreach(string s in CBSerialPort.Items)
{
if(s != comSer.ComPort)
{
CBSerialPort.Items.Add(comSer.ComPort);
break;
}
}
}
else
{
CBSerialPort.Items.Add(comSer.ComPort);
}
}
}
CBSerialPort.MinWidth = 100;
CHReverseRegister.VerticalAlignment = System.Windows.VerticalAlignment.Center;
CHUS800.VerticalAlignment = System.Windows.VerticalAlignment.Center;
TBIDModbus.MinWidth = 150;
TBIDModbus.Margin = new Thickness(3);
TBIDModbus.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
TBIDModbus.MaxWidth = 300;
TBIDModbus.IsReadOnly = true;
TBDescriptionModbus.MinWidth = 150;
TBDescriptionModbus.Margin = new Thickness(3);
TBDescriptionModbus.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
TBDescriptionModbus.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
TBDescriptionModbus.MaxWidth = 300;
TBDescriptionModbus.MaxHeight = 200;
TBDescriptionModbus.AcceptsReturn = true;
TBAddressSlave.MinWidth = 50;
TBAddressSlave.Margin = new Thickness(3);
TBAddressSlave.MaxWidth = 50;
TBTime.MinWidth = 40;
CBProtocol.Items.Add("RTU");
CBProtocol.Items.Add("ASCII");
#region DG
Binding bindingCollectionNet = new Binding();
bindingCollectionNet.NotifyOnSourceUpdated = true;
bindingCollectionNet.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
bindingCollectionNet.Source = NewModbusSer.CollectionItemModbus;
DG.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
DG.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
DG.BorderThickness = new Thickness(3);
DG.BorderBrush = Brushes.Black;
DG.SetValue(Grid.RowProperty, 10);
DG.AutoGenerateColumns = false;
DG.CellEditEnding += DG_CellEditEnding;
DG.PreparingCellForEdit += DG_PreparingCellForEdit;
DG.MaxHeight = 600;
DG.MaxWidth = 800;
DG.CanUserAddRows = false;
DG.SetBinding(DataGrid.ItemsSourceProperty, bindingCollectionNet);
Binding bindingType = new Binding();
bindingType.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
bindingType.Path = new PropertyPath("TypeValue");
Binding bindingFunction = new Binding();
bindingFunction.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
bindingFunction.Path = new PropertyPath("Function");
Binding bindingValue = new Binding();
bindingValue.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
bindingValue.Path = new PropertyPath("Value");
Binding bindingID = new Binding();
bindingID.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
bindingID.Path = new PropertyPath("ID");
Binding bindingDescription = new Binding();
bindingDescription.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
bindingDescription.Path = new PropertyPath("Description");
Binding bindingIsSaveDatabase = new Binding();
bindingIsSaveDatabase.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
bindingIsSaveDatabase.Path = new PropertyPath("IsSaveDatabase");
Binding bindingTableName = new Binding();
bindingTableName.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
bindingTableName.Path = new PropertyPath("TableName");
Binding bindingPeriodSaveDB = new Binding();
bindingPeriodSaveDB.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
bindingPeriodSaveDB.Path = new PropertyPath("PeridTimeSaveDB");
Binding bindingAddress = new Binding();
bindingAddress.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
bindingAddress.Path = new PropertyPath("Address");
Binding bindingFormula = new Binding();
bindingFormula.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
bindingFormula.Path = new PropertyPath("Formula");
Binding bindingText = new Binding();
bindingText.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
bindingText.Path = new PropertyPath("Text");
Binding bindingEmergencyUp = new Binding();
bindingEmergencyUp.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
bindingEmergencyUp.Path = new PropertyPath("EmergencyUp");
Binding bindingEmergencyDown = new Binding();
bindingEmergencyDown.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
bindingEmergencyDown.Path = new PropertyPath("EmergencyDown");
Binding bindingIsEmergencySaveDB = new Binding();
bindingIsEmergencySaveDB.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
bindingIsEmergencySaveDB.Path = new PropertyPath("IsEmergencySaveDB");
Binding bindingPeriodEmergencySaveDB = new Binding();
bindingPeriodEmergencySaveDB.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
bindingPeriodEmergencySaveDB.Path = new PropertyPath("PeriodEmergencySaveDB");
Binding bindingIsEmergencyUp = new Binding();
bindingIsEmergencyUp.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
bindingIsEmergencyUp.Path = new PropertyPath("IsEmergencyUpDG");
Binding bindingIsEmergencyDown = new Binding();
bindingIsEmergencyDown.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
bindingIsEmergencyDown.Path = new PropertyPath("IsEmergencyDownDG");
Binding bindingEmergencyUpEnable = new Binding();
bindingEmergencyUpEnable.Path = new PropertyPath("IsEmergencyUpDG");
Binding bindingEmergencyDownEnable = new Binding();
bindingEmergencyDownEnable.Path = new PropertyPath("IsEmergencyDownDG");
Binding bindingIsUp = new Binding();
bindingIsUp.Path = new PropertyPath("IsEmergencyUpDG");
Binding bindingIsDown = new Binding();
bindingIsDown.Path = new PropertyPath("IsEmergencyDownDG");
MultiBinding bindingIsEmergencyDB = new MultiBinding();
bindingIsEmergencyDB.Converter = new CheckBoxEmergencySaveDBValueConverter();
bindingIsEmergencyDB.Bindings.Add(bindingIsUp);
bindingIsEmergencyDB.Bindings.Add(bindingIsDown);
Binding bindingEnableTBPeriodEmergencySaveDB1 = new Binding();
bindingEnableTBPeriodEmergencySaveDB1.Path = new PropertyPath("IsEmergencyUpDG");
Binding bindingEnableTBPeriodEmergencySaveDB2 = new Binding();
bindingEnableTBPeriodEmergencySaveDB2.Path = new PropertyPath("IsEmergencyDownDG");
Binding bindingEnableTBPeriodEmergencySaveDB3 = new Binding();
bindingEnableTBPeriodEmergencySaveDB3.Path = new PropertyPath("IsEmergencySaveDB");
MultiBinding bindingEnableTBPeriodEmergencySaveDB4 = new MultiBinding();
bindingEnableTBPeriodEmergencySaveDB4.Converter = new DGTBEmergencyEnabledValueConverter();
bindingEnableTBPeriodEmergencySaveDB4.Bindings.Add(bindingEnableTBPeriodEmergencySaveDB1);
bindingEnableTBPeriodEmergencySaveDB4.Bindings.Add(bindingEnableTBPeriodEmergencySaveDB2);
bindingEnableTBPeriodEmergencySaveDB4.Bindings.Add(bindingEnableTBPeriodEmergencySaveDB3);
FrameworkElementFactory lTypeEditable = new FrameworkElementFactory(typeof(ComboBox));
lTypeEditable.Name = "ComboBoxType";
FrameworkElementFactory lFunctionEditable = new FrameworkElementFactory(typeof(ComboBox));
lFunctionEditable.Name = "ComboBoxFunction";
FrameworkElementFactory lType = new FrameworkElementFactory(typeof(Label));
lType.AddHandler(ComboBox.LoadedEvent, new RoutedEventHandler(LoadedType));
lType.SetBinding(Label.ContentProperty, bindingType);
FrameworkElementFactory lFunction = new FrameworkElementFactory(typeof(Label));
lFunction.AddHandler(ComboBox.LoadedEvent, new RoutedEventHandler(LoadedFunction));
lFunction.SetBinding(Label.ContentProperty, bindingFunction);
FrameworkElementFactory lValue = new FrameworkElementFactory(typeof(Label));
lValue.SetBinding(Label.ContentProperty, bindingValue);
FrameworkElementFactory lAddress = new FrameworkElementFactory(typeof(Label));
lAddress.SetBinding(Label.ContentProperty, bindingAddress);
FrameworkElementFactory lFormula = new FrameworkElementFactory(typeof(Label));
lFormula.SetBinding(Label.ContentProperty, bindingFormula);
FrameworkElementFactory lText = new FrameworkElementFactory(typeof(Label));
lText.SetBinding(Label.ContentProperty, bindingText);
FrameworkElementFactory lEmergencyUp = new FrameworkElementFactory(typeof(Label));
lEmergencyUp.SetBinding(Label.ContentProperty, bindingEmergencyUp);
FrameworkElementFactory lEmergencyDown = new FrameworkElementFactory(typeof(Label));
lEmergencyDown.SetBinding(Label.ContentProperty, bindingEmergencyDown);
FrameworkElementFactory lPeriodEmergencySaveDB = new FrameworkElementFactory(typeof(Label));
lPeriodEmergencySaveDB.SetBinding(Label.ContentProperty, bindingPeriodEmergencySaveDB);
FrameworkElementFactory tbAddressEditable = new FrameworkElementFactory(typeof(TextBox));
tbAddressEditable.Name = "TextBoxAddress";
tbAddressEditable.AddHandler(TextBox.PreviewTextInputEvent, new TextCompositionEventHandler(DigitalTextBox_PreviewTextInput));
tbAddressEditable.AddHandler(TextBox.PreviewKeyDownEvent, new KeyEventHandler(BackspacePreviewTextKeyDown));
tbAddressEditable.AddHandler(TextBox.GotFocusEvent, new RoutedEventHandler(TextBoxFocus));
tbAddressEditable.SetBinding(TextBox.TextProperty, bindingAddress);
FrameworkElementFactory lEthernetSerDescription = new FrameworkElementFactory(typeof(Label));
lEthernetSerDescription.SetBinding(Label.ContentProperty, bindingDescription);
FrameworkElementFactory lID = new FrameworkElementFactory(typeof(TextBox));
lID.SetBinding(TextBox.TextProperty, bindingID);
FrameworkElementFactory lDescriptionEditable = new FrameworkElementFactory(typeof(TextBox));
lDescriptionEditable.Name = "TextBoxDescription";
lDescriptionEditable.AddHandler(TextBox.PreviewTextInputEvent, new TextCompositionEventHandler(Text_PreviewTextInput));
lDescriptionEditable.AddHandler(TextBox.PreviewKeyDownEvent, new KeyEventHandler(BackspacePreviewTextKeyDown));
lDescriptionEditable.AddHandler(TextBox.GotFocusEvent, new RoutedEventHandler(TextBoxFocus));
lDescriptionEditable.SetBinding(TextBox.TextProperty, bindingDescription);
FrameworkElementFactory lEthernetSerIsSaveDatabase = new FrameworkElementFactory(typeof(CheckBox));
lEthernetSerIsSaveDatabase.SetValue(CheckBox.HorizontalAlignmentProperty, HorizontalAlignment.Center);
lEthernetSerIsSaveDatabase.SetValue(CheckBox.VerticalAlignmentProperty, VerticalAlignment.Center);
lEthernetSerIsSaveDatabase.SetBinding(CheckBox.IsCheckedProperty, bindingIsSaveDatabase);
FrameworkElementFactory lEthernetSerTableName = new FrameworkElementFactory(typeof(Label));
lEthernetSerTableName.SetBinding(Label.ContentProperty, bindingTableName);
FrameworkElementFactory lTableNameEditable = new FrameworkElementFactory(typeof(TextBox));
lTableNameEditable.Name = "TextBoxTableName";
lTableNameEditable.AddHandler(TextBox.PreviewTextInputEvent, new TextCompositionEventHandler(Text_PreviewTextInput));
lTableNameEditable.AddHandler(TextBox.PreviewKeyDownEvent, new KeyEventHandler(BackspacePreviewTextKeyDown));
lTableNameEditable.AddHandler(TextBox.GotFocusEvent, new RoutedEventHandler(TextBoxFocus));
lTableNameEditable.SetBinding(TextBox.TextProperty, bindingTableName);
FrameworkElementFactory lFormulaEditable = new FrameworkElementFactory(typeof(TextBox));
lFormulaEditable.Name = "TextBoxFormula";
lFormulaEditable.AddHandler(TextBox.PreviewTextInputEvent, new TextCompositionEventHandler(Text_PreviewTextInput));
lFormulaEditable.AddHandler(TextBox.PreviewKeyDownEvent, new KeyEventHandler(BackspacePreviewTextKeyDown));
lFormulaEditable.AddHandler(TextBox.GotFocusEvent, new RoutedEventHandler(TextBoxFocus));
lFormulaEditable.SetBinding(TextBox.TextProperty, bindingFormula);
FrameworkElementFactory lTextEditable = new FrameworkElementFactory(typeof(TextBox));
lTextEditable.Name = "TextBoxText";
lTextEditable.AddHandler(TextBox.PreviewTextInputEvent, new TextCompositionEventHandler(Text_PreviewTextInput));
lTextEditable.AddHandler(TextBox.PreviewKeyDownEvent, new KeyEventHandler(BackspacePreviewTextKeyDown));
lTextEditable.AddHandler(TextBox.GotFocusEvent, new RoutedEventHandler(TextBoxFocus));
lTextEditable.SetBinding(TextBox.TextProperty, bindingText);
FrameworkElementFactory lEthernetSerPeriodSaveDB = new FrameworkElementFactory(typeof(Label));
lEthernetSerPeriodSaveDB.SetBinding(Label.ContentProperty, bindingPeriodSaveDB);
FrameworkElementFactory lPeriodSaveDBEditable = new FrameworkElementFactory(typeof(TextBox));
lPeriodSaveDBEditable.Name = "TextBoxPeriodSaveDB";
lPeriodSaveDBEditable.AddHandler(TextBox.PreviewTextInputEvent, new TextCompositionEventHandler(DigitalTextBox_PreviewTextInput));
lPeriodSaveDBEditable.AddHandler(TextBox.PreviewKeyDownEvent, new KeyEventHandler(BackspacePreviewTextKeyDown));
lPeriodSaveDBEditable.AddHandler(TextBox.GotFocusEvent, new RoutedEventHandler(TextBoxFocus));
lPeriodSaveDBEditable.SetBinding(TextBox.TextProperty, bindingPeriodSaveDB);
FrameworkElementFactory lEmergencyUpEditable = new FrameworkElementFactory(typeof(TextBox));
lEmergencyUpEditable.Name = "TextBoxEmergencyUp";
lEmergencyUpEditable.AddHandler(TextBox.PreviewTextInputEvent, new TextCompositionEventHandler(DigitalTextBox_PreviewTextInput));
lEmergencyUpEditable.AddHandler(TextBox.PreviewKeyDownEvent, new KeyEventHandler(BackspacePreviewTextKeyDown));
lEmergencyUpEditable.AddHandler(TextBox.GotFocusEvent, new RoutedEventHandler(TextBoxFocus));
lEmergencyUpEditable.SetBinding(TextBox.TextProperty, bindingEmergencyUp);
lEmergencyUpEditable.SetBinding(TextBox.IsEnabledProperty, bindingEmergencyUpEnable);
FrameworkElementFactory lEmergencyDownEditable = new FrameworkElementFactory(typeof(TextBox));
lEmergencyDownEditable.Name = "TextBoxEmergencyDown";
lEmergencyDownEditable.AddHandler(TextBox.PreviewTextInputEvent, new TextCompositionEventHandler(DigitalTextBox_PreviewTextInput));
lEmergencyDownEditable.AddHandler(TextBox.PreviewKeyDownEvent, new KeyEventHandler(BackspacePreviewTextKeyDown));
lEmergencyDownEditable.AddHandler(TextBox.GotFocusEvent, new RoutedEventHandler(TextBoxFocus));
lEmergencyDownEditable.SetBinding(TextBox.TextProperty, bindingEmergencyDown);
lEmergencyDownEditable.SetBinding(TextBox.IsEnabledProperty, bindingEmergencyDownEnable);
FrameworkElementFactory fIsEmergencySaveDB = new FrameworkElementFactory(typeof(CheckBox));
fIsEmergencySaveDB.SetValue(CheckBox.HorizontalAlignmentProperty, HorizontalAlignment.Center);
fIsEmergencySaveDB.SetValue(CheckBox.VerticalAlignmentProperty, VerticalAlignment.Center);
fIsEmergencySaveDB.SetBinding(CheckBox.IsCheckedProperty, bindingIsEmergencySaveDB);
fIsEmergencySaveDB.SetBinding(CheckBox.IsEnabledProperty, bindingIsEmergencyDB);
FrameworkElementFactory fPeriodEmergencySaveDBEditable = new FrameworkElementFactory(typeof(TextBox));
fPeriodEmergencySaveDBEditable.Name = "TextBoxPeriodEmergencySaveDB";
fPeriodEmergencySaveDBEditable.AddHandler(TextBox.PreviewTextInputEvent, new TextCompositionEventHandler(DigitalTextBox_PreviewTextInput));
fPeriodEmergencySaveDBEditable.AddHandler(TextBox.PreviewKeyDownEvent, new KeyEventHandler(BackspacePreviewTextKeyDown));
fPeriodEmergencySaveDBEditable.AddHandler(TextBox.GotFocusEvent, new RoutedEventHandler(TextBoxFocus));
fPeriodEmergencySaveDBEditable.SetBinding(TextBox.TextProperty, bindingPeriodEmergencySaveDB);
fPeriodEmergencySaveDBEditable.SetBinding(TextBox.IsEnabledProperty, bindingEnableTBPeriodEmergencySaveDB4);
FrameworkElementFactory fIsEmergencyUp = new FrameworkElementFactory(typeof(CheckBox));
fIsEmergencyUp.SetValue(CheckBox.HorizontalAlignmentProperty, HorizontalAlignment.Center);
fIsEmergencyUp.SetValue(CheckBox.VerticalAlignmentProperty, VerticalAlignment.Center);
fIsEmergencyUp.SetBinding(CheckBox.IsCheckedProperty, bindingIsEmergencyUp);
FrameworkElementFactory fIsEmergencyDown = new FrameworkElementFactory(typeof(CheckBox));
fIsEmergencyDown.SetValue(CheckBox.HorizontalAlignmentProperty, HorizontalAlignment.Center);
fIsEmergencyDown.SetValue(CheckBox.VerticalAlignmentProperty, VerticalAlignment.Center);
fIsEmergencyDown.SetBinding(CheckBox.IsCheckedProperty, bindingIsEmergencyDown);
DataTemplate dataTemplateType = new DataTemplate();
dataTemplateType.VisualTree = lType;
DataTemplate dataTemplateFunction = new DataTemplate();
dataTemplateFunction.VisualTree = lFunction;
DataTemplate dataTemplateTypeEditable = new DataTemplate();
dataTemplateTypeEditable.VisualTree = lTypeEditable;
DataTemplate dataTemplateFunctionEditable = new DataTemplate();
dataTemplateFunctionEditable.VisualTree = lFunctionEditable;
DataTemplate dataTemplateValue = new DataTemplate();
dataTemplateValue.VisualTree = lValue;
DataTemplate dataTemplateAddress = new DataTemplate();
dataTemplateAddress.VisualTree = lAddress;
DataTemplate dataTemplateAddressEditable = new DataTemplate();
dataTemplateAddressEditable.VisualTree = tbAddressEditable;
DataTemplate dataTemplateID = new DataTemplate();
dataTemplateID.VisualTree = lID;
DataTemplate dataTemplateDescription = new DataTemplate();
dataTemplateDescription.VisualTree = lEthernetSerDescription;
DataTemplate dataTemplateDescriptionEditable = new DataTemplate();
dataTemplateDescriptionEditable.VisualTree = lDescriptionEditable;
DataTemplate dataTemplateIsSaveDatabase = new DataTemplate();
dataTemplateIsSaveDatabase.VisualTree = lEthernetSerIsSaveDatabase;
DataTemplate dataTemplateTableName = new DataTemplate();
dataTemplateTableName.VisualTree = lEthernetSerTableName;
DataTemplate dataTemplateTableNameEditable = new DataTemplate();
dataTemplateTableNameEditable.VisualTree = lTableNameEditable;
DataTemplate dataTemplatePeriodSaveDB = new DataTemplate();
dataTemplatePeriodSaveDB.VisualTree = lEthernetSerPeriodSaveDB;
DataTemplate dataTemplatePeriodSaveDBEditable = new DataTemplate();
dataTemplatePeriodSaveDBEditable.VisualTree = lPeriodSaveDBEditable;
DataTemplate dataTemplateFormula = new DataTemplate();
dataTemplateFormula.VisualTree = lFormula;
DataTemplate dataTemplateFormulaEditable = new DataTemplate();
dataTemplateFormulaEditable.VisualTree = lFormulaEditable;
DataTemplate dataTemplateText = new DataTemplate();
dataTemplateText.VisualTree = lText;
DataTemplate dataTemplateTextEditable = new DataTemplate();
dataTemplateTextEditable.VisualTree = lTextEditable;
DataTemplate dataTemplateEmergencyUp = new DataTemplate();
dataTemplateEmergencyUp.VisualTree = lEmergencyUp;
DataTemplate dataTemplateEmergencyUpEditable = new DataTemplate();
dataTemplateEmergencyUpEditable.VisualTree = lEmergencyUpEditable;
DataTemplate dataTemplateEmergencyDown = new DataTemplate();
dataTemplateEmergencyDown.VisualTree = lEmergencyDown;
DataTemplate dataTemplateEmergencyDownEditable = new DataTemplate();
dataTemplateEmergencyDownEditable.VisualTree = lEmergencyDownEditable;
DataTemplate dataTemplatePeriodEmergencySaveDB = new DataTemplate();
dataTemplatePeriodEmergencySaveDB.VisualTree = lPeriodEmergencySaveDB;
DataTemplate dataTemplatePeriodEmergencySaveDBEditable = new DataTemplate();
dataTemplatePeriodEmergencySaveDBEditable.VisualTree = fPeriodEmergencySaveDBEditable;
DataTemplate dataTemplateIsEmergencySaveDBEditable = new DataTemplate();
dataTemplateIsEmergencySaveDBEditable.VisualTree = fIsEmergencySaveDB;
DataTemplate dataTemplateIsEmergencyUpEditable = new DataTemplate();
dataTemplateIsEmergencyUpEditable.VisualTree = fIsEmergencyUp;
DataTemplate dataTemplateIsEmergencyDownEditable = new DataTemplate();
dataTemplateIsEmergencyDownEditable.VisualTree = fIsEmergencyDown;
DataGridTemplateColumn type = new DataGridTemplateColumn();
type.Header = "Тип";
type.CellTemplate = dataTemplateType;
type.CellEditingTemplate = dataTemplateTypeEditable;
DataGridTemplateColumn function = new DataGridTemplateColumn();
function.Header = "Функция";
function.CellTemplate = dataTemplateFunction;
function.CellEditingTemplate = dataTemplateFunctionEditable;
DataGridTemplateColumn value = new DataGridTemplateColumn();
value.Header = "Значение";
value.CellTemplate = dataTemplateValue;
value.IsReadOnly = true;
DataGridTemplateColumn address = new DataGridTemplateColumn();
address.Header = StaticValue.SAddress;
address.CellTemplate = dataTemplateAddress;
address.CellEditingTemplate = dataTemplateAddressEditable;
DataGridTemplateColumn id = new DataGridTemplateColumn();
id.Header = "ID";
id.CellTemplate = dataTemplateID;
DataGridTemplateColumn description = new DataGridTemplateColumn();
description.Header = StaticValue.SDescription;
description.CellTemplate = dataTemplateDescription;
description.CellEditingTemplate = dataTemplateDescriptionEditable;
DataGridTemplateColumn isSaveDatabase = new DataGridTemplateColumn();
isSaveDatabase.Header = StaticValue.SIsSaveBD;
isSaveDatabase.CellTemplate = dataTemplateIsSaveDatabase;
DataGridTemplateColumn tableName = new DataGridTemplateColumn();
tableName.Header = StaticValue.STableName;
tableName.CellTemplate = dataTemplateTableName;
tableName.CellEditingTemplate = dataTemplateTableNameEditable;
DataGridTemplateColumn periodSaveDB = new DataGridTemplateColumn();
periodSaveDB.Header = StaticValue.SPeriodSaveDB;
periodSaveDB.CellTemplate = dataTemplatePeriodSaveDB;
periodSaveDB.CellEditingTemplate = dataTemplatePeriodSaveDBEditable;
DataGridTemplateColumn formula = new DataGridTemplateColumn();
formula.Header = StaticValue.SFormula;
formula.CellTemplate = dataTemplateFormula;
formula.CellEditingTemplate = dataTemplateFormulaEditable;
DataGridTemplateColumn text = new DataGridTemplateColumn();
text.Header = StaticValue.SText;
text.CellTemplate = dataTemplateText;
text.CellEditingTemplate = dataTemplateTextEditable;
DataGridTemplateColumn emergencyUp = new DataGridTemplateColumn();
emergencyUp.Header = StaticValue.SSetUp;
emergencyUp.CellTemplate = dataTemplateEmergencyUp;
emergencyUp.CellEditingTemplate = dataTemplateEmergencyUpEditable;
DataGridTemplateColumn emergencyDown = new DataGridTemplateColumn();
emergencyDown.Header = StaticValue.SSetDown;
emergencyDown.CellTemplate = dataTemplateEmergencyDown;
emergencyDown.CellEditingTemplate = dataTemplateEmergencyDownEditable;
DataGridTemplateColumn periodEmergencySaveDB = new DataGridTemplateColumn();
periodEmergencySaveDB.Header = StaticValue.SPeriodSaveSetDB;
periodEmergencySaveDB.CellTemplate = dataTemplatePeriodEmergencySaveDB;
periodEmergencySaveDB.CellEditingTemplate = dataTemplatePeriodEmergencySaveDBEditable;
DataGridTemplateColumn isEmergencySaveDB = new DataGridTemplateColumn();
isEmergencySaveDB.Header = StaticValue.SIsSaveSetDB;
isEmergencySaveDB.CellTemplate = dataTemplateIsEmergencySaveDBEditable;
DataGridTemplateColumn isEmergencyUp = new DataGridTemplateColumn();
isEmergencyUp.Header = StaticValue.SIsSetUp;
isEmergencyUp.CellTemplate = dataTemplateIsEmergencyUpEditable;
DataGridTemplateColumn isEmergencyDown = new DataGridTemplateColumn();
isEmergencyDown.Header = StaticValue.SIsSetDown;
isEmergencyDown.CellTemplate = dataTemplateIsEmergencyDownEditable;
DG.Columns.Add(type);
DG.Columns.Add(value);
DG.Columns.Add(function);
DG.Columns.Add(address);
DG.Columns.Add(formula);
DG.Columns.Add(text);
DG.Columns.Add(description);
DG.Columns.Add(isSaveDatabase);
DG.Columns.Add(tableName);
DG.Columns.Add(periodSaveDB);
DG.Columns.Add(isEmergencyUp);
DG.Columns.Add(emergencyUp);
DG.Columns.Add(isEmergencyDown);
DG.Columns.Add(emergencyDown);
DG.Columns.Add(isEmergencySaveDB);
DG.Columns.Add(periodEmergencySaveDB);
DG.Columns.Add(id);
#endregion
RowDefinition rowID = new RowDefinition();
rowID.Height = GridLength.Auto;
RowDefinition rowDescription = new RowDefinition();
rowDescription.Height = GridLength.Auto;
RowDefinition rowSerialPort = new RowDefinition();
rowSerialPort.Height = GridLength.Auto;
RowDefinition rowAddressSlave = new RowDefinition();
rowAddressSlave.Height = GridLength.Auto;
RowDefinition rowTime = new RowDefinition();
rowTime.Height = GridLength.Auto;
RowDefinition rowNet = new RowDefinition();
rowNet.Height = new GridLength(30);
RowDefinition rowStatus = new RowDefinition();
rowStatus.Height = GridLength.Auto;
RowDefinition rowProtocols = new RowDefinition();
rowProtocols.Height = GridLength.Auto;
RowDefinition rowReverseRegister = new RowDefinition();
rowReverseRegister.Height = GridLength.Auto;
RowDefinition rowUS800 = new RowDefinition();
rowUS800.Height = GridLength.Auto;
RowDefinition rowItemNets = new RowDefinition();
rowItemNets.Height = GridLength.Auto;
Image addImage = new Image();
addImage.Source = new BitmapImage(new Uri("Images/AddNet.png", UriKind.Relative));
Image startImage = new Image();
startImage.Source = new BitmapImage(new Uri("Images/StartEthernet.png", UriKind.Relative));
Image stopImage = new Image();
stopImage.Source = new BitmapImage(new Uri("Images/StopEthernet.png", UriKind.Relative));
Binding bindingStartIsEnable = new Binding();
bindingStartIsEnable.Converter = new DGItemsToBoolConverter();
bindingStartIsEnable.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
bindingStartIsEnable.Source = DG;
bindingStartIsEnable.Path = new PropertyPath("Items.Count");
Binding bindingStart2IsEnable = new Binding();
bindingStart2IsEnable.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
bindingStart2IsEnable.Source = this;
bindingStart2IsEnable.Path = new PropertyPath("IsBindingStart");
Binding bindingRemoveButtonIsEnable = new Binding();
bindingRemoveButtonIsEnable.Converter = new RemoveButtonConverter();
bindingRemoveButtonIsEnable.Source = DG;
bindingRemoveButtonIsEnable.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
bindingRemoveButtonIsEnable.Path = new PropertyPath("SelectedItem");
Binding bindingRemoveButton2IsEnable = new Binding();
bindingRemoveButton2IsEnable.Source = this;
bindingRemoveButton2IsEnable.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
bindingRemoveButton2IsEnable.Path = new PropertyPath("IsBindingStart");
MultiBinding multiBindingStart = new MultiBinding();
multiBindingStart.Converter = new ButtonStartInterfaceValueConverter();
multiBindingStart.Bindings.Add(bindingStartIsEnable);
multiBindingStart.Bindings.Add(bindingStart2IsEnable);
MultiBinding RemoveButtonIsEnable = new MultiBinding();
RemoveButtonIsEnable.Converter = new ButtonStartInterfaceValueConverter();
RemoveButtonIsEnable.Bindings.Add(bindingRemoveButtonIsEnable);
RemoveButtonIsEnable.Bindings.Add(bindingRemoveButton2IsEnable);
Start = new Button();
Start.SetBinding(Button.IsEnabledProperty, multiBindingStart);
Start.Style = (Style)Application.Current.FindResource("ControlOnToolBar");
Start.ToolTip = "Начать опрос сетевых параметров";
Start.Margin = new Thickness(3);
Start.Content = startImage;
Start.Click += Start_Click;
Stop = new Button();
Stop.IsEnabled = false;
Stop.Style = (Style)Application.Current.FindResource("ControlOnToolBar");
Stop.ToolTip = "Остановить опрос сетевых параметров";
Stop.Margin = new Thickness(3);
Stop.Content = stopImage;
Stop.Click += Stop_Click;
AddNetButton = new Button();
AddNetButton.Style = (Style)Application.Current.FindResource("ControlOnToolBar");
AddNetButton.ToolTip = "Добавить параметр";
AddNetButton.Margin = new Thickness(3);
AddNetButton.Content = addImage;
AddNetButton.PreviewMouseDown += AddNetButton_PreviewMouseDown;
Image removeImage = new Image();
removeImage.Source = new BitmapImage(new Uri("Images/DeleteNet.png", UriKind.Relative));
RemoveNetButton = new Button();
RemoveNetButton.IsEnabled = false;
RemoveNetButton.Style = (Style)Application.Current.FindResource("ControlOnToolBar");
RemoveNetButton.ToolTip = "Удалить параметр";
RemoveNetButton.Margin = new Thickness(3);
RemoveNetButton.Content = removeImage;
RemoveNetButton.SetBinding(Button.IsEnabledProperty, RemoveButtonIsEnable);
RemoveNetButton.Click += RemoveNetButton_Click;
StackPanel panelID = new StackPanel();
panelID.Orientation = Orientation.Horizontal;
panelID.SetValue(Grid.RowProperty, 0);
StackPanel panelDescription = new StackPanel();
panelDescription.Orientation = Orientation.Horizontal;
panelDescription.SetValue(Grid.RowProperty, 1);
StackPanel panelSerialPort = new StackPanel();
panelSerialPort.Orientation = Orientation.Horizontal;
panelSerialPort.SetValue(Grid.RowProperty, 2);
StackPanel panelAddressSlave = new StackPanel();
panelAddressSlave.Orientation = Orientation.Horizontal;
panelAddressSlave.SetValue(Grid.RowProperty, 3);
StackPanel panelTime = new StackPanel();
panelTime.Orientation = Orientation.Horizontal;
panelTime.SetValue(Grid.RowProperty, 4);
StackPanel panelProtocol = new StackPanel();
panelProtocol.Orientation = Orientation.Horizontal;
panelProtocol.SetValue(Grid.RowProperty, 5);
StackPanel panelReverseRegister = new StackPanel();
panelReverseRegister.Orientation = Orientation.Horizontal;
panelReverseRegister.SetValue(Grid.RowProperty, 6);
StackPanel panelUS800 = new StackPanel();
panelUS800.Orientation = Orientation.Horizontal;
panelUS800.SetValue(Grid.RowProperty, 7);
StackPanel panelNetButton = new StackPanel();
panelNetButton.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
panelNetButton.Orientation = Orientation.Horizontal;
panelNetButton.SetValue(Grid.RowProperty, 8);
StackPanel panelStatus = new StackPanel();
panelStatus.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
panelStatus.Orientation = Orientation.Horizontal;
panelStatus.SetValue(Grid.RowProperty, 9);
TBStatus = new TextBox();
TBStatus.TextWrapping = TextWrapping.Wrap;
TBStatus.MaxWidth = 700;
TBStatus.MaxLines = 5;
TBStatus.IsReadOnly = true;
TBStatus.VerticalScrollBarVisibility = ScrollBarVisibility.Visible;
TBStatus.Text = "Статус: Опрос остановлен";
Label labelIDModbus = new Label();
labelIDModbus.Content = "ID: ";
Label labelDescriptionModbus = new Label();
labelDescriptionModbus.Content = "Описание Modbus: ";
Label LabelSerialPort = new Label();
LabelSerialPort.Content = "Com-порт:";
Label LabelAddressSlave = new Label();
LabelAddressSlave.Content = "Адрес slave:";
Label protocolLabel = new Label();
protocolLabel.Content = "Протокол:";
Label reverseLabel = new Label();
reverseLabel.Content = "Реверс регистров:";
Label us800Label = new Label();
us800Label.Content = "Modbus US800:";
Label timeLabel = new Label();
timeLabel.Content = "Время опроса (с):";
Label collectionNetLabel = new Label();
collectionNetLabel.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
collectionNetLabel.Content = "Список сетевых параметров";
panelID.Children.Add(labelIDModbus);
panelID.Children.Add(TBIDModbus);
panelDescription.Children.Add(labelDescriptionModbus);
panelDescription.Children.Add(TBDescriptionModbus);
panelSerialPort.Children.Add(LabelSerialPort);
panelSerialPort.Children.Add(CBSerialPort);
panelAddressSlave.Children.Add(LabelAddressSlave);
panelAddressSlave.Children.Add(TBAddressSlave);
panelProtocol.Children.Add(protocolLabel);
panelProtocol.Children.Add(CBProtocol);
panelReverseRegister.Children.Add(reverseLabel);
panelReverseRegister.Children.Add(CHReverseRegister);
panelUS800.Children.Add(us800Label);
panelUS800.Children.Add(CHUS800);
panelTime.Children.Add(timeLabel);
panelTime.Children.Add(TBTime);
panelNetButton.Children.Add(Start);
panelNetButton.Children.Add(Stop);
panelNetButton.Children.Add(collectionNetLabel);
panelNetButton.Children.Add(AddNetButton);
panelNetButton.Children.Add(RemoveNetButton);
panelStatus.Children.Add(TBStatus);
RowDefinitions.Add(rowID);
RowDefinitions.Add(rowDescription);
RowDefinitions.Add(rowSerialPort);
RowDefinitions.Add(rowAddressSlave);
RowDefinitions.Add(rowTime);
RowDefinitions.Add(rowProtocols);
RowDefinitions.Add(rowReverseRegister);
RowDefinitions.Add(rowUS800);
RowDefinitions.Add(rowNet);
RowDefinitions.Add(rowStatus);
RowDefinitions.Add(rowItemNets);
MenuItem menuItemPasteBufferSize = new MenuItem();
menuItemPasteBufferSize.Command = ApplicationCommands.Paste;
MenuItem menuItemCopyBufferSize = new MenuItem();
menuItemCopyBufferSize.Command = ApplicationCommands.Copy;
ContextMenu ContextMenuBufferSize = new System.Windows.Controls.ContextMenu();
ContextMenuBufferSize.Items.Add(menuItemPasteBufferSize);
ContextMenuBufferSize.Items.Add(menuItemCopyBufferSize);
MenuItem menuItemPasteDescription = new MenuItem();
menuItemPasteDescription.Command = ApplicationCommands.Paste;
MenuItem menuItemCopyDescription = new MenuItem();
menuItemCopyDescription.Command = ApplicationCommands.Copy;
ContextMenu ContextMenuDescription = new System.Windows.Controls.ContextMenu();
ContextMenuDescription.Items.Add(menuItemPasteDescription);
ContextMenuDescription.Items.Add(menuItemCopyDescription);
MenuItem menuItemPasteTime = new MenuItem();
menuItemPasteTime.Command = ApplicationCommands.Paste;
MenuItem menuItemCopyTime = new MenuItem();
menuItemCopyTime.Command = ApplicationCommands.Copy;
ContextMenu ContextMenuTime = new System.Windows.Controls.ContextMenu();
ContextMenuTime.Items.Add(menuItemPasteTime);
ContextMenuTime.Items.Add(menuItemCopyTime);
TBDescriptionModbus.CommandBindings.Add(new CommandBinding(ApplicationCommands.Cut, IgnoreCut));
TBDescriptionModbus.CommandBindings.Add(new CommandBinding(ApplicationCommands.Paste, TextTextBoxPaste));
TBDescriptionModbus.ContextMenu = ContextMenuDescription;
TBDescriptionModbus.PreviewTextInput += Text_PreviewTextInput;
TBDescriptionModbus.PreviewKeyDown += BackspacePreviewTextKeyDown;
TBDescriptionModbus.PreviewMouseDown += CorrectSelectionAll_PreviewMouseDown;
TBDescriptionModbus.GotFocus += TextBoxFocus;
TBTime.CommandBindings.Add(new CommandBinding(ApplicationCommands.Cut, IgnoreCut));
TBTime.CommandBindings.Add(new CommandBinding(ApplicationCommands.Paste, DigitalTextBoxPaste));
TBTime.ContextMenu = ContextMenuTime;
TBAddressSlave.CommandBindings.Add(new CommandBinding(ApplicationCommands.Cut, IgnoreCut));
TBAddressSlave.CommandBindings.Add(new CommandBinding(ApplicationCommands.Paste, DigitalTextBoxPaste));
TBAddressSlave.ContextMenu = ContextMenuTime;
TBAddressSlave.PreviewTextInput += DigitalTextBox_PreviewTextInput;
TBAddressSlave.PreviewKeyDown += BackspacePreviewTextKeyDown;
TBAddressSlave.PreviewMouseDown += CorrectSelectionAll_PreviewMouseDown;
TBAddressSlave.GotFocus += TextBoxFocus;
TBTime.PreviewTextInput += DigitalTextBox_PreviewTextInput;
TBTime.PreviewKeyDown += BackspacePreviewTextKeyDown;
TBTime.PreviewMouseDown += CorrectSelectionAll_PreviewMouseDown;
TBTime.GotFocus += TextBoxFocus;
TBTime.Margin = new Thickness(3);
Binding bindingDescriptionModbus = new Binding();
bindingDescriptionModbus.Source = NewModbusSer;
bindingDescriptionModbus.Path = new PropertyPath("Description");
Binding bindingTimeModbus = new Binding();
bindingTimeModbus.Source = NewModbusSer;
bindingTimeModbus.Path = new PropertyPath("Time");
Binding bindingSlaveAddressModbus = new Binding();
bindingSlaveAddressModbus.Source = NewModbusSer;
bindingSlaveAddressModbus.Path = new PropertyPath("SlaveAddress");
Binding bindingReverseRegisterModbus = new Binding();
bindingReverseRegisterModbus.Source = NewModbusSer;
bindingReverseRegisterModbus.Path = new PropertyPath("ReverseRegister");
Binding bindingIsUS800Modbus = new Binding();
bindingIsUS800Modbus.Source = NewModbusSer;
bindingIsUS800Modbus.Path = new PropertyPath("IsUS800");
Binding bindingProtocolModbus = new Binding();
bindingProtocolModbus.Source = NewModbusSer;
bindingProtocolModbus.Path = new PropertyPath("Protocol");
Binding bindingComPortModbus = new Binding();
bindingComPortModbus.Source = NewModbusSer;
bindingComPortModbus.Path = new PropertyPath("ComPort");
CHUS800.SetBinding(CheckBox.IsCheckedProperty, bindingIsUS800Modbus);
CHReverseRegister.SetBinding(CheckBox.IsCheckedProperty, bindingReverseRegisterModbus);
TBTime.SetBinding(TextBox.TextProperty, bindingTimeModbus);
TBDescriptionModbus.SetBinding(TextBox.TextProperty, bindingDescriptionModbus);
TBAddressSlave.SetBinding(TextBox.TextProperty, bindingSlaveAddressModbus);
CBProtocol.SetBinding(ComboBox.SelectedItemProperty, bindingProtocolModbus);