#c# #report #rdlc
#c# #Сообщить #rdlc
Вопрос:
Объект, который я хочу установить в отчете
public class SurveyTemplateReportModel
{
public string Topic { get; set; }
public string Section { get; set; }
public string QuestionName { get; set; }
public string Question { get; set; }
public string Field { get; set; }
}
Структура отчета
**Topic 1**
**Section 1**
QuestionName 1.0
Question 1.0
Field 1.0
QuestionName 1.1
Question 1.1
Field 1.1
**Section 1.1**
QuestionName 1.1.0
Question 1.1.0
Field 1.1.0
QuestionName 1.1.1
Question 1.1.1
Field 1.1.1
**Section 2.0**
QuestionName 2.0.0
Question 2.0.0
Field 2.0.0
QuestionName 2.0.1
Question 2.0.1
Field 2.0.1
QuestionName 2.0.2
Question 2.0.2
Field 2.0.2
Кто-нибудь может помочь мне настроить такой отчет
Ответ №1:
код c # будет выглядеть следующим образом :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
List<SurveyTemplateReportModel> model = new List<SurveyTemplateReportModel>() {
new SurveyTemplateReportModel() { Topic = "1" , Section = "1" , QuestionName = "1.0", Question = "1.0", Field = "1.0"},
new SurveyTemplateReportModel() { Topic = "1" , Section = "1" , QuestionName = "1.1", Question = "1.1", Field = "1.1"},
new SurveyTemplateReportModel() { Topic = "1" , Section = "1.1" , QuestionName = "1.1.0", Question = "1.1.0", Field = "1.1.0"},
new SurveyTemplateReportModel() { Topic = "1" , Section = "1" , QuestionName = "1.1.1", Question = "1.1.1", Field = "1.1.1"},
new SurveyTemplateReportModel() { Topic = "1" , Section = "2" , QuestionName = "2.0.0", Question = "2.0.0", Field = "2.0.0"},
new SurveyTemplateReportModel() { Topic = "1" , Section = "2" , QuestionName = "2.0.1", Question = "2.0.1", Field = "2.0.1"},
new SurveyTemplateReportModel() { Topic = "1" , Section = "2" , QuestionName = "2.0.2", Question = "2.0.2", Field = "2.0.2"}
};
foreach (var topic in model.GroupBy(x => x.Topic))
{
Console.WriteLine("**Topic {0}**", topic.Key);
foreach (var section in topic.GroupBy(x => x.Section))
{
Console.WriteLine("{0}**Section {1}**", new string(' ', 5),section.Key);
foreach (SurveyTemplateReportModel survey in section)
{
Console.WriteLine("{0}QuestionName = {1}, Question = {2}, Field = {3}", new string(' ', 10), survey.QuestionName, survey.Question, survey.Field);
}
}
}
Console.ReadLine();
}
}
public class SurveyTemplateReportModel
{
public string Topic { get; set; }
public string Section { get; set; }
public string QuestionName { get; set; }
public string Question { get; set; }
public string Field { get; set; }
}
}