public ActionResult TR01CUpdate(int TR01B_ID, TR01CModel master) { //Validation List <string> errList = TR01Business.Validation(master, ModelState); //BeforeSave + Save if (errList.Count == 0) { //BeforeSave var TR01A = TR01Business.BeforSave(master); TR01A.TR01B_ID = TR01B_ID; System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); TR01A.ARR_DT = (master.DtARR_DT != null ? master.DtARR_DT.Value.ToString("yyyyMMdd") : ""); //Save if (errList.Count == 0) { var result = _Service.Update(TR01A); master = TR01Business.FromEntity(result.Data); if (!string.IsNullOrWhiteSpace(result.Message)) { errList.Add(result.Message); } } } if (errList.Count > 0) { ViewData["ErrMsg"] = string.Join("<br />", errList); master.ModelState = ModelState; ViewData["ErrorData"] = master; } else { CheckStatus(TR01B_ID); ViewData["IsEdit"] = true; ViewData["Success"] = true; } return(PartialView("_GridTR01C", TR01Business.FromEntity(_Service.GetC(x => x.TR01B_ID == TR01B_ID).ToList()))); }
/// <summary>Both master and detail has change</summary> /// <param name="batchData">contain updata、insert、delete list</param> /// <param name="master"></param> /// <returns></returns> public ActionResult DetailGridBatchUpdate(MVCxGridViewBatchUpdateValues <TR01BViewModel, int> updateValues, TR01AViewModel master, string DateBeg, string DateEnd, string Tax) { //Validation string errMsg = ""; if (UserInfo.LanguageType == Language.Type.VN) { master.DtPUR_DT = DateTime.Parse(DateBeg); master.DtEXP_DT = DateTime.Parse(DateEnd); ModelState.Clear(); TryValidateModel(master); } var isValid = TR01Business.Validation(master, updateValues, ModelState); ModelState.Remove("DtPUR_DT"); ModelState.Remove("DtEXP_DT"); if (!TR01Business.ValidateRemove(master, updateValues.Update)) { isValid = false; errMsg = "資料已被其他人異動過"; } if (master.CFN_YN == "Y") { errMsg += "資料已確認 不可修改"; } else if (master.CFN_YN == "P") { errMsg += "資料申請中 不可修改"; } else { //Save if (isValid) { var TR01A = TR01Business.BeforSave(master); if (UserInfo.LanguageType == Language.Type.VN) { TR01A.PUR_DT = DateBeg.Replace("/", ""); //master.DtPUR_DT.Value.ToString("yyyyddMM"); TR01A.EXP_DT = DateEnd.Replace("/", ""); //master.DtEXP_DT.Value.ToString("yyyyddMM"); System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(Language.US); TR01A.TAX_RT = double.Parse(Tax); //越文沒有小數點特殊處理 } else { TR01A.PUR_DT = master.DtPUR_DT.Value.ToString("yyyyMMdd"); TR01A.EXP_DT = master.DtEXP_DT.Value.ToString("yyyyMMdd"); } var addList = TR01Business.BeforSave(updateValues.Insert, EditType.AddNew); var updateList = TR01Business.BeforSave(updateValues.Update, EditType.Update); var result = _Service.Update(TR01A, addList, updateList, updateValues.DeleteKeys); errMsg = result.Message; master = TR01Business.FromEntity(result.Data); } } //Error handling if (errMsg.Length > 0 || !isValid) { for (int i = 0; i < updateValues.Insert.Count; i++) { ModelState.AddModelError($"Insert[{i}].IsValid", "Error"); } for (int i = 0; i < updateValues.Update.Count; i++) { ModelState.AddModelError($"Update[{i}].IsValid", "Error"); } string deleteIDStrList = ""; for (int i = 0; i < updateValues.DeleteKeys.Count; i++) { updateValues.SetErrorText(updateValues.DeleteKeys[i], "Unable to delete!"); deleteIDStrList += updateValues.DeleteKeys[i] + ","; } ViewData["DeleteIDList"] = deleteIDStrList; ViewData["ErrMsg"] = Resources.Resource.FailureStr + "<br />" + errMsg; } ViewData["Key"] = master.TR01A_ID; var BA01BList = new Services.BA01.BA01Service().GetAllD(master.BA01A_ID).ToList(); ViewBag.Data = BA01BList; //var BA01B = BA01BList.FirstOrDefault(x => x.BA01B_ID == master.BA01B_ID); //if (BA01B != null) //{ // master.TEL_NO = BA01B.TEL_NO; // master.TEL_EX = BA01B.TEL_EX; //} ViewData["CFN_YN"] = master.CFN_YN; if (master.CFN_YN == "Y") { ViewData["IsConfirm"] = true; } else { ViewData["IsConfirm"] = false; } ViewData["MasterForm"] = ReadViewHelper.PartialView(this, "_MasterForm", master); return(PartialView("_DetailGrid", GetTR01BList(master.TR01A_ID))); }