Пример #1
0
        /// <summary>
        /// Delete a lesson made by the teacher
        /// </summary>
        private void DeleteLesson()
        {
            //If a lesson has been selected
            if (CB_Lessons.SelectedIndex > -1)
            {
                //Open new instance of db class
                DBRepository DB = DBRepository.GetInstance();

                //Find the lesson by ID
                int Lesson_ID = DB.FindLessonIDByName(CB_Lessons.SelectedItem.ToString());

                //Delete this lesson from the lessons and from the Groups
                DB.DeleteLessonByID(Lesson_ID);
                DB.DeleteLessonAtGroupsByID(Lesson_ID);

                //Get new list of lessons
                GetAllLessons();

                MessageBox.Show("Les verwijderd!");
            }
            else
            {
                MessageBox.Show("Selecteer item om te verwijderen");
            }
        }
        /// <summary>
        /// Update the lesson
        /// </summary>
        private void UpdateLesson()
        {
            //Make new instance of DB Class
            DBRepository DB = DBRepository.GetInstance();


            //Make a new lesson object
            Lesson L = new Lesson(TB_Title.Text, LessonToEditID, CB_Lesson_Status.SelectedItem.ToString(), TB_Desc.Text, TB_Subject.Text, 0);

            //Update the lesson using the object
            DB.UpdateLesson(L);

            //Get Group Information
            var Groups   = DB.FindGroupData();
            int Group_ID = 0;

            //For every group in the list of groups
            foreach (var SGroup in Groups)
            {
                if (SGroup.GetGroupName() == CB_Classes.SelectedItem.ToString())
                {
                    //If groupname equals the selected group (add id)
                    Group_ID = SGroup.Get_Group_ID();
                }
            }

            //Delete previous groups that had this lesson
            DB.DeleteLessonAtGroupsByID(LessonToEditID);
            DB.DeleteImageFromLessonByID(LessonToEditID);
            DB.DeleteArtObjFromLessonByID(LessonToEditID);

            //Add this lesson to the groups that currently have this lesson
            if (CB_Classes.SelectedItem.ToString() == "All")
            {
                DB.InsertLessonForGroups(LessonToEditID, 0);

                //Inserting Images into Lesson
                Saving_Images_To_Lesson(LessonToEditID);

                //Inserting Art into Lesson
                Saving_Artobjects_To_Lesson(LessonToEditID);
            }
            else
            {
                DB.InsertLessonForGroups(LessonToEditID, Group_ID);

                //Inserting Images into Lesson
                Saving_Images_To_Lesson(LessonToEditID);

                //Inserting Art into Lesson
                Saving_Artobjects_To_Lesson(LessonToEditID);
            }

            MessageBox.Show("Lesson Updated");
        }