From 1253a0746d7038a3e26e7e604a20e174fc655dba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=A7=D0=B5=D1=80?= =?UTF-8?q?=D0=BD=D1=8B=D1=88=D0=BE=D0=B2?= Date: Thu, 4 May 2023 01:59:59 +0400 Subject: [PATCH] lab work 5 done --- SubdShoeStore/Program.cs | 121 ++++++++++++++++++++++++++++++++++++++- SubdShoeStore/View.txt | 8 --- 2 files changed, 119 insertions(+), 10 deletions(-) delete mode 100644 SubdShoeStore/View.txt diff --git a/SubdShoeStore/Program.cs b/SubdShoeStore/Program.cs index 3751555..772be55 100644 --- a/SubdShoeStore/Program.cs +++ b/SubdShoeStore/Program.cs @@ -1,2 +1,119 @@ -// See https://aka.ms/new-console-template for more information -Console.WriteLine("Hello, World!"); +using ConsoleTableExt; +using SubdShoeStore; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Subdlab5 +{ + class Program + { + public static void Main(string[] args) + { + string text; + using (var sr = new StreamReader("View.txt")) + { + text = sr.ReadToEnd(); + } + + using var context = new Shoestorelab5Context(); + Controller controller = new(context); + string operation = ""; + do + { + Console.WriteLine(text); + operation = Console.ReadLine() ?? ""; + switch (operation) + { + case "0": + break; + case "1": + controller.GetConsignment(); + break; + case "2": + controller.GetRange(); + break; + case "3": + controller.GetSeller(); + break; + case "4": + controller.GetSelling(); + break; + case "5": + Console.WriteLine("Введите Название, Изготовителя и Цену"); + SubdShoeStore.Range range = new() + { + Shoename = Console.ReadLine(), + Mfr = Console.ReadLine(), + Price = int.Parse(Console.ReadLine()), + }; + controller.AddRange(range); + break; + case "6": + Console.WriteLine($"Введите Id range"); + var rangeId = Convert.ToInt32(Console.ReadLine()); + var shoe = controller.GetRange(rangeId); + Console.WriteLine($"1 для изменения, 2 для удаления"); + var r = Console.ReadLine(); + if (r == "1") + { + Console.WriteLine($"Введите новое название обуви"); + var s = Console.ReadLine(); + shoe.Shoename = s; + controller.UpdateRange(shoe); + } + if (r == "2") + { + controller.RemoveFromRange(shoe); + } + break; + case "7": + Test(controller, context); + break; + default: + Console.WriteLine("Некорректно введенный номер операции"); + break; + } + } while (operation != "0"); + } + public static void Test(Controller controller, Shoestorelab5Context context) + { + var result = new[] + { + new { Name = "1", timems = MeasureTime(controller.GetConsignment)}, + new { Name = "2", timems = MeasureTime(controller.GetRange)}, + new { Name = "3", timems = MeasureTime(controller.GetSeller)}, + new { Name = "4", timems = MeasureTime(() => controller.GetSelling())}, + new { Name = "5", timems = MeasureTime(() => + { + Random r = new Random(); + string name = ""; + for (int i = 0; i < 7; i++) + name += (char)r.Next(65, 89); + SubdShoeStore.Range shoename = new() { + Shoename = name[..7], + }; + controller.AddRange(shoename); + })}, + }.ToList(); + ConsoleTableBuilder.From(result).ExportAndWriteLine(); + } + + public static double MeasureTime(Action action, int count = 10) + { + long sumTime = 0; + Stopwatch stopwatch = new(); + for (int i = 0; i < count; i++) + { + stopwatch.Start(); + action.Invoke(); + stopwatch.Stop(); + sumTime += stopwatch.ElapsedMilliseconds; + } + return sumTime / count; + } + } +} \ No newline at end of file diff --git a/SubdShoeStore/View.txt b/SubdShoeStore/View.txt deleted file mode 100644 index 3821255..0000000 --- a/SubdShoeStore/View.txt +++ /dev/null @@ -1,8 +0,0 @@ -0 - выход -1 - для получения списка всех consignment -2 - для получения списка всех range -3 - для получения списка всех seller -4 - для получения списка всех selling -5 - добавить в range -6 - удаление и редактирование range -7 - замеры времени