private void FillRosterTable()
        {
            int eventId = RequestUtil.GetEventId(Request);
            int eventHc = DataModels.EventRoster.GetEventTotalParticipant(eventId);
            int eventCc = DataModels.EventRoster.GetEventTotalCarpoolCapacity(eventId);

            try
            {
                using (SqlDataReader reader = DataModels.EventRoster.GetReaderEventRoster(eventId))
                {
                    while (reader.Read())
                    {
                        TableCell nameCell = new TableCell();
                        nameCell.Text = HttpUtility.HtmlEncode(reader["name"].ToString());
                        nameCell.CssClass = "rosterTableCell";

                        TableCell partySizeCell = new TableCell();
                        partySizeCell.Text = reader["headCount"].ToString();
                        partySizeCell.CssClass = "rosterTableCell_CenterAlign";

                        TableCell vehicleCapCell = new TableCell();
                        vehicleCapCell.Text = reader["vehicleCap"].ToString();
                        vehicleCapCell.CssClass = "rosterTableCell_CenterAlign";

                        TableRow row = new TableRow();
                        row.Cells.Add(nameCell);
                        row.Cells.Add(partySizeCell);
                        row.Cells.Add(vehicleCapCell);
                        RosterTable.Rows.Add(row);
                    }
                }

                //Table Footer
                TableFooterRow footerRow = new TableFooterRow();
                TableCell c1 = new TableCell();
                c1.Text = "Total";
                c1.CssClass = "rosterTableFooterCell";
                footerRow.Cells.Add(c1);
                TableCell c2 = new TableCell();
                c2.Text = eventHc.ToString();
                footerRow.Cells.Add(c2);
                c2.CssClass = "rosterTableFooterCell_CenterAlign";
                TableCell c3 = new TableCell();
                c3.Text = eventCc.ToString();
                footerRow.Cells.Add(c3);
                c3.CssClass = "rosterTableFooterCell_CenterAlign";

                RosterTable.Rows.Add(footerRow);

            }
            catch (Exception)
            {
                //TODO:Display and log exception.
            }
        }
Пример #2
0
        public static Table HtmlTable(IDataReader rd, string title = null, int? maxrows = null)
        {
            var pctnames = new List<string> {"pct", "percent"};
            var t = new Table();
            t.Attributes.Add("class", "table table-striped");
            if (title.HasValue())
            {
                var c = new TableHeaderCell
                {
                    ColumnSpan = rd.FieldCount,
                    Text = title,
                };
                c.Style.Add(HtmlTextWriterStyle.TextAlign, "center");
                var r = new TableHeaderRow {TableSection = TableRowSection.TableHeader};
                r.Cells.Add(c);
                t.Rows.Add(r);
            }
            var h = new TableHeaderRow {TableSection = TableRowSection.TableHeader};
            for (var i = 0; i < rd.FieldCount; i++)
            {
                var typ = rd.GetDataTypeName(i);
                var nam = rd.GetName(i).ToLower();
                var align = HorizontalAlign.NotSet;
                switch (typ.ToLower())
                {
                    case "decimal":
                        align = HorizontalAlign.Right;
                        break;
                    case "int":
                        if (nam != "Year" && !nam.EndsWith("id") && !nam.EndsWith("id2"))
                            align = HorizontalAlign.Right;
                        break;
                }
                h.Cells.Add(new TableHeaderCell
                {
                    Text = rd.GetName(i),
                    HorizontalAlign = align
                });
            }
            t.Rows.Add(h);
            var rn = 0;
            while (rd.Read())
            {
                rn++;
                if (maxrows.HasValue && rn > maxrows)
                    break;
                var r = new TableRow();
                for (var i = 0; i < rd.FieldCount; i++)
                {
                    var typ = rd.GetDataTypeName(i);
                    var nam = rd.GetName(i).ToLower();
                    string s;
                    var align = HorizontalAlign.NotSet;

                    switch (typ.ToLower())
                    {
                        case "decimal":
                            var dec = rd[i].ToNullableDecimal();
                            s = StartsEndsWith(pctnames, nam)
                                ? dec.ToString2("N1", "%")
                                : dec.ToString2("c");
                            align = HorizontalAlign.Right;
                            break;
                        case "real":
                        case "float":
                            var dbl = rd[i].ToNullableDouble();
                            s = StartsEndsWith(pctnames, nam)
                                ? dbl.ToString2("N1", "%")
                                : dbl.ToString2("N1");
                            align = HorizontalAlign.Right;
                            break;
                        case "date":
                        case "datetime":
                            var dt = rd[i].ToNullableDate();
                            if (dt.HasValue && dt.Value.Date != dt.Value)
                                s = dt.FormatDateTime();
                            else
                                s = dt.FormatDate();
                            break;
                        case "int":
                            var ii = rd[i].ToNullableInt();
                            if (nam.Equal("peopleid") || nam.Equal("spouseid"))
                                s = $"<a href='/Person2/{ii}' target='Person'>{ii}</a>";
                            else if (nam.Equal("organizationid") || nam.EndsWith("orgid"))
                                s = $"<a href='/Org/{ii}' target='Organization'>{ii}</a>";
                            else if (nam.EndsWith("id") || nam.EndsWith("id2") || nam.Equal("Year"))
                                s = ii.ToString();
                            else
                            {
                                s = ii.ToString2("N0");
                                align = HorizontalAlign.Right;
                            }
                            break;
                        default:
                            s = rd[i].ToString();
                            if (s == "Total")
                                s = $"<strong>{s}</strong>";
                            break;
                    }
                    r.Cells.Add(new TableCell()
                    {
                        Text = s,
                        HorizontalAlign = align,
                    });
                }
                t.Rows.Add(r);
            }
            var rowcount = $"Count = {rn} rows";
            if (maxrows.HasValue && rn > maxrows)
                rowcount = $"Displaying {maxrows} of {rn} rows";
            var tc = new TableCell()
            {
                ColumnSpan = rd.FieldCount,
                Text = rowcount,
            };
            var tr = new TableFooterRow();
            tr.Cells.Add(tc);
            t.Rows.Add(tr);
            return t;
        }