First version of the report generating engine finished, Both front and back pages are merged into one PDF. Seems the user's screen resolution and/or size affect the size of the PDF document, I feel this is a sort of bug that must be fixed at some point.

This commit is contained in:
2017-05-08 19:51:45 -05:00
parent 15abab5f50
commit 718562222d
10 changed files with 170 additions and 143 deletions
+30 -8
View File
@@ -10,9 +10,28 @@ namespace AdvertsingProfitControl
{
internal class FrontPageGenerator
{
FrmLogConsole _console = FrmLogConsole.GetStaticInstance;
public void BuildReportFrontPage(DateTime date, ref HtmlTextWriter writer)
/// <summary>
/// Generates the front page of the report, Advertising Profit Control, as a single PDF file.
/// </summary>
/// <param name="date"></param>
public void GenerateFrontPage(DateTime date)
{
var stringWriter = new StringWriter();
var writer = new HtmlTextWriter(stringWriter);
BuildReportFrontPage(date, ref writer);
var frontPage = new SimplePechkin(new GlobalConfig().SetPaperOrientation(true).SetPaperSize(PaperKind.A4)).Convert(stringWriter.ToString());
//
using (var fs = new FileStream(GlobalClasses.LogFilePath + "Front.pdf", FileMode.Create, FileAccess.Write))
{
fs.Write(frontPage, 0, frontPage.Length);
}
}
/// <summary>
/// Generates the HTML code for the front page, Advertising Profit Control.
/// </summary>
/// <param name="date"></param>
/// <param name="writer"></param>
private void BuildReportFrontPage(DateTime date, ref HtmlTextWriter writer)
{
var db = new AdvertisingProfitControlModel();
var dateRecord = db.WeekEndingDates.SingleOrDefault(x => x.EndingDate == date);
@@ -27,15 +46,16 @@ namespace AdvertsingProfitControl
writer.AddAttribute(HtmlTextWriterAttribute.Type, "text/css");
//Set the global style for the data cells.
writer.RenderBeginTag(HtmlTextWriterTag.Style);
writer.Write("td{margins:0; padding:2px; border:1px solid black; font-size:20px; text-align:center; vertical-align:bottom}");
writer.Write("td{margins:0; padding:2px; border:1px solid black; font-size:14px; text-align:center; vertical-align:bottom}");
writer.RenderEndTag();// end style
writer.RenderEndTag(); // end Head
//writer.AddAttribute(HtmlTextWriterAttribute.Style, "width:11in; height:8in");
writer.RenderBeginTag(HtmlTextWriterTag.Body);
writer.AddAttribute(HtmlTextWriterAttribute.Style, "border:none; border-collapse: collapse; width:100%"); //style for the table
writer.AddAttribute(HtmlTextWriterAttribute.Style, "border:none; border-collapse: collapse; margin-top:1in; width:100%; height:100%"); //style for the table
writer.RenderBeginTag(HtmlTextWriterTag.Table);
//Begin rendering the top rows, the form name, store, department and date fields.
writer.RenderBeginTag(HtmlTextWriterTag.Tr);//begin first row
writer.AddAttribute(HtmlTextWriterAttribute.Style, "border:none; font-size:40px");
writer.AddAttribute(HtmlTextWriterAttribute.Style, "border:none; font-size:30px");
writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "20");
writer.RenderBeginTag(HtmlTextWriterTag.Td);
writer.Write("<b>Advertising Profit Control v" + Application.ProductVersion + "</b>");
@@ -291,6 +311,8 @@ namespace AdvertsingProfitControl
writer.RenderEndTag();//end totals row
//end totals row
writer.RenderEndTag();//table
writer.RenderEndTag();//body
writer.RenderEndTag();//html
}
private void RenderCostsAnalysisCell(CostAnalysisCells cell, ref HtmlTextWriter writer, decimal? value, string rowSpan)
@@ -318,11 +340,11 @@ namespace AdvertsingProfitControl
break;
case CostAnalysisCells.ProfitReturnFromRemainingSales:
number = "5";
labelText = "Total $ Profit Return<br>From Remaining Sales<br><br>Going-in Gross % x Remaining Sales";
labelText = "Total $ Profit Return<br>From Remaining Sales";
break;
case CostAnalysisCells.TotalProfitReturn:
number = "6";
labelText = "Total $ Profit<br>Return<br><br>Line 4 Plus Line 5";
labelText = "Total $ Profit<br>Return<br>Line 4 Plus Line 5";
break;
case CostAnalysisCells.CrossProfitInfoCell:
break;