private void bntUpdate_Click(object sender, EventArgs e)
        {
            StudentController studentController = new StudentController();

            if (txtName.Text == "" || dateTimeBirthday.Value == null || txtAddress.Text == "" || txtPhone.Text == "" || cmbYear.Text == "")
            {
                ;
            }
            else
            {
                STUDENTINFORMATION sTUDENTINFORMATION = new STUDENTINFORMATION();
                sTUDENTINFORMATION.MSHOCSINH = _MSHS;
                sTUDENTINFORMATION.NAME      = txtName.Text;
                if (radioNam.Checked = true)
                {
                    sTUDENTINFORMATION.SEX = "Nam";
                }
                else
                {
                    sTUDENTINFORMATION.SEX = "Nữ";
                }
                sTUDENTINFORMATION.PHONE    = txtPhone.Text;
                sTUDENTINFORMATION.ADDRESS  = txtAddress.Text;
                sTUDENTINFORMATION.BIRTHDAY = dateTimeBirthday.Value;
                if (studentController.UpdateStudent(sTUDENTINFORMATION))
                {
                    MessageBox.Show("Update thành công", "Thông báo");
                }
                else
                {
                    MessageBox.Show("Update thất bại", "Thông báo");
                }
            }
        }
 private void bntDelete_Click(object sender, EventArgs e)
 {
     if (this.GridStudent.SelectedRows.Count > 0)
     {
         int row = GridStudent.SelectedRows[0].Index;
         STUDENTINFORMATION studentInformation = new STUDENTINFORMATION();
         studentInformation.MSHOCSINH = GridStudent[0, row].Value.ToString();
         studentInformation.NAME      = GridStudent[1, row].Value.ToString();
         studentInformation.BIRTHDAY  = (DateTime)GridStudent[2, row].Value;
         studentInformation.ADDRESS   = GridStudent[3, row].Value.ToString();
         if (GridStudent[4, row].Value.ToString() == "1")
         {
             studentInformation.SEX = "Nam";
         }
         else
         {
             studentInformation.SEX = "Nữ";
         }
         studentInformation.PHONE = GridStudent[5, row].Value.ToString();
         StudentController studentController = new StudentController();
         bool flag = studentController.RemoveStudent(studentInformation.MSHOCSINH, cmbYear.SelectedValue.ToString(), cmbClass.SelectedValue.ToString());
         if (flag)
         {
             MessageBox.Show("Xóa thành công", "Thông báo");
         }
         else
         {
             MessageBox.Show("Nhập thất bại, vui lòng thử lại sau", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
Beispiel #3
0
        public bool UpdateStudent(STUDENTINFORMATION studentInformation)
        {
            var findStudent = _QuanLyHocSinhEntities.STUDENT.Where(s => s.MSHOCSINH == studentInformation.MSHOCSINH).Take(1).ToList();

            if (findStudent.Count > 0)
            {
                findStudent[0].NAME = studentInformation.NAME;
                if (studentInformation.SEX == "Nam")
                {
                    findStudent[0].SEX = 1;
                }
                else
                {
                    findStudent[0].SEX = 0;
                }
                findStudent[0].PHONE    = studentInformation.PHONE;
                findStudent[0].BIRTHDAY = studentInformation.BIRTHDAY;
                findStudent[0].ADDRESS  = studentInformation.ADDRESS;
                _QuanLyHocSinhEntities.SaveChanges();
                return(true);
            }
            return(false);
        }