admin sin errores
This commit is contained in:
+27
-7
@@ -524,22 +524,42 @@ namespace compabetov2.database
|
||||
|
||||
public static bool eliminarProductoDAO(Producto producto)
|
||||
{
|
||||
|
||||
var db_conexion = new Conexion();
|
||||
|
||||
try
|
||||
{
|
||||
using (SQLiteConnection conexion = db_conexion.get_connection())
|
||||
{
|
||||
conexion.Open();
|
||||
|
||||
string sql = "DELETE FROM Producto WHERE idproducto = @idproducto";
|
||||
|
||||
using (SQLiteCommand command = new SQLiteCommand(sql, conexion))
|
||||
using (var transaccion = conexion.BeginTransaction())
|
||||
{
|
||||
command.Parameters.AddWithValue("@idproducto", producto.idProducto);
|
||||
int filasAfectadas = command.ExecuteNonQuery();
|
||||
try
|
||||
{
|
||||
string sql = "DELETE FROM Producto WHERE idproducto = @idproducto";
|
||||
string sqlVariante = "DELETE FROM variantes WHERE fk_producto=@fk_producto;";
|
||||
|
||||
SQLiteCommand commandProducto = new SQLiteCommand(sql, conexion);
|
||||
commandProducto.Parameters.AddWithValue("@idproducto", producto.idProducto);
|
||||
int filasAfectadas = commandProducto.ExecuteNonQuery();
|
||||
|
||||
SQLiteCommand commandVariante = new SQLiteCommand(sqlVariante, conexion);
|
||||
commandVariante.Parameters.AddWithValue("@fk_producto", producto.idProducto);
|
||||
commandVariante.ExecuteNonQuery();
|
||||
|
||||
transaccion.Commit();
|
||||
return true;
|
||||
|
||||
}
|
||||
catch (SQLiteException ex)
|
||||
{
|
||||
transaccion.Rollback();
|
||||
MessageBox.Show(ex.Message);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (filasAfectadas > 0) { return true; }
|
||||
else { return false; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user