コード例 #1
0
 private void btnThem_Click(object sender, EventArgs e)
 {
     try
     {
         HoSoHocSinhBUL hs            = new HoSoHocSinhBUL();
         string         MaHocSinh     = txtMaHS.Text;
         string         HoTen         = txtHoTen.Text;
         string         NgaySinh      = dateTimePicker1.Value.ToString();
         string         GioiTinh      = (string)cboGT.SelectedValue;
         string         DiaChi        = txtĐiaChi.Text;
         float          DiemVaoTruong = float.Parse(txtDiemVT.Text);
         string         HoTenBoMe     = txtTenBM.Text;
         string         SoDienThoai   = txtSDT.Text;
         string         MaLop         = (string)cboMaLop.SelectedValue;
         hs.Them(MaHocSinh, HoTen, NgaySinh, GioiTinh, DiaChi, DiemVaoTruong,
                 HoTenBoMe, SoDienThoai, MaLop);
         dgvHSHS.DataSource = myHSHS.LayDanhSachHoSoHocSinh();
     }
     catch (Exception)
     {
         MessageBox.Show("Thêm mới không hợp lệ!!!");
     }
 }
 private void btnLuu_Click(object sender, EventArgs e)
 {
     if (btnThem.Enabled == false)
     {
         try
         {
             HoSoHocSinhBUL hs            = new HoSoHocSinhBUL();
             string         MaHocSinh     = txtMaHS.Text;
             string         HoTen         = txtHoTen.Text;
             string         NgaySinh      = dateTimePicker1.Value.ToString();
             string         GioiTinh      = (string)cboGT.SelectedValue;
             string         DiaChi        = txtĐiaChi.Text;
             float          DiemVaoTruong = float.Parse(txtDiemVT.Text);
             string         HoTenBoMe     = txtTenBM.Text;
             string         SoDienThoai   = txtSDT.Text;
             string         MaLop         = (string)cboMaLop.SelectedValue;
             hs.Them(MaHocSinh, HoTen, NgaySinh, GioiTinh, DiaChi, DiemVaoTruong,
                     HoTenBoMe, SoDienThoai, MaLop);
             dgvHSHS.DataSource = myHSHS.LayDanhSachHoSoHocSinh();
             btnThem.Enabled    = true;
         }
         catch (Exception)
         {
             MessageBox.Show("Thêm mới không hợp lệ!!!");
         }
     }
     if (btnSua.Enabled == false)
     {
         try
         {
             HoSoHocSinhBUL hs            = new HoSoHocSinhBUL();
             string         MaHocSinh     = txtMaHS.Text;
             string         HoTen         = txtHoTen.Text;
             string         NgaySinh      = dateTimePicker1.Value.ToString();
             string         GioiTinh      = (string)cboGT.SelectedValue;
             string         DiaChi        = txtĐiaChi.Text;
             float          DiemVaoTruong = float.Parse(txtDiemVT.Text);
             string         HoTenBoMe     = txtTenBM.Text;
             string         SoDienThoai   = txtSDT.Text;
             string         MaLop         = (string)cboMaLop.SelectedValue;
             hs.Sua(MaHocSinh, HoTen, NgaySinh, GioiTinh, DiaChi, DiemVaoTruong,
                    HoTenBoMe, SoDienThoai, MaLop);
             dgvHSHS.DataSource = myHSHS.LayDanhSachHoSoHocSinh();
             btnSua.Enabled     = true;
         }
         catch (Exception)
         {
             MessageBox.Show("Sửa thông tin  không hợp lệ!!!");
         }
     }
     if (btnXoa.Enabled == false)
     {
         try
         {
             HoSoHocSinhBUL hs        = new HoSoHocSinhBUL();
             string         MaHocSinh = txtMaHS.Text;
             hs.Xoa(MaHocSinh);
         }
         catch (Exception)
         {
             MessageBox.Show("Xóa thông tin  không hợp lệ!!!");
         }
         DialogResult dlr = MessageBox.Show("Thông báo xác nhận xóa",
                                            "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
         if (dlr == DialogResult.No)
         {
         }
         if (dlr == DialogResult.Yes)
         {
             dgvHSHS.DataSource = myHSHS.LayDanhSachHoSoHocSinh();
             ClearHoSoHocSinh();
             btnXoa.Enabled = true;
         }
     }
 }