From 37c4a2c891a53a0b4f6869483b4428c69f497142 Mon Sep 17 00:00:00 2001 From: Sai Date: Wed, 27 Sep 2023 15:16:54 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E7=94=9F=E7=94=A2=E5=B1=A5=E6=AD=B7-TestL?= =?UTF-8?q?og=20=E6=96=B0=E5=A2=9E=E6=AA=94=E6=A1=88=E4=B8=8B=E8=BC=89?= =?UTF-8?q?=E5=8F=8A=E4=BF=AE=E6=94=B9=E6=8C=89=E9=88=95=E5=90=8D=E7=A8=B1?= =?UTF-8?q?(=E6=B8=AC=E8=A9=A6=E9=A0=85=E7=9B=AE)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/PCSController.cs | 33 ++++++++++++++++--- AMESCoreStudio.Web/Views/PCS/PCS009R.cshtml | 18 ++++++++-- 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/AMESCoreStudio.Web/Controllers/PCSController.cs b/AMESCoreStudio.Web/Controllers/PCSController.cs index e74f2eb8..dc8e6137 100644 --- a/AMESCoreStudio.Web/Controllers/PCSController.cs +++ b/AMESCoreStudio.Web/Controllers/PCSController.cs @@ -25,7 +25,7 @@ using Microsoft.Extensions.Configuration; using ClosedXML.Excel; using Microsoft.VisualBasic; using AMESCoreStudio.WebApi.Models.SYS; - +using System.IO.Pipes; namespace AMESCoreStudio.Web.Controllers { @@ -4724,19 +4724,44 @@ namespace AMESCoreStudio.Web.Controllers public IActionResult PCS009V(string id) { - string TestLogUncPath = _configuration.GetValue("TestLogUncPath"); + string TestLogUncPath = _configuration.GetValue("TestLogUncPath"); // UNC路径 string uncPath = $@"{TestLogUncPath}\{id}"; if (System.IO.File.Exists(uncPath)) { - var fileStream = new FileStream(uncPath, FileMode.Open, FileAccess.Read); // 读取文件内容 - string fileContent = System.IO.File.ReadAllText(uncPath); + string fileContent = System.IO.File.ReadAllText(uncPath, System.Text.Encoding.UTF8); ViewBag.Log = fileContent; + //// 下載 + //else + //{ + // return File(fileStream, "text/plain", type); + //} } return View(); } + /// + /// 檔案下載 + /// + /// 路徑 + /// 檔名 + /// + public IActionResult PCS009U(string id) + { + string TestLogUncPath = _configuration.GetValue("TestLogUncPath"); + // UNC路径 + string uncPath = $@"{TestLogUncPath}\{id}"; + string FileName = id.Split(@"/")[1]; + var memoryStream = new MemoryStream(); + using (var stream = new FileStream(uncPath, FileMode.Open, FileAccess.Read)) + { + stream.CopyTo(memoryStream); + memoryStream.Seek(0, SeekOrigin.Begin); + return File(memoryStream, "application/octet-stream", FileName); + } + } + public class PCS009TViewModel { public string Name { get; set; } diff --git a/AMESCoreStudio.Web/Views/PCS/PCS009R.cshtml b/AMESCoreStudio.Web/Views/PCS/PCS009R.cshtml index 0fda977e..052d4858 100644 --- a/AMESCoreStudio.Web/Views/PCS/PCS009R.cshtml +++ b/AMESCoreStudio.Web/Views/PCS/PCS009R.cshtml @@ -243,6 +243,7 @@ 檔案路徑 + @@ -266,7 +267,11 @@ @index.FileName - 測試Log + + 檔案下載 + + + 測試項目 } @@ -554,7 +559,7 @@ fixed: false, //不固定 maxmin: true, content: `/PCS/PCS009T?sn=${@Model.BarCodeNo}&id=${id}` - }); + }); }); }; @@ -572,5 +577,14 @@ }); }); }; + + // 檔案下載 + function Filedownload(obj) { + var FileName = $(obj).closest("TR").find('input[id*=filePath]').val(); + let Path = FileName.replace('\', '/'); + filePath = `/PCS/PCS009U?id=${Path}`; + console.log(filePath); + $(obj).attr("href", filePath); + }; }