/// <summary> /// Cooking up a method that will simulate checking in a person to a Occurrence /// to print out their check-in labels but without actually checking them in. /// </summary> protected void btnTest_Click( object sender, EventArgs e ) { if ( tvLocations.CheckedNodes.Length > 0 && txtPersonID.Text.Trim() != string.Empty ) { System.Collections.Generic.List<string> success = new System.Collections.Generic.List<string>(); System.Collections.Generic.List<string> fails = new System.Collections.Generic.List<string>(); foreach ( TreeViewNode node in tvLocations.CheckedNodes ) { // skip all but level 1 if ( node.Depth != 1 ) continue; Location location = new Location( int.Parse( node.ID ) ); try { IPrintLabel pl = PrintLabelHelper.GetPrintLabelClass( int.Parse( providerLookup.SelectedLookup.Value ) ); // The IPrintLabel provider prints labels based on a given: // attendee, a collection of occurrences, and an attendance record. // Our particular provider will print to the location // that is set in the first occurrence. // // We will create multiple occurrences for the collection based // on the user's comma delimited start times from the form. OccurrenceCollection occurrences = new OccurrenceCollection(); foreach ( string time in txtServices.Text.Split( ',' ) ) { Occurrence occurrence = new Occurrence(); occurrence.LocationID = location.LocationId; occurrence.StartTime = DateTime.Parse( DateTime.Now.ToShortDateString() + " " + time ); occurrences.Add( occurrence ); } OccurrenceAttendance attendance = new OccurrenceAttendance(); attendance.SecurityCode = txtSecurityCode.Text; attendance.CheckInTime = DateTime.Now; FamilyMember attendee = new FamilyMember( int.Parse( txtPersonID.Text ) ); pl.Print( attendee, occurrences, attendance, new Arena.Computer.ComputerSystem() ); success.Add( string.Format( "{0} ({1})", location.LocationName, location.Printer.PrinterName )); } catch ( System.Exception ex ) { fails.Add( string.Format( "{0} ({1})<BR>{2}", location.LocationName, location.Printer.PrinterName, ex.Message ) + "<BR>StackTrace: " + ex.StackTrace ); } } if ( success.Count > 0 ) { lblSuccessMessage.Text = "IPrintLabels Provider successfully printed to room (printer): " + string.Join( ", ", success.ToArray() ) + "<hr>"; lblSuccessMessage.Visible = true; } if ( fails.Count > 0 ) { lblErrorMessage.Text = string.Join( "<hr>Failure to print in room (printer):<br>", fails.ToArray() ); lblErrorMessage.Visible = true; } } }
static void PrintLabel(IPrintLabel theAddressObject) { Console.WriteLine(theAddressObject.Name + " " + theAddressObject.Address); }