private void btnXoa_Click(object sender, EventArgs e) { int i = -1; string s = ""; if (radioBtnPN.Checked) { try { PhieuNhap ob = new PhieuNhap(txtMa.Text, cbxMaNV.SelectedValue.ToString(), da_tiNgayNX.Value.ToString(), cbxMaDoiTac.SelectedValue.ToString(), cbxMaKho.SelectedValue.ToString()); i = pn.Delete(ob); } catch { s = "Dữ liệu đã nhập không phù hợp!\n Mời nhập lại!!"; } } else if (radioBtnPX.Checked) { try { PhieuXuat ob = new PhieuXuat(txtMa.Text, cbxMaNV.SelectedValue.ToString(), da_tiNgayNX.Value.ToString(), cbxMaDoiTac.SelectedValue.ToString(), cbxMaKho.SelectedValue.ToString()); i = px.Delete(ob); } catch { s = "Dữ liệu đã nhập không phù hợp!\n Mời nhập lại!!"; } } switch (i) { case -2: s = "Lỗi kết nối!!"; break; case 1: s = "Xóa thành công!!"; btnLoad_Click(sender, e); break; case 2: s = "Không thể xóa dữ liệu!!\n Mã phiếu này không tồn tại!!"; break; case 3: s = "Không thể xóa do mã phiếu này có giao dịch các mặt hàng!!\n Hãy xóa chi tiết phiếu!"; break; case 0: s = "Lỗi!! Không thể xóa dữ liệu!!"; break; } MessageBox.Show(s, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); }
private void btnDelete_Click(object sender, RoutedEventArgs e) { MessageBoxResult result = MessageBox.Show("Bạn có muốn xóa dòng này?", "Confirmation", MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { if (dgvStockImport.SelectedItem != null) { DTO_PhieuNhap obj = new DTO_PhieuNhap(); obj = dgvStockImport.SelectedItem as DTO_PhieuNhap; String id = obj.MaPhieuNhap; BUS_PhieuNhap.Delete(id); dgvStockImport.ItemsSource = BUS_PhieuNhap.showData(); } } }