using Infragistics.Shared; using Infragistics.Win; using Infragistics.Win.UltraWinGrid; using System.Diagnostics; using System; // A class that calculates the totals for orders. namespace Core.StlMes.Client.BuyBillet { public class OrderTotalsSummary : ICustomSummaryCalculator { private decimal totals = 0; private decimal totals1 = 0; private decimal totals2 = 0; private string column1; private string column2; private string column3; public OrderTotalsSummary(string column1,string column2,string column3 ) { this.column1 = column1; this.column2 = column2; this.column3 = column3; } public void BeginCustomSummary( SummarySettings summarySettings, RowsCollection rows ) { // Begins the summary for the SummarySettings object passed in. Implementation of // this method should reset any state variables used for calculating the summary. this.totals = 0; this.totals1 = 0; this.totals2 = 0; } public void AggregateCustomSummary( SummarySettings summarySettings, UltraGridRow row ) { // Here is where we process each row that gets passed in. //object unitPrice = row.GetCellValue(summarySettings.SourceColumn.Band.Columns["FGSTYLG"]); //object unitPrice1 = row.GetCellValue(summarySettings.SourceColumn.Band.Columns["TSYLG"]); //object quantity = row.GetCellValue(summarySettings.SourceColumn.Band.Columns["MATERIALOUTYLG"]); object unitPrice = row.GetCellValue(summarySettings.SourceColumn.Band.Columns[column1]); object unitPrice1 = row.GetCellValue(summarySettings.SourceColumn.Band.Columns[column2]); object quantity = row.GetCellValue(summarySettings.SourceColumn.Band.Columns[column3]); // Handle null values if (unitPrice is DBNull || quantity is DBNull ) { return; } // Convert to decimal. try { decimal nUnitPrice = Convert.ToDecimal( unitPrice ); decimal nUnitPrice1; if(unitPrice1 is DBNull) { nUnitPrice1 = 0; } else { nUnitPrice1 = Convert.ToDecimal(unitPrice1); } decimal nQuantity = Convert.ToDecimal( quantity ); this.totals1 += nUnitPrice + nUnitPrice1; this.totals2 += nQuantity; } catch ( Exception ) { // This should not happen if the columns are numeric. Debug.Assert( false, "Exception thrown while trying to convert cell's value to decimal !" ); } } public object EndCustomSummary( SummarySettings summarySettings, RowsCollection rows ) { // This gets called when the every row has been processed so here is where we // would return the calculated summary value. if(totals2 ==0){ return DBNull.Value; } return Math.Round(this.totals1*1000/this.totals2,0); } } }