/// <summary> /// Reprint the selected labels /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void lbReprintSelectLabelTypes_Click(object sender, EventArgs e) { var fileGuids = hfLabelFileGuids.Value.SplitDelimitedValues().AsGuidList(); var personId = hfSelectedPersonId.ValueAsInt(); var selectedAttendanceIds = hfSelectedAttendanceIds.Value.SplitDelimitedValues().AsIntegerList(); List <string> messages = ZebraPrint.ReprintZebraLabels(fileGuids, personId, selectedAttendanceIds, pnlReprintResults, this.Request); pnlReprintResults.Visible = true; pnlReprintSelectedPersonLabels.Visible = false; hfLabelFileGuids.Value = string.Empty; hfSelectedPersonId.Value = string.Empty; lReprintResultsHtml.Text = messages.JoinStrings("<br>"); }
/// <summary> /// Handles sending the selected labels off to the selected printer. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void mdReprintLabels_PrintClick(object sender, EventArgs e) { var personId = hfPersonId.ValueAsInt(); if (personId == 0) { return; } if (string.IsNullOrWhiteSpace(cblLabels.SelectedValue)) { nbReprintLabelMessages.Visible = true; nbReprintLabelMessages.Text = "Please select at least one label."; return; } if (ddlPrinter.SelectedValue == null || ddlPrinter.SelectedValue == None.IdValue) { nbReprintLabelMessages.Visible = true; nbReprintLabelMessages.Text = "Please select a printer."; return; } // Get the person Id from the Guid var selectedAttendanceIds = hfCurrentAttendanceIds.Value.SplitDelimitedValues().AsIntegerList(); var fileGuids = cblLabels.SelectedValues.AsGuidList(); var reprintLabelOptions = new ReprintLabelOptions { PrintFrom = PrintFrom.Server, ServerPrinterIPAddress = ddlPrinter.SelectedValue }; // Now, finally, re-print the labels. List <string> messages = ZebraPrint.ReprintZebraLabels(fileGuids, personId, selectedAttendanceIds, nbReprintMessage, this.Request, reprintLabelOptions); nbReprintMessage.Visible = true; nbReprintMessage.Text = messages.JoinStrings("<br>"); mdReprintLabels.Hide(); }
/// <summary> /// Handles when a person is selected from the re-print label button. /// </summary> /// <param name="source"></param> /// <param name="e"></param> protected void rReprintLabelPersonResults_ItemCommand(object source, RepeaterCommandEventArgs e) { // Get the person Id int personId = e.CommandArgument.ToString().AsInteger(); hfSelectedPersonId.Value = personId.ToStringSafe(); // Get the attendanceIds var hfAttendanceIds = e.Item.FindControl("hfAttendanceIds") as HiddenField; if (hfAttendanceIds == null) { return; } // save the attendance ids for later use. hfSelectedAttendanceIds.Value = hfAttendanceIds.Value; // hide the reprint person select results, then show the selected labels to pick from pnlReprintLabels.Visible = false; pnlManager.Visible = false; pnlReprintSearchPersonResults.Visible = false; pnlReprintSelectedPersonLabels.Visible = true; // bind all possible tags to reprint var possibleLabels = ZebraPrint.GetLabelTypesForPerson(personId, hfSelectedAttendanceIds.Value.SplitDelimitedValues().AsIntegerList()); if (possibleLabels.Count != 0) { lbReprintSelectLabelTypes.Visible = true; } else { lbReprintSelectLabelTypes.Visible = false; maNoLabelsFound.Show("No labels were found for that selection.", ModalAlertType.Alert); } rReprintLabelTypeSelection.DataSource = possibleLabels; rReprintLabelTypeSelection.DataBind(); }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event. /// </summary> /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (CurrentWorkflow == null || CurrentCheckInState == null) { NavigateToHomePage(); } else { if (!Page.IsPostBack) { try { lTitle.Text = GetAttributeValue(AttributeKey.Title); string detailMsg = GetAttributeValue(AttributeKey.DetailMessage); var printFromClient = new List <CheckInLabel>(); var printFromServer = new List <CheckInLabel>(); List <CheckinResult> checkinResultList = new List <CheckinResult>(); // Print the labels foreach (var family in CurrentCheckInState.CheckIn.Families.Where(f => f.Selected)) { lbAnother.Visible = CurrentCheckInState.CheckInType.TypeOfCheckin == TypeOfCheckin.Individual && family.People.Count > 1; foreach (var person in family.GetPeople(true)) { foreach (var groupType in person.GetGroupTypes(true)) { foreach (var group in groupType.GetGroups(true)) { foreach (var location in group.GetLocations(true)) { foreach (var schedule in location.GetSchedules(true)) { string detailMessage = string.Format(detailMsg, person.ToString(), group.ToString(), location.Location.Name, schedule.ToString(), person.SecurityCode); CheckinResult checkinResult = new CheckinResult(); checkinResult.Person = person; checkinResult.Group = group; checkinResult.Location = location.Location; checkinResult.Schedule = schedule; checkinResult.DetailMessage = detailMessage; checkinResultList.Add(checkinResult); } } } if (groupType.Labels != null && groupType.Labels.Any()) { printFromClient.AddRange(groupType.Labels.Where(l => l.PrintFrom == Rock.Model.PrintFrom.Client)); printFromServer.AddRange(groupType.Labels.Where(l => l.PrintFrom == Rock.Model.PrintFrom.Server)); } } } } var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields(this.RockPage, null, new Rock.Lava.CommonMergeFieldsOptions { GetLegacyGlobalMergeFields = false }); mergeFields.Add("CheckinResultList", checkinResultList); mergeFields.Add("Kiosk", CurrentCheckInState.Kiosk); mergeFields.Add("RegistrationModeEnabled", CurrentCheckInState.Kiosk.RegistrationModeEnabled); mergeFields.Add("Messages", CurrentCheckInState.Messages); if (LocalDeviceConfig.CurrentGroupTypeIds != null) { var checkInAreas = LocalDeviceConfig.CurrentGroupTypeIds.Select(a => Rock.Web.Cache.GroupTypeCache.Get(a)); mergeFields.Add("CheckinAreas", checkInAreas); } if (printFromClient.Any()) { var urlRoot = string.Format("{0}://{1}", Request.Url.Scheme, Request.Url.Authority); #if DEBUG // This is extremely useful when debugging with ngrok and an iPad on the local network. // X-Original-Host will contain the name of your ngrok hostname, therefore the labels will // get a LabelFile url that will actually work with that iPad. if (Request.Headers["X-Forwarded-Proto"] != null && Request.Headers["X-Original-Host"] != null) { urlRoot = string.Format("{0}://{1}", Request.Headers.GetValues("X-Forwarded-Proto").First(), Request.Headers.GetValues("X-Original-Host").First()); } #endif printFromClient .OrderBy(l => l.PersonId) .ThenBy(l => l.Order) .ToList() .ForEach(l => l.LabelFile = urlRoot + l.LabelFile); AddLabelScript(printFromClient.ToJson()); } if (printFromServer.Any()) { var messages = ZebraPrint.PrintLabels(printFromServer); mergeFields.Add("ZebraPrintMessageList", messages); } var successLavaTemplate = CurrentCheckInState.CheckInType.SuccessLavaTemplate; lCheckinResultsHtml.Text = successLavaTemplate.ResolveMergeFields(mergeFields); if (LocalDeviceConfig.GenerateQRCodeForAttendanceSessions) { HttpCookie attendanceSessionGuidsCookie = Request.Cookies[CheckInCookieKey.AttendanceSessionGuids]; if (attendanceSessionGuidsCookie == null) { attendanceSessionGuidsCookie = new HttpCookie(CheckInCookieKey.AttendanceSessionGuids); attendanceSessionGuidsCookie.Value = string.Empty; } // set (or reset) the expiration to be 8 hours from the current time) attendanceSessionGuidsCookie.Expires = RockDateTime.Now.AddHours(8); var attendanceSessionGuids = attendanceSessionGuidsCookie.Value.Split(',').AsGuidList(); attendanceSessionGuids = ValidAttendanceSessionGuids(attendanceSessionGuids); // Add the guid to the list of checkin session cookie guids if it's not already there. if (CurrentCheckInState.CheckIn.CurrentFamily.AttendanceCheckinSessionGuid.HasValue && !attendanceSessionGuids.Contains(CurrentCheckInState.CheckIn.CurrentFamily.AttendanceCheckinSessionGuid.Value)) { attendanceSessionGuids.Add(CurrentCheckInState.CheckIn.CurrentFamily.AttendanceCheckinSessionGuid.Value); } attendanceSessionGuidsCookie.Value = attendanceSessionGuids.AsDelimited(","); Response.Cookies.Set(attendanceSessionGuidsCookie); lCheckinQRCodeHtml.Text = string.Format("<div class='qr-code-container text-center'><img class='img-responsive qr-code' src='{0}' alt='Check-in QR Code' width='500' height='500'></div>", GetAttendanceSessionsQrCodeImageUrl(attendanceSessionGuidsCookie)); } } catch (Exception ex) { LogException(ex); } } } }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event. /// </summary> /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (CurrentWorkflow == null || CurrentCheckInState == null) { NavigateToHomePage(); } else { if (!Page.IsPostBack) { try { lTitle.Text = GetAttributeValue("Title"); var printFromClient = new List <CheckInLabel>(); var printFromServer = new List <CheckInLabel>(); using (var rockContext = new RockContext()) { var attendanceService = new AttendanceService(rockContext); // Print the labels foreach (var family in CurrentCheckInState.CheckIn.Families.Where(f => f.Selected)) { foreach (var person in family.CheckOutPeople.Where(p => p.Selected)) { foreach (var attendance in attendanceService.Queryable() .Where(a => person.AttendanceIds.Contains(a.Id)) .ToList()) { var now = attendance.Campus != null ? attendance.Campus.CurrentDateTime : RockDateTime.Now; attendance.EndDateTime = now; if (attendance.Occurrence.Group != null && attendance.Occurrence.Location != null && attendance.Occurrence.Schedule != null) { var li = new HtmlGenericControl("li"); li.InnerText = string.Format(GetAttributeValue("DetailMessage"), person.ToString(), attendance.Occurrence.Group.ToString(), attendance.Occurrence.Location.Name, attendance.Occurrence.Schedule.Name); phResults.Controls.Add(li); } } if (person.Labels != null && person.Labels.Any()) { printFromClient.AddRange(person.Labels.Where(l => l.PrintFrom == Rock.Model.PrintFrom.Client)); printFromServer.AddRange(person.Labels.Where(l => l.PrintFrom == Rock.Model.PrintFrom.Server)); } } } rockContext.SaveChanges(); } if (printFromClient.Any()) { var urlRoot = string.Format("{0}://{1}", Request.Url.Scheme, Request.Url.Authority); printFromClient .OrderBy(l => l.PersonId) .ThenBy(l => l.Order) .ToList() .ForEach(l => l.LabelFile = urlRoot + l.LabelFile); AddLabelScript(printFromClient.ToJson()); } if (printFromServer.Any()) { var messages = ZebraPrint.PrintLabels(printFromServer); foreach (var message in messages) { phResults.Controls.Add(new LiteralControl(string.Format("<br/>{0}", message))); } } } catch (Exception ex) { LogException(ex); } } } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnReprintLabels_Click(object sender, EventArgs e) { nbReprintMessage.Visible = false; Guid?personGuid = PageParameter(PERSON_GUID_PAGE_QUERY_KEY).AsGuidOrNull(); if (personGuid == null || !personGuid.HasValue) { maNoLabelsFound.Show("No person was found.", ModalAlertType.Alert); return; } if (string.IsNullOrEmpty(hfCurrentAttendanceIds.Value)) { maNoLabelsFound.Show("No labels were found for re-printing.", ModalAlertType.Alert); return; } var rockContext = new RockContext(); var attendanceIds = hfCurrentAttendanceIds.Value.SplitDelimitedValues().AsIntegerList(); // Get the person Id from the Guid in the page parameter var personId = new PersonService(rockContext).Queryable().Where(p => p.Guid == personGuid.Value).Select(p => p.Id).FirstOrDefault(); hfPersonId.Value = personId.ToString(); var possibleLabels = ZebraPrint.GetLabelTypesForPerson(personId, attendanceIds); if (possibleLabels != null && possibleLabels.Count != 0) { cblLabels.DataSource = possibleLabels; cblLabels.DataBind(); } else { maNoLabelsFound.Show("No labels were found for re-printing.", ModalAlertType.Alert); return; } cblLabels.DataSource = ZebraPrint.GetLabelTypesForPerson(personId, attendanceIds).OrderBy(l => l.Name); cblLabels.DataBind(); // Bind the printers list var printers = new DeviceService(rockContext) .GetByDeviceTypeGuid(new Guid(Rock.SystemGuid.DefinedValue.DEVICE_TYPE_PRINTER)) .OrderBy(d => d.Name) .ToList(); if (printers == null || printers.Count == 0) { maNoLabelsFound.Show("Due to browser limitations, only server based printers are supported and none are defined on this server.", ModalAlertType.Information); return; } ddlPrinter.Items.Clear(); ddlPrinter.DataSource = printers; ddlPrinter.DataBind(); ddlPrinter.Items.Insert(0, new ListItem(None.Text, None.IdValue)); nbReprintLabelMessages.Text = string.Empty; mdReprintLabels.Show(); }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event. /// </summary> /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (CurrentWorkflow == null || CurrentCheckInState == null) { NavigateToHomePage(); } else { if (!Page.IsPostBack) { try { lTitle.Text = GetAttributeValue("Title"); string detailMsg = GetAttributeValue("DetailMessage"); var printFromClient = new List <CheckInLabel>(); var printFromServer = new List <CheckInLabel>(); List <CheckinResult> checkinResultList = new List <CheckinResult>(); // Print the labels foreach (var family in CurrentCheckInState.CheckIn.Families.Where(f => f.Selected)) { lbAnother.Visible = CurrentCheckInState.CheckInType.TypeOfCheckin == TypeOfCheckin.Individual && family.People.Count > 1; foreach (var person in family.GetPeople(true)) { foreach (var groupType in person.GetGroupTypes(true)) { foreach (var group in groupType.GetGroups(true)) { foreach (var location in group.GetLocations(true)) { foreach (var schedule in location.GetSchedules(true)) { string detailMessage = string.Format(detailMsg, person.ToString(), group.ToString(), location.Location.Name, schedule.ToString(), person.SecurityCode); CheckinResult checkinResult = new CheckinResult(); checkinResult.Person = person; checkinResult.Group = group; checkinResult.Location = location.Location; checkinResult.Schedule = schedule; checkinResult.DetailMessage = detailMessage; checkinResultList.Add(checkinResult); } } } if (groupType.Labels != null && groupType.Labels.Any()) { printFromClient.AddRange(groupType.Labels.Where(l => l.PrintFrom == Rock.Model.PrintFrom.Client)); printFromServer.AddRange(groupType.Labels.Where(l => l.PrintFrom == Rock.Model.PrintFrom.Server)); } } } } var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields(this.RockPage, null, new Rock.Lava.CommonMergeFieldsOptions { GetLegacyGlobalMergeFields = false }); mergeFields.Add("CheckinResultList", checkinResultList); mergeFields.Add("Kiosk", CurrentCheckInState.Kiosk); mergeFields.Add("RegistrationModeEnabled", CurrentCheckInState.Kiosk.RegistrationModeEnabled); mergeFields.Add("Messages", CurrentCheckInState.Messages); if (CurrentGroupTypeIds != null) { var checkInAreas = CurrentGroupTypeIds.Select(a => Rock.Web.Cache.GroupTypeCache.Get(a)); mergeFields.Add("CheckinAreas", checkInAreas); } if (printFromClient.Any()) { var urlRoot = string.Format("{0}://{1}", Request.Url.Scheme, Request.Url.Authority); printFromClient .OrderBy(l => l.PersonId) .ThenBy(l => l.Order) .ToList() .ForEach(l => l.LabelFile = urlRoot + l.LabelFile); AddLabelScript(printFromClient.ToJson()); } if (printFromServer.Any()) { var messages = ZebraPrint.PrintLabels(printFromServer); mergeFields.Add("ZebraPrintMessageList", messages); } var successLavaTemplate = CurrentCheckInState.CheckInType.SuccessLavaTemplate; lCheckinResultsHtml.Text = successLavaTemplate.ResolveMergeFields(mergeFields); } catch (Exception ex) { LogException(ex); } } } }
/// <summary> /// Handles sending the selected labels off to the selected printer. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void mdReprintLabels_PrintClick(object sender, EventArgs e) { var personId = hfPersonId.ValueAsInt(); if (personId == 0) { return; } if (string.IsNullOrWhiteSpace(cblLabels.SelectedValue)) { nbReprintLabelMessages.Visible = true; nbReprintLabelMessages.Text = "Please select at least one label."; return; } var selectedPrinterGuid = ddlPrinter.SelectedValue.AsGuidOrNull(); if (!selectedPrinterGuid.HasValue) { nbReprintLabelMessages.Visible = true; nbReprintLabelMessages.Text = "Please select a printer."; return; } var selectedAttendanceIds = hfCurrentAttendanceIds.Value.SplitDelimitedValues().AsIntegerList(); var fileGuids = cblLabels.SelectedValues.AsGuidList(); ReprintLabelOptions reprintLabelOptions; string selectedPrinterIPAddress; if (selectedPrinterGuid == Guid.Empty) { reprintLabelOptions = new ReprintLabelOptions { PrintFrom = PrintFrom.Client }; } else { selectedPrinterIPAddress = new DeviceService(new RockContext()).GetSelect(selectedPrinterGuid.Value, s => s.IPAddress); reprintLabelOptions = new ReprintLabelOptions { PrintFrom = PrintFrom.Server, ServerPrinterIPAddress = selectedPrinterIPAddress }; } CheckinManagerHelper.SaveSelectedLabelPrinterToCookie(selectedPrinterGuid); // Now, finally, re-print the labels. List <string> messages = ZebraPrint.ReprintZebraLabels(fileGuids, personId, selectedAttendanceIds, nbReprintMessage, this.Request, reprintLabelOptions); nbReprintMessage.Visible = true; nbReprintMessage.Text = messages.JoinStrings("<br>"); mdReprintLabels.Hide(); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnReprintLabels_Click(object sender, EventArgs e) { nbReprintMessage.Visible = false; Guid personGuid = GetPersonGuid(); if (personGuid == Guid.Empty) { maNoLabelsFound.Show("No person was found.", ModalAlertType.Alert); return; } if (string.IsNullOrEmpty(hfCurrentAttendanceIds.Value)) { maNoLabelsFound.Show("No labels were found for re-printing.", ModalAlertType.Alert); return; } var rockContext = new RockContext(); var attendanceIds = hfCurrentAttendanceIds.Value.SplitDelimitedValues().AsIntegerList(); // Get the person Id from the PersonId page parameter, or look it up based on the Person Guid page parameter. int?personIdParam = PageParameter(PageParameterKey.PersonId).AsIntegerOrNull(); int personId = personIdParam.HasValue ? personIdParam.Value : new PersonService(rockContext).GetId(personGuid).GetValueOrDefault(); hfPersonId.Value = personId.ToString(); var possibleLabels = ZebraPrint.GetLabelTypesForPerson(personId, attendanceIds); if (possibleLabels != null && possibleLabels.Count != 0) { cblLabels.DataSource = possibleLabels; cblLabels.DataBind(); } else { maNoLabelsFound.Show("No labels were found for re-printing.", ModalAlertType.Alert); return; } cblLabels.DataSource = ZebraPrint.GetLabelTypesForPerson(personId, attendanceIds).OrderBy(l => l.Name); cblLabels.DataBind(); // Get the printers list. var printerList = new DeviceService(rockContext) .GetByDeviceTypeGuid(new Guid(Rock.SystemGuid.DefinedValue.DEVICE_TYPE_PRINTER)) .OrderBy(d => d.Name) .Select(a => new { a.Name, a.Guid }) .ToList(); ddlPrinter.Items.Clear(); ddlPrinter.Items.Add(new ListItem()); if (hfHasClientPrinter.Value.AsBoolean()) { ddlPrinter.Items.Add(new ListItem("local printer", Guid.Empty.ToString())); } foreach (var printer in printerList) { ddlPrinter.Items.Add(new ListItem(printer.Name, printer.Guid.ToString())); } var labelPrinterGuid = CheckinManagerHelper.GetCheckinManagerConfigurationFromCookie().LabelPrinterGuid; ddlPrinter.SetValue(labelPrinterGuid); nbReprintLabelMessages.Text = string.Empty; mdReprintLabels.Show(); }
/// <summary> /// Shows the details. /// </summary> private void ShowDetails() { lTitle.Text = GetAttributeValue(AttributeKey.Title); var printFromClient = new List <CheckInLabel>(); var printFromServer = new List <CheckInLabel>(); List <CheckinResult> checkinResultList = new List <CheckinResult>(); var successfullyCompletedAchievementIdsPriorToCheckin = CurrentCheckInState.CheckIn.SuccessfullyCompletedAchievementsPriorToCheckin?.Select(a => a.AchievementAttempt.Id).ToArray() ?? new int[0]; var achievementsStateAfterCheckin = CurrentCheckInState.CheckIn.AchievementsStateAfterCheckin; var successLavaTemplateDisplayMode = CurrentCheckInState.CheckInType.SuccessLavaTemplateDisplayMode; // Populate Checkin Results and label data foreach (var family in CurrentCheckInState.CheckIn.Families.Where(f => f.Selected)) { lbAnother.Visible = CurrentCheckInState.CheckInType.TypeOfCheckin == TypeOfCheckin.Individual && family.People.Count > 1; foreach (var person in family.GetPeople(true)) { foreach (var groupType in person.GetGroupTypes(true)) { foreach (var group in groupType.GetGroups(true)) { foreach (var location in group.GetLocations(true)) { foreach (var schedule in location.GetSchedules(true)) { CheckinResult checkinResult = new CheckinResult(); checkinResult.Person = person; checkinResult.Group = group; checkinResult.Location = location.Location; checkinResult.Schedule = schedule; checkinResult.UpdateAchievementFields(successfullyCompletedAchievementIdsPriorToCheckin, achievementsStateAfterCheckin); checkinResultList.Add(checkinResult); } } } if (groupType.Labels != null && groupType.Labels.Any()) { printFromClient.AddRange(groupType.Labels.Where(l => l.PrintFrom == Rock.Model.PrintFrom.Client)); printFromServer.AddRange(groupType.Labels.Where(l => l.PrintFrom == Rock.Model.PrintFrom.Server)); } } } } var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields(this.RockPage, null, new Rock.Lava.CommonMergeFieldsOptions { GetLegacyGlobalMergeFields = false }); mergeFields.Add(MergeFieldKey.CheckinResultList, checkinResultList); mergeFields.Add(MergeFieldKey.Kiosk, CurrentCheckInState.Kiosk); mergeFields.Add(MergeFieldKey.RegistrationModeEnabled, CurrentCheckInState.Kiosk.RegistrationModeEnabled); mergeFields.Add(MergeFieldKey.Messages, CurrentCheckInState.Messages); if (LocalDeviceConfig.CurrentGroupTypeIds != null) { var checkInAreas = LocalDeviceConfig.CurrentGroupTypeIds.Select(a => Rock.Web.Cache.GroupTypeCache.Get(a)); mergeFields.Add(MergeFieldKey.CheckinAreas, checkInAreas); } if (printFromClient.Any()) { var proxySafeUrl = Request.UrlProxySafe(); var urlRoot = $"{proxySafeUrl.Scheme}://{proxySafeUrl.Authority}"; /* * // This is extremely useful when debugging with ngrok and an iPad on the local network. * // X-Original-Host will contain the name of your ngrok hostname, therefore the labels will * // get a LabelFile url that will actually work with that iPad. * if ( Request.Headers["X-Original-Host" ] != null ) * { * var scheme = Request.Headers["X-Forwarded-Proto"] ?? "http"; * urlRoot = string.Format( "{0}://{1}", scheme, Request.Headers.GetValues( "X-Original-Host" ).First() ); * } */ printFromClient .OrderBy(l => l.PersonId) .ThenBy(l => l.Order) .ToList() .ForEach(l => l.LabelFile = urlRoot + l.LabelFile); AddLabelScript(printFromClient.ToJson()); } if (printFromServer.Any()) { var messages = ZebraPrint.PrintLabels(printFromServer); mergeFields.Add(MergeFieldKey.ZebraPrintMessageList, messages); if (messages.Any()) { lCheckinLabelErrorMessages.Visible = true; var messageHtml = new StringBuilder(); foreach (var message in messages) { messageHtml.AppendLine($"<li>{message}</li>"); } lCheckinLabelErrorMessages.Text = messageHtml.ToString(); } } if (CurrentCheckInState?.Messages?.Any() == true) { lMessages.Visible = true; StringBuilder sbMessages = new StringBuilder(); foreach (var message in CurrentCheckInState.Messages) { var messageHtml = $@"<li><div class='alert alert-{ message.MessageType.ConvertToString( false ).ToLower() }'> { message.MessageText } </div></li>"; sbMessages.AppendLine(messageHtml); } lMessages.Text = sbMessages.ToString(); } if (lbAnother.Visible) { var bodyTag = this.Page.Master.FindControl("body") as HtmlGenericControl; if (bodyTag != null) { bodyTag.AddCssClass("checkin-anotherperson"); } } GenerateQRCodes(); RenderCheckinResults(checkinResultList, mergeFields, successLavaTemplateDisplayMode); }
public PrintSessionLabelsResponse PrintSessionLabels([FromUri] string session, [FromUri] int?kioskId = null) { List <Guid?> sessionGuids; // // The session data is a comma separated list of Guid values. // try { sessionGuids = session.SplitDelimitedValues() .Select(a => { var guid = a.AsGuidOrNull(); // // Check if this is a standard Guid format. // if (guid.HasValue) { return(guid.Value); } return(GuidHelper.FromShortStringOrNull(a)); }) .ToList(); } catch { sessionGuids = null; } // // If no session guids were found or an error occurred trying to // parse them, then return an error. // if (sessionGuids == null || sessionGuids.Count == 0) { return(new PrintSessionLabelsResponse { Labels = new List <CheckInLabel>(), Messages = new List <string> { "No check-in sessions were specified." } }); } using (var rockContext = new RockContext()) { KioskDevice printer = null; // // If they specified a kiosk, attempt to load the printer for // that kiosk. // if (kioskId.HasValue && kioskId.Value != 0) { var kiosk = KioskDevice.Get(kioskId.Value, null); if ((kiosk?.Device?.PrinterDeviceId).HasValue) { // // We aren't technically loading a kiosk, but this lets us // load the printer IP address from cache rather than hitting // the database each time. // printer = KioskDevice.Get(kiosk.Device.PrinterDeviceId.Value, null); } } var attendanceService = new AttendanceService(rockContext); // // Retrieve all session label data from the database, then deserialize // it, then make one giant list of labels and finally order it. // var labels = attendanceService.Queryable() .AsNoTracking() .Where(a => sessionGuids.Contains(a.AttendanceCheckInSession.Guid)) .DistinctBy(a => a.AttendanceCheckInSessionId) .Select(a => a.AttendanceData.LabelData) .ToList() .Select(a => a.FromJsonOrNull <List <CheckInLabel> >()) .Where(a => a != null) .SelectMany(a => a) .OrderBy(a => a.PersonId) .ThenBy(a => a.Order) .ToList(); foreach (var label in labels) { // // If the label is being printed to the kiosk and client printing // is enabled and the client has specified their device // identifier then we need to update the label data to have the // new printer information. // if (label.PrintTo == PrintTo.Kiosk && label.PrintFrom == PrintFrom.Client && printer != null) { label.PrinterDeviceId = printer.Device.Id; label.PrinterAddress = printer.Device.IPAddress; } } var response = new PrintSessionLabelsResponse { Labels = labels.Where(l => l.PrintFrom == PrintFrom.Client).ToList() }; // // Update any labels to convert the relative URL path to an absolute URL // path for client printing. // if (response.Labels.Any()) { var urlRoot = Request.RequestUri.GetLeftPart(UriPartial.Authority); if (Request.Headers.Contains("X-Forwarded-Proto") && Request.Headers.Contains("X-Forwarded-Host")) { urlRoot = $"{Request.Headers.GetValues( "X-Forwarded-Proto" ).First()}://{Request.Headers.GetValues( "X-Forwarded-Host" ).First()}"; } #if DEBUG // This is extremely useful when debugging with ngrok and an iPad on the local network. // X-Original-Host will contain the name of your ngrok hostname, therefore the labels will // get a LabelFile url that will actually work with that iPad. if (Request.Headers.Contains("X-Forwarded-Proto") && Request.Headers.Contains("X-Original-Host")) { urlRoot = $"{Request.Headers.GetValues( "X-Forwarded-Proto" ).First()}://{Request.Headers.GetValues( "X-Original-Host" ).First()}"; } #endif response.Labels.ForEach(l => l.LabelFile = urlRoot + l.LabelFile); } var printFromServer = labels.Where(l => l.PrintFrom == PrintFrom.Server).ToList(); if (printFromServer.Any()) { var messages = ZebraPrint.PrintLabels(printFromServer); response.Messages = messages; } return(response); } }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event. /// </summary> /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (CurrentWorkflow == null || CurrentCheckInState == null) { NavigateToHomePage(); } else { if (!Page.IsPostBack) { try { lTitle.Text = GetAttributeValue("Title"); string detailMsg = GetAttributeValue("DetailMessage"); var printFromClient = new List <CheckInLabel>(); var printFromServer = new List <CheckInLabel>(); // Print the labels foreach (var family in CurrentCheckInState.CheckIn.Families.Where(f => f.Selected)) { lbAnother.Visible = CurrentCheckInState.CheckInType.TypeOfCheckin == TypeOfCheckin.Individual && family.People.Count > 1; foreach (var person in family.GetPeople(true)) { foreach (var groupType in person.GetGroupTypes(true)) { foreach (var group in groupType.GetGroups(true)) { foreach (var location in group.GetLocations(true)) { foreach (var schedule in location.GetSchedules(true)) { var li = new HtmlGenericControl("li"); li.InnerText = string.Format(detailMsg, person.ToString(), group.ToString(), location.Location.Name, schedule.ToString(), person.SecurityCode); phResults.Controls.Add(li); } } } if (groupType.Labels != null && groupType.Labels.Any()) { printFromClient.AddRange(groupType.Labels.Where(l => l.PrintFrom == Rock.Model.PrintFrom.Client)); printFromServer.AddRange(groupType.Labels.Where(l => l.PrintFrom == Rock.Model.PrintFrom.Server)); } } } } if (printFromClient.Any()) { var urlRoot = string.Format("{0}://{1}", Request.Url.Scheme, Request.Url.Authority); printFromClient .OrderBy(l => l.PersonId) .ThenBy(l => l.Order) .ToList() .ForEach(l => l.LabelFile = urlRoot + l.LabelFile); AddLabelScript(printFromClient.ToJson()); } if (printFromServer.Any()) { var messages = ZebraPrint.PrintLabels(printFromServer); foreach (var message in messages) { phResults.Controls.Add(new LiteralControl(string.Format("<br/>{0}", message))); } } } catch (Exception ex) { LogException(ex); } } } }