1: using System;
2: using System.Drawing;
3: using System.Drawing.Imaging;
4: using System.Drawing.Text;
5: using System.Web;
6: using Arena.Event;
7:
8: public partial class eticket : System.Web.UI.Page
9: { 10: protected void Page_Load( object sender, EventArgs e )
11: { 12: if ( ! IsPostBack && Request.QueryString[ "r" ] != null && Request.QueryString[ "b" ] != null )
13: { 14: OutputBarCode( Request.QueryString[ "r" ] );
15: }
16: else if ( ! IsPostBack && Request.QueryString[ "r" ] != null )
17: { 18: PrintEticket( Request.QueryString[ "r" ] );
19: }
20: }
21:
22: /// <summary>
23: /// Binds the needed registration information to the form's controls.
24: /// </summary>
25: /// <param name="guid"></param>
26: private void PrintEticket( string guid )
27: { 28: Registration registration = new Registration( new Guid( guid ) );
29: if ( registration != null && registration.RegistrationId != -1 )
30: { 31: this.pnlViewETicket.Visible = true;
32: this.lblName.Text = registration.Registrants.ToHtml();
33: this.lblEventName.Text = registration.EventProfile.Name;
34: this.lblEventDescription.Text = registration.EventProfile.Details; ;
35: this.lblEventDate.Text = registration.EventProfile.Start.ToShortDateString() +
36: " " + registration.EventProfile.Start.ToShortTimeString() +
37: " - " + registration.EventProfile.End.ToShortDateString() + " " + registration.EventProfile.End.ToShortTimeString();
38:
39: if ( !"".Equals( registration.EventProfile.ConfirmationText.Trim() ) )
40: { 41: this.lblEventConfirmation.Text = registration.EventProfile.ConfirmationText;
42: }
43: else
44: { 45: this.pnlSpecialNotes.Visible = false;
46: }
47:
48: this.lblRegistrationID.Text = registration.Guid.ToString();
49:
50: // Set the barcode source to be this page (the b=1) will cause the
51: // image output to be rendered on the fly via the OutputBarCode method.
52: imgBarcode.ImageUrl = Request.RawUrl + "&b=1";
53: }
54: }
55:
56: /// <summary>
57: /// This method will create the barcode and stream the image
58: /// data to the Response.OutputStream.
59: /// </summary>
60: /// <param name="text">the text to barcode</param>
61: private void OutputBarCode( string text )
62: { 63: string TypeFaceName = "barcode font";
64:
65: PrivateFontCollection fnts = new PrivateFontCollection();
66: fnts.AddFontFile( Server.MapPath( "~/BarcodeFont.ttf" ) );
67: FontFamily fntfam = new FontFamily( TypeFaceName, fnts );
68: Font fnt = new Font( fntfam, 46 );
69:
70: //Draw the barcode as an image
71: Bitmap bmp = new Bitmap( 500, 60 ); //Canvas size
72: Graphics g = Graphics.FromImage( bmp );
73: g.Clear( Color.White );
74:
75: Brush br = new SolidBrush( Color.Black );
76: StringFormat stringFormat = new StringFormat();
77: //stringFormat.FormatFlags = StringFormatFlags.DirectionVertical;
78:
79: g.DrawString( text, fnt, br, 10, 10, stringFormat );
80:
81: Response.Clear();
82: Response.ClearContent();
83: Response.ClearHeaders();
84: Response.ContentType = "image/jpg";
85: Response.AddHeader( "Content-Type", "image/jpg" );
86:
87: bmp.Save( Response.OutputStream, ImageFormat.Jpeg );
88: bmp.Dispose();
89: Response.End();
90: }
91: }