private void FilterLocationList(CheckInGroupType checkInGroupType, bool remove, CheckinConfigurationHelper.LocationSelectionStrategy attributeLocationSelectionStrategy, List <CheckInSchedule> selectedSchedules) { // Order the list var checkinGroups = checkInGroupType.Groups.OrderBy(g => g.Group.Order).ToList(); foreach (var checkinGroup in checkinGroups) { // Get a list of locations that have not reached their threshold. var locationListQuery = checkinGroup.Locations .Where(l => l.Location.SoftRoomThreshold == null || KioskLocationAttendance.Get(l.Location.Id).CurrentCount <= l.Location.SoftRoomThreshold.Value); List <CheckInLocation> locationList = new List <CheckInLocation>(); if (attributeLocationSelectionStrategy == CheckinConfigurationHelper.LocationSelectionStrategy.Balance) { locationList = locationListQuery.OrderBy(l => KioskLocationAttendance.Get(l.Location.Id).CurrentCount).ToList(); } else if (attributeLocationSelectionStrategy == CheckinConfigurationHelper.LocationSelectionStrategy.FillInOrder) { locationList = locationListQuery.OrderBy(l => l.Order).ToList(); } if (selectedSchedules.Count() == 1) { // If we only have one schedule then we can just remove the other locations and not care about the schedules. FilterLocations(checkinGroup, locationList, remove); } else { // Now we have to care about schedules. FilterLocationSchedules(checkinGroup, locationList, selectedSchedules, remove); } } }
/// <summary> /// Handles the ItemDataBound event of the rLocations control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Web.UI.WebControls.RepeaterItemEventArgs"/> instance containing the event data.</param> protected void rLocations_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e) { object locationDataItem = e.Item.DataItem; if (locationDataItem != null) { var lbOpen = e.Item.FindControl("lbOpen") as LinkButton; var lbClose = e.Item.FindControl("lbClose") as LinkButton; var isActive = ( bool )locationDataItem.GetPropertyValue("IsActive"); if (isActive) { lbClose.RemoveCssClass("btn-danger"); lbClose.RemoveCssClass("active"); lbOpen.AddCssClass("btn-success"); lbOpen.AddCssClass("active"); } else { lbOpen.RemoveCssClass("btn-success"); lbOpen.RemoveCssClass("active"); lbClose.AddCssClass("btn-danger"); lbClose.AddCssClass("active"); } var lLocationName = e.Item.FindControl("lLocationName") as Literal; lLocationName.Text = locationDataItem.GetPropertyValue("Name") as string; var lLocationCount = e.Item.FindControl("lLocationCount") as Literal; lLocationCount.Text = KioskLocationAttendance.Get(( int )locationDataItem.GetPropertyValue("LocationId")).CurrentCount.ToString(); } }
/// <summary> /// Executes the specified workflow. /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="action">The workflow action.</param> /// <param name="entity">The entity.</param> /// <param name="errorMessages">The error messages.</param> /// <returns></returns> /// <exception cref="System.NotImplementedException"></exception> public override bool Execute(RockContext rockContext, Model.WorkflowAction action, Object entity, out List <string> errorMessages) { var checkInState = GetCheckInState(entity, out errorMessages); if (checkInState != null) { var family = checkInState.CheckIn.CurrentFamily; if (family != null) { var remove = GetAttributeValue(action, "Remove").AsBoolean(); foreach (var person in family.People) { foreach (var groupType in person.GroupTypes) { foreach (var group in groupType.Groups) { foreach (var location in group.Locations.ToList()) { if (location.Location.SoftRoomThreshold.HasValue) { var locAttendance = KioskLocationAttendance.Get(location.Location.Id); if (locAttendance != null && !locAttendance.DistinctPersonIds.Contains(person.Person.Id) && location.Location.SoftRoomThreshold.Value <= locAttendance.CurrentCount) { if (remove) { group.Locations.Remove(location); } else { location.ExcludedByFilter = true; } } } } } } } } return(true); } return(false); }
/// <summary> /// Get the option text. /// </summary> private string GetOptionText(CheckInPersonSummary option) { var format = GetAttributeValue(AttributeKey.OptionFormat); var mergeFields = new Dictionary <string, object> { { "GroupType", option.GroupType }, { "Group", option.Group }, { "Location", option.Location }, { "Schedule", option.Schedule }, { "DisplayLocationCount", CurrentCheckInState.CheckInType.DisplayLocationCount }, { "LocationCount", KioskLocationAttendance.Get(option.Location.Location.Id).CurrentCount } }; var optionText = format.ResolveMergeFields(mergeFields); return(optionText); }
/// <summary> /// Reads the attendance cache by schedule. /// </summary> /// <param name="locationId">The location identifier.</param> /// <param name="scheduleId">The schedule identifier.</param> /// <returns></returns> public static int ReadAttendanceBySchedule(int locationId, int?scheduleId) { var attendanceCount = 0; var attendanceCache = KioskLocationAttendance.Get(locationId); if (attendanceCache != null) { if (scheduleId != null) { attendanceCount += attendanceCache.Groups.SelectMany(g => g.Schedules).Where(s => s.ScheduleId == (int)scheduleId).Sum(s => s.CurrentCount); } else { attendanceCount = attendanceCache.CurrentCount; } } return(attendanceCount); }
/// <summary> /// Handles the ItemDataBound event of the rLocations control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Web.UI.WebControls.RepeaterItemEventArgs"/> instance containing the event data.</param> protected void rLocations_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e) { var locationGridItem = e.Item.DataItem as LocationGridItem; if (locationGridItem != null) { if (hfAllowOpenClose.Value.AsBoolean()) { var lbOpen = e.Item.FindControl("lbOpen") as LinkButton; var lbClose = e.Item.FindControl("lbClose") as LinkButton; var isActive = locationGridItem.IsActive; if (isActive) { lbClose.RemoveCssClass("btn-danger"); lbClose.RemoveCssClass("active"); lbOpen.AddCssClass("btn-success"); lbOpen.AddCssClass("active"); } else { lbOpen.RemoveCssClass("btn-success"); lbOpen.RemoveCssClass("active"); lbClose.AddCssClass("btn-danger"); lbClose.AddCssClass("active"); } } else { var divLocationToggle = e.Item.FindControl("divLocationToggle") as HtmlGenericControl; divLocationToggle.Visible = false; } var lLocationName = e.Item.FindControl("lLocationName") as Literal; lLocationName.Text = locationGridItem.Name; var lLocationCount = e.Item.FindControl("lLocationCount") as Literal; lLocationCount.Text = KioskLocationAttendance.Get(locationGridItem.LocationId).CurrentCount.ToString(); } }
/// <summary> /// Handles the Click event of the btnManager control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void btnManager_Click(object sender, EventArgs e) { ManagerLoggedIn = false; pnlNotActive.Visible = false; pnlNotActiveYet.Visible = false; pnlClosed.Visible = false; pnlActive.Visible = false; pnlManager.Visible = false; btnManager.Visible = false; tbPIN.Text = string.Empty; // Get room counts List <int> locations = new List <int>(); foreach (var groupType in CurrentCheckInState.Kiosk.FilteredGroupTypes(CurrentCheckInState.ConfiguredGroupTypes)) { var lUl = new HtmlGenericControl("ul"); lUl.AddCssClass("kioskmanager-count-locations"); phCounts.Controls.Add(lUl); foreach (var location in groupType.KioskGroups.SelectMany(g => g.KioskLocations).OrderBy(l => l.Location.Name).Distinct()) { if (!locations.Contains(location.Location.Id)) { locations.Add(location.Location.Id); var locationAttendance = KioskLocationAttendance.Get(location.Location.Id); if (locationAttendance != null) { var lLi = new HtmlGenericControl("li"); lUl.Controls.Add(lLi); lLi.InnerHtml = string.Format("<strong>{0}</strong>: {1}", locationAttendance.LocationName, locationAttendance.CurrentCount); var gUl = new HtmlGenericControl("ul"); gUl.AddCssClass("kioskmanager-count-groups"); lLi.Controls.Add(gUl); foreach (var groupAttendance in locationAttendance.Groups) { var gLi = new HtmlGenericControl("li"); gUl.Controls.Add(gLi); gLi.InnerHtml = string.Format("<strong>{0}</strong>: {1}", groupAttendance.GroupName, groupAttendance.CurrentCount); var sUl = new HtmlGenericControl("ul"); sUl.AddCssClass("kioskmanager-count-schedules"); gLi.Controls.Add(sUl); foreach (var scheduleAttendance in groupAttendance.Schedules.Where(s => s.IsActive)) { var sLi = new HtmlGenericControl("li"); sUl.Controls.Add(sLi); sLi.InnerHtml = string.Format("<strong>{0}</strong>: {1}", scheduleAttendance.ScheduleName, scheduleAttendance.CurrentCount); } } } } } } pnlManagerLogin.Visible = true; // set manager timer to 10 minutes hfRefreshTimerSeconds.Value = "600"; }
/// <summary> /// Executes the specified workflow. /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="action">The workflow action.</param> /// <param name="entity">The entity.</param> /// <param name="errorMessages">The error messages.</param> /// <returns></returns> /// <exception cref="System.NotImplementedException"></exception> public override bool Execute(RockContext rockContext, WorkflowAction action, Object entity, out List <string> errorMessages) { var checkInState = GetCheckInState(entity, out errorMessages); if (checkInState != null) { bool loadAll = GetAttributeValue(action, "LoadAll").AsBoolean(); foreach (var family in checkInState.CheckIn.GetFamilies(true)) { foreach (var person in family.GetPeople(!loadAll)) { foreach (var groupType in person.GetGroupTypes(!loadAll).ToList()) { var kioskGroupType = checkInState.Kiosk.ActiveGroupTypes(checkInState.ConfiguredGroupTypes) .Where(g => g.GroupType.Id == groupType.GroupType.Id) .FirstOrDefault(); if (kioskGroupType != null) { foreach (var group in groupType.GetGroups(!loadAll)) { var closedGroupLocationIds = new AttendanceOccurrenceService(rockContext) .Queryable() .AsNoTracking() .Where(o => o.GroupId == group.Group.Id && o.OccurrenceDate == RockDateTime.Today) .WhereAttributeValue(rockContext, "rocks.kfs.OccurrenceClosed", "True") .Select(l => l.LocationId) .ToList(); var loadBalance = group.Group.GetAttributeValue("rocks.kfs.LoadBalanceLocations").AsBoolean(); if (loadBalance && loadAll) { group.Locations.Clear(); } var locationAttendance = new Dictionary <CheckInLocation, int>(); foreach (var kioskGroup in kioskGroupType.KioskGroups .Where(g => g.Group.Id == group.Group.Id && g.IsCheckInActive) .ToList()) { foreach (var kioskLocation in kioskGroup.KioskLocations.Where(l => l.IsCheckInActive && l.IsActiveAndNotFull && !closedGroupLocationIds.Contains(l.Location.Id))) { if (!group.Locations.Any(l => l.Location.Id == kioskLocation.Location.Id)) { var checkInLocation = new CheckInLocation(); checkInLocation.Location = kioskLocation.Location.Clone(false); checkInLocation.Location.CopyAttributesFrom(kioskLocation.Location); checkInLocation.CampusId = kioskLocation.CampusId; checkInLocation.Order = kioskLocation.Order; locationAttendance.Add(checkInLocation, KioskLocationAttendance.Get(checkInLocation.Location.Id).CurrentCount); } } } if (loadBalance) { var sortedLocationAttendance = locationAttendance.ToList(); sortedLocationAttendance.Sort((x, y) => x.Key.Location.Name.CompareTo(y.Key.Location.Name)); sortedLocationAttendance.Sort((x, y) => x.Value.CompareTo(y.Value)); var order = 0; foreach (var checkInLocationPair in sortedLocationAttendance) { var checkInLocation = checkInLocationPair.Key; checkInLocation.Order = order; group.Locations.Add(checkInLocation); order++; } } else { group.Locations.AddRange(locationAttendance.Select(l => l.Key).ToList()); } } } } } } return(true); } return(false); }
/// <summary> /// Formats the count. /// </summary> /// <param name="locationId">The location id.</param> /// <returns></returns> protected string FormatCount(int locationId) { if (CurrentCheckInType != null && CurrentCheckInType.DisplayLocationCount) { return(string.Format(" <span class='checkin-sub-title'> Count: {0}</span>", KioskLocationAttendance.Get(locationId).CurrentCount)); } return(string.Empty); }