コード例 #1
0
        public static change view_changing(Int32 id)
        {
            Decimal profit       = 0;
            DL      temp         = new DL();
            string  name_company = temp [id].name;            //here we have a name of needed company

            //searching
            Decimal old_cost = 0;
            Entity  i        = Base.first_e;

            while (i != null)
            {
                //for each record in entity's list we should calculate profit
                if (i.name == name_company)
                {
                    //ok, this's needed company
                    //let's calculate profit
                    changing j = Base.first_c;
                    Decimal  q = i.count * i.cost;
                    while (j != null)
                    {
                        if (j.name == name_company && j.date.CompareTo(i.date) > 0)
                        {
                            q = q * (1 + (Decimal)j.change / 100);
                        }
                        j = j.next;
                    }
                    old_cost += i.cost * i.count;
                    profit   += q;
                }
                i = i.next;
            }
            change ret = new change();

            ret.new_cost = profit;
            ret.profit   = profit - old_cost;
            ret.percent  = ((float)(profit / old_cost) - 1) * 100;
            return(ret);
        }
コード例 #2
0
        public static void show_menu()
        {
            var text =
                "1. Добавить элемент\n" +
                "2. Вывести все элементы\n" +
                "3. Вывести элемент по id\n" +
                "4. Изменить элемент\n" +
                "5. Удалить элемент\n" +
                "6. Вычислить цену акций для указанной фирмы\n" +
                "7. Выход";

            bool f = true;

            while (f)
            {
                Console.WriteLine(text);
                Int32 input;
                if (!Int32.TryParse(Console.ReadLine(), out input))
                {
                    input = 100;
                }
                switch (input)
                {
                case 1:
                    //Добавление элемента
                    string   name;
                    DateTime date;
                    Int32    count;
                    Decimal  cost;
                    input_data(out name, out date, out count, out cost);
                    BL.add(name, date, count, cost);
                    break;

                case 2:
                    //Вывод всех элементов
                    Console.WriteLine(BL.show_all());
                    break;

                case 3:
                    //Вывод элемента по id
                    Console.WriteLine(BL.show_all(true));
                    Console.WriteLine("Введите id выводимого элемента. Для отмены введите 0 ");
                    int    int_temp = 0;
                    Entity current;
                    while (true)
                    {
                        string temp = Console.ReadLine();
                        if (Int32.TryParse(temp, out int_temp))
                        {
                            current = BL.show_current(int_temp);
                            if (int_temp == 0)
                            {
                                break;
                            }
                            if (current != null)
                            {
                                break;
                            }
                            else
                            {
                                Console.WriteLine(constants.error_input);
                            }
                        }
                        else
                        {
                            Console.WriteLine(constants.error_input);
                        }
                    }

                    if (current == null)
                    {
                        Console.WriteLine(constants.error_input);
                    }
                    else
                    {
                        string s =
                            "Наименование фирмы: " + current.name + "\n" +
                            "Дата покупки: " + current.date.ToString("d") + "\n" +
                            "Количество: " + current.count + "\n" +
                            "Стоимость: " + current.cost;
                        Console.WriteLine(s);
                    }
                    break;

                case 4:
                    //Изменение элемента
                    Console.WriteLine(BL.show_all(true));
                    Console.WriteLine("Введите id изменяемого элемента. Для отмены введите 0 ");
                    Int32 id = 0;
                    while (true)
                    {
                        string temp = Console.ReadLine();
                        if (Int32.TryParse(temp, out id))
                        {
                            current = BL.show_current(id);
                            if (id == 0)
                            {
                                break;
                            }
                            if (current != null)
                            {
                                break;
                            }
                            break;
                        }
                        else
                        {
                            Console.WriteLine(constants.error_input);
                        }
                    }
                    if (id != 0)
                    {
                        Console.WriteLine("Старые значения:");

                        string s =
                            "Наименование фирмы: " + current.name + "\n" +
                            "Дата покупки: " + current.date.ToString("d") + "\n" +
                            "Количество: " + current.count + "\n" +
                            "Стоимость: " + current.cost;
                        Console.WriteLine(s);
                        input_data(out name, out date, out count, out cost);
                        BL.edit(id, name, date, count, cost);
                    }
                    break;

                case 5:
                    //Удаление элемента
                    Console.WriteLine(BL.show_all(true));
                    Console.WriteLine("Введите id удаляемого элемента ");
                    while (true)
                    {
                        string temp = Console.ReadLine();
                        if (Int32.TryParse(temp, out id))
                        {
                            break;
                        }
                        else
                        {
                            Console.WriteLine(constants.error_input);
                        }
                    }
                    BL.delete(id);
                    break;

                case 6:
                    //Вычисление цен акций
                    Console.WriteLine(BL.show_all(true));
                    Console.WriteLine("Введите id фирмы\n" +
                                      "Можно ввести любой id интересующей фирмы");
                    while (true)
                    {
                        string temp = Console.ReadLine();
                        if (Int32.TryParse(temp, out id))
                        {
                            break;
                        }
                        else
                        {
                            Console.WriteLine(constants.error_input);
                        }
                    }

                    change cur = BL.view_changing(id);

                    Console.WriteLine("Текущая стоимость акций данной компании: {0:0.000}", cur.new_cost);
                    if (cur.profit >= 0)
                    {
                        Console.WriteLine("Прибыль: {0:0.000}", cur.profit);
                    }
                    else
                    {
                        Console.WriteLine("Убыль: {0:0.000}", cur.profit);
                    }
                    if (cur.percent >= 0)
                    {
                        Console.WriteLine("Процент роста: {0}%", cur.percent);
                    }
                    else
                    {
                        Console.WriteLine("Процент спада: {0:0.00}%", cur.percent);
                    }
                    break;

                case 0:
                case 7:
                    //Выход
                    f = false;
                    break;

                default:
                    Console.WriteLine("Неверный ввод!");
                    break;
                }
            }
        }