1: public static class TableCreator
2: {
3: private static double columnWidth = 0.64;
4: private static double rowHeight = 0.14;
5: private static double HeaderWidth = 1.00;
6:
7:
8: public static Telerik.Reporting.Table GetTableObject(List<Product> _source)
9: {
10: Telerik.Reporting.Table ProductTable = new Telerik.Reporting.Table();
11: for(int col = 0; col < _source.GroupBy(d => d.Date)
12: .Select(l => l.Key).Count(); col++) // add columns based on number of periods
13: {
14: Telerik.Reporting.TableGroup tg = new Telerik.Reporting.TableGroup();
15: tg.Groupings.AddRange(new Telerik.Reporting.Data.Grouping[]
16: { new Telerik.Reporting.Data.Grouping() });
17: ProductTable.ColumnGroups.Add(tg);
18: ProductTable.Body.Columns.Add( new Telerik.Reporting.TableBodyColumn
19: (Telerik.Reporting.Drawing.Unit.Inch(columnWidth)));
20: }
21:
22: int rowCounter = 1; // Modified
23: int columnCounter = 0;
24:
25: #region CustomHeader
26: int headerColumnCounter = 0;
27: ProductTable.Body.Rows.Add(new
28: TableBodyRow(Telerik.Reporting.Drawing.Unit.Inch(rowHeight)));
29: Telerik.Reporting.TextBox HeadRowNameC = new Telerik.Reporting.TextBox
30: { Value = "Date",
31: Size = new Telerik.Reporting.Drawing.SizeU(
32: Telerik.Reporting.Drawing.Unit.Inch(HeaderWidth),
33: Telerik.Reporting.Drawing.Unit.Inch(rowHeight)) };
34: TableGroup tgItemH = new TableGroup { ReportItem = HeadRowNameC };
35: ProductTable.RowGroups.Add(tgItemH);
36: foreach (DateTime day in _source.GroupBy(d => d.Date).Select(l => l.Key))
37: {
38: Telerik.Reporting.TextBox textboxh = new Telerik.Reporting.TextBox
39: { Value = day.ToString("MMM, yyyy"),
40: Size = new SizeU(Unit.Inch(columnWidth), Unit.Inch(rowHeight)) };
41: textboxh.Style.Font.Style = System.Drawing.FontStyle.Bold;
42: textboxh.Style.Font.Size = new Unit(8, UnitType.Point);
43: ProductTable.Body.SetCellContent(0, headerColumnCounter, textboxh);
44: headerColumnCounter++;
45: }
46: #endregion
47:
48: foreach (string prod in _source.GroupBy(pr => pr.ProductName.ToString())
49: .Select(h => h.Key))
50: {
51: ProductTable.Body.Rows.Add(new TableBodyRow
52: (Telerik.Reporting.Drawing.Unit.Inch(rowHeight)));
53: Telerik.Reporting.TextBox HeadRowName = new Telerik.Reporting.TextBox
54: { Value = prod.ToString(),
55: Size = new Telerik.Reporting.Drawing.SizeU(
56: Telerik.Reporting.Drawing.Unit
57: .Inch(HeaderWidth),
58: Telerik.Reporting.Drawing.Unit.Inch(rowHeight)) };
59: TableGroup tgItem = new TableGroup { ReportItem = HeadRowName };
60: ProductTable.RowGroups.Add(tgItem);
61: columnCounter = 0;
62: foreach (DateTime day in _source.GroupBy(d => d.Date).Select(l => l.Key))
63: {
64:
65: Telerik.Reporting.TextBox textbox = new Telerik.Reporting.TextBox
66: { Value = _source.Where(w => w.Date == day && w.ProductName == prod)
67: .Select(v => v.sale).FirstOrDefault().ToString(),
68: Size = new SizeU(Unit.Inch(columnWidth), Unit.Inch(rowHeight)) };
69: ProductTable.Body.SetCellContent(rowCounter, columnCounter, textbox);
70: columnCounter++;
71: }
72: rowCounter++;
73: }
74: return ProductTable;
75: }
76: }