Exemple #1
0
        public static string FormatValue(MetricValue.Extend Val, bool BeEmpty)
        {
            string FormatString = string.Empty;

            if (String.IsNullOrEmpty(Val.Value) || BeEmpty)
            {
                FormatString = "&nbsp";
            }
            else
            {
                FormatString = Val.Value.ToString();
                if (Val.MetricDataTypeID == 1 && Val.NODecPlaces != null)
                {
                    try
                    {
                        decimal dv = Decimal.Parse(Val.Value, System.Globalization.NumberStyles.Any);
                        FormatString = dv.ToString("N" + ((int)Val.NODecPlaces));
                    }
                    catch { }
                }
            }
            return(FormatString);
        }
        private static void PushMetricValue(MetricOrgValue mmv, MetricValue.Extend mv, List <DateHeader> hl)
        {
            if (mmv == null)
            {
                return;
            }
            DateTime NextDate = DateTime.MinValue;
            DateTime AddDate  = mv == null ? DateTime.MinValue : mv.Date;

            while (mmv.MetricValues.Count < hl.Count && (NextDate = hl[mmv.MetricValues.Count].Date) > AddDate)
            {
                MetricValue.Extend CalculatedValue = new MetricValue.Extend();
                CalculatedValue.InstanceId           = mmv.InstanceId;
                CalculatedValue.MetricValueID        = Guid.Empty;
                CalculatedValue.MetricID             = mmv.MetricID;
                CalculatedValue.Date                 = NextDate;
                CalculatedValue.OrgLocationID        = mmv.OrgLocationID;
                CalculatedValue.FrequencyID          = mmv.FrequencyID;
                CalculatedValue.Value                = null;
                CalculatedValue.Verified             = false;
                CalculatedValue.Approved             = false;
                CalculatedValue.FilesAttached        = false;
                CalculatedValue.ReviewUpdated        = false;
                CalculatedValue.MissedCalc           = false;
                CalculatedValue.MetricDataTypeID     = 1;
                CalculatedValue.InputUnitOfMeasureID = mmv.InputUnitOfMeasureID;
                CalculatedValue.IsCalculated         = (int)mmv.MetricTypeID > 1;
                CalculatedValue.IsAbsent             = true;
                mmv.MetricValues.Add(CalculatedValue);
            }

            if (mv != null && mmv.MetricValues.Count < hl.Count && hl[mmv.MetricValues.Count].Date == mv.Date)
            {
                mmv.MetricValues.Add(mv);
            }
        }
        public static void SaveBulkValues(List <Bll.MetricOrgLocationUoM> MetricOrgLocationUoMList, List <Bll.MetricValue.Extend> NewValues, List <Bll.MetricValue.Extend> OldValues, Micajah.Common.Security.UserContext CurrentUser, bool InputMode)
        {
            using (LinqMicajahDataContext dc = new LinqMicajahDataContext())
            {
                foreach (MetricOrgLocationUoM uom in MetricOrgLocationUoMList)
                {
                    MetricOrgLocationUoM MOUoM =
                        (from muom in dc.MetricOrgLocationUoM
                         where
                         muom.MetricID == uom.MetricID &&
                         muom.InstanceId == LinqMicajahDataContext.InstanceId &&
                         muom.OrgLocationID == uom.OrgLocationID
                         select muom).FirstOrNull();
                    if (MOUoM == null)
                    {
                        Bll.MetricOrgLocationUoM muom = new Bll.MetricOrgLocationUoM();
                        muom.MetricID             = uom.MetricID;
                        muom.OrgLocationID        = uom.OrgLocationID;
                        muom.InputUnitOfMeasureID = uom.InputUnitOfMeasureID;
                        dc.MetricOrgLocationUoM.InsertOnSubmit(muom);
                    }
                    else
                    if (uom.InputUnitOfMeasureID != MOUoM.InputUnitOfMeasureID)
                    {
                        MOUoM.InputUnitOfMeasureID = uom.InputUnitOfMeasureID;
                    }
                }
                dc.SubmitChanges();
                Metric metric = null;
                for (int i = 0; i < NewValues.Count; i++)
                {
                    MetricValue.Extend NewValue = NewValues[i];
                    MetricValue.Extend OldValue = OldValues[i];
                    bool UpdateMetric           = false;
                    if (metric == null)
                    {
                        UpdateMetric = true;
                    }
                    else if (metric.MetricID != NewValue.MetricID)
                    {
                        UpdateMetric = true;
                    }
                    if (UpdateMetric)
                    {
                        metric =
                            (from m in dc.Metric
                             where
                             m.MetricID == NewValue.MetricID &&
                             m.InstanceId == LinqMicajahDataContext.InstanceId &&
                             m.Status == true
                             select m).FirstOrNull();
                    }
                    if (metric != null)
                    {
                        MetricValue metricValue =
                            (from mv in dc.MetricValue
                             where
                             mv.MetricID == NewValue.MetricID &&
                             mv.InstanceId == LinqMicajahDataContext.InstanceId &&
                             mv.Status == true &&
                             mv.Date == NewValue.Date &&
                             mv.FrequencyID == metric.FrequencyID &&
                             mv.OrgLocationID == NewValue.OrgLocationID
                             select mv).FirstOrNull();

                        string ConvertedValue = NewValue.Value;
                        if (metric.UnitOfMeasureID != NewValue.InputUnitOfMeasureID && metric.MetricDataTypeID == 1 && NewValue.InputUnitOfMeasureID != null && metric.UnitOfMeasureID != null)
                        {
                            ConvertedValue = Mc_UnitsOfMeasure.ConvertValue(NewValue.Value, (Guid)NewValue.InputUnitOfMeasureID, (Guid)metric.UnitOfMeasureID);
                        }

                        if (metricValue == null)
                        {
                            Bll.MetricValue mv = new Bll.MetricValue();
                            mv.MetricValueID    = NewValue.MetricValueID = Guid.NewGuid();
                            mv.FrequencyID      = metric.FrequencyID;
                            mv.UnitOfMeasureID  = metric.UnitOfMeasureID;
                            mv.MetricDataTypeID = metric.MetricDataTypeID;
                            mv.ConvertedValue   = ConvertedValue;
                            mv.InputUserId      = CurrentUser.UserId;
                            mv.Approved         = false;
                            mv.ReviewUpdated    = false;
                            mv.ApproveUserId    = null;
                            mv.Notes            = null;
                            mv.FilesAttached    = false;
                            mv.IsCalc           = true;
                            mv.InProcess        = false;

                            mv.MetricID             = NewValue.MetricID;
                            mv.OrgLocationID        = NewValue.OrgLocationID;
                            mv.Date                 = NewValue.Date;
                            mv.InputUnitOfMeasureID = NewValue.InputUnitOfMeasureID;
                            mv.Value                = NewValue.Value;
                            dc.MetricValue.InsertOnSubmit(mv);
                        }
                        else
                        {
                            metricValue.MetricDataTypeID     = metric.MetricDataTypeID;
                            metricValue.InputUnitOfMeasureID = NewValue.InputUnitOfMeasureID;
                            metricValue.UnitOfMeasureID      = metric.UnitOfMeasureID;
                            metricValue.ConvertedValue       = ConvertedValue;
                            metricValue.Approved             = NewValue.Approved;
                            metricValue.ReviewUpdated        = (!InputMode) ? false : (metricValue.Approved == null && NewValue.Approved == null);
                            if (!InputMode)
                            {
                                if (metricValue.Approved != NewValue.Approved)
                                {
                                    metricValue.ApproveUserId = CurrentUser.UserId;
                                }
                                if (metricValue.Value != NewValue.Value)
                                {
                                    metricValue.InputUserId = CurrentUser.UserId;
                                }
                            }
                            else
                            {
                                metricValue.InputUserId = CurrentUser.UserId;
                            }
                            metricValue.Value  = NewValue.Value;
                            metricValue.IsCalc = true;
                        }
                    }
                }
                dc.SubmitChanges();
                for (int i = 0; i < NewValues.Count; i++)
                {
                    MetricValue.Extend NewValue = NewValues[i];
                    MetricValue.Extend OldValue = OldValues[i];
                    Bll.Mc_User.Extend mue      = Bll.Mc_User.GetValueInputUser(dc, OldValue.MetricValueID);
                    // build mail to data collector if status or comment were changed
                    if ((!InputMode) && (OldValue.Approved != NewValue.Approved))
                    {
                        Bll.MetricValueChangeLog.LogChange(dc,
                                                           OldValue.MetricValueID == Guid.Empty ? NewValue.MetricValueID : OldValue.MetricValueID,
                                                           Bll.MetricValueChangeTypeEnum.StatusChanged,
                                                           OldValue.MetricValueID == Guid.Empty ? "Pending" : (OldValue.Approved == null ? "Under Review" : ((bool)OldValue.Approved ? "Approved" : "Pending")),
                                                           NewValue.Approved == null ? "Under Review" : ((bool)NewValue.Approved ? "Approved" : "Pending"),
                                                           Utils.Mail.BuildLogMessageBody(OldValue, NewValue, String.Empty, CurrentUser, mue, Bll.MetricValueChangeTypeEnum.StatusChanged));

                        if (NewValue.Approved == null && mue != null)
                        {
                            Utils.Mail.Send(mue.Email, mue.FullName, "MetricTrac - Value Status is changed", Utils.Mail.BuildEmailBody(OldValue, NewValue, String.Empty, CurrentUser));
                        }
                    }
                    // record in change log
                    if (OldValue.MetricValueID == Guid.Empty)
                    {
                        Bll.MetricValueChangeLog.LogChange(NewValue.MetricValueID,
                                                           MetricTrac.Bll.MetricValueChangeTypeEnum.ValueEntered,
                                                           String.Empty,
                                                           NewValue.Value,
                                                           Utils.Mail.BuildLogMessageBody(OldValue, NewValue, "Bulk Edit", CurrentUser, mue, MetricTrac.Bll.MetricValueChangeTypeEnum.ValueEntered));
                    }
                    else
                    if (OldValue.Value != NewValue.Value)
                    {
                        Bll.MetricValueChangeLog.LogChange(OldValue.MetricValueID,
                                                           MetricTrac.Bll.MetricValueChangeTypeEnum.ValueChanged,
                                                           OldValue.Value,
                                                           NewValue.Value,
                                                           Utils.Mail.BuildLogMessageBody(OldValue, NewValue, "Bulk Edit", CurrentUser, mue, MetricTrac.Bll.MetricValueChangeTypeEnum.ValueChanged));
                    }
                }
                dc.SubmitChanges();
            }
        }
Exemple #4
0
        protected void ldsMetricValue_Updating(object sender, LinqDataSourceUpdateEventArgs e)
        {
            // save previous value
            MetricTrac.Bll.MetricValue.Extend OldMetricValue = MVS;
            // get new data
            string Value = String.Empty;

            if (rntValue.Visible)
            {
                Value = rntValue.Value.ToString();
            }
            else
            if (tbValue.Visible)
            {
                Value = tbValue.Text;
            }
            else
            if (chbValue.Visible)
            {
                Value = chbValue.Checked ? bool.TrueString : bool.FalseString;
            }
            else
            if (rdpDateValue.Visible)
            {
                Value = rdpDateValue.SelectedDate.ToString();
            }
            ValueArgument = Value;
            Guid?ActualUoMID = null;

            if (!String.IsNullOrEmpty(ddlInputUnitOfMeasure.SelectedValue))
            {
                ActualUoMID = new Guid(ddlInputUnitOfMeasure.SelectedValue);
            }
            string CustomMetricAlias = null; // if pass null to Isert/Update - nothing changed. It's possible if custom names disabled or bulk edit
            string CustomMetricCode  = null;

            if (MVS.AllowMetricCustomNames)
            {
                CustomMetricAlias = tbAlias.Text;
                CustomMetricCode  = tbCode.Text;
            }

            bool?Approved = false;

            switch (ddlApprovalStatus.SelectedValue)
            {
            case "":
                Approved = null;
                break;

            case "True":
                Approved = true;
                break;

            case "False":
            default:
                Approved = false;
                break;
            }
            ValueArgument = Value + "|" + Approved.ToString();
            string comments     = tbComments.Text;
            string Notes        = ((Micajah.Common.WebControls.TextBox)mfMetricValue.FindFieldControl("Notes")).Text;
            Guid   CurentUserId = Micajah.Common.Security.UserContext.Current.UserId;
            //------------------------------

            Guid _ValueID = Bll.MetricValue.InsertOrUpdate(
                MetricID,
                OperationDate,
                OrgLocationID,
                !FilesUpload.IsEmpty,
                Mode == DataMode.Approve,
                ActualUoMID,
                OldMetricValue.Value,
                Value,
                OldMetricValue.Approved,
                Approved,
                CurentUserId,
                Notes,
                CustomMetricAlias,
                CustomMetricCode);

            if (_ValueID != Guid.Empty)
            {
                FilesUpload.LocalObjectId = _ValueID.ToString();
                if (!FilesUpload.AcceptChanges())
                {
                    if (FilesUpload.ErrorOccurred)
                    {
                        string _errorMessage = String.Empty;
                        foreach (string s in FilesUpload.ErrorMessages)
                        {
                            _errorMessage += s + "\n";
                        }
                        this.ErrorMessage = _errorMessage;
                    }
                }
            }
            else // change this error handler after adding central error tracker
            {
                this.ErrorMessage = "Unable to save changes. Please, try again later.";
            }
            Bll.MetricValue.Extend NewMetricValue = Bll.MetricValue.Get(MetricID, OperationDate, OrgLocationID);
            Bll.Mc_User.Extend     mue            = Bll.Mc_User.GetValueInputUser(OldMetricValue.MetricValueID);
            // build mail to data collector if status or comment were changed
            if ((Mode == DataMode.Approve) && ((!String.IsNullOrEmpty(comments)) || (OldMetricValue.Approved != NewMetricValue.Approved)))
            {
                string MailCaption = OldMetricValue.Approved != NewMetricValue.Approved ? "MetricTrac - Value Status is changed" : "SustainApp - Value has new comment from Data Approver";
                if (OldMetricValue.Approved != NewMetricValue.Approved)
                {
                    Bll.MetricValueChangeLog.LogChange(NewMetricValue.MetricValueID,
                                                       Bll.MetricValueChangeTypeEnum.StatusChanged,
                                                       OldMetricValue.ApprovalStatus,
                                                       NewMetricValue.ApprovalStatus,
                                                       Utils.Mail.BuildLogMessageBody(OldMetricValue, NewMetricValue, comments, Micajah.Common.Security.UserContext.Current, mue, Bll.MetricValueChangeTypeEnum.StatusChanged));
                }
                else
                {
                    Bll.MetricValueChangeLog.LogChange(NewMetricValue.MetricValueID,
                                                       Bll.MetricValueChangeTypeEnum.CommentToDataCollector,
                                                       null,
                                                       comments,
                                                       Utils.Mail.BuildLogMessageBody(OldMetricValue, NewMetricValue, comments, Micajah.Common.Security.UserContext.Current, mue, Bll.MetricValueChangeTypeEnum.CommentToDataCollector));
                }
                if (NewMetricValue.Approved == null && mue != null)
                {
                    Utils.Mail.Send(mue.Email, mue.FullName, MailCaption, Utils.Mail.BuildEmailBody(OldMetricValue, NewMetricValue, comments, Micajah.Common.Security.UserContext.Current));
                }
            }


            // record in change log
            // first time value entered
            if (OldMetricValue.MetricValueID == Guid.Empty)
            {
                Bll.MetricValueChangeLog.LogChange(NewMetricValue.MetricValueID,
                                                   MetricTrac.Bll.MetricValueChangeTypeEnum.ValueEntered,
                                                   String.Empty,
                                                   NewMetricValue.Value,
                                                   Utils.Mail.BuildLogMessageBody(OldMetricValue, NewMetricValue, Notes, Micajah.Common.Security.UserContext.Current, mue, MetricTrac.Bll.MetricValueChangeTypeEnum.ValueEntered));
            }
            else
            {
                // value changed
                if (OldMetricValue.Value != NewMetricValue.Value)
                {
                    Bll.MetricValueChangeLog.LogChange(MVS.MetricValueID,
                                                       MetricTrac.Bll.MetricValueChangeTypeEnum.ValueChanged,
                                                       OldMetricValue.Value,
                                                       NewMetricValue.Value,
                                                       Utils.Mail.BuildLogMessageBody(OldMetricValue, NewMetricValue, Notes, Micajah.Common.Security.UserContext.Current, mue, MetricTrac.Bll.MetricValueChangeTypeEnum.ValueChanged));
                }
                // notes changed
                if (OldMetricValue.Notes != NewMetricValue.Notes)
                {
                    Bll.MetricValueChangeLog.LogChange(MVS.MetricValueID,
                                                       MetricTrac.Bll.MetricValueChangeTypeEnum.NoteChanged,
                                                       OldMetricValue.Notes,
                                                       NewMetricValue.Notes,
                                                       Utils.Mail.BuildLogMessageBody(OldMetricValue, NewMetricValue, Notes, Micajah.Common.Security.UserContext.Current, mue, MetricTrac.Bll.MetricValueChangeTypeEnum.NoteChanged));
                }
            }

            e.Cancel = true;
        }
        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);
        }
Exemple #6
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);
        }
Exemple #7
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);
        }
Exemple #8
0
 public static string FormatValue(MetricValue.Extend Val)
 {
     return(FormatValue(Val, false));
 }