//C ГРИДОМ РАЗОБРАТЬСЯ!!!!
        public void ReorganizeGrid(bool isShowGrid)
        {
            _isShowGrid = isShowGrid;

            while (DrawningFraemworkElements.Any(x => x.GetType() == typeof(CoorGrid)))
            {
                DrawningFraemworkElements.Remove(DrawningFraemworkElements.First(x => x.GetType() == typeof(CoorGrid)));
            }

            if (isShowGrid)
            {
                DrawningFraemworkElements.Add(new CoorGrid((int)_currentGridScale / Constants.MainScale, _areaWidth, _areaHeight));
                Canvas.SetZIndex((UIElement)DrawningFraemworkElements.Last(), -40);
            }
        }
        public void AddCellArea(CellAreaData CellAreaBlock)
        {
            var listPlace = BaseDrawElements.ToList().FindAll(x => x is VMRUVNPlace);
            var allPlace  = listPlace.FindAll(x => (x as VMRUVNPlace).namePlaceFrame.ToLower().Substring(0, (x as VMRUVNPlace).namePlaceFrame.IndexOf("|")) == _placeforHide.namePlaceFrame.ToLower().Substring(0, _placeforHide.namePlaceFrame.IndexOf("|")));
            int widthCell = 0;
            int shk       = 0;

            if (CellAreaBlock.RowDataList.Count > 1)
            {
                shk = CellAreaBlock.RowDataList[1].Y - (CellAreaBlock.RowDataList[0].Y +
                                                        CellAreaBlock.CellDataList.Find(x =>
                                                                                        x.Depth == CellAreaBlock.CellDataList.Max(y => y.Depth) && x._rowNum == 2).Depth / Constants.MainScale);
                shk *= Constants.MainScale;
            }
            foreach (var vari in CellAreaBlock.CellDataList)
            {
                widthCell += vari.Width;
            }
            if (CellAreaBlock.RowDataList.Count < allPlace.Count)
            {
                IToastNotifications.ShowError(
                    "Вы загружаете однорядную конфигурацию в компоновку с двурядным расположением оборудования!");
                return;
            }
            if (CellAreaBlock.RowDataList.Count > allPlace.Count)
            {
                IToastNotifications.ShowError(
                    "Вы загружаете двурядную конфигурацию в компоновку с однорядным расположением оборудования!");
                return;
            }

            //if (shk > 0)
            //{
            //    if (shk < MyBMZ.InformationForBuild.Shkn)
            //    {
            //            IToastNotifications.ShowError(
            //                "Ширина корридора в конфигурации меньше ширины корридора в компоновке");
            //            return;
            //    }
            //}

            double widthPlace = 0;

            foreach (var vari in allPlace)
            {
                widthPlace += vari.Width;
            }
            if (CellAreaBlock.AreaType == AreaType.HighVoltage)
            {
                if (_placeforHide.RoomType == RoomType.HighVoltage)
                {
                    if ((widthCell > widthPlace * Constants.MainScale) || (CellAreaBlock.CellDataList[0].Depth > _placeforHide.Height * Constants.MainScale))
                    {
                        LoadDialog(widthCell, CellAreaBlock.CellDataList[0].Depth);
                        return;
                    }
                    else
                    {
                        var place    = allPlace.Find(x => x.Y == allPlace.Min(z => z.Y));
                        int allWidth = 0;
                        foreach (var vari in CellAreaBlock.RowDataList)
                        {
                            allWidth += vari.Width;
                        }
                        if (allWidth == place.Width)
                        {
                            CellAreaBlock.X = (int)place.X;
                        }
                        else
                        {
                            if (_placeforHide.Rotation == Rotation.D0)
                            {
                                CellAreaBlock.X = (int)place.X + ((int)place.Width - allWidth) / 2;
                            }
                            else
                            {
                                CellAreaBlock.X = (int)place.X;
                            }
                        }
                        if (CellAreaBlock.RowDataList[0].Height == place.Height)
                        {
                            CellAreaBlock.Y = (int)place.Y;
                        }
                        else
                        {
                            CellAreaBlock.Y = (int)place.Y + ((int)place.Height - CellAreaBlock.RowDataList[0].Height) / 2;
                        }
                        Rotation rotata     = Rotation.D0;
                        Rotation rotataText = Rotation.D0;
                        if (_placeforHide.FacadePlace != Facade.NA)
                        {
                            if (_placeforHide.FacadePlace != CellAreaBlock.CellDataList[0].Facade)
                            {
                                rotata     = Rotation.D180;
                                rotataText = Rotation.D180;
                            }
                        }

                        if (_placeforHide.Rotation == Rotation.D90 || _placeforHide.Rotation == Rotation.D270)
                        {
                            rotata     = Rotation.D90;
                            rotataText = Rotation.D270;
                        }

                        if (allPlace.Count > 1)
                        {
                            if ((allPlace[0].X != allPlace[1].X) && ((allPlace[0].Y != allPlace[1].Y)))
                            {
                                ;//TODO
                            }
                        }

                        var aCell = new PVMCell(this, CellAreaBlock, CellAreaBlock.X, CellAreaBlock.Y, rotata, rotataText, AreaType.HighVoltage, widthCell);
                        BaseDrawElements.Add(aCell);
                        foreach (var vari in allPlace)
                        {
                            (vari as VMRUVNPlace).Visibility = Visibility.Collapsed;
                            (vari as VMRUVNPlace).idmyCell   = aCell.idCell;
                        }
                        Canvas.SetZIndex((CellAreaBlock)DrawningFraemworkElements.Last(), 1000);
                        IToastNotifications.ShowSuccess("Конфигурация РУВН успешно загружена");
                    }
                }
            }

            if (CellAreaBlock.AreaType == AreaType.LowVoltage)
            {
                if (_placeforHide.RoomType == RoomType.LowVoltage)
                {
                    if ((widthCell > widthPlace * Constants.MainScale) ||
                        (CellAreaBlock.CellDataList[0].Depth > _placeforHide.Height * Constants.MainScale))
                    {
                        LoadDialog(widthCell, CellAreaBlock.CellDataList[0].Depth);
                        return;
                    }
                    else
                    {
                        var place    = allPlace.Find(x => x.Y == allPlace.Min(z => z.Y));
                        int allWidth = 0;
                        foreach (var vari in CellAreaBlock.RowDataList)
                        {
                            allWidth += vari.Width;
                        }
                        if (allWidth == place.Width)
                        {
                            CellAreaBlock.X = (int)place.X;
                        }
                        else
                        {
                            if (_placeforHide.Rotation == Rotation.D0)
                            {
                                CellAreaBlock.X = (int)place.X + ((int)place.Width - allWidth) / 2;
                            }
                            else
                            {
                                CellAreaBlock.X = (int)place.X;
                            }
                        }
                        if (CellAreaBlock.RowDataList[0].Height == place.Height)
                        {
                            CellAreaBlock.Y = (int)place.Y;
                        }
                        else
                        {
                            CellAreaBlock.Y = (int)place.Y + ((int)place.Height - CellAreaBlock.RowDataList[0].Height) / 2;
                        }

                        Rotation rotata     = Rotation.D0;
                        Rotation rotataText = Rotation.D0;
                        if (_placeforHide.FacadePlace != Facade.NA)
                        {
                            if (_placeforHide.FacadePlace != CellAreaBlock.CellDataList[0].Facade)
                            {
                                rotata = Rotation.D180;
                                //rotataText = Rotation.D180;
                            }
                        }

                        if (_placeforHide.Rotation == Rotation.D90 || _placeforHide.Rotation == Rotation.D270)
                        {
                            rotata = Rotation.D90;
                            //rotataText = Rotation.D270;
                        }

                        var aCell = new PVMCell(this, CellAreaBlock, CellAreaBlock.X, CellAreaBlock.Y, rotata, rotataText, AreaType.LowVoltage, widthCell);

                        BaseDrawElements.Add(aCell);
                        foreach (var pl in allPlace)
                        {
                            (pl as VMRUVNPlace).Visibility = Visibility.Collapsed;
                            (pl as VMRUVNPlace).idmyCell   = aCell.idCell;
                        }

                        Canvas.SetZIndex((CellAreaBlock)DrawningFraemworkElements.Last(), 1000);
                        IToastNotifications.ShowSuccess("Конфигурация РУНН успешно загружена");
                        //var lst = MyBMZ.CollectFrame.ToList();
                        //var ss = lst.Find(x => x.position.ToLower() == placeforHide.namePlaceFrame.ToLower().Substring(0, placeforHide.namePlaceFrame.IndexOf("|")).Trim());
                        //if (MyBMZ.elementFloor == null)
                        //    MyBMZ.elementFloor = new SortedList<string, List<int>>();
                        //if (MyBMZ.elementFloor.ContainsKey(ss.position))
                        //    MyBMZ.elementFloor.Remove(ss.position);
                        //MyBMZ.elementFloor.Add(ss.position, (ListElem.FindLast(x => x is pVMCell) as pVMCell).elementFloor);

                        //DataClass dc = new DataClass("KontinentDBEntity.db");
                        //var frameIndex = MyBMZ.CollectFrame.ToList().FindIndex(x => x.position == ss.position);
                        //var bmzArray = MyBMZ.CollectFrame.ToArray();
                        //DataTable dt = dc.SelectQuery($"select nameCarc from _carcas where countElementFloor = {(ListElem.FindLast(x => x is pVMCell) as pVMCell).elementFloor.Count} AND countTrans = {bmzArray[frameIndex].countTrans}");
                        //var ss2 = dt.AsEnumerable().ToList();
                        //if (ss2.Count == 0)
                        //    IToastNotifications.ShowError("Подходящий каркас не найден");
                        //else
                        //{
                        //    bmzArray[frameIndex].nameCarcas = ss2[0][0].ToString();
                        //    MyBMZ.CollectFrame = new ObservableCollection<ClassCompositeBMZ.Frame>(bmzArray.ToList());
                        //}
                    }
                }
            }

            var lst = MyBMZ.CollectFrame.ToList();
            var ss  = lst.Find(x => x.position.ToLower() == _placeforHide.namePlaceFrame.ToLower().Substring(0, _placeforHide.namePlaceFrame.IndexOf("|")).Trim());

            if (MyBMZ.elementFloor == null)
            {
                MyBMZ.elementFloor = new SortedList <string, List <int> >();
            }
            if (MyBMZ.elementFloor.ContainsKey(ss.position))
            {
                MyBMZ.elementFloor.Remove(ss.position);
            }
            MyBMZ.elementFloor.Add(ss.position, (BaseDrawElements.ToList().FindLast(x => x is PVMCell) as PVMCell).elementFloor);

            DataClass dc         = new DataClass("KontinentDBEntity.db");
            var       frameIndex = MyBMZ.CollectFrame.ToList().FindIndex(x => x.position == ss.position);
            var       bmzArray   = MyBMZ.CollectFrame.ToArray();
            DataTable dt         = dc.SelectQuery($"select nameCarc from _carcas where countElementFloor = {(BaseDrawElements.ToList().FindLast(x => x is PVMCell) as PVMCell).elementFloor.Count} AND countTrans = {bmzArray[frameIndex].countTrans}");
            var       ss2        = dt.AsEnumerable().ToList();

            if (ss2.Count == 0)
            {
                IToastNotifications.ShowError("Подходящий каркас не найден");
            }
            else
            {
                bmzArray[frameIndex].nameCarcas = ss2[0][0].ToString();
                MyBMZ.CollectFrame = new ObservableCollection <ClassCompositeBMZ.Frame>(bmzArray.ToList());
            }
        }