protected override void DeleteRow() { try { DeleteRowGrid(dgv_DanhSach, "ID", "TenPhong"); if (IdDelete.Count <= 0) return; foreach (var i in IdDelete) { var xp = new XepPhong { IdKyThi = _idkythi, IdPhong = i }; var ktp = new KTPhong { IdKyThi = _idkythi, IdPhong = i }; _listXepPhong.Add(xp); _listKtPhong.Add(ktp); } DeleteData.XoaKtPhong(_listKtPhong); UpdateData.UpdateXepPhongNull(_listXepPhong); MessageBox.Show(FormResource.MsgThongbaothanhcong, FormResource.MsgCaption, MessageBoxButtons.OK, MessageBoxIcon.Information); LoadGrid(); IdDelete.Clear(); } catch (Exception ex) { Log2File.LogExceptionToFile(ex); } }
/// <summary> /// Lưu 1 phòng được sử dụng trong kỳ thi /// </summary> /// <param name="item"></param> /// <returns></returns> public static bool KtPhong(KTPhong item) { try { Conn.ExcuteQuerySql("insert into KT_PHONG(IdKyThi,IdPhong,SiSo) values(" + item.IdKyThi + "," + item.IdPhong + "," + item.SiSo + ")"); return true; } catch (Exception ex) { Log2File.LogExceptionToFile(ex); return false; } }
private void button2_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(cboPhongthi.Text)) { errorPhongthi.SetError(cboPhongthi, "Chọn Phòng thi"); return; } if (bUpdate) { var hs = new XepPhong { IdSV = int.Parse(txtmasinhvien.Text), IdPhong = int.Parse(cboPhongthi.Value.ToString()), IdKyThi = IdKythi }; UpdateData.UpdateXepPhong(hs); UpdateData.UpdateKtPhong(hs.IdPhong, IdPhong, IdKythi); bUpdate = false; Close(); } else { var a = cboPhongthi.Value; if (a == null) return; var hsxp = new XepPhong { IdKyThi = IdKythi, IdPhong = (int)a, IdSV = int.Parse(txtmasinhvien.Text), }; var hspp = new KTPhong { IdKyThi = IdKythi, IdPhong = (int)a, SiSo = 1 }; UpdateData.UpdateXepPhong(hsxp); UpdateData.UpdateTangSiSo(hspp.IdPhong, hspp.IdKyThi); bUpdate = true; Close(); } }
protected override void DeleteRow() { try { bool xoa = false; if (dgv_DanhSach.Selected.Rows.Count > 0) { if (DialogResult.Yes == MessageBox.Show(FormResource.msgHoixoa, FormResource.MsgCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Question)) { foreach (var row in dgv_DanhSach.Selected.Rows) { var masv = row.Cells["MaSV"].Text; var idPhong = row.Cells["IdPhong"].Text; if (!string.IsNullOrEmpty(idPhong)) { var ktp = new KTPhong { IdKyThi = _idkythi, IdPhong = int.Parse(idPhong) }; _listKtPhong.Add(ktp); } var xp = new XepPhong { IdKyThi = _idkythi, IdSV = int.Parse(masv) }; _listXepPhong.Add(xp); } DeleteAndUpdate = true; dgv_DanhSach.DeleteSelectedRows(false); xoa = true; } } else if (dgv_DanhSach.ActiveRow != null) { if (DialogResult.Yes == MessageBox.Show(FormResource.msgHoixoa, FormResource.MsgCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Question)) { var masv = dgv_DanhSach.ActiveRow.Cells["MaSV"].Text; var idPhong = dgv_DanhSach.ActiveRow.Cells["IdPhong"].Text; if (!string.IsNullOrEmpty(idPhong)) { var ktp = new KTPhong { IdKyThi = _idkythi, IdPhong = int.Parse(idPhong) }; _listKtPhong.Add(ktp); } var xp = new XepPhong { IdKyThi = _idkythi, IdSV = int.Parse(masv) }; _listXepPhong.Add(xp); DeleteAndUpdate = true; dgv_DanhSach.ActiveRow.Delete(false); xoa = true; } } UpdateData.UpdateGiamSiSo(_listKtPhong); DeleteData.XoaXepPhong(_listXepPhong); if (xoa) { MessageBox.Show(@"Xóa dữ liệu thành công.", @"Thông báo"); } LoadGrid(); } catch (Exception ex) { Log2File.LogExceptionToFile(ex); } }
/// <summary> /// sửa lại SiSo trong bảng KT_PHONG khi xếp phòng xong /// </summary> /// <param name="item"></param> /// <returns></returns> private static void UpdateKtPhong(KTPhong item) { try { Conn.ExcuteQuerySql("update KT_PHONG set SiSo = " + item.SiSo + " where IdPhong = " + item.IdPhong + " and IdKyThi =" + item.IdKyThi + ""); } catch (Exception ex) { Log2File.LogExceptionToFile(ex); } }
/// <summary> /// xóa bảng KT_PHONG theo kỳ thi và mã phòng /// </summary> private static void XoaKtPhong(KTPhong item) { try { Conn.ExcuteQuerySql("DELETE FROM KT_PHONG WHERE IdKyThi = " + item.IdKyThi + " and IdPhong = " + item.IdPhong + ""); } catch (Exception ex) { Log2File.LogExceptionToFile(ex); } }