private void khChinhSuaDatChoBtn_Click(object sender, EventArgs e) { int count = datchoGridView_Huy.Rows.Count; if (count == 0) { if (MessageBox.Show("Bạn có muốn xóa luôn giao dịch không???", "Xác nhận", MessageBoxButtons.YesNo) == DialogResult.No) { return; } SqlCommand cmd1 = new SqlCommand("sp_XoaGiaoDich", Program.conn); //--****HUỶ MỘT GIAO DICH * ***-- //---1: lỗi giao dịch //-- 0: mã giao dịch không tồn tại //--1: giao dịch đã được kích hoạt nên không thể xoá //--2: lỗi trong quá trình xoá chi tiết giao dịch //-- 3: xoá giao dịch thành công cmd1.CommandType = CommandType.StoredProcedure; cmd1.Parameters.Add("@maGiaoDich", SqlDbType.Int).Value = KhachHangForm.id; cmd1.Parameters.Add("@ketQua", SqlDbType.Int).Direction = ParameterDirection.Output; cmd1.ExecuteNonQuery(); int rs1 = Convert.ToInt32(cmd1.Parameters["@ketQua"].Value); if (rs1 == -1) { MessageBox.Show("Đã xảy ra lỗi khi xóa giao dịch."); } else if (rs1 == 0) { MessageBox.Show("Giao dịch không tồn tại.Đăng xuất khỏi tài khoản"); khform.Close(); } else if (rs1 == 1) { MessageBox.Show("Giao dịch đã được kích hoạt nên không thể xóa."); } else if (rs1 == 2) { MessageBox.Show("Đã xảy ra lỗi trong quá trình xóa chi tiết giao dịch."); } else { MessageBox.Show("Xóa giao dịch thành công."); khform.Close(); } cmd1.Dispose(); } else { int idChiTietGiaoDich = Convert.ToInt32(datchoGridView_Huy.CurrentRow.Cells[0].Value.ToString()); // Stored Procedure // sp_XoaChiTietGiaoDich // @IdGiaoDich INT // @ketQua INT OUT try { SqlCommand cmd = new SqlCommand("sp_XoaChiTietGiaoDich", Program.conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@maChiTietGiaoDich", SqlDbType.Int).Value = idChiTietGiaoDich; cmd.Parameters.Add("@ketQua", SqlDbType.Int).Direction = ParameterDirection.Output; cmd.ExecuteNonQuery(); int rs = Convert.ToInt32(cmd.Parameters["@ketQua"].Value); if (rs == -1) { loadDanhSachDatCho(); MessageBox.Show("Đã xảy ra lỗi khi xóa."); } else if (rs == 0) { loadDanhSachDatCho(); MessageBox.Show("Không tồn tại chi tiết."); } else { loadDanhSachDatCho(); MessageBox.Show("Xóa thành công."); KhachHangForm.loadSoNguoiDaDatPhong(); if (datchoGridView_Huy.Rows.Count == 0) { if (MessageBox.Show("Bạn có muốn xóa luôn giao dịch không???", "Xác nhận", MessageBoxButtons.YesNo) == DialogResult.No) { return; } SqlCommand cmd1 = new SqlCommand("sp_XoaGiaoDich", Program.conn); //--****HUỶ MỘT GIAO DICH * ***-- //---1: lỗi giao dịch //-- 0: mã giao dịch không tồn tại //--1: giao dịch đã được kích hoạt nên không thể xoá //--2: lỗi trong quá trình xoá chi tiết giao dịch //-- 3: xoá giao dịch thành công cmd1.CommandType = CommandType.StoredProcedure; cmd1.Parameters.Add("@maGiaoDich", SqlDbType.Int).Value = KhachHangForm.id; cmd1.Parameters.Add("@ketQua", SqlDbType.Int).Direction = ParameterDirection.Output; cmd1.ExecuteNonQuery(); int rs1 = Convert.ToInt32(cmd1.Parameters["@ketQua"].Value); if (rs1 == -1) { MessageBox.Show("Đã xảy ra lỗi khi xóa giao dịch."); } else if (rs1 == 0) { MessageBox.Show("Giao dịch không tồn tại.Đăng xuất khỏi tài khoản"); khform.Close(); } else if (rs1 == 1) { MessageBox.Show("Giao dịch đã được kích hoạt nên không thể xóa."); } else if (rs1 == 2) { MessageBox.Show("Đã xảy ra lỗi trong quá trình xóa chi tiết giao dịch."); } else { MessageBox.Show("Xóa giao dịch thành công."); khform.Close(); } cmd1.Dispose(); } } cmd.Dispose(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } }