Пример #1
0
        public static double?CalculateTotalValue(LinqMicajahDataContext dc, Guid OrganizationId, Guid InstanceId, Guid MetricID, Guid?OrgLocationID, Guid?UomID, DateTime BeginDate, DateTime?EndDate, bool IncludeSubLocation, enTotalValueType TotalValueType, bool IgnoreUnitOfMessure)
        {
            DateTime d2000     = new DateTime(2000, 1, 1);
            int      Begin2000 = (int)(BeginDate - d2000).TotalDays;
            int      End2000   = EndDate == null ? int.MaxValue : (int)((((DateTime)EndDate)) - d2000).TotalDays;
            var      mvs       = dc.Sp_CalcMetricValue(InstanceId, MetricID, OrgLocationID, Begin2000, End2000);

            var m = Bll.Metric.Get(MetricID);

            if (m == null)
            {
                return(null);
            }
            if (IgnoreUnitOfMessure)
            {
                UomID = m.UnitOfMeasureID;
            }

            double v          = 0;
            bool   ValueExist = false;

            foreach (var mv in mvs)
            {
                if (mv.Val == null || mv.Val == 0)
                {
                    continue;
                }
                ValueExist = true;
                if (mv.UnitOfMeasureID != UomID && mv.UnitOfMeasureID != null && UomID != null)
                {
                    double?v0 = Mc_UnitsOfMeasure.ConvertValue((double)((decimal)(mv.Val)), (Guid)mv.UnitOfMeasureID, (Guid)UomID, OrganizationId);
                    if (v0 != null)
                    {
                        v += (double)v0;
                    }
                }
                else
                {
                    v += (double)mv.Val;
                }
            }

            return(ValueExist ? v : (double?)null);
        }