Last active
December 30, 2015 19:29
-
-
Save masaru-b-cl/7874861 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var oldCustomer = ""; | |
| var newCustomer = ""; | |
| var oldProduct = ""; | |
| var newProduct = ""; | |
| var totalQuantity = 0L; | |
| var totalPrice = 0m; | |
| var totalCustomerQuantity = 0L; | |
| var totalCustomerPrice = 0m; | |
| var totalProductQuantity = 0L; | |
| var totalProductPrice = 0m; | |
| foreach (var sales in source) | |
| { | |
| if (oldCustomer == "") | |
| { | |
| oldCustomer = sales.Customer; | |
| oldProduct = sales.Product; | |
| } | |
| newCustomer = sales.Customer; | |
| newProduct = sales.Product; | |
| if (oldCustomer != newCustomer || oldProduct != newProduct) | |
| { | |
| Console.WriteLine("小計 P:{0}, {1}, {2}", oldProduct, totalProductQuantity, totalProductPrice); | |
| totalProductQuantity = 0L; | |
| totalProductPrice = 0m; | |
| oldProduct = newProduct; | |
| } | |
| if (oldCustomer != newCustomer) | |
| { | |
| Console.WriteLine("大計 P:{0}, {1}, {2}", oldCustomer, totalCustomerQuantity, totalCustomerPrice); | |
| totalCustomerQuantity = 0L; | |
| totalCustomerPrice = 0m; | |
| oldCustomer = newCustomer; | |
| } | |
| totalProductQuantity += sales.Quantity; | |
| totalProductPrice += sales.UnitPrice * sales.Quantity; | |
| totalCustomerQuantity += sales.Quantity; | |
| totalCustomerPrice += sales.UnitPrice * sales.Quantity; | |
| totalQuantity += sales.Quantity; | |
| totalPrice += sales.UnitPrice * sales.Quantity; | |
| Console.WriteLine(sales); | |
| } | |
| Console.WriteLine("小計 P:{0}, {1}, {2}", oldProduct, totalProductQuantity, totalProductPrice); | |
| Console.WriteLine("大計 P:{0}, {1}, {2}", oldCustomer, totalCustomerQuantity, totalCustomerPrice); | |
| Console.WriteLine("総計 {0}, {1}", totalQuantity, totalPrice); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment