コード例 #1
0
        public static decimal BalanceDebitOrDefault(this IBalanceItem balanceItem)
        {
            if (balanceItem == null)
            {
                return(0);
            }

            return(balanceItem.BalanceDebit - balanceItem.BalanceCredit);
        }
コード例 #2
0
        /// <summary>
        /// Возвращает значение энергии элемента
        /// </summary>
        /// <param name="BalanceItem">Элемент баланса</param>
        /// <param name="energyDirection">Направление энергии</param>
        /// <returns>Значение энергии</returns>
        private double?GetEnergyValueForBalanceItem(IBalanceItem BalanceItem, BalanceFormula.EnergyDirection energyDirection)
        {
            IEnergy energy = _BalanceItemsEnergy[BalanceItem];
            var     value  = energyDirection == BalanceFormula.EnergyDirection.@in
                ? energy.Plus.CorrectedValue
                : energy.Minus.CorrectedValue;

            return(value);
        }
コード例 #3
0
        public static decimal TotalCreditOrDefault(this IBalanceItem balanceItem)
        {
            if (balanceItem == null)
            {
                return(0);
            }

            return(balanceItem.TotalCredit);
        }
コード例 #4
0
 /// <summary>
 /// Возвращает энергию элемента
 /// </summary>
 /// <param name="BalanceItem">Элемент баланса</param>
 /// <returns>Энегия - активная или реактивная</returns>
 private IEnergy GetEnergyForBalanceItem(IBalanceItem BalanceItem)
 {
     if (BalanceItem.ActiveEnergy.GetType() == typeof(T))
     {
         return(BalanceItem.ActiveEnergy);
     }
     if (BalanceItem.ReactiveEnergy.GetType() == typeof(T))
     {
         return(BalanceItem.ReactiveEnergy);
     }
     return(null);
 }
コード例 #5
0
        private void CreateBodyForDepartament(string departament, IList <Substation> list)
        {
            sheet = book.Worksheets.Add(departament);
            CreateSheetHeader(departament);

            int count = list.Count();

            int startRowIndex = 2;
            int rowIndex      = startRowIndex;
            int orderIndex    = 1;

            for (int index = 0; index < count; index++)
            {
                var substation = list[index];
                if (substation == null || substation.Children == null)
                {
                    continue;
                }
                IList <Model.IHierarchicalEmcosPoint> sections = substation.Children.Where((c) => c.ElementType == Model.ElementTypes.SECTION && (c as SubstationSection).IsLowVoltage).ToList();
                foreach (IBalanceItem section in sections)
                {
                    var bss = section as SubstationSection;
                    if (bss == null)
                    {
                        continue;
                    }
                    if (bss.Children != null)
                    {
                        foreach (IBalanceItem item in bss.Children)
                        {
                            if (item is PowerTransformer || item is Fider || item is UnitTransformerBus)
                            {
                                // А+ за месяц
                                CreateCell(rowIndex, 1, orderIndex++);
                                CreateCell(rowIndex, 2, Convert.ToInt32(item.Id));
                                CreateCell(rowIndex, 3, 381);
                                CreateCell(rowIndex, 4, item.ActiveEnergy.Plus.Value);
                                CreateCell(rowIndex, 5, exportInfo.StartDate.ToString("dd.MM.yyyy"));
                                CreateCell(rowIndex, 7, item.Code);
                                rowIndex++;
                                // А- за месяц
                                CreateCell(rowIndex, 1, orderIndex++);
                                CreateCell(rowIndex, 2, Convert.ToInt32(item.Id));
                                CreateCell(rowIndex, 3, 382);
                                CreateCell(rowIndex, 4, item.ActiveEnergy.Minus.Value);
                                CreateCell(rowIndex, 5, exportInfo.StartDate.ToString("dd.MM.yyyy"));
                                rowIndex++;
                            }
                        }
                    }
                }
                // собственные нуды
                IList <Model.IHierarchicalEmcosPoint> sectionAux = substation.Children.Where((c) => c.ElementType == Model.ElementTypes.AUXILIARY && c.Name == "Собственные нужды").ToList();
                foreach (IBalanceGroupItem aux in sectionAux)
                {
                    if (aux == null || aux.Children == null)
                    {
                        continue;
                    }
                    foreach (IBalanceItem auxChild in aux.Children)
                    {
                        IBalanceItem unit = null;
                        if (auxChild is UnitTransformer)
                        {
                            unit = auxChild as UnitTransformer;
                        }
                        if (unit == null)
                        {
                            continue;
                        }
                        // А+ за месяц
                        CreateCell(rowIndex, 1, orderIndex++);
                        CreateCell(rowIndex, 2, Convert.ToInt32(unit.Id));
                        CreateCell(rowIndex, 3, 381);
                        CreateCell(rowIndex, 4, unit.ActiveEnergy.Plus.Value);
                        CreateCell(rowIndex, 5, exportInfo.StartDate.ToString("dd.MM.yyyy"));
                        CreateCell(rowIndex, 7, unit.Code);
                        rowIndex++;
                        // А- за месяц
                        CreateCell(rowIndex, 1, orderIndex++);
                        CreateCell(rowIndex, 2, Convert.ToInt32(unit.Id));
                        CreateCell(rowIndex, 3, 382);
                        CreateCell(rowIndex, 4, unit.ActiveEnergy.Minus.Value);
                        CreateCell(rowIndex, 5, exportInfo.StartDate.ToString("dd.MM.yyyy"));
                        rowIndex++;
                    }
                }
            }
            rowIndex--;
            ChangeRangeStyle(1, 1, rowIndex, 5, "style_table");

            // be-BY 423
            // ru-RU 419
            Range(2, 4, rowIndex - 1, 1).Style.Numberformat.Format = @"[$-419]#,##0.00_ ;[Red]\-# ##0.00, ";

            SetColumnWidthAndRowHeight();

            sheet.View.ShowGridLines        = false;
            sheet.PrinterSettings.PrintArea = Range(1, 1, rowIndex, 5);
            ChangePageSettings();
        }
コード例 #6
0
        public static SubstationsCollection PointToBalanceSubstations(EmcosPoint root)
        {
            var result = new SubstationsCollection(null);

            if (root.Children == null)
            {
                return(null);
            }

            foreach (EmcosPoint departamentPoint in root.Children) // департаменты (РЭС)
            {
                if (departamentPoint.ElementType == ElementTypes.DEPARTAMENT && departamentPoint.TypeCode == "RES" && departamentPoint.Children != null)
                {
                    foreach (EmcosPoint substationPoint in departamentPoint.Children) // подстанции
                    {
                        var substation = new Substation();
                        substation.Departament = departamentPoint.Name;
                        // название имеет формат вида ПС 35кВ Бакшты
                        var nameParts = substationPoint.Name.Split(' ');
                        if (nameParts.Length < 3)
                        {
                            throw new System.ArgumentException(string.Format("Неверный формат названия подстанции - '{0}'", substationPoint.Name));
                        }
                        // выделяем название
                        var name = "";
                        for (int i = 2; i < nameParts.Length; i++)
                        {
                            name += nameParts[i];
                        }
                        substation.Name = name;
                        // выделяем напряжение
                        substation.Voltage = nameParts[1];

                        substation.Code = substationPoint.Code;
                        substation.Id   = substationPoint.Id;

                        if (substationPoint.Children != null)
                        {
                            foreach (EmcosPoint groupPoint in substationPoint.Children) // группы
                            {
                                if (groupPoint.Children == null)
                                {
                                    continue;
                                }

                                IBalanceGroupItem group;
                                IBalanceItem      item;
                                switch (groupPoint.TypeCode)
                                {
                                case "AUXILIARY":
                                    group = new SubstationAuxiliary();
                                    foreach (var subgroupPoint in groupPoint.Children)
                                    {
                                        if (subgroupPoint.ElementType == ElementTypes.UNITTRANSFORMER)
                                        {
                                            item = new UnitTransformer();
                                        }
                                        else
                                        {
                                            item = new UnitTransformerBus();
                                        }
                                        item.Name        = subgroupPoint.Name;
                                        item.Code        = subgroupPoint.Code;
                                        item.Id          = subgroupPoint.Id;
                                        item.Description = subgroupPoint.Description;
                                        item.SetSubstation(substation);
                                        group.Children.Add(item);
                                    }
                                    substation.Children.Add(group);
                                    break;

                                case "POWERTRANSFORMERS":
                                    group = new SubstationPowerTransformers();
                                    foreach (var subgroupPoint in groupPoint.Children)
                                    {
                                        item = new PowerTransformer
                                        {
                                            Name        = subgroupPoint.Name,
                                            Code        = subgroupPoint.Code,
                                            Id          = subgroupPoint.Id,
                                            Description = subgroupPoint.Description
                                        };
                                        item.SetSubstation(substation);
                                        group.Children.Add(item);
                                    }
                                    substation.Children.Add(group);
                                    break;

                                case "SECTIONS":
                                    // проход по ступеням напряжения
                                    foreach (var subgroupPoint in groupPoint.Children)
                                    {
                                        SubstationSection highSection = null;
                                        // по секциям
                                        if (subgroupPoint.Children != null)
                                        {
                                            foreach (var sectionPoint in subgroupPoint.Children)
                                            {
                                                if (sectionPoint.TypeCode == "SECTIONBUS")
                                                {
                                                    var substationSection = new SubstationSection
                                                    {
                                                        Voltage     = subgroupPoint.Name,
                                                        Name        = sectionPoint.Name,
                                                        Code        = sectionPoint.Code,
                                                        Id          = sectionPoint.Id,
                                                        Description = sectionPoint.Description
                                                    };
                                                    substationSection.SetSubstation(substation);

                                                    if (sectionPoint.Children != null)
                                                    {
                                                        foreach (var sectionChildPoint in sectionPoint.Children)
                                                        {
                                                            IBalanceItem childItem = null;
                                                            switch (sectionChildPoint.ElementType)
                                                            {
                                                            case ElementTypes.FIDER:
                                                                childItem = new Fider();
                                                                break;

                                                            case ElementTypes.POWERTRANSFORMER:
                                                                childItem = new PowerTransformer();
                                                                break;

                                                            case ElementTypes.UNITTRANSFORMERBUS:
                                                                childItem = new UnitTransformerBus();
                                                                break;

                                                            case ElementTypes.UNITTRANSFORMER:
                                                                childItem = new UnitTransformer();
                                                                break;
                                                            }
                                                            if (childItem == null)
                                                            {
                                                                System.Diagnostics.Debugger.Break();
                                                            }

                                                            childItem.Name        = sectionChildPoint.Name;
                                                            childItem.Code        = sectionChildPoint.Code;
                                                            childItem.Id          = sectionChildPoint.Id;
                                                            childItem.Description = sectionChildPoint.Description;
                                                            childItem.SetSubstation(substation);

                                                            substationSection.Children.Add(childItem);
                                                        }
                                                    }
                                                    substation.Children.Add(substationSection);
                                                }
                                                else
                                                {
                                                    if (highSection == null)
                                                    {
                                                        highSection = new SubstationSection
                                                        {
                                                            Voltage     = subgroupPoint.Name,
                                                            Name        = subgroupPoint.Name,
                                                            Code        = subgroupPoint.Code,
                                                            Id          = subgroupPoint.Id,
                                                            Description = subgroupPoint.Description
                                                        };
                                                        highSection.SetSubstation(substation);
                                                    }
                                                    switch (sectionPoint.EcpName)
                                                    {
                                                    case "TRANSFORMER":
                                                        var pt = new PowerTransformer
                                                        {
                                                            Id          = sectionPoint.Id,
                                                            Code        = sectionPoint.Code,
                                                            Name        = sectionPoint.Name,
                                                            Description = sectionPoint.Description
                                                        };
                                                        pt.SetSubstation(substation);
                                                        highSection.Children.Add(pt);
                                                        break;

                                                    case "LINE":
                                                        var f = new Fider
                                                        {
                                                            Id          = sectionPoint.Id,
                                                            Code        = sectionPoint.Code,
                                                            Name        = sectionPoint.Name,
                                                            Description = sectionPoint.Description
                                                        };
                                                        f.SetSubstation(substation);
                                                        highSection.Children.Add(f);
                                                        break;
                                                    }
                                                }
                                            }
                                        }
                                        if (highSection != null)
                                        {
                                            substation.Children.Add(highSection);
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                        result.Add(substation);
                    }
                }
            }
            return(result);
        }
コード例 #7
0
        /// <summary>
        /// Загрузка файла сессии версии 1.0
        /// </summary>
        /// <remarks>
        /// Файл сессии версии 1.0 представляет собой сериализованный в json объект BalanceSession дополнительно сжатый gzip
        /// </remarks>
        /// <param name="fileName">Имя файла</param>
        /// <param name="balanceSession">Ссылка на сессию</param>
        /// <returns>Сессия</returns>
        private BalanceSession LoadDataFromFileVersion_1_0(string fileName)
        {
            const string UNKNOWN_DEPARTAMENT_NAME = "<неизвестно>";

            BalanceSession balanceSession = new BalanceSession();

            try
            {
                dynamic obj = ParseJsonFromFile(fileName);
                if (obj != null)
                {
                    var fi = new FileInfo(fileName);
                    BalanceSessionInfo balanceSessionInfo = LoadSessionInfoFromOldFileFormat(obj);
                    balanceSessionInfo.FileSize = fi.Length;
                    balanceSession.Info         = balanceSessionInfo;

                    if (obj.Substations != null)
                    {
                        balanceSession.BalancePoints.Clear();

                        // создание списка департаментов (рэс)
                        HashSet <string> departamentsSet = new HashSet <string>();
                        foreach (var item in obj.Substations)
                        {
                            string departament = item?.Departament?.ToString();
                            if (String.IsNullOrWhiteSpace(departament) == false && departamentsSet.Contains(departament) == false)
                            {
                                departamentsSet.Add(departament);
                            }
                        }
                        Dictionary <string, IHierarchicalEmcosPoint> departamentsDictionary = new Dictionary <string, IHierarchicalEmcosPoint>();
                        foreach (var item in departamentsSet)
                        {
                            departamentsDictionary.Add(item, new EmcosPoint()
                            {
                                ElementType = ElementTypes.DEPARTAMENT, TypeCode = "RES", Name = item
                            });
                        }
                        departamentsDictionary.Add("?", new EmcosPoint()
                        {
                            ElementType = ElementTypes.DEPARTAMENT, TypeCode = "RES", Name = UNKNOWN_DEPARTAMENT_NAME
                        });
                        System.Collections.IList parentList = departamentsDictionary["?"].Children;

                        void parseBase(IHierarchicalEmcosPoint source, dynamic data)
                        {
                            try
                            {
                                source.Id          = data.Id ?? 0;
                                source.Code        = data.Code;
                                source.Name        = data.Title;
                                source.Status      = data.Status;
                                source.Description = data.Description;
                                if (String.IsNullOrEmpty(source.Description) == false)
                                {
                                    balanceSession.DescriptionsById.Add(source.Id, source.Description);
                                }
                            }
                            catch (Exception e)
                            {
                                _callBackAction(e);
                            }
                        }

                        object getPropertyValue(string propertyName, dynamic jObject)
                        {
                            if ((jObject is Newtonsoft.Json.Linq.JObject o) && (o.Property(propertyName) != null))
                            {
                                return(o.Property(propertyName).Value);
                            }
                            else
                            {
                                return(null);
                            }
                        }

                        double?getDoubleValue(string propertyName, dynamic jObject)
                        {
                            object value = getPropertyValue(propertyName, jObject);

                            if (value == null)
                            {
                                return(null);
                            }
                            else
                            {
                                return(Convert.ToDouble(value));
                            }
                        }
                        bool getBoolValue(string propertyName, dynamic jObject)
                        {
                            object value = getPropertyValue(propertyName, jObject);

                            if (value == null)
                            {
                                return(false);
                            }
                            else
                            {
                                return(Convert.ToBoolean(value));
                            }
                        }

                        void parseTokens(IEnumerable <Newtonsoft.Json.Linq.JToken> tokens)
                        {
                            foreach (Newtonsoft.Json.Linq.JToken jobj in tokens)
                            {
                                if (jobj.Children().Where(i => (i is Newtonsoft.Json.Linq.JProperty p) && p.Name == "$type").FirstOrDefault() is Newtonsoft.Json.Linq.JProperty typeProperty)
                                {
                                    string tokenType = typeProperty.Value.ToString();
                                    if (String.IsNullOrWhiteSpace(tokenType) == false)
                                    {
                                        string   t     = tokenType.Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries)[0];
                                        string[] parts = t.Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries);
                                        if (parts.Length > 1 && parts[0] == "TMP")
                                        {
                                            string part = parts[parts.Length - 1];

                                            IBalanceGroupItem group = null;
                                            dynamic           data  = jobj;
                                            switch (part)
                                            {
                                            case "Substation":
                                                group = new Substation
                                                {
                                                    Departament = data.Departament,
                                                    Voltage     = data.Voltage
                                                };
                                                break;

                                            case "SubstationSection":
                                                group = new SubstationSection
                                                {
                                                    Voltage = data.Voltage
                                                };
                                                break;

                                            case "SubstationPowerTransformers":
                                                group = new SubstationPowerTransformers();
                                                break;

                                            case "SubstationAuxiliary":
                                                group = new SubstationAuxiliary();
                                                break;

                                            default:
                                            {
                                                IBalanceItem item = null;
                                                switch (part)
                                                {
                                                case "Fider":
                                                    item = new Fider();
                                                    break;

                                                case "PowerTransformer":
                                                    item = new PowerTransformer();
                                                    break;

                                                case "UnitTransformer":
                                                    item = new UnitTransformer();
                                                    break;

                                                case "UnitTransformerBus":
                                                    item = new UnitTransformerBus();
                                                    break;

                                                default:
                                                    System.Diagnostics.Debugger.Break();
                                                    break;
                                                }
                                                if (item != null)
                                                {
                                                    parseBase(item, data);
                                                }

                                                object value      = getPropertyValue("DailyEplus", data);
                                                string daysValues = value?.ToString();
                                                item.ActiveEnergy.Plus.DaysValues = (daysValues != null && daysValues.StartsWith("<"))
                                                            ? null
                                                            : (value as Newtonsoft.Json.Linq.JToken)?.ToObject <List <double?> >();

                                                value      = getPropertyValue("DailyEminus", data);
                                                daysValues = value?.ToString();
                                                item.ActiveEnergy.Minus.DaysValues = (daysValues != null && daysValues.StartsWith("<"))
                                                            ? null
                                                            : (value as Newtonsoft.Json.Linq.JToken)?.ToObject <List <double?> >();

                                                item.ActiveEnergy.Plus.MonthValue  = getDoubleValue("MonthEplus", data);
                                                item.ActiveEnergy.Minus.MonthValue = getDoubleValue("MonthEminus", data);

                                                item.ActiveEnergy.Plus.CorrectionValue  = getDoubleValue("Eplus", data) - getDoubleValue("DayEplusValue", data);
                                                item.ActiveEnergy.Minus.CorrectionValue = getDoubleValue("Eminus", data) - getDoubleValue("DayEminusValue", data);

                                                item.ActiveEnergy.Plus.UseMonthValue  = getBoolValue("UseMonthValue", data);
                                                item.ActiveEnergy.Minus.UseMonthValue = getBoolValue("UseMonthValue", data);

                                                if (group != null)
                                                {
                                                    group.Children.Add(item);
                                                }
                                                if (item == null && group == null)
                                                {
                                                    System.Diagnostics.Debugger.Break();
                                                }
                                            }
                                            break;
                                            }
                                            if (group != null)
                                            {
                                                parseBase(group, data);

                                                if (group is Substation substation)
                                                {
                                                    departamentsDictionary[substation.Departament].Children.Add(substation);
                                                }
                                                else
                                                {
                                                    parentList.Add(group);
                                                }

                                                var childrenProperty = jobj.Children()
                                                                       .Where(i => (i is Newtonsoft.Json.Linq.JProperty p) && p.Name == "Children")
                                                                       .FirstOrDefault() as Newtonsoft.Json.Linq.JProperty;
                                                if (childrenProperty != null && childrenProperty.Value != null && childrenProperty.Value is Newtonsoft.Json.Linq.JArray childrenArray)
                                                {
                                                    System.Collections.IList oldParentList = parentList;
                                                    parentList = group.Children;
                                                    parseTokens(childrenArray);
                                                    parentList = oldParentList;
                                                }
                                                else
                                                {
                                                    System.Diagnostics.Debugger.Break();
                                                }
                                            }
                                        }
                                    } // значение типа токена пустое
                                    else
                                    {
                                        System.Diagnostics.Debugger.Break();
                                    }
                                } // не найден тип токена
                                else
                                {
                                    System.Diagnostics.Debugger.Break();
                                }
                            }