Beispiel #1
0
        public static List <TR01B> BeforSave(List <TR01BViewModel> data, EditType editType)
        {
            List <TR01B> list = new List <TR01B>();

            if (editType == EditType.AddNew)
            {
                foreach (var item in data)
                {
                    item.CREATE_USER = UserInfo.Id;
                    item.CREATE_DATE = DateTime.Now;
                    list.Add(ToEntity(item));
                }
            }
            else
            {
                TR01Service _Service    = new TR01Service();
                var         DBTR01BList = _Service.GetB(data.Select(x => x.TR01B_ID).ToList());
                foreach (var item in DBTR01BList)
                {
                    var tempData = data.First(x => x.TR01B_ID == item.TR01B_ID);
                    tempData.TR01A_ID    = item.TR01A_ID;
                    tempData.CREATE_USER = item.CREATE_USER;
                    tempData.CREATE_DATE = item.CREATE_DATE;
                    tempData.UPDATE_USER = UserInfo.Id;
                    tempData.UPDATE_DATE = DateTime.Now;
                    list.Add(ToEntity(tempData));
                }
            }
            return(list);
        }
Beispiel #2
0
 //==========================BeforSave==========================
 public static TR01A BeforSave(TR01AViewModel data)
 {
     if (data.TR01A_ID == 0)//Adding New
     {
         data.CFN_YN      = "N";
         data.CREATE_USER = UserInfo.Id;
         data.CREATE_DATE = DateTime.Now;
     }
     else//Update
     {
         TR01Service _Service = new TR01Service();
         var         TR01A    = _Service.GetA(data.TR01A_ID);
         data.CREATE_USER = TR01A.CREATE_USER;
         data.CREATE_DATE = TR01A.CREATE_DATE;
         data.CFN_DT      = TR01A.CFN_DT;
         data.UPDATE_USER = UserInfo.Id;
         data.UPDATE_DATE = DateTime.Now;
     }
     return(ToEntity(data));
 }
Beispiel #3
0
        public static List <string> Validation(TR01AViewModel model, MVCxGridViewBatchUpdateValues <TR01BViewModel, int> updateValues, ModelStateDictionary modelState)
        {
            List <string> errMsg = new List <string>();

            //不是新增的時候要去驗證是否有被異動過
            if (model.TR01A_ID > 0)
            {
                TR01Service _Service = new TR01Service();
                var         count    = _Service.GetA(x => x.TR01A_ID == model.TR01A_ID).Count();
                if (count == 0)
                {
                    errMsg.Add("已被其他使用者刪除");
                }

                if (updateValues != null && updateValues.Update.Count > 0)
                {
                    var TR01B_IDList         = updateValues.Update.Select(x => x.TR01B_ID).ToList();
                    EntityConnection _Entity = new EntityConnection();
                    var DBCount = _Entity.TR01B.Where(x => TR01B_IDList.Contains(x.TR01B_ID)).Count();
                    if (DBCount != TR01B_IDList.Count())
                    {
                        errMsg.Add("部份明細已被其他使用者刪除" + "<br />" + "請重新整理");
                    }
                }
            }

            //驗證Master
            var masterErrDic = new Dictionary <string, string>();

            ValidateMaster(masterErrDic, model);
            if (masterErrDic.Count > 0)
            {
                errMsg.Add("Master contains error");
                foreach (var err in masterErrDic)
                {
                    modelState.AddModelError($"{err.Key}", err.Value);//display error in cell
                }
            }

            //驗證Detail
            if (updateValues != null)
            {
                var detailErrDic = new Dictionary <string, string>();
                for (int i = 0; i < updateValues.Insert.Count; i++)
                {
                    ValidateDetail(i, detailErrDic, updateValues.Insert[i], EditType.AddNew);
                }

                for (int i = 0; i < updateValues.Update.Count; i++)
                {
                    ValidateDetail(i, detailErrDic, updateValues.Update[i], EditType.Update);
                }

                if (detailErrDic.Count > 0)
                {
                    errMsg.Add("Detail contains error");
                    foreach (var item in detailErrDic)
                    {
                        modelState.AddModelError(item.Key, item.Value);
                    }
                }
            }

            if (!modelState.IsValid)
            {
                errMsg.Add("請檢查紅色驚嘆號");
            }

            return(errMsg);
        }