Ejemplo n.º 1
0
        static internal void ConsoleMode()
        {
            Reception rep = new Reception();

            rep.CreateNewModel();
            while (true)
            {
                Console.WriteLine("You are in Console mod now\nChoose operating mode.\nManager of: doctors(1), therapyAreas(2), diagnosis(3), appointments(4)\n");
                string mode = Console.ReadLine();
                if (mode == "doctors" || mode == "1")
                {
                    managerOfDoctorsMode();
                    continue;
                }
                if (mode == "therapyAreas" || mode == "2")
                {
                    managerOfTherapyAreas();
                    continue;
                }
                if (mode == "diagnosis" || mode == "3")
                {
                    managerOfDiagnosis();
                    continue;
                }
                if (mode == "appointments" || mode == "4")
                {
                    managerOfAppointments();
                    continue;
                }
                if (mode == "exit")
                {
                    return;
                }
                Console.WriteLine(mode + " is not an internal or external command, executable program, or batch file. Choose another operation");
            }

            void managerOfDoctorsMode()
            {
                ManagerOfDoctors manager = new ManagerOfDoctors(ref rep);

                Console.WriteLine("You are in Manager of doctors mode now");
                Console.WriteLine("Oprations: nextDay, add, getById, getByTherapyAreaId, delete, goBack");
                while (true)
                {
                    Console.WriteLine("Choose operation");
                    string operation = Console.ReadLine();

                    try
                    {
                        if (operation == "nextDay")
                        {
                            nextDay(manager);
                            continue;
                        }
                        if (operation == "add")
                        {
                            Console.WriteLine("enter id of doctor and his therapyAreaId");
                            string enter = Console.ReadLine();
                            int    id    = int.Parse(enter);

                            enter = Console.ReadLine();
                            int therapyAreaId;
                            if (enter == "-")
                            {
                                manager.AddDoctor(id);
                                Console.WriteLine("doctor was added");
                            }
                            else
                            {
                                therapyAreaId = int.Parse(enter);
                                manager.AddDoctor(id, therapyAreaId);
                                Console.WriteLine("doctor was added");
                            }
                            continue;
                        }
                        if (operation == "getById")
                        {
                            Console.WriteLine("enter id of doctor");
                            string enter = Console.ReadLine();
                            int    id    = int.Parse(enter);

                            Doctor doc = new Doctor();
                            manager.GetDoctorById(id, ref doc);
                            if (doc is Therapist)
                            {
                                Console.WriteLine(((Therapist)doc).id + " therapist");
                            }
                            else
                            {
                                Console.WriteLine(((Specialist)doc).id + " " + manager.TherapyAreas[((Specialist)doc).therapyAreaId].Item1);
                            }
                            continue;
                        }
                        if (operation == "getByTherapyAreaId")
                        {
                            Console.WriteLine("enter id of therapyArea");
                            List <Doctor> docs  = new List <Doctor>();
                            string        enter = Console.ReadLine();
                            int           id    = -1;
                            if (enter == "-")
                            {
                                manager.GetDoctorsByTherapyAreaId(ref docs);
                            }
                            else
                            {
                                id = int.Parse(enter);
                                manager.GetDoctorsByTherapyAreaId(ref docs, id);

                                for (int i = 0; i < docs.Count; i++)
                                {
                                    if (docs[i] is Therapist)
                                    {
                                        Console.WriteLine(((Therapist)docs[i]).id + " therapist");
                                    }
                                    else
                                    {
                                        Console.WriteLine(((Specialist)docs[i]).id + " " + manager.TherapyAreas[((Specialist)docs[i]).therapyAreaId].Item1);
                                    }
                                }
                            }
                            continue;
                        }
                        if (operation == "delete")
                        {
                            Console.WriteLine("enter id of doctor");
                            string enter = Console.ReadLine();
                            int    id    = int.Parse(enter);
                            manager.DeleteDoctor(id);
                            Console.WriteLine("Doctor deleted");
                            continue;
                        }
                        if (operation == "goBack")
                        {
                            return;
                        }
                        Console.WriteLine(operation + " is not an internal or external command, executable program, or batch file. Choose another operation");
                    }
                    catch (Exception exc)
                    {
                        Console.WriteLine(exc.Message);
                    }
                }
            }

            void managerOfDiagnosis()
            {
                managerOfDiagnosis manager = new managerOfDiagnosis(ref rep);

                Console.WriteLine("You are in Manager of diagnosis mode now");
                Console.WriteLine("Oprations: nextDay, add, getById, getByTherapyAreaId, getByDeathRate, delete, goBack");

                while (true)
                {
                    Console.WriteLine("Choose operation");
                    string operation = Console.ReadLine();

                    try
                    {
                        if (operation == "nextDay")
                        {
                            nextDay(manager);
                            continue;
                        }
                        if (operation == "add")
                        {
                            Console.WriteLine("enter id of diagnosis, its title and deathRate");
                            string enter = Console.ReadLine();

                            int    id    = int.Parse(enter);
                            string title = Console.ReadLine();
                            enter = Console.ReadLine();
                            if (enter == "-")
                            {
                                manager.AddDiagnosis(id, title);
                                Console.WriteLine("diagnosis was added");
                                continue;
                            }
                            else
                            {
                                int deathRate = int.Parse(enter);
                                manager.AddDiagnosis(id, title, deathRate);
                                Console.WriteLine("diagnosis was added");
                                continue;
                            }
                        }
                        if (operation == "getById")
                        {
                            Console.WriteLine("enter id of diagnosis");
                            string    enter     = Console.ReadLine();
                            int       id        = int.Parse(enter);
                            Diagnosis diagnosis = new Diagnosis(0, "");

                            manager.GetDiagnosisById(id, ref diagnosis);
                            Console.WriteLine(diagnosis.id + " " + diagnosis.title + " " + diagnosis.deathRate);
                            continue;
                        }
                        if (operation == "getByTherapyAreaId")
                        {
                            Console.WriteLine("enter id of therapyArea");
                            string           enter     = Console.ReadLine();
                            int              id        = int.Parse(enter);
                            List <Diagnosis> diagnoses = new List <Diagnosis>();

                            manager.GetDiagnosesByTherapyAreaId(id, ref diagnoses);
                            for (int i = 0; i < diagnoses.Count; i++)
                            {
                                Console.WriteLine(diagnoses[i].id + " " + diagnoses[i].title + " " + diagnoses[i].deathRate);
                            }
                            continue;
                        }
                        if (operation == "getByDeathRate")
                        {
                            Console.WriteLine("enter deathRate");
                            string           enter     = Console.ReadLine();
                            int              deathRate = int.Parse(enter);
                            List <Diagnosis> diagnoses = new List <Diagnosis>();

                            manager.GetDiagnosesByDeathRate(deathRate, ref diagnoses);
                            for (int i = 0; i < diagnoses.Count; i++)
                            {
                                Console.WriteLine(diagnoses[i].id + " " + diagnoses[i].title + " " + diagnoses[i].deathRate);
                            }
                            continue;
                        }
                        if (operation == "changeDeathRate")
                        {
                            Console.WriteLine("enter id of diagnosis and new deathRate");
                            string enter = Console.ReadLine();
                            int    id    = int.Parse(enter);
                            enter = Console.ReadLine();
                            int deathRate = int.Parse(enter);

                            manager.ChangeDeathRate(id, deathRate);
                            Console.WriteLine("deathRate was changed");
                            continue;
                        }
                        if (operation == "delete")
                        {
                            Console.WriteLine("enter id of diagnosis");
                            string enter = Console.ReadLine();
                            int    id    = int.Parse(enter);

                            manager.DeleteDiagnosis(id);
                            Console.WriteLine("diagnosis was deleted");
                            continue;
                        }
                        if (operation == "goBack")
                        {
                            return;
                        }
                        Console.WriteLine(operation + " is not an internal or external command, executable program, or batch file. Choose another operation");
                    }
                    catch (Exception exc)
                    {
                        Console.WriteLine(exc.Message);
                    }
                }
            }

            void managerOfTherapyAreas()
            {
                ManagerOfTherapyAreas manager = new ManagerOfTherapyAreas(ref rep);

                Console.WriteLine("You are in Manager of therapyAreas mode now");
                Console.WriteLine("Oprations: nextDay, add, getById, goBack");

                while (true)
                {
                    Console.WriteLine("Choose operation");
                    string operation = Console.ReadLine();

                    try
                    {
                        if (operation == "nextDay")
                        {
                            nextDay(manager);
                            continue;
                        }
                        if (operation == "add")
                        {
                            Console.WriteLine("enter id of therapyAreas, its title and diagnosesId");
                            string enter = Console.ReadLine();
                            int    id    = int.Parse(enter);
                            string title = Console.ReadLine();
                            enter = Console.ReadLine();
                            string[]   diagnosesId_ = enter.Split(" ");
                            List <int> diagnosesId  = new List <int>();
                            for (int i = 0; i < diagnosesId_.Length; i++)
                            {
                                diagnosesId.Add(int.Parse(diagnosesId_[i]));
                            }

                            manager.AddTherapyArea(id, title, diagnosesId);
                            Console.WriteLine("therapyArea was added");
                            continue;
                        }
                        if (operation == "getById")
                        {
                            Console.WriteLine("enter id of therapyArea");
                            string enter = Console.ReadLine();
                            int    id    = int.Parse(enter);
                            Tuple <string, List <int> > therapyArea = new Tuple <string, List <int> >("", new List <int>());

                            manager.GetTherapyAreaById(id, ref therapyArea);
                            Console.Write(therapyArea.Item1 + "  ");
                            for (int i = 0; i < therapyArea.Item2.Count; i++)
                            {
                                Console.Write(therapyArea.Item2[i] + " ");
                            }
                            continue;
                        }
                        if (operation == "goBack")
                        {
                            return;
                        }
                        Console.WriteLine(operation + " is not an internal or external command, executable program, or batch file. Choose another operation");
                    }
                    catch (Exception exc)
                    {
                        Console.WriteLine(exc.Message);
                    }
                }
            }

            void managerOfAppointments()
            {
                ManagerOfAppointments manager = new ManagerOfAppointments(ref rep);

                Console.WriteLine("You are in Manager of appointments mode now");
                Console.WriteLine("Oprations: nextDay, add, getAppointmentsForDay, getAppointmentsOfDoctor, getPatient, delete, changeDateTime, goBack");

                while (true)
                {
                    Console.WriteLine("Choose operation");
                    string operation = Console.ReadLine();

                    try
                    {
                        if (operation == "nextDay")
                        {
                            nextDay(manager);
                            continue;
                        }
                        if (operation == "add")
                        {
                            Console.WriteLine("enter id of patient");
                            string  enter   = Console.ReadLine();
                            int     id      = int.Parse(enter);
                            Patient patient = new Patient(id);

                            Console.WriteLine("enter id of doctor");
                            int doctorId = -1;
                            enter = Console.ReadLine();
                            if (enter != "-")
                            {
                                doctorId = int.Parse(enter);
                            }

                            Console.WriteLine("enter date (yy/mm/dd hh)");
                            enter = Console.ReadLine();
                            DateTime dateTime = new DateTime();
                            if (enter == "-")
                            {
                                manager.AddAppointment(patient, doctorId);
                            }
                            else
                            {
                                enter   += ":00:00";
                                dateTime = DateTime.Parse(enter);
                                manager.AddAppointment(patient, doctorId, dateTime);
                            }
                            Console.WriteLine("new appointment was added");
                            continue;
                        }
                        if (operation == "getAppointmentsForDay")
                        {
                            Console.WriteLine("enter date (yy/mm/dd)");
                            string   enter    = Console.ReadLine();
                            DateTime dateTime = DateTime.Parse(enter);
                            Dictionary <int, Dictionary <int, int> > outVal = new Dictionary <int, Dictionary <int, int> >();

                            manager.GetAppointmentsForDay(dateTime, ref outVal);
                            foreach (KeyValuePair <int, Dictionary <int, int> > doctorAppoint in outVal)
                            {
                                Console.Write(doctorAppoint.Key + ":  ");
                                if (doctorAppoint.Value.Count == 0)
                                {
                                    Console.Write("empty");
                                }
                                else
                                {
                                    foreach (KeyValuePair <int, int> appoint in doctorAppoint.Value)
                                    {
                                        Console.Write(appoint.Key + ":00  -  " + appoint.Value);
                                    }
                                }
                                Console.WriteLine();
                            }
                            continue;
                        }
                        if (operation == "getAppointmentsOfDoctor")
                        {
                            Console.WriteLine("enter id of doctor");
                            string enter = Console.ReadLine();
                            int    id    = int.Parse(enter);
                            Dictionary <DateTime, Dictionary <int, int> > appointmentsOfDoctor = new Dictionary <DateTime, Dictionary <int, int> >();

                            manager.GetAppointmentsOfDoctor(id, ref appointmentsOfDoctor);
                            foreach (KeyValuePair <DateTime, Dictionary <int, int> > day in appointmentsOfDoctor)
                            {
                                Console.Write(day.Key.Date + ":  ");
                                if (day.Value.Count == 0)
                                {
                                    Console.Write("empty");
                                }
                                else
                                {
                                    foreach (KeyValuePair <int, int> el in day.Value)
                                    {
                                        Console.Write(el.Key + ":00 - " + el.Value + ", ");
                                    }
                                }
                                Console.WriteLine();
                            }
                            continue;
                        }
                        if (operation == "getPatient")
                        {
                            Console.WriteLine("enter date (yy/mm/dd hh)");
                            string   enter    = Console.ReadLine() + ":00:00";
                            DateTime dateTime = DateTime.Parse(enter);
                            Console.WriteLine("enter id of doctor");
                            enter = Console.ReadLine();
                            int doctorId = int.Parse(enter);

                            int patientId = 0;
                            manager.GetPatient(dateTime, doctorId, ref patientId);
                            Console.WriteLine("patient id is " + patientId);
                            continue;
                        }
                        if (operation == "delete")
                        {
                            Console.WriteLine("enter date (yy/mm/dd hh)");
                            string   enter    = Console.ReadLine() + ":00:00";
                            DateTime dateTime = DateTime.Parse(enter);
                            Console.WriteLine("enter id of doctor");
                            int doctorId = int.Parse(enter);

                            manager.DeleteAppointment(dateTime, doctorId);
                            Console.WriteLine("appointment was deleted");
                            continue;
                        }
                        if (operation == "changeDateTime")
                        {
                            Console.WriteLine("enter previous date (yy/mm/dd hh)");
                            string   enter        = Console.ReadLine() + ":00:00";
                            DateTime prevDateTime = DateTime.Parse(enter);
                            Console.WriteLine("enter id of doctor");
                            enter = Console.ReadLine();
                            int doctorId = int.Parse(enter);
                            Console.WriteLine("enter new date (yy/mm/dd hh)");
                            enter = Console.ReadLine() + ":00:00";
                            DateTime newDateTime = DateTime.Parse(enter);

                            manager.ChangeAppointment(prevDateTime, doctorId, newDateTime);
                            Console.WriteLine("appointment was changed");
                            continue;
                        }
                        if (operation == "goBack")
                        {
                            return;
                        }
                        Console.WriteLine(operation + " is not an internal or external command, executable program, or batch file. Choose another operation");
                    }
                    catch (Exception exc)
                    {
                        Console.WriteLine(exc.Message);
                    }
                }
            }

            void nextDay(Reception reception)
            {
                reception.NextDay();
            }
        }