示例#1
0
        public ComControl(PageScada ps, CanvasPage canvasPage, ComSer comSer)
            : base(comSer)
        {
            this.Focusable = false;
            PS             = ps;
            canvasPage     = canvasPage;
            ComSer         = comSer;

            menuItemProperties.Click += Properties;
        }
示例#2
0
        public ImageControl(PageScada ps, CanvasPage canvasPage, ImageSer imageSer)
            : base(imageSer)
        {
            this.Focusable = false;
            PS             = ps;
            CanvasPage     = canvasPage;
            ImageSer       = imageSer;

            menuItemProperties.Click += Properties;
        }
示例#3
0
        public ModbusControl(PageScada ps, CanvasPage canvasPage, ModbusSer modbusSer)
            : base(modbusSer)
        {
            this.Focusable = false;
            PS             = ps;
            CanvasPage     = canvasPage;
            ModbusSer      = modbusSer;

            menuItemProperties.Click += Properties;
        }
示例#4
0
        public EthernetControl(PageScada ps, CanvasPage canvasPage, EthernetSer ethernetSer)
            : base(ethernetSer)
        {
            this.Focusable = false;
            PS             = ps;
            CanvasPage     = canvasPage;
            EthernetSer    = ethernetSer;

            menuItemProperties.Click += Properties;
        }
示例#5
0
        public Display(PageScada ps, CanvasPage canvasPage, DisplaySer displaySer)
            : base(displaySer)
        {
            this.Focusable = false;
            PS             = ps;
            CanvasPage     = canvasPage;
            DisplaySer     = displaySer;

            menuItemProperties.Click += Properties;
        }
示例#6
0
        public Text(PageScada ps, CanvasPage canvasPage, TextSer textSer)
            : base(textSer)
        {
            this.Focusable = false;
            PS             = ps;
            CanvasPage     = canvasPage;
            TextSer        = textSer;

            menuItemProperties.Click += Properties;
        }
        public int CompareTo(object obj)
        {
            PageScada otherPageScada = obj as PageScada;

            if (otherPageScada != null)
            {
                return(this.Attachments.CompareTo(otherPageScada.Attachments));
            }

            else
            {
                throw new ArgumentException("Пустой объект для сортировки");
            }
        }
示例#8
0
        private void CreatePage(object sender, RoutedEventArgs e)
        {
            char[] InvalidChars = { '"', '/', '\\', '<', '>', '?', '*', '|', ':' };

            if (NamePage.Text.IndexOfAny(InvalidChars) != -1)
            {
                Border border = new Border();
                border.BorderThickness = new Thickness(2);
                border.Background      = new SolidColorBrush(Colors.White);
                border.BorderBrush     = new SolidColorBrush(Colors.Red);

                TextBlock textBlock = new TextBlock();
                textBlock.TextWrapping = TextWrapping.Wrap;
                textBlock.Text         = "Имя странцы не должно содержать символы: < > | \" / \\ * : ?";

                border.Child = textBlock;

                Message.Child  = border;
                Message.IsOpen = true;

                e.Handled = true;
                return;
            }

            if (string.IsNullOrWhiteSpace(NamePage.Text))
            {
                Border border = new Border();
                border.BorderThickness = new Thickness(2);
                border.Background      = new SolidColorBrush(Colors.White);
                border.BorderBrush     = new SolidColorBrush(Colors.Red);

                TextBlock textBlock = new TextBlock();
                textBlock.TextWrapping = TextWrapping.Wrap;
                textBlock.Text         = "Имя страницы не должно содержать только пробелы или быть пустой строкой.";
                border.Child           = textBlock;

                Message.Child  = border;
                Message.IsOpen = true;

                e.Handled = true;
                return;
            }

            if (!NamePage.Text.EndsWith(".pg"))
            {
                NamePage.Text += ".pg";
            }

            //Находим индекс имени проекта, для удаления и получения пути проекта
            int index = ((MainWindow)((AppWPF)Application.Current).MainWindow).ProjectBin.PathProject.LastIndexOf(((MainWindow)((AppWPF)Application.Current).MainWindow).ProjectBin.ProjectName);

            Window MainWindow = ((AppWPF)System.Windows.Application.Current).MainWindow;

            PageScada ps = new PageScada();

            ps.Name        = NamePage.Text;
            ps.Path        = ((MainWindow)((AppWPF)Application.Current).MainWindow).ProjectBin.PathProject.Remove(index) + "\\" + NamePage.Text;
            ps.Attachments = 0;

            if (File.Exists(ps.Path))
            {
                MessageBox.Show("Страница " + ps.Path + " уже существует.", "Ошибка создания страницы", MessageBoxButton.OK, MessageBoxImage.Error);

                e.Handled = true;
                return;
            }

            StackPanel panelPage = new StackPanel();

            panelPage.Orientation = System.Windows.Controls.Orientation.Horizontal;

            Image imageScada = new Image();

            imageScada.Source = new BitmapImage(new Uri("Images/Page16.png", UriKind.Relative));

            Image imageCut = new Image();

            imageCut.Source = new BitmapImage(new Uri("Images/Cut16.png", UriKind.Relative));

            Image imageDelete = new Image();

            imageDelete.Source = new BitmapImage(new Uri("Images/PageDelete16.png", UriKind.Relative));

            Image imageCopy = new Image();

            imageCopy.Source = new BitmapImage(new Uri("Images/CopyPage16.png", UriKind.Relative));

            MenuItem menuItemCopyPage = new MenuItem();

            menuItemCopyPage.IsEnabled = false;
            menuItemCopyPage.Style     = (Style)Application.Current.FindResource("ControlOnToolBar");
            menuItemCopyPage.Header    = "Копировать";
            menuItemCopyPage.Icon      = imageCopy;
            menuItemCopyPage.Tag       = ps;
            menuItemCopyPage.Click    += ((MainWindow)MainWindow).CopyItem;

            MenuItem menuItemCutPage = new MenuItem();

            menuItemCutPage.IsEnabled = false;
            menuItemCutPage.Style     = (Style)Application.Current.FindResource("ControlOnToolBar");
            menuItemCutPage.Header    = "Вырезать";
            menuItemCutPage.Icon      = imageCut;
            menuItemCutPage.Tag       = ps;
            menuItemCutPage.Click    += ((MainWindow)MainWindow).CutItem;

            MenuItem menuItemDeletePage = new MenuItem();

            menuItemDeletePage.Header = "Удалить";
            menuItemDeletePage.Icon   = imageDelete;
            menuItemDeletePage.Tag    = ps;
            menuItemDeletePage.Click += ((MainWindow)MainWindow).DeleteItem;

            ContextMenu contextMenuPage = new ContextMenu();

            contextMenuPage.Tag = "PageScada";
            contextMenuPage.Items.Add(menuItemCopyPage);
            contextMenuPage.Items.Add(menuItemCutPage);
            contextMenuPage.Items.Add(menuItemDeletePage);

            TreeViewItem ItemPage = new TreeViewItem();

            ItemPage.MouseDoubleClick += ((MainWindow)MainWindow).OpenBrowsePage;
            ItemPage.Tag         = ps;
            ItemPage.KeyDown    += ((MainWindow)MainWindow).RenamePage;
            ItemPage.ContextMenu = contextMenuPage;

            ps.TreeItem = ItemPage;

            System.Windows.Controls.TextBox tbRenamePage = new System.Windows.Controls.TextBox();
            tbRenamePage.KeyDown += ((MainWindow)MainWindow).OkRenamePage;
            tbRenamePage.Text     = ps.Name;

            System.Windows.Controls.Label lNamePage = new System.Windows.Controls.Label();
            lNamePage.Content = ps.Name;
            lNamePage.Tag     = tbRenamePage;

            AlphanumComparator a = new AlphanumComparator();

            a.Name = (string)lNamePage.Content;

            panelPage.Children.Add(imageScada);
            panelPage.Children.Add(lNamePage);
            panelPage.Tag = a;

            ItemPage.Header = panelPage;
            ((MainWindow)MainWindow).BrowseProject.Items.Add(ItemPage);

            Page pg = new Page();

            ((MainWindow)((AppWPF)Application.Current).MainWindow).ProjectBin.CollectionPageScada.Add(ps.Path, ps);
            ((AppWPF)System.Windows.Application.Current).CollectionPage.Add(ps.Path, pg);

            TabItemPage tabItemPage = new TabItemPage(ps);

            using (FileStream fs = File.Create((ps.Path)))
            {
                XamlWriter.Save(pg, fs);
                fs.Close();
            }

            ((MainWindow)MainWindow).BrowseProject.Items.SortDescriptions.Clear();
            ((MainWindow)MainWindow).BrowseProject.Items.SortDescriptions.Add(new SortDescription("ContextMenu.Tag", ListSortDirection.Ascending));
            ((MainWindow)MainWindow).BrowseProject.Items.SortDescriptions.Add(new SortDescription("Header.Tag", ListSortDirection.Ascending));

            e.Handled = true;
            this.Close();
        }
示例#9
0
        public TabItemPage(PageScada ps)
        {
            PS = ps;
            CanvasPage canvasPage = new CanvasPage(this.PS, this);

            CanvasPage = canvasPage;

            MainWindow mainWindow = (MainWindow)Application.Current.MainWindow;

            Image imageClose = new Image();

            imageClose.Source = new BitmapImage(new Uri("Images/Close16.png", UriKind.Relative));

            Button close = new Button();

            close.Tag     = this;
            close.Click  += CloseTabItem;
            close.ToolTip = "Закрыть";
            close.Content = imageClose;
            close.Height  = 16;
            close.Width   = 16;

            Label lPageName = new Label();

            lPageName.Content = PS.Name;

            ScrollViewer scroll = new ScrollViewer();

            scroll.VerticalScrollBarVisibility   = ScrollBarVisibility.Auto;
            scroll.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
            scroll.SetValue(Grid.RowProperty, 0);

            Image insertImage = new Image();

            insertImage.Source = new BitmapImage(new Uri("Images/Insert16.ico", UriKind.Relative));

            Binding BindingInsert = new Binding();

            BindingInsert.Source = mainWindow;
            BindingInsert.Path   = new PropertyPath("IsBindingInsertObject");
            BindingInsert.Mode   = BindingMode.OneWay;

            MenuItem menuItemInsert = new MenuItem();

            menuItemInsert.SetBinding(MenuItem.IsEnabledProperty, BindingInsert);
            menuItemInsert.Icon   = insertImage;
            menuItemInsert.Click += canvasPage.Insert;
            menuItemInsert.Header = "Вставить";

            ContextMenu contextMenuCanvas = new ContextMenu();

            contextMenuCanvas.Items.Add(menuItemInsert);

            canvasPage.ContextMenu = contextMenuCanvas;

            StackPanel panelTabItem = new StackPanel();

            panelTabItem.ToolTip     = PS.Path;
            panelTabItem.Orientation = Orientation.Horizontal;
            panelTabItem.Children.Add(lPageName);
            panelTabItem.Children.Add(close);

            this.Header    = panelTabItem;
            this.Content   = scroll;
            scroll.Content = canvasPage;

            ((AppWPF)Application.Current).CollectionTabItemParent.Add(PS.Path, this);

            Page page = ((AppWPF)Application.Current).CollectionPage[PS.Path];

            foreach (PipeSer pipeSer in page.CollectionPipe)
            {
                Pipe pipe = new Pipe(PS, CanvasPage, pipeSer);

                pipe.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
                {
                    pipe.PathFigureLeftSize.StartPoint = pipeSer.LeftSize.point[0];
                    pipe.LineSegmentLeftSize.Point     = pipeSer.LeftSize.point[1];

                    pipe.PathFigureRightSize.StartPoint = pipeSer.RightSize.point[0];
                    pipe.LineSegmentRightSize.Point     = pipeSer.RightSize.point[1];

                    pipe.PathFigureTopSize.StartPoint = pipeSer.TopSize.point[0];
                    pipe.LineSegmentTopSize.Point     = pipeSer.TopSize.point[1];

                    pipe.PathFigureDownSize.StartPoint = pipeSer.DownSize.point[0];
                    pipe.LineSegmentDownSize.Point     = pipeSer.DownSize.point[1];

                    pipe.PathFigureLeftFlange.StartPoint     = pipeSer.LeftFlange.point[0];
                    pipe.PolyLineSegmentLeftFlange.Points[0] = pipeSer.LeftFlange.point[1];
                    pipe.PolyLineSegmentLeftFlange.Points[1] = pipeSer.LeftFlange.point[2];
                    pipe.PolyLineSegmentLeftFlange.Points[2] = pipeSer.LeftFlange.point[3];
                    pipe.PolyLineSegmentLeftFlange.Points[3] = pipeSer.LeftFlange.point[4];

                    pipe.PathFigureRightFlange.StartPoint     = pipeSer.RightFlange.point[0];
                    pipe.PolyLineSegmentRightFlange.Points[0] = pipeSer.RightFlange.point[1];
                    pipe.PolyLineSegmentRightFlange.Points[1] = pipeSer.RightFlange.point[2];
                    pipe.PolyLineSegmentRightFlange.Points[2] = pipeSer.RightFlange.point[3];
                    pipe.PolyLineSegmentRightFlange.Points[3] = pipeSer.RightFlange.point[4];

                    pipe.PathFigurePipe.StartPoint     = pipeSer.Pipe.point[0];
                    pipe.PolyLineSegmentPipe.Points[0] = pipeSer.Pipe.point[1];
                    pipe.PolyLineSegmentPipe.Points[1] = pipeSer.Pipe.point[2];
                    pipe.PolyLineSegmentPipe.Points[2] = pipeSer.Pipe.point[3];
                    pipe.PolyLineSegmentPipe.Points[3] = pipeSer.Pipe.point[4];

                    pipe.PathFigureBorder.StartPoint     = pipeSer.BorderPipe.point[0];
                    pipe.PolyLineSegmentBorder.Points[0] = pipeSer.BorderPipe.point[1];
                    pipe.PolyLineSegmentBorder.Points[1] = pipeSer.BorderPipe.point[2];
                    pipe.PolyLineSegmentBorder.Points[2] = pipeSer.BorderPipe.point[3];
                    pipe.PolyLineSegmentBorder.Points[3] = pipeSer.BorderPipe.point[4];

                    pipe.Diameter = (pipe.PathFigureDownSize.StartPoint.Y - pipe.PathFigureTopSize.StartPoint.Y);
                }));

                pipe.SetValue(Canvas.LeftProperty, pipeSer.Сoordinates.X);
                pipe.SetValue(Canvas.TopProperty, pipeSer.Сoordinates.Y);

                canvasPage.Children.Add(pipe);
                pipe.ApplyTemplate();
            }
            foreach (Pipe90Ser pipe90Ser in page.CollectionPipe90)
            {
                Pipe90 pipe90 = new Pipe90(PS, CanvasPage, pipe90Ser);

                pipe90.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
                {
                    pipe90.PathFigureTopLenghtSize.StartPoint = pipe90Ser.TopLenghtSize.point[0];
                    pipe90.LineSegmentTopLenghtSize.Point     = pipe90Ser.TopLenghtSize.point[1];

                    pipe90.PathFigureDownLenghtSize.StartPoint = pipe90Ser.DownLenghtSize.point[0];
                    pipe90.LineSegmentDownLenghtSize.Point     = pipe90Ser.DownLenghtSize.point[1];

                    pipe90.PathFigureTopSize.StartPoint = pipe90Ser.TopSize.point[0];
                    pipe90.LineSegmentTopSize.Point     = pipe90Ser.TopSize.point[1];

                    pipe90.PathFigureDownSize.StartPoint = pipe90Ser.DownSize.point[0];
                    pipe90.LineSegmentDownSize.Point     = pipe90Ser.DownSize.point[1];

                    pipe90.PathFigureLeftFlange.StartPoint     = pipe90Ser.LeftFlange.point[0];
                    pipe90.PolyLineSegmentLeftFlange.Points[0] = pipe90Ser.LeftFlange.point[1];
                    pipe90.PolyLineSegmentLeftFlange.Points[1] = pipe90Ser.LeftFlange.point[2];
                    pipe90.PolyLineSegmentLeftFlange.Points[2] = pipe90Ser.LeftFlange.point[3];
                    pipe90.PolyLineSegmentLeftFlange.Points[3] = pipe90Ser.LeftFlange.point[4];

                    pipe90.PathFigureRightFlange.StartPoint     = pipe90Ser.RightFlange.point[0];
                    pipe90.PolyLineSegmentRightFlange.Points[0] = pipe90Ser.RightFlange.point[1];
                    pipe90.PolyLineSegmentRightFlange.Points[1] = pipe90Ser.RightFlange.point[2];
                    pipe90.PolyLineSegmentRightFlange.Points[2] = pipe90Ser.RightFlange.point[3];
                    pipe90.PolyLineSegmentRightFlange.Points[3] = pipe90Ser.RightFlange.point[4];

                    pipe90.PathFigureTopImage.StartPoint     = pipe90Ser.TopImage.point[0];
                    pipe90.PolyLineSegmentTopImage.Points[0] = pipe90Ser.TopImage.point[1];
                    pipe90.PolyLineSegmentTopImage.Points[1] = pipe90Ser.TopImage.point[2];
                    pipe90.PolyLineSegmentTopImage.Points[2] = pipe90Ser.TopImage.point[3];
                    pipe90.PolyLineSegmentTopImage.Points[3] = pipe90Ser.TopImage.point[4];

                    pipe90.PathFigureDownImage.StartPoint     = pipe90Ser.DownImage.point[0];
                    pipe90.PolyLineSegmentDownImage.Points[0] = pipe90Ser.DownImage.point[1];
                    pipe90.PolyLineSegmentDownImage.Points[1] = pipe90Ser.DownImage.point[2];
                    pipe90.PolyLineSegmentDownImage.Points[2] = pipe90Ser.DownImage.point[3];
                    pipe90.PolyLineSegmentDownImage.Points[3] = pipe90Ser.DownImage.point[4];

                    pipe90.PathFigureLeftDownSize.StartPoint = pipe90Ser.LeftDownSize.point[0];
                    pipe90.LineSegmentLeftDownSize.Point     = pipe90Ser.LeftDownSize.point[1];

                    pipe90.PathFigureRightDownSize.StartPoint = pipe90Ser.RightDownSize.point[0];
                    pipe90.LineSegmentRightDownSize.Point     = pipe90Ser.RightDownSize.point[1];

                    pipe90.PathFigureBorder.StartPoint     = pipe90Ser.BorderPipe90.point[0];
                    pipe90.PolyLineSegmentBorder.Points[0] = pipe90Ser.BorderPipe90.point[1];
                    pipe90.PolyLineSegmentBorder.Points[1] = pipe90Ser.BorderPipe90.point[2];
                    pipe90.PolyLineSegmentBorder.Points[2] = pipe90Ser.BorderPipe90.point[3];
                    pipe90.PolyLineSegmentBorder.Points[3] = pipe90Ser.BorderPipe90.point[4];

                    pipe90.Diameter = (pipe90.PathFigureDownSize.StartPoint.Y - pipe90.PathFigureTopSize.StartPoint.Y);
                }));

                pipe90.SetValue(Canvas.LeftProperty, pipe90Ser.Сoordinates.X);
                pipe90.SetValue(Canvas.TopProperty, pipe90Ser.Сoordinates.Y);

                canvasPage.Children.Add(pipe90);
                pipe90.ApplyTemplate();
            }
            foreach (TextSer textSer in page.CollectionText)
            {
                Text text = new Text(PS, CanvasPage, textSer);

                text.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
                {
                    text.PathFigureBorder.StartPoint     = textSer.Border.point[0];
                    text.PolyLineSegmentBorder.Points[0] = textSer.Border.point[1];
                    text.PolyLineSegmentBorder.Points[1] = textSer.Border.point[2];
                    text.PolyLineSegmentBorder.Points[2] = textSer.Border.point[3];
                    text.PolyLineSegmentBorder.Points[3] = textSer.Border.point[4];

                    text.PathFigureDownSize.StartPoint = textSer.DownSize.point[0];
                    text.LineSegmentDownSize.Point     = textSer.DownSize.point[1];

                    text.PathFigureLeftSize.StartPoint = textSer.LeftSize.point[0];
                    text.LineSegmentLeftSize.Point     = textSer.LeftSize.point[1];

                    text.PathFigureRightSize.StartPoint = textSer.RightSize.point[0];
                    text.LineSegmentRightSize.Point     = textSer.RightSize.point[1];

                    text.PathFigureTopSize.StartPoint = textSer.TopSize.point[0];
                    text.LineSegmentTopSize.Point     = textSer.TopSize.point[1];
                }));

                text.SetValue(Canvas.LeftProperty, textSer.Сoordinates.X);
                text.SetValue(Canvas.TopProperty, textSer.Сoordinates.Y);

                canvasPage.Children.Add(text);

                text.ApplyTemplate();
            }
            foreach (DisplaySer displaySer in page.CollectionDisplay)
            {
                Display display = new Display(PS, CanvasPage, displaySer);

                display.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
                {
                    display.PathFigureBorder.StartPoint     = displaySer.Border.point[0];
                    display.PolyLineSegmentBorder.Points[0] = displaySer.Border.point[1];
                    display.PolyLineSegmentBorder.Points[1] = displaySer.Border.point[2];
                    display.PolyLineSegmentBorder.Points[2] = displaySer.Border.point[3];
                    display.PolyLineSegmentBorder.Points[3] = displaySer.Border.point[4];

                    display.PathFigureDownSize.StartPoint = displaySer.DownSize.point[0];
                    display.LineSegmentDownSize.Point     = displaySer.DownSize.point[1];

                    display.PathFigureLeftSize.StartPoint = displaySer.LeftSize.point[0];
                    display.LineSegmentLeftSize.Point     = displaySer.LeftSize.point[1];

                    display.PathFigureRightSize.StartPoint = displaySer.RightSize.point[0];
                    display.LineSegmentRightSize.Point     = displaySer.RightSize.point[1];

                    display.PathFigureTopSize.StartPoint = displaySer.TopSize.point[0];
                    display.LineSegmentTopSize.Point     = displaySer.TopSize.point[1];
                }));

                display.SetValue(Canvas.LeftProperty, displaySer.Сoordinates.X);
                display.SetValue(Canvas.TopProperty, displaySer.Сoordinates.Y);

                canvasPage.Children.Add(display);

                display.ApplyTemplate();

                if (display.DisplaySer.IsEthernet)
                {
                    foreach (EthernetSer ethernetSer in ((AppWPF)Application.Current).CollectionEthernetSers)
                    {
                        if (ethernetSer.ID == displaySer.EthernetID)
                        {
                            if (displaySer.IsCollRec)
                            {
                                foreach (ItemEthernet itemEthernet in ethernetSer.CollectionItemNetRec)
                                {
                                    if (displaySer.ItemEthernetID == itemEthernet.ID)
                                    {
                                        displaySer.ItemEthernet = itemEthernet;

                                        display.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
                                        {
                                            Binding valueBinding   = new Binding();
                                            valueBinding.Converter = new ValueItemNetConverter(displaySer.ItemEthernet);
                                            valueBinding.Source    = displaySer.ItemEthernet;
                                            valueBinding.Path      = new PropertyPath("Value");

                                            display.RunBinding.SetBinding(Run.TextProperty, valueBinding);
                                        }));

                                        break;
                                    }
                                }
                            }

                            if (displaySer.IsCollSend)
                            {
                                foreach (ItemEthernet itemEthernet in ethernetSer.CollectionItemNetSend)
                                {
                                    if (displaySer.ItemEthernetID == itemEthernet.ID)
                                    {
                                        displaySer.ItemEthernet = itemEthernet;

                                        display.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
                                        {
                                            Binding valueBinding   = new Binding();
                                            valueBinding.Converter = new ValueItemNetConverter(displaySer.ItemEthernet);
                                            valueBinding.Source    = displaySer.ItemEthernet;
                                            valueBinding.Path      = new PropertyPath("Value");

                                            display.RunBinding.SetBinding(Run.TextProperty, valueBinding);
                                        }));

                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                else if (display.DisplaySer.IsModbus)
                {
                    foreach (ModbusSer modbusSer in ((AppWPF)Application.Current).CollectionModbusSers)
                    {
                        if (modbusSer.ID == displaySer.ModbusID)
                        {
                            foreach (ItemModbus itemModbus in modbusSer.CollectionItemModbus)
                            {
                                if (displaySer.ItemModbusID == itemModbus.ID)
                                {
                                    displaySer.ItemModbus = itemModbus;

                                    display.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
                                    {
                                        Binding valueBinding   = new Binding();
                                        valueBinding.Converter = new ValueItemModbusConverter(displaySer.ItemModbus);
                                        valueBinding.Source    = displaySer.ItemModbus;
                                        valueBinding.Path      = new PropertyPath("Value");

                                        display.RunBinding.SetBinding(Run.TextProperty, valueBinding);
                                    }));

                                    break;
                                }
                            }

                            break;
                        }
                    }
                }
            }
            foreach (ImageSer imageSer in page.CollectionImage)
            {
                ImageControl imageControl = new ImageControl(PS, CanvasPage, imageSer);

                imageControl.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
                {
                    imageControl.PathFigureBorder.StartPoint     = imageSer.Border.point[0];
                    imageControl.PolyLineSegmentBorder.Points[0] = imageSer.Border.point[1];
                    imageControl.PolyLineSegmentBorder.Points[1] = imageSer.Border.point[2];
                    imageControl.PolyLineSegmentBorder.Points[2] = imageSer.Border.point[3];
                    imageControl.PolyLineSegmentBorder.Points[3] = imageSer.Border.point[4];

                    imageControl.PathFigureDownSize.StartPoint = imageSer.DownSize.point[0];
                    imageControl.LineSegmentDownSize.Point     = imageSer.DownSize.point[1];

                    imageControl.PathFigureLeftSize.StartPoint = imageSer.LeftSize.point[0];
                    imageControl.LineSegmentLeftSize.Point     = imageSer.LeftSize.point[1];

                    imageControl.PathFigureRightSize.StartPoint = imageSer.RightSize.point[0];
                    imageControl.LineSegmentRightSize.Point     = imageSer.RightSize.point[1];

                    imageControl.PathFigureTopSize.StartPoint = imageSer.TopSize.point[0];
                    imageControl.LineSegmentTopSize.Point     = imageSer.TopSize.point[1];

                    if (imageSer.PathImage != null)
                    {
                        try
                        {
                            BitmapImage bi = new BitmapImage(new Uri(@imageSer.PathImage, UriKind.RelativeOrAbsolute));

                            if (bi.PixelWidth < 10 || bi.PixelWidth < 10)
                            {
                                new Exception();
                            }

                            imageControl.templateImage.Source = bi;
                        }
                        catch
                        {
                            imageControl.templateImage.Source = new BitmapImage(new Uri("../Images/ImageNotFound.png", UriKind.RelativeOrAbsolute));

                            bool rotate0   = false;
                            bool rotate90  = false;
                            bool rotate180 = false;
                            bool rotate270 = false;

                            if ((int)imageControl.RenderTransform.Value.M11 == 0 && (int)imageControl.RenderTransform.Value.M12 == -1)
                            {
                                rotate90 = true;
                            }
                            else if ((int)imageControl.RenderTransform.Value.M11 == -1 && (int)imageControl.RenderTransform.Value.M12 == 0)
                            {
                                rotate180 = true;
                            }
                            else if ((int)imageControl.RenderTransform.Value.M11 == 0 && (int)imageControl.RenderTransform.Value.M12 == 1)
                            {
                                rotate270 = true;
                            }
                            else
                            {
                                rotate0 = true;
                            }

                            if (rotate0)
                            {
                                SizeImage((BitmapImage)imageControl.templateImage.Source, imageControl);
                            }
                            else if (rotate90)
                            {
                                SizeImage((BitmapImage)imageControl.templateImage.Source, imageControl);
                            }
                            else if (rotate180)
                            {
                                SizeImage((BitmapImage)imageControl.templateImage.Source, imageControl);
                            }
                            else if (rotate270)
                            {
                                SizeImage((BitmapImage)imageControl.templateImage.Source, imageControl);
                            }
                        }
                    }
                    else if (imageControl.ImageSer.LibraryImage != null)
                    {
                        BitmapImage bi = new BitmapImage(new Uri(@"pack://application:,,,/Images/" + imageControl.ImageSer.LibraryImage + ".png", UriKind.RelativeOrAbsolute));

                        imageControl.templateImage.Source = bi;
                    }
                    else
                    {
                        imageControl.templateImage.Source = new BitmapImage(new Uri("../Images/ImageNotFound.png", UriKind.RelativeOrAbsolute));

                        bool rotate0   = false;
                        bool rotate90  = false;
                        bool rotate180 = false;
                        bool rotate270 = false;

                        if ((int)imageControl.RenderTransform.Value.M11 == 0 && (int)imageControl.RenderTransform.Value.M12 == -1)
                        {
                            rotate90 = true;
                        }
                        else if ((int)imageControl.RenderTransform.Value.M11 == -1 && (int)imageControl.RenderTransform.Value.M12 == 0)
                        {
                            rotate180 = true;
                        }
                        else if ((int)imageControl.RenderTransform.Value.M11 == 0 && (int)imageControl.RenderTransform.Value.M12 == 1)
                        {
                            rotate270 = true;
                        }
                        else
                        {
                            rotate0 = true;
                        }

                        if (rotate0)
                        {
                            SizeImage((BitmapImage)imageControl.templateImage.Source, imageControl);
                        }
                        else if (rotate90)
                        {
                            SizeImage((BitmapImage)imageControl.templateImage.Source, imageControl);
                        }
                        else if (rotate180)
                        {
                            SizeImage((BitmapImage)imageControl.templateImage.Source, imageControl);
                        }
                        else if (rotate270)
                        {
                            SizeImage((BitmapImage)imageControl.templateImage.Source, imageControl);
                        }
                    }

                    if (imageControl.ImageSer.StretchImage == "None")
                    {
                        imageControl.templateImage.Stretch = Stretch.None;
                    }
                    else if (imageControl.ImageSer.StretchImage == "Fill")
                    {
                        imageControl.templateImage.Stretch = Stretch.Fill;
                    }
                    else if (imageControl.ImageSer.StretchImage == "Uniform")
                    {
                        imageControl.templateImage.Stretch = Stretch.Uniform;
                    }
                    else if (imageControl.ImageSer.StretchImage == "UniformToFill")
                    {
                        imageControl.templateImage.Stretch = Stretch.UniformToFill;
                    }
                }));

                imageControl.SetValue(Canvas.LeftProperty, imageSer.Сoordinates.X);
                imageControl.SetValue(Canvas.TopProperty, imageSer.Сoordinates.Y);

                canvasPage.Children.Add(imageControl);

                imageControl.ApplyTemplate();
            }
            foreach (EthernetSer ethernetSer in page.CollectionEthernet)
            {
                EthernetControl ethernetControl = new EthernetControl(PS, CanvasPage, ethernetSer);

                ((AppWPF)Application.Current).CollectionEthernetSers.Add(ethernetSer);

                ethernetControl.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
                {
                    ethernetControl.PathFigureBorder.StartPoint     = ethernetSer.Border.point[0];
                    ethernetControl.PolyLineSegmentBorder.Points[0] = ethernetSer.Border.point[1];
                    ethernetControl.PolyLineSegmentBorder.Points[1] = ethernetSer.Border.point[2];
                    ethernetControl.PolyLineSegmentBorder.Points[2] = ethernetSer.Border.point[3];
                    ethernetControl.PolyLineSegmentBorder.Points[3] = ethernetSer.Border.point[4];

                    ethernetControl.PathFigureDownSize.StartPoint = ethernetSer.DownSize.point[0];
                    ethernetControl.LineSegmentDownSize.Point     = ethernetSer.DownSize.point[1];

                    ethernetControl.PathFigureLeftSize.StartPoint = ethernetSer.LeftSize.point[0];
                    ethernetControl.LineSegmentLeftSize.Point     = ethernetSer.LeftSize.point[1];

                    ethernetControl.PathFigureRightSize.StartPoint = ethernetSer.RightSize.point[0];
                    ethernetControl.LineSegmentRightSize.Point     = ethernetSer.RightSize.point[1];

                    ethernetControl.PathFigureTopSize.StartPoint = ethernetSer.TopSize.point[0];
                    ethernetControl.LineSegmentTopSize.Point     = ethernetSer.TopSize.point[1];
                }));

                ethernetControl.SetValue(Canvas.LeftProperty, ethernetSer.Сoordinates.X);
                ethernetControl.SetValue(Canvas.TopProperty, ethernetSer.Сoordinates.Y);

                canvasPage.Children.Add(ethernetControl);

                ethernetControl.ApplyTemplate();
            }
            foreach (ComSer comSer in page.CollectionCom)
            {
                ComControl comControl = new ComControl(PS, CanvasPage, comSer);

                ((AppWPF)Application.Current).CollectionComSers.Add(comSer);

                comControl.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
                {
                    comControl.PathFigureBorder.StartPoint     = comSer.Border.point[0];
                    comControl.PolyLineSegmentBorder.Points[0] = comSer.Border.point[1];
                    comControl.PolyLineSegmentBorder.Points[1] = comSer.Border.point[2];
                    comControl.PolyLineSegmentBorder.Points[2] = comSer.Border.point[3];
                    comControl.PolyLineSegmentBorder.Points[3] = comSer.Border.point[4];

                    comControl.PathFigureDownSize.StartPoint = comSer.DownSize.point[0];
                    comControl.LineSegmentDownSize.Point     = comSer.DownSize.point[1];

                    comControl.PathFigureLeftSize.StartPoint = comSer.LeftSize.point[0];
                    comControl.LineSegmentLeftSize.Point     = comSer.LeftSize.point[1];

                    comControl.PathFigureRightSize.StartPoint = comSer.RightSize.point[0];
                    comControl.LineSegmentRightSize.Point     = comSer.RightSize.point[1];

                    comControl.PathFigureTopSize.StartPoint = comSer.TopSize.point[0];
                    comControl.LineSegmentTopSize.Point     = comSer.TopSize.point[1];
                }));

                comControl.SetValue(Canvas.LeftProperty, comSer.Сoordinates.X);
                comControl.SetValue(Canvas.TopProperty, comSer.Сoordinates.Y);

                canvasPage.Children.Add(comControl);

                comControl.ApplyTemplate();
            }
            foreach (ModbusSer modbusSer in page.CollectionModbus)
            {
                ModbusControl modbusControl = new ModbusControl(PS, CanvasPage, modbusSer);

                ((AppWPF)Application.Current).CollectionModbusSers.Add(modbusSer);

                modbusControl.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
                {
                    modbusControl.PathFigureBorder.StartPoint     = modbusSer.Border.point[0];
                    modbusControl.PolyLineSegmentBorder.Points[0] = modbusSer.Border.point[1];
                    modbusControl.PolyLineSegmentBorder.Points[1] = modbusSer.Border.point[2];
                    modbusControl.PolyLineSegmentBorder.Points[2] = modbusSer.Border.point[3];
                    modbusControl.PolyLineSegmentBorder.Points[3] = modbusSer.Border.point[4];

                    modbusControl.PathFigureDownSize.StartPoint = modbusSer.DownSize.point[0];
                    modbusControl.LineSegmentDownSize.Point     = modbusSer.DownSize.point[1];

                    modbusControl.PathFigureLeftSize.StartPoint = modbusSer.LeftSize.point[0];
                    modbusControl.LineSegmentLeftSize.Point     = modbusSer.LeftSize.point[1];

                    modbusControl.PathFigureRightSize.StartPoint = modbusSer.RightSize.point[0];
                    modbusControl.LineSegmentRightSize.Point     = modbusSer.RightSize.point[1];

                    modbusControl.PathFigureTopSize.StartPoint = modbusSer.TopSize.point[0];
                    modbusControl.LineSegmentTopSize.Point     = modbusSer.TopSize.point[1];
                }));

                modbusControl.SetValue(Canvas.LeftProperty, modbusSer.Сoordinates.X);
                modbusControl.SetValue(Canvas.TopProperty, modbusSer.Сoordinates.Y);

                canvasPage.Children.Add(modbusControl);

                modbusControl.ApplyTemplate();
            }
        }