|
|
@ -3231,12 +3231,12 @@ namespace AMESCoreStudio.Web.Controllers |
|
|
|
|
|
|
|
if (Type == "all") |
|
|
|
{ |
|
|
|
UnitItems.Add(new SelectListItem("全部", "all")); |
|
|
|
UnitItems.Add(new SelectListItem("全部", "-99")); |
|
|
|
} |
|
|
|
for (int i = 0; i < result.Count; i++) |
|
|
|
if (result[i].StatusNo == "A") |
|
|
|
{ |
|
|
|
UnitItems.Add(new SelectListItem(result[i].WorkingUnitName, result[i].WorkingUnitNo.ToString())); |
|
|
|
UnitItems.Add(new SelectListItem(result[i].WorkingUnitName, result[i].WorkingUnitID.ToString())); |
|
|
|
} |
|
|
|
|
|
|
|
ViewBag.WorkingUnitNo = UnitItems; |
|
|
@ -3437,7 +3437,7 @@ namespace AMESCoreStudio.Web.Controllers |
|
|
|
|
|
|
|
[ResponseCache(Duration = 0)] |
|
|
|
[HttpGet] |
|
|
|
public async Task<IActionResult> GetWorkingStationsAsync(string id) |
|
|
|
public async Task<IActionResult> GetWorkingStationsAsync(int id) |
|
|
|
{ |
|
|
|
var result = await _whsApi.GetWorkingStationsbyMultiUnit(id); |
|
|
|
|
|
|
@ -3452,7 +3452,7 @@ namespace AMESCoreStudio.Web.Controllers |
|
|
|
|
|
|
|
[ResponseCache(Duration = 0)] |
|
|
|
[HttpGet] |
|
|
|
public async Task<IActionResult> GetWorkingLinesAsync(string id) |
|
|
|
public async Task<IActionResult> GetWorkingLinesAsync(int id) |
|
|
|
{ |
|
|
|
// var result = await _whsApi.GetWorkingLinesbyUnit(id);
|
|
|
|
var result = await _whsApi.GetWorkingLinesbyMultiUnit(id); |
|
|
@ -3477,8 +3477,8 @@ namespace AMESCoreStudio.Web.Controllers |
|
|
|
public async Task<IActionResult> WHS025C() |
|
|
|
{ |
|
|
|
await GetWorkingUnit(""); //報工生產單位
|
|
|
|
await GetFactoryUnitsListbyWH005(""); //途程生產單位
|
|
|
|
GetSideList(); |
|
|
|
await GetFactoryUnitsListbyWH025(""); //途程生產單位
|
|
|
|
GetSideListByWH025(); |
|
|
|
return View(); |
|
|
|
} |
|
|
|
//修改页面
|
|
|
@ -3486,8 +3486,8 @@ namespace AMESCoreStudio.Web.Controllers |
|
|
|
public async Task<IActionResult> WHS025UAsync(int id) |
|
|
|
{ |
|
|
|
await GetWorkingUnit(""); //報工生產單位
|
|
|
|
|
|
|
|
GetSideList(); |
|
|
|
|
|
|
|
GetSideListByWH025(); |
|
|
|
|
|
|
|
var result = await _whsApi.GetWorkingStandardWorkTime(id); |
|
|
|
|
|
|
@ -3507,73 +3507,56 @@ namespace AMESCoreStudio.Web.Controllers |
|
|
|
[HttpPost] |
|
|
|
public async Task<IActionResult> WHS025CSaveAsync(WHS025ViewModel model) |
|
|
|
{ |
|
|
|
if (!ModelState.IsValid) |
|
|
|
return View("WHS025C", model); |
|
|
|
|
|
|
|
// 若 WorkingLineIDs 為空,直接回傳錯誤
|
|
|
|
if (model.WorkingLineIDs == null) |
|
|
|
if (ModelState.IsValid) |
|
|
|
{ |
|
|
|
ModelState.AddModelError("error", "請至少選擇一個線別"); |
|
|
|
return View("WHS025C", model); |
|
|
|
} |
|
|
|
// 複製 model 中的其他欄位,產生新的物件
|
|
|
|
var item = new WorkingStandardWorkTime |
|
|
|
{ |
|
|
|
WorkingStandardID = model.WorkingStandardID, |
|
|
|
ItemNo = model.ItemNo, |
|
|
|
WorkingUnitNo = model.WorkingUnitNo, |
|
|
|
UnitNo = model.UnitNo, |
|
|
|
WorkingStationID = model.WorkingStationID, |
|
|
|
Side = model.Side, |
|
|
|
OpCnt = model.OpCnt, |
|
|
|
Ct = model.Ct, |
|
|
|
StationID = model.StationID, |
|
|
|
MachineCnt = model.MachineCnt, |
|
|
|
Remark = model.Remark, |
|
|
|
CreateUserID = model.CreateUserID, |
|
|
|
UpdateUserID = model.UpdateUserID, |
|
|
|
CreateDate = model.CreateDate, |
|
|
|
UpdateDate = model.UpdateDate |
|
|
|
}; |
|
|
|
|
|
|
|
foreach (var lineId in model.WorkingLineIDs) |
|
|
|
{ |
|
|
|
item.WorkingLineID = lineId; // ⭐ 關鍵:取代為迴圈內的 lineId
|
|
|
|
|
|
|
|
var json = JsonConvert.SerializeObject(item); |
|
|
|
var result = await _whsApi.PostWorkingStandardWorkTime(json); |
|
|
|
if (!result.Success) |
|
|
|
{ |
|
|
|
// 其中一筆失敗就回傳錯誤
|
|
|
|
ModelState.AddModelError("error", $"線別ID {lineId} 錯誤:{result.Msg}"); |
|
|
|
|
|
|
|
// 若 WorkingLineIDs 為空,直接回傳錯誤
|
|
|
|
if (model.WorkingLineIDs == null) |
|
|
|
{ |
|
|
|
ModelState.AddModelError("error", "請至少選擇一個線別"); |
|
|
|
return View("WHS025C", model); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return RedirectToAction("Refresh", "Home", new { msg = "添加成功!" }); |
|
|
|
|
|
|
|
|
|
|
|
//if (ModelState.IsValid)
|
|
|
|
//{
|
|
|
|
// IResultModel result;
|
|
|
|
// 複製 model 中的其他欄位,產生新的物件
|
|
|
|
var item = new WorkingStandardWorkTime |
|
|
|
{ |
|
|
|
WorkingStandardID = model.WorkingStandardID, |
|
|
|
ItemNo = model.ItemNo, |
|
|
|
WorkingUnitID = model.WorkingUnitID, |
|
|
|
UnitNo = model.UnitNo, |
|
|
|
WorkingStationID = model.WorkingStationID, |
|
|
|
Side = model.Side, |
|
|
|
OpCnt = model.OpCnt, |
|
|
|
Ct = model.Ct, |
|
|
|
MachineCnt = model.MachineCnt, |
|
|
|
Remark = model.Remark, |
|
|
|
CreateUserID = model.CreateUserID, |
|
|
|
UpdateUserID = model.UpdateUserID, |
|
|
|
CreateDate = model.CreateDate, |
|
|
|
UpdateDate = model.UpdateDate |
|
|
|
}; |
|
|
|
|
|
|
|
foreach (var lineId in model.WorkingLineIDs) |
|
|
|
{ |
|
|
|
item.WorkingLineID = lineId; // ⭐ 關鍵:取代為迴圈內的 lineId
|
|
|
|
|
|
|
|
// result = await _whsApi.PostWorkingStandardWorkTime(JsonConvert.SerializeObject(model));
|
|
|
|
var json = JsonConvert.SerializeObject(item); |
|
|
|
var result = await _whsApi.PostWorkingStandardWorkTime(json); |
|
|
|
if (!result.Success) |
|
|
|
{ |
|
|
|
// 其中一筆失敗就回傳錯誤
|
|
|
|
ModelState.AddModelError("error", $"線別ID {lineId} 錯誤:{result.Msg}"); |
|
|
|
return View("WHS025C", model); |
|
|
|
} |
|
|
|
|
|
|
|
// if (result.Success)
|
|
|
|
// {
|
|
|
|
// var _msg = "添加成功!";
|
|
|
|
// return RedirectToAction("Refresh", "Home", new { msg = _msg });
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
} |
|
|
|
|
|
|
|
// ModelState.AddModelError("error", result.Msg);
|
|
|
|
return RedirectToAction("Refresh", "Home", new { msg = "添加成功!" }); |
|
|
|
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
//return View("WHS025C", model);
|
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
return View("WHS025C", model); |
|
|
|
} |
|
|
|
} |
|
|
|
public async Task<IActionResult> WHS025USaveAsync(WorkingStandardWorkTime model) |
|
|
|
{ |
|
|
@ -3610,9 +3593,9 @@ namespace AMESCoreStudio.Web.Controllers |
|
|
|
|
|
|
|
[ResponseCache(Duration = 0)] |
|
|
|
[HttpGet] |
|
|
|
public async Task<IActionResult> GetWorkingUnitNobyUnitAsync(string id) |
|
|
|
public async Task<IActionResult> GetWorkingUnitNobyUnitAsync(int id) |
|
|
|
{ |
|
|
|
var result = await _whsApi.GetWorkingUnitbyNo(id); |
|
|
|
var result = await _whsApi.GetWorkingUnit(id); |
|
|
|
var data = new List<FactoryUnit>(); |
|
|
|
|
|
|
|
if (result != null && result.Count > 0) |
|
|
@ -3643,7 +3626,7 @@ namespace AMESCoreStudio.Web.Controllers |
|
|
|
|
|
|
|
[ResponseCache(Duration = 0)] |
|
|
|
[HttpGet] |
|
|
|
public async Task<IActionResult> GetWorkingLinesbyUnitAsync(string id) |
|
|
|
public async Task<IActionResult> GetWorkingLinesbyUnitAsync(int id) |
|
|
|
{ |
|
|
|
// var result = await _whsApi.GetWorkingLinesbyUnit(id);
|
|
|
|
var result = await _whsApi.GetWorkingLinesbyMultiUnit(id); |
|
|
@ -3661,7 +3644,7 @@ namespace AMESCoreStudio.Web.Controllers |
|
|
|
|
|
|
|
[ResponseCache(Duration = 0)] |
|
|
|
[HttpGet] |
|
|
|
public async Task<IActionResult> GetWorkingStationsbyUnitAsync(string id) |
|
|
|
public async Task<IActionResult> GetWorkingStationsbyUnitAsync(int id) |
|
|
|
{ |
|
|
|
var result = await _whsApi.GetWorkingStationsbyUnit(id); |
|
|
|
|
|
|
@ -3691,7 +3674,7 @@ namespace AMESCoreStudio.Web.Controllers |
|
|
|
|
|
|
|
[ResponseCache(Duration = 0)] |
|
|
|
[HttpGet] |
|
|
|
public async Task<IActionResult> GetWorkingStandardWorkTimes2Async(string u, int l, string i, int page = 0, int limit = 10) |
|
|
|
public async Task<IActionResult> GetWorkingStandardWorkTimes2Async(int u, int l, string i, int page = 0, int limit = 10) |
|
|
|
{ |
|
|
|
if (l == 0) |
|
|
|
{ |
|
|
@ -3703,9 +3686,9 @@ namespace AMESCoreStudio.Web.Controllers |
|
|
|
i = "Null"; |
|
|
|
} |
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(u)) |
|
|
|
if (u == 0) |
|
|
|
{ |
|
|
|
u = "Null"; |
|
|
|
u = -99; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -3718,7 +3701,7 @@ namespace AMESCoreStudio.Web.Controllers |
|
|
|
return Json(new Table() { count = 0, data = null }); |
|
|
|
} |
|
|
|
|
|
|
|
private async Task GetFactoryUnitsListbyWH005(string Types) |
|
|
|
private async Task GetFactoryUnitsListbyWH025(string Types) |
|
|
|
{ |
|
|
|
var result = await _basApi.GetFactoryUnits(); |
|
|
|
|
|
|
@ -3748,6 +3731,16 @@ namespace AMESCoreStudio.Web.Controllers |
|
|
|
return Json(new Table() { count = 0, data = null }); |
|
|
|
} |
|
|
|
|
|
|
|
private void GetSideListByWH025() |
|
|
|
{ |
|
|
|
|
|
|
|
var SideItems = new List<SelectListItem>(); |
|
|
|
SideItems.Add(new SelectListItem("N/A", "N/A")); |
|
|
|
SideItems.Add(new SelectListItem("A", "A")); |
|
|
|
SideItems.Add(new SelectListItem("B", "B")); |
|
|
|
|
|
|
|
ViewBag.SideList = SideItems; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 標準工時批次Excel匯入
|
|
|
@ -3777,6 +3770,16 @@ namespace AMESCoreStudio.Web.Controllers |
|
|
|
var columnCount = data.ColumnCount(); |
|
|
|
var ErrorMsg = ""; |
|
|
|
var recordKeys = new HashSet<string>(); // 用於檢查組合是否重複
|
|
|
|
var result = await _whsApi.GetWorkingStandardWorkTimesbyMultiQuery(-99, -99, "Null", 0, 99); //將已存在的資料加入組合
|
|
|
|
if (result.DataTotal > 0) |
|
|
|
{ |
|
|
|
foreach (var item in result.Data) |
|
|
|
{ |
|
|
|
var rowKey = $"{item.itemNo}|{item.workingUnitName}|{item.workingLineName}|{item.workingStationName}|{item.side}"; |
|
|
|
recordKeys.Add(rowKey); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
for (int i = 2; i <= rowCount; i++) |
|
|
|
{ |
|
|
|
var rowMsg = $"[第{i}列] "; |
|
|
@ -3786,13 +3789,11 @@ namespace AMESCoreStudio.Web.Controllers |
|
|
|
var WorkingUnitName = data.Cell(i, 2).GetString().Trim(); |
|
|
|
var WorkingLineName = data.Cell(i, 3).GetString().Trim(); |
|
|
|
var WorkingStationName = data.Cell(i, 4).GetString().Trim(); |
|
|
|
// var UnitName = data.Cell(i, 5).GetString().Trim();
|
|
|
|
var Side = data.Cell(i, 5).GetString().Trim(); |
|
|
|
var OpCntStr = data.Cell(i, 6).GetString().Trim(); |
|
|
|
var CtStr = data.Cell(i, 7).GetString().Trim(); |
|
|
|
var StationID = data.Cell(i, 8).GetString().Trim(); |
|
|
|
var MachineCntStr = data.Cell(i, 9).GetString().Trim(); |
|
|
|
var Remark = data.Cell(i, 10).GetString().Trim(); |
|
|
|
var MachineCntStr = data.Cell(i, 8).GetString().Trim(); |
|
|
|
var Remark = data.Cell(i, 9).GetString().Trim(); |
|
|
|
|
|
|
|
// 組合唯一鍵
|
|
|
|
var rowKey = $"{ItemNo}|{WorkingUnitName}|{WorkingLineName}|{WorkingStationName}|{Side}"; |
|
|
@ -3808,12 +3809,11 @@ namespace AMESCoreStudio.Web.Controllers |
|
|
|
if (string.IsNullOrWhiteSpace(WorkingUnitName)) { ErrorMsg += $"{rowMsg}報工生產單位不得為空\n"; continue; } |
|
|
|
if (string.IsNullOrWhiteSpace(WorkingLineName)) { ErrorMsg += $"{rowMsg}報工線別不得為空\n"; continue; } |
|
|
|
if (string.IsNullOrWhiteSpace(WorkingStationName)) { ErrorMsg += $"{rowMsg}報工站別不得為空\n"; continue; } |
|
|
|
// if (string.IsNullOrWhiteSpace(UnitName)) { ErrorMsg += $"{rowMsg}途程單位不得為空\n"; continue; }
|
|
|
|
List<string> validSides = new List<string> { "正面", "背面" }; |
|
|
|
List<string> validSides = new List<string> { "A", "B", "N/A" }; |
|
|
|
if (string.IsNullOrWhiteSpace(Side)) { ErrorMsg += $"{rowMsg}面別不得為空\n"; continue; } |
|
|
|
else if (!validSides.Contains(Side)) |
|
|
|
{ |
|
|
|
ErrorMsg += $"{rowMsg}面別資料錯誤,請使用 N/A、正面、背面\n"; |
|
|
|
ErrorMsg += $"{rowMsg}面別資料錯誤,請使用A、B、N/A\n"; |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
@ -3835,11 +3835,6 @@ namespace AMESCoreStudio.Web.Controllers |
|
|
|
ErrorMsg += $"{rowMsg}CT 必須大於 0\n"; continue; |
|
|
|
} |
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(StationID)) |
|
|
|
{ |
|
|
|
ErrorMsg += $"{rowMsg}工站ID不得為空\n"; continue; |
|
|
|
} |
|
|
|
|
|
|
|
if (!int.TryParse(MachineCntStr, out int MachineCnt)) |
|
|
|
{ |
|
|
|
ErrorMsg += $"{rowMsg}機台數格式錯誤\n"; continue; |
|
|
@ -3857,26 +3852,24 @@ namespace AMESCoreStudio.Web.Controllers |
|
|
|
var WU = await _whsApi.GetWorkingUnitbyName(WorkingUnitName); |
|
|
|
var WL = await _whsApi.GetWorkingLinebyName(WorkingLineName); |
|
|
|
var WS = await _whsApi.GetWorkingStationbyName(WorkingStationName); |
|
|
|
// var UN = await _whsApi.GetFactoryUnitbyName(UnitName);
|
|
|
|
|
|
|
|
|
|
|
|
if (WU.Count == 0) { ErrorMsg += $"{rowMsg}查無 報工生產單位「{WorkingUnitName}」\n"; continue; } |
|
|
|
if (WL.Count == 0) { ErrorMsg += $"{rowMsg}查無 報工線別「{WorkingLineName}」\n"; continue; } |
|
|
|
if (WS.Count == 0) { ErrorMsg += $"{rowMsg}查無 報工站別「{WorkingStationName}」\n"; continue; } |
|
|
|
// if (UN.Count == 0) { ErrorMsg += $"{rowMsg}查無 途程生產單位「{UnitName}」\n"; continue; }
|
|
|
|
|
|
|
|
|
|
|
|
// 加入清單
|
|
|
|
workingST.Add(new WorkingStandardWorkTime |
|
|
|
{ |
|
|
|
WorkingUnitNo = WU[0].WorkingUnitNo, |
|
|
|
WorkingUnitID = WU[0].WorkingUnitID, |
|
|
|
WorkingLineID = WL[0].WorkingLineID, |
|
|
|
WorkingStationID = WS[0].WorkingStationID, |
|
|
|
// UnitNo = UN[0].UnitNo,
|
|
|
|
UnitNo = WU[0].UnitNo, |
|
|
|
ItemNo = ItemNo, |
|
|
|
Side = Side, |
|
|
|
OpCnt = OpCnt, |
|
|
|
Ct = Ct, |
|
|
|
StationID = StationID, |
|
|
|
MachineCnt = MachineCnt, |
|
|
|
Remark = Remark, |
|
|
|
CreateDate = System.DateTime.Now, |
|
|
@ -3910,11 +3903,6 @@ namespace AMESCoreStudio.Web.Controllers |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//将資料Json化并传到前台视图
|
|
|
|
return Json(new { data = "", success = true }); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|