1
0

fix: final working code for DynamicMemory.LD_24

This commit is contained in:
Rokas Puzonas 2022-03-14 14:13:41 +02:00
parent 3bc94fc52a
commit ba678342e4
11 changed files with 249 additions and 298 deletions

View File

@ -1,80 +1,55 @@
------------------------------------------ ----------------------------
| Įtaisai | | Įtaisai |
------------------------------------------ ----------------------------
| ID | Vardas | Kaina | | ID | Vardas | Kaina |
------------------------------------------ ----------------------------
| 0 | Atsuktuvas | 0.99 | | 0 | Atsuktuvas | 0,99 |
| 1 | Varztas | 0.05 | | 1 | Varztas | 0,05 |
| 2 | Laidas | 2.00 | | 2 | Laidas | 2,00 |
| 3 | Plaktukas | 2.99 | | 3 | Plaktukas | 2,99 |
------------------------------------------ ----------------------------
--------------------------------------------------------------- --------------------------------------------------
| Pirkėjai | | Pirkėjai |
--------------------------------------------------------------- --------------------------------------------------
| Pavardė | Vardas | Įtaisas | Įtaiso kiekis | | Pavardė | Vardas | Įtaisas | Įtaiso kiekis |
--------------------------------------------------------------- --------------------------------------------------
| Petraitis | Petras | 0 | 10 | | Petraitis | Petras | 0 | 10 |
| Petraitis | Petras | 1 | 10 |
| Jonaitis | Jonas | 1 | 20 | | Jonaitis | Jonas | 1 | 20 |
| Jonaitis | Jonas | 1 | 20 | | Jonaitis | Jonas | 1 | 20 |
| Jonaitis | Jonas | 1 | 20 | | Jonaitis | Jonas | 1 | 20 |
| Onaite | Ona | 2 | 200 | | Onaite | Ona | 2 | 200 |
| Jonaitis | Brolis | 1 | 100 | | Jonaitis | Brolis | 1 | 100 |
| Jonaitis | Brolis | 0 | 100 |
| Jonaitis | Jonas | 1 | 20 | | Jonaitis | Jonas | 1 | 20 |
| Jonaitis | Jonas | 1 | 20 | | Jonaitis | Jonas | 1 | 20 |
| Jonaitis | Jonas | 2 | 20 |
| Onaite | Ona | 0 | 20 | | Onaite | Ona | 0 | 20 |
--------------------------------------------------------------- --------------------------------------------------
--------------------------------------------------------------------------- ------------------------------------------------------------
| Populiariausi įtaisai | | Populiariausi įtaisai |
--------------------------------------------------------------------------- ------------------------------------------------------------
| ID | Vardas | Įtaisų kiekis, vnt. | Įtaisų kaina, eur. | | ID | Vardas | Įtaisų kiekis, vnt. | Įtaisų kaina, eur. |
--------------------------------------------------------------------------- ------------------------------------------------------------
| 1 | Varztas | 200 | 10.00 | | 2 | Laidas | 220 | 440,00 |
| 2 | Laidas | 200 | 400.00 | ------------------------------------------------------------
---------------------------------------------------------------------------
Pirkėjai pagal rūšį: ----------------------------------------------------------
--------------------------------------------------------------- | Vienos rūšies pirkėjai |
| Atsuktuvas | ----------------------------------------------------------
--------------------------------------------------------------- | Pavardė | Vardas | Įtaiso kiekis, vnt. | Kaina, eur. |
| Pavardė | Vardas | Įtaiso kiekis | Kaina | ----------------------------------------------------------
---------------------------------------------------------------
| Onaite | Ona | 20 | 19.80 |
| Petraitis | Petras | 10 | 9.90 |
---------------------------------------------------------------
---------------------------------------------------------------
| Varztas |
---------------------------------------------------------------
| Pavardė | Vardas | Įtaiso kiekis | Kaina |
---------------------------------------------------------------
| Jonaitis | Brolis | 100 | 5.00 |
| Jonaitis | Jonas | 100 | 5.00 |
---------------------------------------------------------------
---------------------------------------------------------------
| Laidas |
---------------------------------------------------------------
| Pavardė | Vardas | Įtaiso kiekis | Kaina |
---------------------------------------------------------------
| Onaite | Ona | 200 | 400.00 |
---------------------------------------------------------------
---------------------------------------------------------------
| Plaktukas |
---------------------------------------------------------------
| Pavardė | Vardas | Įtaiso kiekis | Kaina |
---------------------------------------------------------------
| Nėra | | Nėra |
--------------------------------------------------------------- ----------------------------------------------------------
------------------------------------------ ----------------------------------
| Atrinkti įtaisai (n=1, k=1.00) | | Atrinkti įtaisai (n=1, k=1,00) |
------------------------------------------ ----------------------------------
| ID | Vardas | Kaina | | ID | Vardas | Kaina |
------------------------------------------ ----------------------------------
| 0 | Atsuktuvas | 0.99 | | 0 | Atsuktuvas | 0,99 |
| 1 | Varztas | 0.05 | | 1 | Varztas | 0,05 |
------------------------------------------ ----------------------------------

View File

@ -1,9 +1,12 @@
Petraitis, Petras, 0, 10 Petraitis, Petras, 0, 10
Petraitis, Petras, 1, 10
Jonaitis, Jonas, 1, 20 Jonaitis, Jonas, 1, 20
Jonaitis, Jonas, 1, 20 Jonaitis, Jonas, 1, 20
Jonaitis, Jonas, 1, 20 Jonaitis, Jonas, 1, 20
Onaite, Ona, 2, 200 Onaite, Ona, 2, 200
Jonaitis, Brolis, 1, 100 Jonaitis, Brolis, 1, 100
Jonaitis, Brolis, 0, 100
Jonaitis, Jonas, 1, 20 Jonaitis, Jonas, 1, 20
Jonaitis, Jonas, 1, 20 Jonaitis, Jonas, 1, 20
Jonaitis, Jonas, 2, 20
Onaite, Ona, 0, 20 Onaite, Ona, 0, 20

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
@ -49,99 +50,136 @@ namespace LD_24.Code
return orders; return orders;
} }
private static void PrintTableRow(StreamWriter writer, List<string> cells, List<int> widths)
{
for (int i = 0; i < widths.Count; i++)
{
if (widths[i] < 0)
writer.Write("| {0} ", cells[i].PadRight(-widths[i]));
else
writer.Write("| {0} ", cells[i].PadLeft(widths[i]));
}
writer.WriteLine("|");
}
private static IEnumerable<Tuple<object, List<String>>> PrintTable(StreamWriter writer, string header, IEnumerable list, params string[] columns)
{
// 0. Collect all the rows
List<List<string>> rows = new List<List<string>>();
foreach (object item in list)
{
List<string> row = new List<string>();
yield return Tuple.Create(item, row);
rows.Add(row);
}
// 1. Determine the width of each column
List<int> widths = new List<int>();
int totalWidth = 3*(columns.Length - 1);
for (int i = 0; i < columns.Length; i++)
{
int width = columns[i].Length;
foreach (var row in rows)
{
width = Math.Max(row[i].Length, width);
}
widths.Add(width);
totalWidth += width;
}
// If the header is longer than the body, make the last column wider.
// So the table is a nice rectangle when output to the file
if (header.Length > totalWidth)
{
widths[widths.Count - 1] += (header.Length - totalWidth);
totalWidth = header.Length;
}
totalWidth += 2 * 2;
// 2. Adjust widths to account for aligning
for (int i = 0; i < columns.Length; i++)
{
if (columns[i][0] == '-')
{
widths[i] = -widths[i];
columns[i] = columns[i].Substring(1);
}
}
// 3. Display the table
writer.WriteLine(new string('-', totalWidth));
writer.WriteLine("| {0} |", header.PadRight(totalWidth - 4));
writer.WriteLine(new string('-', totalWidth));
PrintTableRow(writer, new List<string>(columns), widths);
writer.WriteLine(new string('-', totalWidth));
if (rows.Count > 0)
{
foreach (var row in rows)
{
PrintTableRow(writer, row, widths);
}
} else
{
writer.WriteLine("| {0} |", "Nėra".PadRight(totalWidth - 4));
}
writer.WriteLine(new string('-', totalWidth));
writer.WriteLine();
}
public static void PrintOrders(StreamWriter writer, OrderList orders, string header) public static void PrintOrders(StreamWriter writer, OrderList orders, string header)
{ {
writer.WriteLine(new string('-', 63)); foreach (var tuple in PrintTable(writer, header, orders, "Pavardė", "Vardas", "-Įtaisas", "-Įtaiso kiekis"))
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 (orders.Count() > 0)
{ {
foreach (Order o in orders) Order order = (Order)tuple.Item1;
{ List<string> row = tuple.Item2;
writer.WriteLine("| {0, -15} | {1, -15} | {2, 7} | {3, 13} |", o.CustomerSurname, o.CustomerName, o.ProductID, o.ProductAmount); row.Add(order.CustomerSurname);
row.Add(order.CustomerName);
row.Add(order.ProductID);
row.Add(order.ProductAmount.ToString());
} }
} }
else
{
writer.WriteLine("| {0, -59} |", "Nėra");
}
writer.WriteLine(new string('-', 63));
writer.WriteLine();
}
public static void PrintOrdersWithPrices(StreamWriter writer, OrderList orders, Product product, string header) public static void PrintOrdersWithPrices(StreamWriter writer, OrderList orders, ProductList products, string header)
{ {
writer.WriteLine(new string('-', 63)); foreach (var tuple in PrintTable(writer, header, orders, "Pavardė", "Vardas", "-Įtaiso kiekis, vnt.", "-Kaina, eur."))
writer.WriteLine("| {0, -59} |", header); {
writer.WriteLine(new string('-', 63)); Order order = (Order)tuple.Item1;
writer.WriteLine("| {0, -15} | {1, -15} | {2, 13} | {3, 7} |", "Pavardė", "Vardas", "Įtaiso kiekis", "Kaina"); List<string> row = tuple.Item2;
writer.WriteLine(new string('-', 63)); Product product = TaskUtils.FindByID(products, order.ProductID);
OrderList filtered = TaskUtils.FilterByProduct(orders, product.ID); row.Add(order.CustomerSurname);
filtered = TaskUtils.MergeOrders(filtered); row.Add(order.CustomerName);
filtered.Sort(); row.Add(order.ProductAmount.ToString());
row.Add(String.Format("{0:f2}", order.ProductAmount * product.Price));
if (filtered.Count() > 0)
{
foreach (Order o in filtered)
{
writer.WriteLine("| {0, -15} | {1, -15} | {2, 13} | {3, 7:f2} |", o.CustomerSurname, o.CustomerName, o.ProductAmount, o.ProductAmount*product.Price);
} }
} }
else
{
writer.WriteLine("| {0, -59} |", "Nėra");
}
writer.WriteLine(new string('-', 63));
writer.WriteLine();
}
public static void PrintProducts(StreamWriter writer, ProductList products, string header) public static void PrintProducts(StreamWriter writer, ProductList products, string header)
{ {
writer.WriteLine(new string('-', 42)); foreach (var tuple in PrintTable(writer, header, products, "ID", "Vardas", "-Kaina"))
writer.WriteLine("| {0, -38} |", header);
writer.WriteLine(new string('-', 42));
writer.WriteLine("| {0, -5} | {1, -20} | {2, 7} |", "ID", "Vardas", "Kaina");
writer.WriteLine(new string('-', 42));
if (products.Count() > 0)
{ {
foreach (Product c in products) Product product = (Product)tuple.Item1;
{ List<string> row = tuple.Item2;
writer.WriteLine("| {0, -5} | {1, -20} | {2, 7} |", c.ID, c.Name, c.Price); row.Add(product.ID);
row.Add(product.Name);
row.Add(String.Format("{0:f2}", product.Price));
} }
} }
else
{
writer.WriteLine("| {0, -38} |", "Nėra");
}
writer.WriteLine(new string('-', 42));
writer.WriteLine();
}
public static void PrintMostPopularProducts(StreamWriter writer, OrderList orders, ProductList popularProducts, string header) public static void PrintMostPopularProducts(StreamWriter writer, OrderList orders, ProductList popularProducts, string header)
{ {
writer.WriteLine(new string('-', 75)); foreach (var tuple in PrintTable(writer, header, popularProducts, "ID", "Vardas", "-Įtaisų kiekis, vnt.", "-Įtaisų kaina, eur."))
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) Product product = (Product)tuple.Item1;
{ List<string> row = tuple.Item2;
int sales = TaskUtils.CountProductSales(orders, p.ID); int sales = TaskUtils.CountProductSales(orders, product.ID);
writer.WriteLine("| {0, -5} | {1, -20} | {2, 19} | {3, 18:f2} |", p.ID, p.Name, sales, sales*p.Price); row.Add(product.ID);
row.Add(product.Name);
row.Add(sales.ToString());
row.Add(String.Format("{0:f2}", sales * product.Price));
} }
} }
else
{
writer.WriteLine("| {0, -71} |", "Nėra");
}
writer.WriteLine(new string('-', 75));
writer.WriteLine();
}
} }
} }

View File

@ -53,18 +53,6 @@ namespace LD_24.Code
} }
} }
public Order Get(int index)
{
int i = 0;
OrderNode current = head;
while (i < index && current != null)
{
current = head.Next;
i++;
}
return current.Data;
}
public int Count() public int Count()
{ {
int count = 0; int count = 0;

View File

@ -53,18 +53,6 @@ namespace LD_24.Code
} }
} }
public Product Get(int index)
{
int i = 0;
ProductNode current = head;
while (i < index && current != null)
{
current = head.Next;
i++;
}
return current.Data;
}
public int Count() public int Count()
{ {
int count = 0; int count = 0;

View File

@ -129,5 +129,29 @@ namespace LD_24.Code
return filtered; return filtered;
} }
public static OrderList FindCustomerWithSingleProduct(OrderList orders)
{
Dictionary<Tuple<string, string>, OrderList> ordersByCusomer = new Dictionary<Tuple<string, string>, OrderList>();
foreach (var order in TaskUtils.MergeOrders(orders))
{
var key = Tuple.Create(order.CustomerName, order.CustomerSurname);
if (!ordersByCusomer.ContainsKey(key))
{
ordersByCusomer.Add(key, new OrderList());
}
ordersByCusomer[key].AddToEnd(order);
}
OrderList finalList = new OrderList();
foreach (var customerOrders in ordersByCusomer.Values)
{
if (customerOrders.Count() == 1)
{
finalList.AddToEnd(customerOrders.First());
}
}
return finalList;
}
} }
} }

View File

@ -35,9 +35,9 @@
<asp:Label ID="Label8" runat="server" Text="Populiariausi įtaisai:"></asp:Label> <asp:Label ID="Label8" runat="server" Text="Populiariausi įtaisai:"></asp:Label>
<asp:Table ID="Table5" runat="server"> <asp:Table ID="Table5" runat="server">
</asp:Table> </asp:Table>
<asp:Label ID="Label4" runat="server" Text="Pirkėjai pagal rūšį:"></asp:Label> <asp:Label ID="Label4" runat="server" Text="Vienos rūšies pirkėjai:"></asp:Label>
<div id="OrdersByProductContainer" runat="server"> <asp:Table ID="Table3" runat="server">
</div> </asp:Table>
<asp:Label ID="Label7" runat="server" Text="Atrinkti įtaisai:"></asp:Label> <asp:Label ID="Label7" runat="server" Text="Atrinkti įtaisai:"></asp:Label>
<asp:Table ID="Table4" runat="server"> <asp:Table ID="Table4" runat="server">
</asp:Table> </asp:Table>

View File

@ -34,11 +34,13 @@ namespace LD_24
List<string> mostPopularProductIds = TaskUtils.FindMostPopularProducts(orders); List<string> mostPopularProductIds = TaskUtils.FindMostPopularProducts(orders);
ProductList mostPopularProducts = TaskUtils.FindByID(products, mostPopularProductIds); ProductList mostPopularProducts = TaskUtils.FindByID(products, mostPopularProductIds);
ProductList filteredProducts = TaskUtils.FilterByQuantitySoldAndPrice(products, orders, n, k); ProductList filteredProducts = TaskUtils.FilterByQuantitySoldAndPrice(products, orders, n, k);
OrderList customersWithSingleProduct = TaskUtils.FindCustomerWithSingleProduct(orders);
customersWithSingleProduct.Sort();
ShowProducts(Table1, products); ShowProducts(Table1, products);
ShowOrders(Table2, orders); ShowOrders(Table2, orders);
ShowMostPopularProducts(Table5, orders, mostPopularProducts); ShowMostPopularProducts(Table5, orders, mostPopularProducts);
ShowOrdersByProduct(FindControl("OrdersByProductContainer"), orders, products); ShowOrdersWithPrices(Table3, customersWithSingleProduct, products);
ShowProducts(Table4, filteredProducts); ShowProducts(Table4, filteredProducts);
using (StreamWriter writer = new StreamWriter(Server.MapPath(outputFilename))) using (StreamWriter writer = new StreamWriter(Server.MapPath(outputFilename)))
@ -46,39 +48,9 @@ namespace LD_24
InOutUtils.PrintProducts(writer, products, "Įtaisai"); InOutUtils.PrintProducts(writer, products, "Įtaisai");
InOutUtils.PrintOrders(writer, orders, "Pirkėjai"); InOutUtils.PrintOrders(writer, orders, "Pirkėjai");
InOutUtils.PrintMostPopularProducts(writer, orders, mostPopularProducts, "Populiariausi įtaisai"); InOutUtils.PrintMostPopularProducts(writer, orders, mostPopularProducts, "Populiariausi įtaisai");
InOutUtils.PrintOrdersWithPrices(writer, customersWithSingleProduct, products, "Vienos rūšies pirkėjai");
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})"); 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)
{
writer.WriteLine("Nėra");
}
else
{
writer.WriteLine(PopularProduct.Name);
int sales = TaskUtils.CountProductSales(Customers, PopularProduct.ID);
writer.WriteLine($"Pardavimų kiekis: {sales} vnt.");
writer.WriteLine($"Pardavimų kaina: {sales * PopularProduct.Price:f2} eur.");
}
writer.WriteLine();
InOutUtils.PrintCustomersWithPrices(writer, CustomersByTargetProduct, TargetProduct, $"Pirkėjai pagal rūšį ({TargetProduct.Name})");
InOutUtils.PrintProducts(writer, filteredProducts, $"Atrinkti įtaisai (n={n}, k={k:f2})");
}*/
} }
} }
} }

View File

@ -7,12 +7,10 @@
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
namespace LD_24 namespace LD_24 {
{
public partial class Forma1 public partial class Forma1 {
{
/// <summary> /// <summary>
/// form1 control. /// form1 control.
@ -168,13 +166,13 @@ namespace LD_24
protected global::System.Web.UI.WebControls.Label Label4; protected global::System.Web.UI.WebControls.Label Label4;
/// <summary> /// <summary>
/// OrdersByProductContainer control. /// Table3 control.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// Auto-generated field. /// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file. /// To modify move field declaration from designer file to code-behind file.
/// </remarks> /// </remarks>
protected global::System.Web.UI.HtmlControls.HtmlGenericControl OrdersByProductContainer; protected global::System.Web.UI.WebControls.Table Table3;
/// <summary> /// <summary>
/// Label7 control. /// Label7 control.

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Web; using System.Web;
@ -10,10 +11,8 @@ namespace LD_24
{ {
public partial class Forma1 : System.Web.UI.Page public partial class Forma1 : System.Web.UI.Page
{ {
private IEnumerable<Tuple<Product, TableRow>> ShowProdcutsTable(Table table, ProductList products, params string[] columns) private IEnumerable<Tuple<object, TableRow>> ShowTable(Table table, IEnumerable list, params string[] columns)
{ {
table.Rows.Clear();
TableRow header = new TableRow(); TableRow header = new TableRow();
foreach (string column in columns) foreach (string column in columns)
{ {
@ -21,14 +20,16 @@ namespace LD_24
} }
table.Rows.Add(header); table.Rows.Add(header);
if (products.Count() > 0) { int n = 0;
foreach (Product product in products) foreach (object item in list)
{ {
TableRow row = new TableRow(); TableRow row = new TableRow();
yield return Tuple.Create(product, row); yield return Tuple.Create(item, row);
table.Rows.Add(row); table.Rows.Add(row);
n++;
} }
} else
if (n == 0)
{ {
TableRow row = new TableRow(); TableRow row = new TableRow();
row.Cells.Add(new TableCell { Text = "Nėra", ColumnSpan = columns.Length }); row.Cells.Add(new TableCell { Text = "Nėra", ColumnSpan = columns.Length });
@ -36,51 +37,20 @@ namespace LD_24
} }
} }
private IEnumerable<Tuple<Order, TableRow>> ShowOrdersTable(Table table, string title, OrderList orders, params string[] columns) private IEnumerable<Tuple<object, TableRow>> ShowTable(Table table, string title, IEnumerable list, params string[] columns)
{
table.Rows.Clear();
if (title != null)
{ {
TableRow row = new TableRow(); TableRow row = new TableRow();
row.Cells.Add(new TableCell { Text = title, ColumnSpan = columns.Length }); row.Cells.Add(new TableCell { Text = title, ColumnSpan = columns.Length });
table.Rows.Add(row); table.Rows.Add(row);
}
TableRow header = new TableRow(); return ShowTable(table, list, columns);
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<Tuple<Order, TableRow>> ShowOrdersTable(Table table, OrderList orders, params string[] columns)
{
return ShowOrdersTable(table, null, orders, columns);
} }
public void ShowProducts(Table table, ProductList products) public void ShowProducts(Table table, ProductList products)
{ {
foreach (var tuple in ShowProdcutsTable(table, products, "ID", "Vardas", "Kaina, eur.")) foreach (var tuple in ShowTable(table, products, "ID", "Vardas", "Kaina, eur."))
{ {
Product product = tuple.Item1; Product product = (Product)tuple.Item1;
TableRow row = tuple.Item2; TableRow row = tuple.Item2;
row.Cells.Add(new TableCell { Text = product.ID }); row.Cells.Add(new TableCell { Text = product.ID });
row.Cells.Add(new TableCell { Text = product.Name }); row.Cells.Add(new TableCell { Text = product.Name });
@ -90,9 +60,9 @@ namespace LD_24
public void ShowOrders(Table table, OrderList orders) public void ShowOrders(Table table, OrderList orders)
{ {
foreach (var tuple in ShowOrdersTable(table, orders, "Pavardė", "Vardas", "Įtaisas", "Įtaisų kiekis, vnt.")) foreach (var tuple in ShowTable(table, orders, "Pavardė", "Vardas", "Įtaisas", "Įtaisų kiekis, vnt."))
{ {
Order order = tuple.Item1; Order order = (Order)tuple.Item1;
TableRow row = tuple.Item2; TableRow row = tuple.Item2;
row.Cells.Add(new TableCell { Text = order.CustomerSurname }); row.Cells.Add(new TableCell { Text = order.CustomerSurname });
row.Cells.Add(new TableCell { Text = order.CustomerName }); row.Cells.Add(new TableCell { Text = order.CustomerName });
@ -103,9 +73,9 @@ namespace LD_24
public void ShowMostPopularProducts(Table table, OrderList orders, ProductList popularProducts) public void ShowMostPopularProducts(Table table, OrderList orders, ProductList popularProducts)
{ {
foreach (var tuple in ShowProdcutsTable(table, popularProducts, "ID", "Vardas", "Įtaisų kiekis, vnt.", "Įtaisų kaina, eur.")) foreach (var tuple in ShowTable(table, popularProducts, "ID", "Vardas", "Įtaisų kiekis, vnt.", "Įtaisų kaina, eur."))
{ {
Product product = tuple.Item1; Product product = (Product)tuple.Item1;
TableRow row = tuple.Item2; TableRow row = tuple.Item2;
int sales = TaskUtils.CountProductSales(orders, product.ID); int sales = TaskUtils.CountProductSales(orders, product.ID);
row.Cells.Add(new TableCell { Text = product.ID }); row.Cells.Add(new TableCell { Text = product.ID });
@ -115,21 +85,14 @@ namespace LD_24
} }
} }
public void ShowOrdersByProduct(Control container, OrderList orders, ProductList products) public void ShowOrdersWithPrices(Table table, OrderList orders, ProductList products)
{ {
container.Controls.Clear(); foreach (var tuple in ShowTable(table, orders, "Pavardė", "Vardas", "Įtaisų kiekis, vnt.", "Sumokėta, eur."))
foreach (Product product in products)
{ {
OrderList filtered = TaskUtils.FilterByProduct(orders, product.ID); Order order = (Order)tuple.Item1;
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; TableRow row = tuple.Item2;
Product product = TaskUtils.FindByID(products, order.ProductID);
row.Cells.Add(new TableCell { Text = order.CustomerSurname }); row.Cells.Add(new TableCell { Text = order.CustomerSurname });
row.Cells.Add(new TableCell { Text = order.CustomerName }); row.Cells.Add(new TableCell { Text = order.CustomerName });
row.Cells.Add(new TableCell { Text = order.ProductAmount.ToString() }); row.Cells.Add(new TableCell { Text = order.ProductAmount.ToString() });
@ -137,5 +100,4 @@ namespace LD_24
} }
} }
} }
}
} }

View File

@ -73,6 +73,9 @@
<Content Include="App_Data\U24a.txt" /> <Content Include="App_Data\U24a.txt" />
<Content Include="Forma1.aspx" /> <Content Include="Forma1.aspx" />
<Content Include="Styles\main.css" /> <Content Include="Styles\main.css" />
<Content Include="tests\1\inputs\U24a.txt" />
<Content Include="tests\1\inputs\U24b.txt" />
<Content Include="tests\1\outputs\Rezultatai.txt" />
<Content Include="Web.config" /> <Content Include="Web.config" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>