@@ -3,6 +3,11 @@ using System.Data; | |||||
using Learun.Application.TwoDevelopment.AssetManagementSystem; | using Learun.Application.TwoDevelopment.AssetManagementSystem; | ||||
using System.Web.Mvc; | using System.Web.Mvc; | ||||
using System.Collections.Generic; | 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 | namespace Learun.Application.Web.Areas.AssetManagementSystem.Controllers | ||||
{ | { | ||||
@@ -64,8 +69,31 @@ namespace Learun.Application.Web.Areas.AssetManagementSystem.Controllers | |||||
return View(); | return View(); | ||||
} | } | ||||
[HttpGet] | [HttpGet] | ||||
public ActionResult QRPrint() | |||||
public ActionResult QRPrint(string keyValue) | |||||
{ | { | ||||
var lists = new List<Ass_AssetsInfoItemEntity>(); | |||||
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(); | return View(); | ||||
} | } | ||||
#endregion | #endregion | ||||
@@ -225,6 +253,88 @@ namespace Learun.Application.Web.Areas.AssetManagementSystem.Controllers | |||||
ass_AssetsInfoItemIBLL.SaveEntity(keyValue, entity); | ass_AssetsInfoItemIBLL.SaveEntity(keyValue, entity); | ||||
return Success("保存成功!"); | return Success("保存成功!"); | ||||
} | } | ||||
/// <summary> | |||||
/// 批量生成二维码 | |||||
/// <summary> | |||||
/// <returns></returns> | |||||
[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<string>(); | |||||
//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<string>(); | |||||
//明细数据 | |||||
var lists = new List<Ass_AssetsInfoItemEntity>(); | |||||
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); | |||||
} | |||||
/// <summary> | |||||
/// 批量生成二维码下载 | |||||
/// </summary> | |||||
/// <param name="path"></param> | |||||
[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 | #endregion | ||||
} | } | ||||
@@ -81,7 +81,7 @@ | |||||
<a id="lr_usedetail" class="btn btn-default"><i class="fa fa-bars"></i> 查看使用人员记录</a> | <a id="lr_usedetail" class="btn btn-default"><i class="fa fa-bars"></i> 查看使用人员记录</a> | ||||
</div> | </div> | ||||
<div class=" btn-group btn-group-sm"> | <div class=" btn-group btn-group-sm"> | ||||
<a id="lr_getqrcode" class="btn btn-default"><i class="fa fa-plus"></i> 生成二维码</a> | |||||
<a id="lr_getqrcode" class="btn btn-default"><i class="fa fa-plus"></i> 批量生成二维码</a> | |||||
</div> | </div> | ||||
</div> | </div> | ||||
</div> | </div> | ||||
@@ -34,7 +34,7 @@ var bootstrap = function ($, learun) { | |||||
nodeClick: function (item) { | nodeClick: function (item) { | ||||
page.search({ AIASSClass: item.value }); | page.search({ AIASSClass: item.value }); | ||||
} | } | ||||
}); | |||||
}); | |||||
$('#multiple_condition_query').lrMultipleQuery(function (queryJson) { | $('#multiple_condition_query').lrMultipleQuery(function (queryJson) { | ||||
page.search(queryJson); | page.search(queryJson); | ||||
}, 400, 400); | }, 400, 400); | ||||
@@ -65,7 +65,8 @@ var bootstrap = function ($, learun) { | |||||
height: 80 | height: 80 | ||||
}); | }); | ||||
$("#lr_printBar").on('click', function () { | $("#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'); | var AName = $('#gridtable').jfGridValue('AIASSName'); | ||||
if (learun.checkrow(keyValue)) { | if (learun.checkrow(keyValue)) { | ||||
//todo 打印标签 | //todo 打印标签 | ||||
@@ -86,7 +87,7 @@ var bootstrap = function ($, learun) { | |||||
learun.layerForm({ | learun.layerForm({ | ||||
id: 'formcardprint', | id: 'formcardprint', | ||||
title: '打印二维码', | 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, | width: 700, | ||||
height: 300, | height: 300, | ||||
btn: null, | 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 () { | initGird: function () { | ||||
@@ -377,7 +411,7 @@ var bootstrap = function ($, learun) { | |||||
mainId: 'AIId', | mainId: 'AIId', | ||||
isMultiselect: true, | isMultiselect: true, | ||||
isPage: true, | isPage: true, | ||||
sidx: 'AICodeNum' | |||||
sidx: 'AICodeNum', | |||||
}); | }); | ||||
page.search(); | page.search(); | ||||
}, | }, | ||||
@@ -1,4 +1,5 @@ | |||||
<!DOCTYPE html> | |||||
@using Learun.Application.TwoDevelopment.AssetManagementSystem | |||||
<!DOCTYPE html> | |||||
<html> | <html> | ||||
@@ -23,38 +24,47 @@ | |||||
</head> | </head> | ||||
<body style=""> | <body style=""> | ||||
<div id="qrcodeBox" style="text-align:center;margin-top:20px;"> | |||||
<div class="qrcodeBox" style="display:inline-block"> | |||||
<div id="qrcode" style="margin:0 auto 5px;"></div> | |||||
<div class="qrcodeTxt" style="font-size:12px;"></div> | |||||
<div id="qrcodeBox" style="text-align:center;margin-top:20px;"> | |||||
@*<div class="qrcodeBox" style="display:inline-block"> | |||||
<div id="qrcode" style="margin:0 auto 5px;"></div> | |||||
<div class="qrcodeTxt" style="font-size:12px;"></div> | |||||
</div>*@ | |||||
@foreach (Ass_AssetsInfoItemEntity item in ViewBag.Lists) | |||||
{ | |||||
<div style="margin-bottom:20px;"> | |||||
<img src="@item.ImgBase64String"/> | |||||
<div style="font-size:12px;">@item.AIASSName@item.AICode</div> | |||||
</div> | |||||
} | |||||
</div> | </div> | ||||
</div> | |||||
<div id="btnprint" type="button" class="btns" value="打印">打印</div> | |||||
<script> | |||||
//标签打印 | |||||
var qrcode = new QRCode(document.getElementById("qrcode"), { | |||||
width: 80, | |||||
height: 80 | |||||
}); | |||||
var keyValue = request('keyValue');//二维码 | |||||
var aName = request('aName'); | |||||
$('.qrcodeTxt').html(unescape( aName)); | |||||
$(function () { | |||||
qrcode.makeCode(keyValue); | |||||
$("#btnprint").on("click", function () { | |||||
AddPrintContent3() | |||||
}); | |||||
<div id="btnprint" type="button" class="btns" value="打印">打印</div> | |||||
<script> | |||||
//标签打印 | |||||
//var qrcode = new QRCode(document.getElementById("qrcode"), { | |||||
// width: 142, | |||||
// height: 142 | |||||
//}); | |||||
//var keyValue = request('keyValue');//二维码 | |||||
//var aName = request('aName'); | |||||
//$('.qrcodeTxt').html(unescape(aName)); | |||||
$(function () { | |||||
//qrcode.makeCode(keyValue); | |||||
$("#btnprint").on("click", function () { | |||||
AddPrintContent3() | |||||
}); | |||||
}); | |||||
// 打印表单 | |||||
}); | |||||
// 打印表单 | |||||
function AddPrintContent3() { | |||||
$('#btnprint').css('display', 'none') | |||||
window.print(); | |||||
$('#btnprint').css('display', 'block') | |||||
} | |||||
</script> | |||||
function AddPrintContent3() { | |||||
$('#btnprint').css('display', 'none') | |||||
window.print(); | |||||
$('#btnprint').css('display', 'block') | |||||
} | |||||
</script> | |||||
</body> | </body> | ||||
</html> | </html> |
@@ -389,6 +389,19 @@ namespace Learun.Application.TwoDevelopment.AssetManagementSystem | |||||
/// </summary> | /// </summary> | ||||
[NotMapped] | [NotMapped] | ||||
public string AIPhoto { get; set; } | public string AIPhoto { get; set; } | ||||
/// <summary> | |||||
/// 资产名称 | |||||
/// </summary> | |||||
[NotMapped] | |||||
public string AName { get; set; } | |||||
/// <summary> | |||||
/// 批量生成二维码base64字符串 | |||||
/// </summary> | |||||
[NotMapped] | |||||
public string ImgBase64String { get; set; } | |||||
#endregion | #endregion | ||||
} | } | ||||
} | } | ||||
@@ -274,7 +274,7 @@ namespace Learun.Application.TwoDevelopment.AssetManagementSystem | |||||
t.AContent | t.AContent | ||||
"); | "); | ||||
strSql.Append(" FROM Ass_AssetsInfoItem a LEFT JOIN dbo.Ass_AssetsInfo t ON a.AId=t.AId "); | 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 queryParam = queryJson.ToJObject(); | ||||
// 虚拟参数 | // 虚拟参数 | ||||
var dp = new DynamicParameters(new { }); | var dp = new DynamicParameters(new { }); | ||||
@@ -7,6 +7,7 @@ using System.IO; | |||||
using System.Text; | using System.Text; | ||||
using System.Drawing; | using System.Drawing; | ||||
using System.Drawing.Drawing2D; | using System.Drawing.Drawing2D; | ||||
using System.Collections.Generic; | |||||
namespace Learun.Util | namespace Learun.Util | ||||
{ | { | ||||
@@ -16,11 +17,16 @@ namespace Learun.Util | |||||
/// 生成带图片的二维码 | /// 生成带图片的二维码 | ||||
/// </summary> | /// </summary> | ||||
/// <param name="qrcodeText">二维码内容</param> | /// <param name="qrcodeText">二维码内容</param> | ||||
/// <param name="imagePath">二维码上图片地址</param> | |||||
public static string ProcessRequest(string qrcodeText,string imagePath,string savePath) | |||||
/// <param name="imagePath">二维码上logo图片地址</param> | |||||
/// <param name="savePath"></param> | |||||
/// <param name="imageName">二维码图片名称</param> | |||||
public static Result ProcessRequest(string qrcodeText,string imagePath,string savePath,string imageName) | |||||
{ | { | ||||
//最终图片保存路径 | //最终图片保存路径 | ||||
var resultImgPath = string.Empty; | var resultImgPath = string.Empty; | ||||
//最终图片文件夹保存路径 | |||||
var resultImgDirectoryPath = string.Empty; | |||||
if (!string.IsNullOrEmpty(qrcodeText)) | if (!string.IsNullOrEmpty(qrcodeText)) | ||||
{ | { | ||||
QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(); | 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); | CombinImage(image, HttpContext.Current.Server.MapPath(imagePath)).Save(MStream1, System.Drawing.Imaging.ImageFormat.Png); | ||||
//保存图片到本地文件夹 | //保存图片到本地文件夹 | ||||
System.Drawing.Image img = System.Drawing.Image.FromStream(MStream1); | 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; | resultImgPath = imgPath; | ||||
//HttpContext.Current.Response.ClearContent(); | //HttpContext.Current.Response.ClearContent(); | ||||
@@ -55,7 +63,13 @@ namespace Learun.Util | |||||
//HttpContext.Current.Response.Flush(); | //HttpContext.Current.Response.Flush(); | ||||
//HttpContext.Current.Response.End(); | //HttpContext.Current.Response.End(); | ||||
return resultImgPath; | |||||
var result = new Result() | |||||
{ | |||||
resultImgPath = resultImgPath, | |||||
resultImgDirectoryPath = resultImgDirectoryPath | |||||
}; | |||||
return result; | |||||
} | } | ||||
/// <summary> | /// <summary> | ||||
/// 调用此函数后使此两种图片合并,类似相册,有个 | /// 调用此函数后使此两种图片合并,类似相册,有个 | ||||
@@ -111,5 +125,9 @@ namespace Learun.Util | |||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
public class Result { | |||||
public string resultImgPath { get; set; } | |||||
public string resultImgDirectoryPath { get; set; } | |||||
} | |||||
} | } | ||||
} | } |