Browse Source

1. 生產履歷-TestLog 新增檔案下載及修改按鈕名稱(測試項目)

PTD
Sai 1 year ago
parent
commit
37c4a2c891
  1. 31
      AMESCoreStudio.Web/Controllers/PCSController.cs
  2. 16
      AMESCoreStudio.Web/Views/PCS/PCS009R.cshtml

31
AMESCoreStudio.Web/Controllers/PCSController.cs

@ -25,7 +25,7 @@ using Microsoft.Extensions.Configuration;
using ClosedXML.Excel; using ClosedXML.Excel;
using Microsoft.VisualBasic; using Microsoft.VisualBasic;
using AMESCoreStudio.WebApi.Models.SYS; using AMESCoreStudio.WebApi.Models.SYS;
using System.IO.Pipes;
namespace AMESCoreStudio.Web.Controllers namespace AMESCoreStudio.Web.Controllers
{ {
@ -4729,14 +4729,39 @@ namespace AMESCoreStudio.Web.Controllers
string uncPath = $@"{TestLogUncPath}\{id}"; string uncPath = $@"{TestLogUncPath}\{id}";
if (System.IO.File.Exists(uncPath)) 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; ViewBag.Log = fileContent;
//// 下載
//else
//{
// return File(fileStream, "text/plain", type);
//}
} }
return View(); return View();
} }
/// <summary>
/// 檔案下載
/// </summary>
/// <param name="Path">路徑</param>
/// <param name="FileName">檔名</param>
/// <returns></returns>
public IActionResult PCS009U(string id)
{
string TestLogUncPath = _configuration.GetValue<string>("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 class PCS009TViewModel
{ {
public string Name { get; set; } public string Name { get; set; }

16
AMESCoreStudio.Web/Views/PCS/PCS009R.cshtml

@ -243,6 +243,7 @@
檔案路徑 檔案路徑
</th> </th>
<th style="width:70px;"></th> <th style="width:70px;"></th>
<th style="width:70px;"></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -266,7 +267,11 @@
<a style="cursor: pointer;" onclick='show("@index.FilePath");'>@index.FileName</a> <a style="cursor: pointer;" onclick='show("@index.FilePath");'>@index.FileName</a>
</td> </td>
<td> <td>
<a class="layui-btn layui-btn-primary layui-border-black layui-btn-sm" onclick='testLog(@index.TestId);'>測試Log</a> <input type="hidden" id="filePath" name="filePath" value="@index.FilePath">
<a class="layui-btn layui-btn-primary layui-border-blue layui-btn-sm" onclick='Filedownload(this);'>檔案下載</a>
</td>
<td>
<a class="layui-btn layui-btn-primary layui-border-black layui-btn-sm" onclick='testLog(@index.TestId);'>測試項目</a>
</td> </td>
</tr> </tr>
} }
@ -572,5 +577,14 @@
}); });
}); });
}; };
// 檔案下載
function Filedownload(obj) {
var FileName = $(obj).closest("TR").find('input[id*=filePath]').val();
let Path = FileName.replace('&#92;', '/');
filePath = `/PCS/PCS009U?id=${Path}`;
console.log(filePath);
$(obj).attr("href", filePath);
};
</script> </script>
} }

Loading…
Cancel
Save