private void btnXoa_Click(object sender, EventArgs e) { BLPTP = new BLPhieuNhanPhong(); try { DialogResult DL = MessageBox.Show("Bạn có muốn xóa mẫu tin này?", "xác nhận", MessageBoxButtons.YesNoCancel); if (DL == DialogResult.Yes) { int r = dgvPTP.CurrentCell.RowIndex; if (BLPTP.XoaPhieuThuePhong(ref err, this.txtPTP.Text)) { LoadData(); MessageBox.Show("Đã xóa xong"); IsThuePhong = 0; IsXoaPTP = 1; } else { MessageBox.Show(err, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } catch { MessageBox.Show("Lỗi rồi"); } }
private void LoadData() { LoadMAKH(); try { BLPTP = new BLPhieuNhanPhong(); DTPTP = new DataTable(); DTPTP.Clear(); DataSet ds = BLPTP.ThongTinPhieuThuePhong(MaPhong); DTPTP = ds.Tables[0]; // Đưa dữ liệu lên DataGridView dgvPTP.DataSource = DTPTP; Default_txt(); Default_Button(); dgvPTP_CellClick(null, null); } catch (SqlException) { } }
private void dgvPTP_CellClick(object sender, DataGridViewCellEventArgs e) { BLPTP = new BLPhieuNhanPhong(); try { int r = dgvPTP.CurrentCell.RowIndex; this.txtPDP.Text = dgvPTP.Rows[r].Cells[1].Value.ToString().Trim(); this.txtPTP.Text = dgvPTP.Rows[r].Cells[0].Value.ToString().Trim(); this.cbbMaKH.Text = dgvPTP.Rows[r].Cells[2].Value.ToString().Trim(); this.txtTenKH.Text = dgvPTP.Rows[r].Cells[3].Value.ToString().Trim(); this.txtMaPhong.Text = dgvPTP.Rows[r].Cells[4].Value.ToString().Trim(); this.dtNgayTraDK.Value = (DateTime)dgvPTP.Rows[r].Cells[6].Value; } catch { this.txtPTP.Text = ""; this.txtPDP.Text = ""; this.cbbMaKH.Text = ""; this.txtTenKH.Text = ""; this.txtMaPhong.Text = ""; } }
private void btnLuu_Click(object sender, EventArgs e) { BLPTP = new BLPhieuNhanPhong(); if (Them) { var TTHopLe = BLPTP.KiemTraThemPTP(txtPDP.Text, cbbMaKH.Text); if (TTHopLe.Equals(true)) { try { BLPTP = new BLPhieuNhanPhong(); if (BLPTP.ThemPTP(this.txtPDP.Text, this.cbbMaKH.Text, this.MaPhong, this.dtNgayTraDK.Value, ref err)) { LoadData(); MessageBox.Show("Đã thêm xong!"); Default_Button(); IsThuePhong = 1; IsXoaPTP = 0; } else { MessageBox.Show(err, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); BLPTP = new BLPhieuNhanPhong(); BLPTP.XoaPhieuKhongCoCTPTP(ref err); } } catch (SqlException) { MessageBox.Show("Không thêm được. Lỗi rồi!"); } } else { MessageBox.Show("Mã PDP và Mã KH chưa trùng khớp", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { var TTHopLe = BLPTP.KiemTraThemPTP(txtPDP.Text, cbbMaKH.Text); if (TTHopLe.Equals(true) || (this.txtPDP.Text == DTPTP.Rows[0].ItemArray[1].ToString() && this.cbbMaKH.Text == DTPTP.Rows[0].ItemArray[2].ToString())) { try { BLPTP = new BLPhieuNhanPhong(); if (BLPTP.CapNhatPhieuThuePhong(this.txtPTP.Text, this.txtPDP.Text, this.cbbMaKH.Text, dtNgayTraDK.Value, ref err)) { LoadData(); MessageBox.Show("Đã sửa xong!"); Default_Button(); } else { MessageBox.Show(this.err); } } catch (SqlException) { MessageBox.Show("Không sửa được. Lỗi rồi!"); } } else { MessageBox.Show("Mã PDP và Mã KH chưa trùng khớp", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }