diff --git a/DynamicMemory/LD_24/App_Data/Rezultatai.txt b/DynamicMemory/LD_24/App_Data/Rezultatai.txt index d4d569d..570cd9b 100644 --- a/DynamicMemory/LD_24/App_Data/Rezultatai.txt +++ b/DynamicMemory/LD_24/App_Data/Rezultatai.txt @@ -15,17 +15,37 @@ | Pavardė | Vardas | Įtaisas | Įtaiso kiekis | --------------------------------------------------------------- | Petraitis | Petras | 0 | 10 | -| Onaite | Ona | 2 | 15 | +| Jonaitis | Jonas | 1 | 20 | +| Jonaitis | Jonas | 1 | 20 | +| Jonaitis | Jonas | 1 | 20 | +| Onaite | Ona | 2 | 200 | | Jonaitis | Brolis | 1 | 100 | -| Jonaitis | Jonas | 1 | 100 | +| Jonaitis | Jonas | 1 | 20 | +| Jonaitis | Jonas | 1 | 20 | +| Onaite | Ona | 0 | 20 | --------------------------------------------------------------- -Populiariausias produktas: Varztas -Pardavimų kiekis: 200 vnt. -Pardavimų kaina: 10.00 eur. +--------------------------------------------------------------------------- +| Populiariausi įtaisai | +--------------------------------------------------------------------------- +| ID | Vardas | Įtaisų kiekis, vnt. | Įtaisų kaina, eur. | +--------------------------------------------------------------------------- +| 1 | Varztas | 200 | 10.00 | +| 2 | Laidas | 200 | 400.00 | +--------------------------------------------------------------------------- + +Pirkėjai pagal rūšį: +--------------------------------------------------------------- +| Atsuktuvas | +--------------------------------------------------------------- +| Pavardė | Vardas | Įtaiso kiekis | Kaina | +--------------------------------------------------------------- +| Onaite | Ona | 20 | 19.80 | +| Petraitis | Petras | 10 | 9.90 | +--------------------------------------------------------------- --------------------------------------------------------------- -| Pirkėjai pagal rūšį (Varztas) | +| Varztas | --------------------------------------------------------------- | Pavardė | Vardas | Įtaiso kiekis | Kaina | --------------------------------------------------------------- @@ -33,13 +53,28 @@ Pardavimų kaina: 10.00 eur. | Jonaitis | Jonas | 100 | 5.00 | --------------------------------------------------------------- +--------------------------------------------------------------- +| Laidas | +--------------------------------------------------------------- +| Pavardė | Vardas | Įtaiso kiekis | Kaina | +--------------------------------------------------------------- +| Onaite | Ona | 200 | 400.00 | +--------------------------------------------------------------- + +--------------------------------------------------------------- +| Plaktukas | +--------------------------------------------------------------- +| Pavardė | Vardas | Įtaiso kiekis | Kaina | +--------------------------------------------------------------- +| Nėra | +--------------------------------------------------------------- + ------------------------------------------ -| Atrinkti įtaisai (n=1, k=10.00) | +| Atrinkti įtaisai (n=1, k=1.00) | ------------------------------------------ | ID | Vardas | Kaina | ------------------------------------------ | 0 | Atsuktuvas | 0.99 | | 1 | Varztas | 0.05 | -| 2 | Laidas | 2.00 | ------------------------------------------ diff --git a/DynamicMemory/LD_24/App_Data/U24b.txt b/DynamicMemory/LD_24/App_Data/U24b.txt index 3db7b1a..8defdf5 100644 --- a/DynamicMemory/LD_24/App_Data/U24b.txt +++ b/DynamicMemory/LD_24/App_Data/U24b.txt @@ -1,4 +1,9 @@ Petraitis, Petras, 0, 10 -Onaite, Ona, 2, 15 +Jonaitis, Jonas, 1, 20 +Jonaitis, Jonas, 1, 20 +Jonaitis, Jonas, 1, 20 +Onaite, Ona, 2, 200 Jonaitis, Brolis, 1, 100 -Jonaitis, Jonas, 1, 100 \ No newline at end of file +Jonaitis, Jonas, 1, 20 +Jonaitis, Jonas, 1, 20 +Onaite, Ona, 0, 20 \ No newline at end of file diff --git a/DynamicMemory/LD_24/Code/CustomerNode.cs b/DynamicMemory/LD_24/Code/CustomerNode.cs deleted file mode 100644 index 3ecff7f..0000000 --- a/DynamicMemory/LD_24/Code/CustomerNode.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; - -namespace LD_24.Code -{ - public class CustomerNode - { - public Customer Data { get; set; } - public CustomerNode Next { get; set; } - - public CustomerNode(Customer data = null, CustomerNode next = null) - { - Data = data; - Next = next; - } - } -} \ No newline at end of file diff --git a/DynamicMemory/LD_24/Code/InOutUtils.cs b/DynamicMemory/LD_24/Code/InOutUtils.cs index 5804a4c..40ea88e 100644 --- a/DynamicMemory/LD_24/Code/InOutUtils.cs +++ b/DynamicMemory/LD_24/Code/InOutUtils.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.IO; using System.Linq; using System.Web; @@ -27,39 +28,39 @@ namespace LD_24.Code string[] parts = line.Split(','); string id = parts[0].Trim(); string name = parts[1].Trim(); - decimal price = decimal.Parse(parts[2].Trim()); + decimal price = decimal.Parse(parts[2].Trim(), CultureInfo.InvariantCulture); products.AddToEnd(new Product(id, name, price)); } return products; } - public static CustomerList ReadCustomers(string filename) + public static OrderList ReadOrders(string filename) { - CustomerList customers = new CustomerList(); + OrderList orders = new OrderList(); foreach (string line in ReadLines(filename)) { string[] parts = line.Split(','); - string surname = parts[0].Trim(); - string name = parts[1].Trim(); + string customerSurname = parts[0].Trim(); + string customerName = parts[1].Trim(); string productID = parts[2].Trim(); int productAmount = int.Parse(parts[3].Trim()); - customers.AddToEnd(new Customer(surname, name, productID, productAmount)); + orders.AddToEnd(new Order(customerSurname, customerName, productID, productAmount)); } - return customers; + return orders; } - public static void PrintCustomers(StreamWriter writer, CustomerList customers, string header) + public static void PrintOrders(StreamWriter writer, OrderList orders, string header) { writer.WriteLine(new string('-', 63)); writer.WriteLine("| {0, -59} |", header); writer.WriteLine(new string('-', 63)); writer.WriteLine("| {0, -15} | {1, -15} | {2, 7} | {3, 13} |", "Pavardė", "Vardas", "Įtaisas", "Įtaiso kiekis"); writer.WriteLine(new string('-', 63)); - if (customers.Count() > 0) + if (orders.Count() > 0) { - foreach (Customer c in customers) + foreach (Order o in orders) { - writer.WriteLine("| {0, -15} | {1, -15} | {2, 7} | {3, 13} |", c.Surname, c.Name, c.ProductID, c.ProductAmount); + writer.WriteLine("| {0, -15} | {1, -15} | {2, 7} | {3, 13} |", o.CustomerSurname, o.CustomerName, o.ProductID, o.ProductAmount); } } else @@ -70,18 +71,23 @@ namespace LD_24.Code writer.WriteLine(); } - public static void PrintCustomersWithPrices(StreamWriter writer, CustomerList customers, Product product, string header) + public static void PrintOrdersWithPrices(StreamWriter writer, OrderList orders, Product product, string header) { writer.WriteLine(new string('-', 63)); writer.WriteLine("| {0, -59} |", header); writer.WriteLine(new string('-', 63)); writer.WriteLine("| {0, -15} | {1, -15} | {2, 13} | {3, 7} |", "Pavardė", "Vardas", "Įtaiso kiekis", "Kaina"); writer.WriteLine(new string('-', 63)); - if (customers.Count() > 0) + + OrderList filtered = TaskUtils.FilterByProduct(orders, product.ID); + filtered = TaskUtils.MergeOrders(filtered); + filtered.Sort(); + + if (filtered.Count() > 0) { - foreach (Customer c in customers) + foreach (Order o in filtered) { - writer.WriteLine("| {0, -15} | {1, -15} | {2, 13} | {3, 7:f2} |", c.Surname, c.Name, c.ProductAmount, c.ProductAmount *product.Price); + writer.WriteLine("| {0, -15} | {1, -15} | {2, 13} | {3, 7:f2} |", o.CustomerSurname, o.CustomerName, o.ProductAmount, o.ProductAmount*product.Price); } } else @@ -113,5 +119,29 @@ namespace LD_24.Code writer.WriteLine(new string('-', 42)); writer.WriteLine(); } + + + public static void PrintMostPopularProducts(StreamWriter writer, OrderList orders, ProductList popularProducts, string header) + { + writer.WriteLine(new string('-', 75)); + writer.WriteLine("| {0, -71} |", header); + writer.WriteLine(new string('-', 75)); + writer.WriteLine("| {0, -5} | {1, -20} | {2, 7} | {3} |", "ID", "Vardas", "Įtaisų kiekis, vnt.", "Įtaisų kaina, eur."); + writer.WriteLine(new string('-', 75)); + if (popularProducts.Count() > 0) + { + foreach (Product p in popularProducts) + { + int sales = TaskUtils.CountProductSales(orders, p.ID); + writer.WriteLine("| {0, -5} | {1, -20} | {2, 19} | {3, 18:f2} |", p.ID, p.Name, sales, sales*p.Price); + } + } + else + { + writer.WriteLine("| {0, -71} |", "Nėra"); + } + writer.WriteLine(new string('-', 75)); + writer.WriteLine(); + } } } \ No newline at end of file diff --git a/DynamicMemory/LD_24/Code/Customer.cs b/DynamicMemory/LD_24/Code/Order.cs similarity index 50% rename from DynamicMemory/LD_24/Code/Customer.cs rename to DynamicMemory/LD_24/Code/Order.cs index 7c80809..fda1d89 100644 --- a/DynamicMemory/LD_24/Code/Customer.cs +++ b/DynamicMemory/LD_24/Code/Order.cs @@ -5,27 +5,27 @@ using System.Web; namespace LD_24.Code { - public class Customer + public class Order { - public string Surname { get; set; } - public string Name { get; set; } + public string CustomerSurname { get; set; } + public string CustomerName { get; set; } public string ProductID { get; set; } public int ProductAmount { get; set; } - public Customer(string surname, string name, string productID, int productAmount) + public Order(string customerSurname, string customerName, string productID, int productAmount) { - Surname = surname; - Name = name; + CustomerSurname = customerSurname; + CustomerName = customerName; ProductID = productID; ProductAmount = productAmount; } public override string ToString() { - return String.Format("Customer{Name = '{0}'}", Name); + return String.Format("Order{Name = '{0}'}", CustomerName); } - public static bool operator <(Customer a, Customer b) + public static bool operator <(Order a, Order b) { if (a.ProductAmount > b.ProductAmount) { @@ -33,28 +33,28 @@ namespace LD_24.Code } else if (a.ProductAmount == b.ProductAmount) { - int surnameCompare = a.Surname.CompareTo(b.Surname); + int surnameCompare = a.CustomerSurname.CompareTo(b.CustomerSurname); if (surnameCompare < 0) { return true; } else if (surnameCompare == 0) { - return a.Name.CompareTo(b.Name) < 0; + return a.CustomerName.CompareTo(b.CustomerName) < 0; } } return false; } - public static bool operator >(Customer a, Customer b) + public static bool operator >(Order a, Order b) { return !(a < b && a == b); } - public static bool operator ==(Customer a, Customer b) + public static bool operator ==(Order a, Order b) { - return a.ProductAmount == b.ProductAmount && a.Name == b.Name && a.Surname == b.Surname; + return a.ProductAmount == b.ProductAmount && a.CustomerName == b.CustomerName && a.CustomerSurname == b.CustomerSurname; } - public static bool operator !=(Customer a, Customer b) + public static bool operator !=(Order a, Order b) { return !(a == b); } diff --git a/DynamicMemory/LD_24/Code/CustomerList.cs b/DynamicMemory/LD_24/Code/OrderList.cs similarity index 61% rename from DynamicMemory/LD_24/Code/CustomerList.cs rename to DynamicMemory/LD_24/Code/OrderList.cs index 7652a41..5b45438 100644 --- a/DynamicMemory/LD_24/Code/CustomerList.cs +++ b/DynamicMemory/LD_24/Code/OrderList.cs @@ -6,14 +6,26 @@ using System.Web; namespace LD_24.Code { - public class CustomerList : IEnumerable + public class OrderList : IEnumerable { - private CustomerNode head; - private CustomerNode tail; - - public void AddToEnd(Customer customer) + class OrderNode { - CustomerNode node = new CustomerNode(customer); + public Order Data { get; set; } + public OrderNode Next { get; set; } + + public OrderNode(Order data = null, OrderNode next = null) + { + Data = data; + Next = next; + } + } + + private OrderNode head; + private OrderNode tail; + + public void AddToEnd(Order customer) + { + OrderNode node = new OrderNode(customer); if (tail != null && head != null) { tail.Next = node; @@ -26,9 +38,9 @@ namespace LD_24.Code } } - public void AddToStart(Customer customer) + public void AddToStart(Order customer) { - CustomerNode node = new CustomerNode(customer); + OrderNode node = new OrderNode(customer); if (tail != null && head != null) { node.Next = head; @@ -41,10 +53,10 @@ namespace LD_24.Code } } - public Customer Get(int index) + public Order Get(int index) { int i = 0; - CustomerNode current = head; + OrderNode current = head; while (i < index && current != null) { current = head.Next; @@ -56,7 +68,7 @@ namespace LD_24.Code public int Count() { int count = 0; - CustomerNode current = head; + OrderNode current = head; while (current != null) { current = current.Next; @@ -67,10 +79,10 @@ namespace LD_24.Code public void Sort() { - for (CustomerNode nodeA = head; nodeA != null; nodeA = nodeA.Next) + for (OrderNode nodeA = head; nodeA != null; nodeA = nodeA.Next) { - CustomerNode min = nodeA; - for (CustomerNode nodeB = nodeA.Next; nodeB != null; nodeB = nodeB.Next) + OrderNode min = nodeA; + for (OrderNode nodeB = nodeA.Next; nodeB != null; nodeB = nodeB.Next) { if (nodeB.Data < min.Data) { @@ -78,7 +90,7 @@ namespace LD_24.Code } } - Customer tmp = nodeA.Data; + Order tmp = nodeA.Data; nodeA.Data = min.Data; min.Data = tmp; } @@ -86,12 +98,12 @@ namespace LD_24.Code public override string ToString() { - return String.Format("CustomerList{ Count = '{0}' }", Count()); + return String.Format("OrderList{ Count = '{0}' }", Count()); } - public IEnumerator GetEnumerator() + public IEnumerator GetEnumerator() { - CustomerNode current = head; + OrderNode current = head; while (current != null) { yield return current.Data; diff --git a/DynamicMemory/LD_24/Code/Product.cs b/DynamicMemory/LD_24/Code/Product.cs index 662565e..8093c0e 100644 --- a/DynamicMemory/LD_24/Code/Product.cs +++ b/DynamicMemory/LD_24/Code/Product.cs @@ -5,12 +5,30 @@ using System.Web; namespace LD_24.Code { + /// + /// Holds informations about a single product + /// public class Product { + /// + /// Identification number of product + /// public string ID { get; set; } + /// + /// Name of product + /// public string Name { get; set; } + /// + /// Price of product + /// public decimal Price { get; set; } + /// + /// Constructs a new product + /// + /// + /// + /// public Product(string iD, string name, decimal price) { ID = iD; diff --git a/DynamicMemory/LD_24/Code/ProductList.cs b/DynamicMemory/LD_24/Code/ProductList.cs index f8fc70d..85ac4f6 100644 --- a/DynamicMemory/LD_24/Code/ProductList.cs +++ b/DynamicMemory/LD_24/Code/ProductList.cs @@ -8,6 +8,18 @@ namespace LD_24.Code { public class ProductList : IEnumerable { + class ProductNode + { + public Product Data { get; set; } + public ProductNode Next { get; set; } + + public ProductNode(Product data = null, ProductNode next = null) + { + Data = data; + Next = next; + } + } + private ProductNode head; private ProductNode tail; diff --git a/DynamicMemory/LD_24/Code/ProductNode.cs b/DynamicMemory/LD_24/Code/ProductNode.cs deleted file mode 100644 index 950dd18..0000000 --- a/DynamicMemory/LD_24/Code/ProductNode.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; - -namespace LD_24.Code -{ - public class ProductNode - { - public Product Data { get; set; } - public ProductNode Next { get; set; } - - public ProductNode(Product data = null, ProductNode next = null) - { - Data = data; - Next = next; - } - } -} \ No newline at end of file diff --git a/DynamicMemory/LD_24/Code/TaskUtils.cs b/DynamicMemory/LD_24/Code/TaskUtils.cs index 0a33d58..e672b5e 100644 --- a/DynamicMemory/LD_24/Code/TaskUtils.cs +++ b/DynamicMemory/LD_24/Code/TaskUtils.cs @@ -8,62 +8,88 @@ namespace LD_24.Code { public static class TaskUtils { - public static string FindMostPopularProduct(CustomerList customers) + public static List FindMostPopularProducts(OrderList orders) { - Dictionary productCounter = new Dictionary(); - foreach (Customer customer in customers) + Dictionary productSales = new Dictionary(); + foreach (Order order in orders) { - if (!productCounter.ContainsKey(customer.ProductID)) + if (!productSales.ContainsKey(order.ProductID)) { - productCounter.Add(customer.ProductID, 1); + productSales.Add(order.ProductID, order.ProductAmount); } else { - productCounter[customer.ProductID]++; + productSales[order.ProductID] += order.ProductAmount; } } - string mostPopularProduct = null; + List mostPopularProducts = new List(); int mostPopularCount = 0; - foreach (string product in productCounter.Keys) + foreach (string product in productSales.Keys) { - int count = productCounter[product]; + int count = productSales[product]; if (count > mostPopularCount) { mostPopularCount = count; - mostPopularProduct = product; + mostPopularProducts = new List { product }; + } else if (count == mostPopularCount) + { + mostPopularProducts.Add(product); } } - return mostPopularProduct; + return mostPopularProducts; } - public static int CountProductSales(CustomerList customers, string product) + public static int CountProductSales(OrderList orders, string product) { int sales = 0; - foreach (Customer customer in customers) + foreach (Order order in orders) { - if (customer.ProductID == product) + if (order.ProductID == product) { - sales += customer.ProductAmount; + sales += order.ProductAmount; } } return sales; } - public static CustomerList FilterByProduct(CustomerList customers, string product) + public static OrderList FilterByProduct(OrderList orders, string product) { - CustomerList filtered = new CustomerList(); - foreach (Customer customer in customers) + OrderList filtered = new OrderList(); + foreach (Order order in orders) { - if (customer.ProductID == product) + if (order.ProductID == product) { - filtered.AddToEnd(customer); + filtered.AddToEnd(order); } } return filtered; } + public static OrderList MergeOrders(OrderList orders) + { + Dictionary, Order> ordersByName = new Dictionary, Order>(); + foreach (var order in orders) + { + var key = Tuple.Create(order.CustomerSurname, order.CustomerName, order.ProductID); + if (ordersByName.ContainsKey(key)) + { + ordersByName[key].ProductAmount += order.ProductAmount; + } else + { + ordersByName.Add(key, new Order(order.CustomerSurname, order.CustomerName, order.ProductID, order.ProductAmount)); + } + } + + OrderList mergedOrders = new OrderList(); + foreach (var order in ordersByName.Values) + { + mergedOrders.AddToEnd(order); + } + return mergedOrders; + } + public static Product FindByID(ProductList products, string id) { foreach (Product product in products) @@ -76,28 +102,28 @@ namespace LD_24.Code return null; } - public static ProductList FilterByMaxPrice(ProductList products, decimal maxPrice) + public static ProductList FindByID(ProductList products, List ids) + { + ProductList foundProducts = new ProductList(); + foreach (string id in ids) + { + foundProducts.AddToEnd(FindByID(products, id)); + } + return foundProducts; + } + + public static ProductList FilterByQuantitySoldAndPrice(ProductList products, OrderList customers, int minSold, decimal maxPrice) { ProductList filtered = new ProductList(); foreach (Product product in products) { if (product.Price < maxPrice) { - filtered.AddToEnd(product); - } - } - return filtered; - } - - public static ProductList FilterByMinQuantitySold(ProductList products, CustomerList customers, decimal minSold) - { - ProductList filtered = new ProductList(); - foreach (Product product in products) - { - int sold = CountProductSales(customers, product.ID); - if (sold >= minSold) - { - filtered.AddToEnd(product); + int sold = CountProductSales(customers, product.ID); + if (sold >= minSold) + { + filtered.AddToEnd(product); + } } } return filtered; diff --git a/DynamicMemory/LD_24/Forma1.aspx b/DynamicMemory/LD_24/Forma1.aspx index 42bf752..3c5ae2b 100644 --- a/DynamicMemory/LD_24/Forma1.aspx +++ b/DynamicMemory/LD_24/Forma1.aspx @@ -4,28 +4,12 @@ - +
- - - -
- - - -
- -
-
- - - -
-
+ -

@@ -38,11 +22,26 @@

-
-
- - - +
+
+
+
+ + + + + + + + + + +
+
+ + + +
diff --git a/DynamicMemory/LD_24/Forma1.aspx.cs b/DynamicMemory/LD_24/Forma1.aspx.cs index 0352a5b..cc128b4 100644 --- a/DynamicMemory/LD_24/Forma1.aspx.cs +++ b/DynamicMemory/LD_24/Forma1.aspx.cs @@ -16,49 +16,50 @@ namespace LD_24 private const string inputFileB = "App_Data/U24b.txt"; private const string outputFilename = "App_Data/Rezultatai.txt"; - private ProductList Products; - private CustomerList Customers; - - private Product PopularProduct; - private Product TargetProduct; - private CustomerList CustomersByTargetProduct; - protected void Page_Load(object sender, EventArgs e) { - Products = InOutUtils.ReadProducts(Server.MapPath(inputFileA)); - Customers = InOutUtils.ReadCustomers(Server.MapPath(inputFileB)); - ShowProducts(Table1, Products); - ShowCustomers(Table2, Customers); - - string popularProductID = TaskUtils.FindMostPopularProduct(Customers); - PopularProduct = null; - if (popularProductID != null) - { - PopularProduct = TaskUtils.FindByID(Products, popularProductID); - } - - TargetProduct = TaskUtils.FindByID(Products, targetProductID); - CustomersByTargetProduct = TaskUtils.FilterByProduct(Customers, targetProductID); - CustomersByTargetProduct.Sort(); - - ShowMostPopularProduct(Label3, Customers, PopularProduct); - - Label4.Text = $"Pirkėjai pagal rūšį ({TargetProduct.Name}):"; - ShowCustomersByProduct(Table3, CustomersByTargetProduct, TargetProduct); + FindControl("ResultsDiv").Visible = false; } protected void Button1_Click(object sender, EventArgs e) { int n = int.Parse(TextBox1.Text); decimal k = decimal.Parse(TextBox2.Text); - ProductList filteredProducts = TaskUtils.FilterByMinQuantitySold(TaskUtils.FilterByMaxPrice(Products, k), Customers, n); + FindControl("ResultsDiv").Visible = true; + + ProductList products = InOutUtils.ReadProducts(Server.MapPath(inputFileA)); + OrderList orders = InOutUtils.ReadOrders(Server.MapPath(inputFileB)); + + List mostPopularProductIds = TaskUtils.FindMostPopularProducts(orders); + ProductList mostPopularProducts = TaskUtils.FindByID(products, mostPopularProductIds); + ProductList filteredProducts = TaskUtils.FilterByQuantitySoldAndPrice(products, orders, n, k); + + ShowProducts(Table1, products); + ShowOrders(Table2, orders); + ShowMostPopularProducts(Table5, orders, mostPopularProducts); + ShowOrdersByProduct(FindControl("OrdersByProductContainer"), orders, products); ShowProducts(Table4, filteredProducts); using (StreamWriter writer = new StreamWriter(Server.MapPath(outputFilename))) { - InOutUtils.PrintProducts(writer, Products, "Įtaisai"); - InOutUtils.PrintCustomers(writer, Customers, "Pirkėjai"); + InOutUtils.PrintProducts(writer, products, "Įtaisai"); + InOutUtils.PrintOrders(writer, orders, "Pirkėjai"); + InOutUtils.PrintMostPopularProducts(writer, orders, mostPopularProducts, "Populiariausi įtaisai"); + + writer.WriteLine("Pirkėjai pagal rūšį:"); + foreach (Product product in products) + { + InOutUtils.PrintOrdersWithPrices(writer, orders, product, product.Name); + } + + InOutUtils.PrintProducts(writer, filteredProducts, $"Atrinkti įtaisai (n={n}, k={k:f2})"); + } + + /* + using (StreamWriter writer = new StreamWriter(Server.MapPath(outputFilename))) + { + writer.Write("Populiariausias produktas: "); if (PopularProduct == null) @@ -77,7 +78,7 @@ namespace LD_24 InOutUtils.PrintCustomersWithPrices(writer, CustomersByTargetProduct, TargetProduct, $"Pirkėjai pagal rūšį ({TargetProduct.Name})"); InOutUtils.PrintProducts(writer, filteredProducts, $"Atrinkti įtaisai (n={n}, k={k:f2})"); - } + }*/ } } } \ No newline at end of file diff --git a/DynamicMemory/LD_24/Forma1.aspx.designer.cs b/DynamicMemory/LD_24/Forma1.aspx.designer.cs index 9a40019..a479e24 100644 --- a/DynamicMemory/LD_24/Forma1.aspx.designer.cs +++ b/DynamicMemory/LD_24/Forma1.aspx.designer.cs @@ -23,69 +23,6 @@ namespace LD_24 /// protected global::System.Web.UI.HtmlControls.HtmlForm form1; - /// - /// Label1 control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.WebControls.Label Label1; - - /// - /// Table1 control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.WebControls.Table Table1; - - /// - /// Label2 control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.WebControls.Label Label2; - - /// - /// Table2 control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.WebControls.Table Table2; - - /// - /// Label3 control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.WebControls.Label Label3; - - /// - /// Label4 control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.WebControls.Label Label4; - - /// - /// Table3 control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.WebControls.Table Table3; - /// /// ValidationSummary1 control. /// @@ -158,6 +95,87 @@ namespace LD_24 /// protected global::System.Web.UI.WebControls.Button Button1; + /// + /// ResultsDiv control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.HtmlControls.HtmlGenericControl ResultsDiv; + + /// + /// Label1 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Label Label1; + + /// + /// Table1 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Table Table1; + + /// + /// Label2 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Label Label2; + + /// + /// Table2 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Table Table2; + + /// + /// Label8 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Label Label8; + + /// + /// Table5 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Table Table5; + + /// + /// Label4 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Label Label4; + + /// + /// OrdersByProductContainer control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.HtmlControls.HtmlGenericControl OrdersByProductContainer; + /// /// Label7 control. /// diff --git a/DynamicMemory/LD_24/Forma1Utils.aspx.cs b/DynamicMemory/LD_24/Forma1Utils.aspx.cs index d62b903..1d17cc6 100644 --- a/DynamicMemory/LD_24/Forma1Utils.aspx.cs +++ b/DynamicMemory/LD_24/Forma1Utils.aspx.cs @@ -10,83 +10,131 @@ namespace LD_24 { public partial class Forma1 : System.Web.UI.Page { - public void ShowProducts(Table table, ProductList products) + private IEnumerable> ShowProdcutsTable(Table table, ProductList products, params string[] columns) { table.Rows.Clear(); TableRow header = new TableRow(); - header.Cells.Add(new TableCell { Text = "ID" }); - header.Cells.Add(new TableCell { Text = "Vardas" }); - header.Cells.Add(new TableCell { Text = "Kaina, eur." }); + foreach (string column in columns) + { + header.Cells.Add(new TableCell { Text = column }); + } table.Rows.Add(header); - foreach (Product product in products) + if (products.Count() > 0) { + foreach (Product product in products) + { + TableRow row = new TableRow(); + yield return Tuple.Create(product, row); + table.Rows.Add(row); + } + } else { TableRow row = new TableRow(); + row.Cells.Add(new TableCell { Text = "Nėra", ColumnSpan = columns.Length }); + table.Rows.Add(row); + } + } + + private IEnumerable> ShowOrdersTable(Table table, string title, OrderList orders, params string[] columns) + { + table.Rows.Clear(); + + if (title != null) + { + TableRow row = new TableRow(); + row.Cells.Add(new TableCell { Text = title, ColumnSpan = columns.Length }); + table.Rows.Add(row); + } + + TableRow header = new TableRow(); + foreach (string column in columns) + { + header.Cells.Add(new TableCell { Text = column }); + } + table.Rows.Add(header); + + if (orders.Count() > 0) + { + foreach (Order order in orders) + { + TableRow row = new TableRow(); + yield return Tuple.Create(order, row); + table.Rows.Add(row); + } + } + else + { + TableRow row = new TableRow(); + row.Cells.Add(new TableCell { Text = "Nėra", ColumnSpan = columns.Length }); + table.Rows.Add(row); + } + } + + private IEnumerable> ShowOrdersTable(Table table, OrderList orders, params string[] columns) + { + return ShowOrdersTable(table, null, orders, columns); + } + + public void ShowProducts(Table table, ProductList products) + { + foreach (var tuple in ShowProdcutsTable(table, products, "ID", "Vardas", "Kaina, eur.")) + { + Product product = tuple.Item1; + TableRow row = tuple.Item2; row.Cells.Add(new TableCell { Text = product.ID }); row.Cells.Add(new TableCell { Text = product.Name }); row.Cells.Add(new TableCell { Text = product.Price.ToString() }); - table.Rows.Add(row); } } - public void ShowCustomers(Table table, CustomerList customers) + public void ShowOrders(Table table, OrderList orders) { - table.Rows.Clear(); - - TableRow header = new TableRow(); - header.Cells.Add(new TableCell { Text = "Pavardė" }); - header.Cells.Add(new TableCell { Text = "Vardas" }); - header.Cells.Add(new TableCell { Text = "Įtaisas" }); - header.Cells.Add(new TableCell { Text = "Įtaiso kiekis, vnt." }); - table.Rows.Add(header); - - foreach (Customer customer in customers) + foreach (var tuple in ShowOrdersTable(table, orders, "Pavardė", "Vardas", "Įtaisas", "Įtaisų kiekis, vnt.")) { - TableRow row = new TableRow(); - row.Cells.Add(new TableCell { Text = customer.Surname }); - row.Cells.Add(new TableCell { Text = customer.Name }); - row.Cells.Add(new TableCell { Text = customer.ProductID.ToString() }); - row.Cells.Add(new TableCell { Text = customer.ProductAmount.ToString() }); - table.Rows.Add(row); + Order order = tuple.Item1; + TableRow row = tuple.Item2; + row.Cells.Add(new TableCell { Text = order.CustomerSurname }); + row.Cells.Add(new TableCell { Text = order.CustomerName }); + row.Cells.Add(new TableCell { Text = order.ProductID.ToString() }); + row.Cells.Add(new TableCell { Text = order.ProductAmount.ToString() }); } } - public void ShowMostPopularProduct(Label label, CustomerList customers, Product product) + public void ShowMostPopularProducts(Table table, OrderList orders, ProductList popularProducts) { - label.Text = "Populiariausias produktas: "; - if (product == null) + foreach (var tuple in ShowProdcutsTable(table, popularProducts, "ID", "Vardas", "Įtaisų kiekis, vnt.", "Įtaisų kaina, eur.")) { - label.Text = "Nėra"; - return; + Product product = tuple.Item1; + TableRow row = tuple.Item2; + int sales = TaskUtils.CountProductSales(orders, product.ID); + row.Cells.Add(new TableCell { Text = product.ID }); + row.Cells.Add(new TableCell { Text = product.Name }); + row.Cells.Add(new TableCell { Text = sales.ToString() }); + row.Cells.Add(new TableCell { Text = String.Format("{0:f2}", sales * product.Price) }); } - - label.Text += $"{product.Name}
"; - - int sales = TaskUtils.CountProductSales(customers, product.ID); - label.Text += $"Pardavimų kiekis: {sales} vnt.
"; - label.Text += $"Pardavimų kaina: {sales*product.Price:f2} eur."; } - public void ShowCustomersByProduct(Table table, CustomerList customers, Product product) + public void ShowOrdersByProduct(Control container, OrderList orders, ProductList products) { - table.Rows.Clear(); - - TableRow header = new TableRow(); - header.Cells.Add(new TableCell { Text = "Pavardė" }); - header.Cells.Add(new TableCell { Text = "Vardas" }); - header.Cells.Add(new TableCell { Text = "Įtaisas kiekis, vnt." }); - header.Cells.Add(new TableCell { Text = "Kaina, eur." }); - table.Rows.Add(header); - - foreach (Customer customer in customers) + container.Controls.Clear(); + foreach (Product product in products) { - TableRow row = new TableRow(); - row.Cells.Add(new TableCell { Text = customer.Surname }); - row.Cells.Add(new TableCell { Text = customer.Name }); - row.Cells.Add(new TableCell { Text = customer.ProductAmount.ToString() }); - row.Cells.Add(new TableCell { Text = (Math.Round(customer.ProductAmount*product.Price, 2)).ToString() }); - table.Rows.Add(row); + OrderList filtered = TaskUtils.FilterByProduct(orders, product.ID); + filtered = TaskUtils.MergeOrders(filtered); + filtered.Sort(); + + Table table = new Table(); + container.Controls.Add(table); + foreach (var tuple in ShowOrdersTable(table, product.Name, filtered, "Pavardė", "Vardas", "Įtaisų kiekis, vnt.", "Sumokėta, eur.")) + { + Order order = tuple.Item1; + TableRow row = tuple.Item2; + row.Cells.Add(new TableCell { Text = order.CustomerSurname }); + row.Cells.Add(new TableCell { Text = order.CustomerName }); + row.Cells.Add(new TableCell { Text = order.ProductAmount.ToString() }); + row.Cells.Add(new TableCell { Text = String.Format("{0:f2}", order.ProductAmount * product.Price, 2) }); + } } } } diff --git a/DynamicMemory/LD_24/LD_24.csproj b/DynamicMemory/LD_24/LD_24.csproj index 1a3ddb0..755840c 100644 --- a/DynamicMemory/LD_24/LD_24.csproj +++ b/DynamicMemory/LD_24/LD_24.csproj @@ -72,16 +72,15 @@ + - - - + + - Forma1.aspx diff --git a/DynamicMemory/LD_24/Styles/main.css b/DynamicMemory/LD_24/Styles/main.css new file mode 100644 index 0000000..d479be0 --- /dev/null +++ b/DynamicMemory/LD_24/Styles/main.css @@ -0,0 +1,10 @@ +table, th, td { + border: 1px solid black; + border-collapse: collapse; +} + +table { + margin-bottom: 1em; + background-color: #FFFFCC; +} +