コード例 #1
0
        public EO_MenuFunDataTable EoMenuFun_create(int rowCount = 1)
        {
            var dt = new EO_MenuFunDataTable();

            if (rowCount < 0)
            {
                rowCount = 0;
            }

            for (int i = 0; i < rowCount; i++)
            {
                var row = dt.newTypedRow();
                row.ns_AssignNewId();
                dt.addTypedRow(row);
            }
            return(dt);
        }
コード例 #2
0
        public ActionResult Edit(FormCollection collection)
        {
            var token = collection["__RequestVerificationToken"];
            var mode  = collection["ViewMode"];
            var id    = collection[AppDataName.EOMF_MenuFunId];
            var msgOK = "OK";

            EO_MenuFunDataTable dt  = null;
            EO_MenuFunRow       row = null;

            try
            {
                if (mode.equalIgnoreCase("create"))
                {
                    dt    = EoDataService.Instance.EoMenuFun_create();
                    msgOK = FtdStatus.InsertSuccess.ToString();
                }
                else
                {
                    //找出該筆資料
                    dt = EoDataService.Instance.EoMenuFun_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)
                {
                    return(Json(new { Result = jTable_ERROR_CODE, Message = string.Join("<br/>", ModelState.Values) }));
                }

                #region //驗證欄位
                List <string> lstError = new List <string>();

                if (row.EOMF_MenuFunId.isNullOrEmpty())
                {
                    lstError.Add("程式功能清單ID不能為空");
                }
                if (row.EOMF_ItemNo.isNullOrEmpty())
                {
                    lstError.Add("程式代號不能為空");
                }
                if (row.EOMF_FunctionCode.isNullOrEmpty())
                {
                    lstError.Add("功能代號不能為空");
                }
                if (row.EOMF_FunctionName.isNullOrEmpty())
                {
                    lstError.Add("功能名稱不能為空");
                }
                if (!row.EOMF_SeqNo.HasValue)
                {
                    lstError.Add("排序不能為空");
                }
                //回傳錯誤訊息
                if (lstError.Count > 0)
                {
                    return(Json(new { Result = jTable_ERROR_CODE, Message = string.Join("<br/>", lstError.ToArray()) }));
                }
                //檢查鍵值是否重覆
                if (EoDataService.Instance.EoMenuFun_checkDuplicate(row.EOMF_MenuFunId, row.EOMF_ItemNo, row.EOMF_FunctionCode))
                {
                    return(Json(new { Result = jTable_ERROR_CODE, Message = "相同鍵值的資料已存在" }));
                }
                #endregion

                row.EOMF_FunctionCode = row.EOMF_FunctionCode.ToUpper();
                dt.ns_update();
                dt.AcceptChanges();
                return(Json(new { Result = msgOK }));
            }
            catch (Exception ex)
            {
                return(Json(new { Result = jTable_ERROR_CODE, Message = ex.Message }));
            }
        }