Ejemplo n.º 1
0
        /// <summary>
        /// Sort worker list by two fields.
        /// </summary>
        /// <param name="dep">Department instance.</param>
        /// <param name="value">First digit in value is first field, Second digit is second.</param>
        /// <returns></returns>
        public static List <Worker> GetDoubleSortedList(Department dep, int value)
        {
            dSort sort = new dSort();
            Dictionary <int, List <Worker> > Sorting = new Dictionary <int, List <Worker> >();

            //First name + Second name.
            Sorting.Add(12, sort.fNameSName(dep));
            Sorting.Add(21, sort.fNameSName(dep));
            //First name + age.
            Sorting.Add(13, sort.fNameAge(dep));
            Sorting.Add(31, sort.fNameAge(dep));
            //First name + ID.
            Sorting.Add(14, sort.fNameID(dep));
            Sorting.Add(41, sort.fNameID(dep));
            //First name + salary.
            Sorting.Add(15, sort.fNameSalary(dep));
            Sorting.Add(51, sort.fNameSalary(dep));
            //First name + project count.
            Sorting.Add(16, sort.FNamePCount(dep));
            Sorting.Add(61, sort.FNamePCount(dep));

            //Second name + age.
            Sorting.Add(23, sort.sNameAge(dep));
            Sorting.Add(32, sort.sNameAge(dep));
            //Second name + ID.
            Sorting.Add(24, sort.sNameID(dep));
            Sorting.Add(42, sort.sNameID(dep));
            //Second name + salary.
            Sorting.Add(25, sort.sNameSalary(dep));
            Sorting.Add(52, sort.sNameSalary(dep));
            //Second name + project count.
            Sorting.Add(26, sort.SNamePCount(dep));
            Sorting.Add(62, sort.SNamePCount(dep));

            //Age + ID.
            Sorting.Add(34, sort.AgeId(dep));
            Sorting.Add(43, sort.AgeId(dep));
            //Age + Salary.
            Sorting.Add(35, sort.AgeSalary(dep));
            Sorting.Add(53, sort.AgeSalary(dep));
            //Age + project count.
            Sorting.Add(36, sort.AgePCount(dep));
            Sorting.Add(63, sort.AgePCount(dep));

            //ID + salary.
            Sorting.Add(45, sort.IDSalary(dep));
            Sorting.Add(54, sort.IDSalary(dep));
            //ID + project count.
            Sorting.Add(46, sort.IDPCount(dep));
            Sorting.Add(64, sort.IDPCount(dep));

            //Salary + project count.
            Sorting.Add(56, sort.SalaryPCount(dep));
            Sorting.Add(65, sort.SalaryPCount(dep));

            return(Sorting[value]);
        }
Ejemplo n.º 2
0
        public static void SortDepartmentMenu(Department dep)
        {
            Console.Clear();
            dSort sort = new dSort();

            Console.WriteLine("По одному(1) или двум(2) полям?");
            int sortMode = -1;

            //Check for proper values
            while (sortMode < 1 || sortMode > 2)
            {
                Console.WriteLine("Введите значение: ");
                int.TryParse(Console.ReadLine(), out sortMode);
            }

            #region Single Sort.

            if (sortMode == 1)
            {
                Console.Clear();
                Console.WriteLine("Выберите поле: ");
                Console.WriteLine("1 - Имя.");
                Console.WriteLine("2 - Фамилия.");
                Console.WriteLine("3 - Возраст.");
                Console.WriteLine("4 - ID.");
                Console.WriteLine("5 - Зарплата.");
                Console.WriteLine("6 - Количество закрепленных проэктов.");
                int fieldMode = -1;
                while (fieldMode < 1 || fieldMode > 6)
                {
                    Console.WriteLine("Введите значение.");
                    int.TryParse(Console.ReadLine(), out fieldMode);
                    switch (fieldMode)
                    {
                    case 1:
                        dep.RewriteWorkerList(sort.fName(dep));
                        Console.WriteLine(dep.PrintDepartment());
                        break;

                    case 2:
                        dep.RewriteWorkerList(sort.sName(dep));
                        Console.WriteLine(dep.PrintDepartment());
                        break;

                    case 3:
                        dep.RewriteWorkerList(sort.Age(dep));
                        Console.WriteLine(dep.PrintDepartment());
                        break;

                    case 4:
                        dep.RewriteWorkerList(sort.ID(dep));
                        Console.WriteLine(dep.PrintDepartment());
                        break;

                    case 5:
                        dep.RewriteWorkerList(sort.Salary(dep));
                        Console.WriteLine(dep.PrintDepartment());
                        break;

                    case 6:
                        dep.RewriteWorkerList(sort.PCount(dep));
                        Console.WriteLine(dep.PrintDepartment());
                        break;
                    }

                    Console.ReadKey();
                }
            }

            #endregion

            #region Double sort.

            else
            {
                Console.WriteLine("Выберите поля: ");
                Console.WriteLine("1 - Имя.");
                Console.WriteLine("2 - Фамилия.");
                Console.WriteLine("3 - Возраст.");
                Console.WriteLine("4 - ID.");
                Console.WriteLine("5 - Зарплата.");
                Console.WriteLine("6 - Количество закрепленных проэктов.");
                int fieldMode = -1;

                #region Check for proper values

                //List that contains all avaliable values
                int[] avaliableValues =
                {
                    12, 13, 14, 15, 16,
                    21, 31, 41, 51, 61,

                    23, 24, 25, 26,
                    32, 42, 52, 62,

                    34, 35, 36,
                    43, 53, 64,

                    45, 46,
                    54, 64,

                    56,
                    65
                };

                #endregion

                //check for proper values.
                while (!avaliableValues.Contains(fieldMode))
                {
                    Console.WriteLine("Введите два значения БЕЗ ПРОБЕЛА.");
                    int.TryParse(Console.ReadLine(), out fieldMode);
                }
                dep.RewriteWorkerList(GetDoubleSortedList(dep, fieldMode));
                Console.WriteLine(dep.PrintDepartment());
                Console.ReadKey();
            }

            #endregion
        }