Skip to content

Commit

Permalink
- reports: refactor 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav committed Jan 25, 2016
1 parent 064f887 commit e764fe9
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public abstract class BaseDetailedReport<T> : BaseReport
protected ICellStyle sumCellStyle;
protected ICellStyle countCellStyle;

protected override int ColumnCount { get { return 5; } }

protected BaseDetailedReport(AdditionalServicesRatingReportSettings settings)
{
ServiceLocator.Current.GetInstance<UnityContainer>()
Expand Down
25 changes: 24 additions & 1 deletion sources/Reports/BaseReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public abstract class BaseReport : IQueueReport
{
protected StandardCellStyles styles;

protected abstract int ColumnCount { get; }

#region dependency

[Dependency]
Expand All @@ -28,7 +30,28 @@ public HSSFWorkbook Generate()
{
var wk = InternalGenerate();
var sheet = wk.GetSheetAt(0);
wk.SetPrintArea(0, 0, sheet.GetRow(1).LastCellNum, 0, sheet.LastRowNum);

wk.SetPrintArea(0, 0, ColumnCount, 0, sheet.LastRowNum);

for (var i = 0; i < sheet.LastRowNum; i++)
{
var row = sheet.GetRow(i);

for (int j = row.FirstCellNum; j < ColumnCount; j++)
{
var cell = row.GetCell(j);

if (cell == null)
{
continue;
}

cell.CellStyle.BorderLeft = BorderStyle.Thin;
cell.CellStyle.BorderRight = BorderStyle.Thin;
cell.CellStyle.BorderTop = BorderStyle.Thin;
cell.CellStyle.BorderBottom = BorderStyle.Thin;
}
}

return wk;
}
Expand Down
2 changes: 2 additions & 0 deletions sources/Reports/ClientRequestReport/ClientRequestReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class ClientRequestReport : BaseReport
{
private readonly Guid clientRequestId;

protected override int ColumnCount { get { return 2; } }

public ClientRequestReport(Guid clientRequestId)
: base()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class ExceptionScheduleReport : BaseReport
{
private readonly DateTime fromDate;

protected override int ColumnCount { get { return 7; } }

public ExceptionScheduleReport(DateTime fromDate)
{
this.fromDate = fromDate;
Expand Down
2 changes: 2 additions & 0 deletions sources/Reports/OperatorRatingReport/BaseDetailedReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public abstract class BaseDetailedReport<T> : BaseReport

private Lazy<Operator[]> allOperators;

protected override int ColumnCount { get { return 20; } }

public BaseDetailedReport(OperatorRatingReportSettings settings)
: base()
{
Expand Down
41 changes: 21 additions & 20 deletions sources/Reports/ServiceRatingReport/BaseDetailedReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using NHibernate.Type;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using NPOI.SS.Util;
using Queue.Model;
using Queue.Model.Common;
using System;
Expand All @@ -20,6 +21,8 @@ public abstract class BaseDetailedReport<T> : BaseReport
{
protected ServiceRatingReportSettings settings;

protected override int ColumnCount { get { return 19; } }

public BaseDetailedReport(ServiceRatingReportSettings settings)
: base()
{
Expand Down Expand Up @@ -190,23 +193,21 @@ protected ServiceGroupDto GetServicesHierarchy()

protected void RenderRating(IRow row, ServiceRating rating)
{
WriteCell(row, 5, c => c.SetCellValue(rating.Total), styles[StandardCellStyles.BorderedStyle]);
WriteCell(row, 6, c => c.SetCellValue(rating.Live), styles[StandardCellStyles.BorderedStyle]);
WriteCell(row, 7, c => c.SetCellValue(rating.Early), styles[StandardCellStyles.BorderedStyle]);
WriteCell(row, 8, c => c.SetCellValue(rating.Waiting), styles[StandardCellStyles.BorderedStyle]);
WriteCell(row, 9, c => c.SetCellValue(rating.Absence), styles[StandardCellStyles.BorderedStyle]);
WriteCell(row, 10, c => c.SetCellValue(rating.Rendered), styles[StandardCellStyles.BorderedStyle]);
WriteCell(row, 11, c => c.SetCellValue(rating.Canceled), styles[StandardCellStyles.BorderedStyle]);
WriteCell(row, 12, c => c.SetCellValue(rating.Rendered != 0 ? Math.Round(rating.RenderTime.TotalMinutes / rating.Rendered) : 0),
styles[StandardCellStyles.BorderedStyle]);
WriteCell(row, 13, c => c.SetCellValue(rating.Rendered != 0 ? Math.Round(rating.WaitingTime.TotalMinutes / rating.Rendered) : 0),
styles[StandardCellStyles.BorderedStyle]);
WriteCell(row, 14, c => c.SetCellValue(rating.SubjectsTotal), styles[StandardCellStyles.BorderedStyle]);
WriteCell(row, 15, c => c.SetCellValue(rating.SubjectsLive), styles[StandardCellStyles.BorderedStyle]);
WriteCell(row, 16, c => c.SetCellValue(rating.SubjectsEarly), styles[StandardCellStyles.BorderedStyle]);
WriteCell(row, 17, c => c.SetCellValue(rating.RatingMin), styles[StandardCellStyles.BorderedStyle]);
WriteCell(row, 18, c => c.SetCellValue(rating.RatingMax), styles[StandardCellStyles.BorderedStyle]);
WriteCell(row, 19, c => c.SetCellValue(Math.Round(rating.RatingAvg * 100) / 100), styles[StandardCellStyles.BorderedStyle]);
WriteCell(row, 5, c => c.SetCellValue(rating.Total));
WriteCell(row, 6, c => c.SetCellValue(rating.Live));
WriteCell(row, 7, c => c.SetCellValue(rating.Early));
WriteCell(row, 8, c => c.SetCellValue(rating.Waiting));
WriteCell(row, 9, c => c.SetCellValue(rating.Absence));
WriteCell(row, 10, c => c.SetCellValue(rating.Rendered));
WriteCell(row, 11, c => c.SetCellValue(rating.Canceled));
WriteCell(row, 12, c => c.SetCellValue(rating.Rendered != 0 ? Math.Round(rating.RenderTime.TotalMinutes / rating.Rendered) : 0));
WriteCell(row, 13, c => c.SetCellValue(rating.Rendered != 0 ? Math.Round(rating.WaitingTime.TotalMinutes / rating.Rendered) : 0));
WriteCell(row, 14, c => c.SetCellValue(rating.SubjectsTotal));
WriteCell(row, 15, c => c.SetCellValue(rating.SubjectsLive));
WriteCell(row, 16, c => c.SetCellValue(rating.SubjectsEarly));
WriteCell(row, 17, c => c.SetCellValue(rating.RatingMin));
WriteCell(row, 18, c => c.SetCellValue(rating.RatingMax));
WriteCell(row, 19, c => c.SetCellValue(Math.Round(rating.RatingAvg * 100) / 100));
}

protected void WriteServiceData(ISheet worksheet, ServiceRating[] ratings, ServiceDto service, ref int rowIndex)
Expand All @@ -222,7 +223,7 @@ protected void WriteServiceData(ISheet worksheet, ServiceRating[] ratings, Servi
foreach (ServiceType serviceType in Enum.GetValues(typeof(ServiceType)))
{
row = worksheet.CreateRow(rowIndex++);
WriteCell(row, 4, c => c.SetCellValue(Translater.Enum(serviceType)), styles[StandardCellStyles.BorderedStyle]);
WriteCell(row, 4, c => c.SetCellValue(Translater.Enum(serviceType)));
RenderRating(row, ratings.FirstOrDefault(r => r.Service.Id == service.Id && r.ServiceType.Equals(serviceType)) ??
new ServiceRating());
}
Expand All @@ -236,8 +237,8 @@ protected void WriteServiceData(ISheet worksheet, ServiceRating[] ratings, Servi

protected void WriteServiceGroupData(ISheet worksheet, ServiceRating[] ratings, ServiceGroupDto group, ref int rowIndex)
{
WriteCell(worksheet.CreateRow(rowIndex++), 0,
c => c.SetCellValue(group.Name), styles[StandardCellStyles.BorderedStyle]);
WriteCell(worksheet.CreateRow(rowIndex++), 0, c => c.SetCellValue(group.Name));
worksheet.AddMergedRegion(new CellRangeAddress(rowIndex - 1, rowIndex - 1, 0, ColumnCount));

foreach (var subGroup in group.ServicesGroups)
{
Expand Down
18 changes: 0 additions & 18 deletions sources/Reports/StandardCellStyles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace Queue.Reports
public class StandardCellStyles
{
public const int BoldStyle = 0;
public const int BorderedStyle = 1;

private readonly Dictionary<int, ICellStyle> styles = new Dictionary<int, ICellStyle>();

Expand All @@ -24,7 +23,6 @@ public StandardCellStyles(IWorkbook workbook)
private void InitializeStyles(IWorkbook workbook)
{
this[BoldStyle] = CreateBoldStyle(workbook);
this[BorderedStyle] = CreateBorderedStyle(workbook);
}

private ICellStyle CreateBoldStyle(IWorkbook workbook)
Expand All @@ -34,22 +32,6 @@ private ICellStyle CreateBoldStyle(IWorkbook workbook)
var font = workbook.CreateFont();
font.Boldweight = 1000;
style.SetFont(font);
style.BorderLeft = BorderStyle.Thin;
style.BorderRight = BorderStyle.Thin;
style.BorderBottom = BorderStyle.Thin;
style.BorderTop = BorderStyle.Thin;

return style;
}

private ICellStyle CreateBorderedStyle(IWorkbook workbook)
{
var style = workbook.CreateCellStyle();

style.BorderLeft = BorderStyle.Thin;
style.BorderRight = BorderStyle.Thin;
style.BorderBottom = BorderStyle.Thin;
style.BorderTop = BorderStyle.Thin;

return style;
}
Expand Down

0 comments on commit e764fe9

Please sign in to comment.