|
|
@ -259,6 +259,112 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 治具使用次數計數
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="OutfitNO">治具編號</param>
|
|
|
|
/// <param name="ItemNo">料號</param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPut("PutForUseTime")] |
|
|
|
public async Task<ResultModel<OutfitInfo>> PutOutfitInfoForUseTim(string OutfitNO, string ItemNo) |
|
|
|
{ |
|
|
|
//YIRU add 2023-04-13
|
|
|
|
ResultModel<OutfitInfo> result = new ResultModel<OutfitInfo>(); |
|
|
|
#region 判斷這個治具可否使用於這個料號
|
|
|
|
//先查詢item id
|
|
|
|
var q_item = await _context.MaterialItems.Where(w => w.ItemNo == ItemNo).FirstOrDefaultAsync(); |
|
|
|
if (q_item == null) |
|
|
|
{ |
|
|
|
result.Success = false; |
|
|
|
result.Msg = "查無料號"; |
|
|
|
return result; |
|
|
|
} |
|
|
|
var q_item1 = await _context.MaterialOutfits.Where(w => w.ItemID == q_item.ItemID && w.OutfitNo == OutfitNO).FirstOrDefaultAsync(); |
|
|
|
if (q_item1 == null) |
|
|
|
{ |
|
|
|
result.Success = false; |
|
|
|
result.Msg = "治具不可使用於此料號"; |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region 判斷這個治具是否為可使用狀態
|
|
|
|
var q = await _context.OutfitInfoes.Where(w => w.OutfitNo == OutfitNO).FirstOrDefaultAsync(); |
|
|
|
if (q == null) |
|
|
|
{ |
|
|
|
result.Success = false; |
|
|
|
result.Msg = "查無治具"; |
|
|
|
return result; |
|
|
|
} |
|
|
|
if (q.StatusNo != "A") |
|
|
|
{ |
|
|
|
|
|
|
|
result.Success = false; |
|
|
|
result.Msg = "治具狀態不可使用"; |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
if (q.UseStatusNo != "N" && q.UseStatusNo != "R") |
|
|
|
{ |
|
|
|
// 使用狀態(新設備 = N ; 報廢 = C; 領用 = B; 維修 = S; 歸還 = R)
|
|
|
|
result.Msg = q.UseStatusNo switch |
|
|
|
{ |
|
|
|
"C" => "治具狀態為報廢不可使用", |
|
|
|
"B" => "治具狀態為領用中不可使用", |
|
|
|
"S" => "治具狀態為維修中不可使用", |
|
|
|
_ => "治具狀態為不可使用", |
|
|
|
}; |
|
|
|
|
|
|
|
result.Success = false; |
|
|
|
return result; |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
#region 判斷這個治具是否已超過可用次數
|
|
|
|
var q1 = await _context.OutfitVarityInfoes.Where(w => w.VarityID == q.VarietyID).FirstOrDefaultAsync(); |
|
|
|
|
|
|
|
if (q.UseTimes >= q1.UseLimitTimes) |
|
|
|
{ |
|
|
|
result.Success = false; |
|
|
|
result.Msg = "治具使用次數已超出"; |
|
|
|
return result; |
|
|
|
} |
|
|
|
if (q.TotalTimes >= q1.UseLimitTimes) |
|
|
|
{ |
|
|
|
result.Success = false; |
|
|
|
result.Msg = "治具累計使用次數已超出"; |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region 治具次數以及累計使用次數累加
|
|
|
|
q.TotalTimes = q.TotalTimes + 1; |
|
|
|
q.UseTimes = q.UseTimes + 1; |
|
|
|
q.UpdateDate = System.DateTime.Now; |
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
_context.Entry(q).State = EntityState.Modified; |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
await _context.SaveChangesAsync(); |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
|
|
|
|
result.Success = false; |
|
|
|
result.Msg = ex.Message; |
|
|
|
return result; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
result.Success = true; |
|
|
|
result.Msg = "OK"; |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private bool OutfitInfoExists(int id) |
|
|
|
{ |
|
|
|
return _context.OutfitInfoes.Any(e => e.OutfitID == id); |
|
|
|