private void DrawMap() { List <ObservableCollection <BaseDrawClass> > listCollectionsColor = new List <ObservableCollection <BaseDrawClass> >() { ListColorVMA, ListColorVMB, ListColorVMV, ListColorVMG }; List <ObservableCollection <BaseDrawClass> > listCollection = new List <ObservableCollection <BaseDrawClass> >() { ListViewsVMA, ListViewsVMB, ListViewsVMV, ListViewsVMG }; List <ObservableCollection <FrameworkElement> > listCollectionElement = new List <ObservableCollection <FrameworkElement> >() { ListColorElementA, ListColorElementB, ListColorElementV, ListColorElementG }; List <ViewPanel> viewPanels = new List <ViewPanel>() { _panelColorA, _panelColorB, _panelColorV, _panelColorG }; List <VMViewPanel> viewVMPanels = new List <VMViewPanel>() { _viewPanelColorVMA, _viewPanelColorVMB, _viewPanelColorVMV, _viewPanelColorVMG }; List <string> views = new List <string>() { "А", "Б", "В", "Г" }; if (_drawMapGo) { return; } _viewToolbarColor = null; _nameElement.Clear(); _nameElementPlace = new ObservableCollection <string>() { "Опоры", "Лестница", "Балки перил", "Стойки перил", "Перила", "Перильные ограждения", "Основание", }; _nameElementPortal = new ObservableCollection <string>() { "Стойки", "Траверс" }; //colorViews.ForEach(colorView => colorView = null); _drawMapGo = true; ListViewPlaceColor.Clear(); ListViewPlaceElementColor.Clear(); ListViewPortalColor.Clear(); ListViewPortalElementColor.Clear(); listCollectionsColor.ForEach(list => list.Clear()); listCollectionElement.ForEach(list => list.Clear()); dictColorElem.Clear(); listCollection.ForEach(ListVM => { var numberView = listCollection.Select((item, index) => new { item, index }) .Where(ix => ix.item == ListVM) .Select(ix => ix.index) .FirstOrDefault(); ProgBarViewModel _progBarViewModel = new ProgBarViewModel(); Application.Current.Dispatcher.Invoke((Action)(() => { _progBarViewModel.ActionName = $"Построение карты покраски Вида {views[numberView]}"; _progBarViewModel.ShowBar(); })); ListVM .ToList() .ForEach(colorElement => { if (!(colorElement is VMSchemeElement)) { if ((colorElement is VMPanelRZA) || (colorElement is VMInformTable)) { BaseDrawClass ss2; if (colorElement is VMPanelRZA) { ss2 = new VMPanelRZA(colorElement as VMPanelRZA); } else { ss2 = new VMInformTable(colorElement as VMInformTable); } if (numberView == 0 || numberView == 1) { ss2.X -= 150; } Canvas.SetLeft(ss2.ParentEl, ss2.X); listCollectionsColor[numberView].Add(ss2); listCollectionElement[numberView].Add(ss2.ParentEl); return; } else { return; } } var nameElem = _nameElement.ToList().Find(x => x == (colorElement as VMSchemeElement).Name); if (nameElem == null) { _nameElement.Add((colorElement as VMSchemeElement).Name); } var ss = new VMSchemeElement(colorElement as VMSchemeElement); if (numberView == 0 || numberView == 1) { ss.X -= 150; } Canvas.SetLeft(ss.ParentEl, ss.X); listCollectionsColor[numberView].Add(ss); listCollectionElement[numberView].Add(ss.ParentEl); }); _progBarViewModel.CloseBar(); }); foreach (var vari in ListViewPortal) { if (!(vari is VMSchemeElement)) { continue; } var nameElem = _nameElement.ToList().Find(x => x == (vari as VMSchemeElement).Name); if (nameElem == null) { _nameElement.Add((vari as VMSchemeElement).Name); } var ss = new VMSchemeElement(vari as VMSchemeElement); ListViewPortalColor.Add(ss); ListViewPortalElementColor.Add(ss.ParentEl); } foreach (var vari in ListViewPlace) { if (!(vari is VMSchemeElement)) { continue; } var nameElem = _nameElement.ToList().Find(x => x == (vari as VMSchemeElement).Name); if (nameElem == null) { _nameElement.Add((vari as VMSchemeElement).Name); } var ss = new VMSchemeElement(vari as VMSchemeElement); ListViewPlaceColor.Add(ss); ListViewPlaceElementColor.Add(ss.ParentEl); } _nameElement.Remove("Заземление"); _nameElement.Remove("Площадка обслуживания"); _nameElement.Remove("Портал"); foreach (var vari in _nameElement) { dictColorElem.Add(vari, 0); } viewVMPanels.ForEach(viewVM => { var numberView = viewVMPanels.Select((item, index) => new { item, index }) .Where(ix => ix.item == viewVM) .Select(ix => ix.index) .FirstOrDefault(); viewVM.NameView = $"Карта Вида {views[numberView]}"; viewVM.ListViews = listCollectionElement[numberView]; }); _viewPanelColorPlace.NameView = "Покраска площадки"; _viewPanelColorPlace.ListViews = ListViewPlaceElementColor; _viewPanelColorPortal.NameView = "Покраска портала"; _viewPanelColorPortal.ListViews = ListViewPortalElementColor; ColorViewPortal = _panelColorPortal; ColorViewA = _panelColorA; ColorViewB = _panelColorB; ColorViewV = _panelColorV; ColorViewG = _panelColorG; //(ColorViewPlace as ViewPanel).PreviewMouseDown += ViewModel_MouseLeftButtonDown; (ColorViewA as ViewPanel).PreviewMouseDown += ViewModel_MouseLeftButtonDown; (ColorViewB as ViewPanel).PreviewMouseDown += ViewModel_MouseLeftButtonDown; (ColorViewV as ViewPanel).PreviewMouseDown += ViewModel_MouseLeftButtonDown; (ColorViewG as ViewPanel).PreviewMouseDown += ViewModel_MouseLeftButtonDown; ProgBarViewModel _progBarViewModelPaint = new ProgBarViewModel(); Application.Current.Dispatcher.Invoke((Action)(() => { _progBarViewModelPaint.ActionName = "Покраска БМЗ"; _progBarViewModelPaint.ShowBar(); })); DataClass dc = new DataClass("KontinentDBEntity.db"); Dictionary <string, int> fooDic = new Dictionary <string, int>(); if (dictColorLoad.Count != 0) { fooDic = dictColorLoad; } else { fooDic = dictDefaultColor; } fooDic .ToList() .ForEach(defaultColor => { listCollectionsColor.ForEach(listColor => { var elements = listColor.ToList() .FindAll(x => x is VMSchemeElement) .FindAll(y => (y as VMSchemeElement).Name == defaultColor.Key); if (dictColorElem.ToList().FindAll(x => x.Key == defaultColor.Key).Count > 0) { dictColorElem[defaultColor.Key] = defaultColor.Value; } ItemsColor selectColor = new ItemsColor(); DataTable dt = dc.SelectQuery($"select * from _colorRGB where nameInRAL = {defaultColor.Value}"); var sss = dt.AsEnumerable().ToList(); selectColor.Red = Convert.ToInt32(sss[0]["R"].ToString()); selectColor.Green = Convert.ToInt32(sss[0]["G"].ToString()); selectColor.Blue = Convert.ToInt32(sss[0]["B"].ToString()); elements.ForEach(element => { element.ReverseBackGround( Color.FromArgb(selectColor.Red, selectColor.Green, selectColor.Blue), AppDomain.CurrentDomain.BaseDirectory + @"\SVG\" + element.PathToImg); }); }); }); Dictionary <string, Color> colorDict = new Dictionary <string, Color>(); List <string> secretName = new List <string>(); foreach (var name in dictColorElemPlace.Keys) { if (name == "Перила") { continue; } var nameSecret = dictConnectToSVGPlace[name]; secretName.Add(nameSecret); ItemsColor selectColor = new ItemsColor(); DataTable dt = dc.SelectQuery($"select * from _colorRGB where nameInRAL = {dictColorElemPlace[name]}"); var sss = dt.AsEnumerable().ToList(); selectColor.Red = Convert.ToInt32(sss[0]["R"].ToString()); selectColor.Green = Convert.ToInt32(sss[0]["G"].ToString()); selectColor.Blue = Convert.ToInt32(sss[0]["B"].ToString()); colorDict.Add(nameSecret, Color.FromArgb(selectColor.Red, selectColor.Green, selectColor.Blue)); } var elem = ListViewPlaceColor.FirstOrDefault(); elem.ReverseBackGround(colorDict, AppDomain.CurrentDomain.BaseDirectory + @"\SVG\" + elem.PathToImg, secretName); Dictionary <string, Color> colorDictPortal = new Dictionary <string, Color>(); List <string> secretNamePortal = new List <string>(); foreach (var name in dictColorElemPortal.Keys) { var nameSecret = dictConnectToSVGPortal[name]; secretNamePortal.Add(nameSecret); ItemsColor selectColor = new ItemsColor(); DataTable dt = dc.SelectQuery($"select * from _colorRGB where nameInRAL = {dictColorElemPortal[name]}"); var sss = dt.AsEnumerable().ToList(); selectColor.Red = Convert.ToInt32(sss[0]["R"].ToString()); selectColor.Green = Convert.ToInt32(sss[0]["G"].ToString()); selectColor.Blue = Convert.ToInt32(sss[0]["B"].ToString()); colorDictPortal.Add(nameSecret, Color.FromArgb(selectColor.Red, selectColor.Green, selectColor.Blue)); } var elemPortal = ListViewPortalColor.FirstOrDefault(); elemPortal?.ReverseBackGroundPortal(colorDictPortal, AppDomain.CurrentDomain.BaseDirectory + @"\SVG\" + elemPortal.PathToImg, secretNamePortal); _progBarViewModelPaint.CloseBar(); _mainBlockViewModel.IToastNotifications.ShowSuccess($"Покрасочная карта успешно сформирована"); }