Browse Source

1.新增維修方式維護PPS014

PTD
marvinhong 3 years ago
parent
commit
712efad0df
  1. 108
      AMESCoreStudio.Web/Controllers/PPSController.cs
  2. 40
      AMESCoreStudio.Web/HttpApis/AMES/IPPS.cs
  3. 3
      AMESCoreStudio.Web/Views/Home/Framework.cshtml
  4. 90
      AMESCoreStudio.Web/Views/PPS/PPS014.cshtml
  5. 53
      AMESCoreStudio.Web/Views/PPS/PPS014C.cshtml
  6. 53
      AMESCoreStudio.Web/Views/PPS/PPS014U.cshtml
  7. 191
      AMESCoreStudio.WebApi/Controllers/AMES/RepairTypesController.cs
  8. 37
      AMESCoreStudio.WebApi/Models/AMES/RepairType.cs
  9. 7
      AMESCoreStudio.WebApi/Models/AMESContext.cs

108
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<IActionResult> PPS014UAsync(string id)
{
var result = await _ppsApi.GetRepairType(id);
if (result.Count == 0)
{
return View();
}
return View(result[0]);
}
public async Task<IActionResult> PPS014DAsync(string id)
{
var result = await _ppsApi.DeleteRepairType(id);
return Json(new Result() { success = true, msg = "" });
}
//頁面提交,id=0 添加,id>0 修改
[HttpPost]
public async Task<IActionResult> 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<IActionResult> 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<IActionResult> 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()

40
AMESCoreStudio.Web/HttpApis/AMES/IPPS.cs

@ -483,6 +483,45 @@ namespace AMESCoreStudio.Web
#endregion
#region PPS014 維修方式維護
/// <summary>
/// 新增維修方式
/// </summary>
/// <returns></returns>
[WebApiClient.Attributes.HttpPost("api/RepairTypes")]
ITask<ResultModel<RepairType>> PostRepairType([FromBody, RawJsonContent] string model);
/// <summary>
/// 更新維修方式
/// </summary>
/// <returns></returns>
[WebApiClient.Attributes.HttpPut("api/RepairTypes/{id}")]
ITask<ResultModel<RepairType>> PutRepairType(string id, [FromBody, RawJsonContent] string model);
/// <summary>
/// 刪除維修方式
/// </summary>
/// <returns></returns>
[WebApiClient.Attributes.HttpDelete("api/RepairTypes/{id}")]
ITask<ResultModel<RepairType>> DeleteRepairType(string id);
/// <summary>
/// 根據ID獲取指定維修方式資料
/// </summary>
/// <returns></returns>
[WebApiClient.Attributes.HttpGet("api/RepairTypes/{id}")]
ITask<List<RepairType>> GetRepairType(string id);
/// <summary>
/// 獲取維修方式資料
/// </summary>
/// <returns></returns>
[WebApiClient.Attributes.HttpGet("api/RepairTypes")]
ITask<List<RepairType>> GetRepairTypes(int page = 1, int limit = 10);
#endregion
#region PPS016 問題類別維護
/// <summary>
@ -522,5 +561,6 @@ namespace AMESCoreStudio.Web
#endregion
}
}

3
AMESCoreStudio.Web/Views/Home/Framework.cshtml

@ -198,6 +198,9 @@
<li class="sub-tab" hg-title="维修原因維護" hg-nav="/PPS/PPS013">
<a><i class="fa fa-comment-o fa-fw"></i><cite>维修原因維護</cite></a>
</li>
<li class="sub-tab" hg-title="維修方式維護" hg-nav="/PPS/PPS014">
<a><i class="fa fa-comment-o fa-fw"></i><cite>維修方式維護</cite></a>
</li>
<li class="sub-tab" hg-title="問題類別維護" hg-nav="/PPS/PPS016">
<a><i class="fa fa-comment-o fa-fw"></i><cite>問題類別維護</cite></a>
</li>

90
AMESCoreStudio.Web/Views/PPS/PPS014.cshtml

@ -0,0 +1,90 @@
@{
ViewData["Title"] = "維修方式維護";
Layout = "~/Views/Shared/_AMESLayout.cshtml";
}
<div class="layui-card">
<div class="layui-card-header">
<div class="layui-form">
<div class="layui-form-item ">
<div class="layui-inline"><i class="fa fa-file-text-o fa-fw"></i> @ViewBag.Title</div>
</div>
</div>
</div>
<div class="layui-card-body">
<table class="layui-hide" id="test" lay-filter="test"></table>
</div>
</div>
@section Scripts{
<script type="text/javascript">
//监听表单提交事件
hg.form.onsubmit('querysubmit', function (data) {
table && table.reload(data);
});
var tableCols = [[
{
field: 'repairTypeNo',
width: 200,
title: '維修項目代碼'
},
{
field: 'repairTypeDesc',
title: '維修項目名稱'
},
{
field: 'right',
width: 200,
title: '操作',
fixed: 'right',
templet: function (d) {
return '<a class="layui-btn layui-btn-normal layui-btn-xs layui-icon layui-icon-edit" lay-event="edit">修改</a> <a class="layui-btn layui-btn-danger layui-btn-xs layui-icon layui-icon-delete" lay-event="del">删除</a>'
}
}]
];
//通过行tool编辑,lay-event="edit"
function edit(obj) {
if (obj.data.repairTypeNo) {
hg.open('修改維修方式', '/PPS/PPS014U/' + obj.data.repairTypeNo, 640,320);
}
}
//通过行tool删除,lay-event="del"
function del(obj) {
if (obj.data.repairTypeNo) {
hg.confirm("維修方式:" + obj.data.repairTypeDesc + ",确定要删除吗?", function () {
$.ajax({
url: '/PPS/PPS014D',
data: { id: obj.data.repairTypeNo },
type: 'POST',
success: function (data) {
if (data.success) {
obj.del(); //只删本地数据
hg.msghide("删除成功!");
}
else {
hg.msg(data.msg);
}
},
error: function () {
hg.msg("网络请求失败!");
}
});
});
}
}
var toolbar = [{
text: '新增',
layuiicon: '&#xe608;',
class: 'layui-btn-normal',
handler: function () {
hg.open('新增維修方式', '/PPS/PPS014C', 640, 320);
}
}
];
//基本数据表格
var table = hg.table.datatable('test', '維修方式維護', '/PPS/GetRepairTypes', {}, tableCols, toolbar, true, 'full-100', ['filter', 'print', 'exports']);
</script>
}

53
AMESCoreStudio.Web/Views/PPS/PPS014C.cshtml

@ -0,0 +1,53 @@
@model AMESCoreStudio.WebApi.Models.AMES.RepairType
@{ ViewData["Title"] = "PPS014C";
Layout = "~/Views/Shared/_FormLayout.cshtml"; }
<style>
.control-label {
justify-content: flex-end !important;
}
</style>
<div class="row">
<div class="col-sm-12">
<form enctype="multipart/form-data" method="post" asp-action="PPS014CSave">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group form-inline my-sm-1">
<label asp-for="RepairTypeNo" class="control-label col-sm-3"></label>
<input asp-for="RepairTypeNo" class="form-control col-sm-9" placeholder="請輸入維修項目代碼" />
<span asp-validation-for="RepairTypeNo" class="text-danger offset-sm-3 my-sm-1"></span>
</div>
<div class="form-group form-inline my-sm-1">
<label asp-for="RepairTypeDesc" class="control-label col-sm-3"></label>
<input asp-for="RepairTypeDesc" class="form-control col-sm-9" placeholder="請輸入維修項目名稱" />
<span asp-validation-for="RepairTypeDesc" class="text-danger offset-sm-3 my-sm-1"></span>
</div>
<span style="color: firebrick;word-break: break-all;" class="text-danger offset-sm-3">@Html.ValidationMessage("error")</span>
<div class="form-group">
<input type="submit" value="保存" class="btn btn-primary offset-sm-3" />
</div>
</form>
</div>
</div>
@section Scripts {
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial");
await Html.RenderPartialAsync("_FileinputScriptsPartial"); }
<script type="text/javascript">
$(document).ready(function () {
var error = '@Html.ValidationMessage("error")';
if ($(error).text() != '') {
parent.hg.msg(error);
}
});
</script>
}

53
AMESCoreStudio.Web/Views/PPS/PPS014U.cshtml

@ -0,0 +1,53 @@
@model AMESCoreStudio.WebApi.Models.AMES.RepairType
@{ ViewData["Title"] = "PPS014U";
Layout = "~/Views/Shared/_FormLayout.cshtml"; }
<style>
.control-label {
justify-content: flex-end !important;
}
</style>
<div class="row">
<div class="col-sm-12">
<form enctype="multipart/form-data" method="post" asp-action="PPS014USave">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group form-inline my-sm-1">
<label asp-for="RepairTypeNo" class="control-label col-sm-3"></label>
<input asp-for="RepairTypeNo" class="form-control col-sm-9" placeholder="請輸入維修項目代碼" />
<span asp-validation-for="RepairTypeNo" class="text-danger offset-sm-3 my-sm-1"></span>
</div>
<div class="form-group form-inline my-sm-1">
<label asp-for="RepairTypeDesc" class="control-label col-sm-3"></label>
<input asp-for="RepairTypeDesc" class="form-control col-sm-9" placeholder="請輸入維修項目名稱" />
<span asp-validation-for="RepairTypeDesc" class="text-danger offset-sm-3 my-sm-1"></span>
</div>
<span style="color: firebrick;word-break: break-all;" class="text-danger offset-sm-3">@Html.ValidationMessage("error")</span>
<div class="form-group">
<input type="submit" value="保存" class="btn btn-primary offset-sm-3" />
</div>
</form>
</div>
</div>
@section Scripts {
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial");
await Html.RenderPartialAsync("_FileinputScriptsPartial"); }
<script type="text/javascript">
$(document).ready(function () {
var error = '@Html.ValidationMessage("error")';
if ($(error).text() != '') {
parent.hg.msg(error);
}
});
</script>
}

191
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
{
/// <summary>
/// 維修方式資料維護
/// </summary>
[Route("api/[controller]")]
[ApiController]
public class RepairTypesController : ControllerBase
{
private readonly AMESContext _context;
/// <summary>
///
/// </summary>
/// <param name="context"></param>
public RepairTypesController(AMESContext context)
{
_context = context;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
// GET: api/RepairTypes
[HttpGet]
public async Task<ActionResult<IEnumerable<RepairType>>> GetRepairType(int page = 1, int limit = 10)
{
IQueryable<RepairType> 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;
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
// GET: api/RepairTypes/5
[HttpGet("{id}")]
public async Task<ActionResult<IEnumerable<RepairType>>> GetRepairType(string id)
{
IQueryable<RepairType> q = _context.RepairTypes;
q = q.Where(p => p.RepairTypeNo.Equals(id));
var repairType = await q.ToListAsync();
if (repairType == null)
{
return NotFound();
}
return repairType;
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <param name="repairType"></param>
/// <returns></returns>
// 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<ResultModel<RepairType>> PutRepairType(string id, [FromBody] RepairType repairType)
{
ResultModel<RepairType> result = new ResultModel<RepairType>();
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;
}
/// <summary>
///
/// </summary>
/// <param name="repairType"></param>
/// <returns></returns>
// 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<ResultModel<RepairType>> PostRepairType([FromBody] RepairType repairType)
{
ResultModel<RepairType> result = new ResultModel<RepairType>();
_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;
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
// DELETE: api/RepairTypes/5
[HttpDelete("{id}")]
public async Task<ResultModel<RepairType>> DeleteRepairType(string id)
{
ResultModel<RepairType> result = new ResultModel<RepairType>();
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);
}
}
}

37
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
{
/// <summary>
/// 維修方式資料表
/// </summary>
[Table("REPAIR_TYPE", Schema = "JHAMES")]
[DataContract]
public class RepairType
{
/// <summary>
/// 維修項目代碼
/// </summary>
[Key]
[Column("REPAIR_TYPE_NO")]
[Required(ErrorMessage = "{0},不能空白")]
[Display(Name = "維修項目代碼")]
[StringLength(6, ErrorMessage = "{0},不能大于{1}")]
[DataMember]
public string RepairTypeNo { get; set; }
/// <summary>
/// 維修項目名稱
/// </summary>
[Column("REPAIR_TYPE_DESC")]
[DataMember]
[Required(ErrorMessage = "{0},不能空白")]
[Display(Name = "維修項目名稱")]
[StringLength(100, ErrorMessage = "{0},不能大于{1}")]
public string RepairTypeDesc { get; set; }
}
}

7
AMESCoreStudio.WebApi/Models/AMESContext.cs

@ -272,7 +272,7 @@ namespace AMESCoreStudio.WebApi
public DbSet<RMAReason> RMAReasons { get; set; }
/// <summary>
/// 标准工时资
/// 機種C/T資
/// </summary>
public DbSet<CycleTime> CycleTimes { get; set; }
@ -285,6 +285,11 @@ namespace AMESCoreStudio.WebApi
/// 問題類別資料
/// </summary>
public DbSet<QAType> QATypes { get; set; }
/// <summary>
/// 維修方式資料
/// </summary>
public DbSet<RepairType> RepairTypes { get; set; }
}
}

Loading…
Cancel
Save