diff --git a/AMESCoreStudio.Web/Controllers/PPSController.cs b/AMESCoreStudio.Web/Controllers/PPSController.cs index 79e4eed1..04ee1100 100644 --- a/AMESCoreStudio.Web/Controllers/PPSController.cs +++ b/AMESCoreStudio.Web/Controllers/PPSController.cs @@ -1522,6 +1522,114 @@ namespace AMESCoreStudio.Web.Controllers #endregion + #region PPS014維修方式維護相關 + + public IActionResult PPS014() + { + return View(); + } + + //新增頁面 + public IActionResult PPS014C() + { + return View(); + } + + //修改页面 + [HttpGet] + public async Task PPS014UAsync(string id) + { + var result = await _ppsApi.GetRepairType(id); + + if (result.Count == 0) + { + return View(); + } + return View(result[0]); + } + + public async Task PPS014DAsync(string id) + { + var result = await _ppsApi.DeleteRepairType(id); + return Json(new Result() { success = true, msg = "" }); + } + + //頁面提交,id=0 添加,id>0 修改 + [HttpPost] + public async Task PPS014CSaveAsync(RepairType model) + { + if (ModelState.IsValid) + { + IResultModel result; + + result = await _ppsApi.PostRepairType(JsonConvert.SerializeObject(model)); + + if (result.Success) + { + var _msg = "添加成功!"; + return RedirectToAction("Refresh", "Home", new { msg = _msg }); + } + else + { + if (result.Errors.Count > 0) + { + ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg); + } + else + { + ModelState.AddModelError("error", result.Msg); + } + } + } + return View("PPS014C", model); + } + + public async Task PPS014USaveAsync(RepairType model) + { + if (ModelState.IsValid) + { + IResultModel result; + + result = await _ppsApi.PutRepairType(model.RepairTypeNo, JsonConvert.SerializeObject(model)); + + if (result.Success) + { + var _msg = "修改成功!"; + return RedirectToAction("Refresh", "Home", new { msg = _msg }); + } + else + { + if (result.Errors.Count > 0) + { + ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg); + } + else + { + ModelState.AddModelError("error", result.Msg); + } + } + } + return View("PPS014U", model); + } + + [ResponseCache(Duration = 0)] + [HttpGet] + public async Task GetRepairTypesAsync(int page = 1, int limit = 10) + { + var result_total = await _ppsApi.GetRepairTypes(0, limit); + var result = await _ppsApi.GetRepairTypes(page, limit); + + if (result.Count > 0) + { + return Json(new Table() { code = 0, msg = "", data = result, count = result_total.Count }); + } + + return Json(new Table() { count = 0, data = null }); + } + + #endregion + + #region PPS016 問題類別維護相關 public IActionResult PPS016() diff --git a/AMESCoreStudio.Web/HttpApis/AMES/IPPS.cs b/AMESCoreStudio.Web/HttpApis/AMES/IPPS.cs index f11973f5..35530915 100644 --- a/AMESCoreStudio.Web/HttpApis/AMES/IPPS.cs +++ b/AMESCoreStudio.Web/HttpApis/AMES/IPPS.cs @@ -483,6 +483,45 @@ namespace AMESCoreStudio.Web #endregion + #region PPS014 維修方式維護 + + /// + /// 新增維修方式 + /// + /// + [WebApiClient.Attributes.HttpPost("api/RepairTypes")] + ITask> PostRepairType([FromBody, RawJsonContent] string model); + + /// + /// 更新維修方式 + /// + /// + [WebApiClient.Attributes.HttpPut("api/RepairTypes/{id}")] + ITask> PutRepairType(string id, [FromBody, RawJsonContent] string model); + + /// + /// 刪除維修方式 + /// + /// + [WebApiClient.Attributes.HttpDelete("api/RepairTypes/{id}")] + ITask> DeleteRepairType(string id); + + /// + /// 根據ID獲取指定維修方式資料 + /// + /// + [WebApiClient.Attributes.HttpGet("api/RepairTypes/{id}")] + ITask> GetRepairType(string id); + + /// + /// 獲取維修方式資料 + /// + /// + [WebApiClient.Attributes.HttpGet("api/RepairTypes")] + ITask> GetRepairTypes(int page = 1, int limit = 10); + + #endregion + #region PPS016 問題類別維護 /// @@ -522,5 +561,6 @@ namespace AMESCoreStudio.Web #endregion + } } diff --git a/AMESCoreStudio.Web/Views/Home/Framework.cshtml b/AMESCoreStudio.Web/Views/Home/Framework.cshtml index 201134df..1bf61536 100644 --- a/AMESCoreStudio.Web/Views/Home/Framework.cshtml +++ b/AMESCoreStudio.Web/Views/Home/Framework.cshtml @@ -198,6 +198,9 @@
  • 维修原因維護
  • +
  • + 維修方式維護 +
  • 問題類別維護
  • diff --git a/AMESCoreStudio.Web/Views/PPS/PPS014.cshtml b/AMESCoreStudio.Web/Views/PPS/PPS014.cshtml new file mode 100644 index 00000000..17890474 --- /dev/null +++ b/AMESCoreStudio.Web/Views/PPS/PPS014.cshtml @@ -0,0 +1,90 @@ +@{ + ViewData["Title"] = "維修方式維護"; + Layout = "~/Views/Shared/_AMESLayout.cshtml"; +} + +
    +
    +
    +
    +
    @ViewBag.Title
    +
    +
    +
    +
    +
    +
    +
    + +@section Scripts{ + +} \ No newline at end of file diff --git a/AMESCoreStudio.Web/Views/PPS/PPS014C.cshtml b/AMESCoreStudio.Web/Views/PPS/PPS014C.cshtml new file mode 100644 index 00000000..34d1765c --- /dev/null +++ b/AMESCoreStudio.Web/Views/PPS/PPS014C.cshtml @@ -0,0 +1,53 @@ +@model AMESCoreStudio.WebApi.Models.AMES.RepairType + + +@{ ViewData["Title"] = "PPS014C"; + Layout = "~/Views/Shared/_FormLayout.cshtml"; } + + + + +
    +
    +
    +
    + +
    + + + +
    +
    + + + +
    + @Html.ValidationMessage("error") +
    + +
    + +
    +
    +
    + +@section Scripts { + @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); + await Html.RenderPartialAsync("_FileinputScriptsPartial"); } + + + + +} + diff --git a/AMESCoreStudio.Web/Views/PPS/PPS014U.cshtml b/AMESCoreStudio.Web/Views/PPS/PPS014U.cshtml new file mode 100644 index 00000000..704a2055 --- /dev/null +++ b/AMESCoreStudio.Web/Views/PPS/PPS014U.cshtml @@ -0,0 +1,53 @@ +@model AMESCoreStudio.WebApi.Models.AMES.RepairType + + +@{ ViewData["Title"] = "PPS014U"; + 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/RepairTypesController.cs b/AMESCoreStudio.WebApi/Controllers/AMES/RepairTypesController.cs new file mode 100644 index 00000000..92def5a2 --- /dev/null +++ b/AMESCoreStudio.WebApi/Controllers/AMES/RepairTypesController.cs @@ -0,0 +1,191 @@ +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 RepairTypesController : ControllerBase + { + private readonly AMESContext _context; + + /// + /// + /// + /// + public RepairTypesController(AMESContext context) + { + _context = context; + } + + /// + /// + /// + /// + // GET: api/RepairTypes + [HttpGet] + public async Task>> GetRepairType(int page = 1, int limit = 10) + { + IQueryable q = _context.RepairTypes; + if (page > 0) + { + q = q.OrderBy(p => p.RepairTypeNo).Skip((page - 1) * limit).Take(limit); + } + else + { + q = q.OrderBy(p => p.RepairTypeNo); + } + + var repairType = await q.ToListAsync(); + return repairType; + } + + /// + /// + /// + /// + /// + // GET: api/RepairTypes/5 + [HttpGet("{id}")] + public async Task>> GetRepairType(string id) + { + IQueryable q = _context.RepairTypes; + q = q.Where(p => p.RepairTypeNo.Equals(id)); + + var repairType = await q.ToListAsync(); + + if (repairType == null) + { + return NotFound(); + } + + return repairType; + } + + /// + /// + /// + /// + /// + /// + // PUT: api/RepairTypes/5 + // To protect from overposting attacks, enable the specific properties you want to bind to, for + // more details, see https://go.microsoft.com/fwlink/?linkid=2123754. + [HttpPut("{id}")] + public async Task> PutRepairType(string id, [FromBody] RepairType repairType) + { + ResultModel result = new ResultModel(); + + if (id != repairType.RepairTypeNo) + { + result.Success = false; + result.Msg = "維修項目代碼錯誤"; + return result; + } + + _context.Entry(repairType).State = EntityState.Modified; + + try + { + await _context.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + if (!RepairTypeExists(id)) + { + result.Success = false; + result.Msg = "維修項目代碼不存在"; + return result; + } + else + { + throw; + } + } + + result.Success = true; + result.Msg = "OK"; + return result; + } + + /// + /// + /// + /// + /// + // POST: api/RepairTypes + // To protect from overposting attacks, enable the specific properties you want to bind to, for + // more details, see https://go.microsoft.com/fwlink/?linkid=2123754. + [HttpPost] + public async Task> PostRepairType([FromBody] RepairType repairType) + { + ResultModel result = new ResultModel(); + + _context.RepairTypes.Add(repairType); + try + { + await _context.SaveChangesAsync(); + } + catch (DbUpdateException) + { + if (RepairTypeExists(repairType.RepairTypeNo)) + { + result.Success = false; + result.Msg = "維修項目代碼重複"; + return result; + } + else + { + throw; + } + } + + result.Success = true; + result.Msg = "OK"; + return result; + } + + /// + /// + /// + /// + /// + // DELETE: api/RepairTypes/5 + [HttpDelete("{id}")] + public async Task> DeleteRepairType(string id) + { + ResultModel result = new ResultModel(); + + var repairType = await _context.RepairTypes.FindAsync(id); + if (repairType == null) + { + result.Success = false; + result.Msg = "維修項目代碼不存在"; + return result; + } + + _context.RepairTypes.Remove(repairType); + await _context.SaveChangesAsync(); + + result.Success = true; + result.Msg = "OK"; + return result; + } + + private bool RepairTypeExists(string id) + { + return _context.RepairTypes.Any(e => e.RepairTypeNo == id); + } + } +} diff --git a/AMESCoreStudio.WebApi/Models/AMES/RepairType.cs b/AMESCoreStudio.WebApi/Models/AMES/RepairType.cs new file mode 100644 index 00000000..a92be133 --- /dev/null +++ b/AMESCoreStudio.WebApi/Models/AMES/RepairType.cs @@ -0,0 +1,37 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; + +namespace AMESCoreStudio.WebApi.Models.AMES +{ + /// + /// 維修方式資料表 + /// + [Table("REPAIR_TYPE", Schema = "JHAMES")] + [DataContract] + public class RepairType + { + /// + /// 維修項目代碼 + /// + [Key] + [Column("REPAIR_TYPE_NO")] + [Required(ErrorMessage = "{0},不能空白")] + [Display(Name = "維修項目代碼")] + [StringLength(6, ErrorMessage = "{0},不能大于{1}")] + [DataMember] + public string RepairTypeNo { get; set; } + + + /// + /// 維修項目名稱 + /// + [Column("REPAIR_TYPE_DESC")] + [DataMember] + [Required(ErrorMessage = "{0},不能空白")] + [Display(Name = "維修項目名稱")] + [StringLength(100, ErrorMessage = "{0},不能大于{1}")] + public string RepairTypeDesc { get; set; } + } +} diff --git a/AMESCoreStudio.WebApi/Models/AMESContext.cs b/AMESCoreStudio.WebApi/Models/AMESContext.cs index ad4688b9..f2c509d7 100644 --- a/AMESCoreStudio.WebApi/Models/AMESContext.cs +++ b/AMESCoreStudio.WebApi/Models/AMESContext.cs @@ -272,7 +272,7 @@ namespace AMESCoreStudio.WebApi public DbSet RMAReasons { get; set; } /// - /// 标准工时资料 + /// 機種C/T資料 /// public DbSet CycleTimes { get; set; } @@ -285,6 +285,11 @@ namespace AMESCoreStudio.WebApi /// 問題類別資料 ///
    public DbSet QATypes { get; set; } + + /// + /// 維修方式資料 + /// + public DbSet RepairTypes { get; set; } } }