-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm4.cs
More file actions
107 lines (88 loc) · 4.54 KB
/
Copy pathForm4.cs
File metadata and controls
107 lines (88 loc) · 4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
using iTextSharp.text;
using iTextSharp.text.pdf;
namespace H1
{
public partial class Form4 : Form
{
private string connectionString = @"Data Source=ABDULSABOOR190\SQLEXPRESS;Initial Catalog=sabbbb;Integrated Security=True;Encrypt=False";
private int currentUserId; // Will be set from login
public Form4(int userId) // Modified constructor to accept user ID
{
InitializeComponent();
currentUserId = userId;
}
private void Form4_Load(object sender, EventArgs e)
{
}
private void button1_Click_1(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "PDF Files (*.pdf)|*.pdf";
saveFileDialog.FileName = $"TravelPass_{DateTime.Now:yyyyMMdd}.pdf";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
GenerateDigitalPassPDF(saveFileDialog.FileName);
}
}
private void GenerateDigitalPassPDF(string filePath)
{
try
{
// Create document
Document document = new Document(PageSize.A4, 20, 20, 30, 30);
PdfWriter writer = PdfWriter.GetInstance(document, new System.IO.FileStream(filePath, System.IO.FileMode.Create));
document.Open();
// Add title
Font titleFont = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 18, BaseColor.BLUE);
Paragraph title = new Paragraph("DIGITAL TRAVEL PASS\n\n", titleFont);
title.Alignment = Element.ALIGN_CENTER;
document.Add(title);
// Add passenger section
Font sectionFont = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 12);
Paragraph passengerSection = new Paragraph("PASSENGER INFORMATION", sectionFont);
passengerSection.SpacingBefore = 20;
document.Add(passengerSection);
// Add passenger details from textboxes
Font detailFont = FontFactory.GetFont(FontFactory.HELVETICA, 10);
document.Add(new Paragraph($"First Name: {txtFirstName.Text}", detailFont));
document.Add(new Paragraph($"Last Name: {txtLastName.Text}", detailFont));
document.Add(new Paragraph($"Email: {lblEmail.Text}", detailFont));
document.Add(new Paragraph($"Phone: {txtPhone.Text}\n", detailFont));
// Add pass section
Paragraph passSection = new Paragraph("TRAVEL DETAILS", sectionFont);
passSection.SpacingBefore = 15;
document.Add(passSection);
// Add pass details from labels
document.Add(new Paragraph($"Passenger Name: {lblPassenger.Text.Replace("Passenger Name: ", "")}", detailFont));
document.Add(new Paragraph($"Pass ID: {lblPassId.Text}", detailFont));
document.Add(new Paragraph($"Validity: {lblValidity.Text}", detailFont));
document.Add(new Paragraph($"Destination: {lblDestination.Text}\n", detailFont));
// Add decorative elements
Paragraph divider = new Paragraph(new string('-', 50));
divider.SpacingBefore = 10;
divider.SpacingAfter = 10;
document.Add(divider);
// Add footer
Paragraph footer = new Paragraph("\nThis is your official digital travel pass.\nGenerated on: " + DateTime.Now.ToString("MMMM dd, yyyy"));
footer.Alignment = Element.ALIGN_CENTER;
document.Add(footer);
document.Close();
writer.Close();
}
catch (Exception ex)
{
MessageBox.Show($"Error generating PDF: {ex.Message}");
}
}
private void button2_Click(object sender, EventArgs e)
{
// Share button remains unchanged
MessageBox.Show("Share functionality would send the digital pass via email or other methods",
"Share", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}