예제 #1
0
        public static List <DistinctMetricOrgValue> MissedQueueList(LinqMicajahDataContext dc, DateTime BaseDate, DateTime NormalizedDate, int FrequencyID, Guid?MetricID, Guid?OrgLocationID, Guid?SelUserId, bool OrderByMetric)
        {
            DateTime EndDate = Frequency.AddPeriod(NormalizedDate, FrequencyID, 1);
            ISingleResult <Sp_SelectMissedInputMetricValuesResult> V = dc.Sp_SelectMissedInputMetricValues(LinqMicajahDataContext.InstanceId, BaseDate, EndDate, FrequencyID, MetricID, OrgLocationID, SelUserId, OrderByMetric);

            List <DistinctMetricOrgValue> MetricMetricValues    = new List <DistinctMetricOrgValue>();
            DistinctMetricOrgValue        LastMetricMetricValue = null;

            List <Micajah.Common.Bll.MeasureUnit> OrgUoMs = Mc_UnitsOfMeasure.GetOrganizationUoMs();
            int      i        = 0;
            int      j        = 0;
            DateTime NextDate = DateTime.MinValue;

            foreach (var v in V)
            {
                if (LastMetricMetricValue == null ||
                    v.MetricID != LastMetricMetricValue.MetricID ||
                    v.OrgLocationID != LastMetricMetricValue.OrgLocationID)
                {
                    i = 0;
                    j = 0;
                    LastMetricMetricValue = new DistinctMetricOrgValue();
                    // copy metric data
                    LastMetricMetricValue.InstanceId                    = LinqMicajahDataContext.InstanceId;
                    LastMetricMetricValue.MetricID                      = (Guid)v.MetricID;
                    LastMetricMetricValue.Name                          = v.MetricName;
                    LastMetricMetricValue.FrequencyID                   = FrequencyID;
                    LastMetricMetricValue.MetricTypeID                  = 1;
                    LastMetricMetricValue.MetricDataTypeID              = 1;
                    LastMetricMetricValue.NODecPlaces                   = v.NODecPlaces;
                    LastMetricMetricValue.InputUnitOfMeasureID          = v.MetricInputUnitOfMeasureID;
                    LastMetricMetricValue.InputUnitOfMeasureName        = GetMeasureUnitAbbvr(OrgUoMs, v.MetricInputUnitOfMeasureID);
                    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);
                    LastMetricMetricValue.CollectionStartDate           = v.CollectionStartDate;
                    LastMetricMetricValue.CollectionEndDate             = v.CollectionEndDate;
                    LastMetricMetricValue.AllowCustomNames              = (bool)v.AllowCustomNames;

                    // find actual input measure unit for metric-org location pair
                    LastMetricMetricValue.InputUnitOfMeasureName         = (LastMetricMetricValue.RelatedOrgLocationUoMRecordID == null) ? LastMetricMetricValue.InputUnitOfMeasureName : LastMetricMetricValue.OrgLocationUnitOfMeasureName;
                    LastMetricMetricValue.RelatedOrgLocationNameRecordID = v.MetricOrgLocationNameID;
                    LastMetricMetricValue.MetricOrgLocationAlias         = v.CustomMetricAlias;
                    LastMetricMetricValue.MetricOrgLocationCode          = v.CustomMetricCode;
                    LastMetricMetricValue.IsPreviousValues = false;
                    LastMetricMetricValue.IsNextValues     = false;
                    LastMetricMetricValue.PreviousDate     = DateTime.MinValue;
                    LastMetricMetricValue.NextDate         = DateTime.MinValue;
                    LastMetricMetricValue.DatesHeader      = new List <DateHeader>();
                    MetricMetricValues.Add(LastMetricMetricValue);
                }

                if (v.ValuePosType == "A") // check for existed left values
                {
                    j++;
                    if (j == 2)
                    {
                        LastMetricMetricValue.NextDate = (DateTime)v.Date;
                    }
                    continue;
                }

                if (LastMetricMetricValue.MetricValues.Count == 6) // check for existed right values
                {
                    LastMetricMetricValue.IsPreviousValues = true;
                    continue;
                }

                if (j == 2)
                {
                    LastMetricMetricValue.IsNextValues = true;
                }

                MetricValue.Extend LastMetricValue = new MetricValue.Extend();
                // metric data
                LastMetricValue.InstanceId  = LinqMicajahDataContext.InstanceId;
                LastMetricValue.MetricID    = (Guid)v.MetricID;
                LastMetricValue.NODecPlaces = v.NODecPlaces;
                // value data
                LastMetricValue.MetricValueID                 = (Guid)v.MetricValueID;
                LastMetricValue.FrequencyID                   = FrequencyID;
                LastMetricValue.Date                          = (DateTime)v.Date;
                LastMetricValue.Value                         = v.Value;
                LastMetricValue.Approved                      = v.Approved;
                LastMetricValue.FilesAttached                 = (bool)v.FilesAttached;
                LastMetricValue.ReviewUpdated                 = (bool)v.ReviewUpdated;
                LastMetricValue.OrgLocationID                 = (Guid)v.OrgLocationID;
                LastMetricValue.MetricDataTypeID              = 1;
                LastMetricValue.InputUnitOfMeasureID          = v.ValueInputUnitOfMeasureID;
                LastMetricValue.OrgLocationFullName           = v.OrgLocationID == Guid.Empty ? LinqMicajahDataContext.OrganizationName : v.OrgLocationFullName;
                LastMetricValue.RelatedOrgLocationUoMRecordID = v.MetricOrgLocationUoMID;
                LastMetricValue.OrgLocationUnitOfMeasureID    = v.OrgLocationUnitOfMeasureID;
                LastMetricValue.IsCalculated                  = false;

                LastMetricValue.CollectionStartDate = v.CollectionStartDate;
                LastMetricValue.CollectionEndDate   = v.CollectionEndDate;
                LastMetricValue.CollectionEnabled   = IsCollectingDate(LastMetricValue.CollectionStartDate, LastMetricValue.CollectionEndDate, LastMetricValue.Date);

                DateHeader h = new DateHeader();
                h.Date  = (DateTime)v.Date;
                h.sDate = Frequency.GetPeriodName((DateTime)v.Date, FrequencyID, true);
                LastMetricMetricValue.DatesHeader.Add(h);

                if (i == 1)
                {
                    LastMetricMetricValue.PreviousDate = LastMetricValue.Date;
                }

                LastMetricMetricValue.MetricValues.Add(LastMetricValue);
                i++;
            }
            foreach (DistinctMetricOrgValue m in MetricMetricValues)
            {
                if (m.MetricValues.Count < 6)
                {
                    int count = 6 - m.MetricValues.Count;
                    for (int k = 1; k <= count; k++)
                    {
                        MetricValue.Extend AnotherMetricValue = new MetricValue.Extend();
                        // metric data
                        AnotherMetricValue.InstanceId  = LastMetricMetricValue.InstanceId;
                        AnotherMetricValue.MetricID    = LastMetricMetricValue.MetricID;
                        AnotherMetricValue.NODecPlaces = LastMetricMetricValue.NODecPlaces;
                        // value data
                        AnotherMetricValue.MetricValueID                 = Guid.Empty;
                        AnotherMetricValue.FrequencyID                   = FrequencyID;
                        AnotherMetricValue.Date                          = DateTime.MinValue;
                        AnotherMetricValue.Value                         = null;
                        AnotherMetricValue.Approved                      = false;
                        AnotherMetricValue.FilesAttached                 = false;
                        AnotherMetricValue.ReviewUpdated                 = false;
                        AnotherMetricValue.OrgLocationID                 = LastMetricMetricValue.OrgLocationID;
                        AnotherMetricValue.MetricDataTypeID              = LastMetricMetricValue.MetricDataTypeID;
                        AnotherMetricValue.InputUnitOfMeasureID          = LastMetricMetricValue.InputUnitOfMeasureID;
                        AnotherMetricValue.OrgLocationFullName           = LastMetricMetricValue.OrgLocationFullName;
                        AnotherMetricValue.RelatedOrgLocationUoMRecordID = LastMetricMetricValue.RelatedOrgLocationUoMRecordID;
                        AnotherMetricValue.OrgLocationUnitOfMeasureID    = LastMetricMetricValue.OrgLocationUnitOfMeasureID;
                        AnotherMetricValue.IsCalculated                  = LastMetricMetricValue.MetricTypeID != 1;

                        AnotherMetricValue.CollectionStartDate = LastMetricMetricValue.CollectionStartDate;
                        AnotherMetricValue.CollectionEndDate   = LastMetricMetricValue.CollectionEndDate;
                        AnotherMetricValue.CollectionEnabled   = false;//IsCollectingDate(AnotherMetricValue.CollectionStartDate, AnotherMetricValue.CollectionEndDate, AnotherMetricValue.Date);

                        DateHeader ah = new DateHeader();
                        ah.Date  = DateTime.MinValue;
                        ah.sDate = "&nbsp;";
                        m.DatesHeader.Add(ah);
                        m.MetricValues.Add(AnotherMetricValue);
                    }
                }
            }

            for (int k = 0; k < MetricMetricValues.Count; k++)
            {
                bool AllValuesCollectionDisabled = true;
                DistinctMetricOrgValue mov       = MetricMetricValues[k];
                foreach (MetricValue.Extend me in mov.MetricValues)
                {
                    if (me.CollectionEnabled)
                    {
                        AllValuesCollectionDisabled = false;
                    }
                }
                if (AllValuesCollectionDisabled && !mov.IsNextValues && !mov.IsPreviousValues)
                {
                    MetricMetricValues.Remove(mov);
                }
            }
            return(MetricMetricValues);
        }
예제 #2
0
        static double?GetValue(LinqMicajahDataContext dc, Guid MetricID, Guid?OrgLocationID, Guid?UomID, PeriodDate d, Guid OrganizationId, Guid InstanceId, out Guid?TotalUnitOfMessureID)
        {
            var values = (from m in dc.Metric
                          join v in dc.MetricValue on new { MetricID, m.FrequencyID, Status = (bool?)true } equals new { v.MetricID, v.FrequencyID, v.Status }
                          join o in dc.EntityNodeFullNameView on v.OrgLocationID equals(Guid?) o.EntityNodeId
                          join r in dc.D_MetricOrgLocationRule on new { InstanceId, v.MetricID, v.OrgLocationID } equals new { r.InstanceId, r.MetricID, r.OrgLocationID }

                          where (
                              OrgLocationID == null || OrgLocationID == Guid.Empty || OrgLocationID == v.OrgLocationID ||
                              OrgLocationID == o.Parent1 || OrgLocationID == o.Parent2 || OrgLocationID == o.Parent3 || OrgLocationID == o.Parent4 || OrgLocationID == o.Parent5
                              ) &&
                          m.MetricID == MetricID && m.Status == true &&
                          v.Date >= d.Begin && v.Date < d.End
                          select v).Distinct().ToList();

            TotalUnitOfMessureID = null;
            if (values.Count < 1)
            {
                return(null);
            }

            double Sum        = 0;
            bool   ValueExist = false;

            TotalUnitOfMessureID = values[0].InputUnitOfMeasureID;
            for (int i = 1; i < values.Count; i++)
            {
                Guid?UID = values[i].InputUnitOfMeasureID;
                if (UID != TotalUnitOfMessureID)
                {
                    TotalUnitOfMessureID = UomID;
                    break;
                }
            }
            foreach (var v in values)
            {
                if (string.IsNullOrEmpty(v.Value))
                {
                    continue;
                }
                double SingleValue;

                try { SingleValue = double.Parse(v.Value, System.Globalization.NumberStyles.Any); }
                catch { continue; }

                if (TotalUnitOfMessureID != v.InputUnitOfMeasureID)
                {
                    if (TotalUnitOfMessureID == null || v.InputUnitOfMeasureID == null)
                    {
                        continue;
                    }
                    double?ConvertedVal = Mc_UnitsOfMeasure.ConvertValue(SingleValue, (Guid)v.InputUnitOfMeasureID, (Guid)TotalUnitOfMessureID, OrganizationId);
                    if (ConvertedVal == null)
                    {
                        continue;
                    }
                    SingleValue = (double)ConvertedVal;
                }

                ValueExist = true;
                Sum       += SingleValue;
            }
            if (!ValueExist)
            {
                return(null);
            }

            return(Sum);
        }