Загрузка данных
using System.Data;
namespace ConsoleApp1
{
public class Program
{
static void Main(string[] args)
{
PrintOrder[] printOrders = new PrintOrder[20];
int countPrintOrder = 0;
bool isContinue = true;
while(isContinue)
{
Console.Write("\tМеню\n" +
"1. Принять простой заказ\n" +
"2. Принять расширенный заказ\n" +
"3. Показать все заказы\n" +
"4. Изменить заказ по индексу массива\n" +
"5. Предварительно расчитать стоимость\n" +
"6. Выполнить заказ\n" +
"7. Показать общую статистику по количеству созданных и выполненных заказов, общей суммы выручки\n" +
"0. Завершить работу\n" +
"Выберите: ");
string selectedAction = Console.ReadLine();
Console.WriteLine();
switch(selectedAction)
{
case "1":
if (countPrintOrder < 20)
{
Console.Write("Введите имя клиента: ");
string? customerName;
while (string.IsNullOrWhiteSpace(customerName = Console.ReadLine()))
Console.Write("Имя не должно быть пустым!\n" +
"Введите имя клиента: ");
Console.Write("Введите число страниц: ");
int pagesCount;
while (!int.TryParse(Console.ReadLine(), out pagesCount))
Console.Write("Неверный ввод!\n" +
"Введите число страниц: ");
printOrders[countPrintOrder++] = new PrintOrder(customerName, pagesCount);
}
else
Console.WriteLine("Число заказов не может быть больше 20");
break;
case "2":
if (countPrintOrder < 20)
{
Console.Write("Введите имя клиента: ");
string? customerName;
while (string.IsNullOrWhiteSpace(customerName = Console.ReadLine()))
Console.Write("Имя не должно быть пустым!\n" +
"Введите имя клиента: ");
Console.Write("Введите число страниц: ");
int pagesCount;
while (!int.TryParse(Console.ReadLine(), out pagesCount))
Console.Write("Неверный ввод!\n" +
"Введите число страниц: ");
Console.Write("Введите количество копий: ");
int copiesCount;
while (!int.TryParse(Console.ReadLine(), out copiesCount))
Console.Write("Неверный ввод!\n" +
"Введите количество копий: ");
Console.Write("Цветная печать? (Y/N): ");
string? isColor_;
while ((isColor_ = Console.ReadLine()) != "Y" && isColor_ != "N")
Console.Write("Неверный ввод!\n" +
"Цветная печать? (Y/N): ");
bool isColor = isColor_ == "Y";
printOrders[countPrintOrder++] = new PrintOrder(customerName, pagesCount, copiesCount, isColor);
}
else
Console.WriteLine("Число заказов не может быть больше 20");
break;
case "3":
if (countPrintOrder > 0)
for (int i = 0; i < countPrintOrder; i++)
Console.WriteLine($"{i + 1}. {printOrders[i].Info()}");
else
Console.WriteLine("Заказов нет");
break;
case "4":
if (countPrintOrder > 0)
{
for (int i = 0; i < countPrintOrder; i++)
Console.WriteLine($"{i + 1}. {printOrders[i].Info()}");
Console.Write("Выберете заказ: ");
int selectedOrder;
while(!int.TryParse(Console.ReadLine(),out selectedOrder) || selectedOrder < 1 || selectedOrder > countPrintOrder)
Console.Write("Неверный ввод!\n" +
"Выберите заказ: ");
selectedOrder--;
Console.Write("Вы хотите изменить все параметры печати? (Y/N): ");
string? isFullChange;
while((isFullChange = Console.ReadLine()) != "Y" && isFullChange != "N")
Console.Write("Неверный ввод!\n" +
"Вы хотите изменить все параметры печати? (Y/N): ");
Console.WriteLine();
if(isFullChange == "Y")
{
Console.Write("Введите число страниц: ");
int pagesCount;
while (!int.TryParse(Console.ReadLine(), out pagesCount))
Console.Write("Неверный ввод!\n" +
"Введите число страниц: ");
Console.Write("Введите количество копий: ");
int copiesCount;
while (!int.TryParse(Console.ReadLine(), out copiesCount))
Console.Write("Неверный ввод!\n" +
"Введите количество копий: ");
Console.Write("Цветная печать? (Y/N): ");
string? isColor_;
while ((isColor_ = Console.ReadLine()) != "Y" && isColor_ != "N")
Console.Write("Неверный ввод!\n" +
"Цветная печать? (Y/N): ");
bool isColor = isColor_ == "Y";
Console.WriteLine(printOrders[selectedOrder].ChangeOrder(pagesCount, copiesCount, isColor) ? "Успешное изменение заказа!" : "Не удалось изменить заказ");
}
else
{
Console.Write("Введите число страниц: ");
int pagesCount;
while (!int.TryParse(Console.ReadLine(), out pagesCount))
Console.Write("Неверный ввод!\n" +
"Введите число страниц: ");
Console.WriteLine(printOrders[selectedOrder].ChangeOrder(pagesCount) ? "Успешное изменение заказа!" : "Не удалось изменить заказ");
}
}
else
Console.WriteLine("Заказов нет");
break;
case "5":
Console.Write("1. X количество страниц, 1 экземпляр, черно-белая печать\n" +
"2. X количество страниц, X экземпляров, черно-белая печать\n" +
"3. X количество страниц, X экземпляров, цветная печать\n" +
"Выберите вариант расчета: ");
int selectedCalculateCost;
while(!int.TryParse(Console.ReadLine(),out selectedCalculateCost) || selectedCalculateCost < 1 || selectedCalculateCost > 3)
Console.Write("Неверный ввод!\n" +
"Выберите вариант расчета: ");
switch(selectedCalculateCost)
{
case 1:
{
Console.Write("Введите число страниц: ");
int pagesCount;
while (!int.TryParse(Console.ReadLine(), out pagesCount))
Console.Write("Неверный ввод!\n" +
"Введите число страниц: ");
Console.WriteLine();
Console.WriteLine($"Предварительная стоимость: {Price.CalculateCost(pagesCount)}");
}
break;
case 2:
{
Console.Write("Введите число страниц: ");
int pagesCount;
while (!int.TryParse(Console.ReadLine(), out pagesCount))
Console.Write("Неверный ввод!\n" +
"Введите число страниц: ");
Console.Write("Введите количество копий: ");
int copiesCount;
while (!int.TryParse(Console.ReadLine(), out copiesCount))
Console.Write("Неверный ввод!\n" +
"Введите количество копий: ");
Console.WriteLine();
Console.WriteLine($"Предварительная стоимость: {Price.CalculateCost(pagesCount, copiesCount)}");
}
break;
case 3:
{
Console.Write("Введите число страниц: ");
int pagesCount;
while (!int.TryParse(Console.ReadLine(), out pagesCount))
Console.Write("Неверный ввод!\n" +
"Введите число страниц: ");
Console.Write("Введите количество копий: ");
int copiesCount;
while (!int.TryParse(Console.ReadLine(), out copiesCount))
Console.Write("Неверный ввод!\n" +
"Введите количество копий: ");
Console.WriteLine();
Console.WriteLine($"Предварительная стоимость: {Price.CalculateCost(pagesCount, copiesCount, true)}");
}
break;
}
break;
case "6":
if(countPrintOrder > 0)
{
for (int i = 0; i < countPrintOrder; i++)
Console.WriteLine($"{i + 1}. {printOrders[i].Info()}");
Console.Write("Выберете заказ: ");
int selectedOrder;
while (!int.TryParse(Console.ReadLine(), out selectedOrder) || selectedOrder < 1 || selectedOrder > countPrintOrder)
Console.Write("Неверный ввод!\n" +
"Выберите заказ: ");
selectedOrder--;
Console.WriteLine();
if (printOrders[selectedOrder].CompleteOrder())
{
Console.WriteLine($"Заказ успешно выполнился!\n" +
$"{printOrders[selectedOrder].Info()}");
}
else
Console.WriteLine("Этот заказ уже выполненный");
}
else
Console.WriteLine("Заказов нет");
break;
case "7":
Console.WriteLine(PrintOrder.TotalInfo());
break;
case "0":
isContinue = false;
break;
default:
Console.WriteLine("Неверный ввод!");
break;
}
Console.Write("\nНажмите любую клавишу, чтобы продолжить..."); Console.ReadKey();
Console.Clear();
}
}
}
}
static public class Price
{
private const int tariff = 5, tariffIsColor = 15;
static public decimal CalculateCost(int pagesCount)
{ return pagesCount * tariff; }
static public decimal CalculateCost(int pagesCount, int copiesCount)
{ return CalculateCost(pagesCount) * copiesCount; }
static public decimal CalculateCost(int pagesCount, int copiesCount, bool isColor)
{ return isColor ? pagesCount * copiesCount * tariffIsColor : CalculateCost(pagesCount, copiesCount); }
}
public class PrintOrder
{
private int ID;
private string customerName;
private int pagesCount;
private int copiesCount = 1;
private bool isColor = false;
private bool isComplete = false;
static private int totalOrdersCount = 0;
static private int totalCompleteOrdersCount = 0;
static private decimal totalCost = 0;
public PrintOrder(string customerName, int pagesCount)
{
if (string.IsNullOrWhiteSpace(customerName))
throw new Exception("Имя клиента не может быть пустым");
else
this.customerName = customerName;
if (pagesCount < 1) pagesCount = 1;
else if (pagesCount > 500) pagesCount = 500;
this.pagesCount = pagesCount;
totalOrdersCount++;
ID = totalOrdersCount;
}
public PrintOrder(string customerName, int pagesCount, int copiesCount, bool isColor)
{
if (string.IsNullOrWhiteSpace(customerName))
throw new Exception("Имя клиента не может быть пустым");
else
this.customerName = customerName;
if (pagesCount < 1) pagesCount = 1;
else if (pagesCount > 500) pagesCount = 500;
this.pagesCount = pagesCount;
if (copiesCount < 1) copiesCount = 1;
else if (copiesCount > 100) copiesCount = 100;
this.copiesCount = copiesCount;
this.isColor = isColor;
totalOrdersCount++;
ID = totalOrdersCount;
}
public bool ChangeOrder(int pagesCount)
{
if (isComplete) return false;
if (pagesCount < 1) return false;
else if (pagesCount > 500) return false;
this.pagesCount = pagesCount;
return true;
}
public bool ChangeOrder(int pagesCount, int copiesCount, bool isColor)
{
if (isComplete) return false;
if (copiesCount < 1) return false;
else if (copiesCount > 100) return false;
if (!ChangeOrder(pagesCount)) return false;
this.copiesCount = copiesCount;
this.isColor = isColor;
return true;
}
public decimal CalculateCost()
{
if (copiesCount == 1 && !isColor) return Price.CalculateCost(pagesCount);
else if (!isColor) return Price.CalculateCost(pagesCount, copiesCount);
else return Price.CalculateCost(pagesCount,copiesCount, isColor);
}
public string Info()
{
return $"Заказ № {ID} | Клиент: {customerName} | Страниц: {pagesCount} | Экземпляров: {copiesCount} | Печать: {(isColor ? "цветная" : "черно-белая")} | Состояние: {(isComplete ? "Выполнен" : "Принят")} | Стоимость: {(float)CalculateCost():F2} руб.";
}
public bool CompleteOrder()
{
if(isComplete) return false;
totalCompleteOrdersCount++;
totalCost += CalculateCost();
isComplete = true;
return true;
}
static public string TotalInfo()
{
return $"Принято заказов: {totalOrdersCount} | Выполнено заказов: {totalCompleteOrdersCount} | Общая сумма выручки: {totalCost}";
}
}