Пример #1
0
    static void Main(string[] args)
    {
        int numberOfCommands = int.Parse(Console.ReadLine());

        ShoppingCenter shoppingCenter = new ShoppingCenter();

        output = new StringBuilder();

        for (int i = 0; i < numberOfCommands; i++)
        {
            string commandLine = Console.ReadLine();

            int    indexFirstInterval      = commandLine.IndexOf(' ');
            string command                 = commandLine.Substring(0, indexFirstInterval);
            string commandParametersString = commandLine.Substring(indexFirstInterval + 1);

            string[] commandParameters = commandParametersString.Split(new char[] { ';' });

            switch (command)
            {
            case "AddProduct":
                shoppingCenter.Add(commandParameters[0], decimal.Parse(commandParameters[1]), commandParameters[2]);
                output.AppendLine("Product added");
                break;

            case "FindProductsByName":
                Product[] findByNameResult = shoppingCenter.FindProductByName(commandParameters[0]);
                Array.Sort(findByNameResult);
                PrintProductArray(findByNameResult);
                break;

            case "FindProductsByPriceRange":
                Product[] findByPriceResult =
                    shoppingCenter.FindProductByPriceRange(decimal.Parse(commandParameters[0]), decimal.Parse(commandParameters[1]));
                Array.Sort(findByPriceResult);
                PrintProductArray(findByPriceResult);
                break;

            case "FindProductsByProducer":
                Product[] findByProducerResult = shoppingCenter.FindProductByProducer(commandParameters[0]);
                Array.Sort(findByProducerResult);
                PrintProductArray(findByProducerResult);
                break;

            case "DeleteProducts":
                int deletedProducts;
                if (commandParameters.Length == 2)
                {
                    deletedProducts = shoppingCenter.DeleteProduct(commandParameters[0], commandParameters[1]);
                }
                else
                {
                    deletedProducts = shoppingCenter.DeleteProduct(commandParameters[0]);
                }

                if (deletedProducts == 0)
                {
                    output.AppendLine("No products found");
                }
                else
                {
                    output.AppendLine(deletedProducts + " products deleted");
                }
                break;

            default:
                break;
            }
        }

        Console.WriteLine(output.ToString().Trim());
    }