Example #1
0
        private void btnApprove_Click(object sender, EventArgs e)
        {
            studentinfor.ID         = txtStudentID.Text;
            studentinfor.Avatar     = picboxStudent.Image;
            studentinfor.FirstName  = txtFirstName.Text;
            studentinfor.SurName    = txtSurname.Text;
            studentinfor.Address    = txtAddress.Text;
            studentinfor.Phone      = txtPhoneNunber.Text;
            studentinfor.Punishment = txtPunishment.Text == "" ? null : txtPunishment.Text;
            studentinfor.Sex        = cbbSex.Text == "Nam" ? true : false;
            studentinfor.Status     = cbbStatus.Text == "Đang học" ? true : false;
            studentinfor.ClassID    = cbbClass.Text == "" ? null : cbbClass.Text;
            studentinfor.DateBorn   = dateBorn.Value;
            if (!Helper.IsDigitsOnly(studentinfor.ID) || studentinfor.ID.Length != 8 || studentinfor.ClassID == null)
            {
                MessageBox.Show("Mã số học sinh, hoặc mã lớp không hợp lệ.");
                return;
            }
            if (IsNew == true)
            {
                if (studentController.AddNewStudentToDataBase(studentinfor))
                {
                    Is_Progress_Successed = true;
                    MetroMessageBox.Show(this, "Thêm thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    //Tải lại list Student
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Thêm thất bại");
                }
                return;
            }//Không phải thêm mới - > Update
            else
            {
                if (studentController.UpdateStudentToDataBase(studentinfor.ID, studentinfor))
                {
                    Is_Progress_Successed = true;
                    MessageBox.Show("Cập nhật thành công");

                    this.Close();
                    return;
                }
                else
                {
                    MessageBox.Show("Cập nhật thất bại, vui lòng kiểm tra thông tin và thử lại");
                    return;
                }
            }
        }