private void HienThiDSHocSinh() { dgvHocSinh.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; HocSinhDAL hsDAL = new HocSinhDAL(); dgvHocSinh.DataSource = hsDAL.LoadDS(); }
private void btXoa_Click(object sender, EventArgs e) { HocSinhDAL hsDAL = new HocSinhDAL(); if (tbMaHs.TextLength == 0) { MessageBox.Show("Chua co ma hoc sinh", " loi "); } else { try { int id = Convert.ToInt16(tbMaHs.Text); hsDAL.deleteHocSinh(id); dgvHocSinh.DataSource = hsDAL.LoadDS(); } catch { MessageBox.Show("ma hoc sinh khong thoa man", " loi "); } } }
private void btThem_Click(object sender, EventArgs e) { HocSinh hs = new HocSinh(); HocSinhDAL hsDAL = new HocSinhDAL(); if (tbMaHs.TextLength != 0) { MessageBox.Show("Khong can nhap ma hoc sinh", " loi "); } else { if (tbHoTen.TextLength == 0) { MessageBox.Show("Chua nhap ho ten hoc sinh", " loi "); } else { hs.HoTen = tbHoTen.Text; if (rbNam.Checked == false && rbNu.Checked == false) { MessageBox.Show("Chua chon gioi tinh", " loi "); } else { if (rbNam.Checked == true) { hs.GioiTinh = "Nam"; } else if (rbNu.Checked == true) { hs.GioiTinh = "Nữ"; } if (tbNgaySinh.Text == "dd-mm-yyyy" || tbNgaySinh.TextLength == 0) { MessageBox.Show("Chua nhap ngay sinh", " loi "); } else { hs.NgaySinh = Convert.ToDateTime(tbNgaySinh.Text); if (tbNoiSinh.TextLength == 0) { MessageBox.Show("Chua nhap noi sinh ", " loi "); } else { hs.NoiSinh = tbNoiSinh.Text; if (tbDanToc.TextLength == 0) { MessageBox.Show("Chua nhap dan toc", " loi "); } else { hs.DanToc = tbDanToc.Text; if (tbTonGiao.TextLength == 0) { MessageBox.Show("Chua nhap ton giao", " loi "); } else { hs.TonGiao = tbTonGiao.Text; hsDAL.insertHocSinh(hs); dgvHocSinh.DataSource = hsDAL.LoadDS(); } } } } } } } }
private void btSua_Click(object sender, EventArgs e) { HocSinh hs = new HocSinh(); hs.MaHocSinh = Convert.ToInt32(tbMaHs.Text); HocSinhDAL hsDAL = new HocSinhDAL(); if (tbMaHs.Text != hs.MaHocSinh.ToString()) { MessageBox.Show("Khong duoc sua ma hoc sinh", " Lỗi "); } else { if (tbHoTen.TextLength == 0) { MessageBox.Show("Chua nhap ho ten hoc sinh", " Lỗi "); } else { hs.HoTen = tbHoTen.Text; if (rbNam.Checked == false && rbNu.Checked == false) { MessageBox.Show("Chua chon gioi tinh", " Lỗi "); } else { if (rbNam.Checked == true) { hs.GioiTinh = "Nam"; } else if (rbNu.Checked == true) { hs.GioiTinh = "Nữ"; } hs.NgaySinh = Convert.ToDateTime(dtpNgaySinh.Value); if (tbNoiSinh.TextLength == 0) { MessageBox.Show("Chua nhap noi sinh ", " Lỗi "); } else { hs.NoiSinh = tbNoiSinh.Text; if (tbDanToc.TextLength == 0) { MessageBox.Show("Chua nhap dan toc", " Lỗi "); } else { hs.DanToc = tbDanToc.Text; if (tbTonGiao.TextLength == 0) { MessageBox.Show("Chua nhap ton giao", " Lỗi "); } else { hs.TonGiao = tbTonGiao.Text; hsDAL.SuaHocSinh(hs); dgvHocSinh.DataSource = hsDAL.LoadDS(); } } } } } } }