public AL_AssmblingLogDataTable AlAssmblingLog_create(int rowCount = 1) { var dt = new AL_AssmblingLogDataTable(); if (rowCount < 0) { rowCount = 0; } for (int i = 0; i < rowCount; i++) { var row = dt.newTypedRow(); row.ns_AssignNewId(); dt.addTypedRow(row); } return(dt); }
public ActionResult Edit(FormCollection collection) { var token = collection["__RequestVerificationToken"]; var mode = collection["ViewMode"]; var id = collection[AppDataName.ALAL_AssmblingLogId]; var msgOK = "OK"; AL_AssmblingLogDataTable dt = null; AL_AssmblingLogRow row = null; try { if (mode.equalIgnoreCase("create")) { dt = AlDataService.Instance.AlAssmblingLog_create(); msgOK = FtdStatus.InsertSuccess.ToString(); } else { //找出該筆資料 dt = AlDataService.Instance.AlAssmblingLog_getById(id); if (dt == null || dt.Count == 0) { return(Json(new { Result = jTable_ERROR_CODE, Message = "資料不存在" })); } msgOK = FtdStatus.UpdateSuccess.ToString(); } //將Form sumit的資料更新至DataRow row = dt.FirstRow; var isOK = this.TryUpdateModel(row); //若驗證失敗-->回傳錯誤訊息 if (!ModelState.IsValid) { var errors = ModelState.Values.Where(x => x.Errors.Count > 0).SelectMany(x => x.Errors.Select(y => y.ErrorMessage)).ToArray(); return(Json(new { Result = jTable_ERROR_CODE, Message = string.Join("<br/>", errors) })); } #region //驗證欄位 List <string> lstError = new List <string>(); if (row.ALAL_AssmblingLogId.isNullOrEmpty()) { lstError.Add("組立機臺主檔LogID不能為空"); } if (row.ALAL_MCID.isNullOrEmpty()) { lstError.Add("機臺編碼不能為空"); } if (!row.ALAL_SEQRow.HasValue) { lstError.Add("列位置不能為空"); } if (!row.ALAL_SEQCol.HasValue) { lstError.Add("行位置不能為空"); } if (!row.ALAL_EffectDate.HasValue) { lstError.Add("有效日期不能為空"); } if (!row.ALAL_InvalidDate.HasValue) { lstError.Add("失效日期不能為空"); } //回傳錯誤訊息 if (lstError.Count > 0) { return(Json(new { Result = jTable_ERROR_CODE, Message = string.Join("<br/>", lstError.ToArray()) })); } //檢查鍵值是否重覆 #endregion dt.ns_update(); dt.AcceptChanges(); return(Json(new { Result = msgOK })); } catch (Exception ex) { return(Json(new { Result = jTable_ERROR_CODE, Message = ex.Message })); } }