private ForecastDataResponse ProcessGetForecastData(ForecastRequestData requestData) { var response = new ForecastDataResponse(); try { var periodIds = requestData.Periods; var hierarchyRowsId = requestData.HierarchyRows; int rowOffset = int.TryParse(requestData.Offset, out rowOffset) ? rowOffset : 0; int hierarchyLevel = hierarchyRowsId.Count(); var pageableConfig = new PageableConfig() { RowCount = requestData.Count, RowsOffset = rowOffset, LastValue = requestData.LastRow, HierarchyRowsId = hierarchyRowsId, HierarchyLevel = hierarchyLevel, PrimaryFilterValue = HttpUtility.UrlDecode(requestData.FilterValue) }; var data = ForecastProvider.GetData(requestData.ForecastId, periodIds, pageableConfig); var columns = ForecastDataMapper.GetMapTableColumns(data); response.DataSource = ForecastDataMapper.GetMapTreeTableDataItems(data, columns); if (UserConnection.GetIsFeatureEnabled("ForecastSummaryFormula")) { SummaryColumnCalculator.ApplySummaryColumns(UserConnection, columns); SummaryColumnCalculator.ApplySummaryData(UserConnection, requestData.ForecastId, response.DataSource); } FilterHiddenColumns(columns); response.Columns = columns; } catch (Exception ex) { response.Exception = ex; } return(response); }
public ForecastDataResponse GetForecastData(string forecastId, string periods, string offset, string count, string lastRow, string hierarchyRows, string filterValue) { var response = new ForecastDataResponse(); try { var periodIds = ConvertStringIdentifiersToGuidList(periods); var hierarchyRowsId = ConvertStringIdentifiersToGuidList(hierarchyRows); int rowCount = int.TryParse(count, out rowCount) ? rowCount : -1; int rowOffset = int.TryParse(offset, out rowOffset) ? rowOffset : 0; int hierarchyLevel = hierarchyRowsId.Count(); var pageableConfig = new PageableConfig() { RowCount = rowCount, RowsOffset = rowOffset, LastValue = lastRow, HierarchyRowsId = hierarchyRowsId, HierarchyLevel = hierarchyLevel, PrimaryFilterValue = HttpUtility.UrlDecode(filterValue) }; var data = ForecastProvider.GetData(new Guid(forecastId), periodIds, pageableConfig); response.Columns = ForecastDataMapper.GetMapTableColumns(data); response.DataSource = ForecastDataMapper.GetMapTreeTableDataItems(data, response.Columns); } catch (Exception ex) { response.Exception = ex; } return(response); }
private Select GetPageableSelect(Select select, PageableConfig pageableConfig) { var conditionColumn = select.Columns[0]; var direction = PageableSelectDirection.First; var conditionValue = string.Empty; if (pageableConfig.LastValue.IsNotNullOrEmpty()) { direction = PageableSelectDirection.Next; conditionValue = pageableConfig.LastValue; } var options = new PageableSelectOptions(null, pageableConfig.RowCount, direction); options.AddCondition(conditionColumn, new QueryParameter("columnLastValue", conditionValue)); Select pageableSelect = select.ToPageable(options); return(pageableSelect.Top(pageableConfig.RowCount)); }
private ForecastData InnerGetData(Guid forecastId, IEnumerable <Guid> periodIds, PageableConfig pageableConfig) { forecastId.CheckArgumentEmpty(nameof(forecastId)); Sheet sheet = SheetRepository.GetSheet(forecastId); IEnumerable <Period> periods = PeriodRepository.GetForecastPeriods(periodIds, sheet.PeriodTypeId); IEnumerable <ColumnInfo> columns = GetColumnInfos(forecastId, periods); IEnumerable <HierarchyRow> hierarchyRows = ForecastHierarchyRowDataRepository .GetHierarchyRows(sheet, sheet.Setting?.Hierarchy, pageableConfig); List <Row> rows = new List <Row>(); var maxLevel = sheet.Setting?.Hierarchy?.Count() ?? 0; IEnumerable <Cell> allCells = new List <Cell>(); var hierarchy = new List <HierarchyItem>(); if ((pageableConfig.HierarchyLevel == maxLevel) && (hierarchyRows.Any())) { allCells = EntityInForecastCellRepository.GetCellsByRecords(sheet, periods.Select(e => e.Id), hierarchyRows.Select(r => r.RecordId)); hierarchy.Add(new HierarchyItem { Id = Guid.NewGuid(), Level = maxLevel }); } hierarchyRows.ForEach(hr => { IEnumerable <Cell> cells = allCells.Where(c => c.EntityId == hr.RecordId); rows.Add(new Row { Id = hr.RecordId, Value = hr.Value, Hierarchy = hierarchy, Cells = cells }); }); return(new ForecastData { Columns = columns, Rows = rows }); }
///<inheritdoc /> public ForecastData GetData(Guid forecastId, IEnumerable <Guid> periodIds, PageableConfig pageableConfig) { pageableConfig.CheckArgumentNull(nameof(pageableConfig)); return(InnerGetData(forecastId, periodIds, pageableConfig)); }
///<inheritdoc /> public IEnumerable <Cell> GetCells(Sheet forecastSheet, IEnumerable <Guid> periodIds, PageableConfig pageableConfig) { return(new List <Cell>()); }
/// <summary> /// Gets the hierarchy rows. /// </summary> /// <param name="sheet">The forecast sheet <see cref="Sheet" />.</param> /// <param name="hierarchy">The hierarchy <see cref="HierarchySettingItem" />.</param> /// <param name="pageableConfig">The pageable configuration <see cref="PageableConfig" />.</param> /// <returns> Collection of <see cref="HierarchyRow" /></returns> public IEnumerable <HierarchyRow> GetHierarchyRows(Sheet sheet, IEnumerable <HierarchySettingItem> hierarchy, PageableConfig pageableConfig) { sheet.CheckArgumentNull(nameof(sheet)); pageableConfig.CheckArgumentNull(nameof(pageableConfig)); EntitySchema entitySchema = UserConnection.EntitySchemaManager.GetInstanceByUId(sheet.ForecastEntityUId); var level = pageableConfig.HierarchyLevel; var columns = GetHierarchyColumns(entitySchema, hierarchy).Where(c => c.Key <= level); Select select = GetForecastEntitySelect(entitySchema.Name, sheet); AddColumnsToSelect(select, entitySchema, columns); AddRightsConditions(sheet, select, entitySchema); if (level > 0) { AddConditionsToSelect(select, columns.Where(c => c.Key < level), pageableConfig.HierarchyRowsId); } if (!string.IsNullOrEmpty(pageableConfig.PrimaryFilterValue)) { EntitySchema forecastEntitySchema = UserConnection.EntitySchemaManager.GetInstanceByName(entitySchema.Name); select.AddCondition(Func.Upper(ForecastEntityAlias, forecastEntitySchema.PrimaryDisplayColumn.Name), LogicalOperation.And) .IsLike(Column.Parameter($"%{pageableConfig.PrimaryFilterValue.ToUpper()}%")); } if (pageableConfig.RowCount > 0 && pageableConfig.RowsOffset >= 0) { select = GetPageableSelect(select, pageableConfig); } if (!select.HasOrderByItems) { select.OrderByAsc(select.Columns.First()); } var lastHierarchyColumn = columns.First(c => c.Key == level); var emptyValue = GetEmptyHierarchyValue(lastHierarchyColumn.Value, entitySchema); var result = GetFilledHierarchyRows(select, level, emptyValue); return(result); }