fix: final working code for DynamicMemory.LD_24
This commit is contained in:
parent
3bc94fc52a
commit
ba678342e4
@ -1,80 +1,55 @@
|
||||
------------------------------------------
|
||||
| Įtaisai |
|
||||
------------------------------------------
|
||||
| ID | Vardas | Kaina |
|
||||
------------------------------------------
|
||||
| 0 | Atsuktuvas | 0.99 |
|
||||
| 1 | Varztas | 0.05 |
|
||||
| 2 | Laidas | 2.00 |
|
||||
| 3 | Plaktukas | 2.99 |
|
||||
------------------------------------------
|
||||
----------------------------
|
||||
| Įtaisai |
|
||||
----------------------------
|
||||
| ID | Vardas | Kaina |
|
||||
----------------------------
|
||||
| 0 | Atsuktuvas | 0,99 |
|
||||
| 1 | Varztas | 0,05 |
|
||||
| 2 | Laidas | 2,00 |
|
||||
| 3 | Plaktukas | 2,99 |
|
||||
----------------------------
|
||||
|
||||
---------------------------------------------------------------
|
||||
| Pirkėjai |
|
||||
---------------------------------------------------------------
|
||||
| Pavardė | Vardas | Įtaisas | Įtaiso kiekis |
|
||||
---------------------------------------------------------------
|
||||
| Petraitis | Petras | 0 | 10 |
|
||||
| Jonaitis | Jonas | 1 | 20 |
|
||||
| Jonaitis | Jonas | 1 | 20 |
|
||||
| Jonaitis | Jonas | 1 | 20 |
|
||||
| Onaite | Ona | 2 | 200 |
|
||||
| Jonaitis | Brolis | 1 | 100 |
|
||||
| Jonaitis | Jonas | 1 | 20 |
|
||||
| Jonaitis | Jonas | 1 | 20 |
|
||||
| Onaite | Ona | 0 | 20 |
|
||||
---------------------------------------------------------------
|
||||
--------------------------------------------------
|
||||
| Pirkėjai |
|
||||
--------------------------------------------------
|
||||
| Pavardė | Vardas | Įtaisas | Įtaiso kiekis |
|
||||
--------------------------------------------------
|
||||
| Petraitis | Petras | 0 | 10 |
|
||||
| Petraitis | Petras | 1 | 10 |
|
||||
| Jonaitis | Jonas | 1 | 20 |
|
||||
| Jonaitis | Jonas | 1 | 20 |
|
||||
| Jonaitis | Jonas | 1 | 20 |
|
||||
| Onaite | Ona | 2 | 200 |
|
||||
| Jonaitis | Brolis | 1 | 100 |
|
||||
| Jonaitis | Brolis | 0 | 100 |
|
||||
| Jonaitis | Jonas | 1 | 20 |
|
||||
| Jonaitis | Jonas | 1 | 20 |
|
||||
| Jonaitis | Jonas | 2 | 20 |
|
||||
| Onaite | Ona | 0 | 20 |
|
||||
--------------------------------------------------
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
| Populiariausi įtaisai |
|
||||
---------------------------------------------------------------------------
|
||||
| ID | Vardas | Įtaisų kiekis, vnt. | Įtaisų kaina, eur. |
|
||||
---------------------------------------------------------------------------
|
||||
| 1 | Varztas | 200 | 10.00 |
|
||||
| 2 | Laidas | 200 | 400.00 |
|
||||
---------------------------------------------------------------------------
|
||||
------------------------------------------------------------
|
||||
| Populiariausi įtaisai |
|
||||
------------------------------------------------------------
|
||||
| ID | Vardas | Įtaisų kiekis, vnt. | Įtaisų kaina, eur. |
|
||||
------------------------------------------------------------
|
||||
| 2 | Laidas | 220 | 440,00 |
|
||||
------------------------------------------------------------
|
||||
|
||||
Pirkėjai pagal rūšį:
|
||||
---------------------------------------------------------------
|
||||
| Atsuktuvas |
|
||||
---------------------------------------------------------------
|
||||
| Pavardė | Vardas | Įtaiso kiekis | Kaina |
|
||||
---------------------------------------------------------------
|
||||
| Onaite | Ona | 20 | 19.80 |
|
||||
| Petraitis | Petras | 10 | 9.90 |
|
||||
---------------------------------------------------------------
|
||||
----------------------------------------------------------
|
||||
| Vienos rūšies pirkėjai |
|
||||
----------------------------------------------------------
|
||||
| Pavardė | Vardas | Įtaiso kiekis, vnt. | Kaina, eur. |
|
||||
----------------------------------------------------------
|
||||
| Nėra |
|
||||
----------------------------------------------------------
|
||||
|
||||
---------------------------------------------------------------
|
||||
| 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 |
|
||||
---------------------------------------------------------------
|
||||
|
||||
------------------------------------------
|
||||
| Atrinkti įtaisai (n=1, k=1.00) |
|
||||
------------------------------------------
|
||||
| ID | Vardas | Kaina |
|
||||
------------------------------------------
|
||||
| 0 | Atsuktuvas | 0.99 |
|
||||
| 1 | Varztas | 0.05 |
|
||||
------------------------------------------
|
||||
----------------------------------
|
||||
| Atrinkti įtaisai (n=1, k=1,00) |
|
||||
----------------------------------
|
||||
| ID | Vardas | Kaina |
|
||||
----------------------------------
|
||||
| 0 | Atsuktuvas | 0,99 |
|
||||
| 1 | Varztas | 0,05 |
|
||||
----------------------------------
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
Petraitis, Petras, 0, 10
|
||||
Petraitis, Petras, 1, 10
|
||||
Jonaitis, Jonas, 1, 20
|
||||
Jonaitis, Jonas, 1, 20
|
||||
Jonaitis, Jonas, 1, 20
|
||||
Onaite, Ona, 2, 200
|
||||
Jonaitis, Brolis, 1, 100
|
||||
Jonaitis, Brolis, 0, 100
|
||||
Jonaitis, Jonas, 1, 20
|
||||
Jonaitis, Jonas, 1, 20
|
||||
Jonaitis, Jonas, 2, 20
|
||||
Onaite, Ona, 0, 20
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
@ -49,99 +50,136 @@ namespace LD_24.Code
|
||||
return orders;
|
||||
}
|
||||
|
||||
public static void PrintOrders(StreamWriter writer, OrderList orders, string header)
|
||||
private static void PrintTableRow(StreamWriter writer, List<string> cells, List<int> widths)
|
||||
{
|
||||
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 (orders.Count() > 0)
|
||||
for (int i = 0; i < widths.Count; i++)
|
||||
{
|
||||
foreach (Order o in orders)
|
||||
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)
|
||||
{
|
||||
writer.WriteLine("| {0, -15} | {1, -15} | {2, 7} | {3, 13} |", o.CustomerSurname, o.CustomerName, o.ProductID, o.ProductAmount);
|
||||
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);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
// 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)
|
||||
{
|
||||
writer.WriteLine("| {0, -59} |", "Nėra");
|
||||
foreach (var row in rows)
|
||||
{
|
||||
PrintTableRow(writer, row, widths);
|
||||
}
|
||||
} else
|
||||
{
|
||||
writer.WriteLine("| {0} |", "Nėra".PadRight(totalWidth - 4));
|
||||
}
|
||||
writer.WriteLine(new string('-', 63));
|
||||
writer.WriteLine(new string('-', totalWidth));
|
||||
|
||||
writer.WriteLine();
|
||||
}
|
||||
|
||||
public static void PrintOrdersWithPrices(StreamWriter writer, OrderList orders, Product product, 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, 13} | {3, 7} |", "Pavardė", "Vardas", "Įtaiso kiekis", "Kaina");
|
||||
writer.WriteLine(new string('-', 63));
|
||||
|
||||
OrderList filtered = TaskUtils.FilterByProduct(orders, product.ID);
|
||||
filtered = TaskUtils.MergeOrders(filtered);
|
||||
filtered.Sort();
|
||||
|
||||
if (filtered.Count() > 0)
|
||||
foreach (var tuple in PrintTable(writer, header, orders, "Pavardė", "Vardas", "-Įtaisas", "-Įtaiso kiekis"))
|
||||
{
|
||||
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);
|
||||
}
|
||||
Order order = (Order)tuple.Item1;
|
||||
List<string> row = tuple.Item2;
|
||||
row.Add(order.CustomerSurname);
|
||||
row.Add(order.CustomerName);
|
||||
row.Add(order.ProductID);
|
||||
row.Add(order.ProductAmount.ToString());
|
||||
}
|
||||
else
|
||||
}
|
||||
|
||||
public static void PrintOrdersWithPrices(StreamWriter writer, OrderList orders, ProductList products, string header)
|
||||
{
|
||||
foreach (var tuple in PrintTable(writer, header, orders, "Pavardė", "Vardas", "-Įtaiso kiekis, vnt.", "-Kaina, eur."))
|
||||
{
|
||||
writer.WriteLine("| {0, -59} |", "Nėra");
|
||||
Order order = (Order)tuple.Item1;
|
||||
List<string> row = tuple.Item2;
|
||||
Product product = TaskUtils.FindByID(products, order.ProductID);
|
||||
|
||||
row.Add(order.CustomerSurname);
|
||||
row.Add(order.CustomerName);
|
||||
row.Add(order.ProductAmount.ToString());
|
||||
row.Add(String.Format("{0:f2}", order.ProductAmount * product.Price));
|
||||
}
|
||||
writer.WriteLine(new string('-', 63));
|
||||
writer.WriteLine();
|
||||
}
|
||||
|
||||
public static void PrintProducts(StreamWriter writer, ProductList products, string header)
|
||||
{
|
||||
writer.WriteLine(new string('-', 42));
|
||||
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 (var tuple in PrintTable(writer, header, products, "ID", "Vardas", "-Kaina"))
|
||||
{
|
||||
foreach (Product c in products)
|
||||
{
|
||||
writer.WriteLine("| {0, -5} | {1, -20} | {2, 7} |", c.ID, c.Name, c.Price);
|
||||
}
|
||||
Product product = (Product)tuple.Item1;
|
||||
List<string> row = tuple.Item2;
|
||||
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)
|
||||
{
|
||||
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 (var tuple in PrintTable(writer, header, popularProducts, "ID", "Vardas", "-Įtaisų kiekis, vnt.", "-Įtaisų kaina, eur."))
|
||||
{
|
||||
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);
|
||||
}
|
||||
Product product = (Product)tuple.Item1;
|
||||
List<string> row = tuple.Item2;
|
||||
int sales = TaskUtils.CountProductSales(orders, product.ID);
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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()
|
||||
{
|
||||
int count = 0;
|
||||
|
@ -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()
|
||||
{
|
||||
int count = 0;
|
||||
|
@ -129,5 +129,29 @@ namespace LD_24.Code
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -35,9 +35,9 @@
|
||||
<asp:Label ID="Label8" runat="server" Text="Populiariausi įtaisai:"></asp:Label>
|
||||
<asp:Table ID="Table5" runat="server">
|
||||
</asp:Table>
|
||||
<asp:Label ID="Label4" runat="server" Text="Pirkėjai pagal rūšį:"></asp:Label>
|
||||
<div id="OrdersByProductContainer" runat="server">
|
||||
</div>
|
||||
<asp:Label ID="Label4" runat="server" Text="Vienos rūšies pirkėjai:"></asp:Label>
|
||||
<asp:Table ID="Table3" runat="server">
|
||||
</asp:Table>
|
||||
<asp:Label ID="Label7" runat="server" Text="Atrinkti įtaisai:"></asp:Label>
|
||||
<asp:Table ID="Table4" runat="server">
|
||||
</asp:Table>
|
||||
|
@ -34,11 +34,13 @@ namespace LD_24
|
||||
List<string> mostPopularProductIds = TaskUtils.FindMostPopularProducts(orders);
|
||||
ProductList mostPopularProducts = TaskUtils.FindByID(products, mostPopularProductIds);
|
||||
ProductList filteredProducts = TaskUtils.FilterByQuantitySoldAndPrice(products, orders, n, k);
|
||||
OrderList customersWithSingleProduct = TaskUtils.FindCustomerWithSingleProduct(orders);
|
||||
customersWithSingleProduct.Sort();
|
||||
|
||||
ShowProducts(Table1, products);
|
||||
ShowOrders(Table2, orders);
|
||||
ShowMostPopularProducts(Table5, orders, mostPopularProducts);
|
||||
ShowOrdersByProduct(FindControl("OrdersByProductContainer"), orders, products);
|
||||
ShowOrdersWithPrices(Table3, customersWithSingleProduct, products);
|
||||
ShowProducts(Table4, filteredProducts);
|
||||
|
||||
using (StreamWriter writer = new StreamWriter(Server.MapPath(outputFilename)))
|
||||
@ -46,39 +48,9 @@ namespace LD_24
|
||||
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.PrintOrdersWithPrices(writer, customersWithSingleProduct, products, "Vienos rūšies pirkėjai");
|
||||
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})");
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
54
DynamicMemory/LD_24/Forma1.aspx.designer.cs
generated
54
DynamicMemory/LD_24/Forma1.aspx.designer.cs
generated
@ -7,13 +7,11 @@
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace LD_24
|
||||
{
|
||||
|
||||
|
||||
public partial class Forma1
|
||||
{
|
||||
|
||||
namespace LD_24 {
|
||||
|
||||
|
||||
public partial class Forma1 {
|
||||
|
||||
/// <summary>
|
||||
/// form1 control.
|
||||
/// </summary>
|
||||
@ -22,7 +20,7 @@ namespace LD_24
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.HtmlControls.HtmlForm form1;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// ValidationSummary1 control.
|
||||
/// </summary>
|
||||
@ -31,7 +29,7 @@ namespace LD_24
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.ValidationSummary ValidationSummary1;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Label5 control.
|
||||
/// </summary>
|
||||
@ -40,7 +38,7 @@ namespace LD_24
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.Label Label5;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// TextBox1 control.
|
||||
/// </summary>
|
||||
@ -49,7 +47,7 @@ namespace LD_24
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.TextBox TextBox1;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// RegularExpressionValidator1 control.
|
||||
/// </summary>
|
||||
@ -58,7 +56,7 @@ namespace LD_24
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Label6 control.
|
||||
/// </summary>
|
||||
@ -67,7 +65,7 @@ namespace LD_24
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.Label Label6;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// TextBox2 control.
|
||||
/// </summary>
|
||||
@ -76,7 +74,7 @@ namespace LD_24
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.TextBox TextBox2;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// RegularExpressionValidator2 control.
|
||||
/// </summary>
|
||||
@ -85,7 +83,7 @@ namespace LD_24
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator2;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Button1 control.
|
||||
/// </summary>
|
||||
@ -94,7 +92,7 @@ namespace LD_24
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.Button Button1;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// ResultsDiv control.
|
||||
/// </summary>
|
||||
@ -103,7 +101,7 @@ namespace LD_24
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.HtmlControls.HtmlGenericControl ResultsDiv;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Label1 control.
|
||||
/// </summary>
|
||||
@ -112,7 +110,7 @@ namespace LD_24
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.Label Label1;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Table1 control.
|
||||
/// </summary>
|
||||
@ -121,7 +119,7 @@ namespace LD_24
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.Table Table1;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Label2 control.
|
||||
/// </summary>
|
||||
@ -130,7 +128,7 @@ namespace LD_24
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.Label Label2;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Table2 control.
|
||||
/// </summary>
|
||||
@ -139,7 +137,7 @@ namespace LD_24
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.Table Table2;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Label8 control.
|
||||
/// </summary>
|
||||
@ -148,7 +146,7 @@ namespace LD_24
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.Label Label8;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Table5 control.
|
||||
/// </summary>
|
||||
@ -157,7 +155,7 @@ namespace LD_24
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.Table Table5;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Label4 control.
|
||||
/// </summary>
|
||||
@ -166,16 +164,16 @@ namespace LD_24
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.Label Label4;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// OrdersByProductContainer control.
|
||||
/// Table3 control.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Auto-generated field.
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.HtmlControls.HtmlGenericControl OrdersByProductContainer;
|
||||
|
||||
protected global::System.Web.UI.WebControls.Table Table3;
|
||||
|
||||
/// <summary>
|
||||
/// Label7 control.
|
||||
/// </summary>
|
||||
@ -184,7 +182,7 @@ namespace LD_24
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.Label Label7;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Table4 control.
|
||||
/// </summary>
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
@ -10,10 +11,8 @@ namespace LD_24
|
||||
{
|
||||
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();
|
||||
foreach (string column in columns)
|
||||
{
|
||||
@ -21,14 +20,16 @@ namespace LD_24
|
||||
}
|
||||
table.Rows.Add(header);
|
||||
|
||||
if (products.Count() > 0) {
|
||||
foreach (Product product in products)
|
||||
{
|
||||
TableRow row = new TableRow();
|
||||
yield return Tuple.Create(product, row);
|
||||
table.Rows.Add(row);
|
||||
}
|
||||
} else
|
||||
int n = 0;
|
||||
foreach (object item in list)
|
||||
{
|
||||
TableRow row = new TableRow();
|
||||
yield return Tuple.Create(item, row);
|
||||
table.Rows.Add(row);
|
||||
n++;
|
||||
}
|
||||
|
||||
if (n == 0)
|
||||
{
|
||||
TableRow row = new TableRow();
|
||||
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();
|
||||
TableRow row = new TableRow();
|
||||
row.Cells.Add(new TableCell { Text = title, ColumnSpan = columns.Length });
|
||||
table.Rows.Add(row);
|
||||
|
||||
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<Tuple<Order, TableRow>> ShowOrdersTable(Table table, OrderList orders, params string[] columns)
|
||||
{
|
||||
return ShowOrdersTable(table, null, orders, columns);
|
||||
return ShowTable(table, list, columns);
|
||||
}
|
||||
|
||||
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;
|
||||
row.Cells.Add(new TableCell { Text = product.ID });
|
||||
row.Cells.Add(new TableCell { Text = product.Name });
|
||||
@ -90,9 +60,9 @@ namespace LD_24
|
||||
|
||||
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;
|
||||
row.Cells.Add(new TableCell { Text = order.CustomerSurname });
|
||||
row.Cells.Add(new TableCell { Text = order.CustomerName });
|
||||
@ -103,9 +73,9 @@ namespace LD_24
|
||||
|
||||
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;
|
||||
int sales = TaskUtils.CountProductSales(orders, product.ID);
|
||||
row.Cells.Add(new TableCell { Text = product.ID });
|
||||
@ -115,26 +85,18 @@ 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 (Product product in products)
|
||||
foreach (var tuple in ShowTable(table, orders, "Pavardė", "Vardas", "Įtaisų kiekis, vnt.", "Sumokėta, eur."))
|
||||
{
|
||||
OrderList filtered = TaskUtils.FilterByProduct(orders, product.ID);
|
||||
filtered = TaskUtils.MergeOrders(filtered);
|
||||
filtered.Sort();
|
||||
Order order = (Order)tuple.Item1;
|
||||
TableRow row = tuple.Item2;
|
||||
Product product = TaskUtils.FindByID(products, order.ProductID);
|
||||
|
||||
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) });
|
||||
}
|
||||
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) });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -73,6 +73,9 @@
|
||||
<Content Include="App_Data\U24a.txt" />
|
||||
<Content Include="Forma1.aspx" />
|
||||
<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" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
Loading…
Reference in New Issue
Block a user