コード例 #1
0
        private void LoadSummaryReport()
        {
            var report = Db.Context.Respondents.ToList();

            if (cbYear.SelectedIndex != 0)
            {
                var year = int.Parse(years[cbYear.SelectedIndex]);
                report = report.Where(t => t.Schedule.Date.Year == year).ToList();
            }

            var items = new List <int>()
            {
                report.Count(t => t.Gender == "M"),
                report.Count(t => t.Gender == "F"),
                report.Count(t => t.Age >= 18 && t.Age <= 24),
                report.Count(t => t.Age >= 25 && t.Age <= 39),
                report.Count(t => t.Age >= 40 && t.Age <= 59),
                report.Count(t => t.Age >= 60),
                report.Count(t => t.CabinType == "Economy"),
                report.Count(t => t.CabinType == "Business"),
                report.Count(t => t.CabinType == "First Class"),
                report.Count(t => t.Arrival == "AUH"),
                report.Count(t => t.Arrival == "BAH"),
                report.Count(t => t.Arrival == "DOH"),
                report.Count(t => t.Arrival == "RUH"),
                report.Count(t => t.Arrival == "CAI")
            };

            SurveyDataSet.SurveyDataTable dt = new SurveyDataSet.SurveyDataTable();
            dt.AddSurveyRow("", "", 0, items.Sum(), items[0], items[1], items[2], items[3], items[4], items[5], items[6], items[7], items[8], items[9], items[10], items[11], items[12], items[13]);

            ReportDataSource rdsByDate = new ReportDataSource();
            SurveyDataSet    dataset   = new SurveyDataSet();

            dataset.BeginInit();

            rdsByDate.Name  = "DataSet1";
            rdsByDate.Value = dt;
            this.rvSummaryReport.LocalReport.DataSources.Clear();
            this.rvSummaryReport.LocalReport.DataSources.Add(rdsByDate);
            this.rvSummaryReport.LocalReport.ReportPath = "../../Model/SurveySummaryReport.rdlc";

            dataset.EndInit();

            rvSummaryReport.LocalReport.SetParameters(new ReportParameter("SampleSize", $"Sample size: {report.Count}"));
            rvSummaryReport.LocalReport.SetParameters(new ReportParameter("Year", $"Time: {years[cbYear.SelectedIndex]}"));

            rvSummaryReport.RefreshReport();
        }
コード例 #2
0
        private void LoadDetailReport()
        {
            SetParameterForDetailReport();

            var surveys = Db.Context.Surveys.ToList();

            if (cbTimePeriod.SelectedIndex != 0)
            {
                var date = DateTime.Parse(times[cbTimePeriod.SelectedIndex]);
                surveys = surveys.Where(t => t.Respondent.Schedule.Date.Month == date.Month && t.Respondent.Schedule.Date.Year == date.Year).ToList();
            }

            if (chbGender.IsChecked.Value && cbGender.SelectedIndex != 0)
            {
                surveys = surveys.Where(t => t.Respondent.Gender != null).ToList();
            }
            if (chbAge.IsChecked.Value && cbAge.SelectedIndex != 0)
            {
                surveys = surveys.Where(t => t.Respondent.Age >= 18).ToList();
            }

            if (chbGender.IsChecked.Value && male == 0)
            {
                surveys = surveys.Where(t => !(t.Respondent.Gender == "M")).ToList();
            }
            if (chbGender.IsChecked.Value && female == 0)
            {
                surveys = surveys.Where(t => !(t.Respondent.Gender == "F")).ToList();
            }

            if (chbAge.IsChecked.Value && age18 == 0)
            {
                surveys = surveys.Where(t => !(t.Respondent.Age >= 18 && t.Respondent.Age <= 24)).ToList();
            }
            if (chbAge.IsChecked.Value && age25 == 0)
            {
                surveys = surveys.Where(t => !(t.Respondent.Age >= 25 && t.Respondent.Age <= 39)).ToList();
            }
            if (chbAge.IsChecked.Value && age40 == 0)
            {
                surveys = surveys.Where(t => !(t.Respondent.Age >= 40 && t.Respondent.Age <= 59)).ToList();
            }
            if (chbAge.IsChecked.Value && age60 == 0)
            {
                surveys = surveys.Where(t => !(t.Respondent.Age >= 60)).ToList();
            }

            SurveyDataSet.SurveyDataTable dt = new SurveyDataSet.SurveyDataTable();
            foreach (var ques in Db.Context.Questions.ToList())
            {
                foreach (var ans in Db.Context.Answers.Where(t => t.AnswerId != 0).ToList())
                {
                    var report = surveys.Where(t => t.AnswerId == ans.AnswerId && t.QuestionId == ques.QuestionId).ToList();
                    var items  = new List <int>()
                    {
                        report.Count(t => t.Respondent.Gender == "M") * male,
                        report.Count(t => t.Respondent.Gender == "F") * female,
                        report.Count(t => t.Respondent.Age >= 18 && t.Respondent.Age <= 24) * age18,
                        report.Count(t => t.Respondent.Age >= 25 && t.Respondent.Age <= 39) * age25,
                        report.Count(t => t.Respondent.Age >= 40 && t.Respondent.Age <= 59) * age40,
                        report.Count(t => t.Respondent.Age >= 60) * age60,
                        report.Count(t => t.Respondent.CabinType == "Economy"),
                        report.Count(t => t.Respondent.CabinType == "Business"),
                        report.Count(t => t.Respondent.CabinType == "First Class"),
                        report.Count(t => t.Respondent.Arrival == "AUH"),
                        report.Count(t => t.Respondent.Arrival == "BAH"),
                        report.Count(t => t.Respondent.Arrival == "DOH"),
                        report.Count(t => t.Respondent.Arrival == "RUH"),
                        report.Count(t => t.Respondent.Arrival == "CAI")
                    };

                    dt.AddSurveyRow(ques.Text, ans.Text, ans.AnswerId, items.Sum(), items[0], items[1], items[2], items[3], items[4], items[5], items[6], items[7], items[8], items[9], items[10], items[11], items[12], items[13]);
                }
            }

            ReportDataSource rdsDetail = new ReportDataSource();
            SurveyDataSet    dataset   = new SurveyDataSet();

            dataset.BeginInit();

            rdsDetail.Name  = "DataSet1";
            rdsDetail.Value = dt;
            this.rvDetailReport.LocalReport.DataSources.Clear();
            this.rvDetailReport.LocalReport.DataSources.Add(rdsDetail);
            this.rvDetailReport.LocalReport.ReportPath = "../../Model/SurveyDetailReport.rdlc";

            dataset.EndInit();

            rvDetailReport.LocalReport.SetParameters(new ReportParameter("Male", male.ToString()));
            rvDetailReport.LocalReport.SetParameters(new ReportParameter("Female", female.ToString()));
            rvDetailReport.LocalReport.SetParameters(new ReportParameter("Age18", age18.ToString()));
            rvDetailReport.LocalReport.SetParameters(new ReportParameter("Age25", age25.ToString()));
            rvDetailReport.LocalReport.SetParameters(new ReportParameter("Age40", age40.ToString()));
            rvDetailReport.LocalReport.SetParameters(new ReportParameter("Age60", age60.ToString()));

            this.rvDetailReport.RefreshReport();
        }