protected void SaveBtn_Click(object sender, EventArgs e) { _departmentRepo = RepositoryFactory.CreateDepartmentRepo(); //取得頁面資料 model = WebUtils.ViewModelMapping <DepartmentViewModel>(this.Page); var validator = new Validator(); var validResult = validator.ValidateModel(model); if (!validResult.IsValid) { Response.Write(validResult.ErrorMessage.ToString().ToAlertFormat()); return; } //btn處理 ViewUtils.ButtonOff(SaveBtn, CoverBtn); //存檔 var responseMessage = ""; var successRdUrl = String.Empty; try { if (String.IsNullOrWhiteSpace(Request["DepartmentID"])) { _departmentRepo.CreateData(model); successRdUrl = @"DepartmentDataList.aspx?orderField=CreateDate&descending=True"; responseMessage = "新增成功!"; } else { _departmentRepo.EditData(model); successRdUrl = @"DepartmentDataList.aspx?orderField=ModifyDate&descending=True"; responseMessage = "編輯成功!"; } //btn處理 ViewUtils.ButtonOn(SaveBtn, CoverBtn); responseMessage = responseMessage.ToAlertAndRedirect(successRdUrl); } catch (Exception ex) { responseMessage = String.Concat("存檔失敗!\r\n錯誤訊息: ", ex.Message).ToAlertFormat(); ViewUtils.ShowRefreshBtn(CoverBtn, RefreshBtn); } finally { Response.Write(responseMessage); } }