private void btThem_Click_1(object sender, EventArgs e) { bool gt; if (cbGioiTinh.SelectedIndex == 0) { MessageBox.Show("Giới tính không hợp lệ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else { gt = cbGioiTinh.SelectedIndex == 1 ? true : false; } int Lop; if (cbLop.SelectedIndex == 0) { MessageBox.Show("Trình độ không hợp lệ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else { Lop = cbLop.SelectedIndex + 1; } if (dtNgaySinh.Value > DateTime.Now) { MessageBox.Show("Ngày sinh không hợp lệ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } try { EC_HocSinh HocSinh = new EC_HocSinh(txbMa_HocSinh.Text, txbTen_HocSinh.Text, dtNgaySinh.Value, gt, txbDiaChi.Text, txbSDT.Text, txbEmail.Text, Lop, "", null); BUS_HocSinh busHS = new BUS_HocSinh(); busHS.ThemDuLieu(HocSinh); MessageBox.Show("Thêm học sinh thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch { MessageBox.Show("Thêm học sinh thất bại!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btThem_Click_1(object sender, EventArgs e) { bool gt = cbGioiTinh.SelectedIndex == 0 ? true : false; int Lop; if (cbLop.SelectedIndex == 0) { MessageBox.Show("Trình độ không hợp lệ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else { Lop = cbLop.SelectedIndex + 1; } if (dtNgaySinh.Value > DateTime.Now) { MessageBox.Show("Ngày sinh không hợp lệ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (pictureBox1.Image == null) { MessageBox.Show("Bạn hãy thêm ảnh bằng cách nhấn đúp vào khung hình ảnh nhé!", "Thông báo"); return; } try { EC_HocSinh HocSinh = new EC_HocSinh(TaoMa_HocSinh(), txbTen_HocSinh.Text, dtNgaySinh.Value, gt, txbDiaChi.Text, txbSDT.Text, txbEmail.Text, Lop, "", ArrByte_Anh); BUS_HocSinh busHS = new BUS_HocSinh(); busHS.ThemDuLieu(HocSinh); MessageBox.Show("Thêm học sinh thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); List <EC_HocSinh> listHocSinh = new BUS_HocSinh().SelectAll(); LoadForm(listHocSinh); } catch { MessageBox.Show("Thêm học sinh thất bại!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } }