public static void AddSpinEditColumn( this GridView gridView, string fieldName, string caption, int width, bool isAllowEdit = true, string formatString = "#,###0", SummaryItemType summaryType = SummaryItemType.None, string summaryFormat = "", KeyEventHandler keyDown = null) { RepositoryItemSpinEdit itemCtrl = new RepositoryItemSpinEdit(); itemCtrl.DisplayFormat.FormatString = formatString; itemCtrl.DisplayFormat.FormatType = FormatType.Custom; itemCtrl.EditFormat.FormatString = formatString; itemCtrl.EditFormat.FormatType = FormatType.Custom; itemCtrl.EditMask = formatString; GridColumnSummaryItem summaryItem = new GridColumnSummaryItem(); if (summaryType != SummaryItemType.None) { summaryFormat = string.IsNullOrEmpty(summaryFormat) ? "{0: " + formatString + "}" : summaryFormat; summaryItem = new GridColumnSummaryItem(summaryType, fieldName, summaryFormat); } if (keyDown != null) { itemCtrl.KeyDown += new KeyEventHandler(keyDown); } gridView.AddColumn(fieldName, caption, width, isAllowEdit, itemCtrl: itemCtrl, summaryItem: summaryItem); }
public ASPxSummaryItemCollection <TModel> Add <TValue>(SummaryItemType summaryItemType, Expression <Func <TModel, TValue> > expression, Action <ASPxSummaryItem> setColumn) { var metaData = ModelMetadata.FromLambdaExpression(expression, new ViewDataDictionary <TModel>()); setColumn(SummaryCollection.Add(summaryItemType, metaData.PropertyName)); return(this); }
protected SummaryItemType GetSummaryType(string type) { var summaryType = new SummaryItemType(); switch (type) { case "Min": summaryType = SummaryItemType.Min; break; case "Sum": summaryType = SummaryItemType.Sum; break; case "Average": summaryType = SummaryItemType.Average; break; case "Max": summaryType = SummaryItemType.Max; break; case "Count": summaryType = SummaryItemType.Count; break; case "None": summaryType = SummaryItemType.None; break; } return(summaryType); }
private void CreateTotal(string fieldName, SummaryItemType summaryType) { TreeListSummaryItem total = new TreeListSummaryItem() { FieldName = fieldName, SummaryType = summaryType, ShowInColumn = fieldName }; treeListControl1.TotalSummary.Add(total); }
protected void gvProducts_DataBinding(object sender, EventArgs e) { ASPxGridView gridView = sender as ASPxGridView; gridView.TotalSummary.Clear(); foreach (string fieldName in gridSummaries.Keys) { SummaryItemType type = gridSummaries[fieldName]; gridView.TotalSummary.Add(type, fieldName); } }
private static BandedGridColumn CreateBandedGridColumn(bool readOnly, int rowIndex, string caption, string fieldName, UnboundColumnType unboundColumnType, SummaryItemType summaryItemType, HorzAlignment headerAlignment, object tag, int?minWidth) { var bandedGridColumn = new BandedGridColumn(); bandedGridColumn.Caption = caption; bandedGridColumn.DisplayFormat.FormatString = ColumnFormat; bandedGridColumn.DisplayFormat.FormatType = FormatType.Numeric; bandedGridColumn.FieldName = fieldName; bandedGridColumn.Name = "col" + fieldName; bandedGridColumn.Tag = tag; bandedGridColumn.OptionsColumn.AllowSort = DefaultBoolean.False; bandedGridColumn.OptionsColumn.ShowInCustomizationForm = false; bandedGridColumn.OptionsFilter.AllowFilter = false; bandedGridColumn.OptionsColumn.AllowEdit = !readOnly; bandedGridColumn.OptionsColumn.ReadOnly = readOnly; bandedGridColumn.OptionsColumn.AllowFocus = !readOnly; bandedGridColumn.AppearanceHeader.Options.UseTextOptions = true; bandedGridColumn.AppearanceHeader.TextOptions.HAlignment = headerAlignment; if (minWidth.HasValue) { bandedGridColumn.MinWidth = minWidth.Value; } bandedGridColumn.RowIndex = rowIndex; if (summaryItemType != SummaryItemType.None) { bandedGridColumn.Summary.AddRange(new GridSummaryItem[] { new GridColumnSummaryItem(summaryItemType, fieldName, SummaryFormat) }); } bandedGridColumn.Visible = true; bandedGridColumn.UnboundType = unboundColumnType; bandedGridColumn.Width = InitialColumnWidth; return(bandedGridColumn); }
/// <summary> /// 設定column Summary (如果沒有該column也不會出錯) /// </summary> /// <param name="gv"></param> /// <param name="showColFieldName">要在哪個欄位顯示Summary Value</param> /// <param name="summaryFieldName">要Summary 哪個欄位</param> /// <param name="DisplayFormat"></param> /// <param name="summaryItemType"></param> public static void SetGridSummary(this DevExpress.XtraGrid.Views.Grid.GridView gv, string showColFieldName, string summaryFieldName, string DisplayFormat, SummaryItemType summaryItemType) { if (gv.Columns[showColFieldName] != null && gv.Columns[summaryFieldName] != null) { GridColumnSummaryItem columnSummary = new GridColumnSummaryItem(); columnSummary.FieldName = summaryFieldName; columnSummary.SummaryType = summaryItemType; columnSummary.DisplayFormat = DisplayFormat; gv.Columns[showColFieldName].Summary.Add(columnSummary); } }
/// <summary> /// Set group footer summary /// </summary> /// <param name="summaryType"></param> /// <param name="colNames"></param> public void SetGroupFooterSummary(SummaryItemType summaryType, params string[] colNames) { defaultView.OptionsView.GroupFooterShowMode = GroupFooterShowMode.VisibleAlways; defaultView.GroupSummary.Clear(); foreach (string col in colNames) { GridGroupSummaryItem item = new GridGroupSummaryItem(); item.FieldName = col; item.ShowInGroupColumnFooter = defaultView.Columns[col]; item.SummaryType = summaryType; item.DisplayFormat = "{0:n2}"; defaultView.GroupSummary.Add(item); } }
public static void AddAdvBandedGridGroupSummaries(this GridBand gridBand, int?rowIndex, SummaryItemType summaryType) { Debug.Assert(gridBand != null && gridBand.View != null && gridBand.View.GroupSummary != null, "gridBand == null || gridBand.View == null || gridBand.View.GroupSummary==null"); if (gridBand == null || gridBand.View == null || gridBand.View.GroupSummary == null) { return; } gridBand.View.BeginDataUpdate(); try { var groupSummaryList = new List <GridSummaryItem>(); for (var i = 0; i < gridBand.Columns.Count; i++) { if (rowIndex.HasValue && gridBand.Columns[i].RowIndex != rowIndex.Value) { continue; } var groupSummaryItem = new GridGroupSummaryItem(summaryType, gridBand.Columns[i].FieldName, gridBand.Columns[i], "{0:n0}"); groupSummaryList.Add(groupSummaryItem); } gridBand.View.GroupSummary.AddRange(groupSummaryList.ToArray()); } catch (Exception ex) { throw ex; } finally { gridBand.View.EndDataUpdate(); } }
/// <summary> /// 设定列的汇总信息 /// <para>eg: gridView1.SetSummaryItem(DevExpress.Data.SummaryItemType.Sum, "合计={0:n2}", c => c.Age);</para> /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="TProperty">The type of the property.</typeparam> /// <param name="girdView">The gird view.</param> /// <param name="type">The type.</param> /// <param name="formatString">The format string.</param> /// <param name="keySelector">The key selector.</param> /// 创建时间:2015-05-26 15:13 /// 备注说明:<c>null</c> public static void SetSummaryItem <T, TProperty>(this GridView girdView, SummaryItemType type, string formatString, Expression <Func <T, TProperty> > keySelector) where T : class { if (!girdView.OptionsView.ShowFooter) { girdView.OptionsView.ShowFooter = true; } string _fieldName = keySelector.GetTPropertyName <T, TProperty>(); GridColumn _summaryColumn = girdView.Columns[_fieldName]; if (_summaryColumn != null) { _summaryColumn.SummaryItem.SummaryType = type; if (!string.IsNullOrEmpty(formatString)) { _summaryColumn.SummaryItem.DisplayFormat = formatString; } } }
private SummaryFunc GetSummaryFunc(SummaryItemType summaryItemType) { switch (summaryItemType) { case SummaryItemType.Sum: return(SummaryFunc.Sum); case SummaryItemType.Average: return(SummaryFunc.Avg); case SummaryItemType.Max: return(SummaryFunc.Max); case SummaryItemType.Min: return(SummaryFunc.Min); default: return(SummaryFunc.Custom); } }
private static string GetNameArg(SummaryItemType func) { switch (func) { case SummaryItemType.Sum: return("Сумм. {0:#.##}"); case SummaryItemType.Min: return("Мин. {0:#.##}"); case SummaryItemType.Max: return("Макс. {0:#.##}"); case SummaryItemType.Count: return("Кол. {0:#.##}"); case SummaryItemType.Average: return("Сред. {0:#.##}"); } return(""); }
/// <summary> /// 准备好要取出的AGG的类似SQL的字符串 /// </summary> /// <param name="summaryColString">以逗号隔开的汇总列集合字符串</param> /// <returns></returns> private string prepareAggregationString(string summaryColString) { string agg = string.Empty; string[] sumCols = summaryColString.Split(','); foreach (string sumColName in sumCols) { SummaryItemType sumItem = _SummaryInfo.ColumnSummaryInfos[sumColName].SummaryItemType; switch (sumItem) { case SummaryItemType.Sum: agg = agg + string.Format("sum({0}) as {0},", sumColName); break; case SummaryItemType.Average: agg = agg + string.Format("avg({0}) as {0},", sumColName); break; case SummaryItemType.Count: agg = agg + string.Format("count({0}) as {0},", sumColName); break; case SummaryItemType.Max: agg = agg + string.Format("max({0}) as {0},", sumColName); break; case SummaryItemType.Min: agg = agg + string.Format("min({0}) as {0},", sumColName); break; default: break; } } agg = agg.TrimEnd(','); return(agg); }
/// <summary> /// /// </summary> /// <param name="gridView"></param> /// <param name="fieldName"></param> /// <param name="caption"></param> /// <param name="width"></param> /// <param name="isAllowEdit"></param> /// <param name="formatString"></param> /// <param name="summaryType"></param> /// <param name="summaryFormat"></param> public static void AddSpinEditColumn( this GridView gridView, string fieldName, string caption, int width, bool isAllowEdit = true, string formatString = "###,###,###,###,##0", SummaryItemType summaryType = SummaryItemType.None, string summaryFormat = "", string editFormat = "##############0", FormatType formatType = FormatType.Custom) { RepositoryItemSpinEdit itemCtrl = new RepositoryItemSpinEdit(); itemCtrl.DisplayFormat.FormatString = formatString; itemCtrl.DisplayFormat.FormatType = formatType; itemCtrl.EditFormat.FormatString = editFormat; itemCtrl.EditFormat.FormatType = formatType; //Edit phải set # như vầy: ###,###,###,###,##0 itemCtrl.EditMask = editFormat; if (!isAllowEdit) { itemCtrl.Buttons[0].Visible = false; } GridColumnSummaryItem summaryItem = new GridColumnSummaryItem(); if (summaryType != SummaryItemType.None) { summaryFormat = string.IsNullOrEmpty(summaryFormat) ? "{0: " + formatString + "}" : summaryFormat; summaryItem = new GridColumnSummaryItem(summaryType, fieldName, summaryFormat); } gridView.AddColumn(fieldName, caption, width, isAllowEdit, itemCtrl: itemCtrl, summaryItem: summaryItem); }
private Aggregate GetAggregateType(SummaryItemType summaryType) { switch (summaryType) { case SummaryItemType.Average: return(Aggregate.Avg); case SummaryItemType.Count: return(Aggregate.Count); case SummaryItemType.Max: return(Aggregate.Max); case SummaryItemType.Min: return(Aggregate.Min); case SummaryItemType.Sum: return(Aggregate.Sum); default: string msg = string.Format(CultureInfo.CurrentCulture, "The specified summary type is not supported: {0}", summaryType); throw new System.NotSupportedException(msg); } }
/// <summary> /// 設定column group Summary (如果沒有該column也不會出錯) /// </summary> /// <param name="gv"></param> /// <param name="summaryFieldName">要Summary 哪個欄位</param> /// <param name="DisplayFormat"></param> /// <param name="summaryItemType"></param> /// <param name="showInFooter">要不要顯示在 group footer</param> /// <param name="footerColFieldName">group footer 欄位</param> public static void SetGridGroupSummary(this DevExpress.XtraGrid.Views.Grid.GridView gv, string summaryFieldName, string DisplayFormat, SummaryItemType summaryItemType, bool showInFooter = false, string footerColFieldName = "") { if (gv.Columns[summaryFieldName] == null) { return; } GridGroupSummaryItem groupSummary = new GridGroupSummaryItem(); groupSummary.FieldName = summaryFieldName; groupSummary.SummaryType = summaryItemType; groupSummary.DisplayFormat = DisplayFormat; if (showInFooter) { groupSummary.ShowInGroupColumnFooter = gv.Columns[footerColFieldName]; } gv.GroupSummary.Add(groupSummary); }
public static SummaryItemType GetSummaryItemType(SumaryType sumaryType) { SummaryItemType summaryItemType = new SummaryItemType(); switch (sumaryType) { case SumaryType.Sum: summaryItemType = SummaryItemType.Sum; break; case SumaryType.Min: summaryItemType = SummaryItemType.Min; break; case SumaryType.Max: summaryItemType = SummaryItemType.Max; break; case SumaryType.Count: summaryItemType = SummaryItemType.Count; break; case SumaryType.Average: summaryItemType = SummaryItemType.Average; break; case SumaryType.Custom: summaryItemType = SummaryItemType.Custom; break; case SumaryType.None: summaryItemType = SummaryItemType.None; break; } return(summaryItemType); }
/// <summary> /// 设置统计列内容 /// </summary> /// <param name="gridView">GridView对象</param> /// <param name="fieldName">统计字段</param> /// <param name="summaryItemType">统计类型</param> /// <param name="prefix">显示前缀</param> public static void SetSummaryColumn(this GridView gridView, string fieldName, SummaryItemType summaryItemType = SummaryItemType.Sum, string prefix = "") { if (!gridView.OptionsView.ShowFooter) { gridView.OptionsView.ShowFooter = true; } string upperFieldName = fieldName; gridView.Columns[upperFieldName].SummaryItem.FieldName = upperFieldName; gridView.Columns[upperFieldName].SummaryItem.DisplayFormat = gridView.Columns[upperFieldName].DisplayFormat.FormatString; gridView.Columns[upperFieldName].SummaryItem.SummaryType = summaryItemType; gridView.Columns[upperFieldName].SummaryItem.DisplayFormat = prefix + "{0}"; }
private SummaryFunc GetSummaryFunc(SummaryItemType summaryItemType) { switch (summaryItemType) { case SummaryItemType.Sum: return SummaryFunc.Sum; case SummaryItemType.Average: return SummaryFunc.Avg; case SummaryItemType.Max: return SummaryFunc.Max; case SummaryItemType.Min: return SummaryFunc.Min; default: return SummaryFunc.Custom; } }
public static void AddUnboundBandColumns(this GridBand band, bool readOnly, int rowIndex, string captionFormat, string fieldPrefix, UnboundColumnType unboundColumnType, SummaryItemType summaryType, IEnumerable <string> header, int?minWidth = null) { Debug.Assert(band != null && band.View != null, "band == null || band.View == null "); if (band == null || band.View == null) { return; } band.View.BeginUpdate(); try { var gridColumnList = new List <BandedGridColumn>(); foreach (var item in header) { var fieldName = fieldPrefix + item; var caption = GetCaption(captionFormat, item); var column = CreateBandedGridColumn(readOnly, rowIndex, caption, fieldName, unboundColumnType, summaryType, HorzAlignment.Far, item, minWidth); gridColumnList.Add(column); } band.View.Columns.AddRange(gridColumnList.ToArray()); foreach (var gridColumn in gridColumnList) { band.Columns.Add(gridColumn); } if (summaryType != SummaryItemType.None) { var groupSummaryList = new List <GridGroupSummaryItem>(); foreach (var gridColumn in gridColumnList) { var gridGroupSummaryItem = new GridGroupSummaryItem(summaryType, gridColumn.FieldName, gridColumn, SummaryFormat); groupSummaryList.Add(gridGroupSummaryItem); } band.View.GroupSummary.AddRange(groupSummaryList.ToArray()); } } finally { band.View.EndUpdate(); } }