Exemplo n.º 1
0
        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/COURSE",-20} | {"(2) TRAINERS/COURSE",-20} | {"(3) ASSIGNMENTS/COURSE",-26} | " +
                                  $"\n| {"(4) ASSIGNMENTS per COURSE per STUDENT",-43} | {"(E) RETURN",-26} |");
                Console.ForegroundColor = ConsoleColor.DarkRed;
                Console.WriteLine("============================================================================");
                Console.ForegroundColor = ConsoleColor.White;


                userInput = Console.ReadLine();

                // More Complex SELECT QUERYS
                if (userInput == one)
                {
                    sqlStudentsPerCourse MySperC1 = new sqlStudentsPerCourse();
                    MySperC1.StudentCoursetOutput();
                }
                else if (userInput == two)
                {
                    sqlTrainersPerCourse MyTperC1 = new sqlTrainersPerCourse();
                    MyTperC1.TrainerCoursetOutput();
                }
                else if (userInput == three)
                {
                    sqlAssPerCourse MyAperC1 = new sqlAssPerCourse();
                    MyAperC1.AssignmentCoursetOutput();
                }
                else if (userInput == four)
                {
                    sqlAssPerCoursePerStudent MyAperCperS1 = new sqlAssPerCoursePerStudent();
                    MyAperCperS1.AssCourseStudenttOutput();
                }

                // 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 InsertIntoStudentPerCourse()
        {
            // Bring the Table STUDENT to see/choose a specific STUDENT KEY
            Console.ForegroundColor = ConsoleColor.DarkRed;
            Console.WriteLine("#==========================================================================#");
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine($"|                              EXISTING STUDENTS                           |");
            Console.ForegroundColor = ConsoleColor.DarkRed;
            Console.WriteLine("#==========================================================================#");
            Console.ForegroundColor = ConsoleColor.White;
            sqlStudent MyS2 = new sqlStudent();

            MyS2.StudentSelectOutput();

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

            // Bring the Table COURSES to see/choose a specific COURSE KEY
            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();

            // 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();

            string splInsertStudentCourse = "INSERT INTO CourseStudent(CourseTitle, Student_ID ) " +
                                            "VALUES (@coursetitle, @studentid)";

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

                    using (SqlCommand cmInsert = new SqlCommand(splInsertStudentCourse, conn))
                    {
                        cmInsert.Parameters.Add(new SqlParameter("CourseTitle", CourseTitle));
                        cmInsert.Parameters.Add(new SqlParameter("studentid", Student_ID));

                        int rowsAffected = cmInsert.ExecuteNonQuery();

                        // Display A message for the Inserted STUDENT
                        Console.ForegroundColor = ConsoleColor.DarkRed;
                        Console.WriteLine("#==========================================================================#");
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine($"|                     Successful Insertion: {rowsAffected,-30} |");
                        Console.ForegroundColor = ConsoleColor.DarkRed;
                        Console.WriteLine("#==========================================================================#");
                        Console.ForegroundColor = ConsoleColor.White;

                        // Bring the Table STUDENT/COURSE
                        sqlStudentsPerCourse MySperC2 = new sqlStudentsPerCourse();
                        MySperC2.StudentCoursetOutput();

                        // Display A message for the Inserted STUDENT again
                        Console.ForegroundColor = ConsoleColor.DarkRed;
                        Console.WriteLine("#==========================================================================#");
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine($"|                     Successful Insertion: {rowsAffected,-30} |");
                        Console.ForegroundColor = ConsoleColor.DarkRed;
                        Console.WriteLine("#==========================================================================#");
                        Console.ForegroundColor = ConsoleColor.White;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }