lab work 5 done
This commit is contained in:
parent
d8c89775d2
commit
1253a0746d
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
0 - выход
|
||||
1 - для получения списка всех consignment
|
||||
2 - для получения списка всех range
|
||||
3 - для получения списка всех seller
|
||||
4 - для получения списка всех selling
|
||||
5 - добавить в range
|
||||
6 - удаление и редактирование range
|
||||
7 - замеры времени
|
Loading…
Reference in New Issue
Block a user