From 6bc3e98540ffeca4831591b0d39db08f5e12ee60 Mon Sep 17 00:00:00 2001 From: dyy <807692433@qq.com> Date: Tue, 21 Jun 2022 10:32:06 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=A2=9E=E5=8A=A0=E3=80=91=E5=9C=A8?= =?UTF-8?q?=E5=86=8C=E7=99=BB=E8=AE=B0=E6=98=8E=E7=BB=86=EF=BC=9A=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E2=80=9C=E6=89=B9=E9=87=8F=E7=94=9F=E6=88=90=E4=BA=8C?= =?UTF-8?q?=E7=BB=B4=E7=A0=81=E2=80=9D=E5=8A=9F=E8=83=BD=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E2=80=9C=E6=89=93=E5=8D=B0=E6=9D=A1=E7=A0=81=E2=80=9D?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Ass_AssetsInfoItemController.cs | 112 +++++++++++++++++- .../Views/Ass_AssetsInfoItem/Index.cshtml | 2 +- .../Views/Ass_AssetsInfoItem/Index.js | 42 ++++++- .../Views/Ass_AssetsInfoItem/QRPrint.cshtml | 68 ++++++----- .../Ass_AssetsInfoItemEntity.cs | 13 ++ .../Ass_AssetsInfoItemService.cs | 2 +- .../Learun.Util/Web/QRCodeHelper.cs | 34 ++++-- 7 files changed, 229 insertions(+), 44 deletions(-) diff --git a/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/AssetManagementSystem/Controllers/Ass_AssetsInfoItemController.cs b/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/AssetManagementSystem/Controllers/Ass_AssetsInfoItemController.cs index d188756af..c7496d2a1 100644 --- a/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/AssetManagementSystem/Controllers/Ass_AssetsInfoItemController.cs +++ b/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/AssetManagementSystem/Controllers/Ass_AssetsInfoItemController.cs @@ -3,6 +3,11 @@ using System.Data; using Learun.Application.TwoDevelopment.AssetManagementSystem; using System.Web.Mvc; using System.Collections.Generic; +using ZipOneCode.ZipProvider; +using System.Linq; +using System.Drawing; +using System.IO; +using System; namespace Learun.Application.Web.Areas.AssetManagementSystem.Controllers { @@ -64,8 +69,31 @@ namespace Learun.Application.Web.Areas.AssetManagementSystem.Controllers return View(); } [HttpGet] - public ActionResult QRPrint() + public ActionResult QRPrint(string keyValue) { + var lists = new List(); + if (!string.IsNullOrEmpty(keyValue)) + { + foreach (var item in keyValue.Split(',')) + { + var entity = ass_AssetsInfoItemIBLL.GetAss_AssetsInfoItemEntity(item); + if (entity != null) + { + lists.Add(entity); + //读图片 + var d = QRCodeHelper.ProcessRequest(entity.AIId, @"~\Content\images\img1.png", "在册登记明细", entity.AIASSName + entity.AICode); + FileStream fs = new FileStream(d.resultImgPath, FileMode.Open, FileAccess.Read); + int length = (int)fs.Length; + byte[] image = new byte[length]; + fs.Read(image, 0, length); + var src = "data:image/jepg;base64," + Convert.ToBase64String(image); + entity.ImgBase64String = src; + fs.Close(); + } + } + } + ViewBag.Lists = lists; + return View(); } #endregion @@ -225,6 +253,88 @@ namespace Learun.Application.Web.Areas.AssetManagementSystem.Controllers ass_AssetsInfoItemIBLL.SaveEntity(keyValue, entity); return Success("保存成功!"); } + + /// + /// 批量生成二维码 + /// + /// + [HttpPost] + [AjaxOnly] + public ActionResult GetQRCode(string keyValue,Pagination pagination) + { + //TODO:文件夹压缩成zip + //var a = @"D:\Job\test\zip"; + //var aa = string.Format(@"{0}.zip", a); + //ZipHelper.CreateZip(a, aa); + + //TODO:生成带logo二维码 + //var resultImgPath = QRCodeHelper.ProcessRequest("demo", @"~\Content\images\img1.png"); + + //TODO:生成二维码,并打包 + //var dArr = new List(); + //for (int i = 0; i < 5; i++) + //{ + // var d = QRCodeHelper.ProcessRequest("demo" + i, @"~\Content\images\img1.png", "demo" + i); + // if (dArr.IndexOf(d) == -1) + // { + // dArr.Add(d); + // } + //} + //foreach (var item in dArr) + //{ + // ZipHelper.CreateZip(item, item + ".zip"); + //} + + //图片保存文件夹地址 + var dArr = new List(); + //明细数据 + var lists = new List(); + if (!string.IsNullOrEmpty(keyValue)) + { + foreach (var item in keyValue.Split(',')) + { + var entity = ass_AssetsInfoItemIBLL.GetAss_AssetsInfoItemEntity(item); + if (entity != null) + { + lists.Add(entity); + } + } + } + else + { + var data = ass_AssetsInfoItemIBLL.GetPageList(pagination, "{}"); + lists = data.ToList(); + } + + foreach (var item in lists) + { + var d = QRCodeHelper.ProcessRequest(item.AIId, @"~\Content\images\img1.png", "在册登记明细", item.AIASSName + item.AICode); + if (dArr.IndexOf(d.resultImgDirectoryPath) == -1) + { + dArr.Add(d.resultImgDirectoryPath); + } + } + foreach (var item in dArr) + { + ZipHelper.CreateZip(item, item + ".zip"); + } + + return Success("操作成功!二维码图片地址为:" + string.Join(",", dArr),dArr); + + } + /// + /// 批量生成二维码下载 + /// + /// + [HttpPost] + public void DownFile(string path) + { + path = string.Format(@"{0}{1}", path, ".zip"); + if (FileDownHelper.FileExists(path)) + { + FileDownHelper.DownLoadold(path, path.Substring(path.LastIndexOf(@"\") + 1)); + } + } #endregion } diff --git a/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/AssetManagementSystem/Views/Ass_AssetsInfoItem/Index.cshtml b/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/AssetManagementSystem/Views/Ass_AssetsInfoItem/Index.cshtml index 44dae046c..8fbd51da3 100644 --- a/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/AssetManagementSystem/Views/Ass_AssetsInfoItem/Index.cshtml +++ b/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/AssetManagementSystem/Views/Ass_AssetsInfoItem/Index.cshtml @@ -81,7 +81,7 @@  查看使用人员记录 diff --git a/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/AssetManagementSystem/Views/Ass_AssetsInfoItem/Index.js b/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/AssetManagementSystem/Views/Ass_AssetsInfoItem/Index.js index e7d36d6f0..f43014606 100644 --- a/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/AssetManagementSystem/Views/Ass_AssetsInfoItem/Index.js +++ b/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/AssetManagementSystem/Views/Ass_AssetsInfoItem/Index.js @@ -34,7 +34,7 @@ var bootstrap = function ($, learun) { nodeClick: function (item) { page.search({ AIASSClass: item.value }); } - }); + }); $('#multiple_condition_query').lrMultipleQuery(function (queryJson) { page.search(queryJson); }, 400, 400); @@ -65,7 +65,8 @@ var bootstrap = function ($, learun) { height: 80 }); $("#lr_printBar").on('click', function () { - var keyValue = $('#gridtable').jfGridValue('AICode'); + //var keyValue = $('#gridtable').jfGridValue('AICode'); + var keyValue = $('#gridtable').jfGridValue('AIId'); var AName = $('#gridtable').jfGridValue('AIASSName'); if (learun.checkrow(keyValue)) { //todo 打印标签 @@ -86,7 +87,7 @@ var bootstrap = function ($, learun) { learun.layerForm({ id: 'formcardprint', title: '打印二维码', - url: top.$.rootUrl + '/AssetManagementSystem/Ass_AssetsInfoItem/QRPrint?keyValue=' + keyValue+'&aName='+escape(AName), + url: top.$.rootUrl + '/AssetManagementSystem/Ass_AssetsInfoItem/QRPrint?keyValue=' + keyValue + '&aName=' + escape(AName), width: 700, height: 300, btn: null, @@ -184,6 +185,39 @@ var bootstrap = function ($, learun) { } }); + //生成二维码 + $('#lr_getqrcode').on('click', function () { + //console.log($('#gridtable')[0].dfop.running); + var keyValue = $('#gridtable').jfGridValue('AIId'); + //js方法: + //if (keyValue != null && keyValue != "" && keyValue != undefined) { + // //console.log("有选中"); + //} else { + // //console.log("无选中"); + // if ($('#gridtable')[0].dfop.running.rowdata.length > 100) { + // learun.alert.warning("最多可以选择100条数据!"); + // return false; + // } + // var bb = new Array(); + // for (var i = 0; i < $('#gridtable')[0].dfop.running.rowdata.length; i++) { + // bb.push($('#gridtable')[0].dfop.running.rowdata[i]["jfgridRowData"]["AIId"]); + // } + // keyValue = bb.toString(); + //} + + learun.postForm(top.$.rootUrl + '/AssetManagementSystem/Ass_AssetsInfoItem/GetQRCode', { keyValue: keyValue, pagination: $('#gridtable')[0].dfop.running.pageparam }, function (res) { + //console.log(res); + if (res && res.code == "200") { + //top.layer.alert("二维码图片地址为:" + res.data, { icon: 7, title: "提示", yes: function (index) { layer.close(index) } }); + + //下载文件 + for (var i = 0; i < res.data.length; i++) { + learun.download({ url: top.$.rootUrl + '/AssetManagementSystem/Ass_AssetsInfoItem/DownFile', param: { path: res.data[i], __RequestVerificationToken: $.lrToken }, method: 'POST' }); + } + } + }); + }); + }, // 初始化列表 initGird: function () { @@ -377,7 +411,7 @@ var bootstrap = function ($, learun) { mainId: 'AIId', isMultiselect: true, isPage: true, - sidx: 'AICodeNum' + sidx: 'AICodeNum', }); page.search(); }, diff --git a/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/AssetManagementSystem/Views/Ass_AssetsInfoItem/QRPrint.cshtml b/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/AssetManagementSystem/Views/Ass_AssetsInfoItem/QRPrint.cshtml index 5a39f0077..65e547cb4 100644 --- a/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/AssetManagementSystem/Views/Ass_AssetsInfoItem/QRPrint.cshtml +++ b/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/AssetManagementSystem/Views/Ass_AssetsInfoItem/QRPrint.cshtml @@ -1,4 +1,5 @@ - +@using Learun.Application.TwoDevelopment.AssetManagementSystem + @@ -23,38 +24,47 @@ -
-
-
-
+
+ @*
+
+
+
*@ + + @foreach (Ass_AssetsInfoItemEntity item in ViewBag.Lists) + { +
+ +
@item.AIASSName@item.AICode
+
+ } +
-
-
打印
- + function AddPrintContent3() { + $('#btnprint').css('display', 'none') + window.print(); + $('#btnprint').css('display', 'block') + } + \ No newline at end of file diff --git a/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/AssetManagementSystem/Ass_AssetsInfoItem/Ass_AssetsInfoItemEntity.cs b/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/AssetManagementSystem/Ass_AssetsInfoItem/Ass_AssetsInfoItemEntity.cs index 815eafba5..fb6f6b355 100644 --- a/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/AssetManagementSystem/Ass_AssetsInfoItem/Ass_AssetsInfoItemEntity.cs +++ b/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/AssetManagementSystem/Ass_AssetsInfoItem/Ass_AssetsInfoItemEntity.cs @@ -389,6 +389,19 @@ namespace Learun.Application.TwoDevelopment.AssetManagementSystem ///
[NotMapped] public string AIPhoto { get; set; } + + /// + /// 资产名称 + /// + [NotMapped] + public string AName { get; set; } + + /// + /// 批量生成二维码base64字符串 + /// + [NotMapped] + public string ImgBase64String { get; set; } + #endregion } } diff --git a/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/AssetManagementSystem/Ass_AssetsInfoItem/Ass_AssetsInfoItemService.cs b/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/AssetManagementSystem/Ass_AssetsInfoItem/Ass_AssetsInfoItemService.cs index 71697fc80..f103240ec 100644 --- a/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/AssetManagementSystem/Ass_AssetsInfoItem/Ass_AssetsInfoItemService.cs +++ b/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/AssetManagementSystem/Ass_AssetsInfoItem/Ass_AssetsInfoItemService.cs @@ -274,7 +274,7 @@ namespace Learun.Application.TwoDevelopment.AssetManagementSystem t.AContent "); strSql.Append(" FROM Ass_AssetsInfoItem a LEFT JOIN dbo.Ass_AssetsInfo t ON a.AId=t.AId "); - strSql.Append(" WHERE a.AIASSState<>2 "); + strSql.Append(" WHERE (a.AIASSState <> 2 or a.AIASSState is null) "); var queryParam = queryJson.ToJObject(); // 虚拟参数 var dp = new DynamicParameters(new { }); diff --git a/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Util/Learun.Util/Web/QRCodeHelper.cs b/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Util/Learun.Util/Web/QRCodeHelper.cs index c3e30d2b0..0a6b22d4e 100644 --- a/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Util/Learun.Util/Web/QRCodeHelper.cs +++ b/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Util/Learun.Util/Web/QRCodeHelper.cs @@ -7,6 +7,7 @@ using System.IO; using System.Text; using System.Drawing; using System.Drawing.Drawing2D; +using System.Collections.Generic; namespace Learun.Util { @@ -16,11 +17,16 @@ namespace Learun.Util /// 生成带图片的二维码 ///
/// 二维码内容 - /// 二维码上图片地址 - public static string ProcessRequest(string qrcodeText,string imagePath,string savePath) + /// 二维码上logo图片地址 + /// + /// 二维码图片名称 + public static Result ProcessRequest(string qrcodeText,string imagePath,string savePath,string imageName) { //最终图片保存路径 var resultImgPath = string.Empty; + //最终图片文件夹保存路径 + var resultImgDirectoryPath = string.Empty; + if (!string.IsNullOrEmpty(qrcodeText)) { QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(); @@ -35,13 +41,15 @@ namespace Learun.Util CombinImage(image, HttpContext.Current.Server.MapPath(imagePath)).Save(MStream1, System.Drawing.Imaging.ImageFormat.Png); //保存图片到本地文件夹 System.Drawing.Image img = System.Drawing.Image.FromStream(MStream1); - //string imgPath = System.IO.Path.Combine(Config.GetValue("AnnexesFile"), "带logo图片二维码", DateTime.Now.ToString("yyyyMMddHHmm")); - string imgPath = System.IO.Path.Combine(Config.GetValue("AnnexesFile"), "带logo图片二维码", savePath); - if (!System.IO.Directory.Exists(imgPath)) + //string imgDirectoryPath = System.IO.Path.Combine(Config.GetValue("AnnexesFile"), "带logo图片二维码", DateTime.Now.ToString("yyyyMMddHHmm")); + string imgDirectoryPath = System.IO.Path.Combine(Config.GetValue("AnnexesFile"), "带logo图片二维码", savePath); + if (!System.IO.Directory.Exists(imgDirectoryPath)) { - System.IO.Directory.CreateDirectory(imgPath); + System.IO.Directory.CreateDirectory(imgDirectoryPath); } - img.Save(System.IO.Path.Combine(imgPath, qrcodeText+".png"), System.Drawing.Imaging.ImageFormat.Png); + string imgPath = System.IO.Path.Combine(imgDirectoryPath, imageName + ".png"); + img.Save(imgPath, System.Drawing.Imaging.ImageFormat.Png); + resultImgDirectoryPath = imgDirectoryPath; resultImgPath = imgPath; //HttpContext.Current.Response.ClearContent(); @@ -55,7 +63,13 @@ namespace Learun.Util //HttpContext.Current.Response.Flush(); //HttpContext.Current.Response.End(); - return resultImgPath; + var result = new Result() + { + resultImgPath = resultImgPath, + resultImgDirectoryPath = resultImgDirectoryPath + }; + + return result; } /// /// 调用此函数后使此两种图片合并,类似相册,有个 @@ -111,5 +125,9 @@ namespace Learun.Util return false; } } + public class Result { + public string resultImgPath { get; set; } + public string resultImgDirectoryPath { get; set; } + } } } \ No newline at end of file