Ejemplo n.º 1
0
        private void btnAddUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                StudentContextDB context = new StudentContextDB();
                Student          db      = context.Students.FirstOrDefault(p => p.StudentID == txtStudentID.Text);
                if (db == null)  //TH insert
                {
                    Student s = GetStudent();
                    context.Students.Add(s);
                    context.SaveChanges();
                    MessageBox.Show("Thêm Mới Dữ Liệu thành công!");
                }
                else //TH Uupdate
                {
                    db = GetStudent();
                    context.SaveChanges();
                    MessageBox.Show("Cập nhật thành công!");
                }

                BindGrid(context.Students.ToList());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 2
0
 private void btnAddUpdateF_Click(object sender, EventArgs e)
 {
     try
     {
         StudentContextDB context = new StudentContextDB();
         Faculty          db      = context.Faculties.FirstOrDefault(p => p.FacultyID.ToString() == txtMaKhoa.Text);
         if (db == null)
         {
             Faculty f = GetFaculty();
             context.Faculties.Add(f);
             context.SaveChanges();
             MessageBox.Show("Thêm Mới Dữ Liệu thành công!");
         }
         else
         {
             db = GetFaculty();
             context.SaveChanges();
             MessageBox.Show("Cập nhật thành công!");
         }
         BindGrid(context.Faculties.ToList());
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 3
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     try
     {
         StudentContextDB context = new StudentContextDB();
         Student          db      = context.Students.FirstOrDefault(p => p.StudentID == txtStudentID.Text);
         if (db == null)
         {
             throw new Exception("Không tìm thấy mã sinh viên để xóa!");
         }
         else
         {
             DialogResult dlg = MessageBox.Show("Bạn có muốn xóa không?", "Cảnh Báo", MessageBoxButtons.YesNo);
             if (dlg == DialogResult.Yes)
             {
                 context.Students.Remove(db);
                 context.SaveChanges();
                 MessageBox.Show("Xóa dữ liệu thành công!");
             }
         }
         BindGrid(context.Students.ToList());
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 4
0
 private void frmFacultyManagement_Load(object sender, EventArgs e)
 {
     try
     {
         SetGridViewStyle(dgvFaculty);
         StudentContextDB context       = new StudentContextDB();
         List <Faculty>   listFaculties = context.Faculties.ToList();
         BindGrid(listFaculties);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 5
0
 private void frmStudentManagement_Load(object sender, EventArgs e)
 {
     try
     {
         SetGridViewStyle(dgvStudent);
         StudentContextDB context        = new StudentContextDB();
         List <Faculty>   listFalculties = context.Faculties.ToList();
         List <Student>   listStudent    = context.Students.ToList();
         FillFalcultyCombobox(listFalculties);
         BindGrid(listStudent);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }