/// <summary>
        /// Creator: Robert Holmes
        /// Created: 04/29/2020
        /// Approver:
        ///
        /// Constroctor for view/edit operations.
        /// </summary>
        /// <remarks>
        /// Updater: Robert Holmes
        /// Updated: 5/5/2020
        /// Update: Migrated edit functionality from other tab.
        ///
        /// </remarks>
        /// <param name="frame"></param>
        /// <param name="inventoryItem"></param>
        /// <param name="editMode"></param>
        public pgAddEditViewProduct(Frame frame, InventoryItems inventoryItem, bool editMode = false)
        {
            _frame          = frame;
            _productManager = new ProductManager();
            _pictureManager = new PictureManager();
            _inventoryItem  = inventoryItem;
            _editMode       = editMode;
            try
            {
                _product  = _productManager.RetrieveProductByID(inventoryItem.ProductID);
                _picture  = _pictureManager.RetrieveMostRecentPictureByProductID(_product.ProductID);
                _products = _productManager.RetrieveAllProductsByType();
            }
            catch (Exception ex)
            {
                WPFErrorHandler.ErrorMessage("There was a problem loading product data:\n\n" + ex.Message);
            }
            InitializeComponent();
            setItemFields(_product);
            initializeComboBoxes();
            if (_picture == null)
            {
                _picture = new Picture();
            }

            try
            {
                using (var stream = new MemoryStream(_picture.ImageData))
                {
                    imgPicture.Source = BitmapFrame.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
                }
            }
            catch (Exception ex)
            {
                WPFErrorHandler.ErrorMessage("There was a problem loading the picture.\n\n" + ex.Message);
            }

            if (!editMode)
            {
                lblHeading.Content   = "View Product";
                btnAction.Content    = "Done";
                btnCancel.Visibility = Visibility.Hidden;
                makeReadOnly();
            }
            else
            {
                lblHeading.Content = "Edit Product";
                btnAction.Content  = "Update";
                makeEditable();
                txtProductID.IsReadOnly = true;
            }
        }
Exemple #2
0
        /// <summary>
        /// Creator: Robert Holmes
        /// Created: 04/29/2020
        /// Approver: Jaeho Kim
        ///
        /// Gets the image for a product or returns the default if there isn't one.
        /// </summary>
        /// <remarks>
        /// Updater:
        /// Updated:
        /// Update:
        /// </remarks>
        public FileResult GetImage(string productID)
        {
            Picture picture = _pictureManager.RetrieveMostRecentPictureByProductID(productID);

            if (picture != null)
            {
                return(File(picture.ImageData, picture.ImageMimeType));
            }
            else
            {
                string path = Server.MapPath("/Content/Images/MISSING.jpg");
                return(File(path, "image/jpeg"));
            }
        }