private void PopulateChoices()
        {
            // Initialization.
            string        strConn       = "Data Source=LAPTOP-6RBMDIS7\\SQLEXPRESS;Database=DBMS_Project;Integrated Security=SSPI;";
            SqlConnection sqlConnection = new SqlConnection(strConn);
            SqlCommand    sqlCommand    = new SqlCommand("uspFetchCoursePreferenceDetails", sqlConnection);
            object        rowCount;

            try
            {
                // Settings.
                sqlCommand.CommandType    = CommandType.StoredProcedure;
                sqlCommand.Connection     = sqlConnection;
                sqlCommand.CommandTimeout = 12 * 3600; //// Setting timeeout for longer queries to 12 hours.

                sqlCommand.Parameters.Add("@student_id", SqlDbType.Int).Value = _studentId;

                // Open.
                sqlConnection.Open();

                SqlDataReader reader = sqlCommand.ExecuteReader();

                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        SelectedCourse sc = new SelectedCourse();
                        sc.CollegeName = reader.GetString(0);
                        sc.CourseName  = reader.GetString(1);
                        sc.Priority    = reader.GetInt32(2);
                        lvSelectedCourse.Items.Add(sc);
                    }
                }
                else
                {
                    Console.WriteLine("No rows found.");
                }
                sqlConnection.Close();
            }
            catch (Exception ex)
            {
                // Close.
                sqlConnection.Close();
            }
        }
        private void btnAddCourse_Click(object sender, RoutedEventArgs e)
        {
            int priority = 0;

            if (string.IsNullOrWhiteSpace(cbCourseName.SelectedItem.ToString()))
            {
                MessageBox.Show("Please select course name", "Invalid course name", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            if (string.IsNullOrWhiteSpace(cbCollegeName.SelectedItem.ToString()))
            {
                MessageBox.Show("Please select college name", "Invalid college name", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (!int.TryParse(udPriority.Value.ToString(), out priority) || priority < 1)
            {
                MessageBox.Show("Please enter value more than or equal to 1", "Invalid priority", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            var course = new SelectedCourse()
            {
                CollegeName = cbCollegeName.SelectedItem.ToString(), Priority = priority, CourseName = cbCourseName.SelectedItem.ToString()
            };

            foreach (var courseItem in lvSelectedCourse.Items)
            {
                if (((SelectedCourse)courseItem).CollegeName == course.CollegeName &&
                    ((SelectedCourse)courseItem).CourseName == course.CourseName)
                {
                    MessageBox.Show("Same combination exists, please enter different combination", "Combination exists", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                if (((SelectedCourse)courseItem).Priority == course.Priority)
                {
                    MessageBox.Show("Same priority exists, please enter different priority", "Priority exists", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }

            lvSelectedCourse.Items.Add(course);
        }
 private void OnPrevClicked(object sender, RoutedEventArgs e)
 {
     if (tabDocDetail.IsSelected)
     {
         if (!UpdateDocumentDetail())
         {
             MessageBox.Show("Unexpected Error");
         }
         else
         {
             MessageBox.Show("Document details saved successfully!!!", "Data saved", MessageBoxButton.OK);
             tabStudentDetail.IsSelected = true;
             btnPrev.Visibility          = Visibility.Collapsed;
             FetchStudentDetails();
         }
     }
     else if (tabMarkDetails.IsSelected)
     {
         if (!UpdateMarkDetails())
         {
             MessageBox.Show("Unexpected Error");
         }
         else
         {
             MessageBox.Show("Mark details saved successfully!!!", "Data saved", MessageBoxButton.OK);
             tabDocDetail.IsSelected = true;
             FetchDocumentDetails();
         }
     }
     else if (tabChoice.IsSelected)
     {
         foreach (var course in lvSelectedCourse.Items)
         {
             SelectedCourse selectedCourse = course as SelectedCourse;
             bool           resp           = UpdateCourseDetails(selectedCourse.CollegeName, selectedCourse.CourseName, selectedCourse.Priority);
             if (!resp)
             {
                 MessageBox.Show("Unexpected Error");
                 return;
             }
         }
         MessageBox.Show("Course choice details saved successfully!!!", "Data saved", MessageBoxButton.OK);
         FetchMarkDetails();
         tabMarkDetails.IsSelected = true;
         btnNext.Visibility        = Visibility.Visible;
     }
     else if (tabAllocation.IsSelected)
     {
         foreach (var course in lvSelectedCourse.Items)
         {
             SelectedCourse selectedCourse = course as SelectedCourse;
             bool           resp           = UpdateCourseDetails(selectedCourse.CollegeName, selectedCourse.CourseName, selectedCourse.Priority);
             if (!resp)
             {
                 MessageBox.Show("Unexpected Error");
                 return;
             }
         }
         tabChoice.IsSelected = true;
         btnNext.Visibility   = Visibility.Visible;
     }
 }