Example #1
0
        public static void Main(string[] args)
        {
            MyNewCollection firstCollection  = new MyNewCollection(6, "first");
            MyNewCollection secondCollection = new MyNewCollection(8, "second");

            Journal firstJournal = new Journal();

            firstCollection.CollectionCountChanged     += new CollectionHandler(firstJournal.CollectionCountChanged);
            firstCollection.CollectionReferenceChanged += new CollectionHandler(firstJournal.CollectionReferenceChanged);
            Journal secondJournal = new Journal();

            secondCollection.CollectionReferenceChanged += new CollectionHandler(firstJournal.CollectionReferenceChanged);
            secondCollection.CollectionReferenceChanged += new CollectionHandler(secondJournal.CollectionReferenceChanged);

            firstCollection.Add();
            firstCollection.Add();
            firstCollection.Remove(5);
            firstCollection.Remove(4);
            firstCollection.ChangeItem(3, 700);
            secondCollection.Remove(3);
            secondCollection.ChangeItem(6, 300);

            Console.WriteLine("перебор 1ой коллекции");
            foreach (Transport item in firstCollection._collection)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine();
            firstJournal.Print();
            Console.WriteLine();
            secondJournal.Print();
        }
Example #2
0
        static void PrintMenuPart2()
        {
            MyNewCollection <Document> l1 = new MyNewCollection <Document>();

            l1.Name = "Name";
            Document d  = new Document();
            Document c  = new Document();
            Check    c1 = new Check();
            Journal  j1 = new Journal();
            Journal  j2 = new Journal();

            l1.Add(1, d);
            l1.Add(2, c);
            l1.RemoveKey(c1);
            l1.PrintList();
            l1.CollectionCountChanged     += new CollectionHandler(j1.CollectionCountChange);
            l1.CollectionReferenceChanged += new CollectionHandler(j2.CollectionReferenceChange);
        }
Example #3
0
        static void Main(string[] args)
        {
            Random rand = new Random();
            int    menu = 10;


            while (menu != 0)
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("1. Демонстрация коллекции");
                Console.WriteLine("2. Часть №2");
                Console.WriteLine("0.Выход");
                Console.ResetColor();
                menu = InputMenu(2);
                mc1  = new MyCollection(10);


                if (menu == 0)
                {
                    break;
                }
                else
                {
                    int menuNext = 10;

                    switch (menu)
                    {
                        #region task1
                    case 1:

                        while (menuNext != 0)
                        {
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine("1.Показать коллекцию");
                            Console.WriteLine("2.Добавить элементы");
                            Console.WriteLine("3.Удалить элементы");
                            Console.WriteLine("4.Сортировка");
                            Console.WriteLine("5.Удалить коллекцию");
                            Console.WriteLine("6.Длина");
                            Console.WriteLine("0.Назад");
                            Console.ResetColor();
                            menuNext = InputMenu(6);

                            if (menuNext == 0)
                            {
                                break;
                            }
                            else
                            {
                                switch (menuNext)
                                {
                                case 1:
                                    mc1.Show();
                                    break;

                                case 2:
                                    Add();
                                    Console.WriteLine("Элементы добавлены");
                                    break;

                                case 3:
                                    Delete();
                                    Console.WriteLine("Элементы удалены");
                                    break;

                                case 4:
                                    mc1.Sort();
                                    mc1.Show();
                                    break;

                                case 5:
                                    mc1.Clear();
                                    mc1.Show();
                                    break;

                                case 6:
                                    Console.WriteLine($"Количество:{mc1.Count }");
                                    break;
                                }
                            }
                        }
                        break;
                        #endregion task1

                        #region task2
                    case 2:
                        MyNewCollection list1 = new MyNewCollection();
                        MyNewCollection list2 = new MyNewCollection();
                        list1.Name = "First";
                        list2.Name = "Second";

                        Journal jour1 = new Journal();
                        Journal jour2 = new Journal();

                        list1.CollectionCountChanged     += new CollectionHandler(jour1.CollectionCountChanged);
                        list1.CollectionReferenceChanged += new CollectionHandler(jour1.CollectionReferenceChanged);

                        list2.CollectionCountChanged     += new CollectionHandler(jour2.CollectionCountChanged);
                        list2.CollectionReferenceChanged += new CollectionHandler(jour2.CollectionReferenceChanged);

                        list1.AddRandom();
                        list1.AddRandom();
                        list1.AddRandom();
                        list1.AddRandom();

                        list2.AddRandom();
                        list2.AddRandom();
                        list2.AddRandom();
                        list2.AddRandom();

                        list1.Remove(1);
                        list2.Remove(2);

                        list1.ChangeValue(2);
                        list2.ChangeValue(1);

                        list1.Add(new Engine("ADD", 1111));
                        Console.WriteLine("В каждую коллекцию добавлено по 4 элемента");
                        Console.WriteLine("Из первой удален 1, из второй 2");
                        Console.WriteLine("В первой изменен 2(3 до удаления), во второй 1");
                        Console.WriteLine("В первую добавлен элемент ADD");
                        Console.WriteLine();

                        list1.Show();
                        Console.WriteLine();
                        list2.Show();

                        Console.WriteLine();
                        Console.WriteLine("Journal 1:");
                        Console.WriteLine();
                        jour1.ToString();
                        Console.WriteLine();
                        Console.WriteLine("Journal 2:");
                        Console.WriteLine();
                        jour2.ToString();



                        Console.ReadKey();

                        break;
                        #endregion task2
                    }
                }
            }
        }
Example #4
0
        static void AddElemInCollection(MyNewCollection collect)
        {
            bool t = false;

            while (!t)
            {
                Console.Clear();
                Console.Write(AddMENU);
                int choise = CheckInt();
                switch (choise)
                {
                case 1:
                    List <Transport> list = new List <Transport>();
                    int  size             = 0;
                    bool flag             = false;
                    while (!flag)
                    {
                        list.Add(AddTypeTransport(ref flag, $"Добавить {size + 1}-й элемент\n" +
                                                  TypeMENU));
                        size++;
                    }
                    list.RemoveAt(size - 1);
                    size--;
                    if (size != 0)
                    {
                        Transport[] arr = new Transport[size];
                        list.CopyTo(arr, 0);
                        collect.Add(arr);
                    }
                    else
                    {
                        Console.WriteLine("Попытка добавления пустого массива!");
                    }
                    ENTER();
                    t = true;
                    break;

                case 2:
                    Transport nwE = AddTypeTransport(ref t, $"Добавить {collect.Count} элемент\n" +
                                                     TypeMENU);
                    if (nwE != null)
                    {
                        collect.Add(nwE);
                    }
                    else
                    {
                        Console.WriteLine("Попытка добавления пустого элемента!");
                    }
                    t = true;
                    ENTER();
                    break;

                case 3:
                    collect.AddDefault();
                    ENTER();
                    t = true;
                    break;

                case 4:
                    t = true;
                    break;

                default:
                    Console.WriteLine("Неопознанное значение..");
                    ENTER();
                    break;
                }
            }
        }