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); + }; }