private void btnSua_Click(object sender, EventArgs e) { //string GioiTinh; 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; if (txtTenSV.Text.Trim().Length == 0) { MessageBox.Show("Bạn phải nhập tên sinh viên", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); txtTenSV.Focus(); return; } if (cmbMaKhoa.Text.Trim().Length == 0) { MessageBox.Show("Bạn phải nhập khoa", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); cmbMaKhoa.Focus(); return; } if (cmbMaLop.Text.Trim().Length == 0) { MessageBox.Show("Bạn phải nhập lớp", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); cmbMaLop.Focus(); return; } if (cmbMaQue.Text.Trim().Length == 0) { MessageBox.Show("Bạn phải nhập quê", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); cmbMaQue.Focus(); return; } if (cmbMaDanToc.Text.Trim().Length == 0) { MessageBox.Show("Bạn phải nhập dân tôc", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); cmbMaDanToc.Focus(); return; } if (cmbMaChucVu.Text.Trim().Length == 0) { MessageBox.Show("Bạn phải nhập chức vụ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); cmbMaChucVu.Focus(); return; } if (cmbMaChuyenNganh.Text.Trim().Length == 0) { MessageBox.Show("Bạn phải nhập chuyên ngành", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); cmbMaChuyenNganh.Focus(); return; } if (mtbNgaySinh.Text == " / /") { MessageBox.Show("Bạn không để trống ngày sinh"); mtbNgaySinh.Focus(); 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ữ"; } sql = "UPDATE SinhVien SET TenSV=N'" + txtTenSV.Text.ToString() + "',MaKhoa='" + cmbMaKhoa.SelectedValue.ToString() + "',MaLop='" + cmbMaLop.SelectedValue.ToString() + "',NgaySinh='" + DAO.ConvertDateTime(mtbNgaySinh.Text) + "',GioiTinh=N'" + GioiTinh + "',MaQue='" + cmbMaQue.SelectedValue.ToString() + "',MaDanToc='" + cmbMaDanToc.SelectedValue.ToString() + "',MaChuyenNganh='" + cmbMaChuyenNganh.SelectedValue.ToString() + "',MaHDT='" + cmbMaHDT.SelectedValue.ToString() + "',MaChucVu='" + cmbMaChucVu.SelectedValue.ToString() + "' WHERE MaSV='" + txtMaSV.Text + "'"; //MessageBox.Show(sql); DAO.OpenConnection(); SqlCommand cmd = new SqlCommand(); cmd.CommandText = sql; cmd.Connection = DAO.con; cmd.ExecuteNonQuery();//thực thi câu lệnh DAO.CloseConnection(); LoadDatatogriview(); }
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 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 btnXoa_Click(object sender, EventArgs e) { 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); } 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); } 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; } string a2 = DAO.GetFieldValues("select count(*) from Diem where MaLop = '" + cmbLop.SelectedValue.ToString() + "' and MaMon='" + cmbMon.SelectedValue.ToString() + "' and HocKy=" + strHK + " and Diem>=0"); //MessageBox.Show(a2); if (Convert.ToInt32(a2) > 0) { 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) { string sql = "delete from Thoi_Khoa_Bieu where MaLop = '" + cmbLop.SelectedValue.ToString() + "' and MaMon='" + cmbMon.SelectedValue.ToString() + "' and HocKy=" + strHK + " and ThuHoc=N'" + strThu.ToString() + "' and CaHoc=" + strCa + " and MaPhong='" + cmbPhong.SelectedValue.ToString() + "' "; DAO.OpenConnection(); SqlCommand cmd = new SqlCommand(); cmd.CommandText = sql; cmd.Connection = DAO.con; cmd.ExecuteNonQuery(); DAO.CloseConnection(); LoadDataToGridView(); cmbLop.Enabled = false; cmbMon.Enabled = false; } } }
private void btnSua_Click(object sender, EventArgs e) { 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); } 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; } 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 (cmbLop.Text.Trim().Length == 0) { MessageBox.Show("Bạn chưa chọn bản ghi nào!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); cmbLop.Focus(); return; } if (cmbMon.Text.Trim().Length == 0) { MessageBox.Show("Bạn chưa chọn bản ghi nào!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); cmbMon.Focus(); return; } if (cmbPhong.Text.Trim().Length == 0) { MessageBox.Show("Bạn phải chọn Phòng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); cmbPhong.Focus(); return; } if (strHK == -1) { MessageBox.Show("Bạn phải chọn Học Kỳ!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (strCa == -1) { MessageBox.Show("Bạn phải chọn Ca học!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (strThu == "") { MessageBox.Show("Bạn phải chọn Thứ học!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string sql = "update Thoi_Khoa_Bieu set MaPhong = '" + cmbPhong.SelectedValue.ToString() + "', HocKy=" + strHK + ", ThuHoc=N'" + strThu.ToString() + "',CaHoc=" + strCa + " where id = " + txtid.Text + ""; DAO.OpenConnection(); SqlCommand cmd = new SqlCommand(); cmd.CommandText = sql; cmd.Connection = DAO.con; cmd.ExecuteNonQuery(); DAO.CloseConnection(); LoadDataToGridView(); cmbLop.Enabled = false; cmbMon.Enabled = false; btnHuy.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 btnSua_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; } if (txtTenSV.Text.Trim().Length == 0) { MessageBox.Show("Bạn phải nhập tên sinh viên", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); txtTenSV.Focus(); return; } if (cmbMaKhoa.Text.Trim().Length == 0) { MessageBox.Show("Bạn phải nhập khoa", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); cmbMaKhoa.Focus(); return; } if (cmbMaLop.Text.Trim().Length == 0) { MessageBox.Show("Bạn phải nhập lớp", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); cmbMaLop.Focus(); return; } if (cmbMaQue.Text.Trim().Length == 0) { MessageBox.Show("Bạn phải nhập quê", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); cmbMaQue.Focus(); return; } if (cmbMaDanToc.Text.Trim().Length == 0) { MessageBox.Show("Bạn phải nhập dân tôc", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); cmbMaDanToc.Focus(); return; } if (cmbMaChucVu.Text.Trim().Length == 0) { MessageBox.Show("Bạn phải nhập chức vụ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); cmbMaChucVu.Focus(); return; } if (cmbMaChuyenNganh.Text.Trim().Length == 0) { MessageBox.Show("Bạn phải nhập chuyên ngành", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); cmbMaChuyenNganh.Focus(); return; } if (mtbNgaySinh.Text == " / /") { MessageBox.Show("Bạn không để trống ngày sinh"); mtbNgaySinh.Focus(); 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ữ"; } sql = "UPDATE SinhVien SET TenSV=N'" + txtTenSV.Text.ToString() + "',MaKhoa='" + cmbMaKhoa.SelectedValue.ToString() + "',MaLop='" + cmbMaLop.SelectedValue.ToString() + "',NgaySinh='" + DAO.ConvertDateTime(mtbNgaySinh.Text) + "',GioiTinh=N'" + GioiTinh + "',MaQue='" + cmbMaQue.SelectedValue.ToString() + "',MaDanToc='" + cmbMaDanToc.SelectedValue.ToString() + "',MaChuyenNganh='" + cmbMaChuyenNganh.SelectedValue.ToString() + "',MaHDT='" + cmbMaHDT.SelectedValue.ToString() + "',MaChucVu='" + cmbMaChucVu.SelectedValue.ToString() + "' WHERE MaSV='" + txtMaSV.Text + "'"; string A = cmbMaLop.SelectedValue.ToString(); string B = Convert.ToString(DAO.GetFieldValues("select MaLop from SinhVien where MaSV='" + txtMaSV.Text + "'")); if (A != B) { int s1 = Convert.ToInt32(DAO.GetFieldValues("select SiSo from Lop where MaLop='" + A + "'")); String sql1 = " update Lop set SiSo = SiSo +1 WHERE MaLop = '" + A + "'"; DAO.RunSql(sql1); s1 = Convert.ToInt32(DAO.GetFieldValues(" select SiSo from Lop where MaLop = '" + A + "'")); MessageBox.Show(" Sĩ số sau khi cập nhật của lớp '" + A + "' là " + s1, " thông báo ", MessageBoxButtons.OK, MessageBoxIcon.Information); int s2 = Convert.ToInt32(DAO.GetFieldValues("select SiSo from Lop where MaLop='" + B + "'")); String sql2 = " update Lop set SiSo = SiSo -1 WHERE MaLop = '" + B + "'"; DAO.RunSql(sql2); s2 = Convert.ToInt32(DAO.GetFieldValues("select SiSo from Lop where MaLop='" + B + "'")); MessageBox.Show(" Sĩ số sau khi cập nhật của lớp '" + B + "' là " + s2, " thông báo ", MessageBoxButtons.OK, MessageBoxIcon.Information); } DAO.OpenConnection(); DAO.RunSql(sql); LoadDatatogriview1(); DAO.CloseConnection(); cmbMaLop.Enabled = true; cmbMaKhoa.Enabled = true; }
private void btnLuu_Click(object sender, EventArgs e) { DAO.OpenConnection(); string sql; for (int i = 0; i < tblDiem.Rows.Count; i++) { if ((GridViewDiem.Rows[i].Cells["clmDiem"].Value.ToString().Trim() != "") && (Convert.ToDouble(GridViewDiem.Rows[i].Cells["clmDiem"].Value) > 10)) { MessageBox.Show("Bạn nhập sai điểm.Nhập lại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); GridViewDiem.CurrentCell = GridViewDiem.Rows[i].Cells["clmDiem"]; return; } } for (int i = 0; i < tblDiem.Rows.Count; i++) { string ss = (DAO.GetFieldValues("Select Diem from Diem where MaSV = '" + GridViewDiem.Rows[i].Cells["clmMaSV"].Value.ToString() + "'and MaLop='" + cmbMaLop.SelectedValue + "' and HocKy = '" + cmbHocKy.Text + "' and MaMon='" + cmbMonHoc.SelectedValue + "' and LanThi='" + txtLanThi.Text.Trim() + "'")); if (Convert.ToString(GridViewDiem.Rows[i].Cells["clmDiem"].Value) != ss && ss == "") { int t = 0; if (Convert.ToDouble(GridViewDiem.Rows[i].Cells["clmDiem"].Value) < Convert.ToInt32(GridViewDiem.Rows[i].Cells["clmDiem"].Value)) { t = Convert.ToInt32(GridViewDiem.Rows[i].Cells["clmDiem"].Value); } else if ((Convert.ToDouble(GridViewDiem.Rows[i].Cells["clmDiem"].Value) - Convert.ToInt32(GridViewDiem.Rows[i].Cells["clmDiem"].Value)) == 0.5) { t = Convert.ToInt32(GridViewDiem.Rows[i].Cells["clmDiem"].Value) + 1; } else if ((Convert.ToDouble(GridViewDiem.Rows[i].Cells["clmDiem"].Value) - Convert.ToInt32(GridViewDiem.Rows[i].Cells["clmDiem"].Value)) < 0.5) { t = Convert.ToInt32(GridViewDiem.Rows[i].Cells["clmDiem"].Value); } else if (Convert.ToDouble(GridViewDiem.Rows[i].Cells["clmDiem"].Value) == Convert.ToInt32(GridViewDiem.Rows[i].Cells["clmDiem"].Value)) { t = Convert.ToInt32(GridViewDiem.Rows[i].Cells["clmDiem"].Value); } sql = "UPDATE Diem SET Diem = " + t + " WHERE MaSV=N'" + GridViewDiem.Rows[i].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); if (t < 5) { sql = "INSERT INTO Diem VALUES(N'" + GridViewDiem.Rows[i].Cells["clmMaSV"].Value.ToString() + "',N'" + cmbMaLop.SelectedValue + "','" + cmbMonHoc.SelectedValue + "'," + cmbHocKy.Text + "," + (Convert.ToInt32(txtLanThi.Text.Trim()) + 1) + ",null)"; DAO.RunSql(sql); } } } string a1 = (DAO.GetFieldValues("Select count(*) from Diem where MaLop='" + cmbMaLop.SelectedValue + "' and HocKy = '" + cmbHocKy.Text + "' and MaMon='" + cmbMonHoc.SelectedValue + "' and LanThi='" + txtLanThi.Text.Trim() + "' and diem<5")); if (Convert.ToInt32(a1) > 0) { MessageBox.Show("Lớp có " + Convert.ToInt32(a1) + " sinh viên phải thi lại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } Load_DataGridView(); btnDanhSach.Enabled = true; cmbMaLop.Enabled = true; txtLanThi.Enabled = true; cmbHocKy.Enabled = true; cmbMonHoc.Enabled = true; btnLuu.Enabled = false; btnHuy.Enabled = false; btnSua.Enabled = false; btnDanhSach.Enabled = true; btnQuayLai.Enabled = true; txtMaSV.Text = ""; txtDiem.Text = ""; DAO.CloseConnection(); }
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) { 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; } if (txtSiSo.Text.Trim() == "") { MessageBox.Show("Sĩ số không được để trống", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtSiSo.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() + "'," + txtSiSo.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; txtMaLop.Enabled = false; } }
private void FrmHeDaoTao_Load(object sender, EventArgs e) { DAO.OpenConnection(); Load_DataGridView(); DAO.CloseConnection(); }
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(); }