private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            allLines   = new List <LineMapEntity>();
            visitedmap = resetVisitedMap();
            subs       = Deserializer.DeserializeSubs();
            translateSubs();
            translateNodes();
            translateSwitch();
            double xy = 5.2;

            int x = -2;
            int y = -2;

            SolidColorBrush mySolidColorBrush = new SolidColorBrush();

            for (int i = 0; i < 301; i++)
            {
                for (int j = 0; j < 301; j++)
                {
                    /*
                     * ellipses[i, j] = new Ellipse();
                     * ellipses[i, j].Visibility = Visibility.Collapsed;
                     * //ellipses[i, j].Visibility = Visibility.Visible;
                     * ellipses[i, j].Fill = Brushes.Red;
                     * ellipses[i, j].Stroke = Brushes.Red;
                     * ellipses[i, j].Width = 4;
                     * ellipses[i, j].Height = 4;
                     * Canvas.SetTop(ellipses[i, j], y);
                     * Canvas.SetLeft(ellipses[i, j], x);
                     * x = x + 6;
                     * map.Children.Add(ellipses[i,j]);
                     */
                    ellipsesBool[i, j] = new GraphNode();
                }
            }
            map.LayoutTransform = st;

            addDots();
            AddLines();

            /*myEllipse.Visibility = Visibility.Visible;
             * myEllipse.Fill = Brushes.Red;
             * myEllipse.StrokeThickness = 1;
             * myEllipse.Stroke = Brushes.Red;
             * myEllipse.Width = 8;
             * myEllipse.Height = 8;
             * myEllipse.ToolTip = "Ovo je tool tip";
             * Canvas.SetTop(myEllipse, -3);
             * Canvas.SetLeft(myEllipse, -3);
             * Canvas.Children.Add(myEllipse);
             */
        }
Exemple #2
0
        public override void AddReference(ModelCode referenceId, long globalId)
        {
            switch (referenceId)
            {
            case ModelCode.SUBSTATION_SUBREGION:
                Substations.Add(globalId);
                break;

            default:
                base.AddReference(referenceId, globalId);
                break;
            }
        }
Exemple #3
0
 public void AppendTransmissionLines(NetworkModel model)
 {
     foreach (TransmissionLine transmissionLine in model.TransmissionLines)
     {
         if (Substations.Contains(transmissionLine.FromSubstation))
         {
             if (!TransmissionLines.Contains(transmissionLine))
             {
                 TransmissionLines.Add(transmissionLine);
             }
         }
     }
 }
Exemple #4
0
 public TransmissionLine ConnectingLineBetween(ObservableIsland island, NetworkModel model)
 {
     foreach (TransmissionLine transmissionLine in model.TransmissionLines)
     {
         if (Substations.Contains(transmissionLine.FromSubstation) && island.Substations.Contains(transmissionLine.ToSubstation))
         {
             return(transmissionLine);
         }
         else if (island.Substations.Contains(transmissionLine.ToSubstation) && Substations.Contains(transmissionLine.ToSubstation))
         {
             return(transmissionLine);
         }
     }
     return(null);
 }
        private void LoadSubstations(Substations substations)
        {
            substations.SubstationEntity.ForEach(e =>
            {
                GridPoint point = new GridPoint()
                {
                    Id   = e.Id,
                    X    = e.X,
                    Y    = e.Y,
                    Name = e.Name,
                    Type = GridPointType.Substation
                };

                Points.Add(point);
            });
        }
Exemple #6
0
 public void AppendTransmissionLinesAtVoltageLevel(NetworkModel model, VoltageLevel baseKv)
 {
     foreach (TransmissionLine transmissionLine in model.TransmissionLines)
     {
         if (transmissionLine.FromNode.BaseKV.InternalID == baseKv.InternalID)
         {
             if (Substations.Contains(transmissionLine.FromSubstation))
             {
                 if (!TransmissionLines.Contains(transmissionLine))
                 {
                     TransmissionLines.Add(transmissionLine);
                 }
             }
         }
     }
 }
Exemple #7
0
        public override void GetReferences(Dictionary <ModelCode, List <long> > references, TypeOfReference refType)
        {
            if (Substations != null && Substations.Count > 0 &&
                (refType == TypeOfReference.Target || refType == TypeOfReference.Both))
            {
                references[ModelCode.SUBREGION_SUBSTATIONS] = Substations.GetRange(0, Substations.Count);
            }


            if (Region != 0 && (refType != TypeOfReference.Reference || refType != TypeOfReference.Both))
            {
                references[ModelCode.SUBREGION_REGION] = new List <long>();
                references[ModelCode.SUBREGION_REGION].Add(Region);
            }

            base.GetReferences(references, refType);
        }
Exemple #8
0
        //substation
        public List <Substations> ListSubstation()
        {
            var         list = new List <Substations>();
            Substations obj;

            for (int i = 0; i <= 3; i++)
            {
                obj = new Substations();
                obj._SubGeographicalRegionsID = "0";
                obj._SubstationID             = i.ToString();
                obj._SubstationName           = "Subtations name " + i.ToString();
                obj._Voltages    = ListVoltages();
                obj._Transfomers = ListTransfomers();
                list.Add(obj);
            }
            return(list);
        }
Exemple #9
0
        public override void RemoveReference(ModelCode referenceId, long globalId)
        {
            switch (referenceId)
            {
            case ModelCode.SUBSTATION_SUBREGION:

                if (Substations.Contains(globalId))
                {
                    Substations.Remove(globalId);
                }
                else
                {
                    CommonTrace.WriteTrace(CommonTrace.TraceWarning, "Entity (GID = 0x{0:x16}) doesn't contain reference 0x{1:x16}.", this.GlobalId, globalId);
                }

                break;

            default:
                base.RemoveReference(referenceId, globalId);
                break;
            }
        }
Exemple #10
0
        private void InitView()
        {
            Substations = (Session == null || Session.Substations == null)
                ? new BindableCollection <Substation>()
                : new BindableCollection <Substation>((SelectedDepartament == null || SelectedDepartament.Children.Count == 0)
                ? Session.Substations
                                                      .OrderBy(s => s.Departament)
                                                      .ThenBy(s => s.Name)
                                                      .ToList()
                : Session.Substations
                                                      .Where(s => s.Departament == SelectedDepartament.Name)
                                                      .OrderBy(s => s.Name)
                                                      .ToList());
            RaisePropertyChanged("SubstationsTree");

            HasData = (Substations == null || Substations.Count == 0)
                ? false
                : Substations.Any((s) => s.Status == DataStatus.Processed);

            _substationsCollectionView = CollectionViewSource.GetDefaultView(Substations);

            _substationsCollectionView.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));
            _substationsCollectionView.GroupDescriptions.Add(new PropertyGroupDescription("ElementType"));;
        }
Exemple #11
0
        private void InitCommands(System.Windows.Window window)
        {
            // Редактор конфигурации
            PointsEditorCommand = new DelegateCommand(() =>
            {
                DialogMessage        = "Редактор конфигурации";
                var pe               = new Controls.PointsEditor(Repository.ConfigPoints, Repository.ConfigOtherPoints, this.Window);
                var dialog           = this.CreateDialogCustom(pe, TMPApplication.WpfDialogs.DialogMode.Ok);
                dialog.Caption       = DialogMessage;
                dialog.CloseBehavior = TMPApplication.WpfDialogs.DialogCloseBehavior.ExplicitClose;

                dialog.OkText = "Закрыть";
                dialog.Ok     = () =>
                {
                    dialog.Close();
                    this.ShowDialogWaitingScreen("Применение конфигурации");
                    // сохранить конфигурацию
                    if (Repository.SaveConfiguration() == false)
                    {
                        EmcosSiteWrapperApp.LogWarning("Конфигурация не сохранена");
                    }
                    else
                    {
                        EmcosSiteWrapperApp.LogWarning("Конфигурация сохранена");
                    }

                    // обновить формулы групп в сессии
                    foreach (IHierarchicalEmcosPoint point in pe.EmcosPoints.FlatItemsList)
                    {
                        if (point is IBalanceGroupItem balanceGroupItem)
                        {
                            Repository.UpdateGroupBalanceFormula(balanceGroupItem.Id, balanceGroupItem.Formula);
                        }
                    }
                    // если появились новые точки - добавить точки в сессию и получить данные
                    if (pe.NewPoints != null && pe.NewPoints.Count > 1)
                    {
                        ;
                    }
                    if (pe.DeletedPoints != null && pe.DeletedPoints.Count > 1)
                    {
                        ;
                    }

                    // пересчёт баланса
                    var balanceGroups = Repository.ActiveSession.BalancePoints.FlatItemsList
                                        .Where(p => (p.TypeCode == "SUBSTATION" || p.ElementType == ElementTypes.SUBSTATION) || (p.TypeCode == "SECTIONBUS" || p.ElementType == ElementTypes.SECTION));
                    foreach (IBalanceGroupItem group in balanceGroups)
                    {
                        group.RecalculateBalance();
                    }
                    this.CloseDialog();
                };

                dialog.Show();
            });
            //
            GetDataCommand = new DelegateCommand(GetEmcosArchivesForSubstations);
            // Сохранение данных
            SaveDataCommand = new DelegateCommand(() =>
            {
                var result = U.InputBox("Сохранение", "Укажите название сессии", Session.Info.Period.GetFileNameForSaveSession());
                if (String.IsNullOrWhiteSpace(result) == true)
                {
                    return;
                }
                Repository.SaveAs(result);
                Repository.FillSessionsList();
            },
                                                  (o) => (IsSessionLoadedAdnPeriodSelected));
            // Выбор сессии
            SelectSessionCommand = new DelegateCommand(() =>
            {
                CloseDialog();
                DialogMessage = "Выбор сессии ...";
                Repository.FillSessionsList();

                Controls.SessionManager sm = new Controls.SessionManager(Repository);

                var dialog           = this.CreateDialogCustom(sm, TMPApplication.WpfDialogs.DialogMode.YesNoCancel);
                dialog.Caption       = DialogMessage;
                dialog.CloseBehavior = TMPApplication.WpfDialogs.DialogCloseBehavior.ExplicitClose;

                void closeDialogAction()
                {
                    dialog.Close();
                }

                dialog.YesText = "Загрузить";
                dialog.Yes     = () =>
                {
                    if (sm.SelectedSessionInfo == null)
                    {
                        ShowDialogWarning("Необходимо выбрать сессию из списка!", DialogMessage);
                        return;
                    }
                    else
                    {
                        if (_repository.LoadFromFile(sm.SelectedSessionInfo.FileName) == false)
                        {
                            TMPApp.ShowWarning("Не удалось загрузить сессию.");
                        }
                        else
                        {
                            closeDialogAction();
                        }
                    }
                };

                dialog.NoText = "Новая";
                dialog.No     = () =>
                {
                    _repository.CreateEmptySession();
                    closeDialogAction();
                };

                dialog.CancelText = "Закрыть";
                dialog.Cancel     = () =>
                {
                    closeDialogAction();
                };

                dialog.Show();
            });

            CancelCommand = new DelegateCommand(() =>
            {
                IsCancel = true;
                _cts.Cancel();
            },
                                                (o) => !IsCancel);
            // Детальная информация об элементе
            ViewDetailsCommand = new DelegateCommand(() =>
            {
                ShowDetails(SelectedBalanceItem.ElementType);
            },
                                                     (o) => SelectedBalanceItem != null);

            ExportList = new List <ICommand>
            {
                new DelegateCommand(() => ExportSubstationsBalance(), (o) => (IsSessionLoadedAdnPeriodSelected), "Баланс подстанций"),
                new DelegateCommand(() => BalanceExport(), (o) => (IsSessionLoadedAdnPeriodSelected), "Для программы 'Balance'"),
                new DelegateCommand(() => ExportFiderAnaliz(), (o) => (IsSessionLoadedAdnPeriodSelected), "Для пофидерного анализа")
            };

            OpenAuxiliaryReportCommand = new DelegateCommand(() =>
            {
                IList <AuxiliaryReportItem> model = new List <Model.AuxiliaryReportItem>();

                var list = Substations
                           .GroupBy(i => i.Departament, i => i,
                                    (k, g) => new { Departament = k, Substations = g.ToList() })
                           .OrderBy(i => i.Departament)
                           .ToList();

                foreach (var item in list)
                {
                    var departament = item.Departament;
                    var dep         = new AuxiliaryReportItem
                    {
                        Name = departament,
                        Type = "Departament",

                        Children = new List <AuxiliaryReportItem>()
                    };

                    foreach (Model.Balance.Substation substation in item.Substations)
                    {
                        var sub = new AuxiliaryReportItem
                        {
                            Children = new List <AuxiliaryReportItem>(),
                            Name     = substation.Name,
                            Type     = "Substation"
                        };

                        foreach (Model.Balance.IBalanceItem BalanceItem in substation.Items)
                        {
                            if (BalanceItem.ElementType == ElementTypes.UNITTRANSFORMER || BalanceItem.ElementType == ElementTypes.UNITTRANSFORMERBUS)
                            {
                                sub.Children.Add(new AuxiliaryReportItem
                                {
                                    Name   = BalanceItem.Name,
                                    APlus  = BalanceItem.ActiveEnergy.Plus.Value,
                                    AMinus = BalanceItem.ActiveEnergy.Minus.Value,
                                    RPlus  = BalanceItem.ReactiveEnergy.Plus.Value,
                                    RMinus = BalanceItem.ReactiveEnergy.Minus.Value,
                                });
                            }
                        }
                        dep.Children.Add(sub);
                    }
                    model.Add(dep);
                }
                var arw = new AuxiliaryReportWindow(new AuxiliaryReportTreeModel(model))
                {
                    Owner         = Window as System.Windows.Window,
                    ShowInTaskbar = false
                };

                arw.ShowDialog();
            },
                                                             (o) => IsSessionLoadedAdnPeriodSelected);

            bool canExecuteUpdateSubstationDataCommand(object o)
            {
                if (SelectedBalanceItem == null)
                {
                    return(false);
                }
                if (SelectedBalanceItem is Model.Balance.IBalanceGroupItem && (SelectedBalanceItem as Model.Balance.IBalanceGroupItem).ElementType == ElementTypes.SUBSTATION)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            UpdateSubstationDataCommand = new DelegateCommand(() =>
            {
                IProgressDialog progressDialog = ShowDialogProgress("Обновление данных по подстанции ...") as IProgressDialog;
                DispatcherExtensions.InUi(() =>
                {
                    (Window as System.Windows.Window).TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.Normal;
                    (Window as System.Windows.Window).TaskbarItemInfo.ProgressValue = 0;
                });
                var substation = SelectedBalanceItem as Model.Balance.Substation;
                if (substation == null)
                {
                    return;
                }
                substation.ClearData();

                Action oncompleted = () =>
                {
                    Status = State.Ready;
                    //vm.IsGettingData = false;

                    /*RaisePropertyChanged("HasData");
                     * RaisePropertyChanged("SubstationsTree");
                     * RaisePropertyChanged("WindowTitle");*/
                };

                void updateCallBack(int current, int total)
                {
                    DispatcherExtensions.InUi(() =>
                    {
                        progressDialog.Progress = 100 * current / total;
                        (Window as System.Windows.Window).TaskbarItemInfo.ProgressValue = ((double)current) / total;
                    });
                }

                try
                {
                    Status        = State.Busy;
                    IsGettingData = true;
                    IsCancel      = false;

                    _cts = new System.Threading.CancellationTokenSource();

                    substation.Status = Model.DataStatus.Wait;

                    var task = System.Threading.Tasks.Task.Factory.StartNew(() =>
                                                                            Emcos.Utils.GetArchiveDataForSubstation(Session.Info.Period.StartDate, Session.Info.Period.EndDate, substation, _cts, updateCallBack), _cts.Token);

                    task.ContinueWith((s) =>
                    {
                        if (s.Result == true)
                        {
                            DispatcherExtensions.InUi(() => ShowDialogInfo("Выполнено. "));
                        }
                        else
                        {
                            CheckOnError();
                        }
                        oncompleted();
                    }, System.Threading.Tasks.TaskContinuationOptions.OnlyOnRanToCompletion);
                    task.ContinueWith((s) =>
                    {
                        DispatcherExtensions.InUi(() => ShowDialogError("Произошла ошибка.\n" + s.Exception));
                        oncompleted();
                    }, System.Threading.Tasks.TaskContinuationOptions.OnlyOnFaulted);
                }
                catch (Exception e)
                {
                    EmcosSiteWrapperApp.LogError(String.Format("Обновление данных [{0}]. Ошибка - {1}", substation.Code, e.Message));
                    ShowDialogError("Произошла ошибка.\n" + e.Message);
                    oncompleted();
                }
            }, canExecuteUpdateSubstationDataCommand);

            SetSubstationToUseMonthValueCommand = new DelegateCommand((o) =>
            {
                System.Windows.Controls.MenuItem menuItem = o as System.Windows.Controls.MenuItem;
                if (menuItem == null)
                {
                    return;
                }
                var substation = SelectedBalanceItem as Model.Balance.Substation;
                if (substation == null)
                {
                    return;
                }
                else
                {
                    substation.UseMonthValue = menuItem.IsChecked;
                }
            }, canExecuteUpdateSubstationDataCommand);
        }
        partial void OnCreated()
        {
            substationTypeTable = new List <SubstationType>();
            foreach (SubstationType substationtype in SubstationTypes)
            {
                substationTypeTable.Add(substationtype);
            }

            ownershipTypeTable = new List <OwnershipType>();
            foreach (OwnershipType ownershiptype in OwnershipTypes)
            {
                ownershipTypeTable.Add(ownershiptype);
            }


            fuelTypeTable = new List <FuelType>();
            foreach (FuelType fueltype in FuelTypes)
            {
                fuelTypeTable.Add(fueltype);
            }


            resourceStatusTable = new List <ResourceStatuse>();
            foreach (ResourceStatuse resourcestatuse in ResourceStatuses)
            {
                resourceStatusTable.Add(resourcestatuse);
            }


            powerCallTable = new List <PowerCall>();
            foreach (PowerCall powercall in PowerCalls)
            {
                powerCallTable.Add(powercall);
            }

            genunitTypeTable = new List <GeneratorType>();
            foreach (GeneratorType generatortype in GeneratorTypes)
            {
                genunitTypeTable.Add(generatortype);
            }

            tvcfacilitystatusTypeTable = new List <TvcFacilityStatuse>();
            foreach (TvcFacilityStatuse facilitystatus in TvcFacilityStatuses)
            {
                tvcfacilitystatusTypeTable.Add(facilitystatus);
            }

            tvcfacilitystageTable = new List <TvcFacilityStage>();
            foreach (TvcFacilityStage facilitystage in TvcFacilityStages)
            {
                tvcfacilitystageTable.Add(facilitystage);
            }

            customerTable = new List <Customer>();
            foreach (Customer customer in Customers)
            {
                customerTable.Add(customer);
            }

            Substations.Audit().WithConfiguration <SubstationAuditConfig>();
            GeneratingUnits.Audit().WithConfiguration <GeneratingUnitAuditConfig>();
            TransmissionVoltageCustomers.Audit().WithConfiguration <TVCAuditConfig>();
        }