public BSOHistoryModel(BSOHistoryItem a) { this.ID = a.Id; this.Status = a.Status; this.StatusDate = a.StatusDate; this.VisitGroupId = a.VisitGroupId; this.Comment = a.Comment; this.DeliveryCenterId = a.DeliveryCenterId; this.DeliveryCenter = a.DeliveryCenter; this.DeliveryPointId = a.DeliveryPointId; this.DeliveryPoint = a.DeliveryPoint; this.UserId = a.UserId; this.ResponsibleID = a.ResponsibleID; this.ChangeDate = a.ChangeDate; }
protected override void Process(ISheet table) { int rowNumber = 16; int rowNumberDown = 27; string dateTime = string.Format("за отчетный период с {0} г. по {1} г.", DateTimeFrom.ToShortDateString(), DateTimeTo.ToShortDateString()); table.FindCellByMacros(dateTimeConst).SetValue(dateTime); table.FindCellByMacros(deliveryPointConst).SetValue(DeliveryPoint); var ListHistoryGroupByBSO_IDs = ListHistory.GroupBy(a => a.Id); foreach (var item in ListHistoryGroupByBSO_IDs) { BSOHistoryItem temp = item.OrderBy(a => a.StatusDate).Where(b => b.Status.Id == (long)ListBSOStatusID.OnDelivery || b.Status.Id == (long)ListBSOStatusID.OnResponsible).LastOrDefault(); if (temp != null) { if (temp.StatusDate < DateTimeFrom) { BSOInfo bsoInfo = new BSOInfo() { TemporaryPolicyNumber = ListBSOinRangeDate.Where(a => a.Id == temp.Id).Select(b => b.TemporaryPolicyNumber).LastOrDefault(), //TemporaryPolicyNumber = ListBSOAllDate.Where(a => a.Id == temp.Id).Select(b => b.TemporaryPolicyNumber).LastOrDefault(), Status = new BSOStatusRef() { Id = temp.Status.Id } }; if (!string.IsNullOrEmpty(bsoInfo.TemporaryPolicyNumber)) { ListBSOBeforeDate.Add(bsoInfo); } } else { BSOInfo bsoInfo = new BSOInfo() { TemporaryPolicyNumber = ListBSOinRangeDate.Where(a => a.Id == temp.Id).Select(b => b.TemporaryPolicyNumber).LastOrDefault(), //TemporaryPolicyNumber = ListBSOAllDate.Where(a => a.Id == temp.Id).Select(b => b.TemporaryPolicyNumber).LastOrDefault(), Status = new BSOStatusRef() { Id = temp.Status.Id } }; if (!string.IsNullOrEmpty(bsoInfo.TemporaryPolicyNumber)) { ListBSOGet.Add(bsoInfo); } } } } Dictionary <string, long> dicBefore = SortingAndGroup(ListBSOBeforeDate, new List <long>() { (long)ListBSOStatusID.OnDelivery, (long)ListBSOStatusID.OnResponsible }); Dictionary <string, long> dicRange = SortingAndGroup(ListBSOGet, new List <long>() { (long)ListBSOStatusID.OnDelivery, (long)ListBSOStatusID.OnResponsible }); Dictionary <string, long> dicAll = SortingAndGroup(ListBSOAllDate, new List <long>() { (long)ListBSOStatusID.OnDelivery, (long)ListBSOStatusID.OnResponsible }); Dictionary <string, long> dicOnClient = SortingAndGroup(ListBSOinRangeDate, new List <long>() { (long)ListBSOStatusID.OnClient }); Dictionary <string, long> dicFail = SortingAndGroup(ListBSOinRangeDate, new List <long>() { (long)ListBSOStatusID.FailOnStorage, (long)ListBSOStatusID.FailOnResponsible, (long)ListBSOStatusID.FailGotoStorage }); //определяем в каком словаре максимальное кол-во элементов, для того чтоб насоздавать строки List <int> countDictionary = new List <int>(); countDictionary.Add(dicBefore == null ? 0 : dicBefore.Count); countDictionary.Add(dicRange == null ? 0 : dicRange.Count); countDictionary.Add(dicAll == null ? 0 : dicAll.Count); countDictionary.Add(dicOnClient == null ? 0 : dicOnClient.Count); countDictionary.Add(dicFail == null ? 0 : dicFail.Count); var max = countDictionary.Max() / 2; //если много данных - двигаем последние строчки еще ниже if (max > 10) { for (int i = 0; i < 10; i++) { table.CopyRow(i + rowNumberDown, i + rowNumberDown + max); } } ICellStyle style = table.Workbook.CreateCellStyle(); style.BorderRight = BorderStyle.Thin; style.BorderBottom = BorderStyle.Thin; style.BorderTop = BorderStyle.Thin; style.BorderLeft = BorderStyle.Thin; List <IRow> rows = new List <IRow>(); for (int i = 0; i < countDictionary.Max() / 2; i++) { IRow row = table.CreateRow(i + rowNumber); for (int j = 0; j <= 14; j++) { row.CreateCell(j).CellStyle = style; } rows.Add(row); } Output(dicBefore, rows, 0); Output(dicRange, rows, 3); Output(dicOnClient, rows, 6); Output(dicFail, rows, 9); Output(dicAll, rows, 12); //Итого: IRow rowSum = table.CreateRow(max + rowNumber); rowSum.CreateCell(0).SetValue("Итого:"); rowSum.CreateCell(2).SetCellFormula(string.Format("SUM(C{0}:C{1})", rowNumber + 1, rowNumber + max)); rowSum.CreateCell(5).SetCellFormula(string.Format("SUM(F{0}:F{1})", rowNumber + 1, rowNumber + max)); rowSum.CreateCell(8).SetCellFormula(string.Format("SUM(I{0}:I{1})", rowNumber + 1, rowNumber + max)); rowSum.CreateCell(11).SetCellFormula(string.Format("SUM(L{0}:L{1})", rowNumber + 1, rowNumber + max)); rowSum.CreateCell(14).SetCellFormula(string.Format("SUM(O{0}:O{1})", rowNumber + 1, rowNumber + max)); table.FindCellByMacros(FIOConst).SetValue(FIO); table.FindCellByMacros(PositionConst).SetValue(Position); table.FindCellByMacros(nowDateTimeConst).SetValue(DateTime.Now.ToShortDateString()); }