Ejemplo n.º 1
0
        private void createChildControlsAndWireUpEvents()
        {
            captionTable          = TableOps.CreateUnderlyingTable();
            captionTable.CssClass = "ewfStandardDynamicTableCaption";
            captionTable.Visible  = false;
            var row = new TableRow();

            var captionCell = new TableCell();

            captionCell.Controls.Add(captionStack = ControlStack.Create(false));
            row.Cells.Add(captionCell);

            var actionLinksCell = new TableCell {
                CssClass = "ewfAddItemLink"
            };

            actionLinksCell.Controls.Add(actionLinkStack = ControlStack.Create(false));
            row.Cells.Add(actionLinksCell);

            captionTable.Rows.Add(row);
            Controls.Add(captionTable);

            table = TableOps.CreateUnderlyingTable();
            Controls.Add(table);

            PreRender += ewfTable_PreRender;
        }
        void ControlTreeDataLoader.LoadData()
        {
            if (dateModificationMethod == null)
            {
                throw new ApplicationException("In order to place this calendar on a page, you must call SetParameters before the end of LoadData.");
            }
            buildNavigationBox();

            // Begin drawing calendar
            var table = TableOps.CreateUnderlyingTable();

            table.Attributes["class"] = "ewfMonthView ewfMonthViewCalendar";
            base.Controls.Add(table);

            var headerRow = new TableRow();

            foreach (var day in Enum.GetValues(typeof(DayOfWeek)))
            {
                headerRow.Cells.Add(new TableCell {
                    Text = day.ToString(), CssClass = "commonHeader ewfDaysOfWeekHeader"
                });
            }
            table.Rows.Add(headerRow);

            var localDate      = IsTwoWeekCalendar ? date.WeekBeginDate() : new DateTime(date.Year, date.Month, 1).WeekBeginDate();
            var endDrawingDate = IsTwoWeekCalendar
                                                     ? localDate.AddDays(13)
                                                     : new DateTime(date.Year, date.Month, 1).AddDays(DateTime.DaysInMonth(date.Year, date.Month) - 1);

            do
            {
                var row = new TableRow();
                foreach (DayOfWeek dayOfWeek in Enum.GetValues(typeof(DayOfWeek)))
                {
                    var cell = new TableCell {
                        Text = " "
                    };
                    if (IsTwoWeekCalendar || localDate.Date.Month.CompareTo(date.Date.Month) == 0)
                    {
                        if (daysOfMonthToCells.ContainsKey(localDate))
                        {
                            cell = daysOfMonthToCells[localDate];
                        }

                        if (daysOfMonthToolTips.ContainsKey(localDate))
                        {
                            new ToolTip(daysOfMonthToolTips[localDate].Content, cell);
                        }
                    }
                    cell.Attributes.Add("class", localDate.CompareTo(DateTime.Now.Date) == 0 ? "ewfToday" : localDate.Month == date.Month ? "ewfDay" : "ewfDaySpacer");
                    cell.Controls.AddAt(0, new Paragraph(localDate.Day.ToString().GetLiteralControl())
                    {
                        CssClass = "dayLabel"
                    });
                    row.Cells.Add(cell);
                    localDate = localDate.AddDays(1);
                }
                table.Rows.Add(row);
            }while(localDate.CompareTo(endDrawingDate) <= 0);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a new instance of a Control Line with the given controls.
        /// </summary>
        public ControlLine(params Control[] controls)
        {
            var table = TableOps.CreateUnderlyingTable();

            table.Rows.Add(row = new TableRow());
            base.Controls.Add(table);
            AddControls(controls);
            VerticalAlignment = TableCellVerticalAlignment.NotSpecified;
        }
Ejemplo n.º 4
0
        private void ewfTable_PreRender(object sender, EventArgs e)
        {
            // NOTE: This should all move to ControlTreeDataLoader.LoadData, but it can't right now because so many pages add table rows from PreRender.
            TableOps.AlternateRowColors(table, rowSetups);

            // NOTE: We should be able to get rid of this row hiding when we port everything over to use AddAllDataToTable.
            var dataRowIndex = 0;

            for (var rowIndex = 0; rowIndex < rowSetups.Count; rowIndex++)
            {
                table.Rows[rowIndex].Visible = dataRowIndex++ < CurrentDataRowLimit;
            }
        }
        void ControlTreeDataLoader.LoadData()
        {
            if (hideIfEmpty && itemGroups.All(itemGroup => !itemGroup.Items.Any()))
            {
                Visible = false;
                return;
            }

            EwfTable.SetUpTableAndCaption(this, style, classes, caption, subCaption);

            var itemSetupLists = new[] { headItems }.Concat(itemGroups.Select(i => i.Items)).Select(i => i.Select(j => j.Setup.FieldOrItemSetup));
            var allItemSetups     = itemSetupLists.SelectMany(i => i).ToList();
            var columnWidthFactor = EwfTable.GetColumnWidthFactor(allItemSetups);

            foreach (var itemSetups in itemSetupLists.Where(i => i.Any()))
            {
                Controls.Add(new WebControl(HtmlTextWriterTag.Colgroup).AddControlsReturnThis(itemSetups.Select(i => EwfTable.GetColControl(i, columnWidthFactor))));
            }

            var fields = EwfTable.GetFields(specifiedFields, headItems, itemGroups.SelectMany(i => i.Items));
            var cellPlaceholderListsForItems = TableOps.BuildCellPlaceholderListsForItems(headItems.Concat(itemGroups.SelectMany(i => i.Items)).ToList(),
                                                                                          fields.Length);

            // Pivot the cell placeholders from column primary into row primary format.
            var cellPlaceholderListsForRows =
                Enumerable.Range(0, fields.Length).Select(
                    field => Enumerable.Range(0, allItemSetups.Count).Select(item => cellPlaceholderListsForItems[item][field]).ToList()).ToList();

            var headRows = TableOps.BuildRows(cellPlaceholderListsForRows.Take(firstDataFieldIndex).ToList(),
                                              fields.Select(i => i.FieldOrItemSetup).ToList().AsReadOnly(),
                                              null,
                                              allItemSetups.AsReadOnly(),
                                              allItemSetups.Count,
                                              true);
            var bodyRows = TableOps.BuildRows(cellPlaceholderListsForRows.Skip(firstDataFieldIndex).ToList(),
                                              fields.Select(i => i.FieldOrItemSetup).ToList().AsReadOnly(),
                                              false,
                                              allItemSetups.AsReadOnly(),
                                              headItems.Count,
                                              true);

            // We can't easily put the head fields in thead because we don't have a way of verifying that cells don't cross between head and data fields.
            Controls.Add(new WebControl(HtmlTextWriterTag.Tbody).AddControlsReturnThis(headRows.Concat(bodyRows)));

            EwfTable.AssertAtLeastOneCellPerField(fields, cellPlaceholderListsForItems);
        }
Ejemplo n.º 6
0
        private IEnumerable <Control> buildRows(
            List <EwfTableItem> items, EwfTableField[] fields, bool?useContrastForFirstRow, bool useHeadCells, Func <EwfTableCell> itemActionCheckBoxCellGetter,
            Func <EwfTableCell> itemReorderingCellGetter, List <EwfTableItem> allVisibleItems)
        {
            // Assert that the cells in the list of items are valid and store a data structure for below.
            var cellPlaceholderListsForRows = TableOps.BuildCellPlaceholderListsForItems(items, fields.Length);

            // NOTE: Be sure to take check box and reordering columns into account.
            var rows = TableOps.BuildRows(
                cellPlaceholderListsForRows,
                items.Select(i => i.Setup.FieldOrItemSetup).ToList().AsReadOnly(),
                useContrastForFirstRow,
                fields.Select(i => i.FieldOrItemSetup).ToList().AsReadOnly(),
                useHeadCells ? fields.Length : 0,
                false);

            allVisibleItems.AddRange(items);
            return(rows);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Adds a row to this table.
        /// </summary>
        public void AddRow(RowSetup rowSetup, params EwfTableCell[] cells)
        {
            // If SetUpColumns was never called, implicitly set up the columns based on this first row.
            if (columnSetups == null)
            {
                columnSetups = cells.Select(c => new ColumnSetup()).ToList();
            }

            rowSetups.Add(rowSetup);
            if (!rowSetup.IsHeader)
            {
                dataRowCount++;
            }

            var defaultCsvLine = cells.Select(cell => (cell as CellPlaceholder).SimpleText).ToList();

            if (rowSetup.CsvLine == null)
            {
                rowSetup.CsvLine = defaultCsvLine;
            }

            // Verify that this row has the right number of cells.
            try {
                if (cells.Sum(c => c.FieldSpan) + previousRowColumnSpans.Sum(rcSpan => rcSpan.ColumnSpan) != columnSetups.Count)
                {
                    throw new ApplicationException("Row to be added has the wrong number of cells.");
                }

                // Despite that it would make no sense to do this and all latest browsers will draw tables incorrectly when this happens, I cannot find official documentation
                // saying that it is wrong. NOTE: This check isn't as good as the logic we are going to add to EwfTableItemRemainingData (to ensure that the item has at
                // least one cell) because it doesn't catch a case like two cells that each have a row span greater than one and together span all columns.
                if (cells.Any(c => c.ItemSpan > 1 && c.FieldSpan == columnSetups.Count))
                {
                    throw new ApplicationException("Cell may not take up all columns and span multiple rows.");
                }
            }
            catch (ApplicationException e) {
                if (!AppTools.IsDevelopmentInstallation)
                {
                    TelemetryStatics.ReportError(e);
                }
                else
                {
                    throw;
                }
            }
            foreach (var rowColumnSpanPair in previousRowColumnSpans)
            {
                rowColumnSpanPair.RowSpan--;
            }

            previousRowColumnSpans =
                (previousRowColumnSpans.Where(rowSpan => rowSpan.RowSpan > 0)
                 .Concat(
                     cells.Where(c => c.ItemSpan != 1)
                     .Select(rowSpanCell => new RowColumnSpanPair {
                RowSpan = rowSpanCell.ItemSpan - 1, ColumnSpan = rowSpanCell.FieldSpan
            }))).ToList();

            var cellPlaceHolders = new List <CellPlaceholder>(cells);

            TableOps.DrawRow(table, rowSetup, cellPlaceHolders, columnSetups, false);
        }
Ejemplo n.º 8
0
        void ControlTreeDataLoader.LoadData()
        {
            if (hideIfEmpty && itemGroups.All(itemGroup => !itemGroup.Items.Any()))
            {
                Visible = false;
                return;
            }

            SetUpTableAndCaption(this, style, classes, caption, subCaption);

            var visibleItemGroupsAndItems = new List <KeyValuePair <EwfTableItemGroup, List <EwfTableItem> > >();

            foreach (var itemGroup in itemGroups)
            {
                var visibleItems = itemGroup.Items.Take(CurrentItemLimit - visibleItemGroupsAndItems.Sum(i => i.Value.Count)).Select(i => i());
                visibleItemGroupsAndItems.Add(new KeyValuePair <EwfTableItemGroup, List <EwfTableItem> >(itemGroup, visibleItems.ToList()));
                if (visibleItemGroupsAndItems.Sum(i => i.Value.Count) == CurrentItemLimit)
                {
                    break;
                }
            }

            var fields = GetFields(specifiedFields, headItems.AsReadOnly(), visibleItemGroupsAndItems.SelectMany(i => i.Value));

            if (!fields.Any())
            {
                fields = new EwfTableField().ToSingleElementArray();
            }

            addColumnSpecifications(fields);

            var allVisibleItems = new List <EwfTableItem>();

            var headRows =
                buildRows(
                    getItemLimitingAndGeneralActionsItem(fields.Length).Concat(getItemActionsItem(fields.Length)).ToList(),
                    Enumerable.Repeat(new EwfTableField(), fields.Length).ToArray(),
                    null,
                    false,
                    null,
                    null,
                    allVisibleItems).Concat(buildRows(headItems, fields, null, true, null, null, allVisibleItems)).ToArray();

            if (headRows.Any())
            {
                Controls.Add(new WebControl(HtmlTextWriterTag.Thead).AddControlsReturnThis(headRows));
            }

            for (var visibleGroupIndex = 0; visibleGroupIndex < visibleItemGroupsAndItems.Count; visibleGroupIndex += 1)
            {
                var groupAndItems = visibleItemGroupsAndItems[visibleGroupIndex];

                var groupHeadItems = new List <EwfTableItem>();
                // NOTE: Set up group-level general actions. EwfTableItemGroup.GetGroupHeadItem( int visibleItemsInGroup )
                // NOTE: Set up group-level check box selection (if enabled) and group-level check box actions (if they exist). Make sure all items in the group have identical lists. EwfTableItemGroup.GetGroupItemActionsItem()
                // NOTE: Check box actions should show an error if clicked and no items are selected; this caused confusion in M+Vision.
                // NOTE: Combine the above into one method that returns a list of items.

                var useContrastForFirstRow = visibleItemGroupsAndItems.Where((group, i) => i < visibleGroupIndex).Sum(i => i.Value.Count) % 2 == 1;
                Controls.Add(
                    new WebControl(HtmlTextWriterTag.Tbody).AddControlsReturnThis(
                        buildRows(groupHeadItems, Enumerable.Repeat(new EwfTableField(), fields.Length).ToArray(), null, true, null, null, allVisibleItems)
                        .Concat(buildRows(groupAndItems.Value, fields, useContrastForFirstRow, false, null, null, allVisibleItems))));
            }

            var itemCount = itemGroups.Sum(i => i.Items.Count);

            if (CurrentItemLimit < itemCount)
            {
                var nextLimit          = EnumTools.GetValues <DataRowLimit>().First(i => i > (DataRowLimit)CurrentItemLimit);
                var itemIncrementCount = Math.Min((int)nextLimit, itemCount) - CurrentItemLimit;
                var button             =
                    new PostBackButton(
                        PostBack.CreateFull(
                            id: PostBack.GetCompositeId(postBackIdBase, "showMore"),
                            firstModificationMethod: () => EwfPage.Instance.PageState.SetValue(this, itemLimitPageStateKey, (int)nextLimit)),
                        new TextActionControlStyle("Show " + itemIncrementCount + " more item" + (itemIncrementCount != 1 ? "s" : "")),
                        usesSubmitBehavior: false);
                var item        = new EwfTableItem(button.ToCell(new TableCellSetup(fieldSpan: fields.Length)));
                var useContrast = visibleItemGroupsAndItems.Sum(i => i.Value.Count) % 2 == 1;
                Controls.Add(
                    new WebControl(HtmlTextWriterTag.Tbody).AddControlsReturnThis(
                        buildRows(
                            item.ToSingleElementArray().ToList(),
                            Enumerable.Repeat(new EwfTableField(), fields.Length).ToArray(),
                            useContrast,
                            false,
                            null,
                            null,
                            allVisibleItems)));
            }

            // Assert that every visible item in the table has the same number of cells and store a data structure for below.
            var cellPlaceholderListsForItems = TableOps.BuildCellPlaceholderListsForItems(allVisibleItems, fields.Length);

            if (!disableEmptyFieldDetection)
            {
                AssertAtLeastOneCellPerField(fields, cellPlaceholderListsForItems);
            }
        }