Пример #1
0
        public static List <MetricOrgValue> RelatedValuesList(int ValueCount, DateTime NormalizedDate, int FrequencyID, LinqMicajahDataContext dc, List <DateHeader> hl, Guid?CalcMetricID, bool OrderByMetric, Guid? @ApproverUserId)
        {
            DateTime EndDate   = Frequency.AddPeriod(NormalizedDate, FrequencyID, 1);
            DateTime BeginDate = Frequency.AddPeriod(EndDate, FrequencyID, -ValueCount);
            ISingleResult <Sp_SelectMetricRelatedValuesResult> V = dc.Sp_SelectMetricRelatedValues(LinqMicajahDataContext.InstanceId, FrequencyID, CalcMetricID, BeginDate, EndDate, OrderByMetric, @ApproverUserId);
            List <MetricOrgValue> MetricMetricValues             = new List <MetricOrgValue>();
            MetricOrgValue        LastMetricMetricValue          = null;
            int GroupNumber = 0;
            int GroupCount  = 0;
            List <Micajah.Common.Bll.MeasureUnit> OrgUoMs = Mc_UnitsOfMeasure.GetOrganizationUoMs();

            foreach (var v in V)
            {
                if (LastMetricMetricValue == null || v.MetricID != LastMetricMetricValue.MetricID || v.OrgLocationID != LastMetricMetricValue.OrgLocationID)
                {
                    if (LastMetricMetricValue == null || v.OrgLocationID == LastMetricMetricValue.OrgLocationID)
                    {
                        GroupNumber++;
                    }
                    else
                    {
                        SetOrgLocationNumber(GroupNumber, MetricMetricValues);
                        GroupNumber = 1;
                        GroupCount++;
                    }
                    PushMetricValue(LastMetricMetricValue, null, hl);
                    LastMetricMetricValue            = new MetricOrgValue();
                    LastMetricMetricValue.GroupCount = GroupCount;

                    // Common fields
                    LastMetricMetricValue.InstanceId    = (Guid)v.InstanceId;
                    LastMetricMetricValue.FrequencyID   = FrequencyID;
                    LastMetricMetricValue.FrequencyName = v.FrequencyName;

                    //Metric fields
                    LastMetricMetricValue.MetricID               = (Guid)v.MetricID;
                    LastMetricMetricValue.Name                   = v.MetricName;
                    LastMetricMetricValue.MetricTypeID           = (int)v.MetricTypeID;
                    LastMetricMetricValue.MetricDataTypeID       = 1;
                    LastMetricMetricValue.NODecPlaces            = v.NODecPlaces;
                    LastMetricMetricValue.InputUnitOfMeasureID   = v.MetricInputUnitOfMeasureID;
                    LastMetricMetricValue.InputUnitOfMeasureName = GetMeasureUnitAbbvr(OrgUoMs, v.MetricInputUnitOfMeasureID);

                    //MetricOrg fields
                    LastMetricMetricValue.OrgLocationID                 = (Guid)v.OrgLocationID;
                    LastMetricMetricValue.OrgLocationFullName           = v.OrgLocationID == Guid.Empty ? LinqMicajahDataContext.OrganizationName : v.OrgLocationFullName;
                    LastMetricMetricValue.RelatedOrgLocationUoMRecordID = v.MetricOrgLocationUoMID;
                    LastMetricMetricValue.OrgLocationUnitOfMeasureID    = v.OrgLocationUnitOfMeasureID;
                    LastMetricMetricValue.OrgLocationUnitOfMeasureName  = GetMeasureUnitAbbvr(OrgUoMs, v.OrgLocationUnitOfMeasureID);

                    // define actual measure unit
                    if (v.MetricOrgLocationUoMID != null)
                    {
                        LastMetricMetricValue.InputUnitOfMeasureName = LastMetricMetricValue.OrgLocationUnitOfMeasureName;
                    }
                    MetricMetricValues.Add(LastMetricMetricValue);
                }

                MetricValue.Extend LastMetricValue = new MetricValue.Extend();
                // Value fields
                LastMetricValue.InstanceId           = (Guid)v.InstanceId;
                LastMetricValue.MetricValueID        = (Guid)v.MetricValueID;
                LastMetricValue.MetricID             = (Guid)v.MetricID;
                LastMetricValue.Date                 = (DateTime)v.Date;
                LastMetricValue.OrgLocationID        = (Guid)v.OrgLocationID;
                LastMetricValue.FrequencyID          = FrequencyID;
                LastMetricValue.Value                = v.Value;
                LastMetricValue.Verified             = v.Verified == null ? false : (bool)v.Verified;
                LastMetricValue.Approved             = v.MetricValueID == Guid.Empty ? false : v.Approved;
                LastMetricValue.FilesAttached        = v.FilesAttached == null ? false : (bool)v.FilesAttached;
                LastMetricValue.ReviewUpdated        = v.ReviewUpdated == null ? false : (bool)v.ReviewUpdated;
                LastMetricValue.MissedCalc           = v.MissedCalc == null ? false : (bool)v.MissedCalc;
                LastMetricValue.MetricDataTypeID     = 1;
                LastMetricValue.InputUnitOfMeasureID = v.ValueInputUnitOfMeasureID;

                // Extend fields
                // extend - value reference
                LastMetricValue.ValueFrequencyName            = v.FrequencyName;
                LastMetricValue.ValueInputUnitOfMeasureName   = GetMeasureUnitAbbvr(OrgUoMs, v.ValueInputUnitOfMeasureID);
                LastMetricValue.OrgLocationFullName           = v.OrgLocationID == Guid.Empty ? LinqMicajahDataContext.OrganizationName : v.OrgLocationFullName;
                LastMetricValue.RelatedOrgLocationUoMRecordID = v.MetricOrgLocationUoMID;
                LastMetricValue.OrgLocationUnitOfMeasureID    = v.OrgLocationUnitOfMeasureID;
                LastMetricValue.OrgLocationUnitOfMeasureName  = GetMeasureUnitAbbvr(OrgUoMs, v.OrgLocationUnitOfMeasureID);

                // extend - metric fields
                LastMetricValue.MetricName                   = v.MetricName;
                LastMetricValue.MetricFrequencyID            = FrequencyID;
                LastMetricValue.ActualMetricDataTypeID       = 1;
                LastMetricValue.MetricInputUnitOfMeasureID   = v.MetricInputUnitOfMeasureID;
                LastMetricValue.NODecPlaces                  = v.NODecPlaces;
                LastMetricValue.MetricInputUnitOfMeasureName = GetMeasureUnitAbbvr(OrgUoMs, v.MetricInputUnitOfMeasureID);
                LastMetricValue.IsCalculated                 = (int)v.MetricTypeID > 1;
                LastMetricValue.IsAbsent         = false;
                LastMetricValue.RelatedFormulaID = v.MetricFormulaID;
                LastMetricValue.Formula          = v.Formula;

                PushMetricValue(LastMetricMetricValue, LastMetricValue, hl);
            }
            SetOrgLocationNumber(GroupNumber, MetricMetricValues);
            PushMetricValue(LastMetricMetricValue, null, hl);
            return(MetricMetricValues);
        }