From e764fe95aa1559c717f467958fd159b985678e82 Mon Sep 17 00:00:00 2001 From: Stanislav Date: Mon, 25 Jan 2016 07:13:22 +0300 Subject: [PATCH] - reports: refactor 2 --- .../BaseDetailedReport.cs | 2 + sources/Reports/BaseReport.cs | 25 ++++++++++- .../ClientRequestReport.cs | 2 + .../ExceptionScheduleReport.cs | 2 + .../BaseDetailedReport.cs | 2 + .../ServiceRatingReport/BaseDetailedReport.cs | 41 ++++++++++--------- sources/Reports/StandardCellStyles.cs | 18 -------- 7 files changed, 53 insertions(+), 39 deletions(-) diff --git a/sources/Reports/AdditionalServicesRatingReport/BaseDetailedReport.cs b/sources/Reports/AdditionalServicesRatingReport/BaseDetailedReport.cs index a264d75..50d4b5a 100644 --- a/sources/Reports/AdditionalServicesRatingReport/BaseDetailedReport.cs +++ b/sources/Reports/AdditionalServicesRatingReport/BaseDetailedReport.cs @@ -29,6 +29,8 @@ public abstract class BaseDetailedReport : BaseReport protected ICellStyle sumCellStyle; protected ICellStyle countCellStyle; + protected override int ColumnCount { get { return 5; } } + protected BaseDetailedReport(AdditionalServicesRatingReportSettings settings) { ServiceLocator.Current.GetInstance() diff --git a/sources/Reports/BaseReport.cs b/sources/Reports/BaseReport.cs index a97d94a..7535404 100644 --- a/sources/Reports/BaseReport.cs +++ b/sources/Reports/BaseReport.cs @@ -11,6 +11,8 @@ public abstract class BaseReport : IQueueReport { protected StandardCellStyles styles; + protected abstract int ColumnCount { get; } + #region dependency [Dependency] @@ -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; } diff --git a/sources/Reports/ClientRequestReport/ClientRequestReport.cs b/sources/Reports/ClientRequestReport/ClientRequestReport.cs index 242b274..d080eb2 100644 --- a/sources/Reports/ClientRequestReport/ClientRequestReport.cs +++ b/sources/Reports/ClientRequestReport/ClientRequestReport.cs @@ -13,6 +13,8 @@ public class ClientRequestReport : BaseReport { private readonly Guid clientRequestId; + protected override int ColumnCount { get { return 2; } } + public ClientRequestReport(Guid clientRequestId) : base() { diff --git a/sources/Reports/ExceptionScheduleReport/ExceptionScheduleReport.cs b/sources/Reports/ExceptionScheduleReport/ExceptionScheduleReport.cs index 2fed152..268d008 100644 --- a/sources/Reports/ExceptionScheduleReport/ExceptionScheduleReport.cs +++ b/sources/Reports/ExceptionScheduleReport/ExceptionScheduleReport.cs @@ -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; diff --git a/sources/Reports/OperatorRatingReport/BaseDetailedReport.cs b/sources/Reports/OperatorRatingReport/BaseDetailedReport.cs index 8fced73..1bdfc34 100644 --- a/sources/Reports/OperatorRatingReport/BaseDetailedReport.cs +++ b/sources/Reports/OperatorRatingReport/BaseDetailedReport.cs @@ -21,6 +21,8 @@ public abstract class BaseDetailedReport : BaseReport private Lazy allOperators; + protected override int ColumnCount { get { return 20; } } + public BaseDetailedReport(OperatorRatingReportSettings settings) : base() { diff --git a/sources/Reports/ServiceRatingReport/BaseDetailedReport.cs b/sources/Reports/ServiceRatingReport/BaseDetailedReport.cs index e355946..f0a16b9 100644 --- a/sources/Reports/ServiceRatingReport/BaseDetailedReport.cs +++ b/sources/Reports/ServiceRatingReport/BaseDetailedReport.cs @@ -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; @@ -20,6 +21,8 @@ public abstract class BaseDetailedReport : BaseReport { protected ServiceRatingReportSettings settings; + protected override int ColumnCount { get { return 19; } } + public BaseDetailedReport(ServiceRatingReportSettings settings) : base() { @@ -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) @@ -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()); } @@ -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) { diff --git a/sources/Reports/StandardCellStyles.cs b/sources/Reports/StandardCellStyles.cs index f5412e6..b5662f4 100644 --- a/sources/Reports/StandardCellStyles.cs +++ b/sources/Reports/StandardCellStyles.cs @@ -6,7 +6,6 @@ namespace Queue.Reports public class StandardCellStyles { public const int BoldStyle = 0; - public const int BorderedStyle = 1; private readonly Dictionary styles = new Dictionary(); @@ -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) @@ -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; }