public static string NewUniqueCode(int userID, int employeeID, int bussinessID, string table, int length = 9, string prefix = "450") { var result = ""; while (true) { var ean13 = new Ean13(); ean13.CountryCode = String.IsNullOrEmpty(prefix) ? SKtimeManagement.Functions.RandomNumberString(2) : prefix; ean13.ManufacturerCode = SKtimeManagement.Functions.RandomNumberString(Convert.ToInt32(Math.Floor(length / 2.0))); ean13.ProductCode = SKtimeManagement.Functions.RandomNumberString(Convert.ToInt32(Math.Ceiling(length / 2.0))); ean13.CalculateChecksumDigit(); result = String.Format("{0}{1}{2}{3}", ean13.CountryCode, ean13.ManufacturerCode, ean13.ProductCode, ean13.ChecksumDigit); if (!CodeExist(userID, employeeID, bussinessID, result, table)) { break; } } return(result); }
public static string BarcodeImage(this string code) { if (code.Length == 13) { var ean13 = new Ean13(); ean13.CountryCode = code.Substring(0, 3); ean13.ManufacturerCode = code.Substring(3, 4); ean13.ProductCode = code.Substring(7, 5); ean13.ChecksumDigit = code.Substring(12, 1); System.Drawing.Bitmap bmp = ean13.CreateBitmap(); using (MemoryStream ms = new MemoryStream()) { bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png); byte[] byteImage = ms.ToArray(); Convert.ToBase64String(byteImage); return("data:image/png;base64," + Convert.ToBase64String(byteImage)); } } if (code.Length == 14) { var ean13 = new Ean13(); ean13.CountryCode = code.Substring(0, 3); ean13.ManufacturerCode = code.Substring(3, 5); ean13.ProductCode = code.Substring(8, 5); ean13.ChecksumDigit = code.Substring(13, 1); ean13.Scale = 1.5f; System.Drawing.Bitmap bmp = ean13.CreateBitmap(); using (MemoryStream ms = new MemoryStream()) { bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png); byte[] byteImage = ms.ToArray(); Convert.ToBase64String(byteImage); return("data:image/png;base64," + Convert.ToBase64String(byteImage)); } } return(null); }