Files
compabetoOG/admin/Variantes.cs
T

157 lines
6.2 KiB
C#

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;
using System.Windows.Forms;
namespace compabetov2.admin
{
public partial class Variantes : Form
{
private crud ventanaPadre;
private Producto producto;
private List<Variante> variantes = new List<Variante>();
public Variantes(crud ventanaPadre, Producto producto)
{
this.ventanaPadre = ventanaPadre;
this.producto = producto;
InitializeComponent();
llenarLayout();
}
public void llenarLayout()
{
VariantePanel.Controls.Clear();
variantes.Clear();
variantes = service.conseguirVariante(producto.idProducto);
foreach (Variante variante in variantes)
{
TableLayoutPanel filaLayout = new TableLayoutPanel();
filaLayout.RowCount = 1;
filaLayout.ColumnCount = 2;
filaLayout.Height = 100;
filaLayout.Width = 1115;
filaLayout.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
filaLayout.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
filaLayout.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
TableLayoutPanel informacionProducto = new TableLayoutPanel();
informacionProducto.RowCount = 1;
informacionProducto.ColumnCount = 2;
informacionProducto.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 20F));
informacionProducto.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 80F));
informacionProducto.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
informacionProducto.Dock = DockStyle.Fill;
Label idProducto = new Label();
idProducto.Text = variante.idVariante.ToString();
idProducto.BackColor = Color.FromArgb(82, 82, 82);
idProducto.ForeColor = Color.White;
idProducto.AutoSize = true;
idProducto.Dock = DockStyle.Left;
PictureBox imagen = new PictureBox();
string rutaImg = Path.Combine(Application.StartupPath, "Resources", variante.img);
imagen.Image = Image.FromFile(rutaImg);
imagen.Dock = DockStyle.Fill;
imagen.BackgroundImageLayout = ImageLayout.Stretch;
imagen.SizeMode = PictureBoxSizeMode.Zoom;
imagen.Controls.Add(idProducto);
Label nombreStock = new Label();
nombreStock.Text = variante.nombre + " - $" + variante.precio;
nombreStock.Font = new Font(nombreStock.Font.FontFamily, 14);
nombreStock.Dock = DockStyle.Fill;
nombreStock.TextAlign = ContentAlignment.MiddleCenter;
//panel de agregar stock
TableLayoutPanel agregarPanel = new TableLayoutPanel();
agregarPanel.Dock = DockStyle.Fill;
agregarPanel.RowCount = 1;
agregarPanel.ColumnCount = 2;
agregarPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 33F));
agregarPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 33F));
agregarPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 33F));
agregarPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
Button btnEditar = new Button();
btnEditar.Text = "Editar";
btnEditar.Font = new Font(btnEditar.Font.FontFamily, 20);
btnEditar.ForeColor = Color.White;
btnEditar.FlatStyle = FlatStyle.Flat;
btnEditar.FlatAppearance.BorderSize = 0;
btnEditar.BackColor = Color.FromArgb(33, 90, 255);
btnEditar.Dock = DockStyle.Fill;
btnEditar.Click += new EventHandler(delegate (object sender, EventArgs e)
{
editarvariante editarvariante = new editarvariante(variante, this);
editarvariante.Owner = this;
editarvariante.Show();
});
Button btnEliminar = new Button();
btnEliminar.Text = "Eliminar";
btnEliminar.Font = new Font(btnEliminar.Font.FontFamily, 20);
btnEliminar.ForeColor = Color.White;
btnEliminar.FlatStyle = FlatStyle.Flat;
btnEliminar.FlatAppearance.BorderSize = 0;
btnEliminar.BackColor = Color.Red;
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.eliminarVariante(variante.idVariante))
{
llenarLayout();
}
}
});
informacionProducto.Controls.Add(imagen, 0, 0);
informacionProducto.Controls.Add(nombreStock, 1, 0);
agregarPanel.Controls.Add(btnEditar, 0, 0);
agregarPanel.Controls.Add(btnEliminar, 1, 0);
filaLayout.Controls.Add(informacionProducto, 0, 0);
filaLayout.Controls.Add(agregarPanel, 1, 0);
VariantePanel.Controls.Add(filaLayout);
}
}
private void Variantes_Load(object sender, EventArgs e)
{
}
private void btnAgregar_Click(object sender, EventArgs e)
{
addvariante ventana = new addvariante(producto,this);
ventana.Owner = this;
ventana.Show();
}
private void VariantePanel_Paint(object sender, PaintEventArgs e)
{
}
}
}