/// <summary> /// Tworzy certifikat przynależności użtkownika /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonCreateCertificate_Click(object sender, EventArgs e) { DocumentCreations.Create(new Tables.DocumentCreation() { User = CurrentUser, CreationTime = DateTime.Now, CreatedDocument = $"{CurrentUser.Rank.Name} certificate" }); using (Document document = new Document(PageSize.A4, 10, 10, 10, 10)) using (PdfWriter writer = PdfWriter.GetInstance(document, new FileStream($"C:\\Users\\{Environment.UserName}\\Desktop\\Certificate_{CurrentUser.Login}_{DateTime.Now.ToFileTime()}.pdf", FileMode.Create))) { document.Open(); BaseFont dwarvenBaseFont = BaseFont.CreateFont(@"Resources\Font.TTF", BaseFont.CP1252, BaseFont.EMBEDDED); Image logo = Image.GetInstance(@"Resources\Logo.png"); logo.ScalePercent(50f); logo.Alignment = Element.ALIGN_CENTER; PdfPTable table = new PdfPTable(1); PdfPCell cellLogo = new PdfPCell(); cellLogo.AddElement(logo); cellLogo.Border = Rectangle.NO_BORDER; table.Rows.Add(new PdfPRow(new PdfPCell[] { cellLogo })); PdfPCell cellHeader = new PdfPCell(); Paragraph header = new Paragraph() { Alignment = Element.ALIGN_CENTER, Font = new Font(dwarvenBaseFont, 30f, iTextSharp.text.Font.BOLD, new BaseColor(220, 20, 60)) }; header.Add(@"Member of The Glorious Dwarven Race"); header.SetLeading(0f, 1.2f); cellHeader.AddElement(header); cellHeader.Border = Rectangle.NO_BORDER; table.Rows.Add(new PdfPRow(new PdfPCell[] { cellHeader })); document.Add(table); Paragraph text = new Paragraph() { Alignment = Element.ALIGN_LEFT, Font = new Font(dwarvenBaseFont, 20f) }; StringBuilder stringText = new StringBuilder($"{CurrentUser.Login} is from now henceforth known as a member of The Dwarfs and till the end of times should be treated with all the honours.{Environment.NewLine}The belongings of {CurrentUser.Login} is {CurrentUser.ClanName}"); if (CurrentUser.ClanName == "No Clan") { stringText.Append($" as {CurrentUser.Login} is an Outcast and cannot find a place for itself."); } else { stringText.Append($" and should be proud of as it is true honour for The Dwarf to share life with such a great companions.{Environment.NewLine}In this powerful clan {CurrentUser.Login} is known for holding the rank of {CurrentUser.Rank.Name} and it is truly right thing to do for such skilled hands to bear this duties."); } text.Add(stringText.ToString()); document.Add(text); document.Close(); } }
/// <summary> /// Wyświetla listę stworzonych certifikatów przez użytkownika /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonListOfCertificates_Click(object sender, EventArgs e) { dataGridViewTables.DataSource = DocumentCreations.GetAll().Where(document => document.UserName == CurrentUser.Login).Select(document => new { document.CreationTime, Name = document.CreatedDocument }).ToList(); }