49 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			49 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			C#
		
	
	
	
using System;
 | 
						|
using System.Collections.Generic;
 | 
						|
using System.Collections.ObjectModel;
 | 
						|
using System.Globalization;
 | 
						|
using System.Linq;
 | 
						|
using System.Text;
 | 
						|
using System.Threading.Tasks;
 | 
						|
using System.Windows.Data;
 | 
						|
using DM_Weight.Models;
 | 
						|
 | 
						|
namespace DM_Weight.Converter
 | 
						|
{
 | 
						|
    public class GroupSumConverter : IValueConverter
 | 
						|
    {
 | 
						|
        #region 分组组内求和
 | 
						|
 | 
						|
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 | 
						|
        {
 | 
						|
            var total = 0;
 | 
						|
            // DataGrid分组后对应的组及组内元素CollectionViewGroup.Items 类型是ReadOnlyObservableCollection<object>
 | 
						|
            if (value is ReadOnlyObservableCollection<object> items)
 | 
						|
            {
 | 
						|
                foreach (var item in items)
 | 
						|
                {
 | 
						|
                    var de = item as ChannelStock;
 | 
						|
                    try
 | 
						|
                    {
 | 
						|
                        total += de.Quantity;
 | 
						|
                    }
 | 
						|
                    catch (Exception)
 | 
						|
                    {
 | 
						|
                        var de2 = item as CheckRecordStock;
 | 
						|
                        total = de2.quantity;
 | 
						|
                    }
 | 
						|
                }
 | 
						|
            }
 | 
						|
            return "总库存:" + total;
 | 
						|
        }
 | 
						|
 | 
						|
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
 | 
						|
        {
 | 
						|
            throw new NotImplementedException();
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
    }
 | 
						|
}
 |