9 changed files with 671 additions and 0 deletions
@ -0,0 +1,100 @@ |
|||
@{ |
|||
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: 'itemNo', |
|||
width: 200, |
|||
title: '組件代碼' |
|||
}, |
|||
{ |
|||
field: 'itemName', |
|||
title: '組件名稱' |
|||
}, |
|||
{ |
|||
field: 'itemType', |
|||
width: 200, |
|||
title: '組件類別' |
|||
}, |
|||
{ |
|||
field: 'snInterval', |
|||
width: 200, |
|||
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.itemNo) { |
|||
hg.open('修改組件類別', '/KCS/KCS006U/' + obj.data.itemNo, 640,480); |
|||
} |
|||
} |
|||
|
|||
//通过行tool删除,lay-event="del" |
|||
function del(obj) { |
|||
if (obj.data.itemNo) { |
|||
hg.confirm("組件類別:" + obj.data.itemNo + "," + obj.data.itemName + ",确定要删除吗?", function () { |
|||
$.ajax({ |
|||
url: '/KCS/KCS006D', |
|||
data: { id: obj.data.itemNo }, |
|||
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('新增組件類別', '/KCS/KCS006C', 640, 480); |
|||
|
|||
} |
|||
} |
|||
]; |
|||
//基本数据表格 |
|||
var table = hg.table.datatable('test', '組件類別維護', '/KCS/GetItems', {}, tableCols, toolbar, true, 'full-100', ['filter', 'print', 'exports']); |
|||
</script> |
|||
} |
@ -0,0 +1,63 @@ |
|||
@model AMESCoreStudio.WebApi.Models.AMES.Items |
|||
|
|||
|
|||
@{ ViewData["Title"] = "KCS006C"; |
|||
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="KCS006CSave"> |
|||
<div asp-validation-summary="ModelOnly" class="text-danger"></div> |
|||
|
|||
<div class="form-group form-inline my-sm-1"> |
|||
<label asp-for="ItemNo" class="control-label col-sm-3"></label> |
|||
<input asp-for="ItemNo" class="form-control col-sm-9" placeholder="請輸入組件代碼" /> |
|||
<span asp-validation-for="ItemNo" class="text-danger offset-sm-3 my-sm-1"></span> |
|||
</div> |
|||
<div class="form-group form-inline my-sm-1"> |
|||
<label asp-for="ItemName" class="control-label col-sm-3"></label> |
|||
<input asp-for="ItemName" class="form-control col-sm-9" placeholder="請輸入組件名稱" /> |
|||
<span asp-validation-for="ItemName" class="text-danger offset-sm-3 my-sm-1"></span> |
|||
</div> |
|||
<div class="form-group form-inline my-sm-1"> |
|||
<label asp-for="ItemType" class="control-label col-sm-3"></label> |
|||
<select asp-for="ItemType" asp-items="@ViewBag.ItemTypeList" class="custom-select col-sm-9"></select> |
|||
<span asp-validation-for="ItemType" class="text-danger offset-sm-3 my-sm-1"></span> |
|||
</div> |
|||
<div class="form-group form-inline my-sm-1"> |
|||
<label asp-for="SNInterval" class="control-label col-sm-3"></label> |
|||
<select asp-for="SNInterval" asp-items="@ViewBag.SNIntervalList" class="custom-select col-sm-9"></select> |
|||
<span asp-validation-for="SNInterval" 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,63 @@ |
|||
@model AMESCoreStudio.WebApi.Models.AMES.Items |
|||
|
|||
|
|||
@{ ViewData["Title"] = "KCS006U"; |
|||
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="KCS006USave"> |
|||
<div asp-validation-summary="ModelOnly" class="text-danger"></div> |
|||
|
|||
<div class="form-group form-inline my-sm-1"> |
|||
<label asp-for="ItemNo" class="control-label col-sm-3"></label> |
|||
<input asp-for="ItemNo" class="form-control col-sm-9" placeholder="請輸入組件代碼" readonly="readonly" /> |
|||
<span asp-validation-for="ItemNo" class="text-danger offset-sm-3 my-sm-1"></span> |
|||
</div> |
|||
<div class="form-group form-inline my-sm-1"> |
|||
<label asp-for="ItemName" class="control-label col-sm-3"></label> |
|||
<input asp-for="ItemName" class="form-control col-sm-9" placeholder="請輸入組件名稱" /> |
|||
<span asp-validation-for="ItemName" class="text-danger offset-sm-3 my-sm-1"></span> |
|||
</div> |
|||
<div class="form-group form-inline my-sm-1"> |
|||
<label asp-for="ItemType" class="control-label col-sm-3"></label> |
|||
<select asp-for="ItemType" asp-items="@ViewBag.ItemTypeList" class="custom-select col-sm-9"></select> |
|||
<span asp-validation-for="ItemType" class="text-danger offset-sm-3 my-sm-1"></span> |
|||
</div> |
|||
<div class="form-group form-inline my-sm-1"> |
|||
<label asp-for="SNInterval" class="control-label col-sm-3"></label> |
|||
<select asp-for="SNInterval" asp-items="@ViewBag.SNIntervalList" class="custom-select col-sm-9"></select> |
|||
<span asp-validation-for="SNInterval" 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,192 @@ |
|||
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 ItemsController : ControllerBase |
|||
{ |
|||
private readonly AMESContext _context; |
|||
|
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
/// <param name="context"></param>
|
|||
public ItemsController(AMESContext context) |
|||
{ |
|||
_context = context; |
|||
} |
|||
|
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
/// <returns></returns>
|
|||
// GET: api/Items
|
|||
[HttpGet] |
|||
public async Task<ActionResult<IEnumerable<Items>>> GetItems(int page=1,int limit=10) |
|||
{ |
|||
IQueryable<Items> q = _context.Items; |
|||
if (page > 0) |
|||
{ |
|||
q = q.OrderBy(p => p.ItemNo).Skip((page - 1) * limit).Take(limit); |
|||
} |
|||
else |
|||
{ |
|||
q = q.OrderBy(p => p.ItemNo); |
|||
} |
|||
|
|||
var items = await q.ToListAsync(); |
|||
|
|||
return items; |
|||
} |
|||
|
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
/// <param name="id"></param>
|
|||
/// <returns></returns>
|
|||
// GET: api/Items/5
|
|||
[HttpGet("{id}")] |
|||
public async Task<ActionResult<IEnumerable<Items>>> GetItems(string id) |
|||
{ |
|||
IQueryable<Items> q = _context.Items; |
|||
q = q.Where(p => p.ItemNo.Equals(id)); |
|||
|
|||
var items = await q.ToListAsync(); |
|||
|
|||
if (items == null) |
|||
{ |
|||
return NotFound(); |
|||
} |
|||
|
|||
return items; |
|||
} |
|||
|
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
/// <param name="id"></param>
|
|||
/// <param name="items"></param>
|
|||
/// <returns></returns>
|
|||
// PUT: api/Items/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<Items>> PutItems(string id,[FromBody] Items items) |
|||
{ |
|||
ResultModel<Items> result = new ResultModel<Items>(); |
|||
|
|||
if (id != items.ItemNo) |
|||
{ |
|||
result.Success = false; |
|||
result.Msg = "組件代碼錯誤"; |
|||
return result; |
|||
} |
|||
|
|||
_context.Entry(items).State = EntityState.Modified; |
|||
|
|||
try |
|||
{ |
|||
await _context.SaveChangesAsync(); |
|||
} |
|||
catch (DbUpdateConcurrencyException) |
|||
{ |
|||
if (!ItemsExists(id)) |
|||
{ |
|||
result.Success = false; |
|||
result.Msg = "組件代碼不存在"; |
|||
return result; |
|||
} |
|||
else |
|||
{ |
|||
throw; |
|||
} |
|||
} |
|||
|
|||
result.Success = true; |
|||
result.Msg = "OK"; |
|||
return result; |
|||
} |
|||
|
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
/// <param name="items"></param>
|
|||
/// <returns></returns>
|
|||
// POST: api/Items
|
|||
// 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<Items>> PostItems([FromBody] Items items) |
|||
{ |
|||
ResultModel<Items> result = new ResultModel<Items>(); |
|||
|
|||
_context.Items.Add(items); |
|||
try |
|||
{ |
|||
await _context.SaveChangesAsync(); |
|||
} |
|||
catch (DbUpdateException) |
|||
{ |
|||
if (ItemsExists(items.ItemNo)) |
|||
{ |
|||
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/Items/5
|
|||
[HttpDelete("{id}")] |
|||
public async Task<ResultModel<Items>> DeleteItems(string id) |
|||
{ |
|||
ResultModel<Items> result = new ResultModel<Items>(); |
|||
|
|||
var items = await _context.Items.FindAsync(id); |
|||
if (items == null) |
|||
{ |
|||
result.Success = false; |
|||
result.Msg = "組件代碼不存在"; |
|||
return result; |
|||
} |
|||
|
|||
_context.Items.Remove(items); |
|||
await _context.SaveChangesAsync(); |
|||
|
|||
result.Success = true; |
|||
result.Msg = "OK"; |
|||
return result; |
|||
} |
|||
|
|||
private bool ItemsExists(string id) |
|||
{ |
|||
return _context.Items.Any(e => e.ItemNo == id); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,58 @@ |
|||
using System; |
|||
using System.ComponentModel.DataAnnotations; |
|||
using System.ComponentModel.DataAnnotations.Schema; |
|||
using System.Runtime.Serialization; |
|||
|
|||
namespace AMESCoreStudio.WebApi.Models.AMES |
|||
{ |
|||
/// <summary>
|
|||
/// 組件類別资料表
|
|||
/// </summary>
|
|||
[Table("ITEMS", Schema = "JHAMES")] |
|||
[DataContract] |
|||
public class Items |
|||
{ |
|||
/// <summary>
|
|||
/// 組件代碼
|
|||
/// </summary>
|
|||
[Key] |
|||
[Column("ITEM_NO")] |
|||
[Required(ErrorMessage = "{0},不能空白")] |
|||
[Display(Name = "組件代碼")] |
|||
[StringLength(4, ErrorMessage = "{0},不能大于{1}")] |
|||
[DataMember] |
|||
public string ItemNo { get; set; } |
|||
|
|||
|
|||
/// <summary>
|
|||
/// 組件名稱
|
|||
/// </summary>
|
|||
[Column("ITEM_NAME")] |
|||
[Required(ErrorMessage = "{0},不能空白")] |
|||
[Display(Name = "組件名稱")] |
|||
[StringLength(50, ErrorMessage = "{0},不能大于{1}")] |
|||
[DataMember] |
|||
public string ItemName { get; set; } |
|||
|
|||
|
|||
/// <summary>
|
|||
/// 組件類別
|
|||
/// </summary>
|
|||
[Column("ITEM_TYPE")] |
|||
[DataMember] |
|||
[Required(ErrorMessage = "{0},不能空白")] |
|||
[Display(Name = "組件類別")] |
|||
[StringLength(2, ErrorMessage = "{0},不能大于{1}")] |
|||
public string ItemType { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 組件區間管控
|
|||
/// </summary>
|
|||
[Column("SN_INTERVAL")] |
|||
[DataMember] |
|||
[Required(ErrorMessage = "{0},不能空白")] |
|||
[Display(Name = "組件區間管控")] |
|||
[StringLength(1, ErrorMessage = "{0},不能大于{1}")] |
|||
public string SNInterval { get; set; } |
|||
} |
|||
} |
Loading…
Reference in new issue