Ejemplo n.º 1
0
        public void Initialize()
        {
            Dictionary <uint, int> unitsDict;

            var pollutions = Helpers.LogicHelper.PollutionLogic.Find().ToArray();

            {
                var units     = _resolutionClarify.ValueNorms.GroupBy(x => x.UnitID).Where(x => x.Key > 0).Select(x => x.First().Unit).ToArray();
                int unitIndex = 1;
                unitsDict = units.ToDictionary(x => x.ID, x => unitIndex++);

                this._values = new NormUnitValue[units.Length, pollutions.Length];

                if (units.Length == 0)
                {
                    for (int j = 0; j < pollutions.Length; j++)
                    {
                        this[j, 0] = new NormUnitValue(pollutions[j].ID, this._resolutionClarify.ID, 0);
                        this[j]    = new NormPriceValue(pollutions[j].ID, this._resolutionClarify.ID);
                    }
                }
                else
                {
                    for (int j = 0; j < pollutions.Length; j++)
                    {
                        for (int i = 0; i < units.Length; i++)
                        {
                            this[j, i] = new NormUnitValue(pollutions[j].ID, this._resolutionClarify.ID, units[i].ID);
                        }
                    }
                }
            }

            foreach (var normValue in this._resolutionClarify.ValueNorms)
            {
                int unitIndex;
                unitsDict.TryGetValue(normValue.UnitID, out unitIndex);

                var pollutionIndex = normValue.Pollution.Index;

                this[pollutionIndex, unitIndex] = new NormUnitValue(normValue.ID);
            }

            foreach (var price in this._resolutionClarify.PriceNorms)
            {
                var pollutionIndex = price.Pollution.Index;

                this[pollutionIndex] = new NormPriceValue(price.ID);
            }
        }
Ejemplo n.º 2
0
        public PollutionItem(uint ID)
        {
            this._pollution      = Helpers.LogicHelper.PollutionLogic.FirstModel(ID);
            this._accuratesItems = PollutionBase_Class.AccurateMeasurements.Where(x => x.PollutionID == ID).ToArray();

            {
                this.ValueNorm = new Dictionary <string, NormBaseValue>();

                var valueNorms = PollutionBase_Class.AllValueNorm.Where(x => x.PollutionID == ID);

                foreach (var valueNorm in valueNorms)
                {
                    var normUnitValue = new NormUnitValue(valueNorm.ID);

                    ValueNorm.Add($"{valueNorm.UnitID}|{valueNorm.ResolutionClarifyID}", normUnitValue);
                }
            }

            {
                var priceNorms = PollutionBase_Class.AllPriceNorm.Where(x => x.PollutionID == ID);

                this.priceNorms = new Dictionary <string, NormBaseValue>();

                foreach (var priceNorm in priceNorms)
                {
                    var normPriceValue = new NormPriceValue(priceNorm.ID);

                    this.priceNorms.Add($"{priceNorm.ResolutionClarifyID}", normPriceValue);
                }
            }

            {
                //теперь все прочие сочетания
                var resolutionClarifies = Helpers.LogicHelper.ResolutionClarifyLogic.Find(DateControl_Class.SelectMonth);
                var units = Helpers.LogicHelper.UnitLogic.Find();

                foreach (var resolutionClarify in resolutionClarifies)
                {
                    {
                        var key = $"{resolutionClarify.ID}";

                        if (!this.priceNorms.ContainsKey(key))
                        {
                            this.priceNorms.Add(key, new NormPriceValue(this._pollution.ID, resolutionClarify.ID));
                        }
                    }

                    {
                        var key = $"{0}|{resolutionClarify.ID}";

                        if (!this.ValueNorm.ContainsKey(key))
                        {
                            this.ValueNorm.Add(key, new NormUnitValue(this._pollution.ID, resolutionClarify.ID));
                        }
                    }

                    foreach (var unit in units)
                    {
                        var key = $"{unit.ID}|{resolutionClarify.ID}";

                        if (!this.ValueNorm.ContainsKey(key))
                        {
                            this.ValueNorm.Add(key, new NormUnitValue(this._pollution.ID, resolutionClarify.ID, unit.ID));
                        }
                    }
                }
            }
        }