Finished initial build of the back page generator. Unable to properly merge the two tables with Pechkin so far.

This commit is contained in:
2017-05-06 01:08:38 -05:00
parent 218d5be4d6
commit 15abab5f50
12 changed files with 958 additions and 645 deletions
+8 -64
View File
@@ -4,7 +4,6 @@ using System.Windows.Forms;
using System.IO;
using System.Web.UI;
using System.Linq;
using System.Web.UI.WebControls;
using Pechkin;
namespace AdvertsingProfitControl
@@ -13,61 +12,8 @@ namespace AdvertsingProfitControl
{
FrmLogConsole _console = FrmLogConsole.GetStaticInstance;
public void RenderHtmlToImage()
public void BuildReportFrontPage(DateTime date, ref HtmlTextWriter writer)
{
var htmlCode = File.ReadAllLines(Application.StartupPath + "\\FrontPage.html");
var code = "";
foreach (var line in htmlCode)
{
code = code + "\r\n" + line;
}
try
{
//var imageFromHtml = HtmlRender.RenderToImage(code);
//imageFromHtml.RotateFlip(RotateFlipType.Rotate90FlipNone);
//imageFromHtml.Save(Application.StartupPath + "\\FrontPage.png", ImageFormat.Png);
//imageFromHtml.Dispose();
}
catch (Exception e)
{
_console.WriteToLog(FrmLogConsole.Level.Critical,
"Failed to generate an updated image for the front page of Advertising Profit Control.");
_console.WriteToLog(FrmLogConsole.Level.Debug, e.Message);
_console.WriteToLog(FrmLogConsole.Level.Info,
"This is most likely a screw you from the GDI+ subsystem of Windows.");
}
}
public byte[] RenderHtmlCodeToImage(string path, string targetPath)
{
var htmlCode = File.ReadAllLines(path);
var code = htmlCode.Aggregate("", (current, line) => current + "\r\n" + line);
try
{
var config = new Pechkin.GlobalConfig().SetPaperSize(PaperKind.A4).SetPaperOrientation(true);
byte[] pdfBuf = new SimplePechkin(config).Convert(code);
using (var fs = new FileStream(targetPath, FileMode.Create, FileAccess.Write))
{
fs.Write(pdfBuf, 0, pdfBuf.Length);
}
return pdfBuf;
}
catch (Exception e)
{
_console.WriteToLog(FrmLogConsole.Level.Critical,
"Failed to generate an updated image for the back page of Advertising Profit Control.");
_console.WriteToLog(FrmLogConsole.Level.Debug, e.Message);
_console.WriteToLog(FrmLogConsole.Level.Info, "This is most likely a screw you from the GDI+ subsystem of Windows.");
}
return new byte[1];
}
public void BuildFormFrontCompressedLayout(DateTime date)
{
var stringWriter = new StringWriter();
var writer = new HtmlTextWriter(stringWriter);
var db = new AdvertisingProfitControlModel();
var dateRecord = db.WeekEndingDates.SingleOrDefault(x => x.EndingDate == date);
if (dateRecord == null)
@@ -85,7 +31,7 @@ namespace AdvertsingProfitControl
writer.RenderEndTag();// end style
writer.RenderEndTag(); // end Head
writer.RenderBeginTag(HtmlTextWriterTag.Body);
writer.AddAttribute(HtmlTextWriterAttribute.Style, "border:none; border-collapse: collapse; width:100%; height:100%"); //style for the table
writer.AddAttribute(HtmlTextWriterAttribute.Style, "border:none; border-collapse: collapse; width: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
@@ -345,14 +291,6 @@ namespace AdvertsingProfitControl
writer.RenderEndTag();//end totals row
//end totals row
writer.RenderEndTag();//table
writer.RenderEndTag();//body
writer.RenderEndTag();//HTML
using (var streamWriter = new StreamWriter("C:\\Users\\Crypto\\Desktop\\TestPage.html"))
{
streamWriter.WriteLine(stringWriter.ToString());
}
RenderHtmlToImage();
}
private void RenderCostsAnalysisCell(CostAnalysisCells cell, ref HtmlTextWriter writer, decimal? value, string rowSpan)
@@ -478,10 +416,16 @@ namespace AdvertsingProfitControl
writer.AddAttribute(HtmlTextWriterAttribute.Style, "border-left:none; border-right:double");
break;
case 6:
writer.AddAttribute(HtmlTextWriterAttribute.Style, "border-right:double; background-color:#e9e9e9");
break;
case 16:
writer.AddAttribute(HtmlTextWriterAttribute.Style, "border-right:double");
break;
}
if (cellCount > 0 && cellCount < 6)
{
writer.AddAttribute(HtmlTextWriterAttribute.Style, "background-color:#e9e9e9");
}
writer.RenderBeginTag(HtmlTextWriterTag.Td);
writer.Write("<br>");
writer.RenderEndTag();