crud de productos completado
This commit is contained in:
Generated
+47
@@ -0,0 +1,47 @@
|
||||
namespace compabetov2.admin
|
||||
{
|
||||
partial class Variantes
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// Variantes
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 697);
|
||||
this.Name = "Variantes";
|
||||
this.Text = "Variantes";
|
||||
this.Load += new System.EventHandler(this.Variantes_Load);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace compabetov2.admin
|
||||
{
|
||||
public partial class Variantes : Form
|
||||
{
|
||||
private crud ventanaPadre;
|
||||
public Variantes(crud ventanaPadre)
|
||||
{
|
||||
this.ventanaPadre = ventanaPadre;
|
||||
InitializeComponent();
|
||||
|
||||
}
|
||||
|
||||
private void Variantes_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
Generated
+15
-12
@@ -28,7 +28,7 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.button1 = new System.Windows.Forms.Button();
|
||||
this.btnSubir = new System.Windows.Forms.Button();
|
||||
this.pictureBox2 = new System.Windows.Forms.PictureBox();
|
||||
this.pictureBox1 = new System.Windows.Forms.PictureBox();
|
||||
this.lbImg = new System.Windows.Forms.Label();
|
||||
@@ -40,16 +40,17 @@
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// button1
|
||||
// btnSubir
|
||||
//
|
||||
this.button1.Font = new System.Drawing.Font("Microsoft Sans Serif", 10.2F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.button1.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
|
||||
this.button1.Location = new System.Drawing.Point(243, 312);
|
||||
this.button1.Name = "button1";
|
||||
this.button1.Size = new System.Drawing.Size(103, 46);
|
||||
this.button1.TabIndex = 38;
|
||||
this.button1.Text = "Subir";
|
||||
this.button1.UseVisualStyleBackColor = true;
|
||||
this.btnSubir.Font = new System.Drawing.Font("Microsoft Sans Serif", 10.2F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.btnSubir.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
|
||||
this.btnSubir.Location = new System.Drawing.Point(243, 312);
|
||||
this.btnSubir.Name = "btnSubir";
|
||||
this.btnSubir.Size = new System.Drawing.Size(103, 46);
|
||||
this.btnSubir.TabIndex = 38;
|
||||
this.btnSubir.Text = "Subir";
|
||||
this.btnSubir.UseVisualStyleBackColor = true;
|
||||
this.btnSubir.Click += new System.EventHandler(this.button1_Click);
|
||||
//
|
||||
// pictureBox2
|
||||
//
|
||||
@@ -61,6 +62,7 @@
|
||||
this.pictureBox2.Size = new System.Drawing.Size(100, 69);
|
||||
this.pictureBox2.TabIndex = 37;
|
||||
this.pictureBox2.TabStop = false;
|
||||
this.pictureBox2.Click += new System.EventHandler(this.pictureBox2_Click);
|
||||
//
|
||||
// pictureBox1
|
||||
//
|
||||
@@ -72,6 +74,7 @@
|
||||
this.pictureBox1.Size = new System.Drawing.Size(100, 69);
|
||||
this.pictureBox1.TabIndex = 36;
|
||||
this.pictureBox1.TabStop = false;
|
||||
this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click);
|
||||
//
|
||||
// lbImg
|
||||
//
|
||||
@@ -139,7 +142,7 @@
|
||||
this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.ClientSize = new System.Drawing.Size(897, 575);
|
||||
this.ControlBox = false;
|
||||
this.Controls.Add(this.button1);
|
||||
this.Controls.Add(this.btnSubir);
|
||||
this.Controls.Add(this.pictureBox2);
|
||||
this.Controls.Add(this.pictureBox1);
|
||||
this.Controls.Add(this.lbImg);
|
||||
@@ -161,7 +164,7 @@
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.Button button1;
|
||||
private System.Windows.Forms.Button btnSubir;
|
||||
private System.Windows.Forms.PictureBox pictureBox2;
|
||||
private System.Windows.Forms.PictureBox pictureBox1;
|
||||
private System.Windows.Forms.Label lbImg;
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
using System;
|
||||
using compabetov2.database;
|
||||
using compabetov2.database.modelos;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -12,9 +15,61 @@ namespace compabetov2.admin
|
||||
{
|
||||
public partial class agregarproducto : Form
|
||||
{
|
||||
public agregarproducto()
|
||||
private crud ventanaPadre;
|
||||
private string imagePath;
|
||||
public agregarproducto(crud ventanaPadre)
|
||||
{
|
||||
this.ventanaPadre = ventanaPadre;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void pictureBox2_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
string nombre = txtNombre.Text;
|
||||
decimal precio = decimal.Parse(txtPrecio.Text);
|
||||
//valida que se haya colocado alguna imagen
|
||||
if (!imagePath.Equals("")) {
|
||||
Producto producto = new Producto(-1, nombre, "", precio, imagePath, 0);
|
||||
if (service.insertarProducto(producto))
|
||||
{
|
||||
string destinationFolder = Path.Combine(Application.StartupPath, "Resources");
|
||||
string destinationFile = Path.Combine(destinationFolder, Path.GetFileName(imagePath));
|
||||
File.Copy(imagePath, destinationFile, true);
|
||||
|
||||
Close();
|
||||
ventanaPadre.llenarLayout();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Por favor seleccione alguna imagen", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
}
|
||||
catch {
|
||||
MessageBox.Show("Por favor introduzca un precio valido", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
OpenFileDialog openFileDialog1 = new OpenFileDialog();
|
||||
|
||||
openFileDialog1.Filter = "Archivos de imagen (*.jpg, *.jpeg, *.png, *.bmp)|*.jpg;*.jpeg;*.png;*.bmp";
|
||||
openFileDialog1.Title = "Seleccionar imagen";
|
||||
|
||||
if (openFileDialog1.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
imagePath = openFileDialog1.FileName;
|
||||
lbImg.Text = $"Imagen: {Path.GetFileName(imagePath)}";
|
||||
}
|
||||
}
|
||||
|
||||
private void pictureBox1_Click(object sender, EventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+1
@@ -169,6 +169,7 @@
|
||||
this.btnAgregar.TabIndex = 15;
|
||||
this.btnAgregar.Text = "Agregar";
|
||||
this.btnAgregar.UseVisualStyleBackColor = true;
|
||||
this.btnAgregar.Click += new System.EventHandler(this.btnAgregar_Click);
|
||||
//
|
||||
// crud
|
||||
//
|
||||
|
||||
+46
-4
@@ -24,9 +24,12 @@ namespace compabetov2.admin
|
||||
llenarLayout();
|
||||
}
|
||||
|
||||
private void llenarLayout()
|
||||
public void llenarLayout()
|
||||
{
|
||||
AdminPanel.Controls.Clear();
|
||||
productos.Clear();
|
||||
productos = service.conseguirProductos();
|
||||
|
||||
|
||||
foreach (Producto producto in productos)
|
||||
{
|
||||
@@ -107,6 +110,9 @@ namespace compabetov2.admin
|
||||
btnVariante.Dock = DockStyle.Fill;
|
||||
btnVariante.Click += new EventHandler(delegate (object sender, EventArgs e)
|
||||
{
|
||||
Variantes variantes = new Variantes(this);
|
||||
variantes.Owner = this;
|
||||
variantes.Show();
|
||||
});
|
||||
|
||||
Button btnEliminar = new Button();
|
||||
@@ -119,7 +125,37 @@ namespace compabetov2.admin
|
||||
btnEliminar.Dock = DockStyle.Fill;
|
||||
btnEliminar.Click += new EventHandler(delegate (object sender, EventArgs e)
|
||||
{
|
||||
|
||||
DialogResult result = MessageBox.Show($"¿Está seguro de que desea eliminar el producto {producto.nombre}?",
|
||||
"Confirmación", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
||||
if (result == DialogResult.Yes)
|
||||
{
|
||||
if (service.eliminarProducto(producto))
|
||||
{
|
||||
//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();
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -131,13 +167,12 @@ namespace compabetov2.admin
|
||||
agregarPanel.Controls.Add(btnVariante, 1, 0);
|
||||
agregarPanel.Controls.Add(btnEliminar, 2, 0);
|
||||
|
||||
|
||||
filaLayout.Controls.Add(informacionProducto, 0, 0);
|
||||
filaLayout.Controls.Add(agregarPanel, 1, 0);
|
||||
AdminPanel.Controls.Add(filaLayout);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void crud_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
@@ -169,5 +204,12 @@ namespace compabetov2.admin
|
||||
menuprincipalForm.BringToFront();
|
||||
}
|
||||
}
|
||||
|
||||
private void btnAgregar_Click(object sender, EventArgs e)
|
||||
{
|
||||
agregarproducto agregarproducto = new agregarproducto(this);
|
||||
agregarproducto.Owner = this;
|
||||
agregarproducto.Show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+53
-2
@@ -1,4 +1,5 @@
|
||||
using compabetov2.database.modelos;
|
||||
using compabetov2.database;
|
||||
using compabetov2.database.modelos;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@@ -59,7 +60,57 @@ namespace compabetov2.admin
|
||||
{
|
||||
try {
|
||||
decimal precio = decimal.Parse(txtPrecio.Text);
|
||||
}catch(Exception ex)
|
||||
string nombre = txtNombre.Text;
|
||||
//en caso de que descida cambiar la imagen
|
||||
if (!imagePath.Equals(""))
|
||||
{
|
||||
Producto productoNuevo = new Producto(producto.idProducto, nombre, "", precio, imagePath, 0);
|
||||
if (service.editarProducto(productoNuevo))
|
||||
{
|
||||
//guardar imagen nueva
|
||||
string destinationFolder = Path.Combine(Application.StartupPath, "Resources");
|
||||
string destinationFile = Path.Combine(destinationFolder, Path.GetFileName(imagePath));
|
||||
File.Copy(imagePath, destinationFile, true);
|
||||
|
||||
ventanaPadre.llenarLayout();
|
||||
|
||||
|
||||
//eliminar imagen antigua
|
||||
string imagenEliminada = Path.Combine(destinationFolder, producto.img);
|
||||
//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);
|
||||
}
|
||||
};
|
||||
|
||||
Close();
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// si la imagen no es modificada
|
||||
Producto productoNuevo = new Producto(producto.idProducto, nombre, "", precio, producto.img, 0);
|
||||
if (service.editarProducto(productoNuevo))
|
||||
{
|
||||
ventanaPadre.llenarLayout();
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
MessageBox.Show("Por favor introduzca un precio valido", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user