/// <summary> /// Checks if a product has already been loaded and adds the necessary image. /// If the product is loaded, it uses the existing image, otherwise it loads it from disk /// </summary> /// <param name="product"></param> /// <returns></returns> private Bitmap GetProductImage(Product product) { if (!productIcons.ContainsKey(product)) { productIcons.Add(product, ExtraGraphics.LoadImage(product.ImageName)); } return(productIcons[product]); }
/// <summary> /// Returns the added Picturebox /// </summary> /// <param name="prod"></param> /// <param name="lane"></param> /// <returns></returns> private PictureBox AddToLane(Product prod, FlowLayoutPanel lane) { Image im = productIcons[prod]; im = ExtraGraphics.AddTextOverlay(im, prod); PictureBox pb = ExtraGraphics.GeneratePictureBox(im); lane.Controls.Add(pb); return(pb); }
///Pasting barcode deemed not useful in current version /*private void PasteItem() * { * long barcode=-1; * long.TryParse(Clipboard.GetText(TextDataFormat.Text),out barcode); * if (barcode > 0) * { * AddItem(barcode); * } * }*/ /// <summary> /// Adds the image to the visual list /// </summary> private PictureBox AddPictureBox(Image image) { if (labelHelp.Visible) { labelHelp.Visible = false; labelHelp.Enabled = false; } var pictureBox = ExtraGraphics.GeneratePictureBox(image); pictureBox.Name = "pictureBox" + pictureBoxes.Count; pictureBox.Click += new System.EventHandler(this.PictureBox_Click); pictureBoxes.Add(pictureBox); this.flowLayoutPanelMain.ResumeLayout(false); return(pictureBox); }
/// <summary> /// Adds a product to both the graphical and logical product list. /// </summary> /// <param name="product"></param> private void AddItem(Product product) { List <Product> products = new List <Product>(); //if identical items are grouped, the item has to be found, removed and readded with a higher counter if (isGroupingEnabled) { var toRemove = new List <PictureBox>(); foreach (var pb in addedProducts.Keys) { if (product.Equals(addedProducts[pb])) { toRemove.Add(pb); } } product.Count += toRemove.Sum(x => addedProducts[x].Count); foreach (var pb in toRemove) { SelectPictureBox(pb); RemovePictureBox(); } products.Add(product); } else { ///Adds the number of items in the product object to the logical list for (int i = 0; i < product.Count; i++) { products.Add(new Product(product)); } } /// Handles text overlay on image foreach (var prod in products) { Image im = GetProductImage(prod); im = ExtraGraphics.AddTextOverlay(im, prod); PictureBox pic = AddPictureBox(im); addedProducts.Add(pic, prod); } }