protected void ASPxPivotGrid1_CustomSummary(object sender, PivotGridCustomSummaryEventArgs e) { if (e.DataField != fieldExtendedPrice) { return; } // A variable which counts the number of orders whose sum exceeds $500. int order500Count = 0; // Get the record set for the current cell. PivotDrillDownDataSource ds = e.CreateDrillDownDataSource(); // Iterate through the records and count the orders. for (int i = 0; i < ds.RowCount; i++) { PivotDrillDownDataRow row = ds[i]; // Get the order's total sum. decimal orderSum = (decimal)row[fieldExtendedPrice]; if (orderSum >= minSum) { order500Count++; } } // Calculate the percentage. if (ds.RowCount > 0) { e.CustomValue = (decimal)order500Count / ds.RowCount; } }
void IPivotCustomSummaryEvent.Calculate(PivotGridCustomSummaryEventArgs e) { if (e.RowField == null) { decimal currentSum = 0, topSum = 0; PivotDrillDownDataSource ds = e.CreateDrillDownDataSource(); for (int i = 0; i < ds.RowCount; i++) { decimal val = Convert.ToDecimal(ds[i][Model.TopObject.FieldDataName]); if (ReferenceEquals(ds[i][Model.TopObject.FieldRowName], _topObject)) { topSum += val; } else { currentSum += val; } } e.CustomValue = currentSum - topSum; } else { e.CustomValue = e.SummaryValue.Summary; } }
private void onCustomSummary(PivotGridCustomSummaryEventArgs e) { if (e.DataField != ValueField) { return; } // Get the record set corresponding to the current cell. var ds = e.CreateDrillDownDataSource(); e.CustomValue = ds.Value <object>(ValueField); }
// The CustomSummary event is a legacy approach. private void pivotGridControl1_CustomSummary(object sender, PivotGridCustomSummaryEventArgs e) { if (e.DataField.Name == "fieldValue") { if (CustomSummaryHelper.ShouldCalculateCustomValue(fieldType, e)) { var groupedDataSource = e.CreateDrillDownDataSource().Cast <PivotDrillDownDataRow>().GroupBy(r => r[fieldType]); decimal incomeSummary = CustomSummaryHelper.GetGroupSummary(groupedDataSource, "Income", e.FieldName); decimal outlaySummary = CustomSummaryHelper.GetGroupSummary(groupedDataSource, "Outlay", e.FieldName); e.CustomValue = incomeSummary - outlaySummary; } else { e.CustomValue = e.SummaryValue.Summary; } } }
private void PivotGridControl1_CustomSummary(object sender, PivotGridCustomSummaryEventArgs e) { string name = e.DataField.FieldName; IList list = e.CreateDrillDownDataSource(); Hashtable ht = new Hashtable(); for (int i = 0; i < list.Count; i++) { PivotDrillDownDataRow row = list[i] as PivotDrillDownDataRow; object v = row[name]; if (v != null && v != DBNull.Value) { ht[v] = null; } } e.CustomValue = ht.Count; }
private void pivotGridControl1_CustomSummary(object sender, PivotGridCustomSummaryEventArgs e) { decimal firstn = 0; decimal sumn = 0; PivotDrillDownDataSource ds = e.CreateDrillDownDataSource(); if (e.DataField == fieldRate) { for (int i = 0; i < ds.RowCount; i++) { PivotDrillDownDataRow row = ds[i]; firstn += Convert.ToDecimal(row[fieldPlanQty1]);; sumn += Convert.ToDecimal(row[fieldOutQty1]); if (firstn != 0) { e.CustomValue = sumn / firstn; } } } }
/// <summary> /// Calculate summary value /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Grid_CustomSummary(object sender, PivotGridCustomSummaryEventArgs e) { int ri, dri; int queryEngineInstanceId = -1; PivotGridFieldContext f = GetPivotGridFieldContext(e.DataField); if (f.Aggregation.Role != AggregationRole.DataSummary) // must check this since when moving a field to a new area in the PivotGridDialog, this event fires before the FieldAreaChanged event { return; // throw new Exception("Expected DataSummary Role"); } DataTableMx dt = f.Qm.DataTable; PivotDrillDownDataSource ds = e.CreateDrillDownDataSource(); List <object[]> voList = new List <object[]>(); for (ri = 0; ri < ds.RowCount; ri++) // get list of rows containing values to summarize { PivotDrillDownDataRow row = ds[ri]; dri = row.ListSourceRowIndex; if (dri >= dt.Rows.Count) { throw new Exception("dri >= dt.Rows.Count"); } object[] voa = dt.Rows[dri].ItemArrayRef; voList.Add(voa); continue; } if (f.Qe != null) { queryEngineInstanceId = f.Qe.Id; } Aggregator ag = new Aggregator(); object r = ag.AggregateQueryColumn(queryEngineInstanceId, f.Qc, f.Aggregation, voList); // do the aggregation e.CustomValue = r; // return value return; }
protected void PivotSelMeas_Concat(object sender, PivotGridCustomSummaryEventArgs e) { // Debug.Print("ENTER PivotSelMeas_Concat"); var x = e.DataField; //if (e.DataField != field_meas) return; if (e.DataField.Name != "field_meas") { return; } // Get the record set corresponding to the current cell. PivotDrillDownDataSource ds = e.CreateDrillDownDataSource(); string concat = ""; // Iterate through the records and count the orders. for (int i = 0; i < ds.RowCount; i++) { PivotDrillDownDataRow row = ds[i]; string sep = (i == 0) ? "" : "<br>"; string newtext = row["StudyMeasName"].ToString(); string isREL = row["isREL"].ToString(); if (isREL == "REL") { newtext = String.Format(@"<p style=""background-color: gold; display:inline; text-align: right;"">{0}</p>", newtext); } concat = String.Format("{0}{1}{2}", concat, sep, newtext); } if (ds.RowCount > 0) { e.CustomValue = concat; } // Debug.Print("EXIT PivotSelMeas_Concat"); }
private void pivotGridControl1_CustomSummary(object sender, PivotGridCustomSummaryEventArgs e) { decimal inqty = 0; decimal ngqty = 0; decimal iqcngqty = 0; PivotDrillDownDataSource ds = e.CreateDrillDownDataSource(); if (e.DataField == FieldNGRate) { //报废率 for (int i = 0; i < ds.RowCount; i++) { PivotDrillDownDataRow row = ds[i]; inqty += Convert.ToDecimal(row[fieldInQty1]); //投入 ngqty += Convert.ToDecimal(row[fieldNgQty]); //报废 iqcngqty += Convert.ToDecimal(row[fieldIQCNGQty1]); //iqc报废 if (inqty != 0) { e.CustomValue = (ngqty + iqcngqty) / (inqty + iqcngqty); } } } }
private void pivotGridControlIdleHours_CustomSummary(object sender, PivotGridCustomSummaryEventArgs e) { string field = e.DataField.FieldName; IList list = e.CreateDrillDownDataSource(); if (field == "Idle_Hours") { List <TimeSpan> listHours = new List <TimeSpan>(); foreach (PivotDrillDownDataRow row in list) { object a = row[field]; CultureInfo culture = CultureInfo.InvariantCulture; listHours.Add(TimeSpan.Parse(row[field].ToString(), culture)); } var ts = new TimeSpan(listHours.Sum(t => t.Duration().Ticks)); string total = string.Format("{0:D2}H:{1:D2}M:{2:D2}S", (int)ts.TotalHours, ts.Minutes, ts.Seconds ); e.CustomValue = total; } }
private void pivotGridControl1_CustomSummary(object sender, PivotGridCustomSummaryEventArgs e) { decimal firstn = 0; decimal sumn = 0; decimal second = 0; PivotDrillDownDataSource ds = e.CreateDrillDownDataSource(); if (e.DataField == TDNGRate) { for (int i = 0; i < ds.RowCount; i++) { PivotDrillDownDataRow row = ds[i]; firstn += Convert.ToDecimal(row[fieldTDInQty1]);; sumn += Convert.ToDecimal(row[fieldTDNgQty1]); second += Convert.ToDecimal(row[fieldTDIQCNGQty1]); if ((firstn + second) != 0) { e.CustomValue = (sumn + second) / (firstn + second); } } } else if (e.DataField == NGRate) { for (int i = 0; i < ds.RowCount; i++) { PivotDrillDownDataRow row = ds[i]; firstn += Convert.ToDecimal(row[fieldInQty1]);; sumn += Convert.ToDecimal(row[fieldNgQty1]); second += Convert.ToDecimal(row[fieldIQCNGQty1]); if ((firstn + second) != 0) { e.CustomValue = (sumn + second) / (firstn + second); } } } }
private void pivotGridControl1_CustomSummary(object sender, PivotGridCustomSummaryEventArgs e) { decimal firstn = 0; decimal sumn = 0; PivotDrillDownDataSource ds = e.CreateDrillDownDataSource(); if (e.DataField == pivotGridField13) { //冲压报废率 for (int i = 0; i < ds.RowCount; i++) { PivotDrillDownDataRow row = ds[i]; firstn += Convert.ToDecimal(row[pivotGridField9]); //冲压投入 sumn += Convert.ToDecimal(row[fieldPNGQtyInK1]); //冲压报废 if (firstn != 0) { e.CustomValue = sumn / firstn; } } } if (e.DataField == pivotGridField14) { //电镀报废率 for (int i = 0; i < ds.RowCount; i++) { PivotDrillDownDataRow row = ds[i]; firstn += Convert.ToDecimal(row[pivotGridField10]); //投入 sumn += Convert.ToDecimal(row[fieldENGQtyInK1]); //报废 if (firstn != 0) { e.CustomValue = sumn / firstn; } } } if (e.DataField == pivotGridField15) { //切断报废率pivotGridField19 for (int i = 0; i < ds.RowCount; i++) { PivotDrillDownDataRow row = ds[i]; firstn += Convert.ToDecimal(row[pivotGridField11]); //投入 sumn += Convert.ToDecimal(row[fieldCNGQtyInK1]); //报废 if (firstn != 0) { e.CustomValue = sumn / firstn; } } } if (e.DataField == pivotGridField23) {//其他报废率 for (int i = 0; i < ds.RowCount; i++) { PivotDrillDownDataRow row = ds[i]; firstn += Convert.ToDecimal(row[pivotGridField12]); //投入 sumn += Convert.ToDecimal(row[pivotGridField22]); //报废 if (firstn != 0) { e.CustomValue = sumn / firstn; } } } if (e.DataField == pivotGridField19) { //冲压报废率(当天) for (int i = 0; i < ds.RowCount; i++) { PivotDrillDownDataRow row = ds[i]; firstn += Convert.ToDecimal(row[pivotGridField16]); //投入 sumn += Convert.ToDecimal(row[pivotGridField6]); //报废 if (firstn != 0) { e.CustomValue = sumn / firstn; } } } if (e.DataField == pivotGridField20) { //电镀报废率(当天) for (int i = 0; i < ds.RowCount; i++) { PivotDrillDownDataRow row = ds[i]; firstn += Convert.ToDecimal(row[pivotGridField17]); //投入 sumn += Convert.ToDecimal(row[pivotGridField7]); //报废 if (firstn != 0) { e.CustomValue = sumn / firstn; } } } if (e.DataField == pivotGridField21) { //切断报废率(当天)pivotGridField19 for (int i = 0; i < ds.RowCount; i++) { PivotDrillDownDataRow row = ds[i]; firstn += Convert.ToDecimal(row[pivotGridField18]); //投入 sumn += Convert.ToDecimal(row[pivotGridField8]); //报废 if (firstn != 0) { e.CustomValue = sumn / firstn; } } } if (e.DataField == pivotGridField26) { //切断报废率(当天)pivotGridField19 for (int i = 0; i < ds.RowCount; i++) { PivotDrillDownDataRow row = ds[i]; firstn += Convert.ToDecimal(row[pivotGridField25]); //投入 sumn += Convert.ToDecimal(row[pivotGridField24]); //报废 if (firstn != 0) { e.CustomValue = sumn / firstn; } } } }
void IPivotCustomSummaryEvent.Calculate(PivotGridCustomSummaryEventArgs e) { if (e.RowField == null) { decimal currentSum = 0, topSum = 0; PivotDrillDownDataSource ds = e.CreateDrillDownDataSource(); for (int i = 0; i < ds.RowCount; i++) { decimal val = Convert.ToDecimal(ds[i][Model.TopObject.FieldDataName]); if (ReferenceEquals(ds[i][Model.TopObject.FieldRowName], _topObject)) topSum += val; else currentSum += val; } e.CustomValue = currentSum - topSum; } else e.CustomValue = e.SummaryValue.Summary; }