/// <summary> /// /// Click trigger function for the save button. /// This will check the field requirements are met, /// then it will add the applicant to the list and /// send the user to the ConfirmApplicantForm. /// /// </summary> private void Button_Save_Click(object sender, EventArgs e) { // Checks whether an item in the tempTypeBox has been selected // AND whether all the fields have been filled if ((ListBox_TemplateList.SelectedItem != null) && ((TextBox_DetailsFullName.Text.Length > 0) && (TextBox_DetailsJobPosition.Text.Length > 0) && (TextBox_DetailsEmail.Text.Length > 0))) { if ((TextBox_DetailsFullName.Text.Length <= 50) && (TextBox_DetailsJobPosition.Text.Length <= 50) && (TextBox_DetailsEmail.Text.Length <= 50)) { // Insert applicant details into the database Connection.GetDbConn().CreateCommand(SqlQueries.InsertApplicant(TextBox_DetailsFullName.Text, TextBox_DetailsEmail.Text, TextBox_DetailsJobPosition.Text, Recruiter.GetInstance().Id)); // Crearte a new instance of the applicant class Applicant applicant = new Applicant(TextBox_DetailsFullName.Text, TextBox_DetailsEmail.Text, TextBox_DetailsJobPosition.Text, Recruiter.GetInstance().Id, ListBox_TemplateList.SelectedItem.ToString()); // Add the instance into the applicant list Applicant.applicants.Add(applicant); Template.GenerateTemplateForApplicant(applicant, ListBox_TemplateList.SelectedItem.ToString()); Hide(); // Create a new ConfApplDetails form passing the value false ConfirmApplicantForm instance_ConfirmApplicantForm = new ConfirmApplicantForm(true); instance_ConfirmApplicantForm.Show(); } else { Label_Error.Visible = true; Label_Error.Text = "Fields must be 50 characters or less"; } } else { // Displays the error message Label_Error.Visible = true; Label_Error.Text = "Missing required fields"; } }
/// <summary> /// /// This will convert the contents of the RTF files /// into a final PDF document that would be emailed /// to the recipient. This is done in bulk by looping /// through all applicants. /// /// </summary> private void ConvertToPDF() { for (int i = 0; i < Applicant.applicants.Count; i++) { string feedbackText = "No Feedback given."; string commentText = "No comments made."; string name = Applicant.applicants[i].AfullName; string type = Applicant.applicants[i].Atype; string job = Applicant.applicants[i].AJob; string recruiter = Recruiter.GetInstance().Name; // Check feedback and comments exist, // if not, use default values set above. if (File.Exists(recruiter + name + ".rtf")) { using (StreamReader feedbackFile = new StreamReader(recruiter + name + ".rtf")) { feedbackText = feedbackFile.ReadToEnd(); } } if (File.Exists(recruiter + name + "-comments.rtf")) { using (StreamReader commentsFile = new StreamReader(recruiter + name + "-comments.rtf")) { commentText = commentsFile.ReadToEnd(); } } // Using PdfSharp Library PdfDocument document = new PdfDocument(); PdfPage documentPage = document.AddPage(); XGraphics documentGraphics = XGraphics.FromPdfPage(documentPage); XTextFormatter documentTextFormatter = new XTextFormatter(documentGraphics); XFont documentFont = new XFont("Arial", 8.25, XFontStyle.Bold); Image documentImage = Properties.Resources.happytech_logo_med; MemoryStream documentStream = new MemoryStream(); XBrush documentBrush = XBrushes.Black; XStringFormat documentStringFormat = XStringFormats.TopLeft; documentImage. Save(documentStream, System.Drawing.Imaging.ImageFormat.Png); XImage documentLogo = XImage.FromStream(documentStream); XRect documentEditRectangle = new XRect(documentPage.Width / 8, ((documentPage.Height / 12) + documentImage.Height) + 60, (documentPage.Width / 8) + (documentPage.Width / 1.5), documentPage.Height - (documentPage.Height / 4)); XRect documentLogoRectangle = new XRect((documentPage.Width / 2) - (documentLogo.PixelWidth / 2), documentPage.Height / 16, documentImage.Width, documentImage.Height); // Begin drawing the PDF document // Logo documentGraphics. DrawImage(documentLogo, documentLogoRectangle); // Feedback documentTextFormatter. DrawString($"Dear {name},\n\n" + $"Regarding your {type} for the {job} role at HappyTech.\n\n" + feedbackText + "\n\n" + "Further comments:\n\n" + commentText + $"\n\n" + $"Kind Regards,\n" + $"{recruiter}\n" + $"HappyTech Recruiter", documentFont, documentBrush, documentEditRectangle, documentStringFormat); document.Save(recruiter + name + ".pdf"); Process.Start(recruiter + name + ".pdf"); } }