Beispiel #1
0
        public static ResultHelperBatch <BA02B, int> BeforeSave(MVCxGridViewBatchUpdateValues <BA02BModel, int> values, List <BA02B> updateList, int DeleteCount, ModelStateDictionary ModelState)
        {
            ResultHelperBatch <BA02B, int> result = new ResultHelperBatch <BA02B, int>()
            {
                Message = ""
            };

            ValidateDetail(values.Update, ModelState, EntityState.Modified);
            ValidateDetail(values.Insert, ModelState, EntityState.Added);
            if (updateList.Count != values.Update.Count || DeleteCount != values.DeleteKeys.Count)
            {
                result.Message += "明細資料已被刪除<br/>請重新整理<br/>";
            }

            if (!ModelState.IsValid)
            {
                result.Message += "請檢查紅色驚嘆號<br/>";
            }
            else if (result.Message == "")
            {
                result.Insert = ToEntity(values.Insert, new List <BA02B>(), EntityState.Added);
                result.Update = ToEntity(values.Update, updateList, EntityState.Modified);
                result.Delete = values.DeleteKeys;
            }

            return(result);
        }
Beispiel #2
0
        public static ResultHelperBatch <TR01A, int> BeforeSave(TR01AModel master, MVCxGridViewBatchUpdateValues <TR01BModel, int> values, List <TR01A> updateList, int deleteCount, ModelStateDictionary ModelState)
        {
            ResultHelperBatch <TR01A, int> result = new ResultHelperBatch <TR01A, int>()
            {
                Message = ""
            };
            var updateKeys     = values.Update.Select(x => x.TR01A_ID).ToList();
            var trueUpdateList = updateList.Where(x => updateKeys.Contains(x.TR01A_ID)).ToList();
            var fakeUpdateList = updateList.Where(x => !updateKeys.Contains(x.TR01A_ID)).ToList();

            Validation(master, ModelState);
            ValidateDetail(values.Update, ModelState, EntityState.Modified);
            ValidateDetail(values.Insert, ModelState, EntityState.Added);
            if (trueUpdateList.Count != values.Update.Count || deleteCount != values.DeleteKeys.Count)
            {
                result.Message += "明細資料已被刪除<br/>請重新整理<br/>";
            }
            result.Message += ValidateBalance(values.Update, values.Insert, fakeUpdateList);

            if (!ModelState.IsValid)
            {
                result.Message += "請檢查紅色驚嘆號<br/>";
            }
            else if (result.Message == "")
            {
                if (master.EntityState == EntityState.Added)
                {
                    master.VOU_NO = new ALMSEntities().Database.SqlQuery <string>("select dbo.Get_VOU_NO(" + master.DtTRN_DT.ToString("yyyyMMdd") + ")").FirstOrDefault();
                }
                result.Insert = ToEntity(master, values.Insert, new List <TR01A>(), EntityState.Added);
                result.Update = ToEntity(master, values.Update, trueUpdateList, EntityState.Modified);
                if (fakeUpdateList.Count > 0)
                {
                    result.Update.AddRange(ToEntity(master, fakeUpdateList));//把detail沒有編輯的 也補上master
                }
                result.Delete = values.DeleteKeys;
            }

            return(result);
        }