Exemplo n.º 1
0
        // DEBUG: Dataset-based routine --> Will be deprecated
        public static string ClusterStatusBlock(DataSet srcDataSet, CustomerConfig customerCfg)
        {
            StringBuilder sb = new StringBuilder();
            DataTable tbl = srcDataSet.Tables["Meter"];

            // Loop through each meter
            foreach (DataRow row in tbl.Rows)
            {
                sb.AppendLine("<div class=\" rounded-corners NewMeterBlock\"> ");
                sb.AppendLine("<div class=\"NewMeterTitle\">Meter " + row["ID"].ToString());
                sb.AppendLine("<span class=\"NewMeterSubTitle\"> [Idle For: " + row["imin"].ToString() + " minutes]  [Last Updated: " + row["upTSString"].ToString() + "]");
                sb.AppendLine("</span> ");
                sb.AppendLine("</div> ");

                // Loop through each bay of current meter
                DataRow[] MeterBays = srcDataSet.Tables["Bay"].Select("Meter_Id = " + row["Meter_Id"]);
                foreach (DataRow bayRow in MeterBays)
                {
                    sb.AppendLine("<div class=\"NewBayBlockGavin\"> ");
                    sb.AppendLine("<div class=\"NewBayTitle\">" + bayRow["ID"].ToString() + "</div> ");

                    // Determine the payment expiration state
                    Duncan.PEMS.SpaceStatus.Models.ExpiryState es = Duncan.PEMS.SpaceStatus.Models.ExpiryState.Inoperational;
                    try
                    {
                        if (bayRow["ExpiryState"] != DBNull.Value)
                        {
                            es = (Duncan.PEMS.SpaceStatus.Models.ExpiryState)bayRow["ExpiryState"];
                        }
                    }
                    catch
                    {
                        es = Duncan.PEMS.SpaceStatus.Models.ExpiryState.Inoperational;
                    }

                    // Output appropriate HTML elements for the expiration state
                    if (es == Duncan.PEMS.SpaceStatus.Models.ExpiryState.Safe)
                    {
                        sb.AppendLine("<div class=\"CenteredBlock BayExpiryTimeSafe\">" + bayRow["ExpiryTimeString"].ToString() + "</div> ");
                    }
                    else if (es == Duncan.PEMS.SpaceStatus.Models.ExpiryState.Expired)
                    {
                        sb.AppendLine("<div class=\"CenteredBlock BayExpiryTimeExpired\">" + bayRow["ExpiryTimeString"].ToString() + "</div> ");
                    }
                    else if (es == Duncan.PEMS.SpaceStatus.Models.ExpiryState.Critical)
                    {
                        sb.AppendLine("<div class=\"CenteredBlock BayExpiryTimeCritical\">" + bayRow["ExpiryTimeString"].ToString() + "</div> ");
                    }
                    else if (es == Duncan.PEMS.SpaceStatus.Models.ExpiryState.Grace)
                    {
                        sb.AppendLine("<div class=\"CenteredBlock BayExpiryTimeGracePeriod\">" + bayRow["ExpiryTimeString"].ToString() + "</div> ");
                    }
                    else
                    {
                        sb.AppendLine("<div class=\"CenteredBlock NewBayExpiryTimeInoperational\">" + bayRow["ExpiryTimeString"].ToString() + "</div> ");
                    }

                    /////////////////////////////

                    // Get the vehicle occupancy state
                    Duncan.PEMS.SpaceStatus.Models.OccupancyState os = Duncan.PEMS.SpaceStatus.Models.OccupancyState.NotAvailable;
                    try
                    {
                        if (bayRow["OccupancyState"] != DBNull.Value)
                            os = (Duncan.PEMS.SpaceStatus.Models.OccupancyState)bayRow["OccupancyState"];
                    }
                    catch
                    {
                        os = Duncan.PEMS.SpaceStatus.Models.OccupancyState.NotAvailable;
                    }

                    // Output appropriate HTML elements for the occupancy state
                    switch (os)
                    {
                        case Duncan.PEMS.SpaceStatus.Models.OccupancyState.Empty:
                            sb.AppendLine("<div class=\"CenteredBlock BayOccupancyEmpty\"></div>");
                            sb.AppendLine("<div class=\"LastInOutTimeOut\">" + BindShortTimeSpan(bayRow, "TimeSinceLastInOut", "OccupancyState", customerCfg) + "</div>");
                            sb.AppendLine("<div class=\"LastInOutTimeOfDay\"> <span>" + BindTimeOfDay(bayRow, "LastInOutTime", "OccupancyState", customerCfg) + "</span> </div>");
                            break;
                        case Duncan.PEMS.SpaceStatus.Models.OccupancyState.NotAvailable:
                            sb.AppendLine("<div class=\"CenteredBlock BayOccupancyNotAvailable\"></div>");
                            sb.AppendLine("<div class=\"LastInOutTimeNA\">" + BindShortTimeSpan(bayRow, "TimeSinceLastInOut", "OccupancyState", customerCfg) + "</div>");
                            sb.AppendLine("<div class=\"LastInOutTimeOfDayNA\"> <span>" + BindTimeOfDay(bayRow, "LastInOutTime", "OccupancyState", customerCfg) + "</span> </div>");
                            break;
                        case Duncan.PEMS.SpaceStatus.Models.OccupancyState.Occupied:
                            sb.AppendLine("<div class=\"CenteredBlock BayOccupancyOccupied\"></div>");
                            sb.AppendLine("<div class=\"LastInOutTimeIn\">" + BindShortTimeSpan(bayRow, "TimeSinceLastInOut", "OccupancyState", customerCfg) + "</div>");
                            sb.AppendLine("<div class=\"LastInOutTimeOfDay\">" + BindTimeOfDay(bayRow, "LastInOutTime", "OccupancyState", customerCfg) + "</div>");
                            break;
                        case Duncan.PEMS.SpaceStatus.Models.OccupancyState.OutOfDate:
                            sb.AppendLine("<div class=\"CenteredBlock BayOccupancyOutOfDate\"></div>");
                            sb.AppendLine("<div class=\"LastInOutTimeNA\">" + BindShortTimeSpan(bayRow, "TimeSinceLastInOut", "OccupancyState", customerCfg) + "</div>");
                            sb.AppendLine("<div class=\"LastInOutTimeOfDayNA\"> <span>" + BindTimeOfDay(bayRow, "LastInOutTime", "OccupancyState", customerCfg) + "</span> </div>");
                            break;
                        case Duncan.PEMS.SpaceStatus.Models.OccupancyState.Violation:
                            sb.AppendLine("<div class=\"CenteredBlock Violation\"></div>");
                            sb.AppendLine("<div class=\"LastInOutTimeIn\">" + BindShortTimeSpan(bayRow, "TimeSinceLastInOut", "OccupancyState", customerCfg) + "</div>");
                            sb.AppendLine("<div class=\"LastInOutTimeOfDay\"> <span>" + BindTimeOfDay(bayRow, "LastInOutTime", "OccupancyState", customerCfg) + "</span> </div>");
                            break;
                        case Duncan.PEMS.SpaceStatus.Models.OccupancyState.MeterFeeding:
                            sb.AppendLine("<div class=\"CenteredBlock MeterFeeding\"></div>");
                            sb.AppendLine("<div class=\"LastInOutTimeIn\">" + BindShortTimeSpan(bayRow, "TimeSinceLastInOut", "OccupancyState", customerCfg) + "</div>");
                            sb.AppendLine("<div class=\"LastInOutTimeOfDay\"> <span>" + BindTimeOfDay(bayRow, "LastInOutTime", "OccupancyState", customerCfg) + "</span> </div>");
                            break;
                        case Duncan.PEMS.SpaceStatus.Models.OccupancyState.Unknown:
                            sb.AppendLine("<div class=\"CenteredBlock BayOccupancyNotAvailable\"></div>");
                            sb.AppendLine("<div class=\"LastInOutTimeNA\">" + BindShortTimeSpan(bayRow, "TimeSinceLastInOut", "OccupancyState", customerCfg) + "</div>");
                            sb.AppendLine("<div class=\"LastInOutTimeOfDayNA\"> <span>" + BindTimeOfDay(bayRow, "LastInOutTime", "OccupancyState", customerCfg) + "</span> </div>");
                            break;
                    }

                    sb.AppendLine("</div> "); // End of Bay block
                }

                sb.AppendLine("</div> "); // End of Meter block
            }

            // Finalize the result from the string builder contents
            return sb.ToString();
        }
Exemplo n.º 2
0
        // Strongly type input instead of dataset
        public static string ClusterStatusBlock(List<SpaceStatusModel> modelForView, CustomerConfig customerCfg)
        {
            StringBuilder sb = new StringBuilder();

            // Build list of unique meters -- which will be our grouping
            List<int> uniqueMeterIDs = new List<int>();
            foreach (SpaceStatusModel nextSpaceModel in modelForView)
            {
                if (uniqueMeterIDs.IndexOf(nextSpaceModel.MeterID) == -1)
                    uniqueMeterIDs.Add(nextSpaceModel.MeterID);
            }

            // Loop for each meter
            foreach (int nextMeterID in uniqueMeterIDs)
            {
                // Build list of indexes inside modelForView that are for the current meter
                List<int> itemIndexesForCurrentMeter = new List<int>();
                for (int loIdx = 0; loIdx < modelForView.Count; loIdx++)
                {
                    if (modelForView[loIdx].MeterID == nextMeterID)
                        itemIndexesForCurrentMeter.Add(loIdx);
                }

                SpaceStatusModel currentSpaceStatusModel = modelForView[itemIndexesForCurrentMeter[0]];

                sb.AppendLine("<div class=\" rounded-corners NewMeterBlock\"> ");
                sb.AppendLine("<div class=\"NewMeterTitle\">Meter " + currentSpaceStatusModel.MeterID.ToString());
                sb.AppendLine("<span class=\"NewMeterSubTitle\"> [Idle For: " + currentSpaceStatusModel.Meter_imin.ToString() + " minutes]  [Last Updated: " +
                    currentSpaceStatusModel.Meter_upTS.ToString() + "]"); // DEBUG: We need formatted string like:  row["upTSString"].ToString() 
                sb.AppendLine("</span> ");
                sb.AppendLine("</div> ");

                // Loop through each bay of current meter
                for (int loIdx = 0; loIdx < itemIndexesForCurrentMeter.Count; loIdx++)
                {
                    currentSpaceStatusModel = modelForView[itemIndexesForCurrentMeter[loIdx]];

                    sb.AppendLine("<div class=\"NewBayBlockGavin\"> ");
                    sb.AppendLine("<div class=\"NewBayTitle\">" + currentSpaceStatusModel.BayID.ToString() + "</div> ");

                    // Determine the payment expiration state
                    Duncan.PEMS.SpaceStatus.Models.ExpiryState es = currentSpaceStatusModel.BayExpiryState;

                    string ExpiryTimeString = currentSpaceStatusModel.GetExpiryTimeString(customerCfg);

                    // Output appropriate HTML elements for the expiration state
                    if (es == Duncan.PEMS.SpaceStatus.Models.ExpiryState.Safe)
                    {
                        sb.AppendLine("<div class=\"CenteredBlock BayExpiryTimeSafe\">" + ExpiryTimeString + "</div> ");
                    }
                    else if (es == Duncan.PEMS.SpaceStatus.Models.ExpiryState.Expired)
                    {
                        sb.AppendLine("<div class=\"CenteredBlock BayExpiryTimeExpired\">" + ExpiryTimeString + "</div> ");
                    }
                    else if (es == Duncan.PEMS.SpaceStatus.Models.ExpiryState.Critical)
                    {
                        sb.AppendLine("<div class=\"CenteredBlock BayExpiryTimeCritical\">" + ExpiryTimeString + "</div> ");
                    }
                    else if (es == Duncan.PEMS.SpaceStatus.Models.ExpiryState.Grace)
                    {
                        sb.AppendLine("<div class=\"CenteredBlock BayExpiryTimeGracePeriod\">" + ExpiryTimeString + "</div> ");
                    }
                    else
                    {
                        sb.AppendLine("<div class=\"CenteredBlock NewBayExpiryTimeInoperational\">" + ExpiryTimeString + "</div> ");
                    }

                    /////////////////////////////

                    // Get the vehicle occupancy state
                    Duncan.PEMS.SpaceStatus.Models.OccupancyState os = currentSpaceStatusModel.BayOccupancyState;

                    // Output appropriate HTML elements for the occupancy state
                    string TimeSinceLastInOut = BindShortTimeSpan(currentSpaceStatusModel.TimeSinceLastInOut, currentSpaceStatusModel.BayOccupancyState, customerCfg);
                    string LastInOutTime = BindTimeOfDay(currentSpaceStatusModel.BayVehicleSensingTimestamp, currentSpaceStatusModel.BayOccupancyState, customerCfg);
                    switch (os)
                    {
                        case Duncan.PEMS.SpaceStatus.Models.OccupancyState.Empty:
                            sb.AppendLine("<div class=\"CenteredBlock BayOccupancyEmpty\"></div>");
                            sb.AppendLine("<div class=\"LastInOutTimeOut\">" + TimeSinceLastInOut + "</div>");
                            sb.AppendLine("<div class=\"LastInOutTimeOfDay\"> <span>" + LastInOutTime + "</span> </div>");
                            break;
                        case Duncan.PEMS.SpaceStatus.Models.OccupancyState.NotAvailable:
                            sb.AppendLine("<div class=\"CenteredBlock BayOccupancyNotAvailable\"></div>");
                            sb.AppendLine("<div class=\"LastInOutTimeNA\">" + TimeSinceLastInOut + "</div>");
                            sb.AppendLine("<div class=\"LastInOutTimeOfDayNA\"> <span>" + LastInOutTime + "</span> </div>");
                            break;
                        case Duncan.PEMS.SpaceStatus.Models.OccupancyState.Occupied:
                            sb.AppendLine("<div class=\"CenteredBlock BayOccupancyOccupied\"></div>");
                            sb.AppendLine("<div class=\"LastInOutTimeIn\">" + TimeSinceLastInOut + "</div>");
                            sb.AppendLine("<div class=\"LastInOutTimeOfDay\">" + LastInOutTime + "</div>");
                            break;
                        case Duncan.PEMS.SpaceStatus.Models.OccupancyState.OutOfDate:
                            sb.AppendLine("<div class=\"CenteredBlock BayOccupancyOutOfDate\"></div>");
                            sb.AppendLine("<div class=\"LastInOutTimeNA\">" + TimeSinceLastInOut + "</div>");
                            sb.AppendLine("<div class=\"LastInOutTimeOfDayNA\"> <span>" + LastInOutTime + "</span> </div>");
                            break;
                        case Duncan.PEMS.SpaceStatus.Models.OccupancyState.Violation:
                            sb.AppendLine("<div class=\"CenteredBlock Violation\"></div>");
                            sb.AppendLine("<div class=\"LastInOutTimeIn\">" + TimeSinceLastInOut + "</div>");
                            sb.AppendLine("<div class=\"LastInOutTimeOfDay\"> <span>" + LastInOutTime + "</span> </div>");
                            break;
                        case Duncan.PEMS.SpaceStatus.Models.OccupancyState.MeterFeeding:
                            sb.AppendLine("<div class=\"CenteredBlock MeterFeeding\"></div>");
                            sb.AppendLine("<div class=\"LastInOutTimeIn\">" + TimeSinceLastInOut + "</div>");
                            sb.AppendLine("<div class=\"LastInOutTimeOfDay\"> <span>" + LastInOutTime + "</span> </div>");
                            break;
                        case Duncan.PEMS.SpaceStatus.Models.OccupancyState.Unknown:
                            sb.AppendLine("<div class=\"CenteredBlock BayOccupancyNotAvailable\"></div>");
                            sb.AppendLine("<div class=\"LastInOutTimeNA\">" + TimeSinceLastInOut + "</div>");
                            sb.AppendLine("<div class=\"LastInOutTimeOfDayNA\"> <span>" + LastInOutTime + "</span> </div>");
                            break;
                    }

                    sb.AppendLine("</div> "); // End of Bay block
                }

                sb.AppendLine("</div> "); // End of Meter block
            }

            // Finalize the result from the string builder contents
            return sb.ToString();
        }