/// <summary> /// Fill Summary Report Bridge Data tab. /// </summary> /// <param name="worksheet"></param> /// <param name="simulationModel"></param> /// <param name="simulationYears"></param> /// <param name="dbContext"></param> /// <returns>WorkSummaryModel with simulation and bridge data models</returns> internal WorkSummaryModel Fill(ExcelWorksheet worksheet, SimulationModel simulationModel, List <int> simulationYears, BridgeCareContext dbContext) { var BRKeys = new List <int>(); var sections = bridgeData.GetSectionData(simulationModel, dbContext); var treatments = bridgeData.GetTreatments(simulationModel.simulationId, dbContext); var simulationDataTable = bridgeData.GetSimulationData(simulationModel, dbContext, simulationYears); var projectCostModels = bridgeData.GetReportData(simulationModel, dbContext, simulationYears); var sectionIdsFromSimulationTable = from dt in simulationDataTable.AsEnumerable() select dt.Field <int>("SECTIONID"); var sectionsForSummaryReport = sections.Where(sm => sectionIdsFromSimulationTable.Contains(sm.SECTIONID)).ToList(); BRKeys = sectionsForSummaryReport.Select(sm => Convert.ToInt32(sm.FACILITY)).ToList(); var bridgeDataModels = bridgeData.GetBridgeData(BRKeys, simulationModel, dbContext, parametersModel); var budgetsPerBrKey = bridgeData.GetBudgetsPerBRKey(simulationModel, dbContext); var simulationDataModels = bridgeDataHelper.GetSimulationDataModels(simulationDataTable, simulationYears, projectCostModels, budgetsPerBrKey); var unfundedRecommendations = bridgeData.GetUnfundedRcommendations(simulationModel, dbContext); unfundedRecommendations.ForEach(_ => { _.TotalProjectCost = Convert.ToDouble(_.Budget_Hash.Split('/')[1]); }); // Add data to excel. var headers = GetHeaders(); var currentCell = AddHeadersCells(worksheet, headers, simulationYears); // Add row next to headers for filters and year numbers for dynamic data. Cover from top, left to right, and bottom set of data. using (ExcelRange autoFilterCells = worksheet.Cells[3, 1, currentCell.Row, currentCell.Column - 1]) { autoFilterCells.AutoFilter = true; } var columnForRiskScore = AddBridgeDataModelsCells(worksheet, bridgeDataModels, currentCell); AddDynamicDataCells(worksheet, sectionsForSummaryReport, simulationDataModels, bridgeDataModels, currentCell, columnForRiskScore); // TODO The line below currently hangs Postman in testing. It will be required for final production. // ExcelHelper.ApplyBorder(worksheet.Cells[1, 1, currentCell.Row, currentCell.Column]); worksheet.Cells.AutoFitColumns(); var spacerBeforeFirstYear = SpacerColumnNumbers[0] - 11; worksheet.Column(spacerBeforeFirstYear).Width = 3; foreach (var spacerNumber in SpacerColumnNumbers) { worksheet.Column(spacerNumber).Width = 3; } var lastColumn = worksheet.Dimension.Columns + 1; worksheet.Column(lastColumn).Width = 3; var workSummaryModel = new WorkSummaryModel { SimulationDataModels = simulationDataModels, BridgeDataModels = bridgeDataModels, Treatments = treatments, BudgetsPerBRKeys = budgetsPerBrKey, UnfundedRecommendations = unfundedRecommendations, ParametersModel = parametersModel }; return(workSummaryModel); }
/// <summary> /// Fill Summary Report Bridge Data tab. /// </summary> /// <param name="worksheet"></param> /// <param name="simulationModel"></param> /// <param name="simulationYears"></param> /// <param name="dbContext"></param> /// <returns>WorkSummaryModel with simulation and bridge data models</returns> public WorkSummaryModel Fill(ExcelWorksheet worksheet, SimulationModel simulationModel, List <int> simulationYears, BridgeCareContext dbContext) { var BRKeys = new List <int>(); var sections = bridgeData.GetSectionData(simulationModel, dbContext); var simulationDataTable = bridgeData.GetSimulationData(simulationModel, dbContext, simulationYears); var projectCostModels = bridgeData.GetReportData(simulationModel, dbContext, simulationYears); var sectionIdsFromSimulationTable = from dt in simulationDataTable.AsEnumerable() select dt.Field <int>("SECTIONID"); var sectionsForSummaryReport = sections.Where(sm => sectionIdsFromSimulationTable.Contains(sm.SECTIONID)).ToList(); BRKeys = sectionsForSummaryReport.Select(sm => Convert.ToInt32(sm.FACILITY)).ToList(); var bridgeDataModels = bridgeData.GetBridgeData(BRKeys, dbContext); var simulationDataModels = bridgeDataHelper.GetSimulationDataModels(simulationDataTable, simulationYears, projectCostModels); // Add data to excel. var headers = GetHeaders(); var currentCell = AddHeadersCells(worksheet, headers, simulationYears); // Add row next to headers for filters and year numbers for dynamic data. Cover from top, left to right, and bottom set of data. using (ExcelRange autoFilterCells = worksheet.Cells[3, 1, currentCell.Row, currentCell.Column - 1]) { autoFilterCells.AutoFilter = true; } AddBridgeDataModelsCells(worksheet, bridgeDataModels, currentCell); AddDynamicDataCells(worksheet, sectionsForSummaryReport, simulationDataModels, bridgeDataModels, currentCell); // TODO The line below currently hangs Postman in testing. It will be required for final production. // ExcelHelper.ApplyBorder(worksheet.Cells[1, 1, currentCell.Row, currentCell.Column]); worksheet.Cells.AutoFitColumns(); var workSummaryModel = new WorkSummaryModel { SimulationDataModels = simulationDataModels, BridgeDataModels = bridgeDataModels }; return(workSummaryModel); }