crud de variante sin lo relacionado a editar

This commit is contained in:
Carlos Sandoval
2024-06-21 16:04:33 -06:00
parent ff714ef848
commit 68bcb453d1
15 changed files with 82 additions and 26 deletions
+2 -1
View File
@@ -40,6 +40,7 @@
this.VariantePanel.Name = "VariantePanel";
this.VariantePanel.Size = new System.Drawing.Size(1146, 516);
this.VariantePanel.TabIndex = 16;
this.VariantePanel.Paint += new System.Windows.Forms.PaintEventHandler(this.VariantePanel_Paint);
//
// btnAgregar
//
@@ -59,7 +60,7 @@
this.ClientSize = new System.Drawing.Size(1171, 587);
this.Controls.Add(this.btnAgregar);
this.Controls.Add(this.VariantePanel);
this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.Margin = new System.Windows.Forms.Padding(2);
this.Name = "Variantes";
this.Text = "Variantes";
this.Load += new System.EventHandler(this.Variantes_Load);
+6 -23
View File
@@ -113,31 +113,9 @@ namespace compabetov2.admin
"Confirmación", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
if (service.eliminarProducto(producto))
if (service.eliminarVariante(variante.idVariante))
{
//eliminar imagen antigua
string destinationFolder = Path.Combine(Application.StartupPath, "Resources");
string imagenEliminada = Path.Combine(destinationFolder, producto.img);
llenarLayout();
//se pone a esperar 1 segundo antes de eliminar la imagen
//esto para que al programa le de tiempo de dejar de utilizar la imagen y no lance una excepcion
Timer timer = new Timer();
timer.Interval = 1000; // 1 segundos
timer.Tick += delegate (object sender2, EventArgs e2)
{
try
{
File.Delete(imagenEliminada);
timer.Stop();
}
catch (Exception ex)
{
// Manejar la excepción de eliminación de archivo temporal
Console.WriteLine("Error al eliminar archivo temporal: " + ex.Message);
}
};
timer.Start();
}
}
});
@@ -167,5 +145,10 @@ namespace compabetov2.admin
ventana.Owner = this;
ventana.Show();
}
private void VariantePanel_Paint(object sender, PaintEventArgs e)
{
}
}
}
+8 -1
View File
@@ -1,4 +1,5 @@
using compabetov2.database.modelos;
using compabetov2.database;
using compabetov2.database.modelos;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@@ -41,6 +42,12 @@ namespace compabetov2.admin
producto.idProducto,
Decimal.Parse(txtPrecioCompra.Text)
);
if (service.insertarVariante(NuevaVariante))
{
Close();
ventanaPadre.llenarLayout();
}
}
}
+1 -1
View File
@@ -16,7 +16,7 @@ namespace compabetov2.admin
public partial class agregarproducto : Form
{
private crud ventanaPadre;
private string imagePath;
private string imagePath = "";
public agregarproducto(crud ventanaPadre)
{
this.ventanaPadre = ventanaPadre;
Binary file not shown.

After

Width:  |  Height:  |  Size: 506 KiB

Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 506 KiB

+55
View File
@@ -10,6 +10,7 @@ using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using compabetov2.admin;
using compabetov2.database;
using compabetov2.database.modelos;
@@ -1807,6 +1808,60 @@ namespace compabetov2.database
}
}
public static bool insertarVarianteDAO(Variante variante)
{
var db_conexion = new Conexion();
try
{
SQLiteConnection conexion = db_conexion.get_connection();
conexion.Open();
string sql = "INSERT INTO variantes (nombre, precio, cantidad, img, fk_producto, precioCompra) " +
"VALUES(@nombre, @precio, @cantidad, @img, @fk_producto, @precioCompra);";
SQLiteCommand command = new SQLiteCommand(sql, conexion);
command.Parameters.AddWithValue("@nombre", variante.nombre);
command.Parameters.AddWithValue("@precio", variante.precio);
command.Parameters.AddWithValue("@cantidad", variante.cantidad);
command.Parameters.AddWithValue("@img", variante.img);
command.Parameters.AddWithValue("@fk_producto", variante.fkProducto);
command.Parameters.AddWithValue("@precioCompra", variante.precioCompra);
command.ExecuteNonQuery();
return true;
}
catch (SQLiteException ex)
{
MessageBox.Show(ex.Message);
return false;
}
}
public static bool eliminarVarianteDAO(int idVariante)
{
var db_conexion = new Conexion();
try
{
SQLiteConnection conexion = db_conexion.get_connection();
conexion.Open();
string sql = "DELETE FROM variantes WHERE idVariante = @idVariante;";
SQLiteCommand command = new SQLiteCommand(sql, conexion);
command.Parameters.AddWithValue("@idVariante", idVariante);
command.ExecuteNonQuery();
return true;
}
catch (SQLiteException ex)
{
MessageBox.Show(ex.Message);
return false;
}
}
public static SQLiteDataReader conseguirImportesDAO()
{
SQLiteDataReader reader = null;
+10
View File
@@ -603,6 +603,16 @@ namespace compabetov2.database
return variantes;
}
public static bool insertarVariante(Variante variante)
{
return DAO.insertarVarianteDAO(variante);
}
public static bool eliminarVariante(int idVariante)
{
return DAO.eliminarVarianteDAO(idVariante);
}
public static List<ImporteModel> conseguirImportes()
{
List<ImporteModel> importes = new List<ImporteModel>();
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.