private void btnLuu_Click(object sender, EventArgs e) { if (dataGridViewX1.Rows.Count > 0) { for (int i = 0; i < dataGridViewX1.Rows.Count; i++) { string _maHV = _objhocvienbus.NextIDHocVien(); //Them hoc vien _objhocvien = new HocVien( _maHV, dataGridViewX1.Rows[i].Cells[1].Value.ToString(), //hoten dataGridViewX1.Rows[i].Cells[4].Value.ToString(), //gioitinh dataGridViewX1.Rows[i].Cells[3].Value.ToString(), //diachi dataGridViewX1.Rows[i].Cells[2].Value.ToString(), //sdt null, Double.Parse("0")); //Them thong tin dang ky cua hoc vien _objthongtindangky = new ThongTinDangKy( _maHV, dtNgayLapTTHV.Text, "Chưa học", Int32.Parse("0"), _objngayhocbus.GetMa_TheoTen(dataGridViewX1.Rows[0].Cells[5].Value.ToString()), //mangayranh _objcahocbus.GetMa_TheoTen(dataGridViewX1.Rows[0].Cells[6].Value.ToString()), //macaranh _objtrinhdobus.GetMa_TheoTen(dataGridViewX1.Rows[0].Cells[7].Value.ToString()), //matrinhdohientai _objtrinhdobus.GetMa_TheoTen(dataGridViewX1.Rows[0].Cells[8].Value.ToString()), //matrinhdomuonhoc _objtrinhdobus.GetMa_TheoTen(dataGridViewX1.Rows[0].Cells[8].Value.ToString()), //matrinhdoduochoc null); if (_objthongtindangkybus.AddThongTinDangKy(_objthongtindangky)) { if (_objhocvienbus.AddHocVien(_objhocvien)) { dataGridViewX1.Rows.Remove(dataGridViewX1.Rows[i]); i--; LoadData(); } else { _objthongtindangkybus.DeleteThongTinDangKy(_maHV); } } else { string a = dataGridViewX1.Rows[i].Cells[0].Value.ToString(); MessageBox.Show("Lưu dòng " + a + " thất bại"); } } if (dataGridViewX1.Rows.Count == 0) { MessageBox.Show("Lưu thành công"); } resettextbox(); } else { MessageBox.Show("Không có dữ liệu để lưu ! ", "Thống báo ", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void btnSua_Click(object sender, EventArgs e) { try { if ((txtTenHocVien.Text == "") || (txtSDT.Text == "") || (txtDiaChi.Text == "") || (cbGioiTinh.Text == "") || (cbNgayRanh.Text == "") || (cbCaRanh.Text == "") || (cbTrinhDoHienTai.Text == "") || (cbTrinhDoMuonHoc.Text == "")) { MessageBox.Show("Bạn còn số liệu chưa nhập "); return; } string _maHV = dgvDSHVTiemNang.CurrentRow.Cells[0].Value.ToString();//cbbMaHocVien.Text; //Them hoc vien _objHV = new HocVien( _maHV, txtTenHocVien.Text, //hoten cbGioiTinh.Text, //gioitinh txtDiaChi.Text, //diachi txtSDT.Text, //sdt null, Double.Parse("0")); //Them thong tin dang ky cua hoc vien _objThongTinDangKy = new ThongTinDangKy( _maHV, dtNgayLapTTHV.Text, "Chưa học", Int32.Parse("0"), _objNgayHocBUS.GetMa_TheoTen(cbNgayRanh.Text), //mangayranh _objCaHocBUS.GetMa_TheoTen(cbCaRanh.Text), //macaranh _objTrinhDoBUS.GetMa_TheoTen(cbTrinhDoHienTai.Text), //matrinhdohientai _objTrinhDoBUS.GetMa_TheoTen(cbTrinhDoMuonHoc.Text), //matrinhdomuonhoc _objTrinhDoBUS.GetMa_TheoTen(cbTrinhDoMuonHoc.Text), //matrinhdoduochoc null); if (_objHVBUS.EditHocVien(_objHV) && _objThongTinDangKyBUS.EditThongTinDangKy(_objThongTinDangKy)) { LoadData(); MessageBox.Show("Sửa Thành Công ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); resettextbox(); } else { MessageBox.Show("Sửa Thất Bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch { MessageBox.Show("Bạn đã nhập sai thông tin, vui lòng nhập lại !", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } }