示例#1
0
        public static void Print(WarehouseAvailability warehouseAvailability)
        {
            var warehousesData = warehouseAvailability.MaterialAvailabilities.GroupBy(x => x.Warehouse, (warehouse, materialAvailability) => new
            {
                Warehouse = warehouse,
                Total     = materialAvailability.Sum(x => x.Quantity),
                Materials = materialAvailability.OrderBy(x => x.MaterialId)
            }).OrderByDescending(x => x.Total).ThenByDescending(x => x.Warehouse);

            foreach (var warehouseData in warehousesData)
            {
                Console.Write(Environment.NewLine);
                Console.WriteLine($"{warehouseData.Warehouse}(total {warehouseData.Total})");
                foreach (var materialAvailability in warehouseData.Materials)
                {
                    Console.WriteLine($"{materialAvailability.MaterialId}:{materialAvailability.Quantity}");
                }
            }
        }
        public static WarehouseAvailability Parse(List <string> data)
        {
            var result = new WarehouseAvailability();

            for (var i = 0; i < data.Count; ++i)
            {
                if (string.IsNullOrWhiteSpace(data[i]) || data[i].StartsWith("#", StringComparison.InvariantCultureIgnoreCase))
                {
                    continue;
                }

                var splittedData = data[i].Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                if (splittedData.Length < 3)
                {
                    continue;
                }

                result.Materials.Add(new Material(splittedData[0], splittedData[1]));
                result.MaterialAvailabilities.AddRange(ParseMaterialAvailability(splittedData[1], splittedData[2]));
            }


            return(result);
        }