using System.Collections.Generic;
using System.Drawing.Printing;
using TicketManager.Controllers;
namespace TicketManager.Models
public class clsPrintNatCompRpt : PrintDocument
private const float mcfLineHt = .18f;
List<slsGrpComp> categoriesList = new List<slsGrpComp>();
public void PrintRpt(string xsFile)
PrinterSettings.PrintToFile = true;
PrinterSettings.PrintFileName = xsFile;
PrinterSettings.PrinterName = "Microsoft XPS Document Writer";
protected override void OnPrintPage(PrintPageEventArgs e)
RectangleF poPrintArea = new RectangleF();
e.Graphics.PageUnit = GraphicsUnit.Inch;
e.PageSettings.Margins.Right = 0;
e.PageSettings.Margins.Left = (int)(mfMargin * 100);
e.PageSettings.Margins.Top = 0;
e.PageSettings.Margins.Bottom = 0;
poFormat = new StringFormat(StringFormatFlags.NoWrap);
poPrintArea = new RectangleF(0, 0, e.PageSettings.PaperSize.Width / 100f, e.PageSettings.PaperSize.Height / 100f);
moFont = new Font("Arial", 10);
Header_Print(ref poPrintArea, e);
Title_Print(ref poPrintArea, e);
clsSlsGrpHisRaw poDay = ConnToDB();
List<dbSlsGrpHisRaw> shopData = poDay.LoadByShop();
clsGrpComp categories = AssignToCategory();
DateDebug(ref poPrintArea, e);
foreach (var category in categories)
Subtitle_Print(ref poPrintArea, e, category.GrpID, category.GrpName);
PrintRow(ref poPrintArea, e, category);
Footer_Print(ref poPrintArea, e);
private void PrintCentered(string xsText, Font xoFont, RectangleF xoArea, PrintPageEventArgs e)
xoArea.X = xoArea.Width / 2f - e.Graphics.MeasureString(xsText, moFont).Width / 2f;
e.Graphics.DrawString(xsText, xoFont, Brushes.Black, xoArea);
private void PrintRightAlign(string val, RectangleF xoPrint, PrintPageEventArgs e)
width = e.Graphics.MeasureString(val, moFont).Width;
e.Graphics.DrawString(val, moFont, Brushes.Black, xoPrint.X - width, xoPrint.Y);
private void Header_Print(ref RectangleF xoPrintArea, PrintPageEventArgs e)
xoPrintArea.Y += mcfLineHt * 2;
moFont = new Font("Arial", 48f, FontStyle.Bold);
PrintCentered("NATIONAL SCORECARD", moFont, xoPrintArea, e);
xoPrintArea.Y += mcfLineHt * 4;
moFont = new Font("Arial", 24f, FontStyle.Bold);
PrintCentered("HOW DO YOU MEASURE UP?", moFont, xoPrintArea, e);
xoPrintArea.Y += mcfLineHt * 6;
private void Title_Print(ref RectangleF xoPrintArea, PrintPageEventArgs e)
moFont = new Font("Arial", 16f, FontStyle.Bold);
xoPrintArea.X = mfMargin;
e.Graphics.DrawString("WEEKLY", moFont, Brushes.Black, xoPrintArea);
PrintRightAlign("TICKETS", xoPrintArea, e);
PrintRightAlign("SALES/TICKET", xoPrintArea, e);
e.Graphics.DrawString("PROFIT/TICKET", moFont, Brushes.Black, xoPrintArea);
xoPrintArea.Y += mcfLineHt * 1.25f;
moFont = new Font("Arial", 12f, FontStyle.Bold);
xoPrintArea.X = mfMargin;
e.Graphics.DrawString("AVERAGE", moFont, Brushes.Black, xoPrintArea);
PrintRightAlign("SHOP - NAT'L", xoPrintArea, e);
PrintRightAlign("SHOP - NAT'L", xoPrintArea, e);
e.Graphics.DrawString("SHOP - NAT'L", moFont, Brushes.Black, xoPrintArea);
xoPrintArea.Y += mcfLineHt * 2;
private void Subtitle_Print(ref RectangleF xoPrintArea, PrintPageEventArgs e, int id, string categoryName)
moFont = new Font("Arial", 12f, FontStyle.Bold);
xoPrintArea.X = mfMargin;
e.Graphics.DrawString(id.ToString(), moFont, Brushes.Black, xoPrintArea);
xoPrintArea.X = mfMargin + .25f;
e.Graphics.DrawString(categoryName, moFont, Brushes.Black, xoPrintArea);
xoPrintArea.X = mfMargin + 4.5f;
e.Graphics.DrawString("$", moFont, Brushes.Black, xoPrintArea);
xoPrintArea.X = mfMargin + 6.8f;
e.Graphics.DrawString("%", moFont, Brushes.Black, xoPrintArea);
xoPrintArea.Y += mcfLineHt * 1.25f;
private clsSlsGrpHisRaw ConnToDB()
clsSlsGrpHisRaw poDay = new clsSlsGrpHisRaw();
poDay.RemoteConn_Initialize("localhost\\bmsqlserver", "BMSalesCompNONAL", "sa", "AcrSql@1800");
poDay.ShopID = "7b26aaff-39b9-4b79-9d1b-0b3367c681f6";
private List<dbSlsGrpHisRaw> GetShpData()
clsSlsGrpHisRaw poDay = ConnToDB();
List<dbSlsGrpHisRaw> shopData = poDay.LoadByShop();
public int CalcWeeksPassed(dbSlsGrpRaw data)
string year = data.AcctPerMo.Substring(0, 4);
string month = data.AcctPerMo.Substring(4, 2);
var currentDate = DateTime.Now;
var prevDate = new DateTime(Int32.Parse(year), Int32.Parse(month), 01);
var weeks = Math.Floor((currentDate - prevDate).TotalDays / 7);
public void AssignDataToWeek(int weeks, slsGrpComp category, dbSlsGrpRaw data)
if (weeks <= 52 && weeks >= 0)
category.Week52TktShop += data.Pcnt;
category.Week52TktNat += data.Lcnt;
if (weeks <= 12 && weeks >= 0)
category.Week12TktShop += data.Pcnt;
category.Week12TktNat += data.Lcnt;
if (weeks <= 4 && weeks >= 0)
category.Week4TktShop += data.Pcnt;
category.Week4TktNat += data.Lcnt;
category.Week1TktShop += data.Pcnt;
category.Week1TktNat += (int)data.Lcnt;
category.Week1TktSalesShop += (int)data.Pcst;
category.Week1TktSalesNat += (int)data.Psls;
private clsGrpComp AssignToCategory(List<dbSlsGrpRaw> shopData)
clsGrpComp categories = new clsGrpComp();
foreach (var data in shopData)
weeks = CalcWeeksPassed(data);
if (!categories.Contains(data.SlsGrpID))
temp.GrpID = data.SlsGrpID;
temp.GrpName = data.SlsNam;
AssignDataToWeek(weeks, temp, data);
foreach (var category in categories)
if (category.GrpID == data.SlsGrpID))
AssignDataToWeek(weeks, category, data);
public void PrintCategoryTitle(ref RectangleF xoPrintArea, PrintPageEventArgs e, slsGrpComp category)
moFont = new Font("Arial", 12f, FontStyle.Bold);
xoPrintArea.X = mfMargin;
e.Graphics.DrawString(category.GrpID.ToString(), moFont, Brushes.Black, xoPrintArea);
xoPrintArea.X = mfMargin + .25f;
e.Graphics.DrawString(category.GrpName, moFont, Brushes.Black, xoPrintArea);
public void PrintWeek1(ref RectangleF xoPrintArea, PrintPageEventArgs e, slsGrpComp category)
moFont = new Font("Arial", 12f, FontStyle.Bold);
xoPrintArea.X = mfMargin;
e.Graphics.DrawString("1 week", moFont, Brushes.Black, xoPrintArea);
e.Graphics.DrawString(category.Week1TktShop.ToString(), moFont, Brushes.Black, xoPrintArea);
e.Graphics.DrawString(" - ", moFont, Brushes.Black, xoPrintArea);
e.Graphics.DrawString(category.Week1TktNat.ToString(), moFont, Brushes.Black, xoPrintArea);
e.Graphics.DrawString(category.Week1TktSalesShop.ToString(), moFont, Brushes.Black, xoPrintArea);
e.Graphics.DrawString(category.Week1TktSalesNat.ToString(), moFont, Brushes.Black, xoPrintArea);
xoPrintArea.Y += mcfLineHt * 2f;
public void PrintWeek4(ref RectangleF xoPrintArea, PrintPageEventArgs e, slsGrpComp category)
moFont = new Font("Arial", 12f, FontStyle.Bold);
xoPrintArea.X = mfMargin;
e.Graphics.DrawString("4 week", moFont, Brushes.Black, xoPrintArea);
e.Graphics.DrawString(category.Week4TktShop.ToString(), moFont, Brushes.Black, xoPrintArea);
e.Graphics.DrawString(" - ", moFont, Brushes.Black, xoPrintArea);
e.Graphics.DrawString(category.Week4TktNat.ToString(), moFont, Brushes.Black, xoPrintArea);
e.Graphics.DrawString(category.Week4TktSalesShop.ToString(), moFont, Brushes.Black, xoPrintArea);
e.Graphics.DrawString(category.Week4TktSalesNat.ToString(), moFont, Brushes.Black, xoPrintArea);
xoPrintArea.Y += mcfLineHt * 2f;
public void PrintWeek12(ref RectangleF xoPrintArea, PrintPageEventArgs e, slsGrpComp category)
moFont = new Font("Arial", 12f, FontStyle.Bold);
xoPrintArea.X = mfMargin;
e.Graphics.DrawString("12 week", moFont, Brushes.Black, xoPrintArea);
e.Graphics.DrawString(category.Week12TktShop.ToString(), moFont, Brushes.Black, xoPrintArea);
e.Graphics.DrawString(" - ", moFont, Brushes.Black, xoPrintArea);
e.Graphics.DrawString(category.Week12TktNat.ToString(), moFont, Brushes.Black, xoPrintArea);
e.Graphics.DrawString(category.Week12TktSalesShop.ToString(), moFont, Brushes.Black, xoPrintArea);
e.Graphics.DrawString(category.Week12TktSalesNat.ToString(), moFont, Brushes.Black, xoPrintArea);
xoPrintArea.Y += mcfLineHt * 2f;
public void PrintWeek52(ref RectangleF xoPrintArea, PrintPageEventArgs e, slsGrpComp category)
moFont = new Font("Arial", 12f, FontStyle.Bold);
xoPrintArea.X = mfMargin;
e.Graphics.DrawString("52 week", moFont, Brushes.Black, xoPrintArea);
e.Graphics.DrawString(category.Week1TktShop.ToString(), moFont, Brushes.Black, xoPrintArea);
e.Graphics.DrawString(" - ", moFont, Brushes.Black, xoPrintArea);
e.Graphics.DrawString(category.Week52TktNat.ToString(), moFont, Brushes.Black, xoPrintArea);
e.Graphics.DrawString(category.Week52TktSalesShop.ToString(), moFont, Brushes.Black, xoPrintArea);
e.Graphics.DrawString(category.Week52TktSalesNat.ToString(), moFont, Brushes.Black, xoPrintArea);
xoPrintArea.Y += mcfLineHt * 2f;
public void PrintAllWeeks(ref RectangleF xoPrintArea, PrintPageEventArgs e, slsGrpComp category)
PrintWeek1(ref xoPrintArea, e, category);
PrintWeek4(ref xoPrintArea, e, category);
PrintWeek12(ref xoPrintArea, e, category);
PrintWeek52(ref xoPrintArea, e, category);
public void PrintRow(ref RectangleF xoPrintArea, PrintPageEventArgs e, slsGrpComp category)
moFont = new Font("Arial", 12f, FontStyle.Bold);
xoPrintArea.X = mfMargin;
e.Graphics.DrawString("1 week", moFont, Brushes.Black, xoPrintArea);
e.Graphics.DrawString(category.Week1TktShop.ToString(), moFont, Brushes.Black, xoPrintArea);
e.Graphics.DrawString(" - ", moFont, Brushes.Black, xoPrintArea);
e.Graphics.DrawString(category.Week1TktNat.ToString(), moFont, Brushes.Black, xoPrintArea);
e.Graphics.DrawString(category.Week1TktSalesShop.ToString(), moFont, Brushes.Black, xoPrintArea);
e.Graphics.DrawString(category.Week1TktSalesNat.ToString(), moFont, Brushes.Black, xoPrintArea);
xoPrintArea.Y += mcfLineHt * 2f;
private void Footer_Print(ref RectangleF xoPrintArea, PrintPageEventArgs e)
xoPrintArea.Y += mcfLineHt;
xoPrintArea.Y += mcfLineHt;
moFont = new Font("Arial", 20f, FontStyle.Regular);
xoPrintArea.X = mfMargin * 1.5f;
PrintCentered("How does your performance match up to the rest of the country?", moFont, xoPrintArea, e);
xoPrintArea.Y += mcfLineHt * 1.5f;
PrintCentered("Which sales group accounts were most of your volume?", moFont, xoPrintArea, e);
xoPrintArea.Y += mcfLineHt * 1.5f;
PrintCentered("How much do you sell services for against the national average?", moFont, xoPrintArea, e);
xoPrintArea.Y += mcfLineHt * 1.5f;
PrintCentered("Do you make the same margins as your competitor?", moFont, xoPrintArea, e);
xoPrintArea.Y += mcfLineHt;
xoPrintArea.Y += mcfLineHt;
PrintCentered("Now you know what areas that you need to improve.", moFont, xoPrintArea, e);
public int GrpID { get; set; }
public string GrpName { get; set; }
public int Week1TktShop { get; set; }
public int Week1TktNat { get; set; }
public int Week1TktSalesShop { get; set; }
public int Week1TktSalesNat { get; set; }
public int Week1TktPrftShop { get; set; }
public int Week1TktPrftNat { get; set; }
public int Week4TktShop { get; set; }
public int Week4TktNat { get; set; }
public int Week4TktSalesShop { get; set; }
public int Week4TktSalesNat { get; set; }
public int Week4TktPrftShop { get; set; }
public int Week4TktPrftNat { get; set; }
public int Week12TktShop { get; set; }
public int Week12TktNat { get; set; }
public int Week12TktSalesShop { get; set; }
public int Week12TktSalesNat { get; set; }
public int Week12TktPrftShop { get; set; }
public int Week12TktPrftNat { get; set; }
public int Week52TktShop { get; set; }
public int Week52TktNat { get; set; }
public int Week52TktSalesShop { get; set; }
public int Week52TktSalesNat { get; set; }
public int Week52TktPrftShop { get; set; }
public int Week52TktPrftNat { get; set; }
public class clsGrpComp : System.Collections.ObjectModel.KeyedCollection<int, slsGrpComp>
protected override int GetKeyForItem(slsGrpComp item)