private void btn_hoanthanh_Click(object sender, EventArgs e) { QLHS_BUS bus = new QLHS_BUS(); int nam = int.Parse(DateTime.Now.Year.ToString()); int dtp = int.Parse(dt_ngaysinh.Value.Year.ToString()); int t = nam - dtp; DataTable dt = bus.ThamSo(); //MessageBox.Show(dt.Rows[0]["TuoiToiThieu"].ToString()); //MessageBox.Show(dt.Rows[0]["TuoiToiDa"].ToString()); try { if (Int32.Parse(dt.Rows[0]["TuoiToiThieu"].ToString()) < t && t < Int32.Parse(dt.Rows[0]["TuoiToiDa"].ToString())) { if ((txt_hovaten.Text != "") && (dt_ngaysinh.Value.ToString() != "") && (cb_gioitinh.Text != "") && (txt_diachi.Text != "") && (txt_email.Text != "")) { QLHS_DTO hs = new QLHS_DTO(); hs.MaHocSinh = txt_mahocsinh.Text; hs.HoTen = txt_hovaten.Text; hs.NgaySinh = dt_ngaysinh.Value.ToString(); hs.GioiTinh = cb_gioitinh.Text; hs.DiaChi = txt_diachi.Text; hs.Email = txt_email.Text; bus.ThemHocSinh(hs); MessageBox.Show("Thêm thành công học sinh " + txt_hovaten.Text + " !", "Thông báo"); LoadData(); bus.ThemCTDSLOP(hs); btn_hoanthanh.Visible = false; btn_ThemHS.Visible = true; btn_capnhathocsinh.Visible = true; txt_mahocsinh.Enabled = false; txt_hovaten.Enabled = false; txt_email.Enabled = false; txt_diachi.Enabled = false; cb_gioitinh.Enabled = false; dt_ngaysinh.Enabled = false; txt_hovaten.DataBindings.Clear(); txt_hovaten.DataBindings.Add("Text", dtgv_danhsachhocsinh.DataSource, "HoTen"); txt_mahocsinh.DataBindings.Clear(); txt_mahocsinh.DataBindings.Add("Text", dtgv_danhsachhocsinh.DataSource, "MaHocSinh"); txt_email.DataBindings.Clear(); txt_email.DataBindings.Add("Text", dtgv_danhsachhocsinh.DataSource, "Email"); txt_diachi.DataBindings.Clear(); txt_diachi.DataBindings.Add("Text", dtgv_danhsachhocsinh.DataSource, "DiaChi"); cb_gioitinh.DataBindings.Clear(); cb_gioitinh.DataBindings.Add("Text", dtgv_danhsachhocsinh.DataSource, "GioiTinh"); dt_ngaysinh.DataBindings.Clear(); dt_ngaysinh.DataBindings.Add("Text", dtgv_danhsachhocsinh.DataSource, "NgaySinh"); } else { MessageBox.Show("Bạn chưa nhập đủ thông tin! Mời nhập lại!", "Cảnh báo"); } } else { MessageBox.Show("Tuổi của học sinh chưa đúng quy định! Không thêm thành công", "Cảnh báo"); } } catch (Exception ex) { MessageBox.Show("Mời nhập lại theo đúng quy định!"); } }