From fba2d43dced6769589bc857d4508bd725bc1794b Mon Sep 17 00:00:00 2001 From: Gitea Date: Mon, 10 Feb 2025 14:53:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E5=90=88=E5=AE=89=E5=8B=A4=E8=AA=BF?= =?UTF-8?q?=E6=95=B4=E7=9A=84=E7=A8=8B=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AMESCoreStudio.Web/AppSetting.cs | 15 +- .../Controllers/FQCController.cs | 153 +++-- .../Controllers/JIGController.cs | 117 ++-- .../Controllers/LABController.cs | 154 ++--- .../Controllers/PCSController.cs | 201 +++--- .../Controllers/REPController.cs | 643 +++++++++--------- .../Controllers/SPCController.cs | 263 ++++--- AMESCoreStudio.Web/Startup.cs | 62 +- AMESCoreStudio.Web/Views/FQC/FQC007D.cshtml | 36 +- AMESCoreStudio.Web/Views/FQC/FQC008.cshtml | 10 +- AMESCoreStudio.Web/Views/JIG/JIG004R.cshtml | 22 +- AMESCoreStudio.Web/Views/PCS/PCS001R.cshtml | 36 +- AMESCoreStudio.Web/Views/PCS/PCS003.cshtml | 68 +- AMESCoreStudio.Web/Views/PCS/PCS005.cshtml | 47 +- AMESCoreStudio.Web/Views/PCS/PCS009R.cshtml | 6 + AMESCoreStudio.Web/Views/PCS/PCS021.cshtml | 76 +-- AMESCoreStudio.Web/Views/PCS/PCS041C.cshtml | 188 ++--- AMESCoreStudio.Web/Views/PTD/PTD002.cshtml | 8 +- AMESCoreStudio.Web/Views/PTD/PTD002Old.cshtml | 6 +- AMESCoreStudio.Web/Views/PTD/PTD006.cshtml | 6 +- AMESCoreStudio.Web/Views/PTD/PTD006Old.cshtml | 4 +- AMESCoreStudio.Web/Views/QRS/QRS014.cshtml | 8 +- AMESCoreStudio.Web/Views/QRS/QRS028A.cshtml | 7 +- AMESCoreStudio.Web/Views/REP/REP001R.cshtml | 155 ++--- AMESCoreStudio.Web/Views/RPT/RPT002.cshtml | 6 +- AMESCoreStudio.Web/Views/SPC/SPC004.cshtml | 54 +- AMESCoreStudio.Web/Views/SPC/SPC005R.cshtml | 184 +++-- AMESCoreStudio.Web/Views/SYS/SYS008.cshtml | 12 +- .../AMES/BarcodeItemsController.cs | 5 +- .../AMES/BarcodeStationController.cs | 7 +- .../AMES/FqcResultMasterController.cs | 10 +- .../Controllers/AMES/WipInfosController.cs | 400 ++++++----- .../Controllers/PTD/PTDController.cs | 38 +- .../Controllers/SYS/UserInfoesController.cs | 3 +- .../DTO/AMES/QRS016Detail.cs | 4 +- .../DTO/AMES/RPT002VIiewDto.cs | 6 +- AMESCoreStudio.WebApi/DTO/AMES/WipQueryDto.cs | 11 + .../Models/AMES/BarcodeInfo.cs | 2 +- .../Models/AMES/FqcInhouseMaster.cs | 2 +- .../Models/AMES/PTD101AMESModel.cs | 24 + AMESCoreStudio.WebApi/Models/AMES/WipInfo.cs | 20 + AMESCoreStudio.WebApi/Models/SYS/UserInfo.cs | 8 +- 42 files changed, 1507 insertions(+), 1580 deletions(-) diff --git a/AMESCoreStudio.Web/AppSetting.cs b/AMESCoreStudio.Web/AppSetting.cs index 085ff190..e5884a41 100644 --- a/AMESCoreStudio.Web/AppSetting.cs +++ b/AMESCoreStudio.Web/AppSetting.cs @@ -8,18 +8,23 @@ namespace AMESCoreStudio.Web public class AppSetting { /// - /// MVC网站访问IP端口 + /// MVC網站訪問地址 /// public string Urls { get; set; } + /// - /// WebApi访问地址 + /// WebApi網站訪問地址 /// public string ApiUrl { get; set; } - //Yiru Add ------------------------------------------------------------------- + /// + /// 倉庫位置 + /// public string Location { get; set; } - //2023-02-12 add + /// + /// + /// public string PTD101Key { get; set; } /// @@ -27,8 +32,6 @@ namespace AMESCoreStudio.Web /// public int FQC014FileSize { get; set; } - //Yiru End ------------------------------------------------------------------- - public static AppSetting Setting { get; set; } = new AppSetting(); } } diff --git a/AMESCoreStudio.Web/Controllers/FQCController.cs b/AMESCoreStudio.Web/Controllers/FQCController.cs index 0b42db28..cd138c77 100644 --- a/AMESCoreStudio.Web/Controllers/FQCController.cs +++ b/AMESCoreStudio.Web/Controllers/FQCController.cs @@ -3,8 +3,6 @@ using AMESCoreStudio.Web.Models; using AMESCoreStudio.WebApi.DTO.AMES; using AMESCoreStudio.WebApi.Enum; using AMESCoreStudio.WebApi.Models.AMES; -using AMESCoreStudio.WebApi.Models.BAS; -//using AspNetCore.Reporting; using Microsoft.Reporting.NETCore; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; @@ -19,6 +17,8 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; +using Microsoft.Extensions.Configuration; +using System.Net.Http; namespace AMESCoreStudio.Web.Controllers @@ -28,15 +28,18 @@ namespace AMESCoreStudio.Web.Controllers /// public class FQCController : Controller { - private readonly ILogger _logger; public readonly IFQC _fqcApi; - private readonly IWebHostEnvironment _env; public readonly IPCS _pcsApi; public readonly IBAS _basApi; public readonly IBLL _bllApi; public readonly ISYS _sysApi; + private readonly ILogger _logger; + private readonly IWebHostEnvironment _env; + private readonly IConfiguration _config; public readonly IESUN _esuncApi; - public FQCController(ILogger logger, IFQC fqcApi, IWebHostEnvironment env, IPCS pcsApi, IBLL bllApi, IBAS basApi, ISYS sysApi, IESUN esuncApi) + + public FQCController(ILogger logger, IFQC fqcApi, IWebHostEnvironment env, IPCS pcsApi, + IBLL bllApi, IBAS basApi, ISYS sysApi, IESUN esuncApi, IConfiguration config) { _logger = logger; _fqcApi = fqcApi; @@ -45,6 +48,7 @@ namespace AMESCoreStudio.Web.Controllers _bllApi = bllApi; _basApi = basApi; _sysApi = sysApi; + _config = config; _esuncApi = esuncApi; } @@ -1481,6 +1485,8 @@ namespace AMESCoreStudio.Web.Controllers private async Task CheckFQCToMail(string Material, string Result, string inhouseNo, int seqID) { var result = await _fqcApi.GetFqcNoticeMailQuery(material: Material, fqcResult: Result, status: "Y"); + var UploadFolderFQCPath = _config["ImagePath:UploadFolderFQCPath"]; + if (result.Data.Count() != 0) { var MailGroup = result.Data.Select(s => s.MailGroup).ToArray(); @@ -1494,8 +1500,7 @@ namespace AMESCoreStudio.Web.Controllers //為避免使用者上傳的檔案名稱發生重複,重新給一個亂數名稱 //NewName = Path.GetRandomFileName() + fileExt; //指定要寫入的路徑、檔名和副檔名 - FilePath = $@"{_env.WebRootPath}\UploadFolder\FQC\Temp"; - var path = $@"{FilePath}\{FileName}"; + var path = UploadFolderFQCPath + FileName; if (!Directory.Exists(FilePath)) { @@ -1539,6 +1544,7 @@ namespace AMESCoreStudio.Web.Controllers var fqcResult = await _fqcApi.GetFqcResultMaster(fqc); if (fqcResult != null) fqcDto.StatusName = fqcResult.QaResult; + ViewBag.FileUploadUrl = _config["ImagePath:FileUploadUrl"]; return View(fqcDto); } @@ -1546,60 +1552,61 @@ namespace AMESCoreStudio.Web.Controllers public async Task FQC007DAsync(FqcDto model, string Result, IFormFile formFile) { FqcResultMaster fqcResultMaster = await _fqcApi.GetFqcResultMaster(model.FqcID); + var rootFolderPath = _config["ImagePath:RootPath"]; + var uploadFolderFQCPath = _config["ImagePath:UploadFolderFQCPath"]; if (fqcResultMaster == null) { ModelState.AddModelError("error", "找不到FQC開單紀錄"); return View("FQC007D", model); } - if (formFile != null) + if (formFile != null && formFile.Length > 0) { - if (formFile.Length > 0) - { - // 檔案上傳 - string FileName = string.Empty; - string NewName = string.Empty; - string FilePath = string.Empty; - //取得使用者上傳檔案的原始檔名 - FileName = Path.GetFileName(formFile.FileName); - //取原始檔名中的副檔名 - //var fileExt = Path.GetExtension(FileName); - //為避免使用者上傳的檔案名稱發生重複,重新給一個亂數名稱 - //NewName = Path.GetRandomFileName() + fileExt; - //指定要寫入的路徑、檔名和副檔名 - FilePath = $@"{_env.WebRootPath}\UploadFolder\FQC\{fqcResultMaster.InhouseNo}-{fqcResultMaster.SeqID}"; - var path = $@"{FilePath}\{FileName}"; + //取得使用者上傳檔案的原始檔名 + var imageName = Path.GetFileName(formFile.FileName); + //指定要寫入的路徑、檔名和副檔名 + var rootPath = $@"{rootFolderPath}\{uploadFolderFQCPath}\{fqcResultMaster.InhouseNo}-{fqcResultMaster.SeqID}"; + var filePath = $@"\{uploadFolderFQCPath}\{fqcResultMaster.InhouseNo}-{fqcResultMaster.SeqID}\"; + var path = $@"{rootPath}\{imageName}"; - if (!System.IO.Directory.Exists(FilePath)) + if (!System.IO.Directory.Exists(rootPath)) + { + try { - System.IO.Directory.CreateDirectory(FilePath); + System.IO.Directory.CreateDirectory(rootPath); } - - using (var stream = new FileStream(path, FileMode.Create)) + catch (Exception ex) { - await formFile.CopyToAsync(stream); + ModelState.AddModelError("error", $"無法建立路徑: {rootPath}, 錯誤: {ex.Message}"); + return BadRequest(ModelState); } + } - FqcResultMasterBlob fqcResultMasterBlob = new FqcResultMasterBlob() - { - FqcID = model.FqcID, - ImageName = FileName, - Filepath = $@"\UploadFolder\FQC\{fqcResultMaster.InhouseNo}-{fqcResultMaster.SeqID}\", - CreateUserID = GetLogInUserID(), - UpdateUserID = GetLogInUserID() - }; + using (var stream = new FileStream(path, FileMode.Create)) + { + await formFile.CopyToAsync(stream); + } - var result = await _fqcApi.PostFqcResultMasterBlob(JsonConvert.SerializeObject(fqcResultMasterBlob)); + FqcResultMasterBlob fqcResultMasterBlob = new FqcResultMasterBlob() + { + FqcID = model.FqcID, + ImageName = imageName, + Filepath = filePath, + CreateUserID = GetLogInUserID(), + UpdateUserID = GetLogInUserID() + }; - if (result.Success) - { - ModelState.AddModelError("error", "上傳成功!"); - } - else - { - ModelState.AddModelError("error", "上傳失敗,錯誤訊息:" + result.Msg); - } + var result = await _fqcApi.PostFqcResultMasterBlob(JsonConvert.SerializeObject(fqcResultMasterBlob)); + + if (result.Success) + { + ModelState.AddModelError("error", "上傳成功!"); } + else + { + ModelState.AddModelError("error", "上傳失敗,錯誤訊息:" + result.Msg); + } + } else { @@ -1615,20 +1622,39 @@ namespace AMESCoreStudio.Web.Controllers /// 路徑 /// 檔名 /// - public async Task FileDownload(string Path, string FileName) + public async Task FileDownload(string fileUrl) { - var path = $@"{_env.WebRootPath}\{Path}{FileName}"; - var memoryStream = new MemoryStream(); - using (var stream = new FileStream(path, FileMode.Open)) + fileUrl = fileUrl.Replace("\\", "/"); + try + { + if (string.IsNullOrEmpty(fileUrl)) + { + return StatusCode(500, $"找不到檔案路徑: {fileUrl}"); + } + + // 使用 HttpClient 從遠端 URL 下載檔案 + using (var httpClient = new HttpClient()) + { + var response = await httpClient.GetAsync(fileUrl); + if (!response.IsSuccessStatusCode) + { + return StatusCode(500, $"使用 HttpClient 從遠端 URL 下載檔案錯誤"); + } + + var fileStream = await response.Content.ReadAsStreamAsync(); + var fileName = Path.GetFileName(new Uri(fileUrl).LocalPath); + var contentType = response.Content.Headers.ContentType?.MediaType ?? "application/octet-stream"; + + return File(fileStream, contentType, fileName); + } + } + catch (Exception ex) { - await stream.CopyToAsync(memoryStream); + return StatusCode(500, $"下載檔案錯誤: {ex.Message}"); } - memoryStream.Seek(0, SeekOrigin.Begin); - string contentType = await GetFileContentTypeAsync(FileName); - // 回傳檔案到 Client 需要附上 Content Type,否則瀏覽器會解析失敗。 - return File(memoryStream, contentType, FileName); } + /// /// 刪除工單檔案 /// @@ -2936,25 +2962,6 @@ namespace AMESCoreStudio.Web.Controllers } - /// - /// 檔案下載 - /// - /// 路徑 - /// 檔名 - /// - public async Task FileDownload_byPath(string Path, string FileName) - { - var path = $@"{Path}{FileName}"; - var memoryStream = new MemoryStream(); - using (var stream = new FileStream(path, FileMode.Open)) - { - await stream.CopyToAsync(memoryStream); - } - memoryStream.Seek(0, SeekOrigin.Begin); - string contentType = await GetFileContentTypeAsync(FileName); - // 回傳檔案到 Client 需要附上 Content Type,否則瀏覽器會解析失敗。 - return File(memoryStream, contentType, FileName); - } #endregion #endregion diff --git a/AMESCoreStudio.Web/Controllers/JIGController.cs b/AMESCoreStudio.Web/Controllers/JIGController.cs index c172e8ee..64a91bb8 100644 --- a/AMESCoreStudio.Web/Controllers/JIGController.cs +++ b/AMESCoreStudio.Web/Controllers/JIGController.cs @@ -5,8 +5,10 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using Newtonsoft.Json; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -24,8 +26,10 @@ namespace AMESCoreStudio.Web.Controllers public readonly ISYS _sysApi; public readonly IPPS _ppsApi; private readonly IWebHostEnvironment _env; + private readonly IConfiguration _config; - public JIGController(ILogger logger, IJIG jigApi, IWHS whsApi, IBAS basApi, IPCS pcsApi, ISYS sysApi, IPPS ppsApi, IWebHostEnvironment env) + public JIGController(ILogger logger, IJIG jigApi, IWHS whsApi, IBAS basApi, IPCS pcsApi, ISYS sysApi, IPPS ppsApi, + IWebHostEnvironment env, IConfiguration config) { _logger = logger; _jigApi = jigApi; @@ -34,7 +38,10 @@ namespace AMESCoreStudio.Web.Controllers _pcsApi = pcsApi; _sysApi = sysApi; _ppsApi = ppsApi; + _config = config; _env = env; + + } #region @@ -208,7 +215,7 @@ namespace AMESCoreStudio.Web.Controllers return Json(new { data = "" }); else - return Json(new { data = result.ItemNO}); + return Json(new { data = result.ItemNO }); } //yiru add end @@ -736,9 +743,7 @@ namespace AMESCoreStudio.Web.Controllers } else { - msg = result.Msg; - } } if (msg == "") msg = "缺少必填資料"; @@ -756,9 +761,14 @@ namespace AMESCoreStudio.Web.Controllers public async Task JIG004RSaveAsync(OutfitInfoBlob model, IFormFile formFile) { IResultModel result; + //設備基本數據維護的圖片根目錄路徑 + var rootFolderPath = _config["ImagePath:RootPath"]; + //設備基本數據維護的圖片資料夾 + var jigFilePathPath = _config["ImagePath:JigFilePath"]; var userID = ""; - HttpContext.Request.Cookies.TryGetValue("UserID", out userID); int user_id = 0; + HttpContext.Request.Cookies.TryGetValue("UserID", out userID); + if (userID != null) { if (int.Parse(userID.ToString()) >= 0) @@ -770,70 +780,73 @@ namespace AMESCoreStudio.Web.Controllers model.CreateDate = System.DateTime.Now; model.UpdateUserID = user_id; model.UpdateDate = System.DateTime.Now; - string FileName = string.Empty; - string NewName = string.Empty; - string FilePath = string.Empty; - - if (formFile != null) + if (formFile != null && formFile.Length > 0) { - if (formFile.Length > 0) + //取得使用者上傳檔案的原始檔名 + var imageName = Path.GetFileName(formFile.FileName); + //為避免使用者上傳的檔案名稱發生重複,重新給一個名稱 設備代號-原檔名 + var newName = model.OutfitID + "-" + imageName; + //指定要寫入的路徑、檔名和副檔名 + var rootPath = $@"{rootFolderPath}\{jigFilePathPath}"; + var filePath = $@"\{jigFilePathPath}\"; + var path = $@"{rootPath}\{imageName}"; + + if (!System.IO.Directory.Exists(rootPath)) { - //取得使用者上傳檔案的原始檔名 - FileName = Path.GetFileName(formFile.FileName); - //為避免使用者上傳的檔案名稱發生重複,重新給一個名稱 設備代號-原檔名 - NewName = model.OutfitID + "-" + FileName;//Path.GetRandomFileName() + fileExt; - //指定要寫入的路徑、檔名和副檔名 - FilePath = $"\\JIGFile\\";//本機目錄 - using (var stream = new FileStream(_env.WebRootPath + FilePath + NewName, FileMode.Create)) + try + { + System.IO.Directory.CreateDirectory(rootPath); + } + catch (Exception ex) { - await formFile.CopyToAsync(stream); + ModelState.AddModelError("error", $"無法建立路徑: {rootPath}, 錯誤: {ex.Message}"); + return BadRequest(ModelState); // 或適當的錯誤處理 } + } - //var fileProvider = _fileServerProvider.GetProvider("/aa"); - //var fileInfo = fileProvider.GetFileInfo(formFile.FileName); - //fileInfo = fileProvider.GetFileInfo(formFile.FileName); - ////遠端目錄 - //using (var stream = new FileStream(fileInfo.PhysicalPath, FileMode.Create)) - //{ - // await formFile.CopyToAsync(stream); - model.NewName = NewName; - model.ImageName = FileName; - model.FilePath = FilePath;// fileInfo.PhysicalPath; + using (var stream = new FileStream(path, FileMode.Create)) + { + await formFile.CopyToAsync(stream); + } - var result1 = await _jigApi.GetOutfitInfoBlobByOutfitID(model.OutfitID); + model.NewName = newName; + model.ImageName = imageName; + model.FilePath = filePath; - if (result1.Count > 0) - { - result = await _jigApi.PutOutfitInfoBlob(model.OutfitID, JsonConvert.SerializeObject(model)); - string ExitingFile = Path.Combine(_env.WebRootPath + FilePath, result1.Select(s => s.NewName).FirstOrDefault()); - System.IO.File.Delete(ExitingFile); - } - else - result = await _jigApi.PostOutfitInfoBlob(JsonConvert.SerializeObject(model)); + var result1 = await _jigApi.GetOutfitInfoBlobByOutfitID(model.OutfitID); - if (result.Success) - { - //var _msg = "上傳成功!"; - ViewBag.OutfitID = model.OutfitID; + if (result1.Count > 0) + { + result = await _jigApi.PutOutfitInfoBlob(model.OutfitID, JsonConvert.SerializeObject(model)); + string ExitingFile = Path.Combine(rootPath, result1.Select(s => s.NewName).FirstOrDefault()); + System.IO.File.Delete(ExitingFile); + } + else + { + result = await _jigApi.PostOutfitInfoBlob(JsonConvert.SerializeObject(model)); + } - return View("JIG004R"); - } - else - { - ModelState.AddModelError("error", result.Msg); - } + + if (result.Success) + { + ViewBag.OutfitID = model.OutfitID; + ViewBag.FileUploadUrl = _config["ImagePath:FileUploadUrl"]; + return View("JIG004R"); } + else + { + ModelState.AddModelError("error", result.Msg); + } + } else { ModelState.AddModelError("error", "請選擇要上傳檔案"); } - ViewBag.OutfitID = model.OutfitID; - - + ViewBag.FileUploadUrl = _config["ImagePath:FileUploadUrl"]; return View("JIG004R"); } @@ -1080,7 +1093,7 @@ namespace AMESCoreStudio.Web.Controllers return Json(new Table() { count = 0, data = null }); } - + #endregion #region JIG006設備送修/報廢相關 diff --git a/AMESCoreStudio.Web/Controllers/LABController.cs b/AMESCoreStudio.Web/Controllers/LABController.cs index c19d0335..3d024c12 100644 --- a/AMESCoreStudio.Web/Controllers/LABController.cs +++ b/AMESCoreStudio.Web/Controllers/LABController.cs @@ -12,13 +12,11 @@ using AMESCoreStudio.CommonTools.Result; using static AMESCoreStudio.Web.ViewModels.LAB.LAB003ViewModel; using AMESCoreStudio.WebApi.Models.AMES; using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using Microsoft.AspNetCore.Mvc.Rendering; -using AMESCoreStudio.WebApi.DTO.AMES; using AMESCoreStudio.Web.ViewModels.LAB; -using System.Dynamic; using System.IO; using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; namespace AMESCoreStudio.Web.Controllers { @@ -28,15 +26,18 @@ namespace AMESCoreStudio.Web.Controllers public readonly ILAB _labApi; public readonly IPCS _pcsApi; private readonly IWebHostEnvironment _env; + private readonly IConfiguration _config; - public LABController(ILogger logger, ILAB labApi, ISYS sysApi, IPCS pcsApi, IWebHostEnvironment env, IStringLocalizer sharedLocalizer) + public LABController(ILogger logger, ILAB labApi, ISYS sysApi, IPCS pcsApi, IWebHostEnvironment env, + IStringLocalizer sharedLocalizer) { _sysApi = sysApi; _labApi = labApi; _pcsApi = pcsApi; _env = env; + _config = new ConfigurationBuilder().SetBasePath(Environment.CurrentDirectory).AddJsonFile("appsettings.json").Build(); } private void GetFlagList() @@ -147,9 +148,9 @@ namespace AMESCoreStudio.Web.Controllers [ResponseCache(Duration = 0)] [HttpGet] - public async Task GetLabParamsAsync(string status = "*" ,int page = 0, int limit = 10) + public async Task GetLabParamsAsync(string status = "*", int page = 0, int limit = 10) { - var result = await _labApi.GetLabParamsByStatus(status,page, limit); + var result = await _labApi.GetLabParamsByStatus(status, page, limit); if (result.Data.Count() > 0) { @@ -172,7 +173,7 @@ namespace AMESCoreStudio.Web.Controllers /// /// /// - public async Task LAB002Async(string LabelMatnr, int page = 0, int limit = 10) + public IActionResult LAB002Async(string LabelMatnr, int page = 0, int limit = 10) { return View(); } @@ -196,17 +197,17 @@ namespace AMESCoreStudio.Web.Controllers if (System.IO.File.Exists(ImgFile)) { - var FileName = Path.GetFileName(ImgFile); + var LABFilePath = _config["ImagePath:LABFilePath"]; //指定要寫入的路徑、檔名和副檔名 - var FilePath = $"\\LABFile\\" + LabMatnr + "\\";//本機目錄 + var FilePath = LABFilePath + LabMatnr + "\\";//本機目錄 - if (!System.IO.Directory.Exists(_env.WebRootPath + FilePath)) + if (!System.IO.Directory.Exists(FilePath)) { - System.IO.Directory.CreateDirectory(_env.WebRootPath + FilePath); + System.IO.Directory.CreateDirectory(FilePath); } - var targetFilePath = _env.WebRootPath + FilePath + FileName; + var targetFilePath = FilePath + FileName; System.IO.File.Copy(ImgFile, targetFilePath, true); return Json(new Result() { success = true, msg = FilePath + FileName }); @@ -215,7 +216,7 @@ namespace AMESCoreStudio.Web.Controllers { return Json(new Result() { success = false, msg = "圖片檔案不存在" }); } - + } @@ -232,12 +233,12 @@ namespace AMESCoreStudio.Web.Controllers { //判斷為E209開頭的料號才可輸入 if (LabelMatnr.StartsWith("E209")) - { + { var PlmMeterial = await _pcsApi.GetPlmMeterialInfo(LabelMatnr); if (PlmMeterial.Count > 0) { - var Master = await _labApi.LabelTemplatebyMatnr(LabelMatnr,0,10); + var Master = await _labApi.LabelTemplatebyMatnr(LabelMatnr, 0, 10); if (Master.DataTotal > 0) return Json(new Table() { count = 0, msg = "料號已存在", data = null }); else @@ -298,31 +299,28 @@ namespace AMESCoreStudio.Web.Controllers string FileName = string.Empty; string NewName = string.Empty; - string FilePath = string.Empty; + string LABFilePath = _config["ImagePath:LABFilePath"]; - if (formFile != null) + if (formFile != null && formFile.Length > 0) { - if (formFile.Length > 0) + + //取得使用者上傳檔案的原始檔名 + FileName = Path.GetFileName(formFile.FileName); + //取原始檔名中的副檔名 + var fileExt = Path.GetExtension(FileName); + //為避免使用者上傳的檔案名稱發生重複,重新給一個亂數名稱 + NewName = Path.GetRandomFileName() + fileExt; + //指定要寫入的路徑、檔名和副檔名 + if (!System.IO.Directory.Exists(LABFilePath)) { - //取得使用者上傳檔案的原始檔名 - FileName = Path.GetFileName(formFile.FileName); - //取原始檔名中的副檔名 - var fileExt = Path.GetExtension(FileName); - //為避免使用者上傳的檔案名稱發生重複,重新給一個亂數名稱 - NewName = Path.GetRandomFileName() + fileExt; - //指定要寫入的路徑、檔名和副檔名 - FilePath = $"\\LABFile\\";//本機目錄 - - if (!System.IO.Directory.Exists(_env.WebRootPath + FilePath)) - { - System.IO.Directory.CreateDirectory(_env.WebRootPath + FilePath); - } - using (var stream = new FileStream(_env.WebRootPath + FilePath + NewName, FileMode.Create)) - { - await formFile.CopyToAsync(stream); - } - model.IMAGE_NAME = FilePath+ NewName; + System.IO.Directory.CreateDirectory(LABFilePath); } + using (var stream = new FileStream(LABFilePath + NewName, FileMode.Create)) + { + await formFile.CopyToAsync(stream); + } + model.IMAGE_NAME = LABFilePath + NewName; + } else { @@ -340,12 +338,12 @@ namespace AMESCoreStudio.Web.Controllers else { - ModelState.AddModelError("error", result.Msg); - + ModelState.AddModelError("error", result.Msg); + } } return Json(new Result() { success = false, msg = "缺少必填資料!!" }); - + } public async Task DeleteLabelTemplateDetailAsync(int id) @@ -360,7 +358,7 @@ namespace AMESCoreStudio.Web.Controllers return Json(new Result() { success = false, msg = "資料有誤!!" }); } } - + public async Task LAB002CListSaveAsync(LabelTemplateDetail model) { @@ -377,18 +375,18 @@ namespace AMESCoreStudio.Web.Controllers } } - //修改页面 + //修改页面 [HttpGet] public async Task LAB002UAsync(int id) { GetUserID(); - var result = await _labApi.GetLabelTemplateMaster(id); + var result = await _labApi.GetLabelTemplateMaster(id); if (result.LABEL_FILE == null) { return View(); } return View(result); - + } //頁面提交,id=0 添加,id>0 修改 @@ -401,54 +399,46 @@ namespace AMESCoreStudio.Web.Controllers string FileName = string.Empty; string NewName = string.Empty; - string FilePath = string.Empty; - if (formFile != null) + var RootPath = _config["ImagePath:RootPath"]; + var LABFilePath = _config["ImagePath:LABFilePath"]; + if (formFile != null && formFile.Length > 0) { - if (formFile.Length > 0) + + //取得使用者上傳檔案的原始檔名 + FileName = Path.GetFileName(formFile.FileName); + //取原始檔名中的副檔名 + var fileExt = Path.GetExtension(FileName); + //為避免使用者上傳的檔案名稱發生重複,重新給一個亂數名稱 + NewName = Path.GetRandomFileName() + fileExt; + //指定要寫入的路徑、檔名和副檔名 + if (!System.IO.Directory.Exists(LABFilePath)) { - //取得使用者上傳檔案的原始檔名 - FileName = Path.GetFileName(formFile.FileName); - //取原始檔名中的副檔名 - var fileExt = Path.GetExtension(FileName); - //為避免使用者上傳的檔案名稱發生重複,重新給一個亂數名稱 - NewName = Path.GetRandomFileName() + fileExt; - //指定要寫入的路徑、檔名和副檔名 - FilePath = $"\\LABFile\\";//本機目錄 - - if (!System.IO.Directory.Exists(_env.WebRootPath + FilePath)) - { - System.IO.Directory.CreateDirectory(_env.WebRootPath + FilePath); - } - using (var stream = new FileStream(_env.WebRootPath + FilePath + NewName, FileMode.Create)) - { - await formFile.CopyToAsync(stream); - } - model.IMAGE_NAME = FilePath + NewName; + System.IO.Directory.CreateDirectory(LABFilePath); } + using (var stream = new FileStream(LABFilePath + NewName, FileMode.Create)) + { + await formFile.CopyToAsync(stream); + } + model.IMAGE_NAME = LABFilePath + NewName; + + } + else + { + ModelState.AddModelError("error", "請選擇要上傳檔案"); } - - result = await _labApi.PutLabeTemplateMaster(JsonConvert.SerializeObject(model)); + result = await _labApi.PutLabeTemplateMaster(JsonConvert.SerializeObject(model)); if (result.Success) { - //var _msg = "添加成功!"; return Json(new Result() { success = true, msg = result.Msg }); } else { - ModelState.AddModelError("error", result.Msg); - } } return Json(new Result() { success = false, msg = "資料有誤!!" }); - //else - //{ - - // ModelState.AddModelError("error", "缺少必填資料"); - // return View("LAB002C", model); - //} } public async Task LAB002UListSaveAsync(LabelTemplateDetail model) @@ -505,7 +495,7 @@ namespace AMESCoreStudio.Web.Controllers } [HttpGet] - public async Task LAB003U(string OrderNo,string Operate) + public async Task LAB003U(string OrderNo, string Operate) { LabelItemReqModel model = new LabelItemReqModel(); model = await _labApi.GetLabelItemReq(OrderNo); @@ -514,7 +504,7 @@ namespace AMESCoreStudio.Web.Controllers } [HttpGet] - public async Task GetLab004(string OrderNo, string ModelNo, DateTime? strdate, DateTime? enddate, string UserNo,string Status) + public async Task GetLab004(string OrderNo, string ModelNo, DateTime? strdate, DateTime? enddate, string UserNo, string Status) { List xx = new List(); UserInfo User = new UserInfo(); @@ -547,7 +537,7 @@ namespace AMESCoreStudio.Web.Controllers System.IO.File.Copy(ImgFile, targetFilePath, true); - // var x = result.Data.FirstOrDefault(); + // var x = result.Data.FirstOrDefault(); ViewBag.Picture = FilePath + FileName; return View(result.Data); } @@ -580,11 +570,11 @@ namespace AMESCoreStudio.Web.Controllers } [HttpGet] - public async Task GetLabelField(string Labmat,string ItemNo) + public async Task GetLabelField(string Labmat, string ItemNo) { ResultModel result = new ResultModel(); result = await _labApi.GetLabelField(Labmat, ItemNo); - if(result.Data.Count()>0) + if (result.Data.Count() > 0) return Json(new Result() { success = result.Success, msg = result.Msg, data = result.Data }); else return Json(new Result() { success = false, msg = result.Msg, data = null }); @@ -597,7 +587,7 @@ namespace AMESCoreStudio.Web.Controllers { int Sn = 1; ResultModel result = new ResultModel(); - result = await _labApi.GetLabelItemMaster(OrderNo, null, null, null, -1,"A"); + result = await _labApi.GetLabelItemMaster(OrderNo, null, null, null, -1, "A"); if (result.Data.Any()) { var r2 = result.Data.Max(x => x.ordeR_NO).ToString(); @@ -677,7 +667,7 @@ namespace AMESCoreStudio.Web.Controllers return user_id; } - + #endregion diff --git a/AMESCoreStudio.Web/Controllers/PCSController.cs b/AMESCoreStudio.Web/Controllers/PCSController.cs index c301c658..dc746e3c 100644 --- a/AMESCoreStudio.Web/Controllers/PCSController.cs +++ b/AMESCoreStudio.Web/Controllers/PCSController.cs @@ -23,6 +23,7 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.IO; using System.Linq; +using System.Net.Http; using System.Threading.Tasks; namespace AMESCoreStudio.Web.Controllers @@ -49,6 +50,7 @@ namespace AMESCoreStudio.Web.Controllers /// public static int NoLength = 4; + public PCSController(ILogger logger, ILogger log, ISYS sysApi, IPCS pcsApi, IBAS basApi, IPPS ppsApi, IFQC fqcApi , IFileServerProvider fileServerProvider, IWebHostEnvironment env, IKCS kcsApi, IStringLocalizer sharedLocalizer , IConfiguration configuration, IBLL bllApi) @@ -64,7 +66,7 @@ namespace AMESCoreStudio.Web.Controllers _fileServerProvider = fileServerProvider; _env = env; _sharedLocalizer = sharedLocalizer; - _configuration = configuration; + _configuration = new ConfigurationBuilder().SetBasePath(Environment.CurrentDirectory).AddJsonFile("appsettings.json").Build(); _bllApi = bllApi; } @@ -1739,6 +1741,7 @@ namespace AMESCoreStudio.Web.Controllers if (wipInfoQuery.Any()) { // 判斷工單號碼 在工單基本資料檔只能有一筆(不判斷是否不同製程) ViewBag.MoidByOnlyOne = _configuration["MoidByOnlyOne"]; + if (ViewBag.MoidByOnlyOne == "Y") { if (wipInfoQuery.Count() != 0) @@ -2338,7 +2341,11 @@ namespace AMESCoreStudio.Web.Controllers return View("PCS001", model); } - + /// + /// 工單資料查詢 + /// + /// + /// public async Task PCS001R(int id) { // 針對安勤 工單基本資料統一打開工程資訊 @@ -2460,6 +2467,7 @@ namespace AMESCoreStudio.Web.Controllers GetCheckboxSMD(model.wipBoard != null ? model.wipBoard.Smd : null); GetCheckboxSMDSolderMa(model.wipBoard != null ? model.wipBoard.SmdSolderMask : null); GetCheckboxWipLN(model.wipLabel != null ? model.wipLabel.LN : "N"); + ViewBag.FileUploadUrl = _configuration["ImagePath:FileUploadUrl"]; return View(model); } @@ -2467,7 +2475,7 @@ namespace AMESCoreStudio.Web.Controllers { // 針對安勤 工單基本資料統一打開工程資訊 ViewBag.WipSpecial = _configuration["WipSpecial"]; - + ViewBag.FileUploadUrl = _configuration["ImagePath:FileUploadUrl"]; WipDataViewModel model = new WipDataViewModel(); var q = await _pcsApi.GetWipInfo(id); if (q.Count != 0) @@ -2619,6 +2627,7 @@ namespace AMESCoreStudio.Web.Controllers GetCheckboxSMD(model.wipBoard != null ? model.wipBoard.Smd : ""); GetCheckboxSMDSolderMa(model.wipBoard != null ? model.wipBoard.SmdSolderMask : ""); GetCheckboxWipLN(model.wipLabel != null ? model.wipLabel.LN : "N"); + ViewBag.FileUploadUrl = _configuration["ImagePath:FileUploadUrl"]; return View(model); } @@ -2810,18 +2819,36 @@ namespace AMESCoreStudio.Web.Controllers /// 路徑 /// 檔名 /// - public async Task FileDownload(string Path, string FileName) + public async Task FileDownload(string fileUrl) { - var path = $@"{_env.WebRootPath}\{Path}{FileName}"; - var memoryStream = new MemoryStream(); - using (var stream = new FileStream(path, FileMode.Open)) + fileUrl = fileUrl.Replace("\\", "/"); + try + { + if (string.IsNullOrEmpty(fileUrl)) + { + return StatusCode(500, $"找不到檔案路徑: {fileUrl}"); + } + + // 使用 HttpClient 從遠端 URL 下載檔案 + using (var httpClient = new HttpClient()) + { + var response = await httpClient.GetAsync(fileUrl); + if (!response.IsSuccessStatusCode) + { + return StatusCode(500, $"HttpClient 從遠端 URL 下載檔案錯誤"); + } + + var fileStream = await response.Content.ReadAsStreamAsync(); + var fileName = Path.GetFileName(new Uri(fileUrl).LocalPath); + var contentType = response.Content.Headers.ContentType?.MediaType ?? "application/octet-stream"; + + return File(fileStream, contentType, fileName); + } + } + catch (Exception ex) { - await stream.CopyToAsync(memoryStream); + return StatusCode(500, $"下載檔案錯誤: {ex.Message}"); } - memoryStream.Seek(0, SeekOrigin.Begin); - string contentType = await GetFileContentTypeAsync(FileName); - // 回傳檔案到 Client 需要附上 Content Type,否則瀏覽器會解析失敗。 - return File(memoryStream, contentType, FileName); } /// @@ -6899,6 +6926,7 @@ namespace AMESCoreStudio.Web.Controllers { var bNo = model.B.BarcodeNo; + model.PartNo = model.PartNo.Trim(); if (ModelState.IsValid) { IResultModel result; @@ -7181,61 +7209,6 @@ namespace AMESCoreStudio.Web.Controllers [HttpPost] public async Task PCS030Async(MaterialSop model, IFormFile formFile) { - //string FileName = string.Empty; - //string NewName = string.Empty; - //string FilePath = string.Empty; - - ////var fileProvider = _fileServerProvider.GetProvider("/aa"); - ////var fileInfo = fileProvider.GetFileInfo("/"); - //if (formFile != null) - //{ - // if (formFile.Length > 0) - // { - // //取得使用者上傳檔案的原始檔名 - // FileName = Path.GetFileName(formFile.FileName); - // //取原始檔名中的副檔名 - // var fileExt = Path.GetExtension(FileName); - // //為避免使用者上傳的檔案名稱發生重複,重新給一個亂數名稱 - // NewName = Path.GetRandomFileName() + fileExt; - // //指定要寫入的路徑、檔名和副檔名 - // FilePath = $"\\PDF\\";//本機目錄 - // using (var stream = new FileStream(_env.WebRootPath + FilePath + NewName, FileMode.Create)) - // { - // await formFile.CopyToAsync(stream); - // } - - // var fileProvider = _fileServerProvider.GetProvider("/aa"); - // //var fileInfo = fileProvider.GetFileInfo(formFile.FileName); - // //fileInfo = fileProvider.GetFileInfo(formFile.FileName); - // ////遠端目錄 - // //using (var stream = new FileStream(fileInfo.PhysicalPath, FileMode.Create)) - // //{ - // // await formFile.CopyToAsync(stream); - // //} - - - - // IResultModel result; - // model.FileName = FileName; - // model.NewName = NewName; - // model.FilePath = FilePath;// fileInfo.PhysicalPath; - - // result = await _pcsApi.PostMaterialSop(JsonConvert.SerializeObject(model)); - // if (result.Success) - // { - // var _msg = model.MaterialSopID == 0 ? "新增成功!" : "修改成功!"; - // return RedirectToAction("Refresh", "Home", new { msg = _msg }); - // } - // else - // { - // ModelState.AddModelError("error", result.Msg); - // } - // } - //} - //else - //{ - // ModelState.AddModelError("error", "請選擇要上傳檔案"); - //} await GetFactoryUnit(false); GetSOPTypeSelect(); @@ -7558,6 +7531,7 @@ namespace AMESCoreStudio.Web.Controllers IResultModel result; IResultModel result2; + model.PartNo = model.PartNo.Trim(); var barcodeItemOldList = await _pcsApi.GetBarcodeItem(model.BarcodeItemID); var barcodeItemOld = barcodeItemOldList[0]; var barcodeItemChange = new BarcodeItemChange(); @@ -8891,28 +8865,30 @@ namespace AMESCoreStudio.Web.Controllers } model.WipSops = model.WipSops.Where(w => w.WipSOPID != -1); - // 檔案上傳 - string FileName = string.Empty; - string NewName = string.Empty; - string FilePath = string.Empty; - + // 圖片上傳 + var rootFolderPath = _configuration["ImagePath:RootPath"]; + var uploadFolderPath = _configuration["ImagePath:UploadFolderPath"]; if (formFile != null) { if (formFile.Length > 0) { //取得使用者上傳檔案的原始檔名 - FileName = Path.GetFileName(formFile.FileName); - //取原始檔名中的副檔名 - //var fileExt = Path.GetExtension(FileName); - //為避免使用者上傳的檔案名稱發生重複,重新給一個亂數名稱 - //NewName = Path.GetRandomFileName() + fileExt; + var imageName = Path.GetFileName(formFile.FileName); //指定要寫入的路徑、檔名和副檔名 - FilePath = $@"{_env.WebRootPath}\UploadFolder\{model.wipInfo.WipNO}"; - var path = $@"{FilePath}\{FileName}"; + var rootPath = $@"{rootFolderPath}\{uploadFolderPath}\{model.wipInfo.WipNO}"; + var filePath = $@"\{uploadFolderPath}\{model.wipInfo.WipNO}"; + var path = $@"{rootPath}\{imageName}"; - if (!System.IO.Directory.Exists(FilePath)) + if (!System.IO.Directory.Exists(rootPath)) { - System.IO.Directory.CreateDirectory(FilePath); + try + { + System.IO.Directory.CreateDirectory(rootPath); + } + catch (Exception ex) + { + ModelState.AddModelError("error", $"無法建立路徑: {rootPath}, 錯誤: {ex.Message}"); + } } using (var stream = new FileStream(path, FileMode.Create)) @@ -8921,8 +8897,8 @@ namespace AMESCoreStudio.Web.Controllers } model.wipInfoBlob.WipNo = model.wipInfo.WipNO; - model.wipInfoBlob.ImageName = FileName; - model.wipInfoBlob.Filepath = $@"\UploadFolder\{model.wipInfo.WipNO}\"; + model.wipInfoBlob.ImageName = imageName; + model.wipInfoBlob.Filepath = filePath; model.wipInfoBlob.CreateUserID = UserID; model.wipInfoBlob.UpdateUserID = UserID; result = await _pcsApi.PostWipInfoBlob(JsonConvert.SerializeObject(model.wipInfoBlob)); @@ -8931,7 +8907,12 @@ namespace AMESCoreStudio.Web.Controllers Msg += result.Msg; } } + else + { + ModelState.AddModelError("error", "請選擇要上傳檔案"); + } } + } } catch (Exception ex) @@ -10073,7 +10054,7 @@ namespace AMESCoreStudio.Web.Controllers #region PCS041 生產注意事項 /// - /// + /// 生產注意事項 /// /// public async Task PCS041() @@ -10083,6 +10064,12 @@ namespace AMESCoreStudio.Web.Controllers return View(); } + + /// + /// 生產注意事項新增 + /// + /// + /// public async Task PCS041C(PCS041CViewModel model) { await GetStation(); @@ -10106,18 +10093,21 @@ namespace AMESCoreStudio.Web.Controllers { PCS041CImageViewModel b = new PCS041CImageViewModel(); b.Filename = blob.FileName; - b.FilePath = blob.FilePath; + b.FilePath = _configuration["ImagePath:ProductionMemoPath"]; b.Description = blob.FileDescription; model.Images.Add(b); } model.Image = new PCS041CImageViewModel(); + } + ViewBag.FileUploadUrl = _configuration["ImagePath:FileUploadUrl"]; return View(model); } + /// - /// Delete + /// 生產注意事項刪除 /// /// PK /// @@ -10129,8 +10119,9 @@ namespace AMESCoreStudio.Web.Controllers var r2 = await _pcsApi.DeleteProductionNoticeBlobByPPID(ppid); return Json(new Result() { success = r1.Success, msg = r1.Msg, data = null }); } + /// - /// View + /// 生產注意事項檢視 /// /// PK /// @@ -10167,11 +10158,13 @@ namespace AMESCoreStudio.Web.Controllers model.Image = new PCS041CImageViewModel(); return View("PCS041V", model); - } /// - /// View - /// - /// PK - /// + } + + /// + /// View + /// + /// PK + /// public async Task PCS041V2(string productTypeID, string material, string productionSID) { @@ -10201,9 +10194,6 @@ namespace AMESCoreStudio.Web.Controllers } } - - //model.Image = new PCS041CImageViewModel(); - return View("PCS041V2", model); } /// @@ -10230,30 +10220,13 @@ namespace AMESCoreStudio.Web.Controllers } return Json(new Table() { count = 0, data = null }); } + public async Task PCS041GetImage(string path) { byte[] fileBytes = await System.IO.File.ReadAllBytesAsync(path); return File(fileBytes, "image/jpeg"); } - /// - /// 檔案下載 - /// - /// 路徑 - /// 檔名 - /// - public async Task PCS041FileDownload(string Path, string FileName) - { - var path = Path + FileName; - var memoryStream = new MemoryStream(); - using (var stream = new FileStream(path, FileMode.Open)) - { - await stream.CopyToAsync(memoryStream); - } - memoryStream.Seek(0, SeekOrigin.Begin); - string contentType = await GetFileContentTypeAsync(FileName); - // 回傳檔案到 Client 需要附上 Content Type,否則瀏覽器會解析失敗。 - return File(memoryStream, contentType, FileName); - } + //頁面提交,id=0 添加,id>0 修改 public async Task PCS041CSave(PCS041CViewModel model) { diff --git a/AMESCoreStudio.Web/Controllers/REPController.cs b/AMESCoreStudio.Web/Controllers/REPController.cs index 5ca4def5..d8c20cc1 100644 --- a/AMESCoreStudio.Web/Controllers/REPController.cs +++ b/AMESCoreStudio.Web/Controllers/REPController.cs @@ -8,13 +8,13 @@ using AMESCoreStudio.CommonTools.Result; using System.Collections.Generic; using Microsoft.AspNetCore.Mvc.Rendering; using AMESCoreStudio.Web.ViewModels; -using System.ComponentModel.DataAnnotations; using System.IO; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Hosting; using AMESCoreStudio.WebApi.DTO.AMES; using Newtonsoft.Json.Linq; -using Microsoft.AspNetCore.Authentication.Cookies; +using Microsoft.Extensions.Configuration; +using System; namespace AMESCoreStudio.Web.Controllers { @@ -27,8 +27,10 @@ namespace AMESCoreStudio.Web.Controllers public readonly IPCS _pcsApi; public readonly ISYS _sysApi; private readonly IWebHostEnvironment _env; + private readonly IConfiguration _config; - public REPController(ILogger logger, IREP repApi, IPPS ppsApi, IBAS basApi, IPCS pcsApi, ISYS sysApi, IWebHostEnvironment env) + public REPController(ILogger logger, IREP repApi, IPPS ppsApi, IBAS basApi, + IPCS pcsApi, ISYS sysApi, IWebHostEnvironment env, IConfiguration config) { _logger = logger; _repApi = repApi; @@ -37,6 +39,7 @@ namespace AMESCoreStudio.Web.Controllers _pcsApi = pcsApi; _sysApi = sysApi; _env = env; + _config = config; } private async Task GetProductTypeList() @@ -196,7 +199,7 @@ namespace AMESCoreStudio.Web.Controllers } [HttpPost] - public async Task GetMaterialNoJson(string wip_no,string location_no) + public async Task GetMaterialNoJson(string wip_no, string location_no) { var wip_att = await _pcsApi.GetWipAtt(wip_no); //E9695A4S001R @@ -469,7 +472,8 @@ namespace AMESCoreStudio.Web.Controllers public IActionResult REP001B(string id) { - ViewBag.ImageUrl = $"\\REPImage\\" + id; + string REPImagePath = _config["ImagePath:REPImagePath"]; + ViewBag.ImageUrl = REPImagePath + id; return View(); } @@ -479,7 +483,7 @@ namespace AMESCoreStudio.Web.Controllers return Json(new Result() { success = true, msg = "" }); } - public async Task SaveRepairDesc(int ng_id,int component_id,string repair_desc) + public async Task SaveRepairDesc(int ng_id, int component_id, string repair_desc) { IResultModel result; var userID = ""; @@ -501,7 +505,7 @@ namespace AMESCoreStudio.Web.Controllers repair_record[0].UpdateUserID = user_id; repair_record[0].UpdateDate = System.DateTime.Now; repair_record[0].RepairDesc = repair_desc; - result = await _repApi.PutRepairRecord((int)repair_record[0].ComponentID, JsonConvert.SerializeObject(repair_record[0])); + result = await _repApi.PutRepairRecord((int)repair_record[0].ComponentID, JsonConvert.SerializeObject(repair_record[0])); } else { @@ -519,7 +523,7 @@ namespace AMESCoreStudio.Web.Controllers return Json(new { _msg = string.Format("維修描述保存成功!") }); } - public async Task SaveNgKeypart(int component_id, string old_part_no,string new_part_no) + public async Task SaveNgKeypart(int component_id, string old_part_no, string new_part_no) { IResultModel result; var userID = ""; @@ -564,6 +568,9 @@ namespace AMESCoreStudio.Web.Controllers var userID = ""; HttpContext.Request.Cookies.TryGetValue("UserID", out userID); int user_id = 0; + string REPImagePath = _config["ImagePath:REPImagePath"]; + + if (userID != null) { if (int.Parse(userID.ToString()) >= 0) @@ -616,7 +623,7 @@ namespace AMESCoreStudio.Web.Controllers model.ngReason = null; } - if (result1[0].ErrorDesc == "" || result1[0].ErrorDesc == null ) + if (result1[0].ErrorDesc == "" || result1[0].ErrorDesc == null) { result1[0].ErrorDesc = ng_reason[0].NGReasonDesc; } @@ -665,9 +672,9 @@ namespace AMESCoreStudio.Web.Controllers } else { - ViewBag.Image1Url = $"\\REPImage\\" + "noimage.jfif"; - ViewBag.Image2Url = $"\\REPImage\\" + "noimage.jfif"; - ViewBag.Image3Url = $"\\REPImage\\" + "noimage.jfif"; + ViewBag.Image1Url = REPImagePath + "noimage.jfif"; + ViewBag.Image2Url = REPImagePath + "noimage.jfif"; + ViewBag.Image3Url = REPImagePath + "noimage.jfif"; } } else @@ -675,9 +682,9 @@ namespace AMESCoreStudio.Web.Controllers NgRepair ngRepair = new NgRepair(); model.ngRepair = ngRepair; - ViewBag.Image1Url = $"\\REPImage\\" + "noimage.jfif"; - ViewBag.Image2Url = $"\\REPImage\\" + "noimage.jfif"; - ViewBag.Image3Url = $"\\REPImage\\" + "noimage.jfif"; + ViewBag.Image1Url = REPImagePath + "noimage.jfif"; + ViewBag.Image2Url = REPImagePath + "noimage.jfif"; + ViewBag.Image3Url = REPImagePath + "noimage.jfif"; } } @@ -694,13 +701,15 @@ namespace AMESCoreStudio.Web.Controllers await GetNGReasonList(); await GetRepairResponsibleUnitList(); + var REPImagePath = _config["ImagePath:REPImagePath"]; var userID = HttpContext.Request.Cookies["UserID"]; HttpContext.Response.Cookies.Append("UserID4REP001", userID.ToString()); - REP001NewViewModel model = new REP001NewViewModel(); - var result1 = await _repApi.GetNgComponent(id); + var result1 = await _repApi.GetNgComponent(id); var ng_reason = await _ppsApi.GetNGReason(result1[0].NgNo); + + REP001NewViewModel model = new REP001NewViewModel(); if (ng_reason.Count != 0) { model.ngReason = ng_reason[0]; @@ -735,7 +744,7 @@ namespace AMESCoreStudio.Web.Controllers var result31 = await _repApi.GetRepairRecordByNgID((int)result1[0].NgID); string repair_desc = ""; - for(int r=0;r 0) { - if (formFile.Count > 0) + newFileName = new string[formFile.Count]; + int idx = 0; + foreach (var item in formFile) { - newFileName = new string[formFile.Count]; - int idx = 0; - foreach (var item in formFile) + if (item.Length > 0) { - if (item.Length > 0) + //取得使用者上傳檔案的原始檔名 + var imageName = Path.GetFileName(item.FileName); + //取原始檔名中的副檔名 + var fileExt = Path.GetExtension(imageName); + //為避免使用者上傳的檔案名稱發生重複,重新給一個亂數名稱 + var newName = Path.GetRandomFileName() + fileExt; + var path = $@"{repImagePath}\{newName}"; + newFileName[idx] = newName; + idx = idx + 1; + //指定要寫入的路徑、檔名和副檔名 + using (var stream = new FileStream(path, FileMode.Create)) { - //取得使用者上傳檔案的原始檔名 - FileName = Path.GetFileName(item.FileName); - //取原始檔名中的副檔名 - var fileExt = Path.GetExtension(FileName); - //為避免使用者上傳的檔案名稱發生重複,重新給一個亂數名稱 - NewName = Path.GetRandomFileName() + fileExt; - newFileName[idx] = NewName; - idx = idx + 1; - //指定要寫入的路徑、檔名和副檔名 - FilePath = $"\\REPImage\\";//本機目錄 - using (var stream = new FileStream(_env.WebRootPath + FilePath + NewName, FileMode.Create)) - { - await item.CopyToAsync(stream); - } + await item.CopyToAsync(stream); } } - } } else @@ -903,7 +906,7 @@ namespace AMESCoreStudio.Web.Controllers result = await _repApi.PostNgRepair(JsonConvert.SerializeObject(model.ngRepair)); } - if (newFileName==null) + if (newFileName == null) { } else { @@ -923,14 +926,14 @@ namespace AMESCoreStudio.Web.Controllers for (int f = 0; f < newFileName.Length; f++) { NgRepairBlob ng_repair_blob = new NgRepairBlob(); - ng_repair_blob.ImageName = newFileName[f]; + ng_repair_blob.ImageName = newFileName[f]; ng_repair_blob.RepairID = repairID; model.ngRepairBlob = ng_repair_blob; result = await _repApi.PostNgRepairBlob(JsonConvert.SerializeObject(model.ngRepairBlob)); } - + } else { @@ -944,7 +947,7 @@ namespace AMESCoreStudio.Web.Controllers } - + } //if (result.Success) @@ -1106,250 +1109,249 @@ namespace AMESCoreStudio.Web.Controllers } //頁面提交,id=0 添加,id>0 修改 - [HttpPost] - public async Task REP001RSave1Async(REP001ViewModel model, IFormFile formFile) - { - IResultModel result; - var userID = ""; - HttpContext.Request.Cookies.TryGetValue("UserID", out userID); - int user_id = 0; - if (userID != null) - { - if (int.Parse(userID.ToString()) >= 0) - { - user_id = int.Parse(userID.ToString()); - } - } - model.ngComponent.ReplyUserID = user_id; - model.ngComponent.ReplyDate = System.DateTime.Now; - model.ngComponent.Status = 1; - model.ngComponent.UpdateUserID = user_id; - - string FileName = string.Empty; - string NewName = string.Empty; - string FilePath = string.Empty; - - if (formFile != null) - { - if (formFile.Length > 0) - { - //取得使用者上傳檔案的原始檔名 - FileName = Path.GetFileName(formFile.FileName); - //取原始檔名中的副檔名 - var fileExt = Path.GetExtension(FileName); - //為避免使用者上傳的檔案名稱發生重複,重新給一個亂數名稱 - NewName = Path.GetRandomFileName() + fileExt; - //指定要寫入的路徑、檔名和副檔名 - FilePath = $"\\REPImage\\";//本機目錄 - using (var stream = new FileStream(_env.WebRootPath + FilePath + NewName, FileMode.Create)) - { - await formFile.CopyToAsync(stream); - } - } - } - else - { - var ng_repiar_blob = await _repApi.GetNgRepairBlob(model.ngRepair.RepairID); - - if (ng_repiar_blob.Count == 0) - { - ModelState.AddModelError("error", "請選擇要上傳檔案"); - } - } - - if (model.ngRepair.Missing == "Y") - { - model.ngRepair.RepairNo = "N/A"; - model.ngComponent.Status = 2; - } - - result = await _repApi.PutNgComponent((int)model.ngComponent.ComponentID, JsonConvert.SerializeObject(model.ngComponent)); - - if (model.repairRecord.ComponentID > 0) - { - model.repairRecord.UpdateUserID = user_id; - result = await _repApi.PutRepairRecord((int)model.repairRecord.ComponentID, JsonConvert.SerializeObject(model.repairRecord)); - } - else - { - model.repairRecord.CreateUserID = user_id; - model.repairRecord.NgID = model.ngComponent.NgID; - model.repairRecord.ComponentID = model.ngComponent.ComponentID; - model.repairRecord.RepairDesc = model.ngRepair.RepairDesc; - result = await _repApi.PostRepairRecord(JsonConvert.SerializeObject(model.repairRecord)); - } - - if (model.ngRepair.RepairID > 0) - { - model.ngRepair.UpdateUserID = user_id; - result = await _repApi.PutNgRepair((int)model.ngRepair.RepairID, JsonConvert.SerializeObject(model.ngRepair)); - } - else - { - model.ngRepair.CreateUserID = user_id; - model.ngRepair.NgID = model.ngComponent.NgID; - model.ngRepair.ComponentID = model.ngComponent.ComponentID; - result = await _repApi.PostNgRepair(JsonConvert.SerializeObject(model.ngRepair)); - } - if (NewName == string.Empty) - { } - else - { - decimal repairID = 0; - if (model.ngRepair.RepairID == 0) - { - var ng_repair = await _repApi.GetNgRepairByComponent(model.ngRepair.ComponentID); - repairID = ng_repair[0].RepairID; - } - else - { - repairID = model.ngRepair.RepairID; - } - - if (model.ngRepairBlob == null) - { - NgRepairBlob ng_repair_blob = new NgRepairBlob(); - ng_repair_blob.ImageName = NewName; - ng_repair_blob.RepairID = repairID; - - model.ngRepairBlob = ng_repair_blob; - } - else - { - model.ngRepairBlob.ImageName = NewName; - model.ngRepairBlob.RepairID = repairID; - } - - result = await _repApi.PostNgRepairBlob(JsonConvert.SerializeObject(model.ngRepairBlob)); - } - - //if (result.Success) - //{ - // var _msg = model.ngRepairBlob.RepairID == 0 ? "新增成功!" : "修改成功!"; - // return RedirectToAction("Refresh", "Home", new { msg = _msg }); - //} - //else - //{ - // ModelState.AddModelError("error", result.Msg); - //} - - bool repairComplete = true; - - var ng_component = await _repApi.GetNgComponentByNGID(model.ngInfo.NgID); - for (int i = 0; i < ng_component.Count; i++) - { - if (ng_component[i].Status == 0) - { - repairComplete = false; - break; - } - } - - List items = new List(); - //判斷組件是否更換 - for (int i = 0; i < ng_component.Count; i++) - { - if (ng_component[i].NewPartNo != "" && ng_component[i].NewPartNo != null) - { - items.Add(new BarCodeCheckDto.inputItem - { - inputType = "KP", - inputData = ng_component[i].NewPartNo, - oldInputData = ng_component[i].OldPartNo - }); - } - } - - if (items.Count == 0) - { - items = null; - } - - if (repairComplete) - { - //判断全部维修完成过站 - int repairStationID = -1; - - //獲取流程ID - int wip_id = model.ngInfo.Barcode.WipID; - var wip_info = await _pcsApi.GetWipInfo(wip_id); - int flow_rule_id = wip_info[0].FlowRuleID; - - var rules = await _basApi.GetRules2(flow_rule_id, model.ngInfo.Barcode.StationID, model.ngInfo.Barcode.RuleStatus, repairStationID); - if (rules.Count > 0) - { - for (int i = 0; i < rules.Count; i++) - { - if (rules[i].RuleStatus == model.ngInfo.Barcode.RuleStatus) - { - repairStationID = rules[i].NextStationID; - break; - } - } - } - - int lineID = -1; - if (model.ngInfo.Wip.LineID != null) - { - lineID = model.ngInfo.Wip.LineID.Value; - } - - //准备资料 - var barCode = new BarCodeCheckDto - { - wipNo = model.ngInfo.Wip.WipNO, - barcode = model.ngInfo.Barcode.BarcodeNo, - barcodeType = "S", - stationID = repairStationID, - line = lineID, - unitNo = model.ngInfo.Wip.UnitNO, - inputItems = items, - userID = user_id - }; - - var barcode_result = new ResultModel(); - try - { - barcode_result = await _pcsApi.PassIngByCheck(JsonConvert.SerializeObject(barCode)); - } - catch { } - - if (barcode_result.Success) - { - //更新NG_INFO - //var ng_info = await _repApi.GetNgInfo((int)model.ngInfo.NgID); - //ng_info[0].Status = 1; - model.ngInfo.Status = 1; - result = await _repApi.PutNgInfo(JsonConvert.SerializeObject(model.ngInfo)); - } - else - { - return RedirectToAction("Refresh", "Home", new { id = model.ngComponent.NgID, msg = barcode_result.Msg }); - } - } - - if (result.Success) - { - var _msg = "儲存成功!"; - //return RedirectToAction("REP001V", "REP", new { id = model.ngComponent.NgID, msg = _msg }); - return RedirectToAction("Refresh", "Home", new { id = model.ngComponent.NgID, msg = _msg }); - } - else - { - if (result.Errors != null) - { - ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg); - } - else - { - ModelState.AddModelError("error", result.Msg); - } - } - - - return View("REP001R", model); - //return RedirectToAction("REP001V", "REP", new { id = model.ngComponent.NgID }); - } + //[HttpPost] + //public async Task REP001RSave1Async(REP001ViewModel model, IFormFile formFile) + //{ + // IResultModel result; + // var userID = ""; + // var REPImagePath = _config["ImagePath:REPImagePath"]; + // HttpContext.Request.Cookies.TryGetValue("UserID", out userID); + // int user_id = 0; + // if (userID != null) + // { + // if (int.Parse(userID.ToString()) >= 0) + // { + // user_id = int.Parse(userID.ToString()); + // } + // } + // model.ngComponent.ReplyUserID = user_id; + // model.ngComponent.ReplyDate = System.DateTime.Now; + // model.ngComponent.Status = 1; + // model.ngComponent.UpdateUserID = user_id; + + // string FileName = string.Empty; + // string NewName = string.Empty; + + // if (formFile != null) + // { + // if (formFile.Length > 0) + // { + // //取得使用者上傳檔案的原始檔名 + // FileName = Path.GetFileName(formFile.FileName); + // //取原始檔名中的副檔名 + // var fileExt = Path.GetExtension(FileName); + // //為避免使用者上傳的檔案名稱發生重複,重新給一個亂數名稱 + // NewName = Path.GetRandomFileName() + fileExt; + // //指定要寫入的路徑、檔名和副檔名 + // using (var stream = new FileStream(REPImagePath + NewName, FileMode.Create)) + // { + // await formFile.CopyToAsync(stream); + // } + // } + // } + // else + // { + // var ng_repiar_blob = await _repApi.GetNgRepairBlob(model.ngRepair.RepairID); + + // if (ng_repiar_blob.Count == 0) + // { + // ModelState.AddModelError("error", "請選擇要上傳檔案"); + // } + // } + + // if (model.ngRepair.Missing == "Y") + // { + // model.ngRepair.RepairNo = "N/A"; + // model.ngComponent.Status = 2; + // } + + // result = await _repApi.PutNgComponent((int)model.ngComponent.ComponentID, JsonConvert.SerializeObject(model.ngComponent)); + + // if (model.repairRecord.ComponentID > 0) + // { + // model.repairRecord.UpdateUserID = user_id; + // result = await _repApi.PutRepairRecord((int)model.repairRecord.ComponentID, JsonConvert.SerializeObject(model.repairRecord)); + // } + // else + // { + // model.repairRecord.CreateUserID = user_id; + // model.repairRecord.NgID = model.ngComponent.NgID; + // model.repairRecord.ComponentID = model.ngComponent.ComponentID; + // model.repairRecord.RepairDesc = model.ngRepair.RepairDesc; + // result = await _repApi.PostRepairRecord(JsonConvert.SerializeObject(model.repairRecord)); + // } + + // if (model.ngRepair.RepairID > 0) + // { + // model.ngRepair.UpdateUserID = user_id; + // result = await _repApi.PutNgRepair((int)model.ngRepair.RepairID, JsonConvert.SerializeObject(model.ngRepair)); + // } + // else + // { + // model.ngRepair.CreateUserID = user_id; + // model.ngRepair.NgID = model.ngComponent.NgID; + // model.ngRepair.ComponentID = model.ngComponent.ComponentID; + // result = await _repApi.PostNgRepair(JsonConvert.SerializeObject(model.ngRepair)); + // } + // if (NewName == string.Empty) + // { } + // else + // { + // decimal repairID = 0; + // if (model.ngRepair.RepairID == 0) + // { + // var ng_repair = await _repApi.GetNgRepairByComponent(model.ngRepair.ComponentID); + // repairID = ng_repair[0].RepairID; + // } + // else + // { + // repairID = model.ngRepair.RepairID; + // } + + // if (model.ngRepairBlob == null) + // { + // NgRepairBlob ng_repair_blob = new NgRepairBlob(); + // ng_repair_blob.ImageName = NewName; + // ng_repair_blob.RepairID = repairID; + + // model.ngRepairBlob = ng_repair_blob; + // } + // else + // { + // model.ngRepairBlob.ImageName = NewName; + // model.ngRepairBlob.RepairID = repairID; + // } + + // result = await _repApi.PostNgRepairBlob(JsonConvert.SerializeObject(model.ngRepairBlob)); + // } + + // //if (result.Success) + // //{ + // // var _msg = model.ngRepairBlob.RepairID == 0 ? "新增成功!" : "修改成功!"; + // // return RedirectToAction("Refresh", "Home", new { msg = _msg }); + // //} + // //else + // //{ + // // ModelState.AddModelError("error", result.Msg); + // //} + + // bool repairComplete = true; + + // var ng_component = await _repApi.GetNgComponentByNGID(model.ngInfo.NgID); + // for (int i = 0; i < ng_component.Count; i++) + // { + // if (ng_component[i].Status == 0) + // { + // repairComplete = false; + // break; + // } + // } + + // List items = new List(); + // //判斷組件是否更換 + // for (int i = 0; i < ng_component.Count; i++) + // { + // if (ng_component[i].NewPartNo != "" && ng_component[i].NewPartNo != null) + // { + // items.Add(new BarCodeCheckDto.inputItem + // { + // inputType = "KP", + // inputData = ng_component[i].NewPartNo, + // oldInputData = ng_component[i].OldPartNo + // }); + // } + // } + + // if (items.Count == 0) + // { + // items = null; + // } + + // if (repairComplete) + // { + // //判断全部维修完成过站 + // int repairStationID = -1; + + // //獲取流程ID + // int wip_id = model.ngInfo.Barcode.WipID; + // var wip_info = await _pcsApi.GetWipInfo(wip_id); + // int flow_rule_id = wip_info[0].FlowRuleID; + + // var rules = await _basApi.GetRules2(flow_rule_id, model.ngInfo.Barcode.StationID, model.ngInfo.Barcode.RuleStatus, repairStationID); + // if (rules.Count > 0) + // { + // for (int i = 0; i < rules.Count; i++) + // { + // if (rules[i].RuleStatus == model.ngInfo.Barcode.RuleStatus) + // { + // repairStationID = rules[i].NextStationID; + // break; + // } + // } + // } + + // int lineID = -1; + // if (model.ngInfo.Wip.LineID != null) + // { + // lineID = model.ngInfo.Wip.LineID.Value; + // } + + // //准备资料 + // var barCode = new BarCodeCheckDto + // { + // wipNo = model.ngInfo.Wip.WipNO, + // barcode = model.ngInfo.Barcode.BarcodeNo, + // barcodeType = "S", + // stationID = repairStationID, + // line = lineID, + // unitNo = model.ngInfo.Wip.UnitNO, + // inputItems = items, + // userID = user_id + // }; + + // var barcode_result = new ResultModel(); + // try + // { + // barcode_result = await _pcsApi.PassIngByCheck(JsonConvert.SerializeObject(barCode)); + // } + // catch { } + + // if (barcode_result.Success) + // { + // //更新NG_INFO + // //var ng_info = await _repApi.GetNgInfo((int)model.ngInfo.NgID); + // //ng_info[0].Status = 1; + // model.ngInfo.Status = 1; + // result = await _repApi.PutNgInfo(JsonConvert.SerializeObject(model.ngInfo)); + // } + // else + // { + // return RedirectToAction("Refresh", "Home", new { id = model.ngComponent.NgID, msg = barcode_result.Msg }); + // } + // } + + // if (result.Success) + // { + // var _msg = "儲存成功!"; + // //return RedirectToAction("REP001V", "REP", new { id = model.ngComponent.NgID, msg = _msg }); + // return RedirectToAction("Refresh", "Home", new { id = model.ngComponent.NgID, msg = _msg }); + // } + // else + // { + // if (result.Errors != null) + // { + // ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg); + // } + // else + // { + // ModelState.AddModelError("error", result.Msg); + // } + // } + + + // return View("REP001R", model); + // //return RedirectToAction("REP001V", "REP", new { id = model.ngComponent.NgID }); + //} #endregion @@ -1398,8 +1400,8 @@ namespace AMESCoreStudio.Web.Controllers await GetRepairResponsibleUnitList(); REP001ViewModel model = new REP001ViewModel(); + var REPImagePath = _config["ImagePath:REPImagePath"]; var result1 = await _repApi.GetNgComponent(id); - var ng_reason = await _ppsApi.GetNGReason(result1[0].NgNo); if (ng_reason.Count != 0) { @@ -1447,36 +1449,12 @@ namespace AMESCoreStudio.Web.Controllers { model.ngRepairBlob = result5[0]; - //if (result5[0].ImageName1 != "" && result5[0].ImageName1 != null) - //{ - // ViewBag.Image1Url = $"\\REPImage\\" + result5[0].ImageName1; - //} - //else - //{ - // ViewBag.Image1Url = $"\\REPImage\\" + "noimage.jfif"; - //} - //if (result5[0].ImageName2 != "" && result5[0].ImageName2 != null) - //{ - // ViewBag.Image2Url = $"\\REPImage\\" + result5[0].ImageName2; - //} - //else - //{ - // ViewBag.Image2Url = $"\\REPImage\\" + "noimage.jfif"; - //} - //if (result5[0].ImageName3 != "" && result5[0].ImageName3 != null) - //{ - // ViewBag.Image3Url = $"\\REPImage\\" + result5[0].ImageName3; - //} - //else - //{ - // ViewBag.Image3Url = $"\\REPImage\\" + "noimage.jfif"; - //} } else { - ViewBag.Image1Url = $"\\REPImage\\" + "noimage.jfif"; - ViewBag.Image2Url = $"\\REPImage\\" + "noimage.jfif"; - ViewBag.Image3Url = $"\\REPImage\\" + "noimage.jfif"; + ViewBag.Image1Url = REPImagePath + "noimage.jfif"; + ViewBag.Image2Url = REPImagePath + "noimage.jfif"; + ViewBag.Image3Url = REPImagePath + "noimage.jfif"; } } else @@ -1484,20 +1462,21 @@ namespace AMESCoreStudio.Web.Controllers NgRepair ngRepair = new NgRepair(); model.ngRepair = ngRepair; - ViewBag.Image1Url = $"\\REPImage\\" + "noimage.jfif"; - ViewBag.Image2Url = $"\\REPImage\\" + "noimage.jfif"; - ViewBag.Image3Url = $"\\REPImage\\" + "noimage.jfif"; + ViewBag.Image1Url = REPImagePath + "noimage.jfif"; + ViewBag.Image2Url = REPImagePath + "noimage.jfif"; + ViewBag.Image3Url = REPImagePath + "noimage.jfif"; } } return View(model); } - + public async Task REP002CSaveAsync(REP001ViewModel model, IFormFile formFile) { IResultModel result; var userID = ""; + var REPImagePath = _config["ImagePath:REPImagePath"]; HttpContext.Request.Cookies.TryGetValue("UserID", out userID); int user_id = 0; if (userID != null) @@ -1516,7 +1495,6 @@ namespace AMESCoreStudio.Web.Controllers string FileName = string.Empty; string NewName = string.Empty; - string FilePath = string.Empty; if (formFile != null) { @@ -1529,8 +1507,7 @@ namespace AMESCoreStudio.Web.Controllers //為避免使用者上傳的檔案名稱發生重複,重新給一個亂數名稱 NewName = Path.GetRandomFileName() + fileExt; //指定要寫入的路徑、檔名和副檔名 - FilePath = $"\\REPImage\\";//本機目錄 - using (var stream = new FileStream(_env.WebRootPath + FilePath + NewName, FileMode.Create)) + using (var stream = new FileStream(REPImagePath + NewName, FileMode.Create)) { await formFile.CopyToAsync(stream); } diff --git a/AMESCoreStudio.Web/Controllers/SPCController.cs b/AMESCoreStudio.Web/Controllers/SPCController.cs index 6a12cbff..b0504e3d 100644 --- a/AMESCoreStudio.Web/Controllers/SPCController.cs +++ b/AMESCoreStudio.Web/Controllers/SPCController.cs @@ -3,11 +3,9 @@ using System.Threading.Tasks; using Microsoft.Extensions.Logging; using AMESCoreStudio.Web.Models; using Newtonsoft.Json; -using AMESCoreStudio.WebApi; using System.Collections.Generic; using Microsoft.AspNetCore.Mvc.Rendering; using AMESCoreStudio.WebApi.Models.AMES; -using AMESCoreStudio.WebApi.Models.BAS; using AMESCoreStudio.CommonTools.Result; using System.IO; using Microsoft.AspNetCore.Http; @@ -16,6 +14,7 @@ using AMESCoreStudio.WebApi.DTO.AMES; using System.Linq; using AspNetCore.Reporting; using System; +using Microsoft.Extensions.Configuration; namespace AMESCoreStudio.Web.Controllers { @@ -30,8 +29,10 @@ namespace AMESCoreStudio.Web.Controllers public readonly IPPS _ppsApi; public readonly IBLL _bllApi; private readonly IWebHostEnvironment _env; + private readonly IConfiguration _config; - public SPCController(ILogger logger, ISPC spcApi, IWHS whsApi,IBAS basApi, IPCS pcsApi, ISYS sysApi, IPPS ppsApi, IWebHostEnvironment env, IBLL bllApi) + public SPCController(ILogger logger, ISPC spcApi, IWHS whsApi, IBAS basApi, + IPCS pcsApi, ISYS sysApi, IPPS ppsApi, IWebHostEnvironment env, IBLL bllApi, IConfiguration config) { _logger = logger; _spcApi = spcApi; @@ -42,6 +43,7 @@ namespace AMESCoreStudio.Web.Controllers _ppsApi = ppsApi; _env = env; _bllApi = bllApi; + _config = config; } @@ -50,8 +52,6 @@ namespace AMESCoreStudio.Web.Controllers { var FlagList = new List(); - - FlagList.Add(new SelectListItem("Y", "Y")); FlagList.Add(new SelectListItem("N", "N")); @@ -117,7 +117,7 @@ namespace AMESCoreStudio.Web.Controllers private void GetSideList() { - var SideItems = new List() ; + var SideItems = new List(); SideItems.Add(new SelectListItem("N/A", "N/A")); SideItems.Add(new SelectListItem("正面", "正面")); SideItems.Add(new SelectListItem("背面", "背面")); @@ -141,10 +141,10 @@ namespace AMESCoreStudio.Web.Controllers StationItems.Add(new SelectListItem("N/A", "0")); for (int i = 0; i < result.Count; i++) { - if(result[i].UnitNo==unit) + if (result[i].UnitNo == unit) StationItems.Add(new SelectListItem(result[i].StationName, result[i].StationID.ToString())); } - if(StationItems.Count==0) + if (StationItems.Count == 0) StationItems.Add(new SelectListItem("N/A", "")); ViewBag.StationList = StationItems; @@ -164,25 +164,68 @@ namespace AMESCoreStudio.Web.Controllers ViewBag.FlagList = FlagList; } + + /// + /// 取得登入帳號 廠別代碼 + /// + /// + private async Task GetLoginFactoryNo() + { + int user_id = -1; + HttpContext.Request.Cookies.TryGetValue("UserID", out string userID); + if (userID != null) + { + if (int.Parse(userID.ToString()) >= 0) + { + user_id = int.Parse(userID.ToString()); + var userData = await _sysApi.GetUserData(user_id); + + if (userData.Data.Any()) + return (string)userData.Data.FirstOrDefault().factoryNo; + } + } + + return ""; + } + + /// + /// 巡檢類型下拉選項 + /// + /// private async Task GetInspectionTypesList() { var result = await _spcApi.GetInspectionTypes(); - + var factoryNo = await GetLoginFactoryNo(); var GroupList = new List(); - for (int i = 0; i < result.Count; i++) + + if (factoryNo != "YS00") + { + GroupList.Add(new SelectListItem("首件檢查表", "1000")); + } + else { - GroupList.Add(new SelectListItem(result[i].InspectionNo, result[i].InspectionTypeID.ToString())); + for (int i = 0; i < result.Count; i++) + { + GroupList.Add(new SelectListItem(result[i].InspectionNo, result[i].InspectionTypeID.ToString())); + } + } + ViewBag.TypesList = GroupList; } - private async Task GetInspectionFormsList() //yiru modify 2022-09-30 + + /// + /// 巡檢表單下拉選項 + /// + /// + private async Task GetInspectionFormsList() { var result = await _spcApi.GetInspectionForms(); - + var GroupList = new List(); - for (int i = 0; i < result.Where(w => w.StatusNo =="Y").ToList().Count; i++) + for (int i = 0; i < result.Where(w => w.StatusNo == "Y").ToList().Count; i++) { - GroupList.Add(new SelectListItem(result[i].InspectionName, result[i].InspectionFormID.ToString())); + GroupList.Add(new SelectListItem(result[i].InspectionName, result[i].InspectionFormID.ToString())); } ViewBag.FromsList = GroupList; } @@ -241,7 +284,7 @@ namespace AMESCoreStudio.Web.Controllers UserItems.Add(new SelectListItem("N/A", "-1")); foreach (var item in result.Data) { - UserItems.Add(new SelectListItem(item.LoginNo +"_" +item.UserName, item.UserID.ToString())); + UserItems.Add(new SelectListItem(item.LoginNo + "_" + item.UserName, item.UserID.ToString())); } ViewBag.UserList = UserItems; } @@ -467,13 +510,13 @@ namespace AMESCoreStudio.Web.Controllers if (ModelState.IsValid) { IResultModel result; - var GetResult = await _spcApi.GetInspectionForms(); //yiru add 22-10-11 - if (GetResult.Where(w => w.InspectionName == model.InspectionName && w.InspectionTypeID == model.InspectionTypeID).ToList().Count > 0) + var GetResult = await _spcApi.GetInspectionForms(); //yiru add 22-10-11 + if (GetResult.Where(w => w.InspectionName == model.InspectionName && w.InspectionTypeID == model.InspectionTypeID).ToList().Count > 0) { ModelState.AddModelError("error", "巡檢表單名稱重覆"); } else - { + { result = await _spcApi.PostInspectionForm(JsonConvert.SerializeObject(model)); @@ -492,7 +535,8 @@ namespace AMESCoreStudio.Web.Controllers { ModelState.AddModelError("error", result.Msg); } - } } + } + } } return View("SPC002C", model); } @@ -540,9 +584,9 @@ namespace AMESCoreStudio.Web.Controllers return Json(new Table() { count = 0, data = null }); } [HttpGet] - public async Task GetInspectionFormsByQueryAsync(int id,string status) + public async Task GetInspectionFormsByQueryAsync(int id, string status) { - if(id == 0) + if (id == 0) return Json(new Table() { count = 0, data = null }); var result = await _spcApi.GetInspectionFormsByQuery(id, status); @@ -571,7 +615,7 @@ namespace AMESCoreStudio.Web.Controllers //await GetStationListByUnit(unit); var result = await _spcApi.GetInspectionForm(id); ViewBag.FormID = result[0].InspectionFormID; - ViewBag.FormName = "正在新增["+result[0].InspectionName+"]細項"; + ViewBag.FormName = "正在新增[" + result[0].InspectionName + "]細項"; await GetUserID(); return View(); } @@ -580,7 +624,7 @@ namespace AMESCoreStudio.Web.Controllers public async Task SPC003UAsync(int id) { var result = await _spcApi.GetInspectionItem(id); - + if (result.Count == 0) { @@ -706,7 +750,7 @@ namespace AMESCoreStudio.Web.Controllers { return View(); } - var FormResult = await _spcApi.GetInspectionForm(result.Select(s=>s.InspectionFormID).FirstOrDefault()); + var FormResult = await _spcApi.GetInspectionForm(result.Select(s => s.InspectionFormID).FirstOrDefault()); ViewBag.FormType = FormResult.Select(s => s.InspectionTypeID).FirstOrDefault(); ; @@ -723,7 +767,7 @@ namespace AMESCoreStudio.Web.Controllers [HttpGet] public async Task SPC004UAsync(int id, int Iid) { - var result = await _spcApi.GetInspectionResultDetailByQuery(id,Iid); + var result = await _spcApi.GetInspectionResultDetailByQuery(id, Iid); var userID = ""; int user_id = 0; HttpContext.Request.Cookies.TryGetValue("UserID", out userID); @@ -756,17 +800,17 @@ namespace AMESCoreStudio.Web.Controllers if (result.Success) { var _msg = "修改成功!"; - var result_Master = await _spcApi.GetInspectionResultMasters(model.InspectionID); + var result_Master = await _spcApi.GetInspectionResultMasters(model.InspectionID); - - if (result_Master.Count() > 0 ) + + if (result_Master.Count() > 0) { model.ReplyReason = model.ReplyReason == null ? model.ReplyReason : model.ReplyReason.Replace("\r\n", "
"); model.ReplyMethod = model.ReplyMethod == null ? model.ReplyMethod : model.ReplyMethod.Replace("\r\n", "
"); #region 寄mail 給IPQC_REPLY string MailGroup = "IPQC_REPLY"; string Subject = $"[AMES系統通知] ,IPQC巡檢異常回覆通知"; - string Body = $@"檢驗單號: { result_Master.Select(s=>s.BarcodeNo).FirstOrDefault()}
+ string Body = $@"檢驗單號: {result_Master.Select(s => s.BarcodeNo).FirstOrDefault()}
工單號碼 : {result_Master.Select(s => s.WipNo).FirstOrDefault()}
料號 : {result_Master.Select(s => s.ItemNo).FirstOrDefault()}
回覆異常原因 :
@@ -857,10 +901,10 @@ namespace AMESCoreStudio.Web.Controllers var EmailMsg = string.Empty; foreach (var item in stringList) { - if( !IsValidEmail(item)) - { - EmailMsg += item +","; - } + if (!IsValidEmail(item)) + { + EmailMsg += item + ","; + } } if (!string.IsNullOrEmpty(EmailMsg)) { @@ -871,10 +915,10 @@ namespace AMESCoreStudio.Web.Controllers else { - model.RejectReason = model.RejectReason == null ? model.RejectReason: model.RejectReason.Replace("\r\n", "
"); + model.RejectReason = model.RejectReason == null ? model.RejectReason : model.RejectReason.Replace("\r\n", "
"); #region 寄mail 給IPQC_REPLY string Subject = $"[AMES系統通知] ,IPQC巡檢異常回覆退回"; - string Body = $@"檢驗單號: { model.BarcodeNo}
+ string Body = $@"檢驗單號: {model.BarcodeNo}
工單號碼 : {model.WipNo}
料號 : {model.ItemNo}
異常回覆退回原因為:
{model.RejectReason}
@@ -917,18 +961,18 @@ namespace AMESCoreStudio.Web.Controllers [ResponseCache(Duration = 0)] [HttpGet] - public async Task GetInspectionResultMastersByQueryAsync(string WipNo, string ItemNo, string BarcodeNo,string Status_No) + public async Task GetInspectionResultMastersByQueryAsync(string WipNo, string ItemNo, string BarcodeNo, string Status_No) { if (string.IsNullOrWhiteSpace(WipNo)) - WipNo=" "; + WipNo = " "; if (string.IsNullOrWhiteSpace(ItemNo)) ItemNo = " "; if (string.IsNullOrWhiteSpace(BarcodeNo)) BarcodeNo = " "; - // if (string.IsNullOrWhiteSpace(Status_No)) - // Status_No = " "; + // if (string.IsNullOrWhiteSpace(Status_No)) + // Status_No = " "; var result = await _spcApi.GetInspectionResultMastersByQuery(WipNo, ItemNo, BarcodeNo, "C"); @@ -940,7 +984,7 @@ namespace AMESCoreStudio.Web.Controllers return Json(new Table() { count = 0, data = null }); } - public async Task GetInspectionResultDetailQueryAsync(int id ,string Line,string RuleStation,string InspectionResult) + public async Task GetInspectionResultDetailQueryAsync(int id, string Line, string RuleStation, string InspectionResult) { var result = await _spcApi.GetInspectionResultDetailQuery(id); @@ -965,13 +1009,13 @@ namespace AMESCoreStudio.Web.Controllers return Json(new Table() { count = 0, data = null }); } - + /// /// 判斷eMail格式正確性 /// /// /// - public bool IsValidEmail(string email) + public bool IsValidEmail(string email) { // 定义一个电子邮件地址的正则表达式模式 string pattern = @"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"; @@ -1010,10 +1054,11 @@ namespace AMESCoreStudio.Web.Controllers } //新增頁面 - public async Task SPC005R(int id,int itemID) + public async Task SPC005R(int id, int itemID) { ViewBag.ItemID = itemID; ViewBag.MasterID = id; + ViewBag.FileUploadUrl = _config["ImagePath:FileUploadUrl"]; await GetStationList(); return View(); @@ -1039,7 +1084,7 @@ namespace AMESCoreStudio.Web.Controllers { return View(); } - var result1 = await _spcApi.GetInspectionForm(result.Select(s=>s.InspectionFormID).FirstOrDefault()); + var result1 = await _spcApi.GetInspectionForm(result.Select(s => s.InspectionFormID).FirstOrDefault()); ViewBag.InspectionTypeID = result1[0].InspectionTypeID; return View(result[0]); } @@ -1073,7 +1118,7 @@ namespace AMESCoreStudio.Web.Controllers [HttpPost] public async Task SPC005TSaveAsync(InspectionResultMaster model) { - + if (ModelState.IsValid) { IResultModel result; @@ -1112,20 +1157,23 @@ namespace AMESCoreStudio.Web.Controllers result = await _spcApi.PostInspectionResultDetail(JsonConvert.SerializeObject(model)); if (result.Success) { - //var _msg = "添加成功!"; return Json(new Result() { success = true, msg = result.Msg }); } else { return Json(new Result() { success = false, msg = "資料有誤!!" }); } - //return Json(new Result() { success = true, msg = "資料有誤!!" }); } public async Task SPC005RSaveAsync(InspectionResultBlob model, IFormFile formFile) { IResultModel result; var userID = ""; + //巡檢結果維護的圖片根目錄路徑 + var rootFolderPath = _config["ImagePath:RootPath"]; + //巡檢結果維護的圖片資料夾 + var pcsFileFolder = _config["ImagePath:PCSFilePath"]; + HttpContext.Request.Cookies.TryGetValue("UserID", out userID); int user_id = 0; if (userID != null) @@ -1135,66 +1183,69 @@ namespace AMESCoreStudio.Web.Controllers user_id = int.Parse(userID.ToString()); } } + model.CreateUserID = user_id; model.CreateDate = System.DateTime.Now; model.UpdateUserID = user_id; model.UpdateDate = System.DateTime.Now; - string FileName = string.Empty; - string NewName = string.Empty; - string FilePath = string.Empty; - - if (formFile != null) + if (formFile != null && formFile.Length > 0) { - if (formFile.Length > 0) - { - //取得使用者上傳檔案的原始檔名 - FileName = Path.GetFileName(formFile.FileName); - //取原始檔名中的副檔名 - var fileExt = Path.GetExtension(FileName); - //為避免使用者上傳的檔案名稱發生重複,重新給一個亂數名稱 - NewName = Path.GetRandomFileName() + fileExt; - //指定要寫入的路徑、檔名和副檔名 - FilePath = $"\\PCSFile\\";//本機目錄 - using (var stream = new FileStream(_env.WebRootPath + FilePath + NewName, FileMode.Create)) - { - await formFile.CopyToAsync(stream); - } - //var fileProvider = _fileServerProvider.GetProvider("/aa"); - //var fileInfo = fileProvider.GetFileInfo(formFile.FileName); - //fileInfo = fileProvider.GetFileInfo(formFile.FileName); - ////遠端目錄 - //using (var stream = new FileStream(fileInfo.PhysicalPath, FileMode.Create)) - //{ - // await formFile.CopyToAsync(stream); - - model.ImageName = FileName; - model.NewName = NewName; - model.FilePath = FilePath;// fileInfo.PhysicalPath; - - result = await _spcApi.PostInspectionResultBlob(JsonConvert.SerializeObject(model)); - if (result.Success) + //取得使用者上傳檔案的原始檔名 + var imageName = Path.GetFileName(formFile.FileName); + //取原始檔名中的副檔名 + var fileExt = Path.GetExtension(imageName); + //為避免使用者上傳的檔案名稱發生重複,重新給一個亂數名稱 + var newName = Path.GetRandomFileName() + fileExt; + //指定要寫入的路徑、檔名和副檔名 + var rootPath = $@"{rootFolderPath}\{pcsFileFolder}"; + var filePath = $@"\{pcsFileFolder}\"; + var path = $@"{rootPath}\{newName}"; + + if (!System.IO.Directory.Exists(rootPath)) + { + try { - //var _msg = "上傳成功!"; - ViewBag.ItemID = model.InspectionItemID; - ViewBag.MasterID = model.InspectionID; - return View("SPC005R"); + System.IO.Directory.CreateDirectory(rootPath); } - else + catch (Exception ex) { - ModelState.AddModelError("error", result.Msg); + ModelState.AddModelError("error", $"無法建立路徑: {rootPath}, 錯誤: {ex.Message}"); + return BadRequest(ModelState); // 或適當的錯誤處理 } } + + using (var stream = new FileStream(path, FileMode.Create)) + { + await formFile.CopyToAsync(stream); + } + + model.ImageName = imageName; + model.NewName = newName; + model.FilePath = filePath; + + result = await _spcApi.PostInspectionResultBlob(JsonConvert.SerializeObject(model)); + if (result.Success) + { + ViewBag.ItemID = model.InspectionItemID; + ViewBag.MasterID = model.InspectionID; + ViewBag.FileUploadUrl = _config["ImagePath:FileUploadUrl"]; + return View("SPC005R"); + } + else + { + ModelState.AddModelError("error", result.Msg); + } } else { ModelState.AddModelError("error", "請選擇要上傳檔案"); } - ViewBag.ItemID = model.InspectionItemID; ViewBag.MasterID = model.InspectionID; + ViewBag.FileUploadUrl = _config["ImagePath:FileUploadUrl"]; return View("SPC005R"); } @@ -1262,14 +1313,12 @@ namespace AMESCoreStudio.Web.Controllers result = await _spcApi.PutInspectionResultDetail(model.InspectionID, JsonConvert.SerializeObject(model)); if (result.Success) { - //var _msg = "添加成功!"; return Json(new Result() { success = true, msg = result.Msg }); } else { return Json(new Result() { success = false, msg = "資料有誤!!" }); } - //return Json(new Result() { success = true, msg = "資料有誤!!" }); } @@ -1319,11 +1368,9 @@ namespace AMESCoreStudio.Web.Controllers return Json(new Table() { count = 0, data = null }); } - public async Task GetInspectionResultMastersByQueryAllAsync(int type,int id, string WipNo, string ItemNo, string BarcodeNo, string StatusNo, string sdate, string edate, int page = 0, int limit = 10) + public async Task GetInspectionResultMastersByQueryAllAsync(int type, int id, string WipNo, string ItemNo, string BarcodeNo, string StatusNo, string sdate, string edate, int page = 0, int limit = 10) { - //yiru 2022-11-17 - //if (id == 0) - // return Json(new Table() { count = 0, data = null }); + if (string.IsNullOrEmpty(WipNo)) WipNo = "*"; if (string.IsNullOrEmpty(ItemNo)) @@ -1338,14 +1385,14 @@ namespace AMESCoreStudio.Web.Controllers sdate = "*"; if (string.IsNullOrEmpty(edate)) edate = "*"; - - var result = await _spcApi.GetInspectionResultMastersByQueryAll(type, id, WipNo, ItemNo, BarcodeNo, StatusNo, sdate, edate, page , limit ); - + + var result = await _spcApi.GetInspectionResultMastersByQueryAll(type, id, WipNo, ItemNo, BarcodeNo, StatusNo, sdate, edate, page, limit); + if (result.DataTotal > 0) { - + return Json(new Table() { code = 0, msg = "", data = result.Data, count = result.DataTotal }); } @@ -1373,7 +1420,7 @@ namespace AMESCoreStudio.Web.Controllers { foreach (var item in result) { - var Bolbresult= await _spcApi.GetInspectionResultBlobsByQuery(item.InspectionID, item.InspectionItemID); + var Bolbresult = await _spcApi.GetInspectionResultBlobsByQuery(item.InspectionID, item.InspectionItemID); item.Stations.NewCno = Bolbresult.Count(); } return Json(new Table() { code = 0, msg = "", data = result, count = result.Count }); @@ -1447,7 +1494,7 @@ namespace AMESCoreStudio.Web.Controllers /// /// /// - public async Task SPC005_PDF(int id,string Types) + public async Task SPC005_PDF(int id, string Types) { string mimeType = ""; int extension = 1; @@ -1543,7 +1590,7 @@ namespace AMESCoreStudio.Web.Controllers SPC005Master.Detail2_ASSY.Add(new SPC005Detail2 { BarcodeNO = item.BarcodeNO, - SEQ = item.Seq.ToString(), + SEQ = item.Seq.ToString(), InspectionItemDesc = item.InspectionItemDesc, InspectionResults = item.InspectionResult }); @@ -1683,7 +1730,7 @@ namespace AMESCoreStudio.Web.Controllers BarcodeNO = item.BarcodeNO, Result = item.Result == "P" ? "PASS" : "FAIL", Defect = item.Defect, - Station = item.Station + Station = item.Station }); } @@ -1698,7 +1745,7 @@ namespace AMESCoreStudio.Web.Controllers }); } - + #region 圖檔轉BASE64 string ApprovedSign = null; @@ -1759,7 +1806,7 @@ namespace AMESCoreStudio.Web.Controllers public async Task SPC006QueryAsync(string wipNo, string itemNo, int page = 0, int limit = 10) { - IResultModel result = await _spcApi.GetIPQCTaskNoticesByQuery(wipNo: wipNo , itemNo: itemNo, page: page, limit: limit); + IResultModel result = await _spcApi.GetIPQCTaskNoticesByQuery(wipNo: wipNo, itemNo: itemNo, page: page, limit: limit); if (result.Data != null) { @@ -1808,7 +1855,7 @@ namespace AMESCoreStudio.Web.Controllers { var tt = Request.Cookies["UserID"]; ViewBag.UserID = tt; - + var result = await _spcApi.GetIPQCTaskNotice(id); @@ -1823,7 +1870,7 @@ namespace AMESCoreStudio.Web.Controllers var result1 = await _pcsApi.GetWipInfoByWipNO(WipNO); //站別 var Wipinfo = await _basApi.GetRuleStationsByFlow(result1.Select(s => s.FlowRuleID).FirstOrDefault(), 0, 20); - + if (Wipinfo.Count() > 0) { foreach (var item in Wipinfo) @@ -1935,7 +1982,7 @@ namespace AMESCoreStudio.Web.Controllers return Json(new Table() { count = 0, data = null }); - + } [ResponseCache(Duration = 0)] @@ -1951,7 +1998,7 @@ namespace AMESCoreStudio.Web.Controllers return Json(new Table() { count = 0, data = null }); } - + #endregion } diff --git a/AMESCoreStudio.Web/Startup.cs b/AMESCoreStudio.Web/Startup.cs index 41af1b38..e220bad9 100644 --- a/AMESCoreStudio.Web/Startup.cs +++ b/AMESCoreStudio.Web/Startup.cs @@ -28,7 +28,6 @@ namespace AMESCoreStudio.Web public IConfiguration Configuration { get; } - // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // XRJSON @@ -47,33 +46,11 @@ namespace AMESCoreStudio.Web options.MaxModelBindingCollectionSize = int.MaxValue; }); - // ValidationVisitor exceeded the maximum configured validation depth '32' services.AddMvc().AddMvcOptions(options => { options.MaxModelValidationErrors = 999999; }); - // ɮץؿ - //Add our IFileServerProvider implementation as a singleton - //services.AddSingleton(new FileServerProvider( - // new List - // { - // new FileServerOptions - // { - // // | - // FileProvider = new PhysicalFileProvider(@"\\10.0.8.7\\shop"), - // // | - // RequestPath = new PathString("/aa"), - // EnableDirectoryBrowsing = true - // } - // new FileServerOptions - // { - // FileProvider = new PhysicalFileProvider(@"//qasrv-n/Web/ISOZone/"), - // RequestPath = new PathString("/DocEsop"), - // EnableDirectoryBrowsing = true - // } - // })); - var config = Configuration.Get().VirtualPath; var fileServerOptions = new List(); if (config != null) @@ -93,7 +70,7 @@ namespace AMESCoreStudio.Web }; services.AddSingleton(new FileServerProvider(fileServerOptions)); - // ÿԴ + // CORS]w services.AddCors(options => options.AddPolicy("AMESPolicy", p => p.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod())); @@ -104,22 +81,19 @@ namespace AMESCoreStudio.Web o.ResourcesPath = "Resources"; }); - // Add framework services. - //services.AddMvc(); - //services.AddMvc().AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix); services.AddMvc() .AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix) .AddDataAnnotationsLocalization(options => { options.DataAnnotationLocalizerProvider = (type, factory) => factory.Create(typeof(SharedResource)); }); - //services.AddControllersWithViews(); services.AddControllersWithViews().AddRazorRuntimeCompilation(); - //ʹSession + // Session]w services.AddSession(); + // v]w services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options => { @@ -127,14 +101,11 @@ namespace AMESCoreStudio.Web options.LogoutPath = new PathString("/Login/Logout"); options.AccessDeniedPath = new PathString("/Home/Error"); options.Cookie.Name = "_AMESCookie"; - //options.Cookie.SameSite = SameSiteMode.None; - - //Cookie ʱѴһʱǷΪExpireTimeSpan options.SlidingExpiration = true; options.Cookie.HttpOnly = true; }); - //HttpClient + // HttpClient]w var types = typeof(Startup).Assembly.GetTypes() .Where(type => type.IsInterface && ((System.Reflection.TypeInfo)type).ImplementedInterfaces != null @@ -151,7 +122,6 @@ namespace AMESCoreStudio.Web } - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IFileServerProvider fileServerprovider) { if (env.IsDevelopment()) @@ -161,13 +131,11 @@ namespace AMESCoreStudio.Web else { app.UseExceptionHandler("/Home/Error"); - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseCors("AMESPolicy"); - //app.UseHttpsRedirection(); app.UseStaticFiles(); IList supportedCultures = new List @@ -189,6 +157,28 @@ namespace AMESCoreStudio.Web app.UseAuthentication(); app.UseSession(); + // VersionCode]w + app.Use(async (context, next) => + { + var currentVersion = Configuration["VersionCode"]; + var webVersion = context.Request.Cookies["VersionCode"]; + if (string.IsNullOrEmpty(context.Request.Cookies["VersionCode"])) + { + context.Response.Cookies.Append("VersionCode", currentVersion); + } + else + { + if ( webVersion != currentVersion) + { + context.Response.ContentType = "text/html; charset=utf-8"; + await context.Response.WriteAsync("AMESwgs!!
1. ХҦwg}
2. As}AMES"); + } + + } + + await next.Invoke(); + }); + app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( diff --git a/AMESCoreStudio.Web/Views/FQC/FQC007D.cshtml b/AMESCoreStudio.Web/Views/FQC/FQC007D.cshtml index a3da4810..e3bae6b2 100644 --- a/AMESCoreStudio.Web/Views/FQC/FQC007D.cshtml +++ b/AMESCoreStudio.Web/Views/FQC/FQC007D.cshtml @@ -1,6 +1,7 @@ @model AMESCoreStudio.WebApi.DTO.AMES.FqcDto -@{ - Layout = "~/Views/Shared/_AMESLayout.cshtml"; } +@{ + Layout = "~/Views/Shared/_AMESLayout.cshtml"; +}
@@ -77,28 +77,20 @@
-@section Scripts{ +@section Scripts { diff --git a/AMESCoreStudio.Web/Views/RPT/RPT002.cshtml b/AMESCoreStudio.Web/Views/RPT/RPT002.cshtml index aa96e13e..d9007f26 100644 --- a/AMESCoreStudio.Web/Views/RPT/RPT002.cshtml +++ b/AMESCoreStudio.Web/Views/RPT/RPT002.cshtml @@ -208,7 +208,7 @@
Board
System
Medical
- +
@@ -50,14 +50,14 @@
- +
- +
@@ -84,7 +84,7 @@
-@section Scripts{ +@section Scripts { diff --git a/AMESCoreStudio.Web/Views/SPC/SPC005R.cshtml b/AMESCoreStudio.Web/Views/SPC/SPC005R.cshtml index 54d51dce..b3cbf400 100644 --- a/AMESCoreStudio.Web/Views/SPC/SPC005R.cshtml +++ b/AMESCoreStudio.Web/Views/SPC/SPC005R.cshtml @@ -2,8 +2,10 @@ -@{ ViewData["Title"] = "SPC005R"; - Layout = "~/Views/Shared/_AMESLayout.cshtml"; } +@{ + ViewData["Title"] = "SPC005R"; + Layout = "~/Views/Shared/_AMESLayout.cshtml"; +}