public void Navigate()
        {
            while (userInput != e)
            {
                // NAVIGATION PANEL
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("____________________________TYPE TO NAVIGATE________________________________");
                Console.ForegroundColor = ConsoleColor.DarkRed;
                Console.WriteLine("============================================================================");
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine($"| {"(1) STUDENTS",-12} | {"(2) TRAINERS",-12} | {"(3) ASSIGNMENTS",-12} | {"(4) COURSES",-11} | {"(E) RETURN",-9} |");
                Console.ForegroundColor = ConsoleColor.DarkRed;
                Console.WriteLine("============================================================================");
                Console.ForegroundColor = ConsoleColor.White;

                userInput = Console.ReadLine();

                // Simple SELECT QUERYS
                if (userInput == one)
                {
                    sqlStudent MyS1 = new sqlStudent();
                    MyS1.StudentSelectOutput();
                }
                else if (userInput == two)
                {
                    sqlTrainer MyT1 = new sqlTrainer();
                    MyT1.TrainerSelectOutput();
                }
                else if (userInput == three)
                {
                    sqlAssignment MyA1 = new sqlAssignment();
                    MyA1.AssignmentSelectOutput();
                }
                else if (userInput == four)
                {
                    sqlCourse MyC1 = new sqlCourse();
                    MyC1.CourseSelectOutput();
                }

                // Exit and Wrong Input Cases
                else if (userInput == e)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("EXIT");
                    Console.ForegroundColor = ConsoleColor.White;
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.DarkRed;
                    Console.WriteLine("Unindentified Input, Please Choose Again");
                    Console.ForegroundColor = ConsoleColor.White;
                }
            }
        }
        public void InsertIntoTrainer()
        {
            // Display TRAINERS
            Console.ForegroundColor = ConsoleColor.DarkRed;
            Console.WriteLine("#==========================================================================#");
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine($"|                              EXISTING TRAINERS                           |");
            Console.ForegroundColor = ConsoleColor.DarkRed;
            Console.WriteLine("#==========================================================================#");
            Console.ForegroundColor = ConsoleColor.White;
            sqlTrainer MyT2 = new sqlTrainer();

            MyT2.TrainerSelectOutput();

            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine($"< TIP: Insert a 5 Character KEY (example: TR099) >");
            Console.ForegroundColor = ConsoleColor.DarkRed;
            Console.WriteLine("----------------------------------------------------------------------------");
            Console.ForegroundColor = ConsoleColor.White;
            Console.Write("Input Trainer ID: ");
            Trainer_ID = Console.ReadLine();


            Console.Write("Input First name: ");
            FirstName = Console.ReadLine();
            Console.Write("Input Last Name: ");
            LastName = Console.ReadLine();
            Console.Write("Input Subject of Teaching: ");
            Subject = Console.ReadLine();

            // Display COURSES
            Console.ForegroundColor = ConsoleColor.DarkRed;
            Console.WriteLine("#==========================================================================#");
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine($"|                            EXISTING COURSES                              |");
            Console.ForegroundColor = ConsoleColor.DarkRed;
            Console.WriteLine("#==========================================================================#");
            Console.ForegroundColor = ConsoleColor.White;
            sqlCourse MyC2 = new sqlCourse();

            MyC2.CourseSelectOutput();

            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine($"< TIP: Choose from the existing Courses Table Above >");
            Console.ForegroundColor = ConsoleColor.DarkRed;
            Console.WriteLine("----------------------------------------------------------------------------");
            Console.ForegroundColor = ConsoleColor.White;
            Console.Write("Input Course Title: ");
            CourseTitle = Console.ReadLine();

            string sqlInsertTrainer =
                "INSERT INTO Trainer(Trainer_ID, FirstName, LastName, Subject, CourseTitle) " +
                "VALUES (@trainerid, @firstname, @lastname, @sub, @coursetitle)";

            try
            {
                using (SqlConnection conn = new SqlConnection(ConnectionString.connection))
                {
                    conn.Open();

                    using (SqlCommand cmInsert = new SqlCommand(sqlInsertTrainer, conn))
                    {
                        cmInsert.Parameters.Add(new SqlParameter("trainerid", Trainer_ID));
                        cmInsert.Parameters.Add(new SqlParameter("firstname", FirstName));
                        cmInsert.Parameters.Add(new SqlParameter("lastname", LastName));
                        cmInsert.Parameters.Add(new SqlParameter("sub", Subject));
                        cmInsert.Parameters.Add(new SqlParameter("coursetitle", CourseTitle));

                        int rowsAffected = cmInsert.ExecuteNonQuery();

                        // Display A message for the Inserted TRAINER
                        Console.ForegroundColor = ConsoleColor.DarkRed;
                        Console.WriteLine("#==========================================================================#");
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine($"|                Trainers Inserted Succesfully: {rowsAffected,-26} |");
                        Console.ForegroundColor = ConsoleColor.DarkRed;
                        Console.WriteLine("#==========================================================================#");
                        Console.ForegroundColor = ConsoleColor.White;

                        // Bring the Table TRAINER to see our newly Input TRAINER
                        sqlTrainer MyIT1 = new sqlTrainer();
                        MyIT1.TrainerSelectOutput();

                        // Again, Show that the Trainer was Inserted at the end of the Table TRAINER
                        Console.ForegroundColor = ConsoleColor.DarkRed;
                        Console.WriteLine("#==========================================================================#");
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine($"|                Trainers Inserted Succesfully: {rowsAffected,-26} |");
                        Console.ForegroundColor = ConsoleColor.DarkRed;
                        Console.WriteLine("#==========================================================================#");
                        Console.ForegroundColor = ConsoleColor.White;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Beispiel #3
0
        public void InsertIntoTrainersPerCourse()
        {
            // Bring the Table COURSES to see/choose a specific COURSE KEY
            sqlCourse MyIC1 = new sqlCourse();

            MyIC1.CourseSelectOutput();

            // Input Data
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine($"< TIP: Insert KEY of choosen COURSE from the Table above >");
            Console.ForegroundColor = ConsoleColor.DarkRed;
            Console.WriteLine("----------------------------------------------------------------------------");
            Console.ForegroundColor = ConsoleColor.White;
            Console.Write("Input Course Title: ");
            CourseTitle = Console.ReadLine();

            // Bring the Table TRAINER as Existing TRAINERS
            // And ask Input of a new TRAINER
            // (That is because a TRAINER can teach ONLY ONE COURSE)

            // Display Title for the Table TRAINERS
            Console.ForegroundColor = ConsoleColor.DarkRed;
            Console.WriteLine("#==========================================================================#");
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine($"|                             EXISTING TRAINERS                            |");
            Console.ForegroundColor = ConsoleColor.DarkRed;
            Console.WriteLine("#==========================================================================#");
            Console.ForegroundColor = ConsoleColor.White;

            sqlTrainer MyIT1 = new sqlTrainer();

            MyIT1.TrainerSelectOutput();

            // Display Title for the Table TRAINERS
            Console.ForegroundColor = ConsoleColor.DarkRed;
            Console.WriteLine("#==========================================================================#");
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine($"|                 INPUT NEW TRAINER FOR THE CHOOSEN COURSE                 |");
            Console.ForegroundColor = ConsoleColor.DarkRed;
            Console.WriteLine("#==========================================================================#");
            Console.ForegroundColor = ConsoleColor.White;

            // Input Data
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine($"< TIP: Insert a 5 Character KEY (As seen in the above Table) >");
            Console.ForegroundColor = ConsoleColor.DarkRed;
            Console.WriteLine("----------------------------------------------------------------------------");
            Console.ForegroundColor = ConsoleColor.White;
            Console.Write("Input Trainer ID: ");
            Trainer_ID = Console.ReadLine();
            Console.Write("Input First name: ");
            FirstName = Console.ReadLine();
            Console.Write("Input Last Name: ");
            LastName = Console.ReadLine();

            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine($"< TIP: The subject description is suggested to match the COURSE previously choosen >");
            Console.ForegroundColor = ConsoleColor.DarkRed;
            Console.WriteLine("----------------------------------------------------------------------------");
            Console.ForegroundColor = ConsoleColor.White;
            Console.Write("Input Subject of Teaching: ");
            Subject = Console.ReadLine();

            string sqlInsertTrainer =
                "INSERT INTO Trainer(Trainer_ID, FirstName, LastName, Subject, CourseTitle) " +
                "VALUES (@trainerid, @firstname, @lastname, @sub, @coursetitle)";

            try
            {
                using (SqlConnection conn = new SqlConnection(ConnectionString.connection))
                {
                    conn.Open();

                    using (SqlCommand cmInsert = new SqlCommand(sqlInsertTrainer, conn))
                    {
                        cmInsert.Parameters.Add(new SqlParameter("trainerid", Trainer_ID));
                        cmInsert.Parameters.Add(new SqlParameter("firstname", FirstName));
                        cmInsert.Parameters.Add(new SqlParameter("lastname", LastName));
                        cmInsert.Parameters.Add(new SqlParameter("sub", Subject));
                        cmInsert.Parameters.Add(new SqlParameter("coursetitle", CourseTitle));

                        int rowsAffected = cmInsert.ExecuteNonQuery();

                        // Display A message for the Inserted TRAINER
                        Console.ForegroundColor = ConsoleColor.DarkRed;
                        Console.WriteLine("#==========================================================================#");
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine($"|                Trainers Inserted Succesfully: {rowsAffected,-26} |");
                        Console.ForegroundColor = ConsoleColor.DarkRed;
                        Console.WriteLine("#==========================================================================#");
                        Console.ForegroundColor = ConsoleColor.White;

                        // Bring the Table TRAINER to see our newly Input TRAINER
                        sqlTrainer MyNEWIT1 = new sqlTrainer();
                        MyNEWIT1.TrainerSelectOutput();

                        // Again, Show that the Trainer was Inserted at the end of the Table TRAINER
                        Console.ForegroundColor = ConsoleColor.DarkRed;
                        Console.WriteLine("#==========================================================================#");
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine($"|                Trainers Inserted Succesfully: {rowsAffected,-26} |");
                        Console.ForegroundColor = ConsoleColor.DarkRed;
                        Console.WriteLine("#==========================================================================#");
                        Console.ForegroundColor = ConsoleColor.White;

                        // Bring the Table TRAINER/COURSE to see our newly Input TRAINER
                        sqlTrainersPerCourse MyTperC1NT = new sqlTrainersPerCourse();
                        MyTperC1NT.TrainerCoursetOutput();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }