Exemplo n.º 1
0
        public EO_EmployeeDataTable EoEmployee_create(int rowCount = 1)
        {
            var dt = new EO_EmployeeDataTable();

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

            for (int i = 0; i < rowCount; i++)
            {
                var row = dt.newTypedRow();
                row.ns_AssignNewId();
                dt.addTypedRow(row);
            }
            return(dt);
        }
Exemplo n.º 2
0
        public ActionResult Edit(FormCollection collection)
        {
            var token = collection["__RequestVerificationToken"];
            var mode  = collection["ViewMode"];
            var id    = collection[AppDataName.EOE_EmployeeId];
            var msgOK = "OK";

            EO_EmployeeDataTable dt  = null;
            EO_EmployeeRow       row = null;

            try
            {
                if (mode.equalIgnoreCase("create"))
                {
                    dt  = new EO_EmployeeDataTable();
                    row = dt.newTypedRow();
                    row.ns_AssignNewId();
                    dt.addTypedRow(row);
                    msgOK = FtdStatus.InsertSuccess.ToString();
                }
                else
                {
                    //找出該筆資料
                    dt = EoDataService.Instance.EoEmployee_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.EOE_EmployeeId.isNullOrEmpty())
                {
                    lstError.Add("人員ID不能為空");
                }
                //if (row.EOE_EmployeeCode.isNullOrEmpty())
                //{
                //    lstError.Add("人員編號不能為空");
                //}
                if (row.EOE_LoginAccount_XX.isNullOrEmpty())
                {
                    lstError.Add("帳號不能為空");
                }
                if (row.EOE_EmployeeName.isNullOrEmpty())
                {
                    lstError.Add("人員姓名不能為空");
                }
                //if (row.EOE_DepartmentId.isNullOrEmpty())
                //{
                //    lstError.Add("部門ID不能為空");
                //}
                //if (row.EOE_EmployeeTitleId.isNullOrEmpty())
                //{
                //    lstError.Add("職稱ID不能為空");
                //}
                //回傳錯誤訊息
                if (lstError.Count > 0)
                {
                    return(Json(new { Result = jTable_ERROR_CODE, Message = string.Join("<br/>", lstError.ToArray()) }));
                }
                //檢查鍵值是否重覆
                if (EoDataService.Instance.EoEmployee_checkDuplicate(row.EOE_EmployeeId, row.EOE_DepartmentId, row.EOE_EmployeeCode))
                {
                    return(Json(new { Result = jTable_ERROR_CODE, Message = "相同鍵值的資料已存在" }));
                }
                #endregion

                //人員編號=登入帳號
                row.EOE_EmployeeCode = row.EOE_LoginAccount_XX;

                //異動 LoginAccount
                var dtLoginAccount = NsDmHelper.EO_LoginAccount
                                     .selectAll(t => t.AllExt)
                                     .where (t => t.EOLA_LoginAccount == row.EOE_EmployeeCode.toConstReq1())
                                     .query();

                var rowLoginAccount = dtLoginAccount.FirstRow;
                if (rowLoginAccount == null)
                {
                    rowLoginAccount = dtLoginAccount.newTypedRow();
                    rowLoginAccount.EOLA_LoginAccountId = row.EOE_EmployeeId;
                    rowLoginAccount.EOLA_LoginAccount   = row.EOE_EmployeeCode;
                    //預設密碼=帳號
                    rowLoginAccount.EOLA_LoginPassword = row.EOE_EmployeeCode;
                    dtLoginAccount.addTypedRow(rowLoginAccount);
                }
                else
                {
                    if (rowLoginAccount.EOLA_LoginAccountId != row.EOE_EmployeeId)
                    {
                        return(Json(new { Result = jTable_ERROR_CODE, Message = "帳號已存在" }));
                    }
                }
                rowLoginAccount.EOLA_IsEnable = row.EOE_Enabled;
                if (!row.EOE_LoginPassword_XX.isNullOrEmpty())
                {
                    rowLoginAccount.EOLA_LoginPassword = row.EOE_LoginPassword_XX;
                }

                var scope = new FdbTransScope(FdbTransScopeOption.RequiresNew);
                using (scope.Use)
                {
                    dt.ns_update();
                    dtLoginAccount.ns_update();
                    dt.AcceptChanges();
                    scope.complete();
                }
                return(Json(new { Result = msgOK }));
            }
            catch (Exception ex)
            {
                return(Json(new { Result = jTable_ERROR_CODE, Message = ex.Message }));
            }
        }