@@ -7,6 +7,7 @@ using System.Collections.Generic; | |||||
using System.Linq; | using System.Linq; | ||||
using Learun.Application.Base.SystemModule; | using Learun.Application.Base.SystemModule; | ||||
using Learun.Application.Organization; | using Learun.Application.Organization; | ||||
using ZipOneCode.ZipProvider; | |||||
namespace Learun.Application.Web.Areas.AssetManagementSystem.Controllers | namespace Learun.Application.Web.Areas.AssetManagementSystem.Controllers | ||||
{ | { | ||||
@@ -368,6 +369,52 @@ 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() | |||||
{ | |||||
//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"); | |||||
} | |||||
return Success("操作成功!", dArr); | |||||
} | |||||
//todo:下载 | |||||
[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 | ||||
} | } | ||||
@@ -97,6 +97,9 @@ | |||||
<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> | ||||
<a id="lr_exportexcel" class="btn btn-default"><i class="fa fa-sign-out"></i> 导出</a> | <a id="lr_exportexcel" class="btn btn-default"><i class="fa fa-sign-out"></i> 导出</a> | ||||
</div> | </div> | ||||
<div class=" btn-group btn-group-sm"> | |||||
<a id="lr_getqrcode" class="btn btn-default"><i class="fa fa-plus"></i> 生成二维码</a> | |||||
</div> | |||||
</div> | </div> | ||||
</div> | </div> | ||||
<div class="lr-layout-body" id="gridtable"></div> | <div class="lr-layout-body" id="gridtable"></div> | ||||
@@ -241,6 +241,21 @@ var bootstrap = function ($, learun) { | |||||
$('#lr_exportexcel').on('click', function () { | $('#lr_exportexcel').on('click', function () { | ||||
page.exportExcel(); | page.exportExcel(); | ||||
}); | }); | ||||
//生成二维码 | |||||
$('#lr_getqrcode').on('click', function () { | |||||
learun.postForm(top.$.rootUrl + '/AssetManagementSystem/Ass_AssetsInfoItem/GetQRCode', { }, function (res) { | |||||
if (res && res.code == "200") { | |||||
//下载文件 | |||||
//只下载一个??? | |||||
//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 () { | ||||
@@ -69,6 +69,18 @@ | |||||
<publisherPolicy apply="no" /> | <publisherPolicy apply="no" /> | ||||
<assemblyIdentity name="Oracle.ManagedDataAccess" publicKeyToken="89b483f429c47342" culture="neutral" /> | <assemblyIdentity name="Oracle.ManagedDataAccess" publicKeyToken="89b483f429c47342" culture="neutral" /> | ||||
</dependentAssembly> | </dependentAssembly> | ||||
<dependentAssembly> | |||||
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> | |||||
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" /> | |||||
</dependentAssembly> | |||||
<dependentAssembly> | |||||
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> | |||||
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" /> | |||||
</dependentAssembly> | |||||
<dependentAssembly> | |||||
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> | |||||
<bindingRedirect oldVersion="0.0.0.0-4.0.6.0" newVersion="4.0.6.0" /> | |||||
</dependentAssembly> | |||||
</assemblyBinding> | </assemblyBinding> | ||||
</runtime> | </runtime> | ||||
<system.webServer> | <system.webServer> | ||||
@@ -6,6 +6,18 @@ | |||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> | <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> | ||||
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" /> | <bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" /> | ||||
</dependentAssembly> | </dependentAssembly> | ||||
<dependentAssembly> | |||||
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> | |||||
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" /> | |||||
</dependentAssembly> | |||||
<dependentAssembly> | |||||
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> | |||||
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" /> | |||||
</dependentAssembly> | |||||
<dependentAssembly> | |||||
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> | |||||
<bindingRedirect oldVersion="0.0.0.0-4.0.6.0" newVersion="4.0.6.0" /> | |||||
</dependentAssembly> | |||||
</assemblyBinding> | </assemblyBinding> | ||||
</runtime> | </runtime> | ||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /></startup></configuration> | <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /></startup></configuration> |
@@ -6,6 +6,18 @@ | |||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> | <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> | ||||
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" /> | <bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" /> | ||||
</dependentAssembly> | </dependentAssembly> | ||||
<dependentAssembly> | |||||
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> | |||||
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" /> | |||||
</dependentAssembly> | |||||
<dependentAssembly> | |||||
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> | |||||
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" /> | |||||
</dependentAssembly> | |||||
<dependentAssembly> | |||||
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> | |||||
<bindingRedirect oldVersion="0.0.0.0-4.0.6.0" newVersion="4.0.6.0" /> | |||||
</dependentAssembly> | |||||
</assemblyBinding> | </assemblyBinding> | ||||
</runtime> | </runtime> | ||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /></startup></configuration> | <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /></startup></configuration> |
@@ -81,6 +81,9 @@ | |||||
<Reference Include="Microsoft.CSharp" /> | <Reference Include="Microsoft.CSharp" /> | ||||
<Reference Include="System.Data" /> | <Reference Include="System.Data" /> | ||||
<Reference Include="System.Xml" /> | <Reference Include="System.Xml" /> | ||||
<Reference Include="ThoughtWorks.QRCode, Version=1.0.4778.30637, Culture=neutral, processorArchitecture=MSIL"> | |||||
<HintPath>..\..\..\packages\ThoughtWorks.QRCode.1.1.0\lib\ThoughtWorks.QRCode.dll</HintPath> | |||||
</Reference> | |||||
<Reference Include="Yahoo.Yui.Compressor"> | <Reference Include="Yahoo.Yui.Compressor"> | ||||
<HintPath>..\..\..\packages\YUICompressor.NET.2.7.0.0\lib\NET20\Yahoo.Yui.Compressor.dll</HintPath> | <HintPath>..\..\..\packages\YUICompressor.NET.2.7.0.0\lib\NET20\Yahoo.Yui.Compressor.dll</HintPath> | ||||
</Reference> | </Reference> | ||||
@@ -128,8 +131,10 @@ | |||||
<Compile Include="Ueditor\UeditorPathFormatter.cs" /> | <Compile Include="Ueditor\UeditorPathFormatter.cs" /> | ||||
<Compile Include="Ueditor\UeditorUploadConfig.cs" /> | <Compile Include="Ueditor\UeditorUploadConfig.cs" /> | ||||
<Compile Include="Ueditor\UeditorUploadResult.cs" /> | <Compile Include="Ueditor\UeditorUploadResult.cs" /> | ||||
<Compile Include="Web\QRCodeHelper.cs" /> | |||||
<Compile Include="Web\CodeRuleEnum.cs" /> | <Compile Include="Web\CodeRuleEnum.cs" /> | ||||
<Compile Include="Web\HttpMethods.cs" /> | <Compile Include="Web\HttpMethods.cs" /> | ||||
<Compile Include="Web\ZipHelper.cs" /> | |||||
<Compile Include="Web\JsCssHelper.cs" /> | <Compile Include="Web\JsCssHelper.cs" /> | ||||
<Compile Include="Web\FilterMode.cs" /> | <Compile Include="Web\FilterMode.cs" /> | ||||
<Compile Include="Web\LoginUserInfo.cs" /> | <Compile Include="Web\LoginUserInfo.cs" /> | ||||
@@ -0,0 +1,115 @@ | |||||
using System; | |||||
using System.Web; | |||||
using ThoughtWorks.QRCode.Codec; | |||||
using ThoughtWorks.QRCode.Codec.Data; | |||||
using ThoughtWorks.QRCode.Codec.Util; | |||||
using System.IO; | |||||
using System.Text; | |||||
using System.Drawing; | |||||
using System.Drawing.Drawing2D; | |||||
namespace Learun.Util | |||||
{ | |||||
public class QRCodeHelper | |||||
{ | |||||
/// <summary> | |||||
/// 生成带图片的二维码 | |||||
/// </summary> | |||||
/// <param name="qrcodeText">二维码内容</param> | |||||
/// <param name="imagePath">二维码上图片地址</param> | |||||
public static string ProcessRequest(string qrcodeText,string imagePath,string savePath) | |||||
{ | |||||
//最终图片保存路径 | |||||
var resultImgPath = string.Empty; | |||||
if (!string.IsNullOrEmpty(qrcodeText)) | |||||
{ | |||||
QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(); | |||||
qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE; | |||||
qrCodeEncoder.QRCodeScale = 4; | |||||
qrCodeEncoder.QRCodeVersion = 8; | |||||
qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M; | |||||
System.Drawing.Image image = qrCodeEncoder.Encode(qrcodeText); | |||||
System.IO.MemoryStream MStream = new System.IO.MemoryStream(); | |||||
image.Save(MStream, System.Drawing.Imaging.ImageFormat.Png); | |||||
System.IO.MemoryStream MStream1 = new System.IO.MemoryStream(); | |||||
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)) | |||||
{ | |||||
System.IO.Directory.CreateDirectory(imgPath); | |||||
} | |||||
img.Save(System.IO.Path.Combine(imgPath, qrcodeText+".png"), System.Drawing.Imaging.ImageFormat.Png); | |||||
resultImgPath = imgPath; | |||||
//HttpContext.Current.Response.ClearContent(); | |||||
//HttpContext.Current.Response.ContentType = "image/png"; | |||||
//HttpContext.Current.Response.BinaryWrite(MStream1.ToArray()); | |||||
//image.Dispose(); | |||||
MStream.Dispose(); | |||||
MStream1.Dispose(); | |||||
} | |||||
//HttpContext.Current.Response.Flush(); | |||||
//HttpContext.Current.Response.End(); | |||||
return resultImgPath; | |||||
} | |||||
/// <summary> | |||||
/// 调用此函数后使此两种图片合并,类似相册,有个 | |||||
/// 背景图,中间贴自己的目标图片 | |||||
/// </summary> | |||||
/// <param name="imgBack">粘贴的源图片</param> | |||||
/// <param name="destImg">粘贴的目标图片</param> | |||||
public static Image CombinImage(Image imgBack, string destImg) | |||||
{ | |||||
Image img = Image.FromFile(destImg); //照片图片 | |||||
if (img.Height != 65 || img.Width != 65) | |||||
{ | |||||
img = KiResizeImage(img, 65, 65, 0); | |||||
} | |||||
Graphics g = Graphics.FromImage(imgBack); | |||||
g.DrawImage(imgBack, 0, 0, imgBack.Width, imgBack.Height); | |||||
//g.DrawImage(imgBack, 0, 0, 相框宽, 相框高); | |||||
//g.FillRectangle(System.Drawing.Brushes.White, imgBack.Width / 2 - img.Width / 2 - 1, imgBack.Width / 2 - img.Width / 2 - 1,1,1);//相片四周刷一层黑色边框 | |||||
//g.DrawImage(img, 照片与相框的左边距, 照片与相框的上边距, 照片宽, 照片高); | |||||
g.DrawImage(img, imgBack.Width / 2 - img.Width / 2, imgBack.Width / 2 - img.Width / 2, img.Width, img.Height); | |||||
GC.Collect(); | |||||
return imgBack; | |||||
} | |||||
/// <summary> | |||||
/// Resize图片 | |||||
/// </summary> | |||||
/// <param name="bmp">原始Bitmap</param> | |||||
/// <param name="newW">新的宽度</param> | |||||
/// <param name="newH">新的高度</param> | |||||
/// <param name="Mode">保留着,暂时未用</param> | |||||
/// <returns>处理以后的图片</returns> | |||||
public static Image KiResizeImage(Image bmp, int newW, int newH, int Mode) | |||||
{ | |||||
try | |||||
{ | |||||
Image b = new Bitmap(newW, newH); | |||||
Graphics g = Graphics.FromImage(b); | |||||
// 插值算法的质量 | |||||
g.InterpolationMode = InterpolationMode.HighQualityBicubic; | |||||
g.DrawImage(bmp, new Rectangle(0, 0, newW, newH), new Rectangle(0, 0, bmp.Width, bmp.Height), GraphicsUnit.Pixel); | |||||
g.Dispose(); | |||||
return b; | |||||
} | |||||
catch | |||||
{ | |||||
return null; | |||||
} | |||||
} | |||||
public bool IsReusable | |||||
{ | |||||
get | |||||
{ | |||||
return false; | |||||
} | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,73 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.IO; | |||||
using System.Diagnostics; | |||||
using ICSharpCode.SharpZipLib; | |||||
using ICSharpCode.SharpZipLib.Zip; | |||||
using ICSharpCode.SharpZipLib.Checksums; | |||||
using ICSharpCode.SharpZipLib.Core; | |||||
namespace ZipOneCode.ZipProvider | |||||
{ | |||||
public class ZipHelper | |||||
{ | |||||
/// <summary> | |||||
/// 压缩文件 | |||||
/// </summary> | |||||
/// <param name="sourceFilePath"></param> | |||||
/// <param name="destinationZipFilePath"></param> | |||||
public static void CreateZip(string sourceFilePath, string destinationZipFilePath) | |||||
{ | |||||
if (sourceFilePath[sourceFilePath.Length - 1] != System.IO.Path.DirectorySeparatorChar) | |||||
sourceFilePath += System.IO.Path.DirectorySeparatorChar; | |||||
ZipOutputStream zipStream = new ZipOutputStream(File.Create(destinationZipFilePath)); | |||||
zipStream.SetLevel(6); // 压缩级别 0-9 | |||||
CreateZipFiles(sourceFilePath, zipStream, sourceFilePath); | |||||
zipStream.Finish(); | |||||
zipStream.Close(); | |||||
} | |||||
/// <summary> | |||||
/// 递归压缩文件 | |||||
/// </summary> | |||||
/// <param name="sourceFilePath">待压缩的文件或文件夹路径</param> | |||||
/// <param name="zipStream">打包结果的zip文件路径(类似 D:\WorkSpace\a.zip),全路径包括文件名和.zip扩展名</param> | |||||
/// <param name="staticFile"></param> | |||||
private static void CreateZipFiles(string sourceFilePath, ZipOutputStream zipStream, string staticFile) | |||||
{ | |||||
Crc32 crc = new Crc32(); | |||||
string[] filesArray = Directory.GetFileSystemEntries(sourceFilePath); | |||||
foreach (string file in filesArray) | |||||
{ | |||||
if (Directory.Exists(file)) //如果当前是文件夹,递归 | |||||
{ | |||||
CreateZipFiles(file, zipStream, staticFile); | |||||
} | |||||
else //如果是文件,开始压缩 | |||||
{ | |||||
FileStream fileStream = File.OpenRead(file); | |||||
byte[] buffer = new byte[fileStream.Length]; | |||||
fileStream.Read(buffer, 0, buffer.Length); | |||||
string tempFile = file.Substring(staticFile.LastIndexOf("\\") + 1); | |||||
ZipEntry entry = new ZipEntry(tempFile); | |||||
entry.DateTime = DateTime.Now; | |||||
entry.Size = fileStream.Length; | |||||
fileStream.Close(); | |||||
crc.Reset(); | |||||
crc.Update(buffer); | |||||
entry.Crc = crc.Value; | |||||
zipStream.PutNextEntry(entry); | |||||
zipStream.Write(buffer, 0, buffer.Length); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} |
@@ -7,5 +7,6 @@ | |||||
<package id="Newtonsoft.Json" version="12.0.1" targetFramework="net461" /> | <package id="Newtonsoft.Json" version="12.0.1" targetFramework="net461" /> | ||||
<package id="NPOI" version="2.3.0" targetFramework="net45" /> | <package id="NPOI" version="2.3.0" targetFramework="net45" /> | ||||
<package id="SharpZipLib" version="0.86.0" targetFramework="net45" /> | <package id="SharpZipLib" version="0.86.0" targetFramework="net45" /> | ||||
<package id="ThoughtWorks.QRCode" version="1.1.0" targetFramework="net461" /> | |||||
<package id="YUICompressor.NET" version="2.7.0.0" targetFramework="net45" /> | <package id="YUICompressor.NET" version="2.7.0.0" targetFramework="net45" /> | ||||
</packages> | </packages> |
@@ -55,6 +55,7 @@ | |||||
<Compile Include="Properties\AssemblyInfo.cs" /> | <Compile Include="Properties\AssemblyInfo.cs" /> | ||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
<None Include="app.config" /> | |||||
<None Include="packages.config" /> | <None Include="packages.config" /> | ||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
@@ -0,0 +1,11 @@ | |||||
<?xml version="1.0" encoding="utf-8"?> | |||||
<configuration> | |||||
<runtime> | |||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> | |||||
<dependentAssembly> | |||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> | |||||
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" /> | |||||
</dependentAssembly> | |||||
</assemblyBinding> | |||||
</runtime> | |||||
</configuration> |