-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
97 lines (89 loc) · 4.57 KB
/
Program.cs
File metadata and controls
97 lines (89 loc) · 4.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AboutCars
{
class Program
{
const string path = @"C:\Users\hp\Desktop\Новая папка\AboutCars\";
static void Main(string[] args)
{
List<Car> list = Help.InputData();
Help.PrintToConsole(list);
int responce;
do
{
Console.WriteLine("Что вы хотите сделать?" +
"\n1 - Добавить инфо о машине" +
"\n2 - Выполнить поиск машин по дате, пробегу и типу коробки передач" +
"\n3 - Сохранить все данные в файл" +
"\n4 - Редактировать данные о машине " +
"\n5 - Удалить данные о машине " +
"\n0 - Завершение работы");
int.TryParse(Console.ReadLine(), out responce);
switch (responce)
{
case 1:
list = list.Concat(Help.InputData()).ToList();
Help.PrintToConsole(list);
break;
case 2:
Console.WriteLine("Будет выведена информация о машинах, которые были " +
"\nвыпущены после определенной даты, имеют пробег меньше заданного и" +
"\nзаданный тип коробки передач, упорядочив по объему двигателя");
Console.ReadLine();
List<Car> sortedList = SortCars(list);
Help.PrintToConsole(sortedList);
break;
case 3:
string name;
IFileManager file = Help.ChooseFile(out name);
file.PrintToFile(list, path+ name);
Console.WriteLine("Запись выполнена");
break;
case 4:
Console.ReadLine();
Console.WriteLine("Выберите какой элемент вы хотите редактрировать, начиная с 0");
int edIndex;
int.TryParse(Console.ReadLine(), out edIndex);
list.Insert(edIndex, Help.EditCar(list, edIndex));
Console.WriteLine("Редактирование завершено");
Console.ReadLine();
Help.PrintToConsole(list);
break;
case 5:
Console.ReadLine();
Console.WriteLine("Выберите какой элемент удалить, начиная с 0");
int resp;
int.TryParse(Console.ReadLine(), out resp);
list.RemoveAt(resp);
Console.WriteLine("Удаление завершено");
Console.ReadLine();
Help.PrintToConsole(list);
break;
}
}
while (responce != 0);
}
static List<Car> SortCars(List<Car> list)
{
Console.WriteLine("Введите год выпуска");
int year;
int.TryParse(Console.ReadLine(), out year);
Console.WriteLine();
Console.WriteLine("Введите пробег");
int run;
int.TryParse(Console.ReadLine(), out run);
Console.WriteLine();
Console.Write("Введите тип коробки передач");
Console.WriteLine("Введите число 1-Автоматическая, 2 - Ручная, 3 - Смешанная ");
transmitionKind transmition = Help.StringToKind(Console.ReadLine());
List<Car> sortedList = list.Where(cn => cn.Transmition == transmition && (cn.Year_create > year) && (cn.Run < run))
.OrderBy(item => item.Volume)
.ToList();
return sortedList;
}
}
}