Ejemplo n.º 1
0
        // NOTE: This row also needs to include general actions, on the right. Don't forget about Export to Excel.
        private EwfTableItem[] getItemLimitingAndGeneralActionsItem(int fieldCount)
        {
            if (defaultItemLimit == DataRowLimit.Unlimited)
            {
                return(new EwfTableItem[0]);
            }

            var itemCount = itemGroups.Sum(i => i.Items.Count);
            var cl        = new ControlLine((itemCount + " Item" + (itemCount != 1 ? "s" : "")).GetLiteralControl(), "".GetLiteralControl(), "Show:".GetLiteralControl());

            cl.AddControls(getItemLimitButton(DataRowLimit.Fifty));
            cl.AddControls(getItemLimitButton(DataRowLimit.FiveHundred));
            cl.AddControls(getItemLimitButton(DataRowLimit.Unlimited));
            return(new EwfTableItem(cl.ToCell(new TableCellSetup(fieldSpan: fieldCount))).ToSingleElementArray());
        }
Ejemplo n.º 2
0
        void ControlTreeDataLoader.LoadData()
        {
            var modifiedCaption = caption;

            // Display the caption and the sub caption.
            if (defaultDataRowLimit != DataRowLimit.Unlimited)
            {
                var formattedDataRowCount = dataRowCount.ToString("N0");
                if (caption.Length > 0)
                {
                    modifiedCaption += " (" + formattedDataRowCount + ")";
                }
                else
                {
                    modifiedCaption = formattedDataRowCount + " items";
                }
            }
            if (modifiedCaption.Length > 0)
            {
                captionTable.Visible = true;
                captionStack.AddControls(new Label {
                    Text = modifiedCaption, CssClass = "ewfCaption"
                });
            }
            if (subCaption.Length > 0)
            {
                captionTable.Visible = true;
                captionStack.AddText(subCaption);
            }

            // Row limiting
            if (defaultDataRowLimit != DataRowLimit.Unlimited)
            {
                captionStack.AddControls(
                    new ControlLine(
                        new LiteralControl("Show:"),
                        getDataRowLimitControl(DataRowLimit.Fifty),
                        getDataRowLimitControl(DataRowLimit.FiveHundred),
                        getDataRowLimitControl(DataRowLimit.Unlimited)));
            }

            // Excel export
            if (allowExportToExcel)
            {
                actionLinks.Add(
                    new ActionButtonSetup(
                        "Export to Excel",
                        new PostBackButton(PostBack.CreateFull(id: PostBack.GetCompositeId(PostBackIdBase, "excel"), actionGetter: ExportToExcel))));
            }

            // Action links
            foreach (var actionLink in actionLinks)
            {
                captionTable.Visible = true;
                actionLinkStack.AddControls(actionLink.BuildButton(text => new TextActionControlStyle(text), false));
            }

            // Selected row actions
            foreach (var button in selectedRowActionButtonsToAdd)
            {
                captionTable.Visible = true;
                actionLinkStack.AddControls(button);
            }

            foreach (var buttonToMethod in selectedRowDataModificationsToMethods)
            {
                var dataModification = buttonToMethod.Key;
                var method           = buttonToMethod.Value;
                dataModification.AddModificationMethod(
                    () => {
                    foreach (var rowSetup in rowSetups)
                    {
                        if (rowSetup.UniqueIdentifier != null &&
                            ((EwfCheckBox)rowSetup.UnderlyingTableRow.Cells[0].Controls[0]).IsCheckedInPostBack(
                                AppRequestState.Instance.EwfPageRequestState.PostBackValues))
                        {
                            method(DataAccessState.Current.PrimaryDatabaseConnection, rowSetup.UniqueIdentifier);
                        }
                    }
                });
            }

            if (selectedRowDataModificationsToMethods.Any())
            {
                foreach (var rowSetup in rowSetups)
                {
                    var cell = new TableCell
                    {
                        Width    = Unit.Percentage(5),
                        CssClass = EwfTable.CssElementCreator.AllCellAlignmentsClass.ConcatenateWithSpace("ewfNotClickable")
                    };
                    if (rowSetup.UniqueIdentifier != null)
                    {
                        var firstDm = selectedRowDataModificationsToMethods.First().Key;
                        var pb      = firstDm as PostBack;
                        cell.Controls.Add(new EwfCheckBox(false, postBack: pb ?? EwfPage.Instance.DataUpdatePostBack));
                    }
                    rowSetup.UnderlyingTableRow.Cells.AddAt(0, cell);
                }
            }

            // Reordering
            var filteredRowSetups = rowSetups.Where(rs => rs.RankId.HasValue).ToList();

            for (var i = 0; i < filteredRowSetups.Count; i++)
            {
                var previousRowSetup = (i == 0 ? null : filteredRowSetups[i - 1]);
                var rowSetup         = filteredRowSetups[i];
                var nextRowSetup     = ((i == filteredRowSetups.Count - 1) ? null : filteredRowSetups[i + 1]);

                var controlLine = new ControlLine(new Control[0]);
                if (previousRowSetup != null)
                {
                    var upButton =
                        new PostBackButton(
                            PostBack.CreateFull(
                                id: PostBack.GetCompositeId(PostBackIdBase, rowSetup.RankId.Value.ToString(), "up"),
                                firstModificationMethod: () => RankingMethods.SwapRanks(previousRowSetup.RankId.Value, rowSetup.RankId.Value)),
                            new ButtonActionControlStyle(@"/\", ButtonActionControlStyle.ButtonSize.ShrinkWrap),
                            usesSubmitBehavior: false);
                    controlLine.AddControls(upButton);
                }
                if (nextRowSetup != null)
                {
                    var downButton =
                        new PostBackButton(
                            PostBack.CreateFull(
                                id: PostBack.GetCompositeId(PostBackIdBase, rowSetup.RankId.Value.ToString(), "down"),
                                firstModificationMethod: () => RankingMethods.SwapRanks(rowSetup.RankId.Value, nextRowSetup.RankId.Value)),
                            new ButtonActionControlStyle(@"\/", ButtonActionControlStyle.ButtonSize.ShrinkWrap),
                            usesSubmitBehavior: false);
                    controlLine.AddControls(downButton);
                }

                // NOTE: What about rows that don't have a RankId? They need to have an empty cell so all rows have the same cell count.
                var cell = new TableCell
                {
                    Width    = Unit.Percentage(10),
                    CssClass = EwfTable.CssElementCreator.AllCellAlignmentsClass.ConcatenateWithSpace("ewfNotClickable")
                };
                cell.Controls.Add(controlLine);
                rowSetup.UnderlyingTableRow.Cells.Add(cell);
            }

            if (HideIfEmpty && !HasContentRows)
            {
                Visible = false;
            }
        }