diff --git a/L3/LD_24/App_Data/Rezultatai.txt b/L3/LD_24/App_Data/Rezultatai.txt index 288d333..c501991 100644 --- a/L3/LD_24/App_Data/Rezultatai.txt +++ b/L3/LD_24/App_Data/Rezultatai.txt @@ -1,45 +1,45 @@ ---------------------------- | Įtaisai | ---------------------------- -| ID | Vardas | Kaina | +| ID | Vardas | Kaina | ---------------------------- -| 0 | Atsuktuvas | 0.99 | -| 1 | Varztas | 0.05 | -| 2 | Laidas | 2.00 | -| 3 | Plaktukas | 2.99 | +| 0 | Atsuktuvas | 0.99 | +| 1 | Varztas | 0.05 | +| 2 | Laidas | 2.00 | +| 3 | Plaktukas | 2.99 | ---------------------------- -------------------------------------------------- | Pirkėjai | -------------------------------------------------- -| Pavardė | Vardas | Įtaisas | Įtaiso kiekis | +| 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 | +| 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. | +| ID | Vardas | Įtaisų kiekis, vnt. | Įtaisų kaina, eur. | ------------------------------------------------------------ -| 2 | Laidas | 220 | 440.00 | +| 2 | Laidas | 220 | 440.00 | ------------------------------------------------------------ ---------------------------------------------------------- | Vienos rūšies pirkėjai | ---------------------------------------------------------- -| Pavardė | Vardas | Įtaiso kiekis, vnt. | Kaina, eur. | +| Pavardė | Vardas | Įtaiso kiekis, vnt. | Kaina, eur. | ---------------------------------------------------------- | Nėra | ---------------------------------------------------------- @@ -47,9 +47,9 @@ ---------------------------------- | Atrinkti įtaisai (n=1, k=1.00) | ---------------------------------- -| ID | Vardas | Kaina | +| ID | Vardas | Kaina | ---------------------------------- -| 0 | Atsuktuvas | 0.99 | -| 1 | Varztas | 0.05 | +| 0 | Atsuktuvas | 0.99 | +| 1 | Varztas | 0.05 | ---------------------------------- diff --git a/L3/LD_24/Code/InOutUtils.cs b/L3/LD_24/Code/InOutUtils.cs index df1d0b3..f8bda0a 100644 --- a/L3/LD_24/Code/InOutUtils.cs +++ b/L3/LD_24/Code/InOutUtils.cs @@ -14,31 +14,28 @@ namespace LD_24.Code public static class InOutUtils { /// - /// Read lines from a file + /// Read lines from a stream /// /// Target filename /// IEnumerable of all the lines - private static IEnumerable ReadLines(string filename) + private static IEnumerable ReadLines(StreamReader stream) { - using (StreamReader reader = File.OpenText(filename)) + string line; + while ((line = stream.ReadLine()) != null) { - string line; - while ((line = reader.ReadLine()) != null) - { - yield return line; - } + yield return line; } } /// - /// Read products from a file + /// Read products from a stream reader /// - /// Target file + /// Target stream reader /// A list of products - public static LinkedList ReadProducts(string filename) + public static LinkedList ReadProducts(StreamReader reader) { LinkedList products = new LinkedList(); - foreach (string line in ReadLines(filename)) + foreach (string line in ReadLines(reader)) { string[] parts = line.Split(','); string id = parts[0].Trim(); @@ -49,15 +46,67 @@ namespace LD_24.Code return products; } + /// + /// Read products from a stream + /// + /// Target stream + /// A list of products + public static LinkedList ReadProducts(Stream stream) + { + using (StreamReader reader = new StreamReader(stream)) + { + return ReadProducts(reader); + } + } + + /// + /// Read products from a file + /// + /// Target file + /// A list of products + public static LinkedList ReadProducts(string filename) + { + using (StreamReader reader = File.OpenText(filename)) + { + return ReadProducts(reader); + } + } + /// /// Read orders from a file /// /// Target file /// A list of orders public static LinkedList ReadOrders(string filename) + { + using (StreamReader reader = File.OpenText(filename)) + { + return ReadOrders(reader); + } + } + + /// + /// Read orders from a stream + /// + /// Target stream + /// A list of orders + public static LinkedList ReadOrders(Stream stream) + { + using (StreamReader reader = new StreamReader(stream)) + { + return ReadOrders(reader); + } + } + + /// + /// Read orders from a stream reader + /// + /// Target stream reader + /// A list of orders + public static LinkedList ReadOrders(StreamReader reader) { LinkedList orders = new LinkedList(); - foreach (string line in ReadLines(filename)) + foreach (string line in ReadLines(reader)) { string[] parts = line.Split(','); string customerSurname = parts[0].Trim(); @@ -79,10 +128,10 @@ namespace LD_24.Code { for (int i = 0; i < widths.Count; i++) { - if (widths[i] < 0) - writer.Write("| {0} ", cells[i].PadRight(-widths[i])); + if (widths[i] > 0) + writer.Write("| {0} ", cells[i].PadRight(widths[i])); else - writer.Write("| {0} ", cells[i].PadLeft(widths[i])); + writer.Write("| {0} ", cells[i].PadLeft(-widths[i])); } writer.WriteLine("|"); } diff --git a/L3/LD_24/Code/LinkedList.cs b/L3/LD_24/Code/LinkedList.cs index 4a389d5..bbe51b4 100644 --- a/L3/LD_24/Code/LinkedList.cs +++ b/L3/LD_24/Code/LinkedList.cs @@ -42,10 +42,8 @@ namespace LD_24.Code public int Count() { int count = 0; - Node current = head; - while (current != null) + for (Node d = head; d != null; d = d.Next) { - current = current.Next; count++; } return count; diff --git a/L3/LD_24/Forma1.aspx b/L3/LD_24/Forma1.aspx index 6aefcdf..3c6686c 100644 --- a/L3/LD_24/Forma1.aspx +++ b/L3/LD_24/Forma1.aspx @@ -10,15 +10,27 @@
+ +
+ + +
+ +
+ + +

- + +

- + +

diff --git a/L3/LD_24/Forma1.aspx.cs b/L3/LD_24/Forma1.aspx.cs index cdb7ab7..dc973c5 100644 --- a/L3/LD_24/Forma1.aspx.cs +++ b/L3/LD_24/Forma1.aspx.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using System.Web; @@ -14,8 +15,6 @@ namespace LD_24 /// public partial class Forma1 : System.Web.UI.Page { - private const string inputFileA = "App_Data/U24a.txt"; - private const string inputFileB = "App_Data/U24b.txt"; private const string outputFilename = "App_Data/Rezultatai.txt"; protected void Page_Load(object sender, EventArgs e) @@ -30,8 +29,8 @@ namespace LD_24 FindControl("ResultsDiv").Visible = true; - var products = InOutUtils.ReadProducts(Server.MapPath(inputFileA)); - var orders = InOutUtils.ReadOrders(Server.MapPath(inputFileB)); + var products = InOutUtils.ReadProducts(FileUpload1.FileContent); + var orders = InOutUtils.ReadOrders(FileUpload2.FileContent); List mostPopularProductIds = TaskUtils.FindMostPopularProducts(orders); var mostPopularProducts = TaskUtils.FindByID(products, mostPopularProductIds); @@ -54,5 +53,6 @@ namespace LD_24 InOutUtils.PrintProducts(writer, filteredProducts, $"Atrinkti įtaisai (n={n}, k={k:f2})"); } } + } } \ No newline at end of file diff --git a/L3/LD_24/Forma1.aspx.designer.cs b/L3/LD_24/Forma1.aspx.designer.cs index 691f56f..ceb44c0 100644 --- a/L3/LD_24/Forma1.aspx.designer.cs +++ b/L3/LD_24/Forma1.aspx.designer.cs @@ -7,11 +7,13 @@ // //------------------------------------------------------------------------------ -namespace LD_24 { - - - public partial class Forma1 { - +namespace LD_24 +{ + + + public partial class Forma1 + { + /// /// form1 control. /// @@ -20,7 +22,7 @@ namespace LD_24 { /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.HtmlControls.HtmlForm form1; - + /// /// ValidationSummary1 control. /// @@ -29,7 +31,61 @@ namespace LD_24 { /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.ValidationSummary ValidationSummary1; - + + /// + /// Label9 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Label Label9; + + /// + /// FileUpload1 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.FileUpload FileUpload1; + + /// + /// RequiredFieldValidator1 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1; + + /// + /// Label10 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Label Label10; + + /// + /// FileUpload2 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.FileUpload FileUpload2; + + /// + /// RequiredFieldValidator2 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2; + /// /// Label5 control. /// @@ -38,7 +94,7 @@ namespace LD_24 { /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.Label Label5; - + /// /// TextBox1 control. /// @@ -47,7 +103,7 @@ namespace LD_24 { /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.TextBox TextBox1; - + /// /// RegularExpressionValidator1 control. /// @@ -56,7 +112,16 @@ namespace LD_24 { /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1; - + + /// + /// RequiredFieldValidator3 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator3; + /// /// Label6 control. /// @@ -65,7 +130,7 @@ namespace LD_24 { /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.Label Label6; - + /// /// TextBox2 control. /// @@ -74,7 +139,7 @@ namespace LD_24 { /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.TextBox TextBox2; - + /// /// RegularExpressionValidator2 control. /// @@ -83,7 +148,16 @@ namespace LD_24 { /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator2; - + + /// + /// RequiredFieldValidator4 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator4; + /// /// Button1 control. /// @@ -92,7 +166,7 @@ namespace LD_24 { /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.Button Button1; - + /// /// ResultsDiv control. /// @@ -101,7 +175,7 @@ namespace LD_24 { /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.HtmlControls.HtmlGenericControl ResultsDiv; - + /// /// Label1 control. /// @@ -110,7 +184,7 @@ namespace LD_24 { /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.Label Label1; - + /// /// Table1 control. /// @@ -119,7 +193,7 @@ namespace LD_24 { /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.Table Table1; - + /// /// Label2 control. /// @@ -128,7 +202,7 @@ namespace LD_24 { /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.Label Label2; - + /// /// Table2 control. /// @@ -137,7 +211,7 @@ namespace LD_24 { /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.Table Table2; - + /// /// Label8 control. /// @@ -146,7 +220,7 @@ namespace LD_24 { /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.Label Label8; - + /// /// Table5 control. /// @@ -155,7 +229,7 @@ namespace LD_24 { /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.Table Table5; - + /// /// Label4 control. /// @@ -164,7 +238,7 @@ namespace LD_24 { /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.Label Label4; - + /// /// Table3 control. /// @@ -173,7 +247,7 @@ namespace LD_24 { /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.Table Table3; - + /// /// Label7 control. /// @@ -182,7 +256,7 @@ namespace LD_24 { /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.Label Label7; - + /// /// Table4 control. /// diff --git a/L3/LD_24/packages.config b/L3/LD_24/packages.config index 5432864..d6710b5 100644 --- a/L3/LD_24/packages.config +++ b/L3/LD_24/packages.config @@ -1,14 +1,6 @@  - - - - - - - - \ No newline at end of file