From 0020cde5a2f122995622531f6543a860c712a2ec Mon Sep 17 00:00:00 2001 From: yiru Date: Sun, 18 Jan 2026 16:25:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=95=AB=E9=9D=A2=EF=BC=9A?= =?UTF-8?q?=20=20=20=20=20=20WHS026=20=E9=99=A4=E5=A4=96=E7=AB=99=E5=88=A5?= =?UTF-8?q?=E7=B6=AD=E8=AD=B7=20=20=20=20=20=20WHS027=20=E5=A0=B1=E5=B7=A5?= =?UTF-8?q?=E7=AB=99=E9=BB=9E=E5=B0=8D=E6=87=89=E9=80=94=E7=A8=8B=E7=AB=99?= =?UTF-8?q?=E9=BB=9E=E7=B6=AD=E8=AD=B7=20=20=20=20=20=20WHS028=20=E5=89=8D?= =?UTF-8?q?=E7=BD=AE=E5=8A=A0=E5=B7=A5=E7=AB=99=E5=88=A5=E5=8A=A0=E5=85=A5?= =?UTF-8?q?=E9=80=94=E7=A8=8B=E7=AB=99=E9=BB=9E=E7=B6=AD=E8=AD=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/WHSController.cs | 333 +++++++++++++++++- AMESCoreStudio.Web/HttpApis/AMES/IWHS.cs | 84 +++++ AMESCoreStudio.Web/Views/WHS/WHS026.cshtml | 150 ++++++++ AMESCoreStudio.Web/Views/WHS/WHS026C.cshtml | 118 +++++++ AMESCoreStudio.Web/Views/WHS/WHS027.cshtml | 159 +++++++++ AMESCoreStudio.Web/Views/WHS/WHS027C.cshtml | 188 ++++++++++ AMESCoreStudio.Web/Views/WHS/WHS028.cshtml | 159 +++++++++ AMESCoreStudio.Web/Views/WHS/WHS028C.cshtml | 185 ++++++++++ .../AMES/ExceptStationsController.cs | 280 +++++++++++++++ .../Controllers/AMES/PreWorkingController.cs | 294 ++++++++++++++++ .../AMES/WorkingFlowStationsController.cs | 289 +++++++++++++++ .../Models/AMES/ExceptStation.cs | 59 ++++ .../Models/AMES/PreWorking.cs | 70 ++++ .../Models/AMES/WorkingFlowStations.cs | 66 ++++ AMESCoreStudio.WebApi/Models/AMESContext.cs | 14 +- 15 files changed, 2436 insertions(+), 12 deletions(-) create mode 100644 AMESCoreStudio.Web/Views/WHS/WHS026.cshtml create mode 100644 AMESCoreStudio.Web/Views/WHS/WHS026C.cshtml create mode 100644 AMESCoreStudio.Web/Views/WHS/WHS027.cshtml create mode 100644 AMESCoreStudio.Web/Views/WHS/WHS027C.cshtml create mode 100644 AMESCoreStudio.Web/Views/WHS/WHS028.cshtml create mode 100644 AMESCoreStudio.Web/Views/WHS/WHS028C.cshtml create mode 100644 AMESCoreStudio.WebApi/Controllers/AMES/ExceptStationsController.cs create mode 100644 AMESCoreStudio.WebApi/Controllers/AMES/PreWorkingController.cs create mode 100644 AMESCoreStudio.WebApi/Controllers/AMES/WorkingFlowStationsController.cs create mode 100644 AMESCoreStudio.WebApi/Models/AMES/ExceptStation.cs create mode 100644 AMESCoreStudio.WebApi/Models/AMES/PreWorking.cs create mode 100644 AMESCoreStudio.WebApi/Models/AMES/WorkingFlowStations.cs diff --git a/AMESCoreStudio.Web/Controllers/WHSController.cs b/AMESCoreStudio.Web/Controllers/WHSController.cs index 9791705..9f2ed12 100644 --- a/AMESCoreStudio.Web/Controllers/WHSController.cs +++ b/AMESCoreStudio.Web/Controllers/WHSController.cs @@ -1,20 +1,21 @@ -using Microsoft.AspNetCore.Mvc; -using System.Threading.Tasks; -using Microsoft.Extensions.Logging; +using AMESCoreStudio.CommonTools.Result; using AMESCoreStudio.Web.Models; -using Newtonsoft.Json; +using AMESCoreStudio.Web.ViewModels.WHS; 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 Microsoft.AspNetCore.Http; -using System.IO; -using Microsoft.AspNetCore.Hosting; using ClosedXML.Excel; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; using System; -using AMESCoreStudio.Web.ViewModels.WHS; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; namespace AMESCoreStudio.Web.Controllers { @@ -3923,5 +3924,315 @@ namespace AMESCoreStudio.Web.Controllers #endregion + + #region WHS026除外站別維護 + public async Task WHS026() + { + await GetUserID(); + await GetFactoryUnitsList(); + return View(); + } + + public async Task WHS026DAsync(string id,int uid) + { + var result = await _whsApi.DeleteExceptStation(id,uid); + + return Json(new Result() { success = true, msg = "" }); + } + + public async Task WHS026C() + { + await GetFactoryUnitsList3(); //報工生產單位 + + var tt = Request.Cookies["UserID"]; + ViewBag.UserID = tt; + return View(); + } + + [HttpPost] + public async Task WHS026CSaveAsync(ExceptStations model) + { + if (ModelState.IsValid) + { + IResultModel result; + + result = await _whsApi.PostExceptStation(JsonConvert.SerializeObject(model)); + + + if (result.Success) + { + var _msg = "添加成功!"; + return RedirectToAction("Refresh", "Home", new { 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("WHS026C", model); + } + + [ResponseCache(Duration = 0)] + [HttpGet] + public async Task GetExceptStationAsync(string unit, int page = 0, int limit = 10) + { + var result = await _whsApi.GetExceptStationsbyUnit(unit, page, limit); + if (result.DataTotal > 0) + { + return Json(new Table() { code = 0, msg = "", data = result.Data, count = result.DataTotal }); + } + + return Json(new Table() { count = 0, data = null }); + } + [HttpGet] + public async Task GetStationListByUnitAsync(string id) + { + var result = await _basApi.GetStationses(); + + var stations = result + .Where(x => x.UnitNo == id && x.StatusNo =="A") + .Select(x => new + { + stationID = x.StationID, + stationName = x.StationName, + statusNo = x.StatusNo + }) + .ToList(); + + if (!stations.Any()) + { + return Json(new + { + code = 0, + msg = "無資料", + data = new[] + { + new { stationID = "", stationName = "N/A" } + }, + count = 0 + }); + } + + return Json(new + { + code = 0, + msg = "", + data = stations, + count = stations.Count + }); + } + + #endregion + + #region WHS027報工對應途程站點資料檔 + public async Task WHS027() + { + await GetUserID(); + await GetWorkingUnit("all"); + return View(); + } + + public async Task WHS027DAsync(string id,int uid) + { + var result = await _whsApi.DeleteWorkingFlowStation(id,uid); + + return Json(new Result() { success = true, msg = "" }); + } + + public async Task WHS027C() + { + await GetFactoryUnitsList3(); //報工生產單位 + await GetWorkingUnit(""); + var tt = Request.Cookies["UserID"]; + ViewBag.UserID = tt; + return View(); + } + + [HttpPost] + public async Task WHS027CSaveAsync(WorkingFlowStations model) + { + if (ModelState.IsValid) + { + IResultModel result; + + result = await _whsApi.PostWorkingFlowStation(JsonConvert.SerializeObject(model)); + + + if (result.Success) + { + var _msg = "添加成功!"; + return RedirectToAction("Refresh", "Home", new { 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("WHS027C", model); + } + + [ResponseCache(Duration = 0)] + [HttpGet] + public async Task GetWorkingFlowStationsAsync(string workingunit, int page = 0, int limit = 10) + { + + + + var result = await _whsApi.GetWorkingFlowStationsbyUnit(workingunit, page, limit); + if (result.DataTotal > 0) + { + return Json(new Table() { code = 0, msg = "", data = result.Data, count = result.DataTotal }); + } + + return Json(new Table() { count = 0, data = null }); + } + + [HttpGet] + public async Task GetWorkingStationListByUnitAsync(int id) + { + var result = await _whsApi.GetWorkingStationsbyAll(); + + var stations = result + .Where(x => x.WorkingUnitID == id && x.StatusNo == "A") + .Select(x => new + { + stationID = x.WorkingStationID, + stationName = x.WorkingStationName, + statusNo = x.StatusNo + }) + .ToList(); + + if (!stations.Any()) + { + return Json(new + { + code = 0, + msg = "無資料", + data = new[] + { + new { stationID = "", stationName = "N/A" } + }, + count = 0 + }); + } + + return Json(new + { + code = 0, + msg = "", + data = stations, + count = stations.Count + }); + } + + + #endregion + + #region WHS028 前置加工站別加入維護 + + public async Task GetUserID() + { + 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()); + } + } + var result = await _sysApi.GetUserInfo(user_id); + var user = result[0].UserName; + ViewBag.UserID = user_id; + ViewBag.UserName = user; + } + public async Task WHS028() + { + await GetUserID(); + await GetWorkingUnit("all"); + return View(); + } + + public async Task WHS028DAsync(string id,int uid) + { + var result = await _whsApi.DeletePreWorking(id,uid); + + return Json(new Result() { success = true, msg = "" }); + } + + public async Task WHS028C() + { + await GetFactoryUnitsList3(); //報工生產單位 + await GetWorkingUnit(""); + var tt = Request.Cookies["UserID"]; + ViewBag.UserID = tt; + return View(); + } + + [ResponseCache(Duration = 0)] + [HttpGet] + public async Task GetPreWorkingAsync(string workingunit, int page = 0, int limit = 10) + { + + + + var result = await _whsApi.GetPreWorkingbyUnit(workingunit, page, limit); + if (result.DataTotal > 0) + { + return Json(new Table() { code = 0, msg = "", data = result.Data, count = result.DataTotal }); + } + + return Json(new Table() { count = 0, data = null }); + } + + [HttpPost] + public async Task WHS028CSaveAsync(PreWorking model) + { + if (ModelState.IsValid) + { + IResultModel result; + + result = await _whsApi.PostPreWorking(JsonConvert.SerializeObject(model)); + + + if (result.Success) + { + var _msg = "添加成功!"; + return RedirectToAction("Refresh", "Home", new { 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("WHS028C", model); + } + + + #endregion + + } } diff --git a/AMESCoreStudio.Web/HttpApis/AMES/IWHS.cs b/AMESCoreStudio.Web/HttpApis/AMES/IWHS.cs index 84acc38..6c55f35 100644 --- a/AMESCoreStudio.Web/HttpApis/AMES/IWHS.cs +++ b/AMESCoreStudio.Web/HttpApis/AMES/IWHS.cs @@ -966,5 +966,89 @@ namespace AMESCoreStudio.Web ITask> PostWorkingStandardWorkTimeList([FromBody, RawJsonContent] string model); #endregion + + #region WHS026途程除外站點資料檔 + + + /// + /// 用生產單位获取该途程除外站點 + /// + /// + [WebApiClient.Attributes.HttpGet("api/ExceptStations/MultiUnit/{id}")] + ITask> GetExceptStationsbyUnit(string id, int page = 0, int limit = 10); + + /// + /// 刪除途程除外站點資料檔資料 + /// + /// + [WebApiClient.Attributes.HttpDelete("api/ExceptStations/{id}/{uid}")] + ITask> DeleteExceptStation(string id,int uid); + + /// + /// 新增途程除外站點資料檔資料 + /// + /// + [WebApiClient.Attributes.HttpPost("api/ExceptStations")] + ITask> PostExceptStation([FromBody, RawJsonContent] string model); + + #endregion + + #region WHS027報工對應途程站點資料檔 + + /// + /// 獲取報工線別基本資料查詢資料 + /// + /// + [WebApiClient.Attributes.HttpGet("api/WorkingStations/byALL")] + ITask> GetWorkingStationsbyAll(); + + /// + /// 用生產單位获取该報工對應途程站點資料檔 + /// + /// + [WebApiClient.Attributes.HttpGet("api/WorkingFlowStations/MultiUnit/{id}")] + ITask> GetWorkingFlowStationsbyUnit(string id, int page = 0, int limit = 10); + + /// + /// 刪除報工對應途程站點資料檔 + /// + /// + [WebApiClient.Attributes.HttpDelete("api/WorkingFlowStations/{id}/{uid}")] + ITask> DeleteWorkingFlowStation(string id,int uid); + + /// + /// 新增報工對應途程站點資料檔 + /// + /// + [WebApiClient.Attributes.HttpPost("api/WorkingFlowStations")] + ITask> PostWorkingFlowStation([FromBody, RawJsonContent] string model); + + #endregion + + #region WHS028前置加工入途程站點資料檔 + + + /// + /// 用生產單位获取该前置加工入途程站點資料檔 + /// + /// + [WebApiClient.Attributes.HttpGet("api/PreWorking/MultiUnit/{id}")] + ITask> GetPreWorkingbyUnit(string id, int page = 0, int limit = 10); + + /// + /// 刪除前置加工入途程站點資料檔 + /// + /// + [WebApiClient.Attributes.HttpDelete("api/PreWorking/{id}/{uid}")] + ITask> DeletePreWorking(string id,int uid); + + /// + /// 新增前置加工入途程站點資料檔 + /// + /// + [WebApiClient.Attributes.HttpPost("api/PreWorking")] + ITask> PostPreWorking([FromBody, RawJsonContent] string model); + + #endregion } } diff --git a/AMESCoreStudio.Web/Views/WHS/WHS026.cshtml b/AMESCoreStudio.Web/Views/WHS/WHS026.cshtml new file mode 100644 index 0000000..b2ea0bc --- /dev/null +++ b/AMESCoreStudio.Web/Views/WHS/WHS026.cshtml @@ -0,0 +1,150 @@ +@{ + ViewData["Title"] = "除外站別維護"; + Layout = "~/Views/Shared/_AMESLayout.cshtml"; +} +@model AMESCoreStudio.WebApi.Models.AMES.ExceptStations + +
+
+
@ViewBag.Title
+
+
+
+
+
+ +
+ +
+
+ +
+ +
+
+
+ +
+
+
+@section Scripts{ + + +} \ No newline at end of file diff --git a/AMESCoreStudio.Web/Views/WHS/WHS026C.cshtml b/AMESCoreStudio.Web/Views/WHS/WHS026C.cshtml new file mode 100644 index 0000000..7a3cc98 --- /dev/null +++ b/AMESCoreStudio.Web/Views/WHS/WHS026C.cshtml @@ -0,0 +1,118 @@ +@model AMESCoreStudio.WebApi.Models.AMES.ExceptStations + +@{ + ViewData["Title"] = "WHS026C"; + Layout = "~/Views/Shared/_FormLayout.cshtml"; +} + + + + +
+
+
+
+ + + + + + + +
+ + + +
+ +
+ + + +
+ + @Html.ValidationMessage("error") +
+ +
+ +
+
+
+ +@section Scripts { + @{ + await Html.RenderPartialAsync("_ValidationScriptsPartial"); + await Html.RenderPartialAsync("_FileinputScriptsPartial"); + } + + + + +} + diff --git a/AMESCoreStudio.Web/Views/WHS/WHS027.cshtml b/AMESCoreStudio.Web/Views/WHS/WHS027.cshtml new file mode 100644 index 0000000..9b55064 --- /dev/null +++ b/AMESCoreStudio.Web/Views/WHS/WHS027.cshtml @@ -0,0 +1,159 @@ +@{ + ViewData["Title"] = "報工對應途程站點資料檔"; + Layout = "~/Views/Shared/_AMESLayout.cshtml"; +} +@model AMESCoreStudio.WebApi.Models.AMES.WorkingFlowStations + +
+
+
@ViewBag.Title
+
+
+
+
+
+ +
+ +
+
+ +
+ +
+
+
+ +
+
+
+@section Scripts{ + + +} \ No newline at end of file diff --git a/AMESCoreStudio.Web/Views/WHS/WHS027C.cshtml b/AMESCoreStudio.Web/Views/WHS/WHS027C.cshtml new file mode 100644 index 0000000..839316e --- /dev/null +++ b/AMESCoreStudio.Web/Views/WHS/WHS027C.cshtml @@ -0,0 +1,188 @@ +@model AMESCoreStudio.WebApi.Models.AMES.WorkingFlowStations + +@{ + ViewData["Title"] = "WHS027C"; + Layout = "~/Views/Shared/_FormLayout.cshtml"; +} + + + + +
+
+
+
+ + + + + + + +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ + @Html.ValidationMessage("error") +
+ +
+ +
+
+
+ +@section Scripts { + @{ + await Html.RenderPartialAsync("_ValidationScriptsPartial"); + await Html.RenderPartialAsync("_FileinputScriptsPartial"); + } + + + + +} + diff --git a/AMESCoreStudio.Web/Views/WHS/WHS028.cshtml b/AMESCoreStudio.Web/Views/WHS/WHS028.cshtml new file mode 100644 index 0000000..25ca183 --- /dev/null +++ b/AMESCoreStudio.Web/Views/WHS/WHS028.cshtml @@ -0,0 +1,159 @@ +@{ + ViewData["Title"] = "前置加工入途程站點資料檔"; + Layout = "~/Views/Shared/_AMESLayout.cshtml"; +} +@model AMESCoreStudio.WebApi.Models.AMES.PreWorking + +
+
+
@ViewBag.Title
+
+
+
+
+
+ +
+ +
+
+ +
+ +
+
+
+ +
+
+
+@section Scripts{ + + +} \ No newline at end of file diff --git a/AMESCoreStudio.Web/Views/WHS/WHS028C.cshtml b/AMESCoreStudio.Web/Views/WHS/WHS028C.cshtml new file mode 100644 index 0000000..a7279c6 --- /dev/null +++ b/AMESCoreStudio.Web/Views/WHS/WHS028C.cshtml @@ -0,0 +1,185 @@ +@model AMESCoreStudio.WebApi.Models.AMES.PreWorking + +@{ + ViewData["Title"] = "WHS028C"; + Layout = "~/Views/Shared/_FormLayout.cshtml"; +} + + + + +
+
+
+
+ + + + + +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ @Html.ValidationMessage("error") +
+ +
+ +
+
+
+ +@section Scripts { + @{ + await Html.RenderPartialAsync("_ValidationScriptsPartial"); + await Html.RenderPartialAsync("_FileinputScriptsPartial"); + } + + + + +} + diff --git a/AMESCoreStudio.WebApi/Controllers/AMES/ExceptStationsController.cs b/AMESCoreStudio.WebApi/Controllers/AMES/ExceptStationsController.cs new file mode 100644 index 0000000..abc41d0 --- /dev/null +++ b/AMESCoreStudio.WebApi/Controllers/AMES/ExceptStationsController.cs @@ -0,0 +1,280 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using AMESCoreStudio.WebApi; +using AMESCoreStudio.WebApi.Models.AMES; +using AMESCoreStudio.CommonTools.Result; + + +namespace AMESCoreStudio.WebApi.Controllers.AMES +{ + /// + /// 途程除外站點维护 + /// + [Route("api/[controller]")] + [ApiController] + public class ExceptStationsController : ControllerBase + { + private readonly AMESContext _context; + + /// + /// + /// + /// + public ExceptStationsController(AMESContext context) + { + _context = context; + } + + /// + /// 获取全部途程除外站點 + /// + /// + [HttpGet] + public async Task> GetExceptStations(int page = 0, int limit = 10) + { + IQueryable q = _context.ExceptStations; + ResultModel result = new ResultModel(); + + // 紀錄筆數 + result.DataTotal = q.Count(); + + // Table 頁數 + if (page > 0) + { + q = q.Skip((page - 1) * limit).Take(limit); + } + result.Data = await q.ToListAsync(); + return result; + } + + /// + /// 用ID获取该途程除外站點 + /// + /// + /// + [HttpGet("{id}")] + public async Task>> GetExceptStations(int id) + { + + IQueryable q = _context.ExceptStations; + q = q.Where(p => p.ExceptStationsID.Equals(id)); + var ExceptStations = await q.ToListAsync(); + + if (ExceptStations == null) + { + return NotFound(); + } + + return ExceptStations; + } + + + /// + /// 用生產單位获取该途程除外站點 + /// + /// 報工生產單位 + /// + [HttpGet("Unit/{id}")] + public async Task>> GetExceptStationsbyUnit(int id) + { + IQueryable q = _context.ExceptStations; + + + if (id != -99) + { + q = q.Where(p => p.UnitNo.Equals(id)); + } + var ExceptStations = await q.ToListAsync(); + + if (ExceptStations == null) + { + return NotFound(); + } + + return ExceptStations; + } + + + + /// + /// 用生產單位获取该途程除外站點 + /// + /// 報工生產單位 + /// + [HttpGet("MultiUnit/{id}")] + public async Task> GetExceptStationsMulti(string id,int page = 0, int limit = 10) + { + + + var q = from q1 in _context.ExceptStations + join q3 in _context.Stationses on q1.StationID equals q3.StationID + join q2 in _context.FactoryUnits on q1.UnitNo equals q2.UnitNo + select new + { + ExceptStationsID = q1.ExceptStationsID, + StationID = q1.StationID, + ExceptStationsName = q3.StationName, + UnitNo = q1.UnitNo, + UnitName = q2.UnitName, + CreateUserID = q1.CreateUserID, + CreateDate = q1.CreateDate, + UpdateDate = q1.UpdateDate, + statusNo = q1.StatusNo + + }; + + if (id != "0") + { + q = q.Where(p => p.UnitNo.Equals(id)); + } + + + ResultModel result = new ResultModel(); + + // 紀錄筆數 + result.DataTotal = q.Count(); + + // Table 頁數 + if (page > 0) + { + q = q.Skip((page - 1) * limit).Take(limit); + } + result.Data = await q.ToListAsync(); + return result; + + } + + + + /// + /// 更新條途程除外站點 + /// + /// + /// + /// + [HttpPut("{id}")] + public async Task> PutExceptStations(int id, [FromBody] ExceptStations ExceptStations) + { + ResultModel result = new ResultModel(); + if (id != ExceptStations.ExceptStationsID) + { + result.Success = false; + result.Msg = "序號錯誤"; + return result; + } + ExceptStations.UpdateDate = DateTime.Now; + _context.Entry(ExceptStations).State = EntityState.Modified; + + try + { + + await _context.SaveChangesAsync(); + result.Success = true; + result.Msg = "OK"; + return result; + + } + catch (Exception ex) + { + result.Success = false; + result.Msg = ex.InnerException.Message; + return result; + //throw; + + } + } + + /// + /// 新增途程除外站點 + /// + /// + /// + [HttpPost] + public async Task> PostExceptStations(ExceptStations ExceptStations) + { + ResultModel result = new ResultModel(); + if (ExceptStationExists(ExceptStations)) + { + + result.Success = false; + result.Msg = "途程站別重覆!!"; + return result; + } + Helper helper = new Helper(_context); + ExceptStations.ExceptStationsID = helper.GetIDKey("ExceptStations_ID").Result; + ExceptStations.CreateDate = DateTime.Now; + ExceptStations.UpdateDate = DateTime.Now; + _context.ExceptStations.Add(ExceptStations); + try + { + await _context.SaveChangesAsync(); + result.Success = true; + result.Msg = "OK"; + } + catch (DbUpdateException ex) + { + + result.Success = false; + result.Msg = ex.InnerException.Message; + } + + return result; + } + /// + /// 停用/啟用途程除外站點 + /// + /// + /// + [HttpDelete("{id}/{uid}")] + public async Task> DeleteExceptStations(int id,int uid) + { + ResultModel result = new ResultModel(); + var workingunit = await _context.ExceptStations.Where(m => m.ExceptStationsID == id).FirstOrDefaultAsync(); + if (workingunit == null) + { + result.Success = false; + result.Msg = "序號錯誤"; + return result; + } + ////// + var workingunitNew = new ExceptStations(); + workingunitNew = workingunit; + + _context.Entry(workingunitNew).State = EntityState.Modified; + + if (workingunit.StatusNo == "A") + workingunitNew.StatusNo = "S"; + else + workingunitNew.StatusNo = "A"; + workingunitNew.UpdateDate = DateTime.Now; + workingunitNew.UpdateUserID = uid; + + try + { + await _context.SaveChangesAsync(); + result.Success = true; + result.Msg = "OK"; + } + catch (Exception ex) + { + result.Success = false; + result.Msg = ex.InnerException.Message; + } + return result; + + } + + + private bool ExceptStationExists(ExceptStations model) + { + return _context.ExceptStations.Any(e => + e.StationID == model.StationID); + } + + } +} diff --git a/AMESCoreStudio.WebApi/Controllers/AMES/PreWorkingController.cs b/AMESCoreStudio.WebApi/Controllers/AMES/PreWorkingController.cs new file mode 100644 index 0000000..ce7fb6f --- /dev/null +++ b/AMESCoreStudio.WebApi/Controllers/AMES/PreWorkingController.cs @@ -0,0 +1,294 @@ +using AMESCoreStudio.CommonTools.Result; +using AMESCoreStudio.WebApi.Models.AMES; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + + +namespace AMESCoreStudio.WebApi.Controllers.AMES +{ + /// + /// 前置加工入途程站點维护 + /// + [Route("api/[controller]")] + [ApiController] + public class PreWorkingController : ControllerBase + { + private readonly AMESContext _context; + + /// + /// + /// + /// + public PreWorkingController(AMESContext context) + { + _context = context; + } + + /// + /// 获取全部前置加工入途程站點 + /// + /// + [HttpGet] + public async Task> GetPreWorking(int page = 0, int limit = 10) + { + IQueryable q = _context.PreWorkings; + ResultModel result = new ResultModel(); + + // 紀錄筆數 + result.DataTotal = q.Count(); + + // Table 頁數 + if (page > 0) + { + q = q.Skip((page - 1) * limit).Take(limit); + } + result.Data = await q.ToListAsync(); + return result; + } + + /// + /// 用ID获取该前置加工入途程站點 + /// + /// + /// + [HttpGet("{id}")] + public async Task>> GetPreWorking(int id) + { + + IQueryable q = _context.PreWorkings; + q = q.Where(p => p.PreWorkingID.Equals(id)); + var PreWorking = await q.ToListAsync(); + + if (PreWorking == null) + { + return NotFound(); + } + + return PreWorking; + } + + + /// + /// 用生產單位获取该前置加工入途程站點 + /// + /// 報工生產單位 + /// + [HttpGet("Unit/{id}")] + public async Task>> GetPreWorkingbyUnit(int id) + { + IQueryable q = _context.PreWorkings; + + + if (id != -99) + { + q = q.Where(p => p.UnitNo.Equals(id)); + } + var PreWorking = await q.ToListAsync(); + + if (PreWorking == null) + { + return NotFound(); + } + + return PreWorking; + } + + + + /// + /// 用生產單位获取该前置加工入途程站點 + /// + /// 報工生產單位 + /// + [HttpGet("MultiUnit/{id}")] + public async Task> GetPreWorkingMulti(int id, int page = 0, int limit = 10) + { + + + var q = from q1 in _context.PreWorkings + join q3 in _context.Stationses on q1.StationID equals q3.StationID + join q2 in _context.FactoryUnits on q1.UnitNo equals q2.UnitNo + join q4 in _context.WorkingUnits on q1.WorkingUnitID equals q4.WorkingUnitID + join q5 in _context.WorkingStations on q1.WorkingStationID equals q5.WorkingStationID + select new + { + PreWorkingID = q1.PreWorkingID, + UnitNo = q1.UnitNo, + UnitName = q2.UnitName, + StationID = q1.StationID, + StationName = q3.StationName, + WorkingUnitID = q1.WorkingUnitID, + WorkingUnionNo = q4.WorkingUnitNo, + WorkingUnitName = q4.WorkingUnitName, + WorkingStationID = q5.WorkingStationID, + WorkingStationName = q5.WorkingStationName, + CreateUserID = q1.CreateUserID, + CreateDate = q1.CreateDate, + UpdateDate = q1.UpdateDate, + StatusNo = q1.StatusNo, + Seq = q1.Seq + + }; + + if (id != -99) + { + q = q.Where(p => p.WorkingUnitID.Equals(id)); + } + + + ResultModel result = new ResultModel(); + + // 紀錄筆數 + result.DataTotal = q.Count(); + + // Table 頁數 + if (page > 0) + { + q = q.Skip((page - 1) * limit).Take(limit); + } + result.Data = await q.ToListAsync(); + return result; + + } + + + + /// + /// 更新條前置加工入途程站點 + /// + /// + /// + /// + [HttpPut("{id}")] + public async Task> PutPreWorking(int id, [FromBody] PreWorking PreWorking) + { + ResultModel result = new ResultModel(); + if (id != PreWorking.PreWorkingID) + { + result.Success = false; + result.Msg = "序號錯誤"; + return result; + } + PreWorking.UpdateDate = DateTime.Now; + _context.Entry(PreWorking).State = EntityState.Modified; + + try + { + + await _context.SaveChangesAsync(); + result.Success = true; + result.Msg = "OK"; + return result; + + } + catch (Exception ex) + { + result.Success = false; + result.Msg = ex.InnerException.Message; + return result; + //throw; + + } + } + + /// + /// 新增前置加工入途程站點 + /// + /// + /// + [HttpPost] + public async Task> PostPreWorking([FromBody] PreWorking PreWorking) + { + ResultModel result = new ResultModel(); + + if (PreWorkingExists(PreWorking)) + { + + result.Success = false; + result.Msg = "途程站別對應報工站別重覆!!"; + return result; + } + int maxSeq = await _context.PreWorkings.Where(w => w.StationID == PreWorking.StationID).Select(w => (int?)w.Seq).MaxAsync() ?? 0; + Helper helper = new Helper(_context); + PreWorking.PreWorkingID = helper.GetIDKey("PreWorking_ID").Result; + PreWorking.CreateDate = DateTime.Now; + PreWorking.UpdateDate = DateTime.Now; + PreWorking.Seq = maxSeq + 1; + _context.PreWorkings.Add(PreWorking); + try + { + await _context.SaveChangesAsync(); + result.Success = true; + result.Msg = "OK"; + } + catch (DbUpdateException ex) + { + + result.Success = false; + result.Msg = ex.InnerException.Message; + } + + return result; + } + /// + /// 停用/啟用前置加工入途程站點 + /// + /// + /// + [HttpDelete("{id}/{uid}")] + public async Task> DeletePreWorking(int id, int uid) + { + ResultModel result = new ResultModel(); + var workingunit = await _context.PreWorkings.Where(m => m.PreWorkingID == id).FirstOrDefaultAsync(); + if (workingunit == null) + { + result.Success = false; + result.Msg = "序號錯誤"; + return result; + } + ////// + var workingunitNew = new PreWorking(); + workingunitNew = workingunit; + + _context.Entry(workingunitNew).State = EntityState.Modified; + + if (workingunit.StatusNo == "A") + workingunitNew.StatusNo = "S"; + else + workingunitNew.StatusNo = "A"; + workingunitNew.UpdateDate = DateTime.Now; + workingunitNew.UpdateUserID = uid; + + + + try + { + await _context.SaveChangesAsync(); + result.Success = true; + result.Msg = "OK"; + } + catch (Exception ex) + { + result.Success = false; + result.Msg = ex.InnerException.Message; + } + return result; + + } + + + + + private bool PreWorkingExists(PreWorking model) + { + return _context.PreWorkings.Any(e => + e.WorkingStationID == model.WorkingStationID && + e.StationID == model.StationID ); + } + + } +} diff --git a/AMESCoreStudio.WebApi/Controllers/AMES/WorkingFlowStationsController.cs b/AMESCoreStudio.WebApi/Controllers/AMES/WorkingFlowStationsController.cs new file mode 100644 index 0000000..90ef56f --- /dev/null +++ b/AMESCoreStudio.WebApi/Controllers/AMES/WorkingFlowStationsController.cs @@ -0,0 +1,289 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using AMESCoreStudio.WebApi.Models.AMES; +using AMESCoreStudio.CommonTools.Result; + + +namespace AMESCoreStudio.WebApi.Controllers.AMES +{ + /// + /// 報工對應途程站點维护 + /// + [Route("api/[controller]")] + [ApiController] + public class WorkingFlowStationsController : ControllerBase + { + private readonly AMESContext _context; + + /// + /// + /// + /// + public WorkingFlowStationsController(AMESContext context) + { + _context = context; + } + + /// + /// 获取全部報工對應途程站點 + /// + /// + [HttpGet] + public async Task> GetWorkingFlowStations(int page = 0, int limit = 10) + { + IQueryable q = _context.WorkingFlowStations; + ResultModel result = new ResultModel(); + + // 紀錄筆數 + result.DataTotal = q.Count(); + + // Table 頁數 + if (page > 0) + { + q = q.Skip((page - 1) * limit).Take(limit); + } + result.Data = await q.ToListAsync(); + return result; + } + + /// + /// 用ID获取该報工對應途程站點 + /// + /// + /// + [HttpGet("{id}")] + public async Task>> GetWorkingFlowStations(int id) + { + + IQueryable q = _context.WorkingFlowStations; + q = q.Where(p => p.WorkingFlowStationsID.Equals(id)); + var WorkingFlowStations = await q.ToListAsync(); + + if (WorkingFlowStations == null) + { + return NotFound(); + } + + return WorkingFlowStations; + } + + + /// + /// 用生產單位获取该報工對應途程站點 + /// + /// 報工生產單位 + /// + [HttpGet("Unit/{id}")] + public async Task>> GetWorkingFlowStationsbyUnit(int id) + { + IQueryable q = _context.WorkingFlowStations; + + + if (id != -99) + { + q = q.Where(p => p.UnitNo.Equals(id)); + } + var WorkingFlowStations = await q.ToListAsync(); + + if (WorkingFlowStations == null) + { + return NotFound(); + } + + return WorkingFlowStations; + } + + + + /// + /// 用生產單位获取该報工對應途程站點 + /// + /// 報工生產單位 + /// + [HttpGet("MultiUnit/{id}")] + public async Task> GetWorkingFlowStationsMulti(int id,int page = 0, int limit = 10) + { + + + var q = from q1 in _context.WorkingFlowStations + join q3 in _context.Stationses on q1.StationID equals q3.StationID + join q2 in _context.FactoryUnits on q1.UnitNo equals q2.UnitNo + join q4 in _context.WorkingUnits on q1.WorkingUnitID equals q4.WorkingUnitID + join q5 in _context.WorkingStations on q1.WorkingStationID equals q5.WorkingStationID + select new + { + WorkingFlowStationsID = q1.WorkingFlowStationsID, + UnitNo = q1.UnitNo, + UnitName = q2.UnitName, + StationID = q1.StationID, + StationName = q3.StationName, + WorkingUnitID = q1.WorkingUnitID, + WorkingUnionNo = q4.WorkingUnitNo, + WorkingUnitName = q4.WorkingUnitName, + WorkingStationID = q5.WorkingStationID, + WorkingStationName = q5.WorkingStationName, + CreateUserID = q1.CreateUserID, + CreateDate = q1.CreateDate, + UpdateDate = q1.UpdateDate, + StatusNo = q1.StatusNo + + }; + + if (id != -99) + { + q = q.Where(p => p.WorkingUnitID.Equals(id)); + } + + + ResultModel result = new ResultModel(); + + // 紀錄筆數 + result.DataTotal = q.Count(); + + // Table 頁數 + if (page > 0) + { + q = q.Skip((page - 1) * limit).Take(limit); + } + result.Data = await q.ToListAsync(); + return result; + + } + + + + /// + /// 更新條報工對應途程站點 + /// + /// + /// + /// + [HttpPut("{id}")] + public async Task> PutWorkingFlowStations(int id, [FromBody] WorkingFlowStations WorkingFlowStations) + { + ResultModel result = new ResultModel(); + if (id != WorkingFlowStations.WorkingFlowStationsID) + { + result.Success = false; + result.Msg = "序號錯誤"; + return result; + } + WorkingFlowStations.UpdateDate = DateTime.Now; + _context.Entry(WorkingFlowStations).State = EntityState.Modified; + + try + { + + await _context.SaveChangesAsync(); + result.Success = true; + result.Msg = "OK"; + return result; + + } + catch (Exception ex) + { + result.Success = false; + result.Msg = ex.InnerException.Message; + return result; + //throw; + + } + } + + /// + /// 新增報工對應途程站點 + /// + /// + /// + [HttpPost] + public async Task> PostWorkingFlowStations([FromBody] WorkingFlowStations WorkingFlowStations) + { + ResultModel result = new ResultModel(); + + if (WorkingFlowStationExists(WorkingFlowStations)) + { + result.Success = false; + result.Msg = "途程站別對應報工站別重覆!!"; + return result; + } + + Helper helper = new Helper(_context); + WorkingFlowStations.WorkingFlowStationsID = helper.GetIDKey("WorkingFlowStationID").Result; + WorkingFlowStations.CreateDate = DateTime.Now; + WorkingFlowStations.UpdateDate = DateTime.Now; + _context.WorkingFlowStations.Add(WorkingFlowStations); + try + { + await _context.SaveChangesAsync(); + result.Success = true; + result.Msg = "OK"; + } + catch (DbUpdateException ex) + { + + result.Success = false; + result.Msg = ex.InnerException.Message; + } + + return result; + } + /// + /// 停用/啟用報工對應途程站點 + /// + /// + /// + [HttpDelete("{id}/{uid}")] + public async Task> DeleteWorkingFlowStations(int id,int uid) + { + ResultModel result = new ResultModel(); + var workingunit = await _context.WorkingFlowStations.Where(m => m.WorkingFlowStationsID == id).FirstOrDefaultAsync(); + if (workingunit == null) + { + result.Success = false; + result.Msg = "序號錯誤"; + return result; + } + ////// + var workingunitNew = new WorkingFlowStations(); + workingunitNew = workingunit; + + _context.Entry(workingunitNew).State = EntityState.Modified; + + if (workingunit.StatusNo == "A") + workingunitNew.StatusNo = "S"; + else + workingunitNew.StatusNo = "A"; + workingunitNew.UpdateDate = DateTime.Now; + workingunitNew.UpdateUserID = uid; + + + try + { + await _context.SaveChangesAsync(); + result.Success = true; + result.Msg = "OK"; + } + catch (Exception ex) + { + result.Success = false; + result.Msg = ex.InnerException.Message; + } + return result; + + } + + + private bool WorkingFlowStationExists(WorkingFlowStations model) + { + return _context.WorkingFlowStations.Any(e => + e.WorkingStationID == model.WorkingStationID && + e.StationID == model.StationID); + } + + + } +} diff --git a/AMESCoreStudio.WebApi/Models/AMES/ExceptStation.cs b/AMESCoreStudio.WebApi/Models/AMES/ExceptStation.cs new file mode 100644 index 0000000..2603a19 --- /dev/null +++ b/AMESCoreStudio.WebApi/Models/AMES/ExceptStation.cs @@ -0,0 +1,59 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; +namespace AMESCoreStudio.WebApi.Models.AMES +{ + /// + /// 途程除外站點資料檔 + /// + [Table("EXCEPT_STATIONS", Schema = "JHAMES")] + public class ExceptStations + { + + [Key] + [Column("EXCEPT_STATIONS_ID")] + [DataMember] + [Display(Name = "途程除外站點ID")] + public int ExceptStationsID { get; set; } + + [Column("STATION_ID")] + [DataMember] + [Display(Name = "途程站點ID")] + public int StationID { get; set; } + + [Column("UNIT_NO")] + [DataMember] + [Display(Name = "途程生產單位代碼")] + [StringLength(2)] + public string UnitNo { get; set; } + + [Column("CREATE_USERID")] + [DataMember] + [Display(Name = "創建者")] + public int CreateUserID { get; set; } + + + [Column("CREATE_DATE")] + [DataMember] + [Display(Name = "創建日期")] + public DateTime CreateDate { get; set; } + + [Column("UPDATE_USERID")] + [DataMember] + [Display(Name = "更新者")] + public int UpdateUserID { get; set; } + + [Column("UPDATE_DATE")] + [DataMember] + [Display(Name = "更新日期")] + public DateTime UpdateDate { get; set; } + + + [Column("STATUS_NO")] + [DataMember] + [Display(Name = "狀態")] + public string StatusNo { get; set; } = "A"; + + } +} \ No newline at end of file diff --git a/AMESCoreStudio.WebApi/Models/AMES/PreWorking.cs b/AMESCoreStudio.WebApi/Models/AMES/PreWorking.cs new file mode 100644 index 0000000..71ff3f5 --- /dev/null +++ b/AMESCoreStudio.WebApi/Models/AMES/PreWorking.cs @@ -0,0 +1,70 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; +namespace AMESCoreStudio.WebApi.Models.AMES +{ + /// + /// 前置加工入途程站點資料檔 + /// + [Table("PRE_WORKING")] + public class PreWorking + { + [Key] + [Column("PRE_WORKING_ID")] + [DataMember] + [Display(Name = "前置加工ID")] + public int PreWorkingID { get; set; } + + [Column("STATION_ID")] + [DataMember] + [Display(Name = "途程站點ID")] + public int StationID { get; set; } + + [Column("UNIT_NO")] + [DataMember] + [Display(Name = "途程生產單位代碼")] + [StringLength(2)] + public string UnitNo { get; set; } + + [Column("WORKING_STATION_ID")] + [DataMember] + [Display(Name = "報工站別ID")] + public int WorkingStationID { get; set; } + + [Column("WORKING_UNIT_ID")] + [DataMember] + [Display(Name = "報工生產單位ID")] + public int WorkingUnitID { get; set; } + + [Column("CREATE_USERID")] + [DataMember] + [Display(Name = "創建者")] + public int CreateUserID { get; set; } + + [Column("CREATE_DATE")] + [DataMember] + [Display(Name = "創建日期")] + public DateTime CreateDate { get; set; } + + [Column("UPDATE_USERID")] + [DataMember] + [Display(Name = "更新者")] + public int UpdateUserID { get; set; } + + [Column("UPDATE_DATE")] + [DataMember] + [Display(Name = "更新日期")] + public DateTime UpdateDate { get; set; } + + [Column("SEQ")] + [DataMember] + [Display(Name = "優先排序")] + public int Seq { get; set; } + + [Column("STATUS_NO")] + [DataMember] + [Display(Name = "狀態")] + public string StatusNo { get; set; } = "A"; + } +} \ No newline at end of file diff --git a/AMESCoreStudio.WebApi/Models/AMES/WorkingFlowStations.cs b/AMESCoreStudio.WebApi/Models/AMES/WorkingFlowStations.cs new file mode 100644 index 0000000..86577d3 --- /dev/null +++ b/AMESCoreStudio.WebApi/Models/AMES/WorkingFlowStations.cs @@ -0,0 +1,66 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; +namespace AMESCoreStudio.WebApi.Models.AMES +{ + /// + /// 報工對應途程站點資料檔 + /// + [Table("WORKING_FLOW_STATIONS")] + public class WorkingFlowStations + { + [Key] + [Column("WORKING_FLOW_STATIONS_ID")] + [DataMember] + [Display(Name = "報工對應途程站點ID")] + public int WorkingFlowStationsID { get; set; } + + [Column("WORKING_STATION_ID")] + [DataMember] + [Display(Name = "報工站別ID")] + public int WorkingStationID { get; set; } + + [Column("WORKING_UNIT_ID")] + [DataMember] + [Display(Name = "報工生產單位ID")] + public int WorkingUnitID { get; set; } + + [Column("STATION_ID")] + [DataMember] + [Display(Name = "途程站點ID")] + public int StationID { get; set; } + + [Column("UNIT_NO")] + [DataMember] + [Display(Name = "途程生產單位代碼")] + [StringLength(2)] + public string UnitNo { get; set; } + + [Column("CREATE_USERID")] + [DataMember] + [Display(Name = "創建者")] + public int CreateUserID { get; set; } + + [Column("CREATE_DATE")] + [DataMember] + [Display(Name = "創建日期")] + public DateTime CreateDate { get; set; } + + [Column("UPDATE_USERID")] + [DataMember] + [Display(Name = "更新者")] + public int UpdateUserID { get; set; } + + [Column("UPDATE_DATE")] + [DataMember] + [Display(Name = "更新日期")] + public DateTime UpdateDate { get; set; } + + + [Column("STATUS_NO")] + [DataMember] + [Display(Name = "狀態")] + public string StatusNo { get; set; } = "A"; + } +} \ No newline at end of file diff --git a/AMESCoreStudio.WebApi/Models/AMESContext.cs b/AMESCoreStudio.WebApi/Models/AMESContext.cs index 379efd1..d7069ed 100644 --- a/AMESCoreStudio.WebApi/Models/AMESContext.cs +++ b/AMESCoreStudio.WebApi/Models/AMESContext.cs @@ -1017,7 +1017,7 @@ namespace AMESCoreStudio.WebApi public virtual DbSet WorkingLines { get; set; } /// - ///報工工作站基本資料 + ///報工站別基本資料 /// public virtual DbSet WorkingStations { get; set; } @@ -1031,6 +1031,18 @@ namespace AMESCoreStudio.WebApi /// public virtual DbSet WorkingStandardWorkTimeLogs { get; set; } + /// + /// 途程除外站點資料檔 + /// + public virtual DbSet ExceptStations { get; set; } + /// + /// 報工對應途程站點資料檔 + /// + public virtual DbSet WorkingFlowStations { get; set; } + /// + /// 前置加工入途程站點資料檔 + /// + public virtual DbSet PreWorkings { get; set; } }