private void btnXoa_Click(object sender, EventArgs e) { if (tblMonHoc.Rows.Count == 0) { MessageBox.Show("Không còn dữ liệu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (txtMaMon.Text == "") { MessageBox.Show("Chưa chọn bản ghi nào", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string sql = "select MaMon from Diem where MaMon='" + txtMaMon.Text.Trim() + "'"; if (DAO.CheckKeyExist(sql) == true) { MessageBox.Show("Bạn không thể xóa!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { if (MessageBox.Show("Bạn có muốn xóa không ?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.OK) { sql = "delete from MonHoc where MaMon=N'" + txtMaMon.Text.Trim() + "'"; DAO.OpenConnection(); SqlCommand cmd = new SqlCommand(); cmd.CommandText = sql; cmd.Connection = DAO.con; cmd.ExecuteNonQuery(); DAO.CloseConnection(); LoadDataToTable(); Reset(); txtMaMon.Enabled = false; } } }
private void btnXoa_Click(object sender, EventArgs e) { //DAO.OpenConnection(); string sql; if (tblKhoa.Rows.Count == 0) { MessageBox.Show("Không còn dữ liệu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (txtMaKhoa.Text == "") { MessageBox.Show("Chưa chọn bản ghi nào", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } sql = "select MaKhoa from ChuyenNganh where MaKhoa='" + txtMaKhoa.Text.Trim() + "'"; string sql1 = "select MaKhoa from SinhVien where MaKhoa='" + txtMaKhoa.Text.Trim() + "'"; string sql2 = "select MaKhoa from Lop where MaKhoa='" + txtMaKhoa.Text.Trim() + "'"; if (DAO.CheckKeyExist(sql) || DAO.CheckKeyExist(sql1) || DAO.CheckKeyExist(sql2)) { MessageBox.Show("Bạn không thể xóa!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { if (MessageBox.Show("Bạn có muốn xóa không?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { sql = "DELETE Khoa WHERE MaKhoa='" + txtMaKhoa.Text.ToString() + "'"; DAO.RunSql(sql); LoadDataToGrivew(); ResetValues(); } } //DAO.CloseConnection(); }
private void btnXoa_Click(object sender, EventArgs e) { string sql; if (tblDanToc.Rows.Count == 0) { MessageBox.Show("Không còn dữ liệu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (txtMaDanToc.Text == "") { MessageBox.Show("Bạn chưa chọn bản ghi nào", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } sql = "select MaDanToc from SinhVien where MaDanToc='" + txtMaDanToc.Text.Trim() + "'"; if (DAO.CheckKeyExist(sql)) { MessageBox.Show("Bạn không thể xóa!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { if (MessageBox.Show("Bạn có muốn xóa không?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { sql = "DELETE DanToc WHERE MaDanToc=N'" + txtMaDanToc.Text + "'"; DAO.RunSql(sql); Load_DataGridView(); ResetValues(); } } }
private void btnLuu_Click(object sender, EventArgs e) { DAO.OpenConnection(); if (txtMaKhoa.Text == "") { MessageBox.Show("bạn chưa nhập mã khoa "); txtMaKhoa.Focus(); return; } if (txtTenKhoa.Text == "") { MessageBox.Show("bạn chưa nhập tên khoa"); txtTenKhoa.Focus(); return; } if (txtDienThoai.Text == "") { MessageBox.Show("bạn chưa nhập số điện thoại "); txtDienThoai.Focus(); return; } if (txtDiaChi.Text == "") { MessageBox.Show("bạn chưa nhập địa chỉ "); txtDiaChi.Focus(); return; } if (txtWebsite.Text == "") { MessageBox.Show("bạn chưa nhập website "); txtWebsite.Focus(); return; } string sqlCheckKey = "Select * from Khoa Where MaKhoa = '" + txtMaKhoa.Text.ToString() + "'"; if (DAO.CheckKeyExist(sqlCheckKey)) { MessageBox.Show("Mã khoa đã tồn tại", "thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); DAO.CloseConnection(); txtMaKhoa.Focus(); return; } string sql = "insert into Khoa values ('" + txtMaKhoa.Text.ToString() + "' , N'" + txtTenKhoa.Text.Trim() + "','" + txtDienThoai.Text.Trim() + "','" + txtDiaChi.Text.Trim() + "','" + txtWebsite.Text.Trim() + "')"; DAO.RunSql(sql); LoadDataToGrivew(); GridViewKhoa.Enabled = true; ResetValues(); btnXoa.Enabled = true; btnThem.Enabled = true; btnSua.Enabled = true; btnHuy.Enabled = true; btnLuu.Enabled = false; txtMaKhoa.Enabled = false; DAO.CloseConnection(); }
private int CheckRdoMaSV() { int kt = 0; if (txtMaSV.Text == "") { MessageBox.Show("Vui lòng chọn mã sinh viên trước!"); ResetValues1(); kt = -1; } else { string sql = "select MaSV from SinhVien where MaSV='" + txtMaSV.Text.Trim() + "'"; tblInBangDiemSV = DAO.GetDataToTable(sql); if (tblInBangDiemSV.Rows.Count == 0) { MessageBox.Show("Mã sinh viên không tồn tại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); ResetValues1(); kt = -1; } else { sql = "select * from Diem where MaSV=N'" + txtMaSV.Text + "'"; if (DAO.CheckKeyExist(sql) == false) { MessageBox.Show("Mã sinh viên chưa có điểm , hãy nhập mã khác để in", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); ResetValues1(); kt = -1; } } } return(kt); }
private void btnLuu_Click(object sender, EventArgs e) { if (txtMaLop.Text.Trim() == "") { MessageBox.Show("Mã lớp không được để trống", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtMaLop.Focus(); return; } if (txtTenLop.Text.Trim() == "") { MessageBox.Show("Tên lớp không được để trống", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtTenLop.Focus(); return; } if (cmbMaKhoa.SelectedIndex == -1) { MessageBox.Show("Bạn phải chọn tên khoa", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (txtKhoaHoc.Text.Trim() == "") { MessageBox.Show("Khóa học không được để trống", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtKhoaHoc.Focus(); return; } string s1 = "select MaLop from Lop where MaLop = N'" + txtMaLop.Text.Trim() + "'"; if (DAO.CheckKeyExist(s1)) { MessageBox.Show("Mã lớp này đã tồn tại. Nhập lại.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); DAO.OpenConnection(); txtMaLop.Text = ""; txtMaLop.Focus(); return; } else { string sql = "insert into Lop values (N'" + txtMaLop.Text.Trim() + "',N'" + txtTenLop.Text.Trim() + "','" + cmbMaKhoa.SelectedValue.ToString() + "',N'" + txtKhoaHoc.Text.Trim() + "',0)"; DAO.OpenConnection(); SqlCommand cmd = new SqlCommand(); cmd.CommandText = sql; cmd.Connection = DAO.con; cmd.ExecuteNonQuery(); DAO.CloseConnection(); MessageBox.Show("Bạn đã thêm mới thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); LoadDataToTable(); Reset(); btnXoa.Enabled = true; btnThem.Enabled = true; btnSua.Enabled = true; btnHuy.Enabled = false; btnLuu.Enabled = false; txtMaLop.Enabled = false; //cmbMaKhoa.Enabled = false; } }
private void btnXoa_Click(object sender, EventArgs e) { int s1 = Convert.ToInt32(DAO.GetFieldValues("select SiSo from Lop where MaLop='" + cmbMaLop.SelectedValue + "'")); if (tblSinhVien.Rows.Count == 0) { MessageBox.Show("Không còn dữ liệu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (txtMaSV.Text == "") { MessageBox.Show("Chưa chọn bản ghi nào", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string s11 = "select MaSV from Diem where MaSV='" + txtMaSV.Text.Trim() + "'"; if (DAO.CheckKeyExist(s11) == true) { MessageBox.Show("Bạn không thể xóa!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { if (s1 > 0) { if (MessageBox.Show("bạn có muốn xóa không?", "thông báo", MessageBoxButtons.OKCancel) == DialogResult.OK) { sql = " delete from SinhVien where MaSV='" + txtMaSV.Text + "'"; String sql1 = " update Lop set SiSo = SiSo -1 WHERE MaLop = '" + cmbMaLop.SelectedValue + "'"; DAO.RunSql(sql1); s1 = Convert.ToInt32(DAO.GetFieldValues(" select SiSo from Lop where MaLop = '" + cmbMaLop.SelectedValue + "'")); MessageBox.Show(" Sĩ số sau khi cập nhật của lớp '" + cmbMaLop.Text + "' là " + s1, " thông báo ", MessageBoxButtons.OK, MessageBoxIcon.Information); DAO.OpenConnection(); DAO.RunSql(sql); ResetValues(); LoadDatatogriview(); } if (s1 == 0) { string sql = DAO.GetFieldValues(" select MaLop from Lop where SiSo = " + s1 + ""); if (MessageBox.Show("sĩ số lớp bằng 0, Bạn có muốn xóa lớp không", "thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { string ss = " select MaSV from SinhVien where MaLop ='" + sql + "'"; if (DAO.CheckKeyExist(ss) == false) { string s = "delete from Lop where MaLop='" + sql + "'"; MessageBox.Show(s); DAO.OpenConnection(); DAO.RunSql(s); DAO.CloseConnection(); ResetValues(); LoadDatatogriview(); } } } } } }
private void btnLuu_Click(object sender, EventArgs e) { //Kiem tra DL //Các trường không được trống if (txtMaChuyenNganh.Text == "") { MessageBox.Show("Bạn chưa nhập Mã Chuyên Ngành!"); txtMaChuyenNganh.Focus(); return; } if (txtTenChuyenNganh.Text == "") { MessageBox.Show("Bạn chưa nhập Tên Chuyên Ngành!"); txtTenChuyenNganh.Focus(); return; } if (cmbKhoa.SelectedIndex == -1) { MessageBox.Show("Bạn chưa chọn Khoa!"); return; } // string sql = "select * from ChuyenNganh where MaChuyenNganh='" + txtMaChuyenNganh.Text.Trim() + "'"; DAO.OpenConnection(); if (DAO.CheckKeyExist(sql)) { MessageBox.Show("Mã Chuyên Ngành đã tồn tại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); DAO.CloseConnection(); txtMaChuyenNganh.Focus(); return; } else { sql = "insert into ChuyenNganh (MaChuyenNganh,TenChuyenNganh,MaKhoa) " + " values ('" + txtMaChuyenNganh.Text.Trim() + "',N'" + txtTenChuyenNganh.Text.Trim() + "','" + cmbKhoa.Text.Trim() + "')"; SqlCommand cmd = new SqlCommand(sql, DAO.con); cmd.ExecuteNonQuery(); DAO.CloseConnection(); LoadDataToGridView(); } ResetValues(); LoadDataToGridView(); GridViewChuyenNganh.Enabled = true; ResetValues(); btnXoa.Enabled = true; btnThem.Enabled = true; btnSua.Enabled = true; btnHuy.Enabled = false; btnLuu.Enabled = false; txtMaChuyenNganh.Enabled = false; DAO.CloseConnection(); }
private void btnLuu_Click(object sender, EventArgs e) { if (txtMaMon.Text.Trim() == "") { MessageBox.Show("Mã môn không được để trống", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtMaMon.Focus(); return; } if (txtTenMon.Text.Trim() == "") { MessageBox.Show("Tên môn không được để trống", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtTenMon.Focus(); return; } if (txtDVHT.Text.Trim() == "") { MessageBox.Show("Số tín chỉ không được để trống", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtDVHT.Focus(); return; } string s1 = "select MaMon from MonHoc where MaMon = N'" + txtMaMon.Text.Trim() + "'"; if (DAO.CheckKeyExist(s1)) { MessageBox.Show("Mã môn này đã tồn tại. Nhập lại.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); DAO.OpenConnection(); txtMaMon.Text = ""; txtMaMon.Focus(); return; } else { string sql = "insert into MonHoc values (N'" + txtMaMon.Text.Trim() + "',N'" + txtTenMon.Text.Trim() + "'," + txtDVHT.Text.Trim() + ")"; DAO.OpenConnection(); SqlCommand cmd = new SqlCommand(); cmd.CommandText = sql; cmd.Connection = DAO.con; cmd.ExecuteNonQuery(); DAO.CloseConnection(); MessageBox.Show("Bạn đã thêm mới thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); LoadDataToTable(); Reset(); btnXoa.Enabled = true; btnThem.Enabled = true; btnSua.Enabled = true; btnHuy.Enabled = false; btnLuu.Enabled = false; txtMaMon.Enabled = false; } }
private void btnLuu_Click(object sender, EventArgs e) { if (txtMaChucVu.Text == "") { MessageBox.Show("bạn chưa nhập mã chức vụ "); txtMaChucVu.Focus(); return; } if (txtTenChucVu.Text == "") { MessageBox.Show("bạn chưa nhập tên chức vụ"); txtTenChucVu.Focus(); return; } string sqlCheckKey = "Select * from ChucVu Where MaChucVu = '" + txtMaChucVu.Text.Trim() + "'"; DAO.OpenConnection(); if (DAO.CheckKeyExist(sqlCheckKey)) { MessageBox.Show("Mã chức vụ đã tồn tại", "thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); DAO.CloseConnection(); txtMaChucVu.Focus(); return; } else { string sql = "insert into ChucVu values ('" + txtMaChucVu.Text.Trim() + "' , N'" + txtTenChucVu.Text.Trim() + "')"; SqlCommand cmd = new SqlCommand(sql, DAO.con); cmd.ExecuteNonQuery(); LoadDataToGrivew(); GridViewChucVu.Enabled = true; ResetValues(); btnXoa.Enabled = true; btnThem.Enabled = true; btnSua.Enabled = true; btnHuy.Enabled = true; btnLuu.Enabled = false; txtMaChucVu.Enabled = false; DAO.CloseConnection(); } }
private void btnLuu_Click(object sender, EventArgs e) { if (txtMaPhong.Text.Trim() == "") { MessageBox.Show("Mã phòng không được để trống", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtMaPhong.Focus(); return; } if (txtTenPhong.Text.Trim() == "") { MessageBox.Show("Tên phòng không được để trống", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtTenPhong.Focus(); return; } string s1 = "select MaPhong from PhongHoc where MaPhong = N'" + txtMaPhong.Text.Trim() + "'"; if (DAO.CheckKeyExist(s1)) { MessageBox.Show("Mã phòng này đã tồn tại. Nhập lại.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); DAO.OpenConnection(); txtMaPhong.Text = ""; txtMaPhong.Focus(); return; } else { string sql = "insert into PhongHoc values (N'" + txtMaPhong.Text.Trim() + "',N'" + txtTenPhong.Text.Trim() + "')"; DAO.OpenConnection(); SqlCommand cmd = new SqlCommand(); cmd.CommandText = sql; cmd.Connection = DAO.con; cmd.ExecuteNonQuery(); DAO.CloseConnection(); LoadDataToTable(); Reset(); btnXoa.Enabled = true; btnThem.Enabled = true; btnSua.Enabled = true; btnHuy.Enabled = false; btnLuu.Enabled = false; txtMaPhong.Enabled = false; } }
private void btnLuu_Click(object sender, EventArgs e) { DAO.OpenConnection(); if (txtMaQue.Text == "") { MessageBox.Show("bạn chưa nhập mã quê "); txtMaQue.Focus(); return; } if (txtTenQue.Text == "") { MessageBox.Show("bạn chưa nhập tên quê"); txtTenQue.Focus(); return; } string sqlCheckKey = "Select * from Que Where MaQue = '" + txtMaQue.Text.Trim() + "'"; DAO.OpenConnection(); if (DAO.CheckKeyExist(sqlCheckKey)) { MessageBox.Show("Mã quê đã tồn tại", "thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); DAO.CloseConnection(); txtMaQue.Focus(); return; } string sql = "insert into Que values ('" + txtMaQue.Text.Trim() + "' , N'" + txtTenQue.Text.Trim() + "')"; DAO.RunSql(sql); LoadDataToGrivew(); GridViewQue.Enabled = true; ResetValues(); btnXoa.Enabled = true; btnThem.Enabled = true; btnSua.Enabled = true; btnHuy.Enabled = false; btnLuu.Enabled = false; txtMaQue.Enabled = false; DAO.CloseConnection(); }
private void btnXoa_Click(object sender, EventArgs e) { if (tblSinhVien.Rows.Count == 0) { MessageBox.Show("Không còn dữ liệu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (txtMaSV.Text == "") { MessageBox.Show("Chưa chọn bản ghi nào", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string sql = "select MaSV from Diem where MaSV='" + txtMaSV.Text.Trim() + "'"; if (DAO.CheckKeyExist(sql) == true) { MessageBox.Show("Bạn không thể xóa!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { if (MessageBox.Show("Bạn có muốn xóa không?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { sql = " delete from SinhVien where MaSV='" + txtMaSV.Text + "'"; //cập nhật sĩ số khi xóa sinh viên String sql1 = " update Lop set SiSo = SiSo -1 WHERE MaLop = '" + cmbMaLop.SelectedValue + "'"; DAO.RunSql(sql1); int s2 = Convert.ToInt32(DAO.GetFieldValues(" select SiSo from Lop where MaLop = '" + cmbMaLop.SelectedValue + "'")); MessageBox.Show(" Sĩ số sau khi cập nhật của lớp '" + cmbMaLop.Text + "' là " + s2, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); DAO.OpenConnection(); SqlCommand cmd = new SqlCommand(); cmd.CommandText = sql; cmd.Connection = DAO.con; cmd.ExecuteNonQuery(); DAO.CloseConnection(); ResetValues(); LoadDatatogriview(); //LoadDatatogriview(); // update sinh viên giảm xuống } } }
private void btnDanhSach_Click(object sender, EventArgs e) { DAO.OpenConnection(); /*string s0 = "INSERT INTO Diem(MaSV) select MaSV from SinhVien"; * DAO.RunSql(s0); * Load_DataGridView();*/ string s1 = DAO.GetFieldValues("SELECT MaSV FROM SinhVien"); MessageBox.Show(s1); string s2 = "select MaSV from Diem where MaSV='" + s1 + "'"; MessageBox.Show(s2); if (DAO.CheckKeyExist(s2) == false) { string s3 = "INSERT INTO Diem VALUES('" + s1 + "', null,null, null,null,null)"; MessageBox.Show(s3); DAO.RunSql(s3); Load_DataGridView(); } }
private void btnLuu_Click(object sender, EventArgs e) { if (txtMaQue.Text == "") { MessageBox.Show("bạn chưa nhập mã quê "); txtMaQue.Focus(); return; } if (txtTenQue.Text == "") { MessageBox.Show("bạn chưa nhập tên quê"); txtTenQue.Focus(); return; } string sqlCheckKey = "Select * from Que Where MaQue = '" + txtMaQue.Text.Trim() + "'"; DAO.OpenConnection(); if (DAO.CheckKeyExist(sqlCheckKey)) { MessageBox.Show("Mã quê đã tồn tại", "thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); DAO.CloseConnection(); txtMaQue.Focus(); return; } else { string sql = "insert into Que values ('" + txtMaQue.Text.Trim() + "' , N'" + txtTenQue.Text.Trim() + "')"; SqlCommand cmd = new SqlCommand(sql, DAO.con); cmd.ExecuteNonQuery(); DAO.CloseConnection(); LoadDataToGrivew(); DAO.CloseConnection(); btnLuu.Enabled = false; txtMaQue.Enabled = false; } }
private void btnLuu_Click(object sender, EventArgs e) { DAO.OpenConnection(); string sql; if (txtMaHDT.Text.Trim().Length == 0) { MessageBox.Show("Bạn phải nhập mã hệ đào tạo", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtMaHDT.Focus(); return; } if (txtTenHDT.Text.Trim().Length == 0) { MessageBox.Show("Bạn phải nhập tên hệ đào tạo", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtTenHDT.Focus(); return; } sql = "SELECT MaHDT FROM HeDaoTao WHERE MaHDT=N'" + txtMaHDT.Text.Trim() + "'"; if (DAO.CheckKeyExist(sql)) { MessageBox.Show("Mã hệ đào tạo này đã có, bạn phải nhập mã khác", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtMaHDT.Focus(); txtMaHDT.Text = ""; return; } sql = "INSERT INTO HeDaoTao(MaHDT,TenHDT) VALUES('" + txtMaHDT.Text.Trim() + "',N'" + txtTenHDT.Text.Trim() + "')"; DAO.RunSql(sql); Load_DataGridView(); GridViewHeDaoTao.Enabled = true; ResetValues(); btnXoa.Enabled = true; btnThem.Enabled = true; btnSua.Enabled = true; btnHuy.Enabled = true; btnLuu.Enabled = false; txtMaHDT.Enabled = false; DAO.CloseConnection(); }
private void btnXoa_Click(object sender, EventArgs e) { string sql = "select MaChuyenNganh from SinhVien where MaChuyenNganh='" + txtMaChuyenNganh.Text.Trim() + "'"; if (DAO.CheckKeyExist(sql) == true) { MessageBox.Show("Bạn không thể xóa!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { if (MessageBox.Show("Bạn có muốn xóa?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { sql = "delete from ChuyenNganh where MaChuyenNganh = '" + txtMaChuyenNganh.Text + "'"; DAO.OpenConnection(); SqlCommand cmd = new SqlCommand(); cmd.CommandText = sql; cmd.Connection = DAO.con; cmd.ExecuteNonQuery(); DAO.CloseConnection(); LoadDataToGridView(); } } }
private void btnXoa_Click(object sender, EventArgs e) { string sql; if (tblQue.Rows.Count == 0) { MessageBox.Show("Không còn dữ liệu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (txtMaQue.Text == "") { MessageBox.Show("Chưa chọn bản ghi nào", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } sql = "select MaQue from SinhVien where MaQue='" + txtMaQue.Text.Trim() + "'"; if (DAO.CheckKeyExist(sql)) { MessageBox.Show("Bạn không thể xóa!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { if (MessageBox.Show("Bạn có muốn xóa không?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { sql = "DELETE Que WHERE MaQue= N'" + txtMaQue.Text.Trim() + "'"; DAO.OpenConnection(); SqlCommand cmd = new SqlCommand(); cmd.CommandText = sql; cmd.Connection = DAO.con; cmd.ExecuteNonQuery(); DAO.CloseConnection(); ResetValues(); LoadDataToGrivew(); } } }
private void btnIn_Click(object sender, EventArgs e) { if (rdoMaSV.Checked == true) { int kt = 0; if (txtMaSV.Text == "") { MessageBox.Show("Vui lòng chọn mã sinh viên trước!"); ResetValues1(); } else { string sql = "select MaSV from SinhVien where MaSV='" + txtMaSV.Text.Trim() + "'"; tblInBangDiemSV = DAO.GetDataToTable(sql); if (tblInBangDiemSV.Rows.Count == 0) { MessageBox.Show("Mã sinh viên không tồn tại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); kt = -1; ResetValues1(); } if (kt == 0) { sql = "select * from Diem where MaSV=N'" + txtMaSV.Text + "'"; if (DAO.CheckKeyExist(sql) == false) { MessageBox.Show("Mã sinh viên chưa có điểm , hãy nhập mã khác để in", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); ResetValues1(); } else { MessageBox.Show("Vui lòng chờ... Đang cập nhật dữ liệu"); COMExcel.Application exApp = new COMExcel.Application(); COMExcel.Workbook exBook; //Trong 1 chương trình Excel có nhiều Workbook COMExcel.Worksheet exSheet; //Trong 1 Workbook có nhiều Worksheet COMExcel.Range exRange; int hang = 0, cot = 0; exBook = exApp.Workbooks.Add(COMExcel.XlWBATemplate.xlWBATWorksheet); exSheet = exBook.Worksheets[1]; exRange = exSheet.Cells[1, 1]; exRange.Range["A1:Z300"].Font.Name = "Times new roman"; //Font chữ exRange.Range["A1:B3"].Font.Size = 10; exRange.Range["A1:B3"].Font.Bold = true; exRange.Range["A1:B3"].Font.ColorIndex = 25; //Màu navy exRange.Range["A1:A1"].ColumnWidth = 7; exRange.Range["B1:B1"].ColumnWidth = 15; exRange.Range["A1:D1"].MergeCells = true; exRange.Range["A1:D1"].HorizontalAlignment = COMExcel.XlHAlign.xlHAlignLeft; exRange.Range["A1:D1"].Value = "Banking Acedemy Vietnam"; exRange.Range["A2:D2"].MergeCells = true; exRange.Range["A2:D2"].HorizontalAlignment = COMExcel.XlHAlign.xlHAlignLeft; exRange.Range["A2:D2"].Value = "12 Chua Boc, Quang Trung, Dong Da, Hanoi, Vietnam"; exRange.Range["B5:F5"].Font.Size = 20; exRange.Range["B5:F5"].Font.Bold = true; exRange.Range["B5:F5"].Font.ColorIndex = 9; //Màu nâu exRange.Range["B5:F5"].MergeCells = true; exRange.Range["B5:F5"].HorizontalAlignment = COMExcel.XlHAlign.xlHAlignCenter; exRange.Range["B5:F5"].Value = "ĐIỂM SINH VIÊN"; exRange.Range["B8:F9"].MergeCells = true; exRange.Range["B7:F7"].Font.ColorIndex = 56; //exRange.Range["B7:F7"].Font.Bold = true; exRange.Range["B8:F8"].HorizontalAlignment = COMExcel.XlHAlign.xlHAlignCenter; exRange.Range["B8:B8"].Value = "Thông tin sinh viên \nMã sinh viên: " + txtMaSV.Text.Trim(); //+ "\nTên sinh viên: " + txtTenSV.Text.Trim() //exRange.Range["B8:F8"].MergeCells = true; //exRange.Range["B8:B8"].HorizontalAlignment = COMExcel.XlHAlign.xlHAlignLeft; //exRange.Range["B8:B8"].Value = "Tên sinh viên: " + txtTenSV.Text.Trim(); // exRange.Range["B9:F9"].MergeCells = true; // exRange.Range["B9:F9"].HorizontalAlignment = COMExcel.XlHAlign.xlHAlignLeft; // exRange.Range["B9:F9"].Value = "; BorderAround(exRange.Range["B8:F9"], 25); int hk = 1; int row = 10; sql = "select MAX(HocKy) from Diem where MaSV=N'" + txtMaSV.Text.Trim() + "'"; string SoLuongHK = DAO.GetFieldValues(sql); for (hk = 1; hk <= Convert.ToInt32(SoLuongHK); hk++) { exRange = exSheet.Cells[1][hk + row]; sql = "SELECT a.MaMon,b.TenMon,b.DVHT,a.LanThi,a.Diem FROM Diem as a inner join MonHoc as b on a.MaMon=b.MaMon where MaSV = N'" + txtMaSV.Text.Trim() + "'and HocKy=" + hk; tblInBangDiemSV = DAO.GetDataToTable(sql); exRange.Range["A1:K1"].Font.Bold = true; exRange.Range["A1:G1"].MergeCells = true; exRange.Range["A1:B1"].HorizontalAlignment = COMExcel.XlHAlign.xlHAlignLeft; exRange.Range["A1:A1"].Value = "Học kỳ " + hk; exRange.Range["A1:A1"].Interior.Color = System.Drawing.Color.Bisque; row++; exRange = exSheet.Cells[2][hk + row]; exRange.Range["A1:K1"].Font.Bold = true; exRange.Range["A1:F1"].HorizontalAlignment = COMExcel.XlHAlign.xlHAlignCenter; exRange.Range["A1:A1"].Value = "STT"; exRange.Range["A1:A1"].ColumnWidth = 5; exRange.Range["B1:B1"].Value = "Mã môn"; exRange.Range["C1:C1"].Value = "Tên môn"; exRange.Range["C1:C1"].ColumnWidth = 40; exRange.Range["D1:D1"].Value = "ĐVHT"; exRange.Range["E1:E1"].Value = "Lần thi"; exRange.Range["F1:F1"].Value = "Điểm"; row++; for (hang = 0; hang < tblInBangDiemSV.Rows.Count; hang++) { //Điền số thứ tự vào cột 1 từ dòng 11 exSheet.Cells[2][hang + hk + row] = hang + 1; for (cot = 0; cot < tblInBangDiemSV.Columns.Count; cot++) //Điền thông tin hàng từ cột thứ 2, dòng 12 { exSheet.Cells[cot + 3][hang + hk + row] = tblInBangDiemSV.Rows[hang][cot].ToString(); //if (cot == 3) exSheet.Cells[cot + 3][hang + hk + row] = tblInBangDiemSV.Rows[hang][cot].ToString(); } } row += tblInBangDiemSV.Rows.Count; } void BorderAround(COMExcel.Range range, int colour) { COMExcel.Borders borders1 = range.Borders; borders1[COMExcel.XlBordersIndex.xlEdgeLeft].LineStyle = COMExcel.XlLineStyle.xlContinuous; borders1[COMExcel.XlBordersIndex.xlEdgeTop].LineStyle = COMExcel.XlLineStyle.xlContinuous; borders1[COMExcel.XlBordersIndex.xlEdgeBottom].LineStyle = COMExcel.XlLineStyle.xlContinuous; borders1[COMExcel.XlBordersIndex.xlEdgeRight].LineStyle = COMExcel.XlLineStyle.xlContinuous; borders1.Color = colour; borders1[COMExcel.XlBordersIndex.xlInsideVertical].LineStyle = COMExcel.XlLineStyle.xlLineStyleNone; borders1[COMExcel.XlBordersIndex.xlInsideHorizontal].LineStyle = COMExcel.XlLineStyle.xlLineStyleNone; borders1[COMExcel.XlBordersIndex.xlDiagonalUp].LineStyle = COMExcel.XlLineStyle.xlLineStyleNone; borders1[COMExcel.XlBordersIndex.xlDiagonalDown].LineStyle = COMExcel.XlLineStyle.xlLineStyleNone; borders1 = null; } exSheet.Name = "Điểm sinh viên"; exApp.Visible = true; } } } } else if (rdoTim.Checked == true) { if (cmbMaLop.Text == "" || cmbMaMon.Text == "" || txtLanThi.Text.Trim() == "") { MessageBox.Show("Vui lòng chọn đủ điều kiện hiển thị trước!"); } else { MessageBox.Show("Vui lòng chờ... Đang cập nhật dữ liệu"); COMExcel.Application exApp = new COMExcel.Application(); COMExcel.Workbook exBook; //Trong 1 chương trình Excel có nhiều Workbook COMExcel.Worksheet exSheet; //Trong 1 Workbook có nhiều Worksheet COMExcel.Range exRange; string sql; int hang = 0, cot = 0; exBook = exApp.Workbooks.Add(COMExcel.XlWBATemplate.xlWBATWorksheet); exSheet = exBook.Worksheets[1]; exRange = exSheet.Cells[1, 1]; exRange.Range["A1:Z300"].Font.Name = "Times new roman"; //Font chữ exRange.Range["A1:B3"].Font.Size = 10; exRange.Range["A1:B3"].Font.Bold = true; exRange.Range["A1:B3"].Font.ColorIndex = 25; //Màu navy exRange.Range["A1:A1"].ColumnWidth = 7; exRange.Range["B1:B1"].ColumnWidth = 15; exRange.Range["A1:B1"].MergeCells = true; exRange.Range["A1:B1"].HorizontalAlignment = COMExcel.XlHAlign.xlHAlignCenter; exRange.Range["A1:B1"].Value = "Banking Acedemy Vietnam"; exRange.Range["A2:E2"].MergeCells = true; exRange.Range["A2:E2"].HorizontalAlignment = COMExcel.XlHAlign.xlHAlignCenter; exRange.Range["A2:E2"].Value = "12 Chua Boc Street, Quang Trung Ward, Dong Da District, Hanoi, Vietnam"; exRange.Range["C5:F5"].Font.Size = 20; exRange.Range["C5:F5"].Font.Bold = true; exRange.Range["C5:F5"].Font.ColorIndex = 9; //Màu nâu exRange.Range["C5:F5"].MergeCells = true; exRange.Range["C5:F5"].HorizontalAlignment = COMExcel.XlHAlign.xlHAlignCenter; exRange.Range["C5:F5"].Value = "DANH SÁCH ĐIỂM SINH VIÊN"; sql = "SELECT * FROM Diem where MaMon=N'" + cmbMaMon.SelectedValue + "' and MaLop=N'" + cmbMaLop.SelectedValue + "'and LanThi=" + txtLanThi.Text.Trim(); tblInBangDiemSV = DAO.GetDataToTable(sql); exRange.Range["A7:K7"].Font.Bold = true; exRange.Range["A7:K7"].HorizontalAlignment = COMExcel.XlHAlign.xlHAlignCenter; exRange.Range["C7:F7"].ColumnWidth = 12; exRange.Range["G7"].ColumnWidth = 16; exRange.Range["I7"].ColumnWidth = 13; exRange.Range["J7"].ColumnWidth = 12; exRange.Range["K7"].ColumnWidth = 12; exRange.Range["A7:G7"].Interior.Color = System.Drawing.Color.Bisque; exRange.Range["A7:A7"].Value = "STT"; exRange.Range["A7:A7"].ColumnWidth = 5; exRange.Range["B7:B7"].Value = "Mã sinh viên"; exRange.Range["C7:C7"].Value = "Mã lớp"; exRange.Range["D7:D7"].Value = "Mã môn"; exRange.Range["E7:E7"].Value = "Học kỳ"; exRange.Range["F7:F7"].Value = "Lần thi"; exRange.Range["G7:G7"].Value = "Điểm"; for (hang = 0; hang < tblInBangDiemSV.Rows.Count; hang++) { //Điền số thứ tự vào cột 1 từ dòng 8 exSheet.Cells[1][hang + 8] = hang + 1; for (cot = 0; cot < tblInBangDiemSV.Columns.Count; cot++) //Điền thông tin hàng từ cột thứ 2, dòng 8 { exSheet.Cells[cot + 2][hang + 8] = tblInBangDiemSV.Rows[hang][cot].ToString(); if (cot == 3) { exSheet.Cells[cot + 2][hang + 8] = tblInBangDiemSV.Rows[hang][cot].ToString(); } } } exSheet.Name = "Danh Sách Điểm Sinh viên"; exApp.Visible = true; } } }
private void btnLuu_Click(object sender, EventArgs e) { btnXoa.Enabled = false; string sql; if (txtMaSV.Text == "") { MessageBox.Show("Bạn không được để trống mã sinh viên"); txtMaSV.Focus(); return; } if (txtTenSV.Text == "") { MessageBox.Show("Bạn không được để trống tên sinh viên"); txtTenSV.Focus(); return; } if (cmbMaKhoa.SelectedIndex == -1) { MessageBox.Show("Bạn chưa chọn khoa"); cmbMaKhoa.Focus(); return; } if (cmbMaLop.SelectedIndex == -1) { MessageBox.Show("Bạn chưa chọn lớp"); cmbMaLop.Focus(); return; } if (cmbMaQue.SelectedIndex == -1) { MessageBox.Show("Bạn chưa chọn quê"); cmbMaQue.Focus(); return; } if (cmbMaDanToc.SelectedIndex == -1) { MessageBox.Show("Bạn chưa chọn dân tộc"); cmbMaDanToc.Focus(); return; } if (cmbMaHDT.SelectedIndex == -1) { MessageBox.Show("Bạn chưa chọn hệ đào tạo"); cmbMaHDT.Focus(); return; } if (cmbMaChuyenNganh.SelectedIndex == -1) { MessageBox.Show("Bạn chưa chọn chuyên ngành"); cmbMaChuyenNganh.Focus(); return; } if (cmbMaChucVu.SelectedIndex == -1) { MessageBox.Show("Bạn chưa chọn chức vụ"); cmbMaChucVu.Focus(); return; } if (mtbNgaySinh.Text == " / /") { MessageBox.Show("Bạn không để trống ngày sinh"); mtbNgaySinh.Focus(); return; } if (rdNam.Checked == false && rdNu.Checked == false) { MessageBox.Show("Bạn chưa chọn giới tính", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (!DAO.IsDate(mtbNgaySinh.Text)) { MessageBox.Show("Bạn phải nhập lại ngày sinh", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); mtbNgaySinh.Text = ""; mtbNgaySinh.Focus(); return; } if (rdNam.Checked == true) { GioiTinh = "Nam"; } if (rdNu.Checked == true) { GioiTinh = "Nữ"; } string s1 = " select MaSV from SinhVien where MaSV =N'" + txtMaSV.Text.Trim() + "'"; DAO.OpenConnection(); if (DAO.CheckKeyExist(s1)) { MessageBox.Show(" Mã sinh viên đã tồn tại", "thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); DAO.CloseConnection(); txtMaSV.Focus(); return; } else { sql = " insert into SinhVien values('" + txtMaSV.Text.Trim() + "',N'" + txtTenSV.Text.Trim() + "','" + cmbMaKhoa.SelectedValue.ToString() + "','" + cmbMaLop.SelectedValue.ToString() + "','" + DAO.ConvertDateTime(mtbNgaySinh.Text) + "',N'" + GioiTinh + "','" + cmbMaQue.SelectedValue.ToString() + "','" + cmbMaDanToc.SelectedValue.ToString() + "','" + cmbMaChuyenNganh.SelectedValue.ToString() + "','" + cmbMaHDT.SelectedValue.ToString() + "','" + cmbMaChucVu.SelectedValue.ToString() + "')"; //MessageBox.Show(sql); //cập nhật sĩ số string sql1 = " update Lop set SiSo = SiSo +1 WHERE MaLop = '" + cmbMaLop.SelectedValue + "'"; DAO.RunSql(sql1); int sl = Convert.ToInt32(DAO.GetFieldValues(" select SiSo from Lop where MaLop = '" + cmbMaLop.SelectedValue + "'")); //MessageBox.Show(" Bạn đã thêm mới thành công, sĩ số sau khi cập nhật của phòng '" + cmbMaLop.Text + "' là " + sl, " thông báo ", MessageBoxButtons.OK, MessageBoxIcon.Information); SqlCommand cmd = new SqlCommand(sql, DAO.con); // khai báo đổi tượng command cmd.CommandText = sql; // gán câu truy vấn cmd.Connection = DAO.con; cmd.ExecuteNonQuery(); DAO.CloseConnection(); LoadDatatogriview(); DAO.CloseConnection(); btnLuu.Enabled = false; txtMaSV.Enabled = false; } }
private void btnLuu_Click(object sender, EventArgs e) { //Kiem tra DL //Các trường không được trống if (cmbLop.SelectedIndex == -1) { MessageBox.Show("Bạn chưa chọn Lớp!"); return; } if (cmbPhong.SelectedIndex == -1) { MessageBox.Show("Bạn chưa chọn Phòng!"); return; } if (cmbMon.SelectedIndex == -1) { MessageBox.Show("Bạn chưa chọn Môn học!"); return; } int strHK = -1; if (rdohk1.Checked == true) { strHK = Convert.ToInt32(rdohk1.Text); } if (rdohk2.Checked == true) { strHK = Convert.ToInt32(rdohk2.Text); } if (rdohk3.Checked == true) { strHK = Convert.ToInt32(rdohk3.Text); } if (rdohk4.Checked == true) { strHK = Convert.ToInt32(rdohk4.Text); } if (rdohk5.Checked == true) { strHK = Convert.ToInt32(rdoca5.Text); } if (rdohk6.Checked == true) { strHK = Convert.ToInt32(rdohk6.Text); } if (rdohk7.Checked == true) { strHK = Convert.ToInt32(rdohk7.Text); } if (rdohk8.Checked == true) { strHK = Convert.ToInt32(rdohk8.Text); } if (strHK == -1) { MessageBox.Show("Bạn chưa chọn Học Kỳ!"); return; } int strCa = -1; if (rdoca1.Checked == true) { strCa = Convert.ToInt32(rdoca1.Text); } if (rdoca2.Checked == true) { strCa = Convert.ToInt32(rdoca2.Text); } if (rdoca3.Checked == true) { strCa = Convert.ToInt32(rdoca3.Text); } if (rdoca4.Checked == true) { strCa = Convert.ToInt32(rdoca4.Text); } if (rdoca5.Checked == true) { strCa = Convert.ToInt32(rdoca5.Text); } if (strCa == -1) { MessageBox.Show("Bạn chưa chọn Ca học!"); return; } string strThu = ""; if (rdothu2.Checked == true) { strThu += rdothu2.Text; } if (rdothu3.Checked == true) { strThu += rdothu3.Text; } if (rdothu4.Checked == true) { strThu += rdothu4.Text; } if (rdothu5.Checked == true) { strThu += rdothu5.Text; } if (rdothu6.Checked == true) { strThu += rdothu6.Text; } if (rdothu7.Checked == true) { strThu += rdothu7.Text; } if (strThu == "") { MessageBox.Show("Bạn chưa chọn Thứ học!"); return; } string sql = "select * from Thoi_Khoa_Bieu where MaLop='" + cmbLop.SelectedValue.ToString() + "' and MaMon=N'" + cmbMon.SelectedValue.ToString() + "' and HocKy=" + strHK + " and ThuHoc=N'" + strThu.ToString() + "' and CaHoc=" + strCa + " and MaPhong='" + cmbPhong.SelectedValue.ToString() + "'"; DAO.OpenConnection(); if (DAO.CheckKeyExist(sql)) { MessageBox.Show("Mã Lớp và Mã Môn đã trùng lịch!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); DAO.CloseConnection(); return; } string sql1 = "select * from Thoi_Khoa_Bieu where HocKy=" + strHK + " and ThuHoc=N'" + strThu.ToString() + "' and CaHoc=" + strCa + " and MaPhong='" + cmbPhong.SelectedValue.ToString() + "'"; DAO.OpenConnection(); if (DAO.CheckKeyExist(sql1)) { MessageBox.Show("Phòng học đã có lớp học!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else { sql = "insert into Thoi_Khoa_Bieu (MaLop,MaMon,HocKy,ThuHoc,CaHoc,MaPhong) " + " values ('" + cmbLop.SelectedValue.ToString() + "','" + cmbMon.SelectedValue.ToString() + "'," + strHK.ToString() + ",N'" + strThu.ToString() + "'," + strCa.ToString() + ",'" + cmbPhong.SelectedValue.ToString() + "')"; SqlCommand cmd = new SqlCommand(sql, DAO.con); cmd.ExecuteNonQuery(); DAO.CloseConnection(); LoadDataToGridView(); cmbLop.Enabled = false; cmbMon.Enabled = false; btnXoa.Enabled = true; btnThem.Enabled = true; btnSua.Enabled = true; btnHuy.Enabled = false; btnLuu.Enabled = false; } }
private void btnSua_Click(object sender, EventArgs e) { DAO.OpenConnection(); string sql; string s4 = "SELECT MaSV, MaLop, MaMon,HocKy,LanThi FROM Diem WHERE MaSV=N'" + GridViewDiem.CurrentRow.Cells["clmMaSV"].Value.ToString() + "'AND MaLop=N'" + cmbMaLop.SelectedValue + "'AND MaMon='" + cmbMonHoc.SelectedValue + "' and HocKy = '" + cmbHocKy.Text + "' and LanThi='" + (Convert.ToInt32(txtLanThi.Text.Trim()) + 1) + "'"; if (GridViewDiem.CurrentRow.Cells["clmDiem"].Value.ToString().Trim() == "") { MessageBox.Show("Bạn phải nhập điểm", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if ((Convert.ToDouble(GridViewDiem.CurrentRow.Cells["clmDiem"].Value.ToString().Trim()) > 10)) { MessageBox.Show("Bạn nhập sai điểm.Nhập lại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtDiem.Focus(); return; } string str = DAO.GetFieldValues("Select Diem from Diem where MaSV = '" + GridViewDiem.CurrentRow.Cells["clmMaSV"].Value.ToString() + "'and MaLop='" + cmbMaLop.SelectedValue + "' and HocKy = '" + cmbHocKy.Text + "' and MaMon='" + cmbMonHoc.SelectedValue + "' and LanThi='" + (Convert.ToInt32(txtLanThi.Text.Trim()) + 1) + "'"); if (str != "") { MessageBox.Show("Bạn không thể sửa vì sinh viên này đã thi lại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { int x = 0; if (Convert.ToDouble(GridViewDiem.CurrentRow.Cells["clmDiem"].Value) < Convert.ToInt32(GridViewDiem.CurrentRow.Cells["clmDiem"].Value)) { x = Convert.ToInt32(GridViewDiem.CurrentRow.Cells["clmDiem"].Value); } else if ((Convert.ToDouble(GridViewDiem.CurrentRow.Cells["clmDiem"].Value) - Convert.ToInt32(GridViewDiem.CurrentRow.Cells["clmDiem"].Value)) == 0.5) { x = Convert.ToInt32(GridViewDiem.CurrentRow.Cells["clmDiem"].Value) + 1; } else if ((Convert.ToDouble(GridViewDiem.CurrentRow.Cells["clmDiem"].Value) - Convert.ToInt32(GridViewDiem.CurrentRow.Cells["clmDiem"].Value)) < 0.5) { x = Convert.ToInt32(GridViewDiem.CurrentRow.Cells["clmDiem"].Value); } else if (Convert.ToDouble(GridViewDiem.CurrentRow.Cells["clmDiem"].Value) == Convert.ToInt32(GridViewDiem.CurrentRow.Cells["clmDiem"].Value)) { x = Convert.ToInt32(GridViewDiem.CurrentRow.Cells["clmDiem"].Value); } sql = "UPDATE Diem SET Diem = " + x + " WHERE MaSV=N'" + GridViewDiem.CurrentRow.Cells["clmMaSV"].Value.ToString() + "'AND MaLop=N'" + cmbMaLop.SelectedValue + "' and HocKy = '" + cmbHocKy.Text + "'AND MaMon='" + cmbMonHoc.SelectedValue + "' and LanThi='" + txtLanThi.Text.Trim() + "'"; DAO.RunSql(sql); txtDiem.Text = Convert.ToString(x); string str1 = "Select MaSV from Diem where MaSV = '" + GridViewDiem.CurrentRow.Cells["clmMaSV"].Value.ToString() + "'and MaLop='" + cmbMaLop.SelectedValue + "' and HocKy = '" + cmbHocKy.Text + "' and MaMon='" + cmbMonHoc.SelectedValue + "' and LanThi='" + (Convert.ToInt32(txtLanThi.Text.Trim()) + 1) + "'"; if (x >= 5 && DAO.CheckKeyExist(str1) == true) { MessageBox.Show("Sinh viên này không phải thi lại lần sau", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); string s0 = "DELETE Diem WHERE MaSV=N'" + GridViewDiem.CurrentRow.Cells["clmMaSV"].Value.ToString() + "'AND MaLop=N'" + cmbMaLop.SelectedValue + "'AND MaMon='" + cmbMonHoc.SelectedValue + "' and HocKy = '" + cmbHocKy.Text + "' and LanThi='" + (Convert.ToInt32(txtLanThi.Text.Trim()) + 1) + "'"; DAO.RunSql(s0); } else if (x < 5 && DAO.CheckKeyExist(s4) == true) { MessageBox.Show("Sinh viên này phải thi lại lần " + (Convert.ToInt32(txtLanThi.Text.Trim()) + 1), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (x < 5 && DAO.CheckKeyExist(s4) == false) { MessageBox.Show("Sinh viên này phải thi lại lần " + (Convert.ToInt32(txtLanThi.Text.Trim()) + 1), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); sql = "INSERT INTO Diem VALUES(N'" + GridViewDiem.CurrentRow.Cells["clmMaSV"].Value.ToString() + "',N'" + cmbMaLop.SelectedValue + "','" + cmbMonHoc.SelectedValue + "'," + cmbHocKy.Text + "," + (Convert.ToInt32(txtLanThi.Text.Trim()) + 1) + ",null)"; DAO.RunSql(sql); } btnDanhSach.Enabled = true; cmbMaLop.Enabled = true; txtLanThi.Enabled = true; cmbHocKy.Enabled = true; cmbMonHoc.Enabled = true; } DAO.CloseConnection(); Load_DataGridView(); btnLuu.Enabled = false; btnHuy.Enabled = false; btnSua.Enabled = false; btnDanhSach.Enabled = true; btnQuayLai.Enabled = true; }
private void btnLuu_Click(object sender, EventArgs e) { if (txtMaKhoa.Text == "") { MessageBox.Show("bạn chưa nhập mã khoa "); txtMaKhoa.Focus(); return; } if (txtTenKhoa.Text == "") { MessageBox.Show("bạn chưa nhập tên khoa"); txtTenKhoa.Focus(); return; } if (txtDienThoai.Text == "") { MessageBox.Show("bạn chưa nhập số điện thoại "); txtDienThoai.Focus(); return; } if (txtDiaChi.Text == "") { MessageBox.Show("bạn chưa nhập địa chỉ "); txtDiaChi.Focus(); return; } if (txtWebsite.Text == "") { MessageBox.Show("bạn chưa nhập website "); txtWebsite.Focus(); return; } string sqlCheckKey = "Select * from Khoa Where MaKhoa = '" + txtMaKhoa.Text.ToString() + "'"; DAO.OpenConnection(); if (DAO.CheckKeyExist(sqlCheckKey)) { MessageBox.Show("Mã khoa đã tồn tại", "thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); DAO.CloseConnection(); txtMaKhoa.Focus(); return; } else { string sql = "insert into Khoa values ('" + txtMaKhoa.Text.ToString() + "' , N'" + txtTenKhoa.Text.Trim() + "','" + txtDienThoai.Text.Trim() + "','" + txtDiaChi.Text.Trim() + "','" + txtWebsite.Text.Trim() + "')"; MessageBox.Show("oke"); SqlCommand cmd = new SqlCommand(sql, DAO.con); cmd.ExecuteNonQuery(); DAO.CloseConnection(); LoadDataToGrivew(); DAO.CloseConnection(); btnLuu.Enabled = false; //cmbMaKhoa.Enabled = false; } }
private void btnLuu_Click(object sender, EventArgs e) { DAO.OpenConnection(); string sql; if (cmbMaLop.SelectedIndex == -1) { MessageBox.Show("Bạn phải chọn mã lớp", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (cmbHocKy.SelectedIndex == -1) { MessageBox.Show("Bạn phải chọn học kỳ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (cmbMonHoc.SelectedIndex == -1) { MessageBox.Show("Bạn phải chọn môn học", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (txtLanThi.Text.Trim().Length == 0) { MessageBox.Show("Bạn phải nhập lần thi", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtLanThi.Focus(); return; } if (GridViewDiem.CurrentRow.Cells["clmMaSV"].Value.ToString().Trim() == "") { MessageBox.Show("Bạn phải nhập mã sinh viên", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } /*if (Convert.ToInt32(txtLanThi.Text.Trim()) > 1) * { * sql = "UPDATE Diem SET Diem = " + GridViewDiem.CurrentRow.Cells["clmDiem"].Value.ToString().Trim() + " WHERE MaSV=N'" + txtMaSV.Text.Trim() + "'AND MaLop=N'" + cmbMaLop.SelectedValue + "'AND MaMon='" + cmbMonHoc.SelectedValue + "' and LanThi='" + txtLanThi.Text.Trim() + "'"; * //MessageBox.Show(sql); * DAO.RunSql(sql); * }*/ /*string s1 = DAO.GetFieldValues("Select MaSV from Diem where MaSV = '"+ GridViewDiem.Rows[(tblDiem.Rows.Count-1)].Cells["clmMaSV"].Value + "'"); * string s2 = DAO.GetFieldValues("Select MaSV from Diem where MaSV = '" + GridViewDiem.Rows[tblDiem.Rows.Count].Cells["clmMaSV"].Value + "'"); * string s3 = DAO.GetFieldValues("Select Diem from Diem where MaSV = '" + GridViewDiem.Rows[tblDiem.Rows.Count].Cells["clmMaSV"].Value + "'"); * string s4 = "SELECT MaSV, MaLop, MaMon,HocKy,LanThi FROM Diem WHERE MaSV=N'" + GridViewDiem.CurrentRow.Cells["clmMaSV"].Value.ToString() + "'AND MaLop=N'" + cmbMaLop.SelectedValue + "'AND MaMon='" + cmbMonHoc.SelectedValue + "' and HocKy = '" + cmbHocKy.Text + "' and LanThi='" + txtLanThi.Text.Trim() + "'"; * ////MessageBox.Show(1); * //MessageBox.Show(s2); * if (Convert.ToInt32(txtLanThi.Text.Trim()) == 1&&s1 !=""&&s2==""&&s3==""&& DAO.CheckKeyExist(s4) == true) * { * MessageBox.Show("Bạn phải nhập mã sinh viên", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); * return; * }*/ /*if(GridViewDiem.Rows[tblDiem.Rows.Count].ToString() == "") * { * MessageBox.Show("Bạn phải nhập mã sinh viên.....", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); * return; * }*/ if (Convert.ToInt32(txtLanThi.Text.Trim()) == 1) { sql = "SELECT MaSV, MaLop, MaMon,HocKy,LanThi FROM Diem WHERE MaSV=N'" + GridViewDiem.CurrentRow.Cells["clmMaSV"].Value.ToString() + "'AND MaLop=N'" + cmbMaLop.SelectedValue + "'AND MaMon='" + cmbMonHoc.SelectedValue + "' and HocKy = '" + cmbHocKy.Text + "' and LanThi='" + txtLanThi.Text.Trim() + "'"; //MessageBox.Show(sql); if (DAO.CheckKeyExist(sql) == true) { MessageBox.Show("Bạn đã nhập điểm cho sinh viên học lớp và môn này , bạn hãy nhập lại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtMaSV.Focus(); return; } } sql = "SELECT MaSV FROM SinhVien WHERE MaSV=N'" + GridViewDiem.CurrentRow.Cells["clmMaSV"].Value.ToString() + "'"; if (DAO.CheckKeyExist(sql) == false) { MessageBox.Show("Mã sinh viên không tồn tại , bạn phải nhập mã khác", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } /*if (GridViewDiem.CurrentRow.Cells["clmMaSV"].Value.ToString().Trim()=="") * { * MessageBox.Show("Bạn phải nhập mã sinh viên", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); * return; * }*/ if (GridViewDiem.CurrentRow.Cells["clmDiem"].Value.ToString().Trim() == "") { MessageBox.Show("Bạn phải nhập điểm", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if ((Convert.ToDouble(GridViewDiem.CurrentRow.Cells["clmDiem"].Value.ToString().Trim()) > 10)) { MessageBox.Show("Bạn nhập sai điểm.Nhập lại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtDiem.Focus(); return; } if (Convert.ToDouble(GridViewDiem.CurrentRow.Cells["clmDiem"].Value.ToString().Trim()) < 5) { MessageBox.Show("Sinh viên này phải thi lại lần " + (Convert.ToInt32(txtLanThi.Text.Trim()) + 1), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); sql = "INSERT INTO Diem VALUES(N'" + GridViewDiem.CurrentRow.Cells["clmMaSV"].Value.ToString() + "',N'" + cmbMaLop.Text + "','" + cmbMonHoc.SelectedValue + "'," + cmbHocKy.Text + "," + (Convert.ToInt32(txtLanThi.Text.Trim()) + 1) + ",null)"; //MessageBox.Show(sql); DAO.RunSql(sql); } string str = DAO.GetFieldValues("Select Diem from Diem where MaSV = '" + GridViewDiem.CurrentRow.Cells["clmMaSV"].Value.ToString() + "'and MaLop='" + cmbMaLop.SelectedValue + "' and HocKy = '" + cmbHocKy.Text + "' and MaMon='" + cmbMonHoc.SelectedValue + "' and LanThi='" + (Convert.ToInt32(txtLanThi.Text.Trim()) - 1) + "'"); //MessageBox.Show(str); if (Convert.ToInt32(txtLanThi.Text.Trim()) > 1 && Convert.ToInt32(str) < 5) { sql = "UPDATE Diem SET Diem = ROUND(" + GridViewDiem.CurrentRow.Cells["clmDiem"].Value.ToString() + ",1) WHERE MaSV=N'" + txtMaSV.Text.Trim() + "'AND MaLop=N'" + cmbMaLop.SelectedValue + "'AND MaMon='" + cmbMonHoc.SelectedValue + "' and LanThi='" + txtLanThi.Text.Trim() + "'"; //MessageBox.Show(sql); DAO.RunSql(sql); MessageBox.Show("Bạn đã thêm mới thành công ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); Load_DataGridView1(); txtMaSV.Text = ""; txtDiem.Text = ""; } else //sql = "INSERT INTO Diem VALUES(N'" + GridViewDiem.Rows[i].Cells["clmMaSV"].Value.ToString() + "',N'" + cmbMaLop.Text + "','" + cmbMonHoc.SelectedValue + "'," //+ cmbHocKy.Text + "," + txtLanThi.Text.Trim() + "," + GridViewDiem.Rows[i].Cells["clmDiem"].Value.ToString() + ")"; { sql = "INSERT INTO Diem VALUES(N'" + GridViewDiem.CurrentRow.Cells["clmMaSV"].Value.ToString() + "',N'" + cmbMaLop.Text + "','" + cmbMonHoc.SelectedValue + "'," + cmbHocKy.Text + "," + txtLanThi.Text.Trim() + ",ROUND(" + GridViewDiem.CurrentRow.Cells["clmDiem"].Value.ToString() + ",1))"; //MessageBox.Show(sql); DAO.RunSql(sql); MessageBox.Show("Bạn đã thêm mới thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); GridViewDiem.CurrentRow.Cells["clmDiem"].Value = Math.Round(Convert.ToDouble(GridViewDiem.CurrentRow.Cells["clmDiem"].Value), 1); Load_DataGridView1(); txtMaSV.Text = ""; txtDiem.Text = ""; } //txtDiem.Enabled = false; DAO.CloseConnection(); }