|
@ -503,7 +503,277 @@ namespace AMESCoreStudio.Web.Controllers |
|
|
|
|
|
|
|
|
//頁面提交,id=0 添加,id>0 修改
|
|
|
//頁面提交,id=0 添加,id>0 修改
|
|
|
[HttpPost] |
|
|
[HttpPost] |
|
|
public async Task<IActionResult> REP001RSaveAsync(REP001ViewModel model, IFormFile formFile) |
|
|
public async Task<IActionResult> REP001RSaveAsync(REP001ViewModel model, List<IFormFile> formFile) |
|
|
|
|
|
{ |
|
|
|
|
|
IResultModel result; |
|
|
|
|
|
var userID = ""; |
|
|
|
|
|
HttpContext.Request.Cookies.TryGetValue("UserID", out userID); |
|
|
|
|
|
int user_id = 0; |
|
|
|
|
|
if (userID != null) |
|
|
|
|
|
{ |
|
|
|
|
|
if (int.Parse(userID.ToString()) >= 0) |
|
|
|
|
|
{ |
|
|
|
|
|
user_id = int.Parse(userID.ToString()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
model.ngComponent.ReplyUserID = user_id; |
|
|
|
|
|
model.ngComponent.ReplyDate = System.DateTime.Now; |
|
|
|
|
|
model.ngComponent.Status = 1; |
|
|
|
|
|
model.ngComponent.UpdateUserID = user_id; |
|
|
|
|
|
|
|
|
|
|
|
string FileName = string.Empty; |
|
|
|
|
|
string NewName = string.Empty; |
|
|
|
|
|
string FilePath = string.Empty; |
|
|
|
|
|
string[] newFileName = null; |
|
|
|
|
|
|
|
|
|
|
|
if (formFile != null) |
|
|
|
|
|
{ |
|
|
|
|
|
if (formFile.Count > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
newFileName = new string[formFile.Count]; |
|
|
|
|
|
int idx = 0; |
|
|
|
|
|
foreach (var item in formFile) |
|
|
|
|
|
{ |
|
|
|
|
|
if (item.Length > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
//取得使用者上傳檔案的原始檔名
|
|
|
|
|
|
FileName = Path.GetFileName(item.FileName); |
|
|
|
|
|
//取原始檔名中的副檔名
|
|
|
|
|
|
var fileExt = Path.GetExtension(FileName); |
|
|
|
|
|
//為避免使用者上傳的檔案名稱發生重複,重新給一個亂數名稱
|
|
|
|
|
|
NewName = Path.GetRandomFileName() + fileExt; |
|
|
|
|
|
newFileName[idx] = NewName; |
|
|
|
|
|
idx = idx + 1; |
|
|
|
|
|
//指定要寫入的路徑、檔名和副檔名
|
|
|
|
|
|
FilePath = $"\\REPImage\\";//本機目錄
|
|
|
|
|
|
using (var stream = new FileStream(_env.WebRootPath + FilePath + NewName, FileMode.Create)) |
|
|
|
|
|
{ |
|
|
|
|
|
await item.CopyToAsync(stream); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
var ng_repiar_blob = await _repApi.GetNgRepairBlob(model.ngRepair.RepairID); |
|
|
|
|
|
|
|
|
|
|
|
if (ng_repiar_blob.Count == 0) |
|
|
|
|
|
{ |
|
|
|
|
|
ModelState.AddModelError("error", "請選擇要上傳檔案"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (model.ngRepair.Missing == "Y") |
|
|
|
|
|
{ |
|
|
|
|
|
model.ngRepair.RepairNo = "N/A"; |
|
|
|
|
|
model.ngComponent.Status = 2; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
result = await _repApi.PutNgComponent((int)model.ngComponent.ComponentID, JsonConvert.SerializeObject(model.ngComponent)); |
|
|
|
|
|
|
|
|
|
|
|
if (model.repairRecord.ComponentID > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
model.repairRecord.UpdateUserID = user_id; |
|
|
|
|
|
result = await _repApi.PutRepairRecord((int)model.repairRecord.ComponentID, JsonConvert.SerializeObject(model.repairRecord)); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
model.repairRecord.CreateUserID = user_id; |
|
|
|
|
|
model.repairRecord.NgID = model.ngComponent.NgID; |
|
|
|
|
|
model.repairRecord.ComponentID = model.ngComponent.ComponentID; |
|
|
|
|
|
model.repairRecord.RepairDesc = model.ngRepair.RepairDesc; |
|
|
|
|
|
result = await _repApi.PostRepairRecord(JsonConvert.SerializeObject(model.repairRecord)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (model.ngRepair.RepairID > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
model.ngRepair.UpdateUserID = user_id; |
|
|
|
|
|
result = await _repApi.PutNgRepair((int)model.ngRepair.RepairID, JsonConvert.SerializeObject(model.ngRepair)); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
model.ngRepair.CreateUserID = user_id; |
|
|
|
|
|
model.ngRepair.NgID = model.ngComponent.NgID; |
|
|
|
|
|
model.ngRepair.ComponentID = model.ngComponent.ComponentID; |
|
|
|
|
|
result = await _repApi.PostNgRepair(JsonConvert.SerializeObject(model.ngRepair)); |
|
|
|
|
|
} |
|
|
|
|
|
if (NewName == string.Empty) |
|
|
|
|
|
{ } |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
decimal repairID = 0; |
|
|
|
|
|
if (model.ngRepair.RepairID == 0) |
|
|
|
|
|
{ |
|
|
|
|
|
var ng_repair = await _repApi.GetNgRepairByComponent(model.ngRepair.ComponentID); |
|
|
|
|
|
repairID = ng_repair[0].RepairID; |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
repairID = model.ngRepair.RepairID; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (model.ngRepairBlob == null) |
|
|
|
|
|
{ |
|
|
|
|
|
for (int f = 0; f < newFileName.Length; f++) |
|
|
|
|
|
{ |
|
|
|
|
|
NgRepairBlob ng_repair_blob = new NgRepairBlob(); |
|
|
|
|
|
ng_repair_blob.ImageName = newFileName[f]; |
|
|
|
|
|
ng_repair_blob.RepairID = repairID; |
|
|
|
|
|
|
|
|
|
|
|
model.ngRepairBlob = ng_repair_blob; |
|
|
|
|
|
|
|
|
|
|
|
result = await _repApi.PostNgRepairBlob(JsonConvert.SerializeObject(model.ngRepairBlob)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
for (int f = 0; f < newFileName.Length; f++) |
|
|
|
|
|
{ |
|
|
|
|
|
model.ngRepairBlob.ImageName = newFileName[f]; |
|
|
|
|
|
model.ngRepairBlob.RepairID = repairID; |
|
|
|
|
|
|
|
|
|
|
|
result = await _repApi.PostNgRepairBlob(JsonConvert.SerializeObject(model.ngRepairBlob)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//if (result.Success)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// var _msg = model.ngRepairBlob.RepairID == 0 ? "新增成功!" : "修改成功!";
|
|
|
|
|
|
// return RedirectToAction("Refresh", "Home", new { msg = _msg });
|
|
|
|
|
|
//}
|
|
|
|
|
|
//else
|
|
|
|
|
|
//{
|
|
|
|
|
|
// ModelState.AddModelError("error", result.Msg);
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
bool repairComplete = true; |
|
|
|
|
|
|
|
|
|
|
|
var ng_component = await _repApi.GetNgComponentByNGID(model.ngInfo.NgID); |
|
|
|
|
|
for (int i = 0; i < ng_component.Count; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
if (ng_component[i].Status == 0) |
|
|
|
|
|
{ |
|
|
|
|
|
repairComplete = false; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
List<BarCodeCheckDto.inputItem> items = new List<BarCodeCheckDto.inputItem>(); |
|
|
|
|
|
//判斷組件是否更換
|
|
|
|
|
|
for (int i = 0; i < ng_component.Count; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
if (ng_component[i].NewPartNo != "" && ng_component[i].NewPartNo != null) |
|
|
|
|
|
{ |
|
|
|
|
|
items.Add(new BarCodeCheckDto.inputItem |
|
|
|
|
|
{ |
|
|
|
|
|
inputType = "KP", |
|
|
|
|
|
inputData = ng_component[i].NewPartNo, |
|
|
|
|
|
oldInputData = ng_component[i].OldPartNo |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (items.Count == 0) |
|
|
|
|
|
{ |
|
|
|
|
|
items = null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (repairComplete) |
|
|
|
|
|
{ |
|
|
|
|
|
//判断全部维修完成过站
|
|
|
|
|
|
int repairStationID = -1; |
|
|
|
|
|
|
|
|
|
|
|
//獲取流程ID
|
|
|
|
|
|
int wip_id = model.ngInfo.Barcode.WipID; |
|
|
|
|
|
var wip_info = await _pcsApi.GetWipInfo(wip_id); |
|
|
|
|
|
int flow_rule_id = wip_info[0].FlowRuleID; |
|
|
|
|
|
|
|
|
|
|
|
var rules = await _basApi.GetRules2(flow_rule_id, model.ngInfo.Barcode.StationID, model.ngInfo.Barcode.RuleStatus, repairStationID); |
|
|
|
|
|
if (rules.Count > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
for (int i = 0; i < rules.Count; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
if (rules[i].RuleStatus == model.ngInfo.Barcode.RuleStatus) |
|
|
|
|
|
{ |
|
|
|
|
|
repairStationID = rules[i].NextStationID; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int lineID = -1; |
|
|
|
|
|
if (model.ngInfo.Wip.LineID != null) |
|
|
|
|
|
{ |
|
|
|
|
|
lineID = model.ngInfo.Wip.LineID.Value; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//准备资料
|
|
|
|
|
|
var barCode = new BarCodeCheckDto |
|
|
|
|
|
{ |
|
|
|
|
|
wipNo = model.ngInfo.Wip.WipNO, |
|
|
|
|
|
barcode = model.ngInfo.Barcode.BarcodeNo, |
|
|
|
|
|
barcodeType = "S", |
|
|
|
|
|
stationID = repairStationID, |
|
|
|
|
|
line = lineID, |
|
|
|
|
|
unitNo = model.ngInfo.Wip.UnitNO, |
|
|
|
|
|
inputItems = items, |
|
|
|
|
|
userID = user_id |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
var barcode_result = new ResultModel<string>(); |
|
|
|
|
|
try |
|
|
|
|
|
{ |
|
|
|
|
|
barcode_result = await _pcsApi.PassIngByCheck(JsonConvert.SerializeObject(barCode)); |
|
|
|
|
|
} |
|
|
|
|
|
catch { } |
|
|
|
|
|
|
|
|
|
|
|
if (barcode_result.Success) |
|
|
|
|
|
{ |
|
|
|
|
|
//更新NG_INFO
|
|
|
|
|
|
//var ng_info = await _repApi.GetNgInfo((int)model.ngInfo.NgID);
|
|
|
|
|
|
//ng_info[0].Status = 1;
|
|
|
|
|
|
model.ngInfo.Status = 1; |
|
|
|
|
|
result = await _repApi.PutNgInfo(JsonConvert.SerializeObject(model.ngInfo)); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
return RedirectToAction("Refresh", "Home", new { id = model.ngComponent.NgID, msg = barcode_result.Msg }); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (result.Success) |
|
|
|
|
|
{ |
|
|
|
|
|
var _msg = "保存成功!"; |
|
|
|
|
|
//return RedirectToAction("REP001V", "REP", new { id = model.ngComponent.NgID, msg = _msg });
|
|
|
|
|
|
return RedirectToAction("Refresh", "Home", new { id = model.ngComponent.NgID, msg = _msg }); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
if (result.Errors != null) |
|
|
|
|
|
{ |
|
|
|
|
|
ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
ModelState.AddModelError("error", result.Msg); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return View("REP001R", model); |
|
|
|
|
|
//return RedirectToAction("REP001V", "REP", new { id = model.ngComponent.NgID });
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//頁面提交,id=0 添加,id>0 修改
|
|
|
|
|
|
[HttpPost] |
|
|
|
|
|
public async Task<IActionResult> REP001RSave1Async(REP001ViewModel model, IFormFile formFile) |
|
|
{ |
|
|
{ |
|
|
IResultModel result; |
|
|
IResultModel result; |
|
|
var userID = ""; |
|
|
var userID = ""; |
|
|