9 changed files with 581 additions and 1 deletions
@ -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: '', |
|||
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> |
|||
} |
@ -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> |
|||
|
|||
|
|||
} |
|||
|
@ -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> |
|||
|
|||
|
|||
} |
|||
|
@ -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); |
|||
} |
|||
} |
|||
} |
@ -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; } |
|||
} |
|||
} |
Loading…
Reference in new issue