示例#1
0
        public static IHtmlString GenerateQrCodeForAdmin(this HtmlHelper html, int offerId, string url, string alt = "QR code", int height = 75, int width = 75, int margin = 0)
        {
            var qrWriter = new BarcodeWriter();

            qrWriter.Format  = BarcodeFormat.QR_CODE;
            qrWriter.Options = new EncodingOptions()
            {
                Height = height, Width = width, Margin = margin
            };

            using (var q = qrWriter.Write(url))
            {
                using (var ms = new MemoryStream())
                {
                    q.Save(ms, ImageFormat.Png);
                    var img = new TagBuilder("img");
                    img.Attributes.Add("src", String.Format("data:image/png;base64,{0}", Convert.ToBase64String(ms.ToArray())));
                    img.Attributes.Add("alt", Convert.ToString(offerId));

                    var    serverPath = System.Web.HttpContext.Current.Server.MapPath("~/Uploads/QRCodes");
                    string fileName   = string.Concat(offerId, ".png");
                    string path       = Path.Combine(serverPath, fileName);
                    if (!File.Exists(path))
                    {
                        FileSaveHelper.SaveBytesToFile(ms.ToArray(), path);
                    }

                    return(MvcHtmlString.Create(img.ToString(TagRenderMode.SelfClosing)));
                }
            }
        }
示例#2
0
        public static void GenerateAndSaveQrCode(string appUserEmail, int swapId, string url, string alt = "QR code", int height = 75, int width = 75, int margin = 0)
        {
            var qrWriter = new BarcodeWriter();

            qrWriter.Format  = BarcodeFormat.QR_CODE;
            qrWriter.Options = new EncodingOptions()
            {
                Height = height, Width = width, Margin = margin
            };

            using (var q = qrWriter.Write(url))
            {
                using (var ms = new MemoryStream())
                {
                    q.Save(ms, ImageFormat.Png);
                    //var img = new TagBuilder("img");
                    //img.Attributes.Add("src", String.Format("data:image/png;base64,{0}", Convert.ToBase64String(ms.ToArray())));
                    //img.Attributes.Add("alt", alt);

                    var    serverPath = System.Web.HttpContext.Current.Server.MapPath("~/Uploads/QRCodes");
                    string fileName   = string.Concat(swapId, ".png");
                    string path       = Path.Combine(serverPath, fileName);
                    if (!File.Exists(path))
                    {
                        FileSaveHelper.SaveBytesToFile(ms.ToArray(), path);
                    }
                    EmailHelper.EmailAttachement(appUserEmail, "QR Code", "please find the attached QR Code", path);
                }
            }
        }
示例#3
0
        public static string GenerateAndSaveQrCodeForOffer(string appUserEmail, int offerId, string url, string alt = "QR code", int height = 75, int width = 75, int margin = 0)
        {
            var qrWriter = new BarcodeWriter();

            qrWriter.Format  = BarcodeFormat.QR_CODE;
            qrWriter.Options = new EncodingOptions()
            {
                Height = height, Width = width, Margin = margin
            };

            using (var q = qrWriter.Write(url))
            {
                using (var ms = new MemoryStream())
                {
                    q.Save(ms, ImageFormat.Png);
                    var    serverPath = System.Web.HttpContext.Current.Server.MapPath("~/Uploads/QRCodes");
                    string fileName   = string.Concat(offerId, ".png");
                    string path       = Path.Combine(serverPath, fileName);
                    if (!File.Exists(path))
                    {
                        FileSaveHelper.SaveBytesToFile(ms.ToArray(), path);
                    }
                    return(path);
                }
            }
        }