Ejemplo n.º 1
0
        private List <Product> CollectProducts(bool separateByItem)
        {
            var productData = new List <Product>();

            foreach (var inputRow in InputRows)
            {
                if (inputRow.ProductName.Text != "" && inputRow.Sku.Text != "" && inputRow.Size.Text != "" && inputRow.Quantity.Value > 0)
                {
                    var product = new Product();
                    product.Sku         = inputRow.Sku.Text;
                    product.ProductName = GetProductName(inputRow.ProductName.Text);
                    product.Size        = inputRow.Size.Text;
                    product.Price       = inputRow.Price;
                    var coder = new Code128();
                    product.Code128Text = coder.Encode(product.Sku);
                    if (separateByItem)
                    {
                        for (int i = 0; i < (int)inputRow.Quantity.Value; i++)
                        {
                            productData.Add(product);
                        }
                    }
                    else
                    {
                        product.Quantity = (int)inputRow.Quantity.Value;
                        productData.Add(product);
                    }
                }
            }
            return(productData);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Funkcja generująca obrazek z kodem 128
        /// </summary>
        /// <param name="data">Dane do przetworzenia</param>
        /// <param name="barWeight">Szerokość kresek</param>
        /// <returns>Obrazek z kodem</returns>
        public static Image Code128(string data, int barWeight)
        {
            if(data.Length < 2)
            {
                return null;
            }

            Code128 content = new Code128(data);
            int[] codes = content.Codes;

            // Obliczanie szerokości dla kodu
            int width, height;
            width = ((codes.Length - 3) * 11 + 35) * barWeight;
            height = Convert.ToInt32(System.Math.Ceiling(Convert.ToSingle(width) * .15F));
            if (height < 100)
                height = 100;

            // Dodanie cichej strefy na początku i na końcu
            width += 2 * cQuietWidth * barWeight;

            // Stworzenie obrazka z kodem
            Image img = new Bitmap(width, height);
            using (Graphics gr = Graphics.FromImage(img))
            {
                // Wyczyszczenie grafiki (białe tło)
                gr.Clear(Color.White);

                Font cn = new Font("Courier New", 20, FontStyle.Bold, GraphicsUnit.Point);
                gr.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
                gr.DrawString("Code128", cn, new SolidBrush(Color.Black), 0, 0);

                int cursor = cQuietWidth * barWeight;
                for (int i = 0; i < codes.Length; i++)
                {
                    int code = codes[i];

                    // Rysujemy tylko czarne kreski
                    for (int bar = 0; bar < 8; bar += 2)
                    {
                        int barwidth = cPatterns[code, bar] * barWeight;
                        int spcwidth = cPatterns[code, bar + 1] * barWeight;

                        if (barwidth > 0)
                        {
                            gr.FillRectangle(Brushes.Black, cursor, 25, barwidth, height - 30);
                        }

                        cursor += (barwidth + spcwidth);
                    }
                }
            }

            return img;
        }