private void toolStripXoa_Click(object sender, EventArgs e) { M_PhieuNoBLL phieuno = new M_PhieuNoBLL(); foreach (DataGridViewRow item in this.datagridviewPhieuBan.SelectedRows) { int x = phieuno.GetSLPhieuNo((int)item.Cells["SoPhieuBan"].Value); if (x > 1) //k cho xoa { MessageBox.Show("Không thể xóa phiếu bán này. Đã tồn tại nhiều phiếu nợ. Kiểm tra và xóa phiếu nợ rồi thử lại"); return; } else // cho xoa { if (x == 1) // nếu có phiếu nợ thì cần xóa chứ { if (MessageBox.Show("Có 1 phiếu nợ của phiếu bán này, Vẫn xóa ?", "Cảnh báo", MessageBoxButtons.OKCancel) == DialogResult.OK) { phieuno.DeletebyPhieuBan((int)item.Cells["SoPhieuBan"].Value); } else { return; } } p.Delete((int)item.Cells["SoPhieuBan"].Value); datagridviewPhieuBan.Rows.Remove(item); } } }
private void M_PhieuBanHanhEdit_FormClosing(object sender, FormClosingEventArgs e) { if (this.DialogResult != DialogResult.OK && Edit == 0)// k luu thi xoa cai moi tao di { PhieuBan.Delete(int.Parse(txtSPhieu.Text)); } }