private Tuple <Report, Crosstab> SetReportDetails(Report report) { var detail = new Telerik.Reporting.DetailSection(); detail.Name = "detail"; ReportStyles.SetReportDetailStyle(detail.Style); report.Items.Add(detail); var columnWidth = Unit.Cm(2); var columnHeight = Unit.Cm(0.7); var crosstab = new Crosstab(); crosstab.Width = reportWidth; crosstab.Name = "crosstab"; // crosstab.Height = report.PageSettings.PaperSize.Height / 2; detail.Items.Add(crosstab); for (int c = 0; c <= CrosstabReportReportDTO.Columns.Count - 1; c++) { foreach (var val in CrosstabReportReportDTO.Values) { crosstab.Body.Columns.Add(new Telerik.Reporting.TableBodyColumn(Telerik.Reporting.Drawing.Unit.Cm(2))); } } foreach (var val in CrosstabReportReportDTO.Values) { crosstab.Body.Columns.Add(new Telerik.Reporting.TableBodyColumn(Telerik.Reporting.Drawing.Unit.Cm(2))); } for (int r = 0; r <= CrosstabReportReportDTO.Rows.Count; r++) { crosstab.Body.Rows.Add(new Telerik.Reporting.TableBodyRow(Telerik.Reporting.Drawing.Unit.Cm(1))); } for (int c = 0; c <= crosstab.Body.Columns.Count - 1; c++) { for (int r = 0; r <= crosstab.Body.Rows.Count - 1; r++) { var mod = c % CrosstabReportReportDTO.Values.Count; Telerik.Reporting.TextBox textbox = new TextBox(); var val = CrosstabReportReportDTO.Values[mod]; textbox.Name = val.EntityListViewColumn.Alias + c.ToString() + r.ToString(); textbox.Width = columnWidth; textbox.Height = columnHeight; textbox.Value = string.Format("= {0}(Fields.{1})", val.ValueFunction.ToString(), val.EntityListViewColumn.RelativeColumnName); crosstab.Items.Add(textbox); crosstab.Body.SetCellContent(r, c, textbox); if (r == crosstab.Body.Rows.Count - 1) { ReportStyles.SetCrossTabRowHeader(textbox.Style); } else { if (c >= crosstab.Body.Columns.Count - CrosstabReportReportDTO.Values.Count) { ReportStyles.SetCrossTabRowHeader(textbox.Style); } else { if (c > CrosstabReportReportDTO.Values.Count - 1) { ReportStyles.SetCrossTabTotalRowColumnStyle(textbox.Style); } else { if (r > 0) { ReportStyles.SetCrossTabTotalRowColumnStyle(textbox.Style); } else { ReportStyles.SetCrossTabBodyTextboxStyle(textbox.Style); } } } } } } if (CrosstabReportReportDTO.Values.Count == 1) { for (int r = 0; r <= CrosstabReportReportDTO.Rows.Count - 1; r++) { var textboxCorner = new TextBox(); textboxCorner.Name = "corner" + r; textboxCorner.Width = columnWidth; textboxCorner.Height = columnHeight; textboxCorner.Value = CrosstabReportReportDTO.Rows[r].EntityListViewColumn.Alias; ReportStyles.SetCrossTabRowHeader(textboxCorner.Style); var rowspan = CrosstabReportReportDTO.Columns.Count; crosstab.Items.Add(textboxCorner); crosstab.Corner.SetCellContent(0, r, textboxCorner, rowspan, 1); } } else { var emptytextboxCorner = new TextBox(); emptytextboxCorner.Name = "corner"; emptytextboxCorner.Width = columnWidth; emptytextboxCorner.Height = columnHeight; emptytextboxCorner.Value = ""; ReportStyles.SetCrossTabEmptyCornerTextboxStyle(emptytextboxCorner.Style); crosstab.Items.Add(emptytextboxCorner); crosstab.Corner.SetCellContent(0, 0, emptytextboxCorner, CrosstabReportReportDTO.Columns.Count, CrosstabReportReportDTO.Rows.Count); for (int r = 0; r <= CrosstabReportReportDTO.Rows.Count - 1; r++) { var textboxCorner = new TextBox(); textboxCorner.Name = "corner" + r; textboxCorner.Width = columnWidth; textboxCorner.Height = columnHeight; textboxCorner.Value = CrosstabReportReportDTO.Rows[r].EntityListViewColumn.Alias; ReportStyles.SetCrossTabRowHeader(textboxCorner.Style); crosstab.Items.Add(textboxCorner); crosstab.Corner.SetCellContent(CrosstabReportReportDTO.Columns.Count, r, textboxCorner); } } TableGroup prevDataTableGroup = null; TableGroup prevTotalTableGroup = null; foreach (var item in CrosstabReportReportDTO.Columns.OrderByDescending(x => x.ID)) { var newDataTableGroup = new TableGroup(); newDataTableGroup.Name = "col" + item.EntityListViewColumn.Alias; newDataTableGroup.Groupings.Add(new Telerik.Reporting.Grouping(string.Format("= Fields.{0}", item.EntityListViewColumn.RelativeColumnName))); newDataTableGroup.Sortings.Add(new Telerik.Reporting.Sorting(string.Format("= Fields.{0}", item.EntityListViewColumn.RelativeColumnName), Telerik.Reporting.SortDirection.Asc)); var textbox = new TextBox(); textbox.Name = "colt" + item.EntityListViewColumn.Alias; textbox.Size = new Telerik.Reporting.Drawing.SizeU(Telerik.Reporting.Drawing.Unit.Inch(0.800000011920929D), Telerik.Reporting.Drawing.Unit.Inch(0.20000000298023224D)); textbox.Value = string.Format("= Fields.{0}", item.EntityListViewColumn.RelativeColumnName); ReportStyles.SetCrossTabRowColumnStyle(textbox.Style); crosstab.Items.Add(textbox); newDataTableGroup.ReportItem = textbox; var newTotalTableGroup = new TableGroup(); newTotalTableGroup.Name = "total_col_" + item.EntityListViewColumn.Alias; var totaltextbox = new TextBox(); totaltextbox.Name = "coltotal" + item.EntityListViewColumn.Alias; totaltextbox.Size = new Telerik.Reporting.Drawing.SizeU(Telerik.Reporting.Drawing.Unit.Inch(0.800000011920929D), Telerik.Reporting.Drawing.Unit.Inch(0.20000000298023224D)); totaltextbox.Value = "جمع"; ReportStyles.SetCrossTabRowHeader(totaltextbox.Style); crosstab.Items.Add(totaltextbox); newTotalTableGroup.ReportItem = totaltextbox; if (prevDataTableGroup != null) { newDataTableGroup.ChildGroups.Add(prevDataTableGroup); newDataTableGroup.ChildGroups.Add(prevTotalTableGroup); } else if (CrosstabReportReportDTO.Values.Count > 1) { //اولین گروهبندی..جزئی ترین..اگر مقادیر بیشتر از یکی باشند یک زیر گروه جدید برای هر مقدار ایجاد میشود var index = 0; foreach (var val in CrosstabReportReportDTO.Values) { var lastDataTableGroup = new TableGroup(); lastDataTableGroup.Name = "last" + val.EntityListViewColumn.Alias + index; var lasttextbox = new TextBox(); lasttextbox.Name = "lastTextbox" + val.EntityListViewColumn.Alias + index; lasttextbox.Size = new Telerik.Reporting.Drawing.SizeU(Telerik.Reporting.Drawing.Unit.Inch(0.800000011920929D), Telerik.Reporting.Drawing.Unit.Inch(0.20000000298023224D)); lasttextbox.Value = val.EntityListViewColumn.Alias; ReportStyles.SetCrossTabRowHeader(lasttextbox.Style); crosstab.Items.Add(lasttextbox); lastDataTableGroup.ReportItem = lasttextbox; newDataTableGroup.ChildGroups.Add(lastDataTableGroup); index++; } } if (prevDataTableGroup != null) { var index = 0; foreach (var val in CrosstabReportReportDTO.Values) { var lastTotalDataTableGroup = new TableGroup(); lastTotalDataTableGroup.Name = "lasttotal" + item.EntityListViewColumn.Alias + val.EntityListViewColumn.Alias + index; var lasttotaltextbox = new TextBox(); lasttotaltextbox.Name = "lasttotalTextbox" + item.EntityListViewColumn.Alias + val.EntityListViewColumn.Alias + index; lasttotaltextbox.Size = new Telerik.Reporting.Drawing.SizeU(Telerik.Reporting.Drawing.Unit.Inch(0.800000011920929D), Telerik.Reporting.Drawing.Unit.Inch(0.20000000298023224D)); lasttotaltextbox.Value = val.EntityListViewColumn.Alias; ReportStyles.SetCrossTabRowHeader(lasttotaltextbox.Style); crosstab.Items.Add(lasttotaltextbox); lastTotalDataTableGroup.ReportItem = lasttotaltextbox; newTotalTableGroup.ChildGroups.Add(lastTotalDataTableGroup); index++; } } else if (CrosstabReportReportDTO.Values.Count > 1) { //اولین گروهبندی تجمیعی..جزئی ترین..اگر مقادیر بیشتر از یکی باشند یک زیر گروه جدید برای هر مقدار ایجاد میشود var index = 0; foreach (var val in CrosstabReportReportDTO.Values) { var smallestGroup = new TableGroup(); smallestGroup.Name = "lasttotal" + item.EntityListViewColumn.Alias + val.EntityListViewColumn.Alias + index; var lasttotaltextbox = new TextBox(); lasttotaltextbox.Name = "lasttotalTextbox" + item.EntityListViewColumn.Alias + val.EntityListViewColumn.Alias + index; lasttotaltextbox.Size = new Telerik.Reporting.Drawing.SizeU(Telerik.Reporting.Drawing.Unit.Inch(0.800000011920929D), Telerik.Reporting.Drawing.Unit.Inch(0.20000000298023224D)); lasttotaltextbox.Value = val.EntityListViewColumn.Alias; ReportStyles.SetCrossTabRowHeader(lasttotaltextbox.Style); crosstab.Items.Add(lasttotaltextbox); smallestGroup.ReportItem = lasttotaltextbox; newTotalTableGroup.ChildGroups.Add(smallestGroup); index++; } } prevDataTableGroup = newDataTableGroup; prevTotalTableGroup = newTotalTableGroup; } crosstab.ColumnGroups.Add(prevDataTableGroup); crosstab.ColumnGroups.Add(prevTotalTableGroup); TableGroup prevRowDataTableGroup = null; TableGroup prevRowTotalTableGroup = null; foreach (var item in CrosstabReportReportDTO.Rows.OrderByDescending(x => x.ID)) { var newDataTableGroup = new TableGroup(); newDataTableGroup.Name = "row" + item.EntityListViewColumn.Alias; if (prevRowDataTableGroup != null) { newDataTableGroup.ChildGroups.Add(prevRowDataTableGroup); newDataTableGroup.ChildGroups.Add(prevRowTotalTableGroup); } var textbox = new TextBox(); textbox.Value = string.Format("= Fields.{0}", item.EntityListViewColumn.RelativeColumnName); textbox.Name = "rowt" + item.EntityListViewColumn.Alias; textbox.Size = new Telerik.Reporting.Drawing.SizeU(Telerik.Reporting.Drawing.Unit.Inch(0.800000011920929D), Telerik.Reporting.Drawing.Unit.Inch(0.20000000298023224D)); crosstab.Items.Add(textbox); ReportStyles.SetCrossTabRowColumnStyle(textbox.Style); newDataTableGroup.ReportItem = textbox; newDataTableGroup.Groupings.Add(new Telerik.Reporting.Grouping(string.Format("= Fields.{0}", item.EntityListViewColumn.RelativeColumnName))); newDataTableGroup.Sortings.Add(new Telerik.Reporting.Sorting(string.Format("= Fields.{0}", item.EntityListViewColumn.RelativeColumnName), Telerik.Reporting.SortDirection.Asc)); var newTotalTableGroup = new TableGroup(); newTotalTableGroup.Name = "total_row_" + item.EntityListViewColumn.Alias; var totaltextbox = new TextBox(); totaltextbox.Name = "totalrow" + item.EntityListViewColumn.Alias; totaltextbox.Size = new Telerik.Reporting.Drawing.SizeU(Telerik.Reporting.Drawing.Unit.Inch(0.800000011920929D), Telerik.Reporting.Drawing.Unit.Inch(0.20000000298023224D)); totaltextbox.Value = "جمع"; ReportStyles.SetCrossTabRowHeader(totaltextbox.Style); crosstab.Items.Add(totaltextbox); newTotalTableGroup.ReportItem = totaltextbox; prevRowDataTableGroup = newDataTableGroup; prevRowTotalTableGroup = newTotalTableGroup; } crosstab.RowGroups.Add(prevRowDataTableGroup); crosstab.RowGroups.Add(prevRowTotalTableGroup); return(new Tuple <Report, Crosstab>(report, crosstab)); }