protected void SaveBtn_Click(object sender, EventArgs e) { _agentRepo = RepositoryFactory.CreateAgentRepo(); //取得頁面資料 model = WebUtils.ViewModelMapping <AgentViewModel>(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 (model.SN <= 0) { _agentRepo.CreateData(model); successRdUrl = @"AgentDataList.aspx?orderField=CreateDate&descending=True"; responseMessage = "新增成功!"; } else { model.SN = Int32.Parse(Request["sn"].ToString()); _agentRepo.EditData(model); successRdUrl = @"AgentDataList.aspx?orderField=ModifyDate&descending=True"; responseMessage = "編輯成功!"; } 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); } }