public void ClearCellArea(PVMCell cell)
        {
            var findPlace  = BaseDrawElements.ToList().FindAll(x => (x is VMRUVNPlace));
            var allMyPlace = findPlace.FindAll(x => (x as VMRUVNPlace).idmyCell == cell.idCell);

            foreach (var vari in allMyPlace)
            {
                (vari as VMRUVNPlace).Visibility = Visibility.Visible;
                _placeforHide = vari as VMRUVNPlace;
            }
            cell.Delete();
        }
예제 #2
0
        public void EditMak(CommonData cd, PVMCell cellForPlace, int width, int height)
        {
            if (cd is null)
            {
                throw new System.ArgumentNullException(nameof(cd));
            }

            CreateNullCell createNullCell    = new CreateNullCell();
            var            vmCreateNullCells = createNullCell.DataContext as VMCreateNullCells;

            if (cellForPlace.type == AreaType.HighVoltage)
            {
                vmCreateNullCells.SetCommonData(cellForPlace._ruvnData);
                vmCreateNullCells.SetCorSize(SelectBMZ.InformationForBuild.Shkv);
                if (cellForPlace._ruvnData.MainData.RowDataList.Count == 1)
                {
                    vmCreateNullCells.SetSettingsWorkspace(width, height);
                }
                else
                {
                    vmCreateNullCells.SetSettingsWorkspace(width, height * 2 + SelectBMZ.InformationForBuild.Shkv / Constants.MainScale);
                    vmCreateNullCells.SetSecondRows(true);
                }
            }
            else
            {
                vmCreateNullCells.SetCommonData(cellForPlace._runnData);
                vmCreateNullCells.SetCorSize(SelectBMZ.InformationForBuild.Shmn);
                if (cellForPlace._runnData.MainData.RowDataList.Count == 1)
                {
                    vmCreateNullCells.SetSettingsWorkspace(width, height);
                }
                else
                {
                    vmCreateNullCells.SetSettingsWorkspace(width, height * 2 + SelectBMZ.InformationForBuild.Shmn / Constants.MainScale);
                    vmCreateNullCells.SetSecondRows(true);
                }
            }

            vmCreateNullCells.SetQuant(vmCreateNullCells._VMMainBlock.CellsDataList.Count > 0 ? vmCreateNullCells._VMMainBlock.CellsDataList.Count : 1);
            createNullCell.ShowDialog();
            if (vmCreateNullCells.IsSucess == false)
            {
                return;
            }
            createNullCell.Close();
            if (vmCreateNullCells.IsSucess == false)
            {
                return;
            }
            var md = vmCreateNullCells.GetMainData();

            if (vmCreateNullCells._VMMainBlock.CellsDataList.Count > 0)
            {
                var finderLink = _mainBlockViewModel.BaseDrawElements.ToList().FindAll(x => (x is VMLink)).Find(x => (x as VMLink).elemId == cellForPlace.ElementId);
                _mainBlockViewModel.BaseDrawElements.Remove(cellForPlace.myLink);

                _mainBlockViewModel.DrawningFraemworkElements.Remove(finderLink.ParentEl);
                _mainBlockViewModel.BaseDrawElements.Remove(cellForPlace);
                _mainBlockViewModel.DrawningFraemworkElements.Remove(cellForPlace.ParentEl);

                _mainBlockViewModel.MainDataParsing(new CommonData()
                {
                    ProductType = ProductType.Untyped, MainData = md
                }, cellForPlace.type);
                if (cellForPlace.type == AreaType.HighVoltage)
                {
                    _mainBlockViewModel.ICommonData.RUVN_SetCommonData(new CommonData()
                    {
                        ProductType = ProductType.Untyped, MainData = md
                    });
                }
                else
                {
                    _mainBlockViewModel.ICommonData.RUNN_SetCommonData(new CommonData()
                    {
                        ProductType = ProductType.Untyped, MainData = md
                    });
                }
            }
        }
        public void StartMaster(Handler handler, AreaType areaType, int code, string path, PVMCell cell = null)
        {
            ProgBarViewModel progBarViewModel = new ProgBarViewModel();

            var thread = new Thread(delegate()
            {
                var masterPath = Regedit.GetString("HKEY_CURRENT_USER\\Software\\Elektrum\\Master\\" + code,
                                                   "StartupPath", "");

                if (!File.Exists(path))
                {
                    Wrapper.ShowNotify("Не удалось найти файл конфигурации изделия по адресу " + path,
                                       Constants.AppName);
                    return;
                }

                if (!File.Exists(masterPath))
                {
                    Wrapper.ShowNotify("Не удалось найти конфигуратор для изделия с кодом " + code, Constants.AppName);
                    return;
                }

                Application.Current.Dispatcher.Invoke((Action)(() =>
                {
                    progBarViewModel.ActionName = "Выполняется конфигурация изделия...";
                    progBarViewModel.ShowBar();
                }));

                var lastWriteTime = File.GetLastWriteTime(path);
                var process       = Process.Start(masterPath, $" -type {code} -from \"{path}\"");
                process.WaitForExit();

                Application.Current.Dispatcher.Invoke((Action)(() => { progBarViewModel.CloseBar(); }));

                if (lastWriteTime != File.GetLastWriteTime(path))
                {
                    _iToastNotifications.ShowSuccess("Файл конфигурации был обновлен");

                    Application.Current.Dispatcher.Invoke((Action)(() =>
                    {
                        FileLoad(handler, path);
                        if (cell != null)
                        {
                            ClearCellArea(cell);
                        }
                        MainDataParsing(handler == Handler.RUVN
                            ? _iCommonData.RUVN_GetCommonData()
                            : _iCommonData.RUNN_GetCommonData(), areaType);
                    }));
                }
            })
            {
                IsBackground = true
            };

            thread.Start();
        }
        public void CellAreaContextMenu(PVMCell cell)
        {
            if (!(_selectedBlock is CellAreaBlock))
            {
                return;
            }

            var contextMenu = new ContextMenu();

            var showObjectInfoMenu = new MenuItem {
                Header = "Просмотреть информацию об объекте"
            };

            var showUserInfoMenu = new MenuItem {
                Header = "Просмотреть информацию о пользователях"
            };

            var showFillDateMenu = new MenuItem {
                Header = "Просмотреть дату заполнения"
            };

            var startMasterMenu = new MenuItem();
            var loadFileMenu    = new MenuItem();
            var unloadFileMenu  = new MenuItem();

            if (((CellAreaBlock)_selectedBlock).CellAreaData.AreaType == AreaType.HighVoltage)
            {
                if (_iCommonData.RUVN_GetCommonData().ProductType == ProductType.Untyped)
                {
                    startMasterMenu.Header = $"Редактировать макет";
                    var           findPlace  = BaseDrawElements.ToList().FindAll(x => (x is VMRUVNPlace));
                    BaseDrawClass allMyPlace = findPlace.Find(x => (x as VMRUVNPlace).idmyCell == cell.idCell); //ТОЛЬКО ОДНОРЯДКИ!!!!!!!!!!!!!
                    _placeforHide          = allMyPlace as VMRUVNPlace;
                    startMasterMenu.Click += delegate { EditMaket(_iCommonData.RUVN_GetCommonData(), cell, (int)allMyPlace.Width, (int)allMyPlace.Height); };
                    loadFileMenu.Header    = "Сменить на конфигурацию";
                    loadFileMenu.Click    += delegate
                    {
                        if (!FileLoad(Handler.RUVN, null))
                        {
                            return;
                        }
                        ClearCellArea(cell);
                        MainDataParsing(_iCommonData.RUVN_GetCommonData(), AreaType.HighVoltage);
                    };
                }
                else
                {
                    loadFileMenu.Header = "Сменить конфигурацию";
                    loadFileMenu.Click += delegate
                    {
                        if (!FileLoad(Handler.RUVN, null))
                        {
                            return;
                        }
                        ClearCellArea(cell);
                        MainDataParsing(_iCommonData.RUVN_GetCommonData(), AreaType.HighVoltage);
                    };
                    showObjectInfoMenu.Click += delegate
                    {
                        Wrapper.ShowNotify($"Запрос: { _iCommonData.RUVN_GetCommonData().ObjectRequest }" +
                                           $"\nНаименование: { _iCommonData.RUVN_GetCommonData().ObjectTitle }" +
                                           $"\nОбъект: { _iCommonData.RUVN_GetCommonData().ObjectInfo }", Constants.AppName);
                    };
                    showUserInfoMenu.Click += delegate
                    {
                        Wrapper.ShowNotify($"Разработал: { _iCommonData.RUVN_GetCommonData().Developer }" +
                                           $"\nУтвердил: { _iCommonData.RUVN_GetCommonData().Approver }", Constants.AppName);
                    };
                    showFillDateMenu.Click += delegate
                    {
                        Wrapper.ShowNotify($"Дата заполнения: { _iCommonData.RUVN_GetCommonData().FillDate }", Constants.AppName);
                    };
                    startMasterMenu.Header = $"Редактировать в {Constants.RUVN_AppName}";
                    startMasterMenu.Click += delegate
                    {
                        StartMaster(Handler.RUVN, AreaType.HighVoltage,
                                    (int)_iCommonData.RUVN_GetCommonData().ProductType,
                                    _iCommonData.RUVN_GetCommonData().FilePath, cell);
                    };
                }

                unloadFileMenu.Header = "Выгрузить конфигурацию";
                unloadFileMenu.Click += delegate { MyBMZ.schemeRUVN = "";  _iCommonData.RUVN_SetCommonData(null); ClearCellArea(cell); ReDrawSubstation(); };
                if (_iCommonData.RUVN_GetCommonData().ProductType != ProductType.Untyped)
                {
                    contextMenu.Items.Add(showObjectInfoMenu);
                    contextMenu.Items.Add(showUserInfoMenu);
                    contextMenu.Items.Add(showFillDateMenu);
                    contextMenu.Items.Add(new Separator());
                }
            }

            if (((CellAreaBlock)_selectedBlock).CellAreaData.AreaType == AreaType.LowVoltage)
            {
                showObjectInfoMenu.Click += delegate
                {
                    Wrapper.ShowNotify($"Запрос: {_iCommonData.RUNN_GetCommonData().ObjectRequest}" +
                                       $"\nНаименование: {_iCommonData.RUNN_GetCommonData().ObjectTitle}" +
                                       $"\nОбъект: {_iCommonData.RUNN_GetCommonData().ObjectInfo}", Constants.AppName);
                };

                showUserInfoMenu.Click += delegate
                {
                    Wrapper.ShowNotify($"Разработал: {_iCommonData.RUNN_GetCommonData().Developer}" +
                                       $"\nУтвердил: {_iCommonData.RUNN_GetCommonData().Approver}", Constants.AppName);
                };

                showFillDateMenu.Click += delegate
                {
                    Wrapper.ShowNotify($"Дата заполнения: {_iCommonData.RUNN_GetCommonData().FillDate}",
                                       Constants.AppName);
                };
                if (_iCommonData.RUNN_GetCommonData().ProductType == ProductType.Untyped)
                {
                    startMasterMenu.Header = $"Редактировать макет";

                    var findPlace  = BaseDrawElements.ToList().FindAll(x => (x is VMRUVNPlace));
                    var allMyPlace = findPlace.Find(x => (x as VMRUVNPlace).idmyCell == cell.idCell); //ТОЛЬКО ОДНОРЯДКИ!!!!!!!!!!!!!
                    startMasterMenu.Click += delegate { EditMaket(_iCommonData.RUNN_GetCommonData(), cell, (int)allMyPlace.Width, (int)allMyPlace.Height); };
                    loadFileMenu.Header    = "Сменить на конфигурацию";
                    loadFileMenu.Click    += delegate
                    {
                        FileLoad(Handler.RUNN, null);
                        ClearCellArea(cell);
                        MainDataParsing(_iCommonData.RUNN_GetCommonData(), AreaType.LowVoltage);
                    };
                }
                else
                {
                    loadFileMenu.Header = "Сменить конфигурацию";
                    loadFileMenu.Click += delegate
                    {
                        FileLoad(Handler.RUNN, null);
                        ClearCellArea(cell);
                        MainDataParsing(_iCommonData.RUNN_GetCommonData(), AreaType.LowVoltage);
                    };
                    startMasterMenu.Header = $"Редактировать в {Constants.RUNN_AppName}";
                    startMasterMenu.Click += delegate
                    {
                        StartMaster(Handler.RUNN, AreaType.LowVoltage,
                                    (int)_iCommonData.RUNN_GetCommonData().ProductType,
                                    _iCommonData.RUNN_GetCommonData().FilePath, cell);
                    };
                }



                unloadFileMenu.Header = "Выгрузить конфигурацию";

                unloadFileMenu.Click += delegate
                {
                    MyBMZ.schemeRUNN = "";
                    _iCommonData.RUNN_SetCommonData(null);
                    ClearCellArea(cell);
                    ReDrawSubstation();
                };


                if (_iCommonData.RUNN_GetCommonData().ProductType != ProductType.Untyped)
                {
                    contextMenu.Items.Add(showObjectInfoMenu);
                    contextMenu.Items.Add(showUserInfoMenu);
                    contextMenu.Items.Add(showFillDateMenu);
                    contextMenu.Items.Add(new Separator());
                }
            }

            contextMenu.Items.Add(startMasterMenu);
            contextMenu.Items.Add(loadFileMenu);
            contextMenu.Items.Add(unloadFileMenu);
            contextMenu.IsOpen = true;
        }
        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());
            }
        }