I have passed in some data into the DefineInvoice function from the database we are using using this code:
Code:
public void DefineInvoice(Document document,List<TicketView1> SampleTickets)
Looking into the data of SampleTickets we have key/value pairs for example such as this:
agreement_name: "Website Development 101"
billable_hrs: 9
customer_id: 36
customer_name: "Python Bank"
date_created: {4/29/2020 12:00:00 AM}...
and so forth. I have a table already created like so:
Code:
//define table
Table table = section.AddTable();
table.Borders.Width = 0.75;
Column column = table.AddColumn(Unit.FromCentimeter(7));
column.Format.Alignment = ParagraphAlignment.Center;
column = table.AddColumn(Unit.FromCentimeter(2));
column.Format.Alignment = ParagraphAlignment.Center;
column = table.AddColumn(Unit.FromCentimeter(2));
column.Format.Alignment = ParagraphAlignment.Center;
column = table.AddColumn(Unit.FromCentimeter(2));
column.Format.Alignment = ParagraphAlignment.Center;
column = table.AddColumn(Unit.FromCentimeter(2));
column.Format.Alignment = ParagraphAlignment.Center;
//define header of table
Row row = table.AddRow();
row.HeadingFormat = true;
Cell cell = row.Cells[0];
cell.AddParagraph("Customer Name");
cell.Format.Font.Bold = true;
cell = row.Cells[1];
cell.AddParagraph("Date Created");
cell.Format.Font.Bold = true;
cell = row.Cells[2];
cell.AddParagraph("Description");
cell.Format.Font.Bold = true;
cell = row.Cells[3];
cell.AddParagraph("Due Date");
cell.Format.Font.Bold = true;
cell = row.Cells[4];
cell.AddParagraph("Billable Hours");
cell.Format.Font.Bold = true;
//define one row of invoice information
row = table.AddRow();
cell = row.Cells[0];
cell.AddParagraph("Admin theme with psd project layouts");
cell = row.Cells[1];
cell.AddParagraph("1");
cell = row.Cells[2];
cell.AddParagraph("$26.00");
cell = row.Cells[3];
cell.AddParagraph("$5.98");
cell = row.Cells[4];
cell.AddParagraph("$31.98");
//define another row of invoice information
row = table.AddRow();
cell = row.Cells[0];
cell.AddParagraph("Wordpress Theme customization");
cell = row.Cells[1];
cell.AddParagraph("2");
cell = row.Cells[2];
cell.AddParagraph("$80.00");
cell = row.Cells[3];
cell.AddParagraph("$36.80");
cell = row.Cells[4];
cell.AddParagraph("$196.80");
//define another row of invoice information
row = table.AddRow();
cell = row.Cells[0];
cell.AddParagraph("Angular 9 and Node JS Application");
cell = row.Cells[1];
cell.AddParagraph("3");
cell = row.Cells[2];
cell.AddParagraph("$420.00");
cell = row.Cells[3];
cell.AddParagraph("$193.20");
cell = row.Cells[4];
cell.AddParagraph("$1033.20");
//add invisible row as a space line to the table
row = table.AddRow();
row.Borders.Visible = false;
//add the subtotal row
row = table.AddRow();
row.Cells[0].Borders.Visible = false;
row.Cells[0].AddParagraph("Sub Total:");
row.Cells[0].Format.Font.Bold = true;
row.Cells[0].Format.Alignment = ParagraphAlignment.Right;
row.Cells[0].MergeRight = 3;
//add tax row
row = table.AddRow();
row.Cells[0].Borders.Visible = false;
row.Cells[0].AddParagraph("TAX:");
row.Cells[0].Format.Font.Bold = true;
row.Cells[0].Format.Alignment = ParagraphAlignment.Right;
row.Cells[0].MergeRight = 3;
//add total
row = table.AddRow();
row.Cells[0].Borders.Visible = false;
row.Cells[0].AddParagraph("TOTAL:");
row.Cells[0].Format.Font.Bold = true;
row.Cells[0].Format.Alignment = ParagraphAlignment.Right;
row.Cells[0].MergeRight = 3;
As you can see for my table headers such as "Customer name" I want to put that customer_name value into that cell. How would I do that? So far I have:
Code:
foreach (TicketView1 ticket in SampleTickets)
{
//customer_name
//date_created
//description
//due_date
//billable_hrs
}
I am also learning C# as I go.. or I at least know most of the basics so this is tough for me. Any hints/tips or suggestions?