Method e

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

<script>

function showConfirmationDialog(event, articleId) {


event.preventDefault(); // Empêche le comportement par défaut du lien
Swal.fire({
title: "Are you sure?",
text: "It will be deleted permanently",
icon: "warning",
showCancelButton: true,
confirmButtonColor: "#3085d6",
cancelButtonColor: "#d33",
confirmButtonText: "Yes, delete it!",
}).then((result) => {
if (result.isConfirmed) {
deleteArticle(articleId);
} else {
Swal.fire("Cancelled", "Your imaginary file is safe.",
"error");
}
});
}

function deleteArticle(articleId) {
$.ajax({
url: "/articles/" + articleId,
type: "DELETE",
success: function (response) {
Swal.fire("Deleted!", response.message,
response.status).then(() => {
window.location.reload(); // Recharger la page pour mettre
à jour l'affichage
});
},
error: function () {
Swal.fire("Oops...", "Something went wrong with ajax!",
"error");
}
});
}
</script>
public void deleteArticle(int articleId) {
String dburl = "jdbc:mysql://localhost:3306/Articles_Stock";
String dbusername = "root";
String dbpassword = "";
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(dburl, dbusername,
dbpassword);
PreparedStatement pstmt = null;
pstmt = con.prepareStatement("DELETE FROM Articles_Stock WHERE id=?");
pstmt.setInt(1, articleId);
int i = pstmt.executeUpdate();
Articles_Stock obj = new Articles_Stock();
if (i != 0) {
obj.setStatus("success");
obj.setMessage("Article Delete Successfully");
} else {
obj.setStatus("error");
obj.setMessage("Unable to delete article....");
}
con.close();
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
}

You might also like