Beispiel #1
0
        private void comboBox1_TextChanged(object sender, EventArgs e)
        {
            for (int i = 0; i < checkedListBox1.Items.Count; i++)
            {
                checkedListBox1.SetItemChecked(i, false);
            }

            List <Teacher> TeacherList = TeacherDB.TeacherLoad();
            List <Classes> ClassList   = ClassesDB.ClassLoad();

            string[] teacherName = comboBox1.Text.Split(' ');
            Teacher  teacher     = TeacherDB.TeacherFind(Convert.ToInt32(teacherName[0]));

            for (int i = 0; i < checkedListBox1.Items.Count; i++)
            {
                string[] classid = checkedListBox1.Items[i].ToString().Split(' ');

                foreach (int id in teacher.ClassID)
                {
                    if (Convert.ToInt32(classid[0]) == id)
                    {
                        checkedListBox1.SetItemChecked(i, true);
                    }
                }
            }
        }
Beispiel #2
0
        private void EditTeacher_Load(object sender, EventArgs e)
        {
            dataGridView1.Rows.Clear();
            dataGridView1.Refresh();

            dataGridView1.ColumnCount     = 3;
            dataGridView1.Columns[0].Name = "Class ID";
            dataGridView1.Columns[1].Name = "Class Title";
            dataGridView1.Columns[2].Name = "Class Track";

            Teacher teacher = TeacherDB.TempLoad();

            lblTeacherID.Text = teacher.TeacherID.ToString();
            txtFirstName.Text = teacher.FirstName;
            txtLastName.Text  = teacher.LastName;

            Teacher        newTeacher = TeacherDB.TeacherFind(teacher.TeacherID);
            List <Classes> ClassList  = new List <Classes>();

            foreach (int classID in newTeacher.ClassID)
            {
                Classes  newClass = ClassesDB.ClassFind(classID);
                string[] row      = new string[] { newClass.ClassID.ToString(), newClass.ClassTitle, newClass.ClassTrack };
                dataGridView1.Rows.Add(row);
            }
        }
Beispiel #3
0
        private void btnSave_Click(object sender, EventArgs e) //Needs validation
        {
            if (true)                                          //Validate everything
            {
                List <int>     ClassList     = new List <int>();
                List <Classes> ClassListSave = new List <Classes>();

                //Retrieves class data and populates list
                foreach (object classData in checkedListBox1.CheckedItems)
                {
                    string[] classInfo = classData.ToString().Split(' ');

                    Classes newClass = ClassesDB.ClassFind(Convert.ToInt32(classInfo[0]));
                    ClassListSave.Add(newClass);
                    ClassList.Add(newClass.ClassID);
                }

                //Find teacher and add data into teacher
                string[] teacherID = comboBox1.Text.Split(' ');

                Teacher newTeacher = TeacherDB.TeacherFind(Convert.ToInt32(teacherID[0]));
                newTeacher.ClassID = ClassList;

                foreach (Classes classes in ClassListSave)
                {
                    classes.TeacherID.Add(newTeacher.TeacherID);

                    ClassesDB.ClassDelete(classes);
                    ClassesDB.ClassSave(classes);
                }

                TeacherDB.TeacherDelete(newTeacher);
                TeacherDB.TeacherSave(newTeacher);
            }
            else
            {
                MessageBox.Show("Please select the correct number of classes or select a different teacher");
            }

            this.Close();
        }