Esempio n. 1
0
        public static byte[] BuildQRCode(Credential credentialSelected)
        {
            if (credentialSelected != null)
            {
                string stringToShow = string.Empty;
                stringToShow += credentialSelected.Title.ToUpper();
                if (!string.IsNullOrEmpty(credentialSelected.Url))
                {
                    stringToShow += " (Url: " + credentialSelected.Url + ")";
                }
                stringToShow += Environment.NewLine;

                if (!string.IsNullOrEmpty(credentialSelected.Email))
                {
                    stringToShow += "Email: " + credentialSelected.Email;
                    stringToShow += Environment.NewLine;
                }
                if (!string.IsNullOrEmpty(credentialSelected.Username))
                {
                    stringToShow += "Username: "******"Password: " + credentialSelected.Password + Environment.NewLine;

                GeneratedBarcode qrCode = BarcodeWriter.CreateBarcode(stringToShow, BarcodeWriterEncoding.QRCode, 200, 200);
                qrCode.AddAnnotationTextBelowBarcode(credentialSelected.Title);
                return(qrCode.ToPngBinaryData());
            }

            return(null);
        }
Esempio n. 2
0
        private void DoMyJob()
        {
            if (ErrorLabel != null)
            {
                ErrorLabel.Content = null;
            }

            string text = new TextRange(TextInput.Document.ContentStart, TextInput.Document.ContentEnd).Text.Trim();

            if (!string.IsNullOrEmpty(text) && Image1 != null)
            {
                try
                {
                    Image1.Source = null;

                    GeneratedBarcode myBarcode = BarcodeWriter.CreateBarcode(text, BarcodeWriterEncoding.DataMatrix);
                    Image1.Source = Convert(myBarcode.ToBitmap());
                }
                catch (Exception e)
                {
                    if (ErrorLabel != null)
                    {
                        ErrorLabel.Content = e.Message;
                    }
                }
            }
            else
            {
                if (text == "" && Image1 != null)
                {
                    Image1.Source = null;
                }
            }
        }
Esempio n. 3
0
        public void GenerateImage(string textData, string path)
        {
            GeneratedBarcode barCode = IronBarCode.BarcodeWriter
                                       .CreateBarcode(textData, BarcodeWriterEncoding.Code128)
                                       .ResizeTo(500, 200)
                                       .AddAnnotationTextBelowBarcode(textData)
                                       .SetMargins(10);

            barCode.SaveAsPng(path);
        }
Esempio n. 4
0
        private void btnOffers_Click(object sender, RoutedEventArgs e)
        {
            ProductsPanel.Visibility = Visibility.Hidden;
            ContactPanel.Visibility  = Visibility.Hidden;
            LocationPanel.Visibility = Visibility.Hidden;
            OffersPanel.Visibility   = Visibility.Visible;
            GeneratedBarcode MyBarCode = BarcodeWriter.CreateBarcode(loggedClient.Password, BarcodeWriterEncoding.Code128).ResizeTo(450, 250).SaveAsImage("barcode.jpeg");

            BarCode.Source = ToImageSource(MyBarCode.Image, ImageFormat.Png);
        }
Esempio n. 5
0
        public static void Example1()
        {
            // Generate a Simple BarCode image and save as PNG
            GeneratedBarcode MyBarCode = IronBarCode.BarcodeWriter.CreateBarcode("http://ironsoftware.com/csharp/barcode", BarcodeWriterEncoding.Code128);

            MyBarCode.AddBarcodeValueTextBelowBarcode();
            MyBarCode.SaveAsPng("MyBarCode.png");

            // This line opens the image in your default image viewer
            System.Diagnostics.Process.Start("MyBarCode.png");
        }
Esempio n. 6
0
        private void generateBarcode(int ArtNr)
        {
            string ean = "400" + ArtNr.ToString() + "1234";

            ean = ean + _checksum_ean13(ean).ToString();
            GeneratedBarcode MyBarCode = IronBarCode.BarcodeWriter.CreateBarcode(ean, BarcodeWriterEncoding.Code128);

            MyBarCode.ResizeTo(500, 200).SetMargins(10);
            System.Drawing.Image BarCode = MyBarCode.Image;
            byte[] bytes = MyBarCode.ToPngBinaryData();
            //BitmapImage bild = ModulModell.Byte2Pic(bytes);
            BitmapImage bild = new BitmapImage();

            bild.BeginInit();
            bild.CacheOption  = BitmapCacheOption.OnLoad;
            bild.StreamSource = new System.IO.MemoryStream(bytes);
            bild.EndInit();


            _uiBarcode.Source = bild;
        }
        public async Task <ActionResult> AddProduct(AddProductVM model)
        {
            if (ModelState.IsValid)
            {
                Supplier supplier = db.Suppliers.Find(model.SupplierId);
                // Check for and set sku
                // Sku must be Upper case and replace spaces with dashes
                string sku           = "";
                string CustomSkuName = model.Name + model.PackSize;
                if (string.IsNullOrWhiteSpace(model.SkuCode))
                {
                    sku = CustomSkuName.Replace(" ", "-").ToLower();
                }
                else
                {
                    sku = model.SkuCode.Replace(" ", "-").ToLower();
                }

                // Check if sku is unique
                if (db.Products.Any(x => x.SkuCode.Equals(sku)))
                {
                    ModelState.AddModelError("", "The Sku Code already exists");
                    model = new AddProductVM
                    {
                        Categories = new SelectList(db.Categories.ToList(), "Id", "Name"),
                        Suppliers  = new SelectList(db.Suppliers.ToList(), "Id", "Name")
                    };
                    return(View(model));
                }

                // Check for and set slug
                // Slug must be lower case and replace spaces with dashes
                string slug = "";
                string name = sku;
                if (string.IsNullOrWhiteSpace(model.Slug))
                {
                    slug = name.Replace(" ", "-").ToLower();
                }
                else
                {
                    slug = model.Slug.Replace(" ", "-").ToLower();
                }

                // Check if slug and title is unique
                if (db.Products.Any(x => x.Slug.Equals(slug)))
                {
                    ModelState.AddModelError("", "The slug or title already exists");
                    model = new AddProductVM
                    {
                        Categories = new SelectList(db.Categories.ToList(), "Id", "Name"),
                        Suppliers  = new SelectList(db.Suppliers.ToList(), "Id", "Name")
                    };
                    return(View(model));
                }

                #region Upload Image and Generate Barcode
                // Upload Image
                string imgUrl = "";
                try
                {
                    if (model.Image == null)
                    {
                        imgUrl = "/Files/Images/noproduct.png";
                    }
                    else if (model.Image.ContentLength > 0)
                    {
                        var    uploadPath     = "~/Files/Images";
                        string _FileName      = Path.GetFileName(model.Image.FileName);
                        string UniqueFileName = model.SkuCode +
                                                "-" + _FileName.ToLower();

                        string _path = Path.Combine(Server
                                                    .MapPath(uploadPath), UniqueFileName);
                        model.Image.SaveAs(_path);

                        imgUrl = "/Files/Images/" + UniqueFileName;
                    }
                    else
                    {
                    }
                }
                catch (Exception e)
                {
                    throw e;
                }

                /*
                 * Generate Barcode
                 */

                // Check if SkuCode exists already
                if (db.Products.Any(x => x.SkuCode.Equals(sku)))
                {
                    ModelState.AddModelError("", "The barcode already exists");
                    return(View(model));
                }

                // Save Barcode to that path
                string _barcodePath = Path.Combine(Server
                                                   .MapPath("~/Files/Barcodes"), sku + ".png");

                // Generate a Simple BarCode image and save as PNG
                //using IronBarCode;
                GeneratedBarcode MyBarCode = BarcodeWriter
                                             .CreateBarcode(sku,
                                                            BarcodeWriterEncoding.Code128);

                MyBarCode.SetMargins(50);

                MyBarCode.SaveAsPng(_barcodePath);

                string _barcodeUrl = "/Files/Barcodes/" + sku + ".png";
                //string _barcodeUrl = "/";
                #endregion

                // Add Product
                db.Products.Add(new Product
                {
                    Name          = model.Name,
                    SkuCode       = sku,
                    CategoryId    = model.CategoryId,
                    Description   = model.Description,
                    Slug          = slug,
                    ImageUrl      = imgUrl,
                    BarcodeUrl    = _barcodeUrl,
                    PackSize      = model.PackSize,
                    Quantity      = 0,
                    SupplierPrice = model.SupplierPrice,
                    SupplierId    = model.SupplierId,
                    SellingPrice  = model.SellingPrice,
                    IsOnSale      = false,
                    Supplier      = supplier
                });

                await db.SaveChangesAsync();

                // Add notification
                var product = await db.Products.OrderByDescending(m => m.Id).FirstOrDefaultAsync();

                db.Notifications.Add(new Notification
                {
                    CreatedDate = DateTime.Now,
                    Message     = "You have added a new product to the pharmacy: " +
                                  product.Name,
                    isRead = false,
                    Icon   = "fa-check",
                    BackgroundColorIcon = "bg-success"
                });

                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            model = new AddProductVM
            {
                Categories = new SelectList(db.Categories.ToList(), "Id", "Name"),
                Suppliers  = new SelectList(db.Suppliers.ToList(), "Id", "Name")
            };
            return(View(model));
        }
        /// <summary>
        /// Generates a barcode PDF and returns the number of barcodes generated
        /// </summary>
        /// <param name="outputPath"></param>
        /// <param name="numberOfPages"></param>
        /// <returns>The number of barcodes generated</returns>
        public int GenerateBarcodes(string outputPath)
        {
            if (NumberOfPages > 0)
            {
                PdfDocument document = new PdfDocument();
                document.Info.Title = "Inventory Barcodes";
                long barcodeToUse      = GeneratedBarcode.GetLatestBarcodeNumber() + 1;
                var  barcodesGenerated = new List <long>();
                for (int i = 0; i < NumberOfPages; i++)
                {
                    PdfPage page = document.AddPage();
                    page.Size = PageSize;

                    XGraphics gfx    = XGraphics.FromPdfPage(page);
                    XFont     font   = new XFont("Verdana", 20, XFontStyle.Bold);
                    XUnit     yCoord = XUnit.FromInch(1); // pixels
                    gfx.DrawString("Inventory Barcodes", font, XBrushes.Black,
                                   new XRect(0, yCoord, page.Width, page.Height), XStringFormats.TopCenter);

                    yCoord += XUnit.FromInch(0.7);

                    // Generate a barcode
                    var barcodeCreator = new BarcodeLib.Barcode();
                    barcodeCreator.ImageFormat   = ImageFormat.Jpeg;
                    barcodeCreator.IncludeLabel  = true;
                    barcodeCreator.LabelPosition = BarcodeLib.LabelPositions.BOTTOMCENTER;
                    barcodeCreator.Alignment     = BarcodeLib.AlignmentPositions.CENTER;

                    bool  isPageFull  = false;
                    XUnit imageHeight = XUnit.FromPoint(60);
                    while (!isPageFull)
                    {
                        var   isWidthFull = false;
                        XUnit xCoord      = XUnit.FromInch(1);
                        while (!isWidthFull)
                        {
                            var image = barcodeCreator.Encode(BarcodeType, barcodeToUse.ToString());
                            if (image != null)
                            {
                                // make sure images are a good size based on DPI
                                // TODO: There has got to be a better way to make things fairly consistent across computers
                                // with different DPI. This is ridiculous. I love WPF most of the time with its DPI
                                // help, but in this case.......ugh. Images come out a little blurry this way
                                // on computers with a non-192 DPI.
                                double ratioTo192   = (192 / image.VerticalResolution);
                                int    resizeHeight = (int)(image.Height / ratioTo192);
                                int    resizeWidth  = (int)(image.Width / ratioTo192);
                                image = ResizeImage(image, resizeWidth, resizeHeight, (int)image.VerticalResolution);
                                // ok, now we can draw.
                                XImage pdfImage = XImage.FromBitmapSource(ConvertImageToBitmapImage(image));
                                gfx.DrawImage(pdfImage, xCoord, yCoord);
                                xCoord     += XUnit.FromPoint(pdfImage.PointWidth);
                                imageHeight = XUnit.FromPoint(pdfImage.PointHeight);
                                var   blah = XUnit.FromPoint(image.Width);
                                XUnit spaceBetweenBarcodes = XUnit.FromInch(0.75);
                                if (xCoord + XUnit.FromPoint(pdfImage.PointWidth) + spaceBetweenBarcodes > page.Width - XUnit.FromInch(1))
                                {
                                    isWidthFull = true;
                                }
                                barcodesGenerated.Add(barcodeToUse);
                                barcodeToUse++;
                                xCoord += spaceBetweenBarcodes;
                            }
                            else
                            {
                                // failure case
                                isWidthFull = true;
                                isPageFull  = true;
                                break;
                            }
                        }
                        yCoord += imageHeight;
                        yCoord += XUnit.FromInch(0.7);
                        if (yCoord + imageHeight > page.Height - XUnit.FromInch(1))
                        {
                            isPageFull = true;
                        }
                    }
                }
                if (!IsDryRun)
                {
                    // save the fact that we generated barcodes
                    GeneratedBarcode.AddGeneratedCodes(barcodesGenerated, DateTime.Now, 1);
                    // save the document and start the process for viewing the pdf
                    document.Save(outputPath);
                    Process.Start(outputPath);
                }
                return(barcodesGenerated.Count);
            }
            return(0);
        }
Esempio n. 9
0
        private void btnImport_Click(object sender, EventArgs e)
        {
            string Barcode, Kyhieu, MaSP, Dai, Rong, ARTID, SonID, DVT, Mieuta, ngaytao, ngaysua;

            Barcode = Kyhieu = MaSP = Dai = Rong = ARTID = SonID = DVT = Mieuta = ngaytao = ngaysua = string.Empty;
            try
            {
                using (OpenFileDialog ofd = new OpenFileDialog()
                {
                    Filter = "Excel Workbook|*.xlsx|Excel Workbook 97-2003|*.xls", ValidateNames = true
                })
                {
                    if (ofd.ShowDialog() == DialogResult.OK)
                    {
                        using (var stream = File.Open(ofd.FileName, FileMode.Open, FileAccess.Read))
                        {
                            IExcelDataReader reader;
                            if (ofd.FilterIndex == 2)
                            {
                                reader = ExcelReaderFactory.CreateBinaryReader(stream);
                            }
                            else
                            {
                                reader = ExcelReaderFactory.CreateOpenXmlReader(stream);
                            }

                            DataSet ds = reader.AsDataSet(new ExcelDataSetConfiguration()
                            {
                                ConfigureDataTable = (_) => new ExcelDataTableConfiguration()
                                {
                                    UseHeaderRow = true
                                }
                            });


                            string InsertItemQry     = "";
                            int    count             = 0;
                            System.Data.DataTable dt = ds.Tables[0];
                            string[] columnNames     = dt.Columns.Cast <DataColumn>()
                                                       .Select(x => x.ColumnName)
                                                       .ToArray();

                            for (int i = 7; i < dt.Rows.Count; i++)
                            {
                                //BarcodeWriter writer = new BarcodeWriter() { Format = BarcodeFormat.CODE_128 };
                                //pictureBox1.Image = writer.Write(textBox1.Text);
                                //Barcode = BarcodeFormat.CODE_128;
                                string           now        = DateTime.Now.ToString("ddmmyyyhhmmssff");
                                GeneratedBarcode newbarcode = BarcodeWriter.CreateBarcode(now, BarcodeWriterEncoding.Code128);

                                Barcode = newbarcode.ToString();
                                Kyhieu  = Convert.ToString(dt.Rows[i][1]).Trim();
                                MaSP    = Convert.ToString(dt.Rows[i][2]).Trim();
                                Dai     = Convert.ToString(dt.Rows[i][3]).Trim();
                                Rong    = Convert.ToString(dt.Rows[i][4]).Trim();
                                ARTID   = DBHelper.Lookup("ART", "ARTID", "Ten", Convert.ToString(dt.Rows[i][5]).Trim('\'').Trim());
                                if (string.IsNullOrEmpty(ARTID))
                                {
                                    MessageBox.Show(Convert.ToString(dt.Rows[i][5]).Trim('\''));
                                }
                                SonID = DBHelper.Lookup("Color", "SonID", "Ten", Convert.ToString(dt.Rows[i][6]).Trim('\'').Trim());
                                if (string.IsNullOrEmpty(SonID))
                                {
                                    MessageBox.Show(Convert.ToString(dt.Rows[i][6]).Trim('\''));
                                }
                                DVT     = Convert.ToString(dt.Rows[i][8]).Trim();
                                Mieuta  = string.Empty;
                                ngaytao = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt");
                                ngaysua = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt");
                                if (Kyhieu != string.Empty)
                                {
                                    InsertItemQry = "Insert into Product([Barcode],[Kyhieu],[Dai],[Rong],[ArtID],[SonID],[DVT],[Mieuta],[Ngaytao],[Ngaysua],[MaSP]) Values ('" + Barcode + "','" + Kyhieu + "','" + Dai + "','" + Rong + "','" + ARTID + "','" + SonID + "','" + DVT + "','" + "" + "','" + ngaysua + "','" + ngaytao + "','" + MaSP + "')";
                                    if (DBAccess.IsServerConnected())
                                    {
                                        if (InsertItemQry.Length > 5)
                                        {
                                            isSuccess = DBAccess.ExecuteQuery(InsertItemQry);
                                        }
                                    }
                                    if (isSuccess)
                                    {
                                        count++;
                                    }
                                    else
                                    {
                                        MessageBox.Show(InsertItemQry);
                                    }
                                }
                                else
                                {
                                    GetTotalRow();
                                    GetAllDataProduct(1, 50);
                                    MessageBox.Show("Import " + count + " dòng thành công!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    return;
                                }
                            }
                            if (isSuccess)
                            {
                                MessageBox.Show("Import " + count + " dòng thành công!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                            else
                            {
                                MessageBox.Show("Import dòng " + count + " không thành công!Kyhieu = " + Kyhieu, "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("File không đúng format! Format Đúng: Dữ liệu bắt đầu từ dòng 7, cột 1: Ký Hiệu, cột 2: Mã SP, cột 3: Dài, cột 4: Rộng, cột 5: ART, cột 6: SON, cột 8:DVT ");
            }
        }