Exemplo n.º 1
0
        private void btnEditar_Click(object sender, EventArgs e)
        {
            if (dgvProductos.SelectedRows.Count > 0)
            {
                int            id       = Convert.ToInt32(dgvProductos.CurrentRow.Cells[0].Value);
                ProductoLogica logica   = new ProductoLogica();
                Producto       producto = logica.SeleccionarPorId(id);
                txtId.Text            = id.ToString();
                txtNombre.Text        = producto.nombre;
                txtMarca.Text         = producto.marca;
                txtCantidad.Text      = producto.cantidad.ToString();
                txtPeso.Text          = producto.peso.ToString();
                txtPrecio.Text        = producto.precio.ToString();
                txtMinCantidad.Text   = producto.minCantidad.ToString();
                cmbArea.SelectedIndex = producto.idCategoria;

                int unidad = producto.unidad == "Kg" ? 0 :
                             producto.unidad == "g" ? 1 :
                             producto.unidad == "mL" ? 2 :
                             producto.unidad == "L" ? 3 :
                             producto.unidad == "oz" ? 4 : 0;

                cmbMedida.SelectedIndex = unidad;
            }
            else
            {
                MessageBox.Show("Debe seleccionar un producto de la tabla.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 2
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            int              id = 0;
            Producto         p;
            ProductoLogica   logica  = new ProductoLogica();
            InventarioLogica logica2 = new InventarioLogica();

            if (dgvProductos.Rows.Count > 0)
            {
                // se crea el encabezado de la salida de productos
                logica2.CrearSalidaProductos(usuario);
                foreach (DataGridViewRow item in dgvProductos.Rows)
                {
                    id          = Convert.ToInt32(item.Cells[0].Value.ToString());
                    p           = logica.SeleccionarPorId(id);
                    p.cantidad -= Convert.ToInt32(item.Cells[6].Value.ToString());
                    logica.Actualizar(p);
                    Inventario inventario = new Inventario();
                    inventario.producto = p;
                    inventario.cantidad = Convert.ToInt32(item.Cells[6].Value.ToString());

                    // se crea el detalle de la salida de productos
                    logica2.SalidaProductos(inventario);
                }

                dgvProductos.Rows.Clear();
                count_fila = 0;
                MessageTimer.Start();
                lblError.Visible   = false;
                lblSuccess.Text    = "*Se ha guardado la salida de productos.";
                lblSuccess.Visible = true;
            }
            else
            {
                MessageTimer.Start();
                lblSuccess.Visible = false;
                lblError.Text      = "*Debe agregar productos de salida.";
                lblError.Visible   = true;
            }
        }
Exemplo n.º 3
0
        private void btnAgregar_Click(object sender, EventArgs e)
        {
            bool existe   = false;
            int  num_fila = 0;

            ProductoLogica logica = new ProductoLogica();

            if (cmbProductos.SelectedItem == null)
            {
                lblSuccess.Visible = false;
                MessageTimer.Start();
                lblError.Text    = "*Debe seleccionar un producto.";
                lblError.Visible = true;
            }

            Producto p        = logica.SeleccionarPorId(((Producto)cmbProductos.SelectedItem).id);
            int      cantidad = Convert.ToInt32(nudCantidad.Value);

            if (count_fila == 0)
            {
                dgvProductos.Rows.Add(p.id, p.nombre, p.marca, p.pesoUnidad, p.precio, p.cantidad, cantidad);
                int cantidadFinal = Convert.ToInt32(dgvProductos.Rows[count_fila].Cells[5].Value) + cantidad;
                dgvProductos.Rows[count_fila].Cells[7].Value = cantidadFinal;
                count_fila++;
                MessageTimer.Start();
                lblError.Visible   = false;
                lblSuccess.Text    = "*Agregado con éxito.";
                lblSuccess.Visible = true;
            }
            else
            {
                foreach (DataGridViewRow item in dgvProductos.Rows)
                {
                    if (item.Cells[0].Value.ToString() == (cmbProductos.SelectedIndex + 1).ToString())
                    {
                        existe   = true;
                        num_fila = item.Index;
                    }
                }

                if (existe)
                {
                    MessageTimer.Start();
                    lblSuccess.Visible = false;
                    lblError.Text      = "*Éste producto ya se encuentra agregado.";
                    lblError.Visible   = true;
                }
                else
                {
                    dgvProductos.Rows.Add(p.id, p.nombre, p.marca, p.pesoUnidad, p.precio, p.cantidad, cantidad);
                    int cantidadFinal = Convert.ToInt32(dgvProductos.Rows[count_fila].Cells[5].Value) + cantidad;
                    dgvProductos.Rows[count_fila].Cells[7].Value = cantidadFinal;
                    count_fila++;
                    MessageTimer.Start();
                    lblError.Visible   = false;
                    lblSuccess.Text    = "*Agregado con éxito.";
                    lblSuccess.Visible = true;
                }
            }

            cmbProductos.SelectedItem        = null;
            cmbProductos.Text                = "";
            nudCantidad.Value                = 0;
            dgvProductos.CurrentRow.Selected = false;
        }
Exemplo n.º 4
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            try
            {
                CategoriaLogica logicaCategoria = new CategoriaLogica();
                ProductoLogica  logicaProducto  = new ProductoLogica();


                Producto producto = new Producto();

                producto.nombre = txtNombre.Text;
                producto.marca  = txtMarca.Text;

                string unidad = cmbMedida.SelectedIndex == 0 ? "Kg" :
                                cmbMedida.SelectedIndex == 1 ? "g" :
                                cmbMedida.SelectedIndex == 2 ? "mL" :
                                cmbMedida.SelectedIndex == 3 ? "L" :
                                cmbMedida.SelectedIndex == 4 ? "oz" : "Kg";

                int     cantidad    = 0;
                int     minCantidad = 0;
                decimal precio      = 0m;
                decimal peso        = 0m;

                if (!int.TryParse(txtMinCantidad.Text, out minCantidad) ||
                    !int.TryParse(txtCantidad.Text, out cantidad) ||
                    !decimal.TryParse(txtPrecio.Text, out precio) ||
                    !decimal.TryParse(txtPeso.Text, out peso))
                {
                    lblError.Text = "*Debe ser un valor numérico."; lblError.Visible = true;
                }

                producto.peso        = peso;
                producto.unidad      = unidad;
                producto.cantidad    = cantidad;
                producto.minCantidad = minCantidad;
                producto.precio      = precio;
                producto.categoria   = logicaCategoria.SeleccionarPorId(cmbArea.SelectedIndex);

                Producto p = logicaProducto.SeleccionarPorId(Convert.ToInt32(txtId.Text));

                if (p != null)
                {
                    producto.id = Convert.ToInt32(txtId.Text);
                    logicaProducto.Actualizar(producto);
                }
                else
                {
                    logicaProducto.Crear(producto);
                }


                dgvProductos.DataSource          = logicaProducto.SeleccionarTodos();
                dgvProductos.CurrentRow.Selected = false;
                MessageTimer.Start();
                lblSuccess.Text    = "*Guardado con éxito.";
                lblSuccess.Visible = true;
                btnLimpiar_Click(this, null);
            }
            catch (Exception ex)
            {
                lblError.Text    = "*" + ex.Message;
                lblError.Visible = true;
                MessageTimer.Start();
            }
        }