Пример #1
0
        /// <summary>
        /// Inserts trainers in a Course
        /// </summary>
        public static void TrainersPerCourse()
        {
            // Course selection
            ReadDB.Courses();
            Console.Write("Choose the id of the course: ");
            int courseSelection = IntInput();

            // Trainer selection
            ReadDB.Trainers();
            Console.Write("Choose the id of the trainer: ");
            int trainerSelection = IntInput();

            string insertqr = "Insert into Course_Trainer (CourseID, TrainerID ) " +
                              "values (@CourseID, @TrainerID)";


            try
            {
                using (SqlConnection dbcon = new SqlConnection(connectionString))
                {
                    dbcon.Open();
                    var command = new SqlCommand(insertqr, dbcon);

                    command.Parameters.AddWithValue("@CourseID", courseSelection);
                    command.Parameters.AddWithValue("@TrainerID", trainerSelection);


                    command.ExecuteNonQuery();
                }

                Console.WriteLine("Trainer related successfully to the course!");
            }
            catch (SqlException e)
            {
                Console.WriteLine("Error Type: " + e.Message);
            }
            finally { }
        }
Пример #2
0
        /// <summary>
        /// Inserts assignments in a Course per Student
        /// </summary>
        public static void AssignmentsPerCoursePerStudent()
        {
            // Course selection
            ReadDB.Courses();
            Console.Write("Choose the id of the course: ");
            int courseSelection = IntInput();

            // Student selection
            ReadDB.Students();
            Console.Write("Choose the id of the student: ");
            int studentSelection = IntInput();

            // Assignment selection
            ReadDB.Assignments();
            Console.Write("Choose the id of the assignment: ");
            int assignmentSelection = IntInput();

            Console.WriteLine("Is the assignment submitted?");
            if (BoolInput())
            {
                // Assignment selection
                Console.Write("Insert the oral mark (if exists): ");
                int?OralMark = MarkInput();

                // Assignment selection
                Console.Write("Insert the total mark (if exists): ");
                int?TotalMark = MarkInput();

                string insertqr = "Insert into AssignmentPerCoursePerStudent (StudentID, CourseID, AssignmentID, Submited, OralMark, TotalMark) " +
                                  "values (@StudentID, @CourseID, @AssignmentID, @Submited, @OralMark, @TotalMark)";

                try
                {
                    using (SqlConnection dbcon = new SqlConnection(connectionString))
                    {
                        dbcon.Open();
                        var command = new SqlCommand(insertqr, dbcon);

                        command.Parameters.AddWithValue("@CourseID", courseSelection);
                        command.Parameters.AddWithValue("@StudentID", studentSelection);
                        command.Parameters.AddWithValue("@AssignmentID", assignmentSelection);
                        command.Parameters.AddWithValue("@Submited", true);
                        command.Parameters.AddWithValue("@OralMark", OralMark);
                        command.Parameters.AddWithValue("@TotalMark", TotalMark);


                        command.ExecuteNonQuery();
                    }
                    Console.WriteLine("Assignment related successfully to the course and to the student!");
                }
                catch (SqlException e)
                {
                    Console.WriteLine("Error Type: " + e.Message);
                }
                finally { }
            }
            else
            {
                string insertqr = "Insert into AssignmentPerCoursePerStudent (StudentID, CourseID, AssignmentID, Submited) " +
                                  "values (@StudentID, @CourseID, @AssignmentID, @Submited)";
                try
                {
                    using (SqlConnection dbcon = new SqlConnection(connectionString))
                    {
                        dbcon.Open();
                        var command = new SqlCommand(insertqr, dbcon);

                        command.Parameters.AddWithValue("@CourseID", courseSelection);
                        command.Parameters.AddWithValue("@StudentID", studentSelection);
                        command.Parameters.AddWithValue("@AssignmentID", assignmentSelection);
                        command.Parameters.AddWithValue("@Submited", false);


                        command.ExecuteNonQuery();
                    }
                    Console.WriteLine("Assignment related successfully to the course and to the student!");
                }
                catch (SqlException e)
                {
                    Console.WriteLine("Error Type: " + e.Message);
                }
                finally { }
            }
        }
Пример #3
0
        /// <summary>
        /// Enters the choice from "ViewMenu()" method and enters to the selected choice
        /// </summary>
        /// <param name="input"></param>
        static void ViewChoiceSwitch(string input)
        {
            switch (input)
            {
            case "1":
            {
                ReadDB.Courses();
                break;
            }

            case "2":
            {
                ReadDB.Trainers();
                break;
            }

            case "3":
            {
                ReadDB.Students();
                break;
            }

            case "4":
            {
                ReadDB.Assignments();
                break;
            }

            case "5":
            {
                ReadDB.StudentsPerCourse();
                break;
            }

            case "6":
            {
                ReadDB.TrainersPerCourse();
                break;
            }

            case "7":
            {
                ReadDB.AssignmentsPerCourse();
                break;
            }

            case "8":
            {
                ReadDB.AssignmentsPerCoursePerStudent();
                break;
            }

            case "9":
            {
                ReadDB.StudentsOver1Course();
                break;
            }

            default:
            {
                Console.WriteLine("Invalid selection! Please try again");
                break;
            }
            }
        }