private AttendeeBadge CreateAttendeeBadgeFromInputs(String FirstName, String LastName, String Company) { // Cleanup strings for printed output String cleanedName = String.Format("{0} {1}", FirstName, LastName ); AttendeeBadge ab = new AttendeeBadge(); if (ab.CreateNameBadge(cleanedName, Company)) { return(ab); } else { MessageBox.Show( "Cannot create name badge!" + System.Environment.NewLine + System.Environment.NewLine + "The temporary directory cannot be writen to:" + System.Environment.NewLine + System.Environment.NewLine + @"%TEMP%\AttendeeTracker", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error ); return(null); } }
private AttendeeBadge CreateAttendeeBadgeFromSelectedRow() { // Cleanup strings for printed output String cleanedName = String.Format("{0} {1}", dtCSVTable.Rows[dgvLoadedList.CurrentCell.RowIndex]["FirstName"].ToString(), dtCSVTable.Rows[dgvLoadedList.CurrentCell.RowIndex]["LastName"].ToString() ); String Company = dtCSVTable.Rows[dgvLoadedList.CurrentCell.RowIndex]["Company"].ToString(); AttendeeBadge ab = new AttendeeBadge(); if (ab.CreateNameBadge(cleanedName, Company)) { return(ab); } else { MessageBox.Show( "Cannot create name badge!" + System.Environment.NewLine + System.Environment.NewLine + "The temporary directory cannot be writen to:" + System.Environment.NewLine + System.Environment.NewLine + @"%TEMP%\AttendeeTracker", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error ); return(null); } }
private void btnWalkonAttendee_Click(object sender, EventArgs e) { frmWalkonRegistration frmWalkon = new frmWalkonRegistration(); frmWalkon.ShowDialog(); WalkonResult newWalkon = frmWalkon.GetWalkonResult(); DataRow newAttendeeRecord = dtCSVTable.NewRow(); newAttendeeRecord["FirstName"] = newWalkon.FirstName; newAttendeeRecord["LastName"] = newWalkon.LastName; newAttendeeRecord["Company"] = newWalkon.Company; newAttendeeRecord["Email"] = newWalkon.Email; newAttendeeRecord["Attended"] = "Yes"; dtCSVTable.Rows.Add(newAttendeeRecord); AttendeeBadge abWalkon = CreateAttendeeBadgeFromInputs( newWalkon.FirstName, newWalkon.LastName, newWalkon.Company); if (!abWalkon.Equals(null)) { PrintAttendeeBadge(abWalkon); } }
private void btnReprintNameBadge_Click(object sender, EventArgs e) { AttendeeBadge abSelected = CreateAttendeeBadgeFromSelectedRow(); if (!abSelected.Equals(null)) { PrintAttendeeBadge(abSelected); } }
private void btnCheckinAttendee_Click(object sender, EventArgs e) { dtCSVTable.Rows[dgvLoadedList.CurrentCell.RowIndex].SetField("Attended", "Yes"); AttendeeBadge abSelected = CreateAttendeeBadgeFromSelectedRow(); if (!abSelected.Equals(null)) { PrintAttendeeBadge(abSelected); } saveSinceLastEdit = false; }
private void PrintPage(AttendeeBadge abadge, PrintDocument pd, object sender, PrintPageEventArgs args) { if (File.Exists(abadge.GetPath())) { // Load the image from the file Image img = Image.FromFile(abadge.GetPath()); // Grab a copy of our "soft margins" (configured printer settings) // Defaults to 1 inch margins, but could be configured otherwise by // the end user. You can also specify some default page margins in // your printDocument.DefaultPageSetting properties. RectangleF marginBounds = args.MarginBounds; // Grab a copy of our "hard margins" (printer's capabilities) // This varies between printer models. Software printers like // CutePDF will have no "physical limitations" and so will return // the full page size 850,1100 for a letter page size. RectangleF printableArea = args.PageSettings.PrintableArea; // Are we using soft margins or hard margins? Lets grab the correct // width/height from either the soft/hard margin rectangles. The // hard margins are usually a little wider than the soft margins. // ---------- // Note: Margins are automatically applied to the rotated page size // when the page is set to landscape, but physical hard margins are // not (the printer is not physically rotating any mechanics inside, // the paper still travels through the printer the same way. So we // rotate in software for landscape) int availableWidth = (int)Math.Floor(pd.OriginAtMargins ? marginBounds.Width : (args.PageSettings.Landscape ? printableArea.Height : printableArea.Width)); int availableHeight = (int)Math.Floor(pd.OriginAtMargins ? marginBounds.Height : (args.PageSettings.Landscape ? printableArea.Width : printableArea.Height)); args.Graphics.DrawImage(img, 0, 0, availableWidth - 1, availableHeight - 1); } }
// // INTERNAL METHODS // private void PrintAttendeeBadge(AttendeeBadge InputBadge) { // Set printer settings PrintDocument pd = new PrintDocument(); pd.DefaultPageSettings.Landscape = true; pd.DefaultPageSettings.PrinterSettings.PrinterName = cmbDYMOPrinter.SelectedItem.ToString(); foreach (PaperSize paper in listPaperSizes) { if (paper.PaperName.Equals(cmbDYMOLabel.SelectedItem.ToString())) { pd.DefaultPageSettings.PaperSize = paper; break; } } // Set printer handler pd.PrintPage += (obj, ppea) => PrintPage(InputBadge, pd, obj, ppea); pd.Print(); }