Пример #1
0
        // Performance Indicator Report section
        public static IList <PIMetricInfo> GetPIReportValues(Guid?OrgLocationID, Guid GroupID, int FrequencyID, Guid?OrgLocationTypeID, DateTime BeginDate, DateTime EndDate)
        {
            LinqMicajahDataContext dc                     = new LinqMicajahDataContext();
            IMultipleResults       results                = dc.Sp_SelectPIReportValues(LinqMicajahDataContext.InstanceId, OrgLocationID, GroupID, FrequencyID, OrgLocationTypeID, BeginDate, EndDate);
            IList <PIMetricInfo>   MetricInfo             = results.GetResult <PIMetricInfo>().ToList();
            IList <PIMetricValue>  MetricValues           = results.GetResult <PIMetricValue>().ToList();
            List <Micajah.Common.Bll.MeasureUnit> OrgUoMs = Mc_UnitsOfMeasure.GetOrganizationUoMs();

            foreach (PIMetricInfo mi in MetricInfo)
            {
                mi.LocationFullName = (OrgLocationID == Guid.Empty && !String.IsNullOrEmpty(mi.LocationFullName)) ? LinqMicajahDataContext.OrganizationName : mi.LocationFullName;

                mi.InputUoMName = GetMeasureUnitPluralName(OrgUoMs, mi.InputUnitOfMeasureID);
                mi.UoMName      = GetMeasureUnitPluralName(OrgUoMs, mi.UnitOfMeasureID);
                CompositeDailyValues cdv = new CompositeDailyValues();
                foreach (PIMetricValue mv in MetricValues)
                {
                    decimal Val = 0;
                    if (mv.MetricID == mi.MetricID && mv.OrgLocationID == mi.OrgLocationID) // add one more linq select
                    {
                        if ((mv.ValueMetricDataTypeID == 1) && (mv.UnitOfMeasureID == mv.MetricUnitOfMeasureID))
                        {
                            // !!! for now we ignore values when its output uom != metric output uom
                            if (decimal.TryParse(mv.ConvertedValue, out Val))
                            {
                                cdv.AddCompositeDailyValue((DateTime)mv.InputDate, Val, (int)mv.FrequencyID, (DateTime)mv.Date, (int)mi.FrequencyID);
                            }
                        }
                    }
                }
                decimal?res = cdv.GetCompositeValue(BeginDate, EndDate, false);
                mi.SumValue = res == null ? "0" : res.ToString();
            }
            return(MetricInfo);
        }
Пример #2
0
        public static Extend Get(Guid MetricID, DateTime NormalizedDate, Guid OrgLocationID)
        {
            LinqMicajahDataContext dc = new LinqMicajahDataContext();
            List <Micajah.Common.Bll.MeasureUnit> OrgUoMs = Mc_UnitsOfMeasure.GetOrganizationUoMs();
            var MetricValue =
                from m in dc.Metric
                join f in dc.Frequency on m.FrequencyID equals f.FrequencyID
                join t in dc.MetricDataType on m.MetricDataTypeID equals t.MetricDataTypeID

                join _mv in dc.MetricValue on
                new
            {
                m.MetricID,
                LinqMicajahDataContext.InstanceId,
                m.FrequencyID,
                Date   = NormalizedDate,
                Status = (bool?)true,
                OrgLocationID
            }
            equals new
            {
                _mv.MetricID,
                _mv.InstanceId,
                _mv.FrequencyID,
                _mv.Date,
                _mv.Status,
                _mv.OrgLocationID
            } into __mv
            join _c in dc.ViewnameMetricCategory on
            new { InstanceId = (Guid?)m.InstanceId, m.MetricCategoryID } equals
            new { _c.InstanceId, _c.MetricCategoryID } into __c
            from mv in __mv.DefaultIfEmpty()
            join _mvf in dc.Frequency on mv.FrequencyID equals _mvf.FrequencyID into __mvf
            join _mvt in dc.MetricDataType on mv.MetricDataTypeID equals _mvt.MetricDataTypeID into __mvt
            join _OrgLocName in dc.ViewnameOrgLocation on
            new { InstanceId = (Guid?)LinqMicajahDataContext.InstanceId, OrgLocationID = (Guid?)OrgLocationID } equals new { _OrgLocName.InstanceId, _OrgLocName.OrgLocationID } into __OrgLocName
            from OrgLocName in __OrgLocName.DefaultIfEmpty()
            from mvf in __mvf.DefaultIfEmpty()
            from mvt in __mvt.DefaultIfEmpty()
            from c in __c.DefaultIfEmpty()
            join _mnuom in dc.MetricOrgLocationUoM on
            new { m.InstanceId, m.MetricID, OrgLocationID }
            equals new { _mnuom.InstanceId, _mnuom.MetricID, _mnuom.OrgLocationID } into __mnuom
            from mnuom in __mnuom.DefaultIfEmpty()
            join _mnname in dc.MetricOrgLocationName on
            new { m.InstanceId, m.MetricID, OrgLocationID }
            equals new { _mnname.InstanceId, _mnname.MetricID, _mnname.OrgLocationID } into __mnname
            from mnname in __mnname.DefaultIfEmpty()

            where
            m.MetricID == MetricID &&
            m.InstanceId == LinqMicajahDataContext.InstanceId &&
            m.Status == true

                select new MetricValue.Extend
            {
                // Metric solid fields
                InstanceId = m.InstanceId,
                MetricID   = m.MetricID,

                // Value fields
                MetricValueID        = mv.MetricValueID == null ? Guid.Empty : mv.MetricValueID,
                OrgLocationID        = mv.OrgLocationID == null ? OrgLocationID : mv.OrgLocationID,
                InputUserId          = mv.InputUserId,
                ApproveUserId        = mv.ApproveUserId,
                FrequencyID          = mv.FrequencyID == null ? m.FrequencyID : mv.FrequencyID,
                Date                 = mv.Date == null ? FailureDate : mv.Date,
                MetricDataTypeID     = mv.MetricDataTypeID == null ? m.MetricDataTypeID : mv.MetricDataTypeID,
                Value                = mv.Value,
                ConvertedValue       = mv.ConvertedValue,
                Notes                = mv.Notes,
                Verified             = mv.Verified == null ? false : mv.Verified,
                Approved             = mv.MetricValueID == null ? false : mv.Approved,
                FilesAttached        = mv.FilesAttached == null ? false : mv.FilesAttached,
                ReviewUpdated        = mv.ReviewUpdated == null ? false : mv.ReviewUpdated,
                InputUnitOfMeasureID = mv.InputUnitOfMeasureID,
                UnitOfMeasureID      = mv.UnitOfMeasureID,

                // Value Reference fields
                ValueFrequencyName            = mvf.Name,
                ValueDataTypeName             = mvt.Name,
                ApprovalStatus                = mv.MetricValueID == null ? "Pending" : (mv.Approved == null ? "Under Review" : ((bool)mv.Approved ? "Approved" : "Pending")),
                Period                        = Frequency.GetPeriodName(NormalizedDate, m.FrequencyID),
                ValueInputUnitOfMeasureName   = Metric.GetMeasureUnitName(OrgUoMs, mv.InputUnitOfMeasureID),
                ValueUnitOfMeasureName        = Metric.GetMeasureUnitName(OrgUoMs, mv.UnitOfMeasureID),
                RelatedOrgLocationUoMRecordID = mnuom.MetricOrgLocationUoMID,
                OrgLocationUnitOfMeasureID    = mnuom.InputUnitOfMeasureID,
                OrgLocationUnitOfMeasureName  = Metric.GetMeasureUnitName(OrgUoMs, mnuom.InputUnitOfMeasureID),
                OrgLocationFullName           = OrgLocationID == Guid.Empty ? LinqMicajahDataContext.OrganizationName : OrgLocName.FullName,

                RelatedOrgLocationNameRecordID = mnname.MetricOrgLocationNameID,
                MetricOrgLocationAlias         = mnname.Alias,
                MetricOrgLocationCode          = mnname.Code,

                // Metric fields
                MetricName                 = m.Name,
                MetricFrequencyID          = m.FrequencyID,
                ActualMetricDataTypeID     = m.MetricDataTypeID,
                MetricCategoryID           = m.MetricCategoryID,
                MetricInputUnitOfMeasureID = m.InputUnitOfMeasureID,
                MetricUnitOfMeasureID      = m.UnitOfMeasureID,
                NODecPlaces                = m.NODecPlaces,
                NOMinValue                 = m.NOMinValue,
                NOMaxValue                 = m.NOMaxValue,
                FormulaCode                = m.FormulaCode,
                Variable               = m.Variable,
                Documentation          = m.Documentation,
                Description            = m.Notes,
                Definition             = m.Definition,
                References             = m.MetricReferences,
                AllowMetricCustomNames = m.AllowCustomNames,

                // Metric reference fields
                MetricFrequencyName          = f.Name,
                MetricCategoryName           = c.FullName,
                MetricDataTypeName           = t.Name,
                MetricInputUnitOfMeasureName = Metric.GetMeasureUnitName(OrgUoMs, m.InputUnitOfMeasureID),
                MetricUnitOfMeasureName      = Metric.GetMeasureUnitName(OrgUoMs, m.UnitOfMeasureID),
                IsCalculated = m.MetricTypeID == 2
            };

            return(MetricValue.FirstOrNull());
        }
Пример #3
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);
        }
Пример #4
0
        public static List <EntityValue> WorkList(int ValueCount, PageEntityID EntityPageInfo, Guid? @ApproverUserId, bool OrderByMetric)
        {
            LinqMicajahDataContext dc = new LinqMicajahDataContext();
            Guid?EntityID             = null;
            int  SkipCount            = 0;

            if (EntityPageInfo != null)
            {
                EntityID  = EntityPageInfo.EntityID;
                SkipCount = EntityPageInfo.PageNumber * ValueCount;
            }

            ISingleResult <Sp_SelectApproverWorkListResult> V = dc.Sp_SelectApproverWorkList(LinqMicajahDataContext.InstanceId, ValueCount, SkipCount, EntityID, OrderByMetric, @ApproverUserId);

            List <EntityValue> MetricMetricValues         = new List <EntityValue>();
            EntityValue        LastMetricMetricValue      = null;
            List <Micajah.Common.Bll.MeasureUnit> OrgUoMs = Mc_UnitsOfMeasure.GetOrganizationUoMs();
            int i = 0;

            foreach (var v in V)
            {
                if (LastMetricMetricValue == null ||
                    (OrderByMetric && v.MetricID != LastMetricMetricValue.EntityID) ||
                    (!OrderByMetric && v.OrgLocationID != LastMetricMetricValue.EntityID))
                {
                    i = 0;
                    LastMetricMetricValue = new EntityValue();
                    // copy metric data
                    LastMetricMetricValue.FrequencyID  = OrderByMetric ? v.MetricFrequencyID : null;
                    LastMetricMetricValue.PageCount    = (SkipCount / ValueCount) + 1;
                    LastMetricMetricValue.EntityID     = OrderByMetric ? (Guid)v.MetricID : (Guid)v.OrgLocationID;
                    LastMetricMetricValue.EntityName   = OrderByMetric ? v.MetricName : v.OrgLocationFullName;
                    LastMetricMetricValue.IsMoreValues = false;
                    LastMetricMetricValue.MetricTypeID = (int)v.MetricTypeID;
                    MetricMetricValues.Add(LastMetricMetricValue);
                }
                if (i == ValueCount)
                {
                    LastMetricMetricValue.IsMoreValues = true;
                    continue;
                }
                MetricValue.Extend LastMetricValue = new MetricValue.Extend();
                // metric data
                LastMetricValue.InstanceId         = (Guid)v.InstanceId;
                LastMetricValue.MetricID           = (Guid)v.MetricID;
                LastMetricValue.NODecPlaces        = v.NODecPlaces;
                LastMetricValue.MetricName         = v.MetricName;
                LastMetricValue.MetricCategoryName = v.MetricCategoryFullName;
                // value data
                LastMetricValue.MetricValueID      = (Guid)v.MetricValueID;
                LastMetricValue.FrequencyID        = (int)v.ValueFrequencyID;
                LastMetricValue.ValueFrequencyName = v.ValueFrequencyName;
                LastMetricValue.Date          = (DateTime)v.Date;
                LastMetricValue.Period        = Frequency.GetPeriodName((DateTime)v.Date, LastMetricValue.FrequencyID, true);
                LastMetricValue.Value         = v.Value;
                LastMetricValue.Approved      = v.Approved;
                LastMetricValue.ReviewUpdated = (bool)v.ReviewUpdated;
                LastMetricValue.MissedCalc    = (bool)v.MissedCalc;
                string title = String.Empty;
                if (v.MetricValueID == null || v.MetricValueID == Guid.Empty || String.IsNullOrEmpty(v.Value) /* || v.Status == false*/) //!!! add after fix stored procedure
                {
                    LastMetricValue.ApprovalStatus = "Missing&nbsp;Value";
                }
                else
                {
                    if (v.MetricTypeID != 1)
                    {
                        title = "Calc&nbsp;value";
                        if (v.MissedCalc == true)
                        {
                            title += " | Some&nbsp;input&nbsp;values&nbsp;missed";
                        }
                    }
                    else
                    {
                        title = "Input&nbsp;value";
                    }
                    LastMetricValue.ApprovalStatus = (v.Approved == null ? (v.ReviewUpdated == true ? "Under&nbsp;Review | Updated&nbsp;by&nbsp;Collector" : "Under&nbsp;Review") : ((bool)v.Approved ? "Approved" : "Pending"));
                }
                title = String.IsNullOrEmpty(title) ? String.Empty : "(" + title + ") ";
                LastMetricValue.Notes                         = title + v.Notes;
                LastMetricValue.FilesAttached                 = (bool)v.FilesAttached;
                LastMetricValue.ReviewUpdated                 = (bool)v.ReviewUpdated;
                LastMetricValue.OrgLocationID                 = (Guid)v.OrgLocationID;
                LastMetricValue.MetricDataTypeID              = (int)v.ValueDataTypeID;
                LastMetricValue.InputUnitOfMeasureID          = v.ValueInputUnitOfMeasureID;
                LastMetricValue.ValueInputUnitOfMeasureName   = GetMeasureUnitAbbvr(OrgUoMs, LastMetricValue.InputUnitOfMeasureID);
                LastMetricValue.OrgLocationFullName           = v.OrgLocationID == Guid.Empty ? LinqMicajahDataContext.OrganizationName : v.OrgLocationFullName;
                LastMetricValue.RelatedOrgLocationUoMRecordID = v.MetricOrgLocationUoMID;
                LastMetricValue.OrgLocationUnitOfMeasureID    = v.OrgLocationUnitOfMeasureID;
                LastMetricValue.IsCalculated                  = v.MetricTypeID != 1;
                LastMetricMetricValue.EntityValues.Add(LastMetricValue);
                i++;
            }
            return(MetricMetricValues);
        }
Пример #5
0
        public static List <DistinctMetricOrgValue> AlertQueueList(LinqMicajahDataContext dc, DateTime NormalizedDate, int FrequencyID, Guid?MetricID, Guid?OrgLocationID, Guid?SelUserId, Guid? @ApproverUserId, bool ViewMode, bool OrderByMetric)
        {
            DateTime EndDate = Frequency.AddPeriod(NormalizedDate, FrequencyID, 1);
            ISingleResult <Sp_SelectUnderReviewMetricValuesResult> V = dc.Sp_SelectUnderReviewMetricValues(LinqMicajahDataContext.InstanceId, EndDate, ViewMode, FrequencyID, MetricID, OrgLocationID, SelUserId, @ApproverUserId, 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                    = (Guid)v.InstanceId;
                    LastMetricMetricValue.MetricID                      = (Guid)v.MetricID;
                    LastMetricMetricValue.Name                          = v.MetricName;
                    LastMetricMetricValue.FrequencyID                   = (int)v.MetricFrequencyID;
                    LastMetricMetricValue.MetricTypeID                  = (int)v.MetricTypeID;
                    LastMetricMetricValue.MetricDataTypeID              = (int)v.MetricDataTypeID;
                    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.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  = (Guid)v.InstanceId;
                LastMetricValue.MetricID    = (Guid)v.MetricID;
                LastMetricValue.NODecPlaces = v.NODecPlaces;
                // value data
                LastMetricValue.MetricValueID                 = (Guid)v.MetricValueID;
                LastMetricValue.FrequencyID                   = (int)v.MetricFrequencyID;
                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              = (int)v.ValueDataTypeID;
                LastMetricValue.InputUnitOfMeasureID          = v.ValueInputUnitOfMeasureID;
                LastMetricValue.OrgLocationFullName           = v.OrgLocationID == Guid.Empty ? LinqMicajahDataContext.OrganizationName : v.OrgLocationFullName;
                LastMetricValue.RelatedOrgLocationUoMRecordID = v.MetricOrgLocationUoMID;
                LastMetricValue.OrgLocationUnitOfMeasureID    = v.OrgLocationUnitOfMeasureID;
                LastMetricValue.IsCalculated                  = v.MetricTypeID != 1;

                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;
                        DateHeader ah = new DateHeader();
                        ah.Date  = DateTime.MinValue;
                        ah.sDate = "&nbsp;";
                        m.DatesHeader.Add(ah);
                        m.MetricValues.Add(AnotherMetricValue);
                    }
                }
            }
            return(MetricMetricValues);
        }
Пример #6
0
        // Methods used buy MetricList control only
        public static List <Extend> List(Guid?MetricCategoryID, string NameDescriptionPart)
        {
            LinqMicajahDataContext dc = new LinqMicajahDataContext();

            List <Micajah.Common.Bll.MeasureUnit> OrgUoMs = Mc_UnitsOfMeasure.GetOrganizationUoMs();
            List <Extend> Metrics =
                (from m in dc.Metric
                 join f in dc.Frequency on m.FrequencyID equals f.FrequencyID
                 join mt in dc.MetricType on m.MetricTypeID equals mt.MetricTypeID
                 join mdt in dc.MetricDataType on m.MetricDataTypeID equals mdt.MetricDataTypeID
                 join _mc in dc.ViewnameMetricCategory on new { InstanceId = (Guid?)m.InstanceId, m.MetricCategoryID } equals new { _mc.InstanceId, _mc.MetricCategoryID } into __mc
                 join _mch in dc.ViewHierarchyMetricCategory on new { InstanceId = (Guid?)m.InstanceId, m.MetricCategoryID } equals new { _mch.InstanceId, MetricCategoryID = _mch.SubMetricCategoryID } into __mch
                 from mc in __mc.DefaultIfEmpty()
                 from mch in __mch.DefaultIfEmpty()
                 where
                 m.InstanceId == LinqMicajahDataContext.InstanceId
                 &&
                 m.Status == true
                 &&
                 (MetricCategoryID == null || mch.MetricCategoryID == MetricCategoryID)
                 &&
                 (String.IsNullOrEmpty(NameDescriptionPart) || SqlMethods.Like(m.Name, '%' + NameDescriptionPart + '%') || SqlMethods.Like(m.Notes, '%' + NameDescriptionPart + '%'))
                 orderby
                 mc.FullName, m.MetricCategoryID, m.Name, m.MetricID
                 select new Extend
            {
                InstanceId = m.InstanceId,
                MetricID = m.MetricID,
                Name = m.Name /*.TrimEnd()*/,
                Notes = m.Notes,
                FrequencyID = m.FrequencyID,
                Status = m.Status,
                Created = m.Created,
                Updated = m.Updated,
                MetricCategoryID = m.MetricCategoryID,
                FrequencyName = f.Name,
                MetricCategoryName = mc.FullName,
                UnitOfMeasureID = m.UnitOfMeasureID,
                InputUnitOfMeasureID = m.InputUnitOfMeasureID,
                UnitOfMeasureName = GetMeasureUnitName(OrgUoMs, m.UnitOfMeasureID),
                InputUnitOfMeasureName = GetMeasureUnitName(OrgUoMs, m.InputUnitOfMeasureID),
                MetricTypeID = m.MetricTypeID,
                MetricDataTypeID = m.MetricDataTypeID,
                MetricDataTypeName = mdt.Name,
                MetricTypeName = mt.Name
            }).Distinct().OrderBy(k => k.MetricCategoryName).ThenBy(k => k.Name).ToList();


            List <MetricOrgLocation> Locations =
                (from m in Metrics
                 join x in dc.ViewPathExtended on new { InstanceId = (Guid?)m.InstanceId, MetricID = (Guid?)m.MetricID } equals new { x.InstanceId, x.MetricID }
                 join o in dc.ViewnameOrgLocation on new { x.InstanceId, x.OrgLocationID } equals new { o.InstanceId, o.OrgLocationID }
                 select new MetricOrgLocation
            {
                MetricID = m.MetricID,
                OrgLocationID = (Guid)x.OrgLocationID,
                Name = o.FullName,
                IsVirtual = x.IsVirtual == 1
            }).Distinct().ToList();

            List <Extend> lME = new List <Extend>();

            foreach (Extend m in Metrics)
            {
                m.Name = m.Name.TrimEnd();
                m.AssignedOrgLocations =
                    (from x in Locations
                     where x.MetricID == m.MetricID
                     select x).ToList();

                if (m.AssignedOrgLocations.Count == 0)
                {
                    m.AssignedLocationsNames = String.Empty;
                    m.AssignedLocationName   = String.Empty;
                }
                else if (m.AssignedOrgLocations.Count == 1)
                {
                    m.AssignedLocationsNames = String.Empty;
                    m.AssignedLocationName   = m.AssignedOrgLocations[0].Name + (m.AssignedOrgLocations[0].IsVirtual ? " (related input)" : String.Empty);
                }
                else if (m.AssignedOrgLocations.Count > 1)
                {
                    StringBuilder LocationNames = new StringBuilder();
                    foreach (MetricOrgLocation mol in m.AssignedOrgLocations)
                    {
                        if (LocationNames.Length > 0)
                        {
                            LocationNames.Append("<br />");
                        }
                        LocationNames.Append(mol.Name + (mol.IsVirtual ? " (related input)" : String.Empty));
                    }
                    m.AssignedLocationsNames = LocationNames.ToString();
                    m.AssignedLocationName   = "Multiple Org Locations";
                }

                lME.Add(m);
            }



            /*ISingleResult<Sp_SelectFilterMetricsResult> result = dc.Sp_SelectFilterMetrics(LinqMicajahDataContext.InstanceId, MetricCategoryID, String.IsNullOrEmpty(NameDescriptionPart) ? null : NameDescriptionPart);
             *
             *
             * foreach (Sp_SelectFilterMetricsResult me in result)
             * {
             *  Extend m = new Extend();
             *  m.InstanceId = (Guid)me.InstanceId;
             *  m.MetricID = (Guid)me.MetricID;
             *  m.Name = me.Name.TrimEnd();
             *  m.Notes = me.Notes;
             *  m.FrequencyID = (int)me.FrequencyID;
             *  m.Status = me.Status;
             *  m.Created = (DateTime)me.Created;
             *  m.Updated = me.Updated;
             *  m.MetricCategoryID = me.MetricCategoryID == null ? null : (me.Status == true ? me.MetricCategoryID : null);
             *  m.FrequencyName = me.FrequencyName;
             *  m.MetricCategoryName = me.MetricCategoryName;
             *
             *  m.UnitOfMeasureID = me.UnitOfMeasureID;
             *  m.InputUnitOfMeasureID = me.InputUnitOfMeasureID;
             *  m.UnitOfMeasureName = GetMeasureUnitName(OrgUoMs, me.UnitOfMeasureID);
             *  m.InputUnitOfMeasureName = GetMeasureUnitName(OrgUoMs, me.InputUnitOfMeasureID);
             *  m.MetricTypeID = (int)me.MetricTypeID;
             *  m.MetricDataTypeID = (int)me.MetricDataTypeID;
             *  m.MetricDataTypeName = me.MetricDataTypeName;
             *  m.MetricTypeName = me.MetricTypeName;
             *
             *  m.AssignedOrgLocations =
             *          (from x in dc.ViewPathExtended
             *           join oln in dc.ViewnameOrgLocation on new { x.InstanceId, x.OrgLocationID } equals new { oln.InstanceId, oln.OrgLocationID }
             *           where x.InstanceId == m.InstanceId && x.MetricID == m.MetricID
             *
             *           select new MetricOrgLocation
             *           {
             *               Name = oln.FullName,
             *               IsVirtual = x.IsVirtual == 1
             *           }).ToList();
             *  if (m.AssignedOrgLocations.Count == 0)
             *  {
             *      m.AssignedLocationsNames = String.Empty;
             *      m.AssignedLocationName = String.Empty;
             *  }
             *  else if (m.AssignedOrgLocations.Count == 1)
             *  {
             *      m.AssignedLocationsNames = String.Empty;
             *      m.AssignedLocationName = m.AssignedOrgLocations[0].Name + (m.AssignedOrgLocations[0].IsVirtual ? " (Virtual)" : String.Empty);
             *  }
             *  else if (m.AssignedOrgLocations.Count > 1)
             *  {
             *      StringBuilder LocationNames = new StringBuilder();
             *      foreach (MetricOrgLocation mol in m.AssignedOrgLocations)
             *      {
             *          if (LocationNames.Length > 0)
             *              LocationNames.Append("<br />");
             *          LocationNames.Append(mol.Name + (mol.IsVirtual ? " (Virtual)" : String.Empty));
             *      }
             *      m.AssignedLocationsNames = LocationNames.ToString();
             *      m.AssignedLocationName = "Multiple Org Locations";
             *  }
             *
             *  lME.Add(m);
             * }*/
            return(lME);
        }