public static string GetString(PeriodTypeValues periodTypeValues) { switch (periodTypeValues) { case PeriodTypeValues.Daily: return "Dzienny"; case PeriodTypeValues.Monthly: return "Miesięczny"; case PeriodTypeValues.Custom: return "Okresowy"; } return "NotDefined"; }
protected override IReportData FillData(DateTime startTime, DateTime endTime, PeriodTypeValues period) { string header = PeriodTypes.GetString(period) + " raport produkcji z "; switch (period) { case PeriodTypeValues.Daily: { header += "dnia " + startTime.ToShortDateString(); break; } case PeriodTypeValues.Monthly: { header += "miesiąca " + startTime.Month.ToString(); break; } case PeriodTypeValues.Custom: { header += "okresu od: " + startTime.ToShortDateString() + " do: " + endTime.ToShortDateString(); break; } } ProductionReportData result = new ProductionReportData() {Header = header}; using (IReportsService service = ServiceFactory.GetReportsService()) { List<DeliveryNoteReportPackage> deliveryNoteReportPackageList = service.GetDeliveryNoteReportPackageListByDateTime(startTime, endTime); var groups = deliveryNoteReportPackageList.GroupBy(x => (x.Recipe != null) ? x.Recipe.Id : 0).AsEnumerable(); double amountAllElements = 0; List<ProductionReportSubData> productionReportSubDatas = new List<ProductionReportSubData>(); foreach (var group in groups) { if (group.Count() <= 0) break; if (group.FirstOrDefault() == null) break; string recipeCode = "0"; string recipeName = "NotDefined"; if (group.FirstOrDefault().Recipe != null) { recipeName = group.FirstOrDefault().Recipe.Name; recipeCode = group.FirstOrDefault().Recipe.Code; } double amountOfElement = 0; foreach (var elementGroup in group) { if (elementGroup != null && elementGroup.DeliveryNote != null && !elementGroup.DeliveryNote.IsDeactive && !elementGroup.DeliveryNote.IsDeleted) { amountOfElement += elementGroup.DeliveryNote.Amount ?? 0; } } amountAllElements += amountOfElement; productionReportSubDatas.Add(new ProductionReportSubData() {RecipeCode = recipeCode, RecipeName = recipeName, Amount = amountOfElement.ToString()}); Debug.WriteLine("Code: " + recipeCode + " Nazwa recepty: " + recipeName + ", GroupKey:" + group.Key + ", GroupCount: " + group.Count() + ", Ilość: " + amountOfElement + " m3"); } result.Items = productionReportSubDatas.OrderBy(x => x.RecipeCode).ToList(); result.Sum = amountAllElements.ToString(); } return result; }