This commit is contained in:
2024-08-11 18:25:42 -03:00
parent 1fc1a0a2a2
commit 253a5d70d7
33 changed files with 705 additions and 26 deletions

View File

@@ -22,6 +22,8 @@ namespace Vista
InitializeComponent();
CargarCategorias();
CargarTabla();
cargarcombo();
if (producto != null)
{
nuevoproducto = producto;
@@ -29,8 +31,10 @@ namespace Vista
InicializarFormulario();
}
}
private void cargarcombo()
{
comboBox1.DataSource = Enum.GetValues(typeof(EnvaseTipo));
}
private void InicializarFormulario()
{
numId.Value = nuevoproducto.Id;
@@ -83,7 +87,6 @@ namespace Vista
// Validar Nombre
if (string.IsNullOrEmpty(txtNombre.Text)) { devolucion += "El nombre del producto no puede estar vacío.\n"; }
if (txtNombre.Text.Length > 100) { devolucion += "El nombre del producto no puede superar los 100 caracteres.\n"; }
if (numId.Value <= 0) { devolucion += "NO es un cuit válido"; };
// Validar Precio
if (numPrecio.Value <= 0)
@@ -103,6 +106,20 @@ namespace Vista
devolucion += "Debe seleccionar una categoría.\n";
}
// Validar Tipo de Producto
if (!checkBox1.Checked && comboBox1.SelectedItem == null)
{
devolucion += "Debe seleccionar un tipo de envase para el producto no perecedero.\n";
}
if (checkBox1.Checked) // Producto Perecedero
{
if (numericUpDown1.Value <= 0 || numericUpDown2.Value <= 0)
{
devolucion += "Los meses hasta consumo preferente y vencimiento deben ser mayores a cero.\n";
}
}
if (devolucion == "")
{
return true;
@@ -118,23 +135,48 @@ namespace Vista
{
if (ValidarDatos())
{
nuevoproducto.Nombre = txtNombre.Text;
nuevoproducto.Precio = (double)numPrecio.Value;
nuevoproducto.Habilitado = checkHabilitado.Checked;
nuevoproducto.Categoria = (Categoria)cmbCategoria.SelectedItem;
var proveedores = new List<Proveedor>(nuevoproducto.ListarProveedores());
string mensaje;
if (mod)
if (checkBox1.Checked) // Producto Perecedero
{
mensaje = ControladoraProductos.Instance.Modificar(nuevoproducto);
var productoPerecedero = new ProductoPercedero
{
Id = (int)numId.Value,
Nombre = txtNombre.Text,
Precio = (double)numPrecio.Value,
Habilitado = checkHabilitado.Checked,
Categoria = (Categoria)cmbCategoria.SelectedItem,
MesesHastaConsumoPreferente = (int)numericUpDown1.Value,
MesesHastaVencimiento = (int)numericUpDown2.Value,
proveedores = proveedores
};
string mensaje = mod
? ControladoraProductos.Instance.Modificar(productoPerecedero)
: ControladoraProductos.Instance.Añadir(productoPerecedero);
MessageBox.Show(mensaje, "Información", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
else // Producto No Perecedero
{
nuevoproducto.Id = (int)numId.Value;
mensaje = ControladoraProductos.Instance.Añadir(nuevoproducto);
var productoNoPerecedero = new ProductoNoPercedero
{
Id = (int)numId.Value,
Nombre = txtNombre.Text,
Precio = (double)numPrecio.Value,
Habilitado = checkHabilitado.Checked,
Categoria = (Categoria)cmbCategoria.SelectedItem,
TipoDeEnvase = (EnvaseTipo)comboBox1.SelectedItem,
proveedores = proveedores
};
string mensaje = mod
? ControladoraProductos.Instance.Modificar(productoNoPerecedero)
: ControladoraProductos.Instance.Añadir(productoNoPerecedero);
MessageBox.Show(mensaje, "Información", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
MessageBox.Show(mensaje, "Información", MessageBoxButtons.OK, MessageBoxIcon.Information);
Close();
}
}
@@ -146,7 +188,7 @@ namespace Vista
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
// Puedes usar este método para manejar cambios en el ComboBox si es necesario
}
private void btnaddProveedor_Click(object sender, EventArgs e)
@@ -199,5 +241,23 @@ namespace Vista
}
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
bool esPerecedero = checkBox1.Checked;
numericUpDown1.Enabled = esPerecedero;
numericUpDown2.Enabled = esPerecedero;
comboBox1.Enabled = !esPerecedero;
}
private void numericUpDown2_ValueChanged(object sender, EventArgs e)
{
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
}
}
}