コード例 #1
0
        /// <summary>
        /// Получить данные для списка
        /// </summary>
        /// <param name="parametr"></param>
        /// <returns></returns>
        public async Task <ReportResultData> GetDataList(BaseModelReportParam parametr)
        {
            var resultData = new ReportResultData();
            var accessForm = await _accessManager.GetAccessFormAsync(parametr.UserName, parametr.FormId);

            if (accessForm != null && (int)accessForm.TypeAccec < 2)
            {
                throw new UserMessageException("Вы запросили данные режима, на который у вас не открыты права");
            }
            var formModelDto =
                (await _reportDbContext.FormModel.FirstOrDefaultAsync(f => f.Id == parametr.FormId)).Map <FormModelDto>();

            if (formModelDto == null)
            {
                throw new UserMessageException("Не удалось определить форму");
            }
            resultData.FormModel   = formModelDto;
            resultData.FieldAccess = await _reportManager.GetFieldsFormWithProfileAsync(parametr.UserName, parametr.FormId, false,
                                                                                        fields => fields.Where(f => (f.IsVisibleList ?? false) || string.IsNullOrWhiteSpace(f.Express)));

            var report = AutoFac.ResolveNamed <IReportEngineData>(string.IsNullOrWhiteSpace(formModelDto.NameClassDataEngine) ? nameof(ReportEngineDefaultData) : formModelDto.NameClassDataEngine);

            var resultDataFieldAccess = resultData.FieldAccess as FieldAccessDto[] ?? resultData.FieldAccess.ToArray();

            resultData.Data    = GetDataAccess(report == null ? null : await report.GetDataList(parametr), resultDataFieldAccess);
            resultData.Columns = await _columnCreater.GetColumns(resultDataFieldAccess);

            resultData.KeyField     = resultDataFieldAccess.FirstOrDefault(f => f.IsKey ?? false)?.Name;
            resultData.FormProperty = await _columnCreater.GetProperty(resultDataFieldAccess, formModelDto);

            return(resultData);
        }
コード例 #2
0
        /// <summary>
        /// Получить данные для списка
        /// </summary>
        /// <param name="parametr"></param>
        /// <returns></returns>
        public async Task <ReportResultData> GetEditModel(BaseModelReportParam parametr)
        {
            var resultData = new ReportResultData();
            var accessForm = await _accessManager.GetAccessFormAsync(parametr.UserName, parametr.FormId);

            if (accessForm != null && (int)accessForm.TypeAccec < 2)
            {
                throw new UserMessageException("Вы запросили данные режима, на который у вас не открыты права");
            }
            var formModelDto =
                Mapper.Map <FormModelDto>((
                                              await _reportDbContext.FormModel.FirstOrDefaultAsync(f => f.Id == parametr.FormId)));

            if (formModelDto == null)
            {
                throw new UserMessageException("Не удалось определить форму");
            }

            resultData.FormModel   = formModelDto;
            resultData.FieldAccess = await _reportManager.GetFieldsFormWithProfileAsync(parametr.UserName, parametr.FormId, false, fields => fields.Where(f => f.IsDetail ?? false));

            // resultData.Buttons = await _reportManager.GetButtonsAsync(parametr.UserName, parametr.FormId, false);
            var report = AutoFac.ResolveNamed <IReportEngineData>(formModelDto.NameClassDataEngine);
            var resultDataFieldAccess = resultData.FieldAccess as FieldAccessDto[] ?? resultData.FieldAccess.ToArray();

            resultData.Data = report == null ? "" : GetModelAccess(await report.GetDataEditModel(parametr), resultDataFieldAccess);
            return(resultData);
        }
コード例 #3
0
ファイル: EmailProcessor.cs プロジェクト: ashokmahla/YakShop
        /// <summary>
        /// Emails the report.
        /// </summary>
        public SchedulerHistoryEmailStatus EmailReport(ReportResultData reportData)
        {
            string emailHtml;
            string subject;
            string toEmailId = Properties.Settings.Default.FaultedEmailId;

            var result = SchedulerHistoryEmailStatus.Sent;

            try
            {
                if (reportData == null || reportData.ReportData == null || !reportData.ReportData.Any())
                {
                    throw new Exception("Something went wrong!");
                }

                emailHtml = this.emailBuilder.GetReportHtml(reportData);

                subject = "Hank report: " + DateTime.Now.ToShortDateString() + " - " + reportData.PostFixToSubject;

                if (reportData.TotalCount != 0 && reportData.DoSendEmail)
                {
                    toEmailId = reportData.ToEmailIds;
                }
                else
                {
                    subject += " - Default";
                }
            }
            catch (Exception ex)
            {
                LoggerService.LogException(ex);

                emailHtml = ex.Message;
                subject   = "Not able to generate! ";
                toEmailId = Properties.Settings.Default.FaultedEmailId;
                result    = SchedulerHistoryEmailStatus.SendException;
            }

            if (toEmailId.IsBlank())
            {
                toEmailId = Properties.Settings.Default.FaultedEmailId;
            }

            var bccTo = ConfigurationManager.AppSettings[ConfigConstants.BccTo].ToEmailArray();

            var resultVal = this.emailSender.SendEmail(toEmailId.ToEmailArray(), bccTo, subject, emailHtml);

            if (resultVal == SchedulerHistoryEmailStatus.NoValidRecipientFound ||
                resultVal == SchedulerHistoryEmailStatus.NoRecipientFound)
            {
                this.emailSender.SendEmail(Properties.Settings.Default.FaultedEmailId.ToEmailArray(), bccTo, subject, emailHtml);
            }

            return(result == SchedulerHistoryEmailStatus.SendException ? result : resultVal);
        }
コード例 #4
0
        private ReportResult GetWfsUURegistryQueryResult(ReportQuery query)
        {
            var    data                   = query.Parameters.Where(p => p.Name == "data").Select(a => a.Value).First();
            var    queryList              = GetQueries();
            var    queryInfo              = queryList.GetQuery(query.QueryName, data);
            string reportStoredQuery      = queryInfo.QueryUrl;
            string reportStoredQueryTotal = queryInfo.Data.QueryUrl;

            var fylker   = _registerService.GetFylker();
            var kommuner = _registerService.GetKommuner();
            var admUnits = fylker.Union(kommuner).ToDictionary(k => k.Key, v => v.Value);

            admUnits.Add("*", "Hele landet");

            ReportResult reportResult = new ReportResult();

            reportResult.Data = new List <ReportResultData>();

            var areas = query.Parameters.Where(p => p.Name == "area").Select(a => a.Value).ToList();

            foreach (var area in areas)
            {
                string areaUnit = (area == "Hele landet" ? "*" : area);

                reportStoredQuery      = SetAdmEnhNr(reportStoredQuery, areaUnit);
                reportStoredQueryTotal = SetAdmEnhNr(reportStoredQueryTotal, areaUnit);

                FeatureCollection result      = GetFeature(reportStoredQuery);
                FeatureCollection resultTotal = GetFeature(reportStoredQueryTotal);

                reportResult.TotalDataCount = 0;

                ReportResultData             reportResultData       = new ReportResultData();
                List <ReportResultDataValue> reportResultDataValues = new List <ReportResultDataValue>();
                reportResultData.Label          = admUnits.ContainsKey(area) ? admUnits[area] : area;
                reportResultData.TotalDataCount = resultTotal.numberMatched;
                ReportResultDataValue reportResultDataValue = new ReportResultDataValue();
                reportResultDataValue.Key   = queryInfo.Data.Name;
                reportResultDataValue.Value = result.numberMatched.ToString();
                reportResultDataValues.Add(reportResultDataValue);

                //additional start
                reportResultDataValue       = new ReportResultDataValue();
                reportResultDataValue.Key   = "";
                reportResultDataValue.Value = "";
                reportResultDataValues.Add(reportResultDataValue);
                //additional end

                reportResultData.Values = reportResultDataValues;
                reportResult.Data.Add(reportResultData);
            }

            return(reportResult);
        }
コード例 #5
0
        public ReportResult GetSelectedDatasetsByTheme(ReportQuery param)
        {
            ReportResult reportResult = new ReportResult();

            reportResult.Data = new List <ReportResultData>();

            var total = _dbContext.Organizations.Where(m => m.OrganizationType == Models.OrganizationType.Municipality).Count();

            reportResult.TotalDataCount = 0;

            var results = (from c in _dbContext.CoverageDatasets.DefaultIfEmpty()
                           join d in _dbContext.Datasets on c.DatasetId equals d.systemId
                           where c.ConfirmedDok == true && d.DatasetType != "Kommunalt"
                           group c by new { d.theme.description, d.name } into grouped
                           select new
            {
                theme = grouped.Key.description,
                Count = grouped.Count(),
                name = grouped.Key.name
            }).OrderByDescending(x => x.Count).ToList();

            foreach (var result in results)
            {
                ReportResultData reportResultData = new ReportResultData();

                List <ReportResultDataValue> reportResultDataValues = new List <ReportResultDataValue>();

                reportResultData.Label          = result.theme.ToString();
                reportResultData.TotalDataCount = total;

                ReportResultDataValue reportResultDataValue = new ReportResultDataValue();

                reportResultDataValue.Key   = result.name.ToString();
                reportResultDataValue.Value = result.Count.ToString();

                reportResultDataValues.Add(reportResultDataValue);

                //additional start
                reportResultDataValue       = new ReportResultDataValue();
                reportResultDataValue.Key   = "";
                reportResultDataValue.Value = "";
                reportResultDataValues.Add(reportResultDataValue);
                //additional end

                reportResultData.Values = reportResultDataValues;

                reportResult.Data.Add(reportResultData);
            }

            return(reportResult);
        }
コード例 #6
0
        /// <summary>
        /// Gets the report HTML.
        /// </summary>
        /// <param name="reportResultData">The report result data.</param>
        /// <returns>HTML for report</returns>
        public string GetReportHtml(ReportResultData reportResultData)
        {
            var baseLocation = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            baseLocation = Path.Combine(baseLocation, "Template", "emailHtml.html");

            var html = this.ReadFile(baseLocation);

            html = html.Replace("##Passed##", reportResultData.PassedCount.ToString())
                   .Replace("##Faulted##", reportResultData.FaultCount.ToString())
                   .Replace("##Total##", reportResultData.TotalCount.ToString())
                   .Replace("##Cancelled##", reportResultData.CancelledCount + " " + reportResultData.CancelledPostFix)
                   .Replace("##UnProcessed##", reportResultData.UnProcessedCount.ToString())
                   .Replace("##ReportUrl##", string.Format(Properties.Settings.Default.BaseWebUrl + WebEndPoints.ReportByWebSiteId, reportResultData.WebsiteId));

            int startIndex = html.IndexOf(TrStartTag) + TrStartTag.Length;
            int length     = html.IndexOf(TrEndTag) - startIndex;

            var trHtml = html.Substring(startIndex, length);

            if (reportResultData.ReportData != null)
            {
                html = html.Replace("##UrlTested##", reportResultData.UrlTested);
                html = html.Replace("##Execution Group##", reportResultData.GroupName);

                var startDate = reportResultData.ReportData.Min(x => x.FinishedAtDateTime);
                var endDate   = reportResultData.ReportData.Max(x => x.FinishedAtDateTime);

                html = html.Replace("##Execution Started##", startDate.ToDateEstFormat());
                html = html.Replace("##Execution Completed##", endDate.ToDateEstFormat());

                html = html.Replace("##Tr-Passed##", this.GetTrHtml(trHtml, reportResultData.ReportData.Where(x => x.Status == ExecutionReportStatus.Passed).OrderBy(x => x.SuiteId), reportResultData.WebsiteId));

                html = html.Replace("##Tr-Faulted##", this.GetTrHtml(trHtml, reportResultData.ReportData.Where(x => x.Status == ExecutionReportStatus.Failed).OrderBy(x => x.SuiteId), reportResultData.WebsiteId));

                html = html.Replace("##Tr-Cancelled##", this.GetTrHtml(trHtml, reportResultData.ReportData.Where(x => x.Status == ExecutionReportStatus.Cancelled).OrderBy(x => x.SuiteId), reportResultData.WebsiteId, false));

                html = html.Replace("##Tr-UnProcessed##", this.GetTrHtml(trHtml, reportResultData.ReportData.Where(x => x.Status != ExecutionReportStatus.Passed && x.Status != ExecutionReportStatus.Failed && x.Status != ExecutionReportStatus.Cancelled).OrderBy(x => x.SuiteId), reportResultData.WebsiteId, false));
            }

            html = html.Replace(trHtml, string.Empty).Replace(TrStartTag, string.Empty).Replace(TrEndTag, string.Empty);

            return(html);
        }
コード例 #7
0
ファイル: Processor.cs プロジェクト: ashokmahla/YakShop
        /// <summary>
        /// Processes the email.
        /// </summary>
        /// <param name="testQueue">The test queue.</param>
        /// <param name="groupName">Name of the group.</param>
        /// <param name="schedulerExecutionStatus">The scheduler execution status.</param>
        private static void ProcessEmail(ResultMessage <List <TestQueue> > testQueue, string groupName, SchedulerExecutionStatus schedulerExecutionStatus)
        {
            var emailStatus = SchedulerHistoryEmailStatus.NotSent;

            if (testQueue != null && testQueue.Item != null && groupName.IsNotBlank())
            {
                var schedulerIds = testQueue.Item.Select(x => x.SchedulerId).Distinct();

                var resultData = TestDataApi.Post <SearchReportObject, SearchReportResult>(EndPoints.ReportSearch, new SearchReportObject {
                    ExecutionGroup = groupName
                });

                if (resultData == null || resultData.IsError)
                {
                    emailStatus = SchedulerHistoryEmailStatus.SendException;
                }
                else if (resultData.Item != null)
                {
                    var emailProcessor = new EmailProcessor();

                    foreach (var schedulerId in schedulerIds)
                    {
                        if (!schedulerId.HasValue)
                        {
                            continue;
                        }

                        var schedularData = TestDataApi.Get <Scheduler>(string.Format(EndPoints.SchedulerById, schedulerId));

                        if (schedularData != null && !schedularData.IsError && schedularData.Item != null)
                        {
                            schedularData.Item.Status = schedulerExecutionStatus;
                            var repostData = new ReportResultData(resultData.Item.Data, schedularData.Item, groupName);
                            emailStatus = emailProcessor.EmailReport(repostData);
                        }
                    }
                }
            }

            TestDataApi.Post(string.Format(EndPoints.SchedulerHistoryEmailStatus, groupName, (int)emailStatus), new List <SchedulerHistory>());
        }
コード例 #8
0
        private string GetLabelNumber(ReportResultData data)
        {
            string label = "";

            if (data.Values.Count > 2 && data.Values[2].Key == "Number")
            {
                return(data.Values[2].Value);
            }

            if (data.Values.Count > 3 && data.Values[3].Key == "Number")
            {
                return(data.Values[3].Value);
            }

            label = data.Label;
            label = label.Replace(" kommune", "");

            if (_codeList.ContainsValue(label))
            {
                return(_codeList.Where(d => d.Value == label).Select(s => s.Key).FirstOrDefault());
            }

            return(label);
        }
コード例 #9
0
        public StatisticsReport GetReport(string measurement, string organization, DateTime?fromDate, DateTime?toDate)
        {
            TimeSpan ts = new TimeSpan(23, 59, 59);

            toDate = toDate.Value.Date + ts;

            StatisticsReport statisticsReport = new StatisticsReport();

            bool organizationSelected = !string.IsNullOrEmpty(organization);

            var list = _dbContext.StatisticalData
                       .Where(c => c.Measurement == measurement && (!organizationSelected || (organizationSelected && c.Organization == organization)) && (c.Date >= fromDate && c.Date <= toDate))
                       .GroupBy(x => x.Date)
                       .Select(g => new {
                Date  = g.Key,
                Count = g.Sum(x => x.Count)
            }).OrderBy(o => o.Date).ToList();

            ReportResult reportResult = new ReportResult();
            var          data         = new List <ReportResultData>();

            ReportResultData resultData = new ReportResultData();

            resultData = new ReportResultData
            {
                Label          = measurement,
                TotalDataCount = 0,
                Values         = new List <ReportResultDataValue>()
            };

            foreach (var item in list)
            {
                resultData.Values.Add(new ReportResultDataValue {
                    Key = item.Date.ToString(), Value = item.Count.ToString()
                });
            }

            data.Add(resultData);
            reportResult.Data = data;

            if (list.Count > 0)
            {
                reportResult.TotalDataCount = list.Max(m => m.Count);
            }

            statisticsReport.ReportResult = reportResult;

            if (list.Count > 0)
            {
                statisticsReport.MinimumCount = list.Min(m => m.Count);
            }

            statisticsReport.MeasurementsAvailable  = GetMeasurements();
            statisticsReport.OrganizationsAvailable = GetOrganizations();

            statisticsReport.MeasurementSelected  = measurement;
            statisticsReport.OrganizationSelected = organization;

            statisticsReport.FromDate = fromDate;
            statisticsReport.ToDate   = toDate;

            return(statisticsReport);
        }
コード例 #10
0
        public ReportResult GetSelectedDatasetsCoverage(ReportQuery param)
        {
            ReportResult reportResult = new ReportResult();

            reportResult.Data = new List <ReportResultData>();

            var total = 0;

            reportResult.TotalDataCount = total;

            var results = (from c in _dbContext.CoverageDatasets
                           join d in _dbContext.Datasets on c.DatasetId equals d.systemId
                           let datasetName = d.name
                                             select new { c.Municipality.name, datasetName, c.Coverage, c.ConfirmedDok, c.Municipality.number, c.Municipality.MunicipalityCode }).Distinct().OrderBy(o => o.name).ThenBy(o2 => o2.datasetName).ToList();

            var orgList = (from org in _dbContext.Organizations
                           where org.OrganizationType == Models.OrganizationType.Municipality
                           select new { org.name, org.number }).ToList();

            var coverageList = (from c in _dbContext.CoverageDatasets
                                select c.Municipality.name).ToList();



            var areas = param.Parameters.Where(p => p.Name == "area").Select(a => a.Value).ToList();

            if (areas.Any())
            {
                if (areas[0] != "Hele landet")
                {
                    var resultsNr = (from res in results
                                     join munici in _dbContext.Organizations on res.number equals munici.number
                                     select new { res.name, res.datasetName, res.Coverage, res.ConfirmedDok, res.number, munici.MunicipalityCode }).ToList();

                    results = (from r in resultsNr
                               where (from c in areas
                                      select c)
                               .Contains(r.MunicipalityCode) ||
                               (from c in areas
                                select c)
                               .Contains(r.MunicipalityCode.Substring(0, 2))

                               select new { r.name, r.datasetName, r.Coverage, r.ConfirmedDok, r.number, r.MunicipalityCode }).ToList();
                }
            }


            foreach (var result in results)
            {
                ReportResultData reportResultData = new ReportResultData();

                List <ReportResultDataValue> reportResultDataValues = new List <ReportResultDataValue>();

                reportResultData.Label          = result.name.ToString();
                reportResultData.TotalDataCount = total;

                ReportResultDataValue reportResultDataValue = new ReportResultDataValue();

                reportResultDataValue.Key   = result.datasetName;
                reportResultDataValue.Value = result.Coverage ? "JA" : "NEI";

                reportResultDataValues.Add(reportResultDataValue);


                reportResultDataValue       = new ReportResultDataValue();
                reportResultDataValue.Key   = "Valgt";
                reportResultDataValue.Value = result.ConfirmedDok ? "JA" : "NEI";
                reportResultDataValues.Add(reportResultDataValue);

                //additional Number start
                reportResultDataValue       = new ReportResultDataValue();
                reportResultDataValue.Key   = "Number";
                reportResultDataValue.Value = result.MunicipalityCode;
                reportResultDataValues.Add(reportResultDataValue);
                //additional Number end

                reportResultData.Values = reportResultDataValues;

                reportResult.Data.Add(reportResultData);
            }

            return(reportResult);
        }
コード例 #11
0
        public ReportResult GetSelectedAndAdditionalDatasets(ReportQuery param)
        {
            ReportResult reportResult = new ReportResult();

            reportResult.Data = new List <ReportResultData>();

            _dbContext.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

            var total = (from dd in _dbContext.Datasets
                         where dd.DatasetType != "Kommunalt"
                         select dd.systemId).Distinct().Count();

            reportResult.TotalDataCount = 0;

            var resultsSelected = (from c in _dbContext.CoverageDatasets
                                   join ds in _dbContext.Datasets on c.DatasetId equals ds.systemId
                                   where c.ConfirmedDok == true && ds.DatasetType != "Kommunalt"
                                   group c by new { c.Municipality.name, c.Municipality.number, c.Municipality.DateConfirmedMunicipalDOK, c.Municipality.MunicipalityCode } into grouped
                                   select new
            {
                name = grouped.Key.name,
                Count = grouped.Distinct().Count(),
                number = grouped.Key.number,
                DateConfirmedMunicipalDOK = grouped.Key.DateConfirmedMunicipalDOK,
                MunicipalityCode = grouped.Key.MunicipalityCode
            }).OrderByDescending(x => x.Count).ToList();

            var resultsSelectedAdditional = (from c in _dbContext.CoverageDatasets
                                             join ds in _dbContext.Datasets on c.DatasetId equals ds.systemId
                                             where ds.DatasetType == "Kommunalt"
                                             group c by new { c.Municipality.name, c.Municipality.number, c.Municipality.DateConfirmedMunicipalDOK, c.Municipality.MunicipalityCode } into grouped
                                             select new
            {
                name = grouped.Key.name,
                Count = grouped.Count(),
                number = grouped.Key.number,
                DateConfirmedMunicipalDOK = grouped.Key.DateConfirmedMunicipalDOK,
                MunicipalityCode = grouped.Key.MunicipalityCode
            }).ToList();


            var resultsNotSelected = (from c in _dbContext.CoverageDatasets
                                      join ds in _dbContext.Datasets on c.DatasetId equals ds.systemId
                                      where c.ConfirmedDok == false && ds.DatasetType != "Kommunalt"
                                      group c by new { c.Municipality.name, c.Municipality.number, c.Municipality.DateConfirmedMunicipalDOK, c.Municipality.MunicipalityCode } into grouped
                                      select new
            {
                name = grouped.Key.name,
                Count = 0,
                number = grouped.Key.number,
                DateConfirmedMunicipalDOK = grouped.Key.DateConfirmedMunicipalDOK,
                MunicipalityCode = grouped.Key.MunicipalityCode
            })
                                     .OrderByDescending(x => x.Count)
                                     .ToList();

            resultsNotSelected = (from cc in resultsNotSelected
                                  where !resultsSelected.Any(s => s.number == cc.number)
                                  select cc)
                                 .ToList();

            var results = resultsSelected.Union(resultsNotSelected).Distinct();

            var areas = param.Parameters.Where(p => p.Name == "area").Select(a => a.Value).ToList();

            if (areas.Any())
            {
                if (areas[0] != "Hele landet")
                {
                    var resultsNr = (from res in results
                                     join munici in _dbContext.Organizations on res.number equals munici.number
                                     select new { res.name, res.Count, res.number, munici.MunicipalityCode, munici.DateConfirmedMunicipalDOK }).ToList();

                    results = (from r in resultsNr
                               where (from c in areas
                                      select c)
                               .Contains(r.MunicipalityCode) ||
                               (from c in areas
                                select c)
                               .Contains(r.MunicipalityCode.Substring(0, 2))

                               select new { r.name, r.Count, r.number, r.DateConfirmedMunicipalDOK, r.MunicipalityCode }).ToList();
                }
            }


            foreach (var result in results.OrderByDescending(s => s.Count).ThenBy(ss => ss.name))
            {
                ReportResultData reportResultData = new ReportResultData();

                List <ReportResultDataValue> reportResultDataValues = new List <ReportResultDataValue>();

                reportResultData.Label          = result.name.ToString();
                reportResultData.TotalDataCount = total;

                ReportResultDataValue reportResultDataValue = new ReportResultDataValue();

                reportResultDataValue.Key   = "Det offentlige kartgrunnlaget";
                reportResultDataValue.Value = result.Count.ToString();

                reportResultDataValues.Add(reportResultDataValue);

                //additional start
                var additionalItem = (from ra in resultsSelectedAdditional
                                      where ra.number == result.number
                                      select ra.Count).FirstOrDefault();

                reportResultDataValue       = new ReportResultDataValue();
                reportResultDataValue.Key   = "Tillegg";
                reportResultDataValue.Value = additionalItem.ToString();
                reportResultDataValues.Add(reportResultDataValue);
                //additional end

                //additional DateConfirmedMunicipalDOK start
                reportResultDataValue       = new ReportResultDataValue();
                reportResultDataValue.Key   = "Bekreftet";
                reportResultDataValue.Value = result.DateConfirmedMunicipalDOK.HasValue ? result.DateConfirmedMunicipalDOK.Value.ToString("dd.MM.yyyy") : "";
                reportResultDataValues.Add(reportResultDataValue);
                //additional DateConfirmedMunicipalDOK end

                //additional Number start
                reportResultDataValue       = new ReportResultDataValue();
                reportResultDataValue.Key   = "Number";
                reportResultDataValue.Value = result.MunicipalityCode;
                reportResultDataValues.Add(reportResultDataValue);
                //additional Number end


                reportResultData.Values = reportResultDataValues;

                reportResult.Data.Add(reportResultData);
            }

            return(reportResult);
        }
コード例 #12
0
        public ReportResult GetSelectedSuitabilityDatasets(ReportQuery param)
        {
            ReportResult reportResult = new ReportResult();

            reportResult.Data = new List <ReportResultData>();

            _dbContext.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

            var total = (from dd in _dbContext.Datasets
                         where dd.DatasetType != "Kommunalt"
                         select dd.systemId).Distinct().Count();

            reportResult.TotalDataCount = 0;

            var resultsSelected = (from c in _dbContext.CoverageDatasets
                                   join ds in _dbContext.Datasets on c.DatasetId equals ds.systemId
                                   where (c.RegionalPlan || c.MunicipalSocialPlan || c.MunicipalLandUseElementPlan ||
                                          c.ZoningPlan || c.BuildingMatter || c.PartitionOff ||
                                          c.ImpactAssessmentPlanningBuildingAct ||
                                          c.RiskVulnerabilityAnalysisPlanningBuildingAct) &&
                                   ds.DatasetType != "Kommunalt"
                                   group c by new { c.Municipality.name, c.Municipality.number, c.Municipality.DateConfirmedMunicipalDOK, c.Municipality.MunicipalityCode, c.Municipality.StatusConfirmationMunicipalDOK } into grouped
                                   select new
            {
                name = grouped.Key.name,
                Count = grouped.Distinct().Count(),
                number = grouped.Key.number,
                DateConfirmedMunicipalDOK = grouped.Key.DateConfirmedMunicipalDOK,
                MunicipalityCode = grouped.Key.MunicipalityCode,
                DOKStatus = grouped.Key.StatusConfirmationMunicipalDOK
            }).OrderByDescending(x => x.Count).ToList();



            var resultsNotSelected = (from c in _dbContext.CoverageDatasets
                                      join ds in _dbContext.Datasets on c.DatasetId equals ds.systemId
                                      where !(c.RegionalPlan || c.MunicipalSocialPlan || c.MunicipalLandUseElementPlan ||
                                              c.ZoningPlan || c.BuildingMatter || c.PartitionOff ||
                                              c.ImpactAssessmentPlanningBuildingAct ||
                                              c.RiskVulnerabilityAnalysisPlanningBuildingAct) &&
                                      ds.DatasetType != "Kommunalt"
                                      group c by new { c.Municipality.name, c.Municipality.number, c.Municipality.DateConfirmedMunicipalDOK, c.Municipality.MunicipalityCode, c.Municipality.StatusConfirmationMunicipalDOK } into grouped
                                      select new
            {
                name = grouped.Key.name,
                Count = 0,
                number = grouped.Key.number,
                DateConfirmedMunicipalDOK = grouped.Key.DateConfirmedMunicipalDOK,
                MunicipalityCode = grouped.Key.MunicipalityCode,
                DOKStatus = grouped.Key.StatusConfirmationMunicipalDOK
            })
                                     .OrderByDescending(x => x.Count)
                                     .ToList();

            resultsNotSelected = (from cc in resultsNotSelected
                                  where !resultsSelected.Any(s => s.number == cc.number)
                                  select cc)
                                 .ToList();

            var results = resultsSelected.Union(resultsNotSelected).Distinct();

            var areas = param.Parameters.Where(p => p.Name == "area").Select(a => a.Value).ToList();

            if (areas.Any())
            {
                if (areas[0] != "Hele landet")
                {
                    var resultsNr = (from res in results
                                     join munici in _dbContext.Organizations on res.number equals munici.number
                                     select new { res.name, res.Count, res.number, munici.MunicipalityCode, munici.DateConfirmedMunicipalDOK, res.DOKStatus }).ToList();

                    results = (from r in resultsNr
                               where (from c in areas
                                      select c)
                               .Contains(r.MunicipalityCode) ||
                               (from c in areas
                                select c)
                               .Contains(r.MunicipalityCode.Substring(0, 2))

                               select new { r.name, r.Count, r.number, r.DateConfirmedMunicipalDOK, r.MunicipalityCode, r.DOKStatus }).ToList();
                }
            }


            foreach (var result in results.OrderByDescending(s => s.Count).ThenBy(ss => ss.name))
            {
                ReportResultData reportResultData = new ReportResultData();

                List <ReportResultDataValue> reportResultDataValues = new List <ReportResultDataValue>();

                reportResultData.Label          = result.name.ToString();
                reportResultData.TotalDataCount = total;

                ReportResultDataValue reportResultDataValue = new ReportResultDataValue();

                reportResultDataValue.Key   = "Det offentlige kartgrunnlaget";
                reportResultDataValue.Value = result.Count.ToString();

                reportResultDataValues.Add(reportResultDataValue);

                reportResultData.Values = reportResultDataValues;

                reportResult.Data.Add(reportResultData);
            }

            return(reportResult);
        }