/*
         * Build the entire page
         */
        public void Page()
        {
            Console.Clear();
            // print the current menu and current page
            this.PrintMenu();
            ConIO.OutputNewLine();
            if (this.PrintMenuPage(this.CurrentMenu, this.CurrentPage))
            {
                ConIO.OutputNewLine();
            }
            ConIO command = null;

            // if a current command is given than skip the user input
            if (this.CurrentCommand == null)
            {
                command = ConIO.Input("Input");
                ConIO.OutputNewLine();
            }
            else
            {
                command             = new ConIO(this.CurrentCommand);
                this.CurrentCommand = null;
            }

            // execute the command
            this.Command(command);
        }
Exemple #2
0
        public static bool Confirm(string message)
        {
            ConIO confirm = null;

            do
            {
                ConIO.OutputLine(message);
                confirm = ConIO.Input("Confirm with (j/n)");
                ConIO.OutputNewLine();
            } while (!confirm.TestBool());
            return(confirm.BoolInput);
        }
        /*
         * Execute commands that depends on menu
         * Return true if the command was found
         */
        public bool MenuCommand(ConIO command)
        {
            switch (this.CurrentMenu)
            {
            case "root":
                switch (command.StringInput)
                {
                case "patients":
                    this.GoTo("patients", "patientlist");
                    return(true);

                case "illnesses":
                    this.GoTo("illnesses", "illnesslist");
                    return(true);

                case "back":
                    if (ConIO.Confirm("Exit programm?"))
                    {
                        ConIO.OutputLine("Programm beendet!");
                        Environment.Exit(0);
                    }
                    return(true);
                }
                break;

            case "patients":
                if (command.TestInt())
                {
                    Patient loadPatient = this.Fachkonzept.GetPatient(command.IntInput);
                    if (loadPatient == null)
                    {
                        ConIO.OutputError("ERROR: Patient " + command.IntInput + " not found!");
                    }
                    else
                    {
                        this.CurrentPatient = loadPatient;
                        this.GoTo("patient", "patient");
                    }
                    return(true);
                }
                switch (command.StringInput)
                {
                case "add":
                    this.GoTo("patient-add", "patient-add");
                    return(true);

                case "back":
                    this.GoTo("root");
                    return(true);
                }
                break;

            case "illnesses":
                if (command.TestInt())
                {
                    Illness loadIllness = this.Fachkonzept.GetIllness(command.IntInput);
                    if (loadIllness == null)
                    {
                        ConIO.OutputError("ERROR: Illness " + command.IntInput + " not found!");
                    }
                    else
                    {
                        this.CurrentIllness = loadIllness;
                        this.GoTo("illness", "illness");
                    }
                    return(true);
                }
                switch (command.StringInput)
                {
                case "add":
                    this.GoTo("illness-add", "illness-add");
                    return(true);

                case "back":
                    this.GoTo("root");
                    return(true);
                }
                break;

            case "patient":
                switch (command.StringInput)
                {
                case "edit":
                    this.GoTo("patient-edit", "patient-edit");
                    return(true);

                case "delete":
                    if (ConIO.Confirm("Delete Patient (" + this.DescribePatient(this.CurrentPatient) + ")?"))
                    {
                        if (this.Fachkonzept.DeletePatient(this.CurrentPatient))
                        {
                            this.GoTo("patients", "patientlist");
                        }
                        else
                        {
                            ConIO.OutputError("ERROR: Can not delete Patient (" + this.DescribePatient(this.CurrentPatient) + ")!");
                        }
                    }
                    return(true);

                case "illnesses":
                    this.GoTo("patient-illness", "patient-illnesslist");
                    return(true);

                case "back":
                    this.GoTo("patients", "patientlist");
                    return(true);
                }
                break;

            case "illness":
                switch (command.StringInput)
                {
                case "edit":
                    this.GoTo("illness-edit", "illness-edit");
                    return(true);

                case "delete":
                    if (ConIO.Confirm("Delete Illness (" + this.DescribeIllness(this.CurrentIllness) + ")?"))
                    {
                        if (this.Fachkonzept.DeleteIllness(this.CurrentIllness))
                        {
                            this.GoTo("illnesses", "illnesslist");
                        }
                        else
                        {
                            ConIO.OutputError("ERROR: Can not delete Illness (" + this.DescribeIllness(this.CurrentIllness) + ")!");
                        }
                    }
                    return(true);

                case "patients":
                    this.GoTo("illness-patient", "illness-patientlist");
                    return(true);

                case "back":
                    this.GoTo("illnesses", "illnesslist");
                    return(true);
                }
                break;

            case "patient-illness":
                switch (command.StringInput)
                {
                case "add":
                    this.GoTo("patient-illness-add", "illnesslist");
                    return(true);

                case "remove":
                    this.GoTo("patient-illness-remove", "patient-illnesslist");
                    return(true);

                case "back":
                    this.GoTo("patient", "patient");
                    return(true);
                }
                break;

            case "illness-patient":
                switch (command.StringInput)
                {
                case "add":
                    this.GoTo("illness-patient-add", "patientlist");
                    return(true);

                case "remove":
                    this.GoTo("illness-patient-remove", "illness-patientlist");
                    return(true);

                case "back":
                    this.GoTo("illness", "illness");
                    return(true);
                }
                break;

            case "patient-add":
                switch (command.StringInput)
                {
                case "add":
                    this.CurrentPatient = new Patient();
                    ConIO input = null;

                    // set the FirstName field of the new patient
                    do
                    {
                        input = ConIO.Input("Patient First Name", "           : ");
                        if (this.CancelAddPatient(input.StringInput))
                        {
                            return(true);
                        }
                    } while (input.StringInput.Length == 0);
                    this.CurrentPatient.FirstName = input.StringInput;

                    // set the LastName field of the new patient
                    do
                    {
                        input = ConIO.Input("Patient Last Name", "            : ");
                        if (this.CancelAddPatient(input.StringInput))
                        {
                            return(true);
                        }
                    } while (input.StringInput.Length == 0);
                    this.CurrentPatient.LastName = input.StringInput;

                    // set the Birthday field of the new patient
                    bool isDate = false;
                    do
                    {
                        input = ConIO.Input("Patient Birthday (dd.mm.YYYY)");
                        if (this.CancelAddPatient(input.StringInput))
                        {
                            isDate = false;
                            break;
                        }
                        isDate = input.TestDate();
                        if (!isDate)
                        {
                            ConIO.OutputNewLine();
                            ConIO.OutputError("ERROR: Wrong date format!");
                        }
                    } while (!isDate);
                    if (isDate)
                    {
                        this.CurrentPatient.Birthday = input.DateInput;
                    }
                    else
                    {
                        return(true);
                    }

                    // confirm the new patient from the user before save the patient
                    ConIO.OutputNewLine();
                    this.PrintMenuPage("patient-add", "patient");
                    ConIO.OutputNewLine();
                    if (ConIO.Confirm("Add the Patient?"))
                    {
                        if (!this.Fachkonzept.CreatePatient(this.CurrentPatient))
                        {
                            ConIO.OutputError("ERROR: Can not create patient!");
                            this.GoTo("patients", "patientlist");
                            return(true);
                        }
                    }
                    else
                    {
                        this.GoTo("patients", "patientlist");
                        return(true);
                    }

                    this.GoTo("patient", "patient");
                    return(true);
                }
                break;

            case "illness-add":
                switch (command.StringInput)
                {
                case "add":
                    this.CurrentIllness = new Illness();
                    ConIO input = null;

                    // set the Name field of the new illness
                    do
                    {
                        input = ConIO.Input("Illness Name", "       : ");
                        if (this.CancelAddIllness(input.StringInput))
                        {
                            return(true);
                        }
                    } while (input.StringInput.Length == 0);
                    this.CurrentIllness.Name = input.StringInput;

                    // set the Contagious field of the new illness
                    do
                    {
                        input = ConIO.Input("Is Contagious?(j/n)");
                    } while (!input.TestBool() && input.StringInput != "cancel");
                    if (this.CancelAddIllness(input.StringInput))
                    {
                        return(true);
                    }
                    this.CurrentIllness.Contagious = input.BoolInput;

                    // set the Lethal field of the new illness
                    do
                    {
                        input = ConIO.Input("Is Lethal?(j/n)", "    : ");
                    } while (!input.TestBool() && input.StringInput != "cancel");
                    if (this.CancelAddIllness(input.StringInput))
                    {
                        return(true);
                    }
                    this.CurrentIllness.Lethal = input.BoolInput;

                    // set the Curable field of the new illness
                    do
                    {
                        input = ConIO.Input("Is Curable?(j/n)", "   : ");
                    } while (!input.TestBool() && input.StringInput != "cancel");
                    if (this.CancelAddIllness(input.StringInput))
                    {
                        return(true);
                    }
                    this.CurrentIllness.Curable = input.BoolInput;

                    // confirm the new illness from the user before save the illness
                    ConIO.OutputNewLine();
                    this.PrintMenuPage("illness-add", "illness");
                    ConIO.OutputNewLine();
                    if (ConIO.Confirm("Add the Illness?"))
                    {
                        if (!this.Fachkonzept.CreateIllness(this.CurrentIllness))
                        {
                            ConIO.OutputError("ERROR: Can not create illness!");
                            this.GoTo("illnesses", "illnesslist");
                            return(true);
                        }
                    }
                    else
                    {
                        this.GoTo("illnesses", "illnesslist");
                        return(true);
                    }

                    this.GoTo("illness", "illness");
                    return(true);
                }
                break;

            case "patient-edit":
                switch (command.StringInput)
                {
                case "edit":
                    ConIO.OutputLine("Enter an empty text to not change the value!");
                    ConIO.OutputNewLine();
                    ConIO input = null;

                    // edit the FirstName field of the current patient
                    input = this.InputEditField(this.CurrentPatient.FirstName, "First name");
                    if (this.CancelEditPatient(input.StringInput))
                    {
                        return(true);
                    }
                    if (input.StringInput.Length != 0)
                    {
                        this.CurrentPatient.FirstName = input.StringInput;
                    }

                    // edit the LastName field of the current patient
                    input = this.InputEditField(this.CurrentPatient.LastName, "Last name ");
                    if (this.CancelEditPatient(input.StringInput))
                    {
                        return(true);
                    }
                    if (input.StringInput.Length != 0)
                    {
                        this.CurrentPatient.LastName = input.StringInput;
                    }

                    // edit the Birthday field of the current patient
                    bool isDate = false;
                    do
                    {
                        input = this.InputEditField(this.CurrentPatient.Birthday.ToShortDateString(), "Birthday  ");
                        if (this.CancelEditPatient(input.StringInput))
                        {
                            return(true);
                        }
                        if (input.StringInput.Length == 0)
                        {
                            break;
                        }
                        isDate = input.TestDate();
                        if (!isDate)
                        {
                            ConIO.OutputNewLine();
                            ConIO.OutputError("ERROR: Wrong date format");
                        }
                    } while (!isDate);
                    if (isDate)
                    {
                        this.CurrentPatient.Birthday = input.DateInput;
                    }

                    // confirm the edit patient from the user before update the patient
                    ConIO.OutputNewLine();
                    this.PrintMenuPage("patient-edit", "patient");
                    ConIO.OutputNewLine();
                    if (ConIO.Confirm("Edit the Patient?"))
                    {
                        if (!this.Fachkonzept.UpdatePatient(this.CurrentPatient))
                        {
                            ConIO.OutputError("ERROR: Can not update patient!");
                            this.CurrentPatient = this.Fachkonzept.GetPatient(this.CurrentPatient.PatientID);
                        }
                    }
                    else
                    {
                        this.CurrentPatient = this.Fachkonzept.GetPatient(this.CurrentPatient.PatientID);
                    }

                    this.GoTo("patient", "patient");
                    return(true);
                }
                break;

            case "illness-edit":
                switch (command.StringInput)
                {
                case "edit":
                    ConIO.OutputLine("Enter an empty text to not change the value!");
                    ConIO.OutputNewLine();
                    ConIO input = null;

                    // edit the Name field of the current illness
                    input = this.InputEditField(this.CurrentIllness.Name, "Illness name       ");
                    if (this.CancelEditIllness(input.StringInput))
                    {
                        return(true);
                    }
                    if (input.StringInput.Length != 0)
                    {
                        this.CurrentIllness.Name = input.StringInput;
                    }

                    // edit the Contagious field of the current illness
                    do
                    {
                        input = this.InputEditField(this.CurrentIllness.Contagious.ToString(), "Is Contagious?(j/n)");
                    } while (!input.TestBool() && input.StringInput != "cancel" && input.StringInput.Length != 0);
                    if (this.CancelEditIllness(input.StringInput))
                    {
                        return(true);
                    }
                    if (input.StringInput.Length != 0)
                    {
                        this.CurrentIllness.Contagious = input.BoolInput;
                    }

                    // edit the Lethal field of the current illness
                    do
                    {
                        input = this.InputEditField(this.CurrentIllness.Lethal.ToString(), "Is Lethal?(j/n)    ");
                    } while (!input.TestBool() && input.StringInput != "cancel" && input.StringInput.Length != 0);
                    if (this.CancelEditIllness(input.StringInput))
                    {
                        return(true);
                    }
                    if (input.StringInput.Length != 0)
                    {
                        this.CurrentIllness.Lethal = input.BoolInput;
                    }

                    // edit the Curable field of the current illness
                    do
                    {
                        input = this.InputEditField(this.CurrentIllness.Curable.ToString(), "Is Curable?(j/n)   ");
                    } while (!input.TestBool() && input.StringInput != "cancel" && input.StringInput.Length != 0);
                    if (this.CancelEditIllness(input.StringInput))
                    {
                        return(true);
                    }
                    if (input.StringInput.Length != 0)
                    {
                        this.CurrentIllness.Curable = input.BoolInput;
                    }

                    // confirm the edit illness from the user before update the illness
                    ConIO.OutputNewLine();
                    this.PrintMenuPage("illness-edit", "illness");
                    ConIO.OutputNewLine();
                    if (ConIO.Confirm("Edit the Illness?"))
                    {
                        if (!this.Fachkonzept.UpdateIllness(this.CurrentIllness))
                        {
                            ConIO.OutputError("ERROR: Can not update Illness!");
                            this.CurrentIllness = this.Fachkonzept.GetIllness(this.CurrentIllness.IllnessID);
                        }
                    }
                    else
                    {
                        this.CurrentIllness = this.Fachkonzept.GetIllness(this.CurrentIllness.IllnessID);
                    }

                    this.GoTo("illness", "illness");
                    return(true);
                }
                break;

            case "patient-illness-add":
                switch (command.StringInput)
                {
                case "back":
                    this.GoTo("patient-illness", "patient-illnesslist");
                    return(true);

                default:
                    if (command.TestInt())
                    {
                        Illness illness = this.Fachkonzept.GetIllness(command.IntInput);
                        if (illness == null)
                        {
                            ConIO.OutputError("ERROR: Can not load Illness!");
                        }
                        else
                        {
                            // Confirm the link from illness to patient
                            if (ConIO.Confirm("Add Illness to patient?"))
                            {
                                if (!this.Fachkonzept.LinkPatientIllness(this.CurrentPatient, illness))
                                {
                                    ConIO.OutputError("ERROR: Can not link Illness to Patient!");
                                }
                            }
                            this.GoTo("patient-illness", "patient-illnesslist");
                        }
                        return(true);
                    }
                    break;
                }
                break;

            case "patient-illness-remove":
                switch (command.StringInput)
                {
                case "back":
                    this.GoTo("patient-illness", "patient-illnesslist");
                    return(true);

                default:
                    if (command.TestInt())
                    {
                        Illness illness = this.Fachkonzept.GetIllness(command.IntInput);
                        if (illness == null)
                        {
                            ConIO.OutputError("ERROR: Can not load Illness!");
                        }
                        else
                        {
                            // Confirm the delink of illness from patient
                            if (ConIO.Confirm("Remove Illness from Patient?"))
                            {
                                if (!this.Fachkonzept.DelinkPatientIllness(this.CurrentPatient, illness))
                                {
                                    ConIO.OutputError("ERROR: Can not delink Illness from Patient!");
                                }
                            }
                            this.GoTo("patient-illness", "patient-illnesslist");
                        }
                        return(true);
                    }
                    break;
                }
                break;

            case "illness-patient-add":
                switch (command.StringInput)
                {
                case "back":
                    this.GoTo("illness-patient", "illness-patientlist");
                    return(true);

                default:
                    if (command.TestInt())
                    {
                        Patient patient = this.Fachkonzept.GetPatient(command.IntInput);
                        if (patient == null)
                        {
                            ConIO.OutputError("ERROR: Can not load Patient!");
                        }
                        else
                        {
                            // Confirm the link from patient to illness
                            if (ConIO.Confirm("Add Patient to Illness?"))
                            {
                                if (!this.Fachkonzept.LinkPatientIllness(patient, this.CurrentIllness))
                                {
                                    ConIO.OutputError("ERROR: Can not link Patient to Illness!");
                                }
                            }
                            this.GoTo("illness-patient", "illness-patientlist");
                        }
                        return(true);
                    }
                    break;
                }
                break;

            case "illness-patient-remove":
                switch (command.StringInput)
                {
                case "back":
                    this.GoTo("illness-patient", "illness-patientlist");
                    return(true);

                default:
                    if (command.TestInt())
                    {
                        Patient patient = this.Fachkonzept.GetPatient(command.IntInput);
                        if (patient == null)
                        {
                            ConIO.OutputError("ERROR: Can not load Patient!");
                        }
                        else
                        {
                            // Confirm the delink of Patient from Illness
                            if (ConIO.Confirm("Remove Patient from Illness?"))
                            {
                                if (!this.Fachkonzept.DelinkPatientIllness(patient, this.CurrentIllness))
                                {
                                    ConIO.OutputError("ERROR: Can not delink Patient from Illness!");
                                }
                            }
                            this.GoTo("illness-patient", "illness-patientlist");
                        }
                        return(true);
                    }
                    break;
                }
                break;
            }
            return(false);
        }
 public ConIO InputEditField(string current, string description)
 {
     return(ConIO.Input(description + " : " + current, " > "));
 }
Exemple #5
0
 public static ConIO Input(string description)
 {
     return(ConIO.Input(description, ": "));
 }
Exemple #6
0
 public static ConIO Input()
 {
     return(ConIO.Input("", ""));
 }
Exemple #7
0
 public static void OutputError(string text)
 {
     ConIO.OutputLine(text);
     ConIO.Input("Confirm with enter");
     ConIO.OutputNewLine();
 }