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; } }
void ControlTreeDataLoader.LoadData() { FormState.ExecuteWithDataModificationsAndDefaultAction( dataModifications, () => { 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 ButtonSetup( "Export to Excel", behavior: new PostBackBehavior( postBack: PostBack.CreateFull(id: PostBack.GetCompositeId(PostBackIdBase, "excel"), actionGetter: ExportToExcel)))); } // Action links foreach (var actionLink in actionLinks) { captionTable.Visible = true; var actionComponent = actionLink.GetActionComponent( (text, icon) => new ButtonHyperlinkStyle(text, buttonSize: ButtonSize.ShrinkWrap, icon: icon), (text, icon) => new StandardButtonStyle(text, buttonSize: ButtonSize.ShrinkWrap, icon: icon)); if (actionComponent == null) { continue; } actionLinkStack.AddControls(new PlaceHolder().AddControlsReturnThis(actionComponent.ToCollection().GetControls())); } // Selected row actions foreach (var button in selectedRowActionButtonsToAdd) { captionTable.Visible = true; actionLinkStack.AddControls(new PlaceHolder().AddControlsReturnThis(button.ToCollection().GetControls())); } var checkedRowSetups = new HashSet <RowSetup>(); foreach (var buttonToMethod in selectedRowDataModificationsToMethods) { var dataModification = buttonToMethod.Key; var method = buttonToMethod.Value; dataModification.AddModificationMethod( () => { foreach (var rowSetup in rowSetups) { if (checkedRowSetups.Contains(rowSetup)) { method(rowSetup.UniqueIdentifier); } } }); } if (selectedRowDataModificationsToMethods.Any()) { foreach (var rowSetup in rowSetups) { var cell = new TableCell { Width = Unit.Percentage(5), CssClass = TableCssElementCreator.AllCellAlignmentsClass.ClassName.ConcatenateWithSpace("ewfAec") }; if (rowSetup.UniqueIdentifier != null) { cell.Controls.Add( new PlaceHolder().AddControlsReturnThis( FormState.ExecuteWithDataModificationsAndDefaultAction( selectedRowDataModificationsToMethods.Keys, () => new Checkbox( false, Enumerable.Empty <PhrasingComponent>().Materialize(), validationMethod: (postBackValue, validator) => { if (postBackValue.Value) { checkedRowSetups.Add(rowSetup); } }), formControlDefaultActionOverride: new SpecifiedValue <NonPostBackFormAction>(null)) .PageComponent.ToCollection() .GetControls())); } 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 EwfButton( new StandardButtonStyle(@"/\", ButtonSize.ShrinkWrap), behavior: new PostBackBehavior( postBack: PostBack.CreateFull( id: PostBack.GetCompositeId(PostBackIdBase, rowSetup.RankId.Value.ToString(), "up"), firstModificationMethod: () => RankingMethods.SwapRanks(previousRowSetup.RankId.Value, rowSetup.RankId.Value)))); controlLine.AddControls(new PlaceHolder().AddControlsReturnThis(upButton.ToCollection().GetControls())); } if (nextRowSetup != null) { var downButton = new EwfButton( new StandardButtonStyle(@"\/", ButtonSize.ShrinkWrap), behavior: new PostBackBehavior( postBack: PostBack.CreateFull( id: PostBack.GetCompositeId(PostBackIdBase, rowSetup.RankId.Value.ToString(), "down"), firstModificationMethod: () => RankingMethods.SwapRanks(rowSetup.RankId.Value, nextRowSetup.RankId.Value)))); controlLine.AddControls(new PlaceHolder().AddControlsReturnThis(downButton.ToCollection().GetControls())); } // 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 = TableCssElementCreator.AllCellAlignmentsClass.ClassName.ConcatenateWithSpace("ewfAec") }; cell.Controls.Add(controlLine); rowSetup.UnderlyingTableRow.Cells.Add(cell); } if (HideIfEmpty && !HasContentRows) { Visible = false; } }); }