/// <summary> /// 批量生成二维码并下载 /// </summary> /// <returns></returns> public ActionResult CreateQRCodeAndDownload(int number, string info) { var useCompanyId = Convert.ToInt64(info.Split(',')[0]); var code = Convert.ToString(info.Split(',')[1]); var byteList = new List <byte[]>(); var fileNameList = new List <string>(); var codeList = new List <string>(); var logoImg = Image.FromFile(Server.MapPath("/") + "logo/zdLogo.png"); var fontImg = Image.FromFile(Server.MapPath("/") + "logo/font.png"); var count = 0L; using (var db = new MbContext()) { var qrCodeCount = db.QrCodeCount.FirstOrDefault(x => x.CompanyId == useCompanyId); if (qrCodeCount == null) { qrCodeCount = new QrCodeCount(); qrCodeCount.Count = 0; qrCodeCount.CompanyId = useCompanyId; qrCodeCount.LastUpdateTime = DateTime.Now; db.QrCodeCount.Add(qrCodeCount); } qrCodeCount.Count += number; qrCodeCount.LastUpdateTime = DateTime.Now; count = qrCodeCount.Count; db.SaveChanges(); } for (var i = 0; i < number; i++) { var cd = string.Format("{0}{1}", code, (count - number + i + 1).ToString().PadLeft(6, '0')); fileNameList.Add(cd); byteList.Add(QRCodeHelper.GetCode(cd, logoImg, fontImg)); codeList.Add(cd); } EquipmentSvr.Instance.CreateQRCode(codeList, useCompanyId); DownZip(byteList, fileNameList, "NewQRCode"); return(RedirectToAction("Index")); }
/// <summary> /// 下载二维码 /// </summary> public ActionResult DownloadQRCodePic() { var strFileName = "QRCode"; if (Request["QRCodeUrl"] == null) { return(RedirectToAction("Index")); } else { var picList = Request["QRCodeUrl"].Split(','); var logoImg = Image.FromFile(Server.MapPath("/") + "logo/zdLogo.png"); var fontImg = Image.FromFile(Server.MapPath("/") + "logo/font.png"); var byteList = new List <byte[]>(); var fileNameList = new List <string>(); foreach (var item in picList) { byteList.Add(QRCodeHelper.GetCode(item, logoImg, fontImg)); fileNameList.Add(item); } DownZip(byteList, fileNameList, strFileName); return(RedirectToAction("Index")); } }