private void GenerateGroupSummary(GridViewGroup g, GridViewRow row) { int colIndex; object colValue; if (!HasAutoSummary(g.Summaries) && !HasSupressGroup()) { return; } // Inserts a new row GridViewRow newRow = InsertGridRow(row, g); foreach (GridViewSummary s in g.Summaries) { if (s.Automatic) { colIndex = GetVisibleColumnIndex(s.Column); colIndex = ResolveCellIndex(newRow, colIndex); newRow.Cells[colIndex].Text = this.GetFormatedString(s.FormatString, this.GetColumnFormat(GetColumnIndex(s.Column)), s.Value); } } // If it is a supress group must set the grouped values in the cells // of the inserted row if (g.IsSupressGroup) { for (int i = 0; i < g.Columns.Length; i++) { colValue = g.ActualValues[i]; if (colValue != null) { colIndex = GetVisibleColumnIndex(g.Columns[i]); colIndex = ResolveCellIndex(newRow, colIndex); newRow.Cells[colIndex].Text = colValue.ToString(); } } } // Triggers event GroupSummary if (GroupSummary != null) { GroupSummary(g.Name, g.ActualValues, newRow); } }
public GridViewSummary RegisterSummary(string column, SummaryOperation operation, string groupName) { if (operation == SummaryOperation.Custom) { throw new Exception(USE_ADEQUATE_METHOD_TO_REGISTER_THE_SUMMARY); } GridViewGroup group = FindGroupByName(groupName); if (group == null) { throw new Exception(String.Format(GROUP_NOT_FOUND, groupName)); } // TO DO: Perform column validation... GridViewSummary s = new GridViewSummary(column, operation, group); group.AddSummary(s); return(s); }
private bool ColumnHasSummary(string column, GridViewGroup g) { List <GridViewSummary> list; if (g == null) { list = this.mGeneralSummaries; } else { list = g.Summaries; } foreach (GridViewSummary s in list) { if (column.ToLower() == s.Column.ToLower()) { return(true); } } return(false); }
private bool ColumnHasSummary(int colindex, GridViewGroup g) { List <GridViewSummary> list; string column = this.GetDataFieldName(mGrid.Columns[colindex]); if (g == null) { list = this.mGeneralSummaries; } else { list = g.Summaries; } foreach (GridViewSummary s in list) { if (column.ToLower() == s.Column.ToLower()) { return(true); } } return(false); }
public GridViewSummary(string col, CustomSummaryOperation op, SummaryResultMethod getResult, GridViewGroup grp) : this(col, grp) { this.Operation = SummaryOperation.Custom; this.CustomOperation = op; this.GetSummaryMethod = getResult; }
/// <summary> /// Inserts a grid row. Only cells required for the summary results /// will be created (except if GenerateAllCellsOnSummaryRow is true). /// The group will be checked for columns with summary /// </summary> /// <param name="beforeRow"></param> /// <param name="g"></param> /// <returns></returns> private GridViewRow InsertGridRow(GridViewRow beforeRow, GridViewGroup g) { int colspan; TableCell cell; TableCell[] tcArray; int visibleColumns = this.GetVisibleColumnCount(); Table tbl = (Table)mGrid.Controls[0]; int newRowIndex = tbl.Rows.GetRowIndex(beforeRow); GridViewRow newRow = new GridViewRow(newRowIndex, newRowIndex, DataControlRowType.DataRow, DataControlRowState.Normal); if (g != null && (g.IsSupressGroup || g.GenerateAllCellsOnSummaryRow)) { // Create all the table cells tcArray = new TableCell[visibleColumns]; for (int i = 0; i < visibleColumns; i++) { cell = new TableCell(); cell.ApplyStyle(mGrid.Columns[GetRealIndexFromVisibleColumnIndex(i)].ItemStyle); cell.Text = " "; tcArray[i] = cell; } } else { // Create only the required table cells colspan = 0; List <TableCell> tcc = new List <TableCell>(); for (int i = 0; i < mGrid.Columns.Count; i++) { if (ColumnHasSummary(i, g)) { if (colspan > 0) { cell = new TableCell(); cell.Text = " "; cell.ColumnSpan = colspan; tcc.Add(cell); colspan = 0; } // insert table cell and copy the style cell = new TableCell(); cell.ApplyStyle(mGrid.Columns[i].ItemStyle); tcc.Add(cell); } else if (mGrid.Columns[i].Visible) { // A visible column that will have no cell because has // no summary. So we increase the colspan... colspan++; } } if (colspan > 0) { cell = new TableCell(); cell.Text = " "; cell.ColumnSpan = colspan; tcc.Add(cell); colspan = 0; } tcArray = new TableCell[tcc.Count]; tcc.CopyTo(tcArray); } newRow.Cells.AddRange(tcArray); tbl.Controls.AddAt(newRowIndex, newRow); return(newRow); }