Created the first version of HTML code for the front form. Changed to the Pechkin HTML to PDF library. Removed the string tester. Fixed a bug with the main form where the APC tables would not be sorted by row position.
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
using System;
|
||||
using System.Drawing.Printing;
|
||||
using System.Windows.Forms;
|
||||
using System.IO;
|
||||
using System.Web.UI;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using TheArtOfDev.HtmlRenderer.WinForms;
|
||||
using System.Linq;
|
||||
using System.Web.UI.WebControls;
|
||||
using Pechkin;
|
||||
|
||||
namespace AdvertsingProfitControl
|
||||
{
|
||||
@@ -23,10 +24,10 @@ namespace AdvertsingProfitControl
|
||||
|
||||
try
|
||||
{
|
||||
var imageFromHtml = HtmlRender.RenderToImage(code);
|
||||
imageFromHtml.RotateFlip(RotateFlipType.Rotate90FlipNone);
|
||||
imageFromHtml.Save(Application.StartupPath + "\\FrontPage.png", ImageFormat.Png);
|
||||
imageFromHtml.Dispose();
|
||||
//var imageFromHtml = HtmlRender.RenderToImage(code);
|
||||
//imageFromHtml.RotateFlip(RotateFlipType.Rotate90FlipNone);
|
||||
//imageFromHtml.Save(Application.StartupPath + "\\FrontPage.png", ImageFormat.Png);
|
||||
//imageFromHtml.Dispose();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -38,469 +39,466 @@ namespace AdvertsingProfitControl
|
||||
}
|
||||
}
|
||||
|
||||
public void BuildFormFrontCompressedLayout(int dateId, double departmentSales, double salesProducedByAdItems, double remainingSales, double totalProfitReturnFromAdItems, double totalProfitReturnFromRemainingSales, double totalProfitReturn, string comments)
|
||||
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 databaseTracker = new DatabaseTracker();
|
||||
//var databaseReader = new DatabaseReader();
|
||||
var stringWriter = new StringWriter();
|
||||
var writer = new HtmlTextWriter(stringWriter);
|
||||
//var table = databaseReader.ReturnApcTableForReport(dateId, databaseTracker.DatabaseConnectionString);
|
||||
//var dateString = databaseReader.RetrieveDateStringById(dateId, databaseTracker.DatabaseConnectionString);
|
||||
//var spam = dateString.Split(' ');
|
||||
//dateString = spam[0];
|
||||
//Begin evaluating the size of the table.
|
||||
var isCompressedFormat = false;
|
||||
var willGenerateCommentRow = false;
|
||||
//if ((table.Rows.Count + 1) == 15)
|
||||
//{
|
||||
// willGenerateCommentRow = true;
|
||||
//}
|
||||
//else if ((table.Rows.Count + 1) < 15)
|
||||
//{
|
||||
// isCompressedFormat = true;
|
||||
//}
|
||||
var db = new AdvertisingProfitControlModel();
|
||||
var dateRecord = db.WeekEndingDates.SingleOrDefault(x => x.EndingDate == date);
|
||||
if (dateRecord == null)
|
||||
{
|
||||
MessageBox.Show("Failed");
|
||||
return;
|
||||
}
|
||||
writer.Write("<!DOCTYPE html>\n");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Html);
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Head);
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Type, "text/css");
|
||||
//Set the global style for the data cells.
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Style);
|
||||
writer.Write("th{margins:0; padding:0; vertical-align:bottom; height:35px; font-size:14px; border:1px solid black}");
|
||||
writer.Write("td{margins:0; padding:0; border:1px solid black; font-size:14px; text-align:center; height:35px}");
|
||||
writer.RenderEndTag();//style
|
||||
writer.RenderEndTag(); // Head
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "width:11in; height:8in");
|
||||
writer.Write("td{margins:0; padding:2px; border:1px solid black; font-size:20px; text-align:center; vertical-align:bottom}");
|
||||
writer.RenderEndTag();// end style
|
||||
writer.RenderEndTag(); // end Head
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Body);
|
||||
//Begin building the header for the page, the HTML engine doesn't seem to like putting content in the Head.
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "margin-top:200px; width:100%");
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "border:none; border-collapse: collapse; width:100%; height:100%"); //style for the table
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Table);
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "margin:0px; padding:0px");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "font-size:14px; width:20%; vertical-align:bottom; border:none");
|
||||
//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.Colspan, "20");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
writer.Write("<p>Store Name:<u> Allen's of Hastings</u></p>");
|
||||
writer.RenderEndTag();//td
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "width:50%; font-size:15px; margin:0px; padding: 0px 0px 0px 0px; border:none");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td); // <br><p style=\"font-size:10px\">(Mode: " + (willGenerateCommentRow ? "Generates Comment row" : "Compressed Format") + ")
|
||||
writer.Write("<p><center><h2>Advertising Profit Control v " + Application.ProductVersion + "</h2></center></p>");
|
||||
writer.RenderEndTag();//td
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "width:33%; padding: 0px 0px 0px 0px; margin:0px; border:none; vertical-align:bottom");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
writer.Write("<p><span style=\"margin-left:102px\">Week Ending: <u> + dateString + </u></span><br><span style=\"margin-left:86px\">Department: <u>Produce</u></span></p>");
|
||||
writer.RenderEndTag();//td
|
||||
writer.RenderEndTag();//tr
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "margin:0px; padding:0px");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
|
||||
writer.Write("<b>Advertising Profit Control v" + Application.ProductVersion + "</b>");
|
||||
writer.RenderEndTag();//end product cell.
|
||||
writer.RenderEndTag(); //End of first row
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Tr); //begin second row
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "text-align:left; border:none");
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "9");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);//begin store name cell
|
||||
writer.Write("Store Name: <u>Allen's of Hastings</u>");
|
||||
writer.RenderEndTag();//end store name cell
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "text-align:right; border:none");
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "11");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td); //begin date and department cell
|
||||
writer.Write("Week Ending: <u>" + date.ToString("d") + "</u><br>Department: <u>Produce</u>");
|
||||
writer.RenderEndTag();//End date and department cell
|
||||
writer.RenderEndTag();// second row
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Tr);//begin label row
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "border:none");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
writer.RenderEndTag();//td
|
||||
writer.RenderEndTag();
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "border:none");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
writer.Write("<p><span style=\"margin-right:280px\">Projection</span><span>Actual</span></p>");
|
||||
writer.RenderEndTag();//td
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "6");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);//projections label cell
|
||||
writer.Write("Projection");
|
||||
writer.RenderEndTag();//end projections label cell
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "border:none");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
writer.Write("<p style=\"margin-left:150px\">Profit Analysis</p>");
|
||||
writer.RenderEndTag();//td
|
||||
writer.RenderEndTag();//tr
|
||||
writer.RenderEndTag();//table
|
||||
//END of header table structure
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "border:none; border-collapse: collapse; width:11in; height:7.0in; table-layout:fixed"); //style for the table
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Table);
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "10");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);//actual label cell
|
||||
writer.Write("Actual");
|
||||
writer.RenderEndTag();//end actual label cell
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "3");
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "border:none");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);//cost analysis label cell
|
||||
writer.Write("Cost Analysis");
|
||||
writer.RenderEndTag();//end cost analysis label cell
|
||||
writer.RenderEndTag();//end label row (third row)
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
|
||||
//Begin building the header row.
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "border-left:none");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Th);
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "border-left:none; border-right:double");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
writer.Write("Ad Items");
|
||||
writer.RenderEndTag(); //th
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "background-color:#e9e9e9");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Th);
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
writer.Write("Sold");
|
||||
writer.RenderEndTag(); //th
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "background-color:#e9e9e9");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Th);
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
writer.Write("Sale<br>Price");
|
||||
writer.RenderEndTag(); //th
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "background-color:#e9e9e9");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Th);
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
writer.Write("Total<br>Sales");
|
||||
writer.RenderEndTag(); //th
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "background-color:#e9e9e9");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Th);
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
writer.Write("Cost");
|
||||
writer.RenderEndTag(); //th
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "background-color:#e9e9e9");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Th);
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
writer.Write("$<br>Prof.<br>Retn.");
|
||||
writer.RenderEndTag(); //th
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "background-color:#e9e9e9");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Th);
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "background-color:#e9e9e9; border-right:double");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
writer.Write("Total<br>$<br>Prof.<br>Retn.");
|
||||
writer.RenderEndTag(); //th
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Th);
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
writer.Write("Beg.<br>Inv.");
|
||||
writer.RenderEndTag(); //th
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Th);
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
writer.Write("Rec'd");
|
||||
writer.RenderEndTag(); //th
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Th);
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
writer.Write("Total");
|
||||
writer.RenderEndTag(); //th
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Th);
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
writer.Write("End.<br>Inv.");
|
||||
writer.RenderEndTag(); //th
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Th);
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
writer.Write("Sold");
|
||||
writer.RenderEndTag(); //th
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Th);
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
writer.Write("Sale<br>Price");
|
||||
writer.RenderEndTag(); //th
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Th);
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
writer.Write("Total<br>Sales");
|
||||
writer.RenderEndTag(); //th
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Th);
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
writer.Write("Cost");
|
||||
writer.RenderEndTag(); //th
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Th);
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
writer.Write("$<br>Prof.<br>Retn.");
|
||||
writer.RenderEndTag(); //th
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Th);
|
||||
writer.RenderEndTag(); //th
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
writer.Write("Total<br>$<br>Prof.<br>Retn.");
|
||||
writer.RenderEndTag(); //th
|
||||
//Department Sales
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "width:159px; border-right:none");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
writer.Write("<center>Department<br>Sales</center><p><span style=\"font-size:9px; vertical-align:bottom\">1</span><span style=\"margin-left:60px\">"+ $"{departmentSales:C}" + "</span></p>");
|
||||
writer.RenderEndTag();//td
|
||||
//Grab the department sales from the database
|
||||
var departmentRecord = db.WeeklySales.SingleOrDefault(x => x.FkDateId == dateRecord.Id);
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "border-right:none; border-left:double; font-size:9px");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);//begin number cell
|
||||
writer.Write("1");
|
||||
writer.RenderEndTag();//end number cell
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "border-right:none; border-left:none");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);//begin department sales cell
|
||||
writer.Write("Department<br>Sales");
|
||||
writer.RenderEndTag();//end department sales cell
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "border-right:none; border-left:none");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);//department sales total sales column
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "margin:0px; border-left:1px solid black; border-top:1px dashed black; text-align:right");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.P);//begin department sales paragraph tag; used because the borders of the element are flush with that of the cell's.
|
||||
writer.Write(departmentRecord == null ? "$0.00" : $"{departmentRecord.TotalSales:C}");
|
||||
writer.RenderEndTag();//end department sales paragraph tag
|
||||
writer.RenderEndTag();//department sales total sales column
|
||||
writer.RenderEndTag();//End of header row code.
|
||||
|
||||
var isRowMember = false;
|
||||
var isRenderingGroup = false;
|
||||
var adSpecialRowIndex = -1;
|
||||
//Variables for the Totals row.
|
||||
double projectionProfitReturn = 0;
|
||||
double projectionTotalProfitReturn = 0;
|
||||
double actualProfitReturn = 0;
|
||||
double actualTotalProfitReturn = 0;
|
||||
var adSpecialOffset = 0;
|
||||
//Profit Analysis values.
|
||||
//for (var rowIndex = 0; rowIndex < (table.Rows.Count < 19 ? 19 : table.Rows.Count); rowIndex++) //The comparison in the for loop is index based, so no need to add one to the row count.
|
||||
//{
|
||||
// var isProfitAnalysisCell = false;
|
||||
// //IF the row index goes beyond the number of rows that are in the table, then start padding with blank cells to fit the Profit Analysis cells.
|
||||
// if (rowIndex < table.Rows.Count)
|
||||
// {
|
||||
// var row = table.Rows[rowIndex];
|
||||
// var rowAttribute = 0;
|
||||
// var groupId = 0;
|
||||
// if (int.TryParse(row.ItemArray[17].ToString(), out rowAttribute))
|
||||
// {
|
||||
// if (rowAttribute != 0)
|
||||
// {
|
||||
// if (rowAttribute == 1)
|
||||
// {
|
||||
// isRowMember = false;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// isRowMember = true;
|
||||
// }
|
||||
// isRenderingGroup = true;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// isRenderingGroup = false;
|
||||
// isRowMember = false;
|
||||
// }
|
||||
// }
|
||||
// if (adSpecialRowIndex == -1 && int.TryParse(row.ItemArray[18].ToString(), out groupId))
|
||||
// {
|
||||
// if (groupId != 0)
|
||||
// {
|
||||
// adSpecialRowIndex = rowIndex;
|
||||
// writer.RenderBeginTag(HtmlTextWriterTag.Tr);
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "17");
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Style, "border-left:none");
|
||||
// writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
// writer.Write("<center>" +
|
||||
// databaseReader.ReturnGroupNameFromGroupId(groupId.ToString(),
|
||||
// databaseTracker.DatabaseConnectionString) + "</center>");
|
||||
// writer.RenderEndTag(); //td
|
||||
// writer.RenderEndTag(); //tr
|
||||
// BuildProfitAnalysisCell(ref writer, rowIndex, out isProfitAnalysisCell, salesProducedByAdItems, remainingSales, totalProfitReturnFromAdItems, totalProfitReturnFromRemainingSales, totalProfitReturn);
|
||||
// adSpecialOffset++;
|
||||
// }
|
||||
// }
|
||||
// writer.RenderBeginTag(HtmlTextWriterTag.Tr);
|
||||
// for (var i = 0; i < row.ItemArray.Length; i++)
|
||||
// {
|
||||
// if (i >= 17) continue;
|
||||
// if (i == 0)
|
||||
// {
|
||||
// writer.AddStyleAttribute(HtmlTextWriterStyle.TextAlign, "left");
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Style, "border-left:none");
|
||||
// }
|
||||
// else if (i > 0 && i < 7)
|
||||
// {
|
||||
// //background-color:#e9e9e9
|
||||
// writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, "#e9e9e9");
|
||||
// }
|
||||
// writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
// decimal number;
|
||||
// if (decimal.TryParse(row.ItemArray[i].ToString(), out number))
|
||||
// {
|
||||
// //Check for the inventory columns and the sold columns.
|
||||
// if (!isRowMember)
|
||||
// {
|
||||
// if (i == 1 || i > 6 && i < 12)
|
||||
// {
|
||||
// writer.Write(number == 0 ? "0" : row.ItemArray[i].ToString());
|
||||
// }
|
||||
// if (i > 1 && i < 7 || i > 11)
|
||||
// {
|
||||
// writer.Write(number == 0 ? "0.00" : $"{number:N}");
|
||||
// }
|
||||
// }
|
||||
var projections = db.Projections.Where(x => x.FkDateId == dateRecord.Id).OrderBy(x => x.RowPosition).ToList();
|
||||
var inventory = db.Inventories.Where(x => x.FkDateId == dateRecord.Id).OrderBy(x => x.RowPosition).ToList();
|
||||
var actualSales = db.ActualSales.Where(x => x.FkDateId == dateRecord.Id).OrderBy(x => x.RowPosition).ToList();
|
||||
var comments = db.Notes.SingleOrDefault(x => x.FkDateId == dateRecord.Id);
|
||||
var projectionA = projections.Sum(x => x.TotalSales);
|
||||
var projectionB = projections.Sum(x => x.TotalProfitReturn);
|
||||
var actualA = actualSales.Sum(x => x.TotalSales);
|
||||
var actualB = actualSales.Sum(x => x.TotalProfitReturn);
|
||||
var adSpecialIndex = -1;
|
||||
for (var i = 0; i < 25; i++)
|
||||
{
|
||||
var skipCheck = false;
|
||||
if (i < projections.Count)
|
||||
{
|
||||
if (projections[i].FkAdSpecialId != null)
|
||||
{
|
||||
if (adSpecialIndex == -1)
|
||||
{
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Tr); //ad special table row
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "border-left:none; border-right:double");
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "17");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
writer.Write(projections[i].AdSpecial.Name);
|
||||
writer.RenderEndTag(); //ad special cell
|
||||
skipCheck = true;
|
||||
SelectCostAnalysisCell(i, ref writer, actualA, actualB, departmentRecord, comments);
|
||||
writer.RenderEndTag(); //end ad special row
|
||||
}
|
||||
adSpecialIndex = i;
|
||||
}
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style,
|
||||
"border-left:none; border-right:double; text-align:left");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td); //ad item cell
|
||||
writer.Write(projections[i].AdItem.Name);
|
||||
writer.RenderEndTag(); //end ad item cell
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "background-color:#e9e9e9");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td); //projection sold
|
||||
writer.Write(projections[i].Sold);
|
||||
writer.RenderEndTag(); //end projection sold
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "background-color:#e9e9e9");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td); //projection sale price
|
||||
writer.Write(projections[i].SalePrice);
|
||||
writer.RenderEndTag(); //end projection sale price
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "background-color:#e9e9e9");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td); //projection total sales
|
||||
writer.Write($"{projections[i].TotalSales:N2}");
|
||||
writer.RenderEndTag(); //end projection total sales
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "background-color:#e9e9e9");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td); //projection cost
|
||||
writer.Write($"{projections[i].Cost:N2}");
|
||||
writer.RenderEndTag(); //end projection cost
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "background-color:#e9e9e9");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td); //projection profit return
|
||||
writer.Write($"{projections[i].ProfitReturn:N2}");
|
||||
writer.RenderEndTag(); //end projection profit return
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "background-color:#e9e9e9; border-right:double");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td); //projection total profit return
|
||||
writer.Write($"{projections[i].TotalProfitReturn:N2}");
|
||||
writer.RenderEndTag(); //end projection total profit return
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td); //inventory beginning
|
||||
writer.Write(inventory[i].BeginningInventory);
|
||||
writer.RenderEndTag(); //end inventory beginning
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td); //inventory received
|
||||
writer.Write(inventory[i].Recieved);
|
||||
writer.RenderEndTag(); //end inventory received
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td); //inventory total
|
||||
writer.Write(inventory[i].TotalInventory);
|
||||
writer.RenderEndTag(); //end inventory total
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td); //inventory ending
|
||||
writer.Write(inventory[i].EndingInventory);
|
||||
writer.RenderEndTag(); //end inventory ending
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td); //actual sales sold
|
||||
writer.Write(actualSales[i].Sold);
|
||||
writer.RenderEndTag(); //end actual sales sold
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td); //actual sales sale price
|
||||
writer.Write(actualSales[i].SalePrice);
|
||||
writer.RenderEndTag(); //end actual sales sale price
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td); //actual sales total sales
|
||||
writer.Write($"{actualSales[i].TotalSales:N2}");
|
||||
writer.RenderEndTag(); //end actual sales total sales
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td); //actual sales cost
|
||||
writer.Write($"{actualSales[i].Cost:N2}");
|
||||
writer.RenderEndTag(); //end actual sales cost
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td); //actual sales profit return
|
||||
writer.Write($"{actualSales[i].ProfitReturn:N2}");
|
||||
writer.RenderEndTag(); //end actual sales profit return
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "border-right:double");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td); //actual sales total profit return
|
||||
writer.Write($"{actualSales[i].TotalProfitReturn:N2}");
|
||||
writer.RenderEndTag(); //end actual sales total profit return
|
||||
}
|
||||
else
|
||||
{
|
||||
//Pad
|
||||
AppendPaddingRow(ref writer);
|
||||
}
|
||||
if(!skipCheck) SelectCostAnalysisCell(adSpecialIndex != -1 ? i + 1 : i, ref writer, actualA, actualB, departmentRecord, comments);
|
||||
writer.RenderEndTag();//tr
|
||||
}
|
||||
//Create the totals row
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "border-left:none; border-right:double");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);//empty cell
|
||||
writer.RenderEndTag();//end padding
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "text-align:right");
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "2");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);//projections total label cell
|
||||
writer.Write("TOTAL");
|
||||
writer.RenderEndTag();//end projections total label cell
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "2");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);//projections A (total sales)
|
||||
writer.Write("(A) " + $"{projectionA:N2}");
|
||||
writer.RenderEndTag();//end projections A (total sales)
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "border-right:double");
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "2");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);//projections B (total profit return)
|
||||
writer.Write("(B) " + $"{projectionB:N2}");
|
||||
writer.RenderEndTag();//end projections B (total profit return)
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "5");
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "text-align:right");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);//actual sales total label cell
|
||||
writer.Write("TOTAL");
|
||||
writer.RenderEndTag();//end actual sales total label cell
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "2");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);//actual sales A (total sales)
|
||||
writer.Write("(A) " + $"{actualA:N2}");
|
||||
writer.RenderEndTag();//end actual sales A (total sales)
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);//begin empty cell
|
||||
writer.RenderEndTag();//end empty cell
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "border-right:double");
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "2");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);//actual sales B (total profit return)
|
||||
writer.Write("(B) " + $"{actualB:N2}");
|
||||
writer.RenderEndTag();//end actual sales A (total profit return)
|
||||
writer.RenderEndTag();//end totals row
|
||||
//end totals row
|
||||
writer.RenderEndTag();//table
|
||||
writer.RenderEndTag();//body
|
||||
writer.RenderEndTag();//HTML
|
||||
|
||||
// switch (i)
|
||||
// {
|
||||
// case 3:
|
||||
// projectionProfitReturn += double.Parse(row.ItemArray[3].ToString());
|
||||
// break;
|
||||
// case 6:
|
||||
// projectionTotalProfitReturn += double.Parse(row.ItemArray[6].ToString());
|
||||
// break;
|
||||
// case 13:
|
||||
// actualProfitReturn += double.Parse(row.ItemArray[13].ToString());
|
||||
// break;
|
||||
// case 16:
|
||||
// actualTotalProfitReturn += double.Parse(row.ItemArray[16].ToString());
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// writer.Write(row.ItemArray[i]);
|
||||
// }
|
||||
// writer.RenderEndTag(); //td
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// //Padding
|
||||
// writer.RenderBeginTag(HtmlTextWriterTag.Tr);
|
||||
// //Generate padding rows to fit the Profit Analysis cells properly onto the sheet.
|
||||
// //Check to see if the row index is equal to the number of rows in the table.
|
||||
// if (rowIndex == table.Rows.Count)
|
||||
// {
|
||||
// //IF so, then that means the current row index represents the index of the Totals row. So build the totals row with the added values from above.
|
||||
// //Begin rendering the totals row.
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Style, "border:1px solid black; border-left:none");
|
||||
// writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
// writer.RenderEndTag();
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Style, "background-color:#e9e9e9; text-align:right");
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "2");
|
||||
// writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
// writer.Write("Total");
|
||||
// writer.RenderEndTag(); //td
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Style, "background-color:#e9e9e9; padding: 0px 0px 0px 5px");
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "2");
|
||||
// writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
// writer.Write("(A) " + $"{projectionProfitReturn:C}");
|
||||
// writer.RenderEndTag();
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Style, "background-color:#e9e9e9; padding: 0px 0px 0px 5px");
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "2");
|
||||
// writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
// writer.Write("(B) " + $"{projectionTotalProfitReturn:C}");
|
||||
// writer.RenderEndTag();
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Style, "text-align:right");
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "5");
|
||||
// writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
// writer.Write("Total");
|
||||
// writer.RenderEndTag();
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Style, "padding: 0px 0px 0px 5px");
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "2");
|
||||
// writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
// writer.Write("(A) " + $"{actualProfitReturn:C}");
|
||||
// writer.RenderEndTag();
|
||||
// writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
// writer.RenderEndTag();
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Style, "padding: 0px 0px 0px 5px");
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "2");
|
||||
// writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
// writer.Write("(B) " + $"{actualTotalProfitReturn:C}");
|
||||
// writer.RenderEndTag();//td
|
||||
// //END rending the totals row.
|
||||
// BuildProfitAnalysisCell(ref writer, rowIndex + adSpecialOffset, out isProfitAnalysisCell, salesProducedByAdItems, remainingSales, totalProfitReturnFromAdItems, totalProfitReturnFromRemainingSales, totalProfitReturn);
|
||||
// }
|
||||
// else if (rowIndex == (table.Rows.Count + 1))
|
||||
// //Check to see if the current index is equal to the row after the totals row and, if so, create the comments row.
|
||||
// {
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "17");
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Style, "border-left:none");
|
||||
// writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
// writer.Write(
|
||||
// "<b>Comments:</b> " + comments);
|
||||
// writer.RenderEndTag(); //td
|
||||
// BuildProfitAnalysisCell(ref writer, rowIndex + adSpecialOffset, out isProfitAnalysisCell, salesProducedByAdItems, remainingSales, totalProfitReturnFromAdItems, totalProfitReturnFromRemainingSales, totalProfitReturn);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// var cellCount = 0;
|
||||
// while (cellCount < 17)
|
||||
// {
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Style, "border:none");
|
||||
// writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
// writer.RenderEndTag();//td
|
||||
// cellCount++;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//Check for every 3rd row to append a Profit Analysis cell onto.
|
||||
// switch (rowIndex + adSpecialOffset)
|
||||
// {
|
||||
// case 0:
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Rowspan, "2");
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Style, "border:none; border-right:none");
|
||||
// writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
// writer.Write("<center style=\"margin-top:1px\">Sales Produced By<br>Ad Items (A)</center><p><span style=\"font-size:9px; vertical-align:bottom\">2</span><span style=\"margin-left:60px\">" + $"{salesProducedByAdItems:C}" + "</span></p>");
|
||||
// writer.RenderEndTag();
|
||||
// break;
|
||||
// case 3:
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Rowspan, "2");
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Style, "border:none; border-top:1px solid black; border-right:none");
|
||||
// writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
// writer.Write("<center style=\"margin-top:1px\">Remaining<br>Sales</center><p><span style=\"font-size:9px; vertical-align:bottom\">3</span><span style=\"margin-left:60px\">" + $"{remainingSales:C}" + " </span></p>");
|
||||
// writer.RenderEndTag();
|
||||
// break;
|
||||
// case 6:
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Rowspan, "2");
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Style, "border:none; border-top:1px solid black; border-right:none");
|
||||
// writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
// writer.Write("<center style=\"margin-top:1px;\">Total $ Profit Return<br>From Ad Items (B)</center><p><span style=\"font-size:9px; vertical-align:bottom\">4</span><span style=\"margin-left:60px\">" + $"{totalProfitReturnFromAdItems:C}" + " </span></p>");
|
||||
// writer.RenderEndTag();
|
||||
// break;
|
||||
// case 9:
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Rowspan, "2");
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Style, "border:none; border-top:1px solid black; border-right:none");
|
||||
// writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
// writer.Write("<center style=\"margin-top:2px\">Total $ Profit Return<br>From Remaining Sales</center><p><span style=\"font-size:9px; vertical-align:bottom\">5</span><span style=\"margin-left:60px\">" + $"{totalProfitReturnFromRemainingSales:C}" + "</span></p>");
|
||||
// writer.RenderEndTag();
|
||||
// break;
|
||||
// case 12:
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Rowspan, "2");
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Style, "border-right:none");
|
||||
// writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
// writer.Write("<center style=\"margin-top:1px\">Total $ Profit<br>Return</center><p><span style=\"font-size:9px; vertical-align:bottom\">6</span><span style=\"margin-left:60px\">" + $"{totalProfitReturn:C}" + "</span></p>");
|
||||
// writer.RenderEndTag();
|
||||
// break;
|
||||
// case 15:
|
||||
// //IF either the compressed format or the generate comment row flags are set, then ignore this case. Only tables with 19 or more rows can generate a full comments cell due to the amount of text it can contain.
|
||||
// if (isCompressedFormat || willGenerateCommentRow) break;
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Rowspan, "4");
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Style, "border-right:none");
|
||||
// writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
// writer.Write("Comments: " + comments);
|
||||
// writer.RenderEndTag();
|
||||
// break;
|
||||
// }
|
||||
|
||||
// writer.RenderEndTag();//tr
|
||||
//}//end for loop
|
||||
|
||||
//if (!willGenerateCommentRow && !isCompressedFormat)
|
||||
//{
|
||||
// //Begin rendering the totals row.
|
||||
// writer.RenderBeginTag(HtmlTextWriterTag.Tr);
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Style, "border:1px solid black; border-left:none");
|
||||
// writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
// writer.RenderEndTag();
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Style, "background-color:#e9e9e9; border:1px solid black; font-size:12px; border-left: 1px solid #000; text-align:right");
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "2");
|
||||
// writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
// writer.Write("Total");
|
||||
// writer.RenderEndTag(); //td
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Style, "background-color:#e9e9e9; border:1px solid black; font-size:12px; border-left: 1px solid #000; padding: 0px 0px 0px 5px");
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "2");
|
||||
// writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
// writer.Write("(A) " + $"{projectionProfitReturn:C}");
|
||||
// writer.RenderEndTag();
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Style, "background-color:#e9e9e9; border:1px solid black; font-size:12px; border-left: 1px solid #000; padding: 0px 0px 0px 5px");
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "2");
|
||||
// writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
// writer.Write("(B) " + $"{projectionTotalProfitReturn:C}");
|
||||
// writer.RenderEndTag();
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Style, "border:1px solid black; font-size:12px; border-left: 1px solid #000; text-align:right");
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "5");
|
||||
// writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
// writer.Write("Total");
|
||||
// writer.RenderEndTag();
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Style, "border:1px solid black; font-size:12px; border-left: 1px solid #000; padding: 0px 0px 0px 5px");
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "2");
|
||||
// writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
// writer.Write("(A) " + $"{actualProfitReturn:C}");
|
||||
// writer.RenderEndTag();
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Style, "border:1px solid black");
|
||||
// writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
// writer.RenderEndTag();
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Style, "border:1px solid black; font-size:12px; border-left: 1px solid #000; padding: 0px 0px 0px 5px");
|
||||
// writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "2");
|
||||
// writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
// writer.Write("(B) " + $"{actualTotalProfitReturn:C}");
|
||||
// writer.RenderEndTag();//td
|
||||
// writer.RenderEndTag(); //tr
|
||||
//}
|
||||
//writer.RenderEndTag();//table
|
||||
//writer.RenderEndTag();//body
|
||||
//writer.RenderEndTag();//HTML
|
||||
|
||||
//using (var streamWriter = new StreamWriter(Application.StartupPath + "\\FrontPage.html"))
|
||||
//{
|
||||
// streamWriter.WriteLine(stringWriter.ToString());
|
||||
//}
|
||||
//RenderHtmlToImage();
|
||||
using (var streamWriter = new StreamWriter("C:\\Users\\Crypto\\Desktop\\TestPage.html"))
|
||||
{
|
||||
streamWriter.WriteLine(stringWriter.ToString());
|
||||
}
|
||||
RenderHtmlToImage();
|
||||
}
|
||||
|
||||
private void BuildProfitAnalysisCell(ref HtmlTextWriter writer, int rowIndex, out bool isProfitAnalysisCell, double salesProducedByAdItems, double remainingSales, double totalProfitReturnFromAdItems, double totalProfitReturnFromRemainingSales, double totalProfitReturn)
|
||||
private void RenderCostsAnalysisCell(CostAnalysisCells cell, ref HtmlTextWriter writer, decimal? value, string rowSpan)
|
||||
{
|
||||
var number = string.Empty;
|
||||
var labelText = string.Empty;
|
||||
|
||||
switch (cell)
|
||||
{
|
||||
case CostAnalysisCells.DepartmentSales:
|
||||
number = "1";
|
||||
labelText = "Department<br>Sales";
|
||||
break;
|
||||
case CostAnalysisCells.SalesProduced:
|
||||
number = "2";
|
||||
labelText = "Sales Produced<br>by<br>Ad Items (A)";
|
||||
break;
|
||||
case CostAnalysisCells.RemainingSales:
|
||||
number = "3";
|
||||
labelText = "Remaining<br>Sales<br>(Line 1 minus<br>Line 2)";
|
||||
break;
|
||||
case CostAnalysisCells.ProfitReturnFromAdItems:
|
||||
number = "4";
|
||||
labelText = "Total $ Profit<br>Return From Ad<br>Items (B)";
|
||||
break;
|
||||
case CostAnalysisCells.ProfitReturnFromRemainingSales:
|
||||
number = "5";
|
||||
labelText = "Total $ Profit Return<br>From Remaining Sales<br><br>Going-in Gross % x Remaining Sales";
|
||||
break;
|
||||
case CostAnalysisCells.TotalProfitReturn:
|
||||
number = "6";
|
||||
labelText = "Total $ Profit<br>Return<br><br>Line 4 Plus Line 5";
|
||||
break;
|
||||
case CostAnalysisCells.CrossProfitInfoCell:
|
||||
break;
|
||||
case CostAnalysisCells.Comments:
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(cell), cell, null);
|
||||
}
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Rowspan, rowSpan);
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "border-right:none; border-left:double; font-size:14px; width:25px");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);//begin number cell
|
||||
writer.Write(number);
|
||||
writer.RenderEndTag();//end number cell
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Rowspan, rowSpan);
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "border-right:none; border-left:none; width:200px");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);//begin department sales cell
|
||||
writer.Write(labelText);
|
||||
writer.RenderEndTag();//end department sales cell
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Rowspan, rowSpan);
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "border-right:none; border-left:none; width:75px");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);//department sales total sales column
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "margin:0px; border-left:1px solid black; border-top:1px dashed black; text-align:right");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.P);//begin department sales paragraph tag; used because the borders of the element are flush with that of the cell's.
|
||||
writer.Write($"{value:C}");
|
||||
writer.RenderEndTag();//end department sales paragraph tag
|
||||
writer.RenderEndTag();//department sales total sales column
|
||||
}
|
||||
|
||||
private void RenderCostsAnalysisCell(CostAnalysisCells cell, ref HtmlTextWriter writer, string value = "")
|
||||
{
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "3");
|
||||
switch (cell)
|
||||
{
|
||||
case CostAnalysisCells.CrossProfitInfoCell:
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Rowspan, "3");
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "border-right:none; text-align:left");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
writer.Write("To Find Gross Profit % Divide<br>Total Profit Return By Dept.<br>Weekly Retail Sales");
|
||||
break;
|
||||
case CostAnalysisCells.Comments:
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Rowspan, "5");
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "border-right:none; text-align:left; vertical-align:top");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
writer.Write("Comments: " + value);
|
||||
break;
|
||||
}
|
||||
writer.RenderEndTag();
|
||||
}
|
||||
|
||||
private void SelectCostAnalysisCell(int rowIndex, ref HtmlTextWriter writer, decimal? actualA, decimal? actualB, WeeklySale departmentRecord, Note comments)
|
||||
{
|
||||
isProfitAnalysisCell = false;
|
||||
switch (rowIndex)
|
||||
{
|
||||
case 0:
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Rowspan, "2");
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "border:none; border-right:1px solid black; border-right:none");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
writer.Write("<center style=\"margin-top:1px\">Sales Produced By<br>Ad Items (A)</center><p><span style=\"font-size:9px; vertical-align:bottom\">2</span><span style=\"margin-left:60px\">" + $"{salesProducedByAdItems:C}" + "</span></p>");
|
||||
writer.RenderEndTag();
|
||||
RenderCostsAnalysisCell(CostAnalysisCells.SalesProduced, ref writer, actualA, "3");
|
||||
break;
|
||||
case 3:
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Rowspan, "2");
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "border:none; border-right:1px solid black; border-top:1px solid black; border-right:none");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
writer.Write("<center style=\"margin-top:1px\">Remaining<br>Sales</center><p><span style=\"font-size:9px; vertical-align:bottom\">3</span><span style=\"margin-left:60px\">" + $"{remainingSales:C}" + " </span></p>");
|
||||
writer.RenderEndTag();
|
||||
if (departmentRecord != null)
|
||||
RenderCostsAnalysisCell(CostAnalysisCells.RemainingSales, ref writer, departmentRecord.TotalSales - actualA, "4");
|
||||
break;
|
||||
case 6:
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Rowspan, "2");
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "border:none; border-right:1px solid black; border-top:1px solid black; border-right:none");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
writer.Write("<center style=\"margin-top:1px;\">Total $ Profit Return<br>From Ad Items (B)</center><p><span style=\"font-size:9px; vertical-align:bottom\">4</span><span style=\"margin-left:60px\">" + $"{totalProfitReturnFromAdItems:C}" + " </span></p>");
|
||||
writer.RenderEndTag();
|
||||
case 7:
|
||||
RenderCostsAnalysisCell(CostAnalysisCells.ProfitReturnFromAdItems, ref writer, actualB, "3");
|
||||
break;
|
||||
case 9:
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Rowspan, "2");
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "border:none; border-right:1px solid black; border-top:1px solid black; border-right:none");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
writer.Write("<center style=\"margin-top:2px\">Total $ Profit Return<br>From Remaining Sales</center><p><span style=\"font-size:9px; vertical-align:bottom\">5</span><span style=\"margin-left:60px\">" + $"{totalProfitReturnFromRemainingSales:C}" + "</span></p>");
|
||||
writer.RenderEndTag();
|
||||
case 10:
|
||||
//get cross profit return
|
||||
var s = (decimal) 0.3;
|
||||
RenderCostsAnalysisCell(CostAnalysisCells.ProfitReturnFromRemainingSales, ref writer, s * (departmentRecord.TotalSales - actualA), "5");
|
||||
break;
|
||||
case 12:
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Rowspan, "2");
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "border-right:none");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
writer.Write("<center style=\"margin-top:1px\">Total $ Profit<br>Return</center><p><span style=\"font-size:9px; vertical-align:bottom\">6</span><span style=\"margin-left:60px\">" + $"{totalProfitReturn:C}" + "</span></p>");
|
||||
writer.RenderEndTag();
|
||||
case 15:
|
||||
var x = (decimal) 0.3 * (departmentRecord.TotalSales - actualA);
|
||||
RenderCostsAnalysisCell(CostAnalysisCells.TotalProfitReturn, ref writer, x + actualB, "4");
|
||||
break;
|
||||
case 19:
|
||||
RenderCostsAnalysisCell(CostAnalysisCells.CrossProfitInfoCell, ref writer);
|
||||
break;
|
||||
case 22:
|
||||
RenderCostsAnalysisCell(CostAnalysisCells.Comments, ref writer, comments.Remark);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void AppendPaddingRow(ref HtmlTextWriter writer)
|
||||
{
|
||||
var cellCount = 0;
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
|
||||
while (cellCount < 17)
|
||||
{
|
||||
switch (cellCount)
|
||||
{
|
||||
case 0:
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "border-left:none; border-right:double");
|
||||
break;
|
||||
case 6:
|
||||
case 16:
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Style, "border-right:double");
|
||||
break;
|
||||
}
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
writer.Write("<br>");
|
||||
writer.RenderEndTag();
|
||||
cellCount++;
|
||||
}
|
||||
}
|
||||
|
||||
private enum CostAnalysisCells
|
||||
{
|
||||
DepartmentSales = 0,
|
||||
SalesProduced = 1,
|
||||
RemainingSales = 2,
|
||||
ProfitReturnFromAdItems = 3,
|
||||
ProfitReturnFromRemainingSales = 4,
|
||||
TotalProfitReturn = 5,
|
||||
CrossProfitInfoCell = 6,
|
||||
Comments = 7
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user