private void btnXoa_Click(object sender, EventArgs e) { QuanLiGiangDay quanli = new QuanLiGiangDay(); DataGridViewRow dgr = dgvQuanLiGiangDay.CurrentRow; if (dgr == null) { MessageBox.Show("Chọn bản ghi cần xóa!"); } else { DialogResult res = MessageBox.Show("Bản ghi này sẽ bị xóa!", "Cảnh báo", MessageBoxButtons.YesNo); if (res == DialogResult.Yes) { quanli.MaGiaoVien = dgr.Cells["magiaovien"].Value.ToString(); quanli.MaMonHoc = dgr.Cells["mamonhoc"].Value.ToString(); quanli.MaLop = dgr.Cells["tenlop"].Value.ToString(); quanli.TietHoc = dgr.Cells["tiethoc"].Value.ToString(); quanli.DiaDiem = dgr.Cells["diadiem"].Value.ToString(); quanli.NgayBatDau = DateTime.Parse(dgr.Cells["ngaybatdau"].Value.ToString()); quanli.NgayKetThuc = DateTime.Parse(dgr.Cells["ngayketthuc"].Value.ToString()); if (ql.Delete(quanli.MaGiaoVien, quanli.MaMonHoc, quanli.MaLop)) { MessageBox.Show("Xóa thành công!"); GetThongTinGiangDay(); } else { MessageBox.Show("Lỗi!"); } } } }
private void btnThem_Click(object sender, EventArgs e) { QuanLiGiangDay quanli = getQuanLiGiangDay(); if (isupdate) { cmbTenGiaoVien.SelectedValue = quanli.MaGiaoVien; cmbMonHoc.SelectedValue = quanli.MaMonHoc; cmbTenLop.SelectedValue = quanli.MaLop; txtTietHoc.Text = quanli.TietHoc; txtDiaDiem.Text = quanli.DiaDiem; if (ql.Update(quanli)) { MessageBox.Show("Sửa thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Sửa thất bại", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } this.Close(); } else { if (ql.Insert(quanli)) { MessageBox.Show("Thêm thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Thêm thất bại", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } this.Close(); } }
public frmThemQuanLiGiangDay(QuanLiGiangDay ql, bool update) { quanli.MaGiaoVien = ql.MaGiaoVien; quanli.MaMonHoc = ql.MaMonHoc; quanli.MaLop = ql.MaLop; quanli.TietHoc = ql.TietHoc; quanli.DiaDiem = ql.DiaDiem; quanli.NgayBatDau = ql.NgayBatDau; quanli.NgayKetThuc = ql.NgayKetThuc; isupdate = update; InitializeComponent(); }
public QuanLiGiangDay getQuanLiGiangDay() { QuanLiGiangDay ql = new QuanLiGiangDay(); ql.MaGiaoVien = cmbTenGiaoVien.SelectedValue.ToString(); ql.MaMonHoc = cmbMonHoc.SelectedValue.ToString(); ql.MaLop = cmbTenLop.SelectedValue.ToString(); ql.NgayBatDau = datNgayBatDau.Value; ql.NgayKetThuc = datNgayKetThuc.Value; ql.TietHoc = txtTietHoc.Text; ql.DiaDiem = txtDiaDiem.Text; return(ql); }
public bool Insert(QuanLiGiangDay ql) { string sql = "if not exists(select * from QuanLiGiangDay where giaovienma = @giaovienma and monhocma = @monhocma and lopma = @lopma) insert into QuanLiGiangDay values(@giaovienma, @monhocma, @lopma, @ngaybatdau, @ngayketthuc, @tiethoc, @diadiem)"; Dictionary <string, object> parameters = new Dictionary <string, object>(); parameters.Add("@giaovienma", ql.MaGiaoVien); parameters.Add("@monhocma", ql.MaMonHoc); parameters.Add("@lopma", ql.MaLop); parameters.Add("@ngaybatdau", ql.NgayBatDau); parameters.Add("@ngayketthuc", ql.NgayKetThuc); parameters.Add("@tiethoc", ql.TietHoc); parameters.Add("@diadiem", ql.DiaDiem); return(con.InsertUpdateDelete(sql, false, parameters)); }
public bool Update(QuanLiGiangDay ql) { string sql = "update QuanLiGiangDay set giaovienma = @giaovienma, monhocma = @monhocma, lopma = @lopma, ngaybatdau=@ngaybatdau, ngayketthuc=@ngayketthuc, tiethoc=@tiethoc, diadiem=@diadiem where giaovienma = @giaovienma and monhocma = @monhocma and lopma = @lopma"; Dictionary <string, object> parameters = new Dictionary <string, object>(); parameters.Add("@giaovienma", ql.MaGiaoVien); parameters.Add("@monhocma", ql.MaMonHoc); parameters.Add("@lopma", ql.MaLop); parameters.Add("@ngaybatdau", ql.NgayBatDau); parameters.Add("@ngayketthuc", ql.NgayKetThuc); parameters.Add("@tiethoc", ql.TietHoc); parameters.Add("@diadiem", ql.DiaDiem); return(con.InsertUpdateDelete(sql, false, parameters)); }
private void btnChinhSua_Click(object sender, EventArgs e) { DataGridViewRow dgr = dgvQuanLiGiangDay.CurrentRow; if (dgvQuanLiGiangDay.SelectedRows.Count <= 0) { MessageBox.Show("Chọn bản ghi cần sửa!"); } else { QuanLiGiangDay ql = new QuanLiGiangDay(); ql.MaGiaoVien = dgr.Cells["magiaovien"].Value.ToString(); ql.MaMonHoc = dgr.Cells["mamonhoc"].Value.ToString(); ql.MaLop = dgr.Cells["tenlop"].Value.ToString(); ql.TietHoc = dgr.Cells["tiethoc"].Value.ToString(); ql.DiaDiem = dgr.Cells["diadiem"].Value.ToString(); ql.NgayBatDau = DateTime.Parse(dgr.Cells["ngaybatdau"].Value.ToString()); ql.NgayKetThuc = DateTime.Parse(dgr.Cells["ngayketthuc"].Value.ToString()); frmThemQuanLiGiangDay frmThem = new frmThemQuanLiGiangDay(ql, true); frmThem.ShowDialog(); GetThongTinGiangDay(); } }