OrderTotalSummary.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using Infragistics.Shared;
  2. using Infragistics.Win;
  3. using Infragistics.Win.UltraWinGrid;
  4. using System.Diagnostics;
  5. using System;
  6. // A class that calculates the totals for orders.
  7. namespace Core.StlMes.Client.BuyBillet
  8. {
  9. public class OrderTotalsSummary : ICustomSummaryCalculator
  10. {
  11. private decimal totals = 0;
  12. private decimal totals1 = 0;
  13. private decimal totals2 = 0;
  14. private string column1;
  15. private string column2;
  16. private string column3;
  17. public OrderTotalsSummary(string column1,string column2,string column3 )
  18. {
  19. this.column1 = column1;
  20. this.column2 = column2;
  21. this.column3 = column3;
  22. }
  23. public void BeginCustomSummary( SummarySettings summarySettings, RowsCollection rows )
  24. {
  25. // Begins the summary for the SummarySettings object passed in. Implementation of
  26. // this method should reset any state variables used for calculating the summary.
  27. this.totals = 0;
  28. this.totals1 = 0;
  29. this.totals2 = 0;
  30. }
  31. public void AggregateCustomSummary( SummarySettings summarySettings, UltraGridRow row )
  32. {
  33. // Here is where we process each row that gets passed in.
  34. //object unitPrice = row.GetCellValue(summarySettings.SourceColumn.Band.Columns["FGSTYLG"]);
  35. //object unitPrice1 = row.GetCellValue(summarySettings.SourceColumn.Band.Columns["TSYLG"]);
  36. //object quantity = row.GetCellValue(summarySettings.SourceColumn.Band.Columns["MATERIALOUTYLG"]);
  37. object unitPrice = row.GetCellValue(summarySettings.SourceColumn.Band.Columns[column1]);
  38. object unitPrice1 = row.GetCellValue(summarySettings.SourceColumn.Band.Columns[column2]);
  39. object quantity = row.GetCellValue(summarySettings.SourceColumn.Band.Columns[column3]);
  40. // Handle null values
  41. if (unitPrice is DBNull || quantity is DBNull )
  42. {
  43. return;
  44. }
  45. // Convert to decimal.
  46. try
  47. {
  48. decimal nUnitPrice = Convert.ToDecimal( unitPrice );
  49. decimal nUnitPrice1;
  50. if(unitPrice1 is DBNull)
  51. {
  52. nUnitPrice1 = 0;
  53. }
  54. else
  55. {
  56. nUnitPrice1 = Convert.ToDecimal(unitPrice1);
  57. }
  58. decimal nQuantity = Convert.ToDecimal( quantity );
  59. this.totals1 += nUnitPrice + nUnitPrice1;
  60. this.totals2 += nQuantity;
  61. }
  62. catch ( Exception )
  63. {
  64. // This should not happen if the columns are numeric.
  65. Debug.Assert( false, "Exception thrown while trying to convert cell's value to decimal !" );
  66. }
  67. }
  68. public object EndCustomSummary( SummarySettings summarySettings, RowsCollection rows )
  69. {
  70. // This gets called when the every row has been processed so here is where we
  71. // would return the calculated summary value.
  72. if(totals2 ==0){
  73. return DBNull.Value;
  74. }
  75. return Math.Round(this.totals1*1000/this.totals2,0);
  76. }
  77. }
  78. }