private void Window_Loaded_Student(object sender, RoutedEventArgs e)
        {
            if (Global.Teacher.Type == "PDT")
            {
                chooseYear.ItemsSource   = AcademicAffairsOfficeBUS.loadListSchoolYearToComboBox();
                chooseYear.SelectedIndex = 0;

                chooseClass.ItemsSource   = AcademicAffairsOfficeBUS.loadListClassToComboBox(chooseYear.SelectedValue.ToString());
                chooseClass.SelectedIndex = 0;

                Global.listStudent          = AcademicAffairsOfficeBUS.loadListStudent(chooseClass.SelectedValue.ToString(), chooseYear.SelectedValue.ToString());
                listviewStudent.ItemsSource = Global.listStudent;
            }
            else
            {
                chooseYear.ItemsSource        = TeacherBUS.loadSchoolYearToComboBox(Global.Teacher.Id);
                chooseYear.SelectedIndex      = 0;
                chooseClass.ItemsSource       = TeacherBUS.loadListClassToComboBox(Global.Teacher.Id, chooseYear.SelectedValue.ToString());
                chooseClass.SelectedIndex     = 0;
                Global.listStudent            = AcademicAffairsOfficeBUS.loadListStudent(chooseClass.SelectedValue.ToString(), chooseYear.SelectedValue.ToString());
                listviewStudent.ItemsSource   = Global.listStudent;
                listviewStudent.SelectedIndex = 0;
            }
            //  Global.listStudent = AcademicAffairsOfficeBUS.loadListStudent(chooseClass.SelectedItem.ToString(), chooseYear.SelectedItem.ToString());

            //   listviewStudent.ItemsSource = Global.listStudent;
        }
예제 #2
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            var rowSelected = this.dgvListTeachers.SelectedRows[0];
            var entity      = new TeacherBUS().GetByID((int)rowSelected.Cells[4].Value);

            new FrmTeacher(entity).Show();
        }
예제 #3
0
        private void Window_Loaded_User(object sender, RoutedEventArgs e)
        {
            //listviewUser.ItemsSource = marks;
            if (Global.Teacher.Type == "PDT")
            {
                listSubject.Add("All");
                List <string> temp = SubjectBUS.loadListNameSubject();
                int           n    = temp.Count;
                for (int i = 0; i < n; i++)
                {
                    listSubject.Add(temp[i]);
                }
                chooseSubject.ItemsSource   = listSubject;
                chooseSubject.SelectedIndex = 1;

                chooseClass.ItemsSource   = AcademicAffairsOfficeBUS.loadListClassToComboBox();
                chooseClass.SelectedIndex = 0;

                if (chooseSemester.SelectedValue.ToString() == "System.Windows.Controls.ComboBoxItem: I")
                {
                    semester = "1";
                }
                else
                {
                    semester = "2";
                }

                if (chooseSubject.SelectedValue.ToString() != "All")
                {
                    listviewUser.ItemsSource = MarkBUS.loadMarkByNameSubject(chooseSubject.SelectedValue.ToString(), chooseClass.SelectedValue.ToString(), Global.schoolYear, semester);
                }
                else
                {
                    listviewUser.ItemsSource = MarkBUS.loadMarkByClass(chooseClass.SelectedValue.ToString(), Global.schoolYear, semester);
                }
            }
            else
            {
                chooseClass.ItemsSource   = TeacherBUS.loadListClassToComboBox(Global.Teacher.Id, Global.schoolYear);
                chooseClass.SelectedIndex = 0;

                chooseSubject.ItemsSource   = TeacherBUS.loadListSubjectToComboBoxInUpdate(Global.Teacher.Id, chooseClass.SelectedValue.ToString(), Global.schoolYear);
                chooseSubject.SelectedIndex = 0;

                if (chooseSemester.SelectedValue.ToString() == "System.Windows.Controls.ComboBoxItem: I")
                {
                    semester = "1";
                }
                else
                {
                    semester = "2";
                }

                listviewUser.ItemsSource = MarkBUS.loadMarkByNameSubject(chooseSubject.SelectedValue.ToString(), chooseClass.SelectedValue.ToString(), Global.schoolYear, semester);
            }
            btnEdit.IsEnabled = false;
        }
예제 #4
0
        private void BinCmbTeacher(String t, String w, String o)
        {
            List <Teacher> lst = new TeacherBUS().Teacher_GetByTop(t, w, o);

            lst.Insert(0, new Teacher("0", "--Select an option--", "", "", ""));

            cmbTeacher.DataSource    = lst;
            cmbTeacher.DisplayMember = "name";
            cmbTeacher.ValueMember   = "id";
            cmbTeacher.SelectedIndex = 0;
        }
        private bool LoginValid(String u, String p)
        {
            TeacherBUS obj = new TeacherBUS();

            if (obj.Teacher_LoginValid(u, p))
            {
                Common.UserName = txtUserName.Text;
                MessageBox.Show("Login successful!");
                return(true);
            }
            else
            {
                MessageBox.Show("Login unsuccessful!");
                Clear();
                return(false);
            }
        }
 private void ChooseYear_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (chooseClass.SelectedValue != null && chooseYear.SelectedValue != null)
     {
         if (Global.Teacher.Type == "PDT")
         {
             chooseClass.ItemsSource   = AcademicAffairsOfficeBUS.loadListClassToComboBox(chooseYear.SelectedValue.ToString());
             chooseClass.SelectedIndex = 0;
         }
         else
         {
             chooseClass.ItemsSource   = TeacherBUS.loadListClassToComboBox(Global.Teacher.Id, chooseYear.SelectedValue.ToString());
             chooseClass.SelectedIndex = 0;
         }
         Global.listStudent          = AcademicAffairsOfficeBUS.loadListStudent(chooseClass.SelectedItem.ToString(), chooseYear.SelectedItem.ToString());
         listviewStudent.ItemsSource = Global.listStudent;
     }
 }
예제 #7
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     try
     {
         if (MessageBox.Show("Realmente deseja apagar este item", "Apagar Professor", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             var rowSelected = this.dgvListTeachers.SelectedRows[0];
             var entity = new TeacherBUS().GetByID((int)rowSelected.Cells[4].Value);
             new TeacherBUS().Delete(entity);
             SearchTeachers();
             MessageBox.Show("Item apagado com sucesso", "Apagar Professor", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Ocorreu um erro ao tentar apagar o item.", "Apagar Professor", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
예제 #8
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     try
     {
         if (MessageBox.Show("Realmente deseja apagar este item", "Apagar Professor", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             var rowSelected = this.dgvListTeachers.SelectedRows[0];
             var entity      = new TeacherBUS().GetByID((int)rowSelected.Cells[4].Value);
             new TeacherBUS().Delete(entity);
             SearchTeachers();
             MessageBox.Show("Item apagado com sucesso", "Apagar Professor", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Ocorreu um erro ao tentar apagar o item.", "Apagar Professor", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        private void btnDoneofEdit_click(object sender, RoutedEventArgs e)
        {
            gender_tc_infor.IsEnabled      = false;
            phone_tc_infor.IsReadOnly      = true;
            email_tc_infor.IsReadOnly      = true;
            birthofday_tc_infor.IsReadOnly = true;
            gender_tc_infor.IsReadOnly     = true;
            position_tc_infor.IsEnabled    = false;
            btnDoneOfEdit.Visibility       = Visibility.Collapsed;
            btnEdit.Visibility             = Visibility.Visible;
            btnEdit.IsEnabled    = false;
            btnCancel.Visibility = Visibility.Collapsed;
            string idTeacher = id_tc_infor.Text;
            string Name      = fullname_tc_infor.Text;
            string Gender    = gender_tc_infor.Text;
            string Email     = email_tc_infor.Text;
            string Phone     = phone_tc_infor.Text;
            string BirthDay  = birthofday_tc_infor.Text;

            if (TeacherBUS.changeMyInfomation(idTeacher, Name, Gender, Email, Phone, BirthDay))
            {
                Global.Teacher.Name       = Name;
                Global.Teacher.Gender     = Gender;
                Global.Teacher.Email      = Email;
                Global.Teacher.Phone      = Phone;
                Global.Teacher.Id         = idTeacher;
                Global.Teacher.DateofBith = BirthDay;

                fullname_tc_infor.Text   = Global.Teacher.Name;
                id_tc_infor.Text         = idTeacher;
                birthofday_tc_infor.Text = Global.Teacher.DateofBith;
                phone_tc_infor.Text      = Global.Teacher.Phone;
                email_tc_infor.Text      = Global.Teacher.Email;


                if (Global.Teacher.Gender == "Male")
                {
                    gender_tc_infor.SelectedIndex = 1;
                }
                else if (Global.Teacher.Gender == "Female")
                {
                    gender_tc_infor.SelectedIndex = 2;
                }
                else
                {
                    gender_tc_infor.SelectedIndex = 0;
                }

                if (choosePosition.SelectedValue.ToString() == "System.Windows.Controls.ComboBoxItem: Academic Affair Office Staff")
                {
                    listviewUser.ItemsSource = AcademicAffairsOfficeBUS.loadListAAOS();
                }
                else if (choosePosition.SelectedValue.ToString() == "System.Windows.Controls.ComboBoxItem: Subject Teacher")
                {
                    listviewUser.ItemsSource = AcademicAffairsOfficeBUS.loadListSubjectTeacher(Global.schoolYear);
                }
                else if (choosePosition.SelectedValue.ToString() == "System.Windows.Controls.ComboBoxItem: Homeroom Teacher")
                {
                    listviewUser.ItemsSource = AcademicAffairsOfficeBUS.loadListHomeRoomTeacher(Global.schoolYear);
                }
                else
                {
                    listviewUser.ItemsSource = AcademicAffairsOfficeBUS.loadListTeacher();
                }
            }
            else
            {
                fullname_tc_infor.Text   = Global.Teacher.Name;
                id_tc_infor.Text         = Global.Teacher.Id;
                birthofday_tc_infor.Text = Global.Teacher.DateofBith;
                phone_tc_infor.Text      = Global.Teacher.Phone;
                email_tc_infor.Text      = Global.Teacher.Email;
                if (Global.Teacher.Gender == "Male")
                {
                    gender_tc_infor.SelectedIndex = 1;
                }
                else if (Global.Teacher.Gender == "Female")
                {
                    gender_tc_infor.SelectedIndex = 2;
                }
                else
                {
                    gender_tc_infor.SelectedIndex = 0;
                }

                MessageBox.Show("Update information failed");
            }
        }
예제 #10
0
        private void btnDoneofEdit_click(object sender, RoutedEventArgs e)
        {
            gender_tc_infor.IsEnabled      = false;
            phone_tc_infor.IsReadOnly      = true;
            email_tc_infor.IsReadOnly      = true;
            birthofday_tc_infor.IsReadOnly = true;
            gender_tc_infor.IsReadOnly     = true;
            btnDoneOfEdit.Visibility       = Visibility.Collapsed;
            btnEdit.Visibility             = Visibility.Visible;
            btnCancel.Visibility           = Visibility.Collapsed;
            string idTeacher = id_tc_infor.Text;
            string Name      = fullname_tc_infor.Text;
            string Gender    = gender_tc_infor.Text;
            string Email     = email_tc_infor.Text;
            string Phone     = phone_tc_infor.Text;
            string BirthDay  = birthofday_tc_infor.Text;

            if (TeacherBUS.changeMyInfomation(idTeacher, Name, Gender, Email, Phone, BirthDay))
            {
                Global.Teacher.Name   = Name;
                Global.Teacher.Gender = Gender;
                Global.Teacher.Email  = Email;
                Global.Teacher.Phone  = Phone;

                Global.Teacher.DateofBith = BirthDay;

                fullname_tc_infor.Text   = Global.Teacher.Name;
                id_tc_infor.Text         = Global.Teacher.Id;
                birthofday_tc_infor.Text = Global.Teacher.DateofBith;
                phone_tc_infor.Text      = Global.Teacher.Phone;
                email_tc_infor.Text      = Global.Teacher.Email;


                if (Global.Teacher.Gender == "Male")
                {
                    gender_tc_infor.SelectedIndex = 1;
                }
                else if (Global.Teacher.Gender == "Female")
                {
                    gender_tc_infor.SelectedIndex = 2;
                }
                else
                {
                    gender_tc_infor.SelectedIndex = 0;
                }

                // Teacher = Global.Teacher;
            }
            else
            {
                fullname_tc_infor.Text   = Global.Teacher.Name;
                id_tc_infor.Text         = Global.Teacher.Id;
                birthofday_tc_infor.Text = Global.Teacher.DateofBith;
                phone_tc_infor.Text      = Global.Teacher.Phone;
                email_tc_infor.Text      = Global.Teacher.Email;
                if (Global.Teacher.Gender == "Male")
                {
                    gender_tc_infor.SelectedIndex = 1;
                }
                else if (Global.Teacher.Gender == "Female")
                {
                    gender_tc_infor.SelectedIndex = 2;
                }
                else
                {
                    gender_tc_infor.SelectedIndex = 0;
                }

                MessageBox.Show("Update your information failed");
            }
        }
예제 #11
0
 private void btnEdit_Click(object sender, EventArgs e)
 {
     var rowSelected = this.dgvListTeachers.SelectedRows[0];
     var entity = new TeacherBUS().GetByID((int)rowSelected.Cells[4].Value);
     new FrmTeacher(entity).Show();
 }
예제 #12
0
        private void AddTeacher()
        {
            try
            {
                TeacherEntity entity = new TeacherBUS().GetByID(Convert.ToInt32(lblIdTeacher.Text));

                if (entity == null)
                {
                    entity = new TeacherEntity();
                }

                entity.Mobile = txtMobile.Text.Trim();
                entity.Name   = txtName.Text.Trim();
                entity.Phone  = txtPhone.Text.Trim();
                entity.Sex    = cbSex.SelectedIndex < 0 ? "" : cbSex.SelectedIndex == 0 ? "M" : "F";

                var validate          = new TeacherBUS().ValideteForm(entity);
                var validateFormLogin = ValidateFormLogin();

                if (string.IsNullOrEmpty(validate) && string.IsNullOrEmpty(validateFormLogin))
                {
                    if (entity.Id > 0)
                    {
                        new TeacherBUS().Update(entity);
                        if (chbUser.Checked)
                        {
                            var entityUser = new UserBUS().GetByIdTeacher(entity.Id);
                            entityUser.AccessType = cbTypeAccess.SelectedValue.ToString();
                            entityUser.Password   = txtPassword.Text.Trim();
                            entityUser.UserName   = txtUser.Text.Trim();

                            new UserBUS().Update(entityUser);
                        }

                        MessageBox.Show("Registro atualizado com sucesso", "Cadastro de Professor", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        new TeacherBUS().Add(entity);
                        if (chbUser.Checked)
                        {
                            var entityUser = new UserEntity()
                            {
                                AccessType = cbTypeAccess.SelectedIndex == 1 ? "A" : "U",
                                CreateDate = DateTime.Now,
                                IdTeacher  = new TeacherBUS().GetAll().Last().Id,
                                Password   = txtPassword.Text.Trim(),
                                UserName   = txtUser.Text.Trim()
                            };

                            new UserBUS().Add(entityUser);
                        }

                        MessageBox.Show("Registro salvo com sucesso", "Cadastro de Professor", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }

                    ClearFields();
                }
                else
                {
                    MessageBox.Show(validate + "\n" + validateFormLogin, "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ocorreu um erro ao tentar salvar o registo.", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #13
0
        private void LogIn_Click(object sender, RoutedEventArgs e)
        {
            passLogIn = passbPassword.Password;

            /* if (userLogIn == null || userLogIn != userAdmin)
             * {
             *   lblErrorMessage_1.Content = "The username that you've entered" + "\n" + "doesn't match any account.";
             *   lblErrorMessage_1.Visibility = Visibility.Visible;
             *   uiErrorSp_1.Visibility = Visibility.Visible;
             *
             *   dispatcherTimer.Start();
             * }
             * else if (passLogIn != passAdmin)
             * {
             *   lblErrorMessage_2.Content = "The password that you've entered" + "\n" + "is incorrect.";
             *   lblErrorMessage_2.Visibility = Visibility.Visible;
             *   uiErrorSp_2.Visibility = Visibility.Visible;
             *   dispatcherTimer.Start();
             *
             * }else if (rb_tc.IsChecked==false&&rb_st.IsChecked==false&&rb_ad.IsChecked==false)
             * {
             *   lblErrorMessage_3.Content = "You must choose a authorities.";
             *   lblErrorMessage_3.Visibility = Visibility.Visible;
             *   uiErrorSp_3.Visibility = Visibility.Visible;
             *   dispatcherTimer.Start();
             * }
             * else if (userLogIn == userAdmin & passLogIn == passAdmin & rb_st.IsChecked==true)
             * {
             *   var window = new DashboardStudent();
             *   window.Show();
             *   this.Close();
             * }
             * else if (userLogIn == userAdmin & passLogIn == passAdmin & rb_tc.IsChecked == true)
             * {
             *   var window = new DashboardTeacher();
             *   window.Show();
             *   this.Close();
             * }
             * else if (userLogIn == userAdmin & passLogIn == passAdmin & rb_ad.IsChecked == true)
             * {
             *   var window = new DashboardAdmin();
             *   window.Show();
             *   this.Close();
             * }*/


            if (rb_tc.IsChecked == false && rb_st.IsChecked == false && rb_ad.IsChecked == false)
            {
                lblErrorMessage_3.Content    = "You must choose a authorities.";
                lblErrorMessage_3.Visibility = Visibility.Visible;
                uiErrorSp_3.Visibility       = Visibility.Visible;
                dispatcherTimer.Start();
            }
            else if (rb_tc.IsChecked == true)
            {
                if (TeacherBUS.Login(userLogIn, passLogIn) != null)
                {
                    var window = new DashboardTeacher();
                    window.Show();
                    this.Close();
                }
                else
                {
                    lblErrorMessage_1.Content    = "The username that you've entered" + "\n" + "doesn't match any account.";
                    lblErrorMessage_1.Visibility = Visibility.Visible;
                    uiErrorSp_1.Visibility       = Visibility.Visible;
                    dispatcherTimer.Start();
                    lblErrorMessage_2.Content    = "The password that you've entered" + "\n" + "is incorrect.";
                    lblErrorMessage_2.Visibility = Visibility.Visible;
                    uiErrorSp_2.Visibility       = Visibility.Visible;
                    dispatcherTimer.Start();
                }
            }
            else if (rb_ad.IsChecked == true)
            {
                if (AdminBUS.Login(userLogIn, passLogIn) != null)
                {
                    var window = new DashboardAdmin();
                    window.Show();
                    this.Close();
                }
                else
                {
                    lblErrorMessage_1.Content    = "The username that you've entered" + "\n" + "doesn't match any account.";
                    lblErrorMessage_1.Visibility = Visibility.Visible;
                    uiErrorSp_1.Visibility       = Visibility.Visible;
                    dispatcherTimer.Start();
                    lblErrorMessage_2.Content    = "The password that you've entered" + "\n" + "is incorrect.";
                    lblErrorMessage_2.Visibility = Visibility.Visible;
                    uiErrorSp_2.Visibility       = Visibility.Visible;
                    dispatcherTimer.Start();
                }
            }
            else if (rb_st.IsChecked == true)
            {
                if (StudentBUS.Login(userLogIn, passLogIn) != null)
                {
                    var window = new DashboardStudent();
                    window.Show();
                    this.Close();
                }
                else
                {
                    lblErrorMessage_1.Content    = "The username that you've entered" + "\n" + "doesn't match any account.";
                    lblErrorMessage_1.Visibility = Visibility.Visible;
                    uiErrorSp_1.Visibility       = Visibility.Visible;
                    dispatcherTimer.Start();
                    lblErrorMessage_2.Content    = "The password that you've entered" + "\n" + "is incorrect.";
                    lblErrorMessage_2.Visibility = Visibility.Visible;
                    uiErrorSp_2.Visibility       = Visibility.Visible;
                    dispatcherTimer.Start();
                }
            }
        }
        private void Window_Loaded_ReviewScore(object sender, RoutedEventArgs e)
        {
            isLoaded         = true;
            id_title.Content = Global.Student.Id;
            if (Global.Teacher.Type == "PDT")
            {
                listSubject.Add("All");
                List <string> temp = SubjectBUS.loadListNameSubject();
                int           n    = temp.Count;
                for (int i = 0; i < n; i++)
                {
                    listSubject.Add(temp[i]);
                }
                chooseSubject.ItemsSource   = listSubject;
                chooseSubject.SelectedIndex = 0;

                chooseYear.ItemsSource   = AcademicAffairsOfficeBUS.getNameClassWithIDStudent(Global.Student.Id);
                chooseYear.SelectedIndex = 0;
                if (chooseSemester.SelectedValue.ToString() == "System.Windows.Controls.ComboBoxItem: I")
                {
                    semester = "1";
                }
                else
                {
                    semester = "2";
                }


                // MessageBox.Show(chooseSemester.SelectedValue.ToString());
                //MessageBox.Show(chooseSubject.SelectedValue.ToString());
                if (chooseSubject.SelectedValue.ToString() == "All")
                {
                    test.ItemsSource = MarkBUS.loadMark(Global.Student.Id, chooseYear.SelectedValue.ToString(), semester);
                }
                else
                {
                    // test.ItemsSource = MarkBUS.loadMark(Global.Student.Id, Global.Student.NameClass, Global.Student.SchoolYear, semester);
                    test.ItemsSource = MarkBUS.loadMarkByNameWithoutSchoolYear(Global.Student.Id, chooseYear.SelectedValue.ToString(), semester, chooseSubject.SelectedValue.ToString());
                }
            }
            else
            {
                listSubject = TeacherBUS.loadListSubjectToComboBoxInUpdate(Global.Teacher.Id, Global.Student.NameClass, Global.Student.SchoolYear);
                chooseSubject.ItemsSource   = listSubject;
                chooseSubject.SelectedIndex = 0;

                chooseYear.ItemsSource   = AcademicAffairsOfficeBUS.getNameClassWithIDStudent(Global.Student.Id);
                chooseYear.SelectedIndex = 0;


                if (chooseSemester.SelectedValue.ToString() == "System.Windows.Controls.ComboBoxItem: I")
                {
                    semester = "1";
                }
                else
                {
                    semester = "2";
                }


                // MessageBox.Show(chooseSemester.SelectedValue.ToString());
                //MessageBox.Show(chooseSubject.SelectedValue.ToString());
                if (chooseSubject.SelectedValue.ToString() == "All")
                {
                    test.ItemsSource = MarkBUS.loadMark(Global.Student.Id, chooseYear.SelectedValue.ToString(), semester);
                }
                else
                {
                    // test.ItemsSource = MarkBUS.loadMark(Global.Student.Id, Global.Student.NameClass, Global.Student.SchoolYear, semester);
                    test.ItemsSource = MarkBUS.loadMarkByNameWithoutSchoolYear(Global.Student.Id, chooseYear.SelectedValue.ToString(), semester, chooseSubject.SelectedValue.ToString());
                }
            }
        }
예제 #15
0
        private void AddTeacher()
        {
            try
            {
                TeacherEntity entity = new TeacherBUS().GetByID(Convert.ToInt32(lblIdTeacher.Text));

                if (entity == null)
                    entity = new TeacherEntity();

                entity.Mobile = txtMobile.Text.Trim();
                entity.Name = txtName.Text.Trim();
                entity.Phone = txtPhone.Text.Trim();
                entity.Sex = cbSex.SelectedIndex < 0 ? "" : cbSex.SelectedIndex == 0 ? "M" : "F";

                var validate = new TeacherBUS().ValideteForm(entity);
                var validateFormLogin = ValidateFormLogin();

                if (string.IsNullOrEmpty(validate) && string.IsNullOrEmpty(validateFormLogin))
                {
                    if (entity.Id > 0)
                    {
                        new TeacherBUS().Update(entity);
                        if(chbUser.Checked)
                        {
                            var entityUser = new UserBUS().GetByIdTeacher(entity.Id);
                            entityUser.AccessType = cbTypeAccess.SelectedValue.ToString();
                            entityUser.Password = txtPassword.Text.Trim();
                            entityUser.UserName = txtUser.Text.Trim();

                            new UserBUS().Update(entityUser);
                        }

                        MessageBox.Show("Registro atualizado com sucesso", "Cadastro de Professor", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        new TeacherBUS().Add(entity);
                        if (chbUser.Checked)
                        {
                            var entityUser = new UserEntity() {
                                AccessType = cbTypeAccess.SelectedIndex == 1 ? "A" : "U",
                                CreateDate = DateTime.Now,
                                IdTeacher = new TeacherBUS().GetAll().Last().Id,
                                Password = txtPassword.Text.Trim(),
                                UserName = txtUser.Text.Trim()
                            };

                            new UserBUS().Add(entityUser);
                        }

                        MessageBox.Show("Registro salvo com sucesso", "Cadastro de Professor", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }

                    ClearFields();
                }
                else
                {
                    MessageBox.Show(validate + "\n" + validateFormLogin, "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ocorreu um erro ao tentar salvar o registo.", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }