public void RightRoll()
        {
            var listBase = DrawningFraemworkElements.ToList().FindAll(x => (x.DataContext is BaseDrawClass));

            if (listBase.Count > 0)
            {
                foreach (var var in listBase)
                {
                    if ((var.DataContext as BaseDrawClass).IsSelected)
                    {
                        (var.DataContext as BaseDrawClass).PositiveRotation();
                    }
                }
            }
            var listBaseCell = DrawningFraemworkElements.ToList().FindAll(x => (x.DataContext is CellAreaBlock));

            if (listBaseCell.Count > 0)
            {
                foreach (var vari in listBaseCell)
                {
                    if ((vari.DataContext as CellAreaBlock).IsSelected)
                    {
                        (vari.DataContext as CellAreaBlock).RotationRight();
                    }
                }
            }
        }
 private void LoadWorkspace()
 {
     _workspace = new UserControl {
         Content = new Workspace(this, AreaWidth, AreaHeight)
     };
     DrawningFraemworkElements.Add(_workspace);
     _workspace.PreviewDrop += Workspace_PreviewDrop;
     Canvas.SetZIndex(_workspace, -20);
 }
        //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());
            }
        }
        private void LoadDialog(double width, double depth)
        {
            var dw = new DialogWindow(
                "Загруженная конфигурация не подходит по размерам к шаблону. Попробуйте загрузить другую конфигурация или выбрать подходящий шаблон",
                "Неподходящий шаблон");

            if (dw.ShowDialog() != true)
            {
                switch (dw.GetSelection())
                {
                case Selection.None:
                    IToastNotifications.ShowError("Конфигурация не загружена");
                    break;
                }
            }


            switch (dw.GetSelection())
            {
            case Selection.LoadConfig:
                if (_roomType == RoomType.HighVoltage)
                {
                    FileLoad(Handler.RUVN, null);
                    MainDataParsing(_iCommonData.RUVN_GetCommonData(), AreaType.HighVoltage);
                }

                if (_roomType == RoomType.LowVoltage)
                {
                    FileLoad(Handler.RUNN, null);
                    MainDataParsing(_iCommonData.RUNN_GetCommonData(), AreaType.LowVoltage);
                }

                break;

            case Selection.ResizeComposite:
            {
                if (_roomType == RoomType.HighVoltage)
                {
                    List <ClassCompositeBMZ> lst = GetInformBMZ.GetList();
                    var listCell  = DrawningFraemworkElements.ToList().FindAll(x => x is CellAreaBlock);
                    var blockcell = listCell.Find(x =>
                                                  (x as CellAreaBlock)._cellAreaData.AreaType == AreaType.LowVoltage);
                    if (blockcell == null)
                    {
                        var lstf = lst.FindAll(x => (x.idBMZ == MyBMZ.idBMZ) &&
                                               (x.InformationForBuild.Gv1 == depth) &&
                                               (x.InformationForBuild.Dv1 + x.InformationForBuild.Dv2 > width));
                        if (lstf.Count != 0)
                        {
                            Mouse.OverrideCursor       = Cursors.Wait;
                            lstf[0].dOneSQuestParametr = GetInformBMZ.SelectBMZ().dOneSQuestParametr;
                            lstf[0].elementFloor       = MyBMZ.elementFloor;
                            lstf[0].schemeRUVN         = MyBMZ.schemeRUVN;
                            lstf[0].schemeRUNN         = MyBMZ.schemeRUNN;
                            GetInformBMZ.GetSelectBMZ(lstf[0]);
                            BuildBMZ(GetInformBMZ.SelectBMZ());
                            var listPlace       = BaseDrawElements.ToList().FindAll(x => x is VMRUVNPlace);
                            var placeforHidesht = listPlace.Find(x =>
                                                                 string.Equals((x as VMRUVNPlace).namePlaceFrame, _placeforHide.namePlaceFrame, System.StringComparison.OrdinalIgnoreCase));
                            _placeforHide = (VMRUVNPlace)placeforHidesht;
                            MainDataParsing(_iCommonData.RUVN_GetCommonData(), AreaType.HighVoltage);
                            Mouse.OverrideCursor = null;
                        }
                        else
                        {
                            DialogAfterNoFind();
                        }
                    }
                    else
                    {
                        var places = DrawningFraemworkElements.ToList().FindAll(x => x is CellAreaBlock);
                        var place  = places.Find(x =>
                                                 (x as CellAreaBlock)._cellAreaData.AreaType == AreaType.LowVoltage);
                        var goodLst   = BaseDrawElements.ToList().FindAll(x => x is PVMCell);
                        var goodCells = goodLst.Find(x => (x as PVMCell).type == AreaType.LowVoltage);



                        var lstf = lst.FindAll(x => (x.idBMZ == MyBMZ.idBMZ) &&
                                               (x.InformationForBuild.Gv1 == depth) &&
                                               (x.InformationForBuild.Dv1 + x.InformationForBuild.Dv2 > width) &&
                                               (x.InformationForBuild.Gn1 > (place as CellAreaBlock)._cellAreaData.Height) &&
                                               (x.InformationForBuild.Dn1 + x.InformationForBuild.Dn2 > (goodCells as PVMCell).WidthAllCell));
                        if (lstf.Count != 0)
                        {
                            Mouse.OverrideCursor       = Cursors.Wait;
                            lstf[0].dOneSQuestParametr = GetInformBMZ.SelectBMZ().dOneSQuestParametr;
                            lstf[0].schemeRUVN         = MyBMZ.schemeRUVN;
                            lstf[0].schemeRUNN         = MyBMZ.schemeRUNN;
                            GetInformBMZ.GetSelectBMZ(lstf[0]);
                            BuildBMZ(GetInformBMZ.SelectBMZ());
                            var listPlace       = BaseDrawElements.ToList().FindAll(x => x is VMRUVNPlace);
                            var placeforHidesht = listPlace.Find(x =>
                                                                 string.Equals((x as VMRUVNPlace).namePlaceFrame, _placeforHide.namePlaceFrame, System.StringComparison.OrdinalIgnoreCase));
                            _placeforHide = (VMRUVNPlace)placeforHidesht;
                            MainDataParsing(_iCommonData.RUVN_GetCommonData(), AreaType.HighVoltage);
                            Mouse.OverrideCursor = null;
                        }
                        else
                        {
                            DialogAfterNoFind();
                        }
                    }
                }

                if (_roomType == RoomType.LowVoltage)
                {
                    List <ClassCompositeBMZ> lst = GetInformBMZ.GetList();
                    var listCell  = DrawningFraemworkElements.ToList().FindAll(x => x is CellAreaBlock);
                    var blockcell = listCell.Find(x =>
                                                  (x as CellAreaBlock)._cellAreaData.AreaType == AreaType.HighVoltage);
                    if (blockcell == null)
                    {
                        var lstf = lst.FindAll(x => (x.idBMZ == MyBMZ.idBMZ) &&
                                               (x.InformationForBuild.Gn1 == depth) &&
                                               (x.InformationForBuild.Dn1 + x.InformationForBuild.Dn2 >
                                                width));
                        if (lstf.Count != 0)
                        {
                            Mouse.OverrideCursor       = Cursors.Wait;
                            lstf[0].dOneSQuestParametr = GetInformBMZ.SelectBMZ().dOneSQuestParametr;
                            lstf[0].schemeRUVN         = MyBMZ.schemeRUVN;
                            lstf[0].schemeRUNN         = MyBMZ.schemeRUNN;
                            lstf[0].elementFloor       = MyBMZ.elementFloor;
                            GetInformBMZ.GetSelectBMZ(lstf[0]);
                            BuildBMZ(GetInformBMZ.SelectBMZ());
                            var listPlace       = BaseDrawElements.ToList().FindAll(x => x is VMRUVNPlace);
                            var placeforHidesht = listPlace.Find(x =>
                                                                 string.Equals((x as VMRUVNPlace).namePlaceFrame, _placeforHide.namePlaceFrame, System.StringComparison.OrdinalIgnoreCase));
                            _placeforHide = (VMRUVNPlace)placeforHidesht;
                            MainDataParsing(_iCommonData.RUNN_GetCommonData(), AreaType.LowVoltage);
                            Mouse.OverrideCursor = null;
                        }
                        else
                        {
                            DialogAfterNoFind();
                        }
                    }
                    else
                    {
                        var places = DrawningFraemworkElements.ToList().FindAll(x => x is CellAreaBlock);
                        var place  = places.Find(x =>
                                                 (x as CellAreaBlock)._cellAreaData.AreaType == AreaType.HighVoltage);

                        var goodLst   = BaseDrawElements.ToList().FindAll(x => x is PVMCell);
                        var goodCells = goodLst.Find(x => (x as PVMCell).type == AreaType.HighVoltage);
                        var lstf      = lst.FindAll(x => (x.idBMZ == MyBMZ.idBMZ) &&
                                                    (x.InformationForBuild.Gn1 == depth) &&
                                                    (x.InformationForBuild.Dn1 + x.InformationForBuild.Dn2 >
                                                     width) &&
                                                    (x.InformationForBuild.Gv1 > (place as CellAreaBlock)._cellAreaData.Height) &&
                                                    (x.InformationForBuild.Dv1 + x.InformationForBuild.Dv2 > (goodCells as PVMCell).WidthAllCell));
                        if (lstf.Count != 0)
                        {
                            Mouse.OverrideCursor       = Cursors.Wait;
                            lstf[0].dOneSQuestParametr = GetInformBMZ.SelectBMZ().dOneSQuestParametr;
                            lstf[0].schemeRUVN         = MyBMZ.schemeRUVN;
                            lstf[0].schemeRUNN         = MyBMZ.schemeRUNN;
                            lstf[0].elementFloor       = MyBMZ.elementFloor;
                            GetInformBMZ.GetSelectBMZ(lstf[0]);
                            BuildBMZ(GetInformBMZ.SelectBMZ());
                            var listPlace       = BaseDrawElements.ToList().FindAll(x => x is VMRUVNPlace);
                            var placeforHidesht = listPlace.Find(x =>
                                                                 string.Equals((x as VMRUVNPlace).namePlaceFrame, _placeforHide.namePlaceFrame, System.StringComparison.OrdinalIgnoreCase));
                            _placeforHide = (VMRUVNPlace)placeforHidesht;
                            MainDataParsing(_iCommonData.RUNN_GetCommonData(), AreaType.LowVoltage);
                            Mouse.OverrideCursor = null;
                        }
                        else
                        {
                            DialogAfterNoFind();
                        }
                    }
                }
            }
            break;

            case Selection.RebuildConfig:

                if (_roomType == RoomType.HighVoltage)
                {
                    StartMaster(Handler.RUVN, AreaType.HighVoltage,
                                (int)_iCommonData.RUVN_GetCommonData().ProductType,
                                _iCommonData.RUVN_GetCommonData().FilePath);
                }
                if (_roomType == RoomType.LowVoltage)
                {
                    StartMaster(Handler.RUNN, AreaType.LowVoltage,
                                (int)_iCommonData.RUNN_GetCommonData().ProductType,
                                _iCommonData.RUNN_GetCommonData().FilePath);
                }
                return;

            case Selection.None:
                IToastNotifications.ShowError("Конфигурация не загружена");
                break;
            }
        }