259 lines
9.8 KiB
C#
259 lines
9.8 KiB
C#
using compabetov2.database;
|
|
using compabetov2.database.modelos;
|
|
using compabetov2.Properties;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox;
|
|
|
|
namespace compabetov2
|
|
{
|
|
public partial class inventario : Form
|
|
{
|
|
private List<Producto> productos;
|
|
private LoginModel loginPrincipal;
|
|
public inventario(LoginModel loginPrincipal)
|
|
{
|
|
InitializeComponent();
|
|
llenarPanel();
|
|
this.loginPrincipal = loginPrincipal;
|
|
}
|
|
|
|
private void llenarPanel()
|
|
{
|
|
stockPanel.Controls.Clear();
|
|
productos = service.conseguirProductos();
|
|
|
|
foreach (Producto producto in productos)
|
|
{
|
|
TableLayoutPanel filaLayout = new TableLayoutPanel();
|
|
filaLayout.RowCount = 1;
|
|
filaLayout.ColumnCount = 2;
|
|
filaLayout.Height = 100;
|
|
filaLayout.Width = 830;
|
|
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 = producto.idProducto.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", producto.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 = producto.nombre + " - Stock: " + producto.stock.ToString();
|
|
nombreStock.Font = new Font(nombreStock.Font.FontFamily, 16);
|
|
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 = 3;
|
|
agregarPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 60F));
|
|
agregarPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 20F));
|
|
agregarPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 20F));
|
|
agregarPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
|
|
|
|
TextBox txtStockAgregar = new TextBox();
|
|
txtStockAgregar.Text = "0";
|
|
txtStockAgregar.Height = 60;
|
|
txtStockAgregar.Width = 200;
|
|
txtStockAgregar.Anchor = AnchorStyles.None;
|
|
txtStockAgregar.Font = new Font(txtStockAgregar.Font.FontFamily, 17);
|
|
|
|
Button btnMenos = new Button();
|
|
btnMenos.Text = "-";
|
|
btnMenos.Width = 60;
|
|
btnMenos.Height = 60;
|
|
btnMenos.Font = new Font(btnMenos.Font.FontFamily, 30);
|
|
btnMenos.ForeColor = Color.White;
|
|
btnMenos.FlatStyle = FlatStyle.Flat;
|
|
btnMenos.FlatAppearance.BorderSize = 0;
|
|
btnMenos.BackColor = Color.FromArgb(33, 90, 255);
|
|
btnMenos.Anchor = AnchorStyles.None;
|
|
btnMenos.Click += new EventHandler(delegate (object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
int numeroContador = int.Parse(txtStockAgregar.Text);
|
|
txtStockAgregar.Text = (numeroContador - 1).ToString();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
txtStockAgregar.Text = "0";
|
|
}
|
|
});
|
|
|
|
Button btnMas = new Button();
|
|
btnMas.Text = "+";
|
|
btnMas.Width = 60;
|
|
btnMas.Height = 60;
|
|
btnMas.Font = new Font(btnMas.Font.FontFamily, 30);
|
|
btnMas.ForeColor = Color.White;
|
|
btnMas.BackColor = Color.FromArgb(33, 90, 255);
|
|
btnMas.FlatStyle = FlatStyle.Flat;
|
|
btnMas.FlatAppearance.BorderSize = 0;
|
|
btnMas.Anchor = AnchorStyles.None;
|
|
btnMas.Click += new EventHandler(delegate (object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
int numeroContador = int.Parse(txtStockAgregar.Text);
|
|
txtStockAgregar.Text = (numeroContador + 1).ToString();
|
|
}catch (Exception ex)
|
|
{
|
|
txtStockAgregar.Text = "0";
|
|
}
|
|
|
|
});
|
|
|
|
|
|
informacionProducto.Controls.Add(imagen,0,0);
|
|
informacionProducto.Controls.Add(nombreStock,1,0);
|
|
|
|
agregarPanel.Controls.Add(txtStockAgregar, 0, 0);
|
|
agregarPanel.Controls.Add(btnMenos, 1, 0);
|
|
agregarPanel.Controls.Add(btnMas, 2, 0);
|
|
|
|
|
|
filaLayout.Controls.Add(informacionProducto, 0, 0);
|
|
filaLayout.Controls.Add(agregarPanel, 1, 0);
|
|
stockPanel.Controls.Add(filaLayout);
|
|
}
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
// Cerrar el formulario de ventas
|
|
this.Close();
|
|
|
|
|
|
// Verificar si ya hay una instancia del formulario principal
|
|
MenuPrincipal menuprincipalForm = Application.OpenForms.OfType<MenuPrincipal>().FirstOrDefault();
|
|
|
|
if (menuprincipalForm == null)
|
|
{
|
|
// Si no hay una instancia, crear una nueva
|
|
menuprincipalForm = new MenuPrincipal(loginPrincipal);
|
|
|
|
// Establecer el formulario principal como el formulario MDI padre
|
|
menuprincipalForm.MdiParent = this.MdiParent;
|
|
|
|
// Mostrar el formulario principal
|
|
menuprincipalForm.Show();
|
|
}
|
|
else
|
|
{
|
|
// Si ya hay una instancia, simplemente llevarlo al frente
|
|
menuprincipalForm.BringToFront();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
private void button6_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
private void button6_Click_1(object sender, EventArgs e)
|
|
{
|
|
List<Producto> stockNuevo = new List<Producto>();
|
|
try {
|
|
foreach (Control control in stockPanel.Controls)
|
|
{
|
|
TableLayoutPanel informacionProducto = control.Controls[0] as TableLayoutPanel;
|
|
TableLayoutPanel agregarPanel = control.Controls[1] as TableLayoutPanel;
|
|
|
|
//id
|
|
Label lbIdProducto = informacionProducto.Controls[0].Controls[0] as Label;
|
|
int idProducto = int.Parse(lbIdProducto.Text);
|
|
|
|
//stock a agregar
|
|
TextBox txtStock = agregarPanel.Controls[0] as TextBox;
|
|
int stock = int.Parse(txtStock.Text);
|
|
|
|
if (stock != 0)
|
|
{
|
|
Producto productoStockNuuevo = new Producto(idProducto, "", "", 0, "", stock, null);
|
|
stockNuevo.Add(productoStockNuuevo);
|
|
}
|
|
|
|
}
|
|
|
|
string mensajeConfirmacion = "Se aumentara el stock a los\nsiguientes productos\n";
|
|
for (int i = 0; i < stockNuevo.Count; i++)
|
|
{
|
|
|
|
mensajeConfirmacion += productos[stockNuevo[i].idProducto - 1].nombre + ": " + stockNuevo[i].stock + "\n";
|
|
|
|
}
|
|
|
|
|
|
if (stockNuevo.Count > 0)
|
|
{
|
|
DialogResult result = MessageBox.Show(mensajeConfirmacion, "Confirmación", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
|
if (result == DialogResult.Yes)
|
|
{
|
|
service.aumentarStock(stockNuevo);
|
|
llenarPanel();
|
|
}
|
|
}
|
|
}
|
|
catch(Exception ex) {
|
|
MessageBox.Show("Solo debe introducir numeros","Error", MessageBoxButtons.OK,MessageBoxIcon.Error);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
private void inventario_Load(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void stockPanel_Paint(object sender, PaintEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void button2_Click(object sender, EventArgs e)
|
|
{
|
|
Estadiscticas verstats = new Estadiscticas();
|
|
verstats.Show();
|
|
}
|
|
}
|
|
}
|