예제 #1
0
        private void CreateUserCertificate(Certificate certificate, Account account, CourseProgress courseProgress, DateTime dateEarnedUtc)
        {
            var certTemplate = new Bitmap(TemplatePathUser);

            var g = Graphics.FromImage(certTemplate);
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

            var alignCenter = new StringFormat
            {
                Alignment = StringAlignment.Center,
                LineAlignment = StringAlignment.Center
            };

            g.DrawString(account.FirstName + " " + account.LastName,
                new System.Drawing.Font("Javanese Text", 26), Brushes.Black, new RectangleF(0, 0, 1110, 797),
                alignCenter);
            var font = new System.Drawing.Font("Javanese Text", 26);
            var maxWidth = 1100f;
            if (CalculateLimitedWidth(courseProgress.Course.DisplayTitle, g, font, maxWidth))
            {
                g.DrawString(courseProgress.Course.DisplayTitle,
                    new System.Drawing.Font("Javanese Text", 26), Brushes.Black, new RectangleF(0, 0, maxWidth, 1000),
                    alignCenter);
            }
            else
            {
                DrawMultipleLines(courseProgress.Course.DisplayTitle, g, font, maxWidth, 445, alignCenter);
            }
            g.DrawString(dateEarnedUtc.ToLongDateString(),
                new System.Drawing.Font("Javanese Text", 21), Brushes.Black, new RectangleF(480, 515, 400, 100),
                alignCenter);
            g.DrawString(account.FirstName + " " + account.LastName,
                new System.Drawing.Font("Javanese Text", 18), Brushes.Black, new RectangleF(115, 630, 400, 100));
            g.DrawString(account.FirstName + " " + account.LastName,
                new System.Drawing.Font("Javanese Text", 18), Brushes.Black, new RectangleF(615, 630, 400, 100));

            float height = 690;
            foreach (var s in account.StateLicensures)
            {
                g.DrawString(s.StateAbbr,
                    new System.Drawing.Font("Javanese Text", 8), Brushes.Black, new RectangleF(119, height, 100, 50));
                var category = !string.IsNullOrEmpty(s.Category) ? _entityRepository.GetByID<CertificationCategory>(s.Category.ToGuid(true)) : null;
                if (category != null)
                {
                    g.DrawString(category.Name + " " + category.Number,
                        new System.Drawing.Font("Javanese Text", 8), Brushes.Black, new RectangleF(230, height, 100, 50));
                }
                g.DrawString(s.LicenseNum,
                    new System.Drawing.Font("Javanese Text", 8), Brushes.Black, new RectangleF(380, height, 100, 50));
                height = height + 15;
            }

            g.DrawString(account.CompanyName,
                new System.Drawing.Font("Javanese Text", 12, FontStyle.Bold), Brushes.Black,
                new RectangleF(615, 670, 400, 100));
            g.DrawString(account.CompanyAddress.Address1,
                new System.Drawing.Font("Javanese Text", 10), Brushes.Black, new RectangleF(615, 688, 400, 100));
            var cityStateZipTop = 706;
            if (!account.CompanyAddress.Address2.IsNullOrEmpty())
            {
                g.DrawString(account.CompanyAddress.Address2,
                    new System.Drawing.Font("Javanese Text", 10), Brushes.Black, new RectangleF(615, 706, 400, 100));
                cityStateZipTop = 724;
            }
            g.DrawString(
                account.CompanyAddress.City + ", " + account.CompanyAddress.State + ", " +
                account.CompanyAddress.ZipCode,
                new System.Drawing.Font("Javanese Text", 10), Brushes.Black, new RectangleF(615, cityStateZipTop, 400, 100));

            certTemplate.Save(CertificatePath + certificate.ID + "_user.jpg", ImageFormat.Jpeg);
        }
예제 #2
0
        public void CreateCertificate(Account account, CourseProgress courseProgress, DateTime dateEarnedUtc)
        {
            var certificate = new Certificate { EarnedUtc = dateEarnedUtc };
            courseProgress.Certificate = certificate;
            _entityRepository.Save(courseProgress);

            CreateUserCertificate(certificate, account, courseProgress, dateEarnedUtc);

            var licensuresWithCEUs =
                account.StateLicensures.Where(
                    s => courseProgress.Course.StateCEUs.Any(ceu => ceu.StateAbbr == s.StateAbbr)).ToList();

            foreach (var licensure in licensuresWithCEUs)
                CreateStateCertificate(certificate, account, licensure, courseProgress, dateEarnedUtc);

            using (var document = new iTextSharp.text.Document())
            using (var stream = new FileStream(CertificatePath + certificate.ID + ".pdf",
                FileMode.Create, FileAccess.Write, FileShare.None))
            {
                document.SetPageSize(new iTextSharp.text.Rectangle(700, 570));
                iTextSharp.text.pdf.PdfWriter.GetInstance(document, stream);
                document.Open();

                // User Certificate
                document.SetPageSize(new iTextSharp.text.Rectangle(700, 570));
                using (var imageStream = new FileStream(CertificatePath + certificate.ID + "_user.jpg",
                    FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    var image = iTextSharp.text.Image.GetInstance(imageStream);
                    image.ScaleToFit(800f, 500f);
                    document.Add(image);
                }

                // State Certificates
                foreach (var licensure in licensuresWithCEUs)
                {
                    document.SetPageSize(new iTextSharp.text.Rectangle(2550, 3300));
                    using (
                        var imageStream =
                            new FileStream(CertificatePath + certificate.ID + "_state_" + licensure.ID + ".jpg",
                                FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                    {
                        var image = iTextSharp.text.Image.GetInstance(imageStream);
                        //image.ScaleToFit(800f, 500f);
                        document.Add(image);
                    }
                }

                document.Close();
            }
        }
예제 #3
0
        private void CreateStateCertificate(Certificate certificate, Account account, StateLicensure licensure, CourseProgress courseProgress, DateTime dateEarnedUtc)
        {
            var certTemplate = new Bitmap(TemplatePathState);

            var ceu =
                courseProgress.Course.StateCEUs.First(
                    s => courseProgress.Course.StateCEUs.Any(c => c.StateAbbr == s.StateAbbr));

            var g = Graphics.FromImage(certTemplate);
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

            var alignCenter = new StringFormat
            {
                Alignment = StringAlignment.Center,
                LineAlignment = StringAlignment.Center
            };

            g.DrawString(account.FirstName + " " + account.LastName,
                new System.Drawing.Font("Arial", 28), Brushes.Black, new RectangleF(515, 818, 400, 100));

            g.DrawString(licensure.LicenseNum + "\n" + licensure.StateAbbr,
                new System.Drawing.Font("Arial", 28), Brushes.Black, new RectangleF(1498, 800, 400, 100));

            g.DrawString(ceu.Category.Number,
                new System.Drawing.Font("Arial", 28), Brushes.Black, new RectangleF(2218, 818, 400, 100));

            g.DrawString(courseProgress.Course.DisplayTitle,
                new System.Drawing.Font("Arial", 28), Brushes.Black, new RectangleF(587, 1040, 1252, 100));

            g.DrawString(ceu.ActivityID,
                new System.Drawing.Font("Arial", 28), Brushes.Black, new RectangleF(2155, 1040, 400, 100));

            g.DrawString(courseProgress.LastActivityUtc.ToLocalTime().ToString("d"),
                new System.Drawing.Font("Arial", 28), Brushes.Black, new RectangleF(515, 1263, 400, 100));

            g.DrawString(ceu.ActivityType,
               new System.Drawing.Font("Arial", 28), Brushes.Black, new RectangleF(2200, 1263, 400, 100));

            var activityTime = TimeSpan.FromMinutes(courseProgress.ActiveTime);
            g.DrawString(activityTime.Hours + ":" + activityTime.Minutes,
                new System.Drawing.Font("Arial", 28), Brushes.Black, new RectangleF(515, 1484, 400, 100));

            var hours = TimeSpan.FromHours((double)ceu.Hours);
            g.DrawString(hours.Hours + ":" + hours.Minutes,
                new System.Drawing.Font("Arial", 28), Brushes.Black, new RectangleF(1225, 1484, 400, 100));

            var percentage = courseProgress.TestProgress.CompletedQuestions.Count(r => r.CorrectOnAttempt != null) /
                             (decimal)courseProgress.Course.Test.Questions.Count;
            var grade = (percentage * 100).Round(true, 0) + "%";
            g.DrawString(grade, new System.Drawing.Font("Arial", 28), Brushes.Black, new RectangleF(1915, 1484, 400, 100));

            if (!courseProgress.VerificationInitials.IsNullOrEmpty() && courseProgress.VerificationDate.HasValue)
                g.DrawString(courseProgress.VerificationInitials + "  " + courseProgress.VerificationDate.Value.ToShortDateString(),
                    new System.Drawing.Font("Arial", 24), Brushes.Black, new RectangleF(595, 1685, 277, 100),
                    alignCenter);

            g.DrawString(DateTime.Now.ToString("d"),
                new System.Drawing.Font("Arial", 28), Brushes.Black, new RectangleF(788, 2240, 276, 100),
                alignCenter);

            certTemplate.Save(CertificatePath + certificate.ID + "_state_" + licensure.ID + ".jpg", ImageFormat.Jpeg);
        }