protected void BbsGridView_RowDeleting(object sender, GridViewDeleteEventArgs e) { _bbsRepo = RepositoryFactory.CreateBbsRepo(); string bbsId = BbsGridView.DataKeys[e.RowIndex].Values["bbs_id"].ToString(); var responseMessage = String.Empty; try { if (!String.IsNullOrEmpty(bbsId)) { String filepath1 = _bbsRepo.Find_Photo(bbsId); String filepath2 = _bbsRepo.Find_Url(bbsId); del_file(filepath1); del_file(filepath2); _bbsRepo.DelData(bbsId); Response.Write("<script language=javascript>alert('刪除成功!')</script>"); } } catch (Exception ex) { Response.Write("<script language=javascript>alert('刪除失敗!\r\n錯誤訊息: '" + ex.Message + ")</script>"); } finally { Response.Write("<script language=javascript>window.location.href='bbs_contentList.aspx'</script>"); } }
protected void Button_DelFILE2_Command(object sender, CommandEventArgs e) { _bbsRepo = RepositoryFactory.CreateBbsRepo(); //取得頁面資料 model = WebUtils.ViewModelMapping <BbsViewModel>(this.Page); String filepath2 = _bbsRepo.Find_Url(model.bbs_id.ToString()); del_file(filepath2); File_Up1.Visible = true; Button_DelFILE2.Visible = false; HyperLink_FILENAME2.Visible = false; }
protected void Page_Load(object sender, EventArgs e) { if (!Authentication.HasResource(User.Identity.Name, "bbs_contentList")) { Response.Redirect(@"/account/logon.aspx?ReturnUrl=%2f"); } if (!IsPostBack) { _bbsRepo = RepositoryFactory.CreateBbsRepo(); _rootRepo = RepositoryFactory.CreateRootRepo(); //從QueryString取得 公佈欄代碼 string bbsID = String.IsNullOrEmpty(Request["BbsID"]) ? String.Empty : Request["BbsID"].ToString(); PageTitle.Value = "公佈欄 > 新增"; if (!String.IsNullOrWhiteSpace(bbsID)) { model = _bbsRepo.GetBbs(bbsID); PageTitle.Value = "公佈欄 > 編輯"; if (model.PhotoName != "") { HyperLink_FILENAME1.Visible = true; HyperLink_FILENAME1.NavigateUrl = @"..\..\Upload\" + model.PhotoName; Button_DelFILE1.Visible = true; File_Photo.Visible = false; } else { HyperLink_FILENAME1.Visible = false; Button_DelFILE1.Visible = false; File_Photo.Visible = true; } if (model.UpName != "") { HyperLink_FILENAME2.Visible = true; HyperLink_FILENAME2.NavigateUrl = @"..\..\Upload\" + model.UpName; Button_DelFILE2.Visible = true; File_Up1.Visible = false; } else { HyperLink_FILENAME2.Visible = false; Button_DelFILE2.Visible = false; File_Up1.Visible = true; } WebUtils.PageDataBind(_bbsRepo.GetBbsData(bbsID), this.Page); } } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { PageTitle.Value = "公佈欄資料 > 公佈的內容"; _bbsRepo = RepositoryFactory.CreateBbsRepo(); //從QueryString取得 簽核代碼 string bbsID = String.IsNullOrEmpty(Request["bbs_id"]) ? String.Empty : Request["bbs_id"].ToString(); //根據查詢的SN 搜尋公告 model = _bbsRepo.GetBbs(bbsID); if (model.PhotoName.ToString() != "") { img_Photo.Visible = true; img_Photo.ImageUrl = @"..\..\Upload\" + model.PhotoName; } else { img_Photo.Visible = false; } if (model.txt_Http.ToString() != "http://" && model.txt_Http.ToString() != "") { hyl_Http.Visible = true; hyl_Http.Text = model.txt_Http; hyl_Http.NavigateUrl = model.txt_Http; } else { hyl_Http.Visible = false; } if (model.UpName.ToString() != "") { hyl_Url.Visible = true; hyl_Url.Text = model.UpName; hyl_Url.NavigateUrl = @"..\..\Upload\" + model.UpName; } else { hyl_Url.Visible = false; } lbl_Creator.Text = model.Creator; WebUtils.PageDataBind(model, this.Page); } }
protected void SaveBtn_Click(object sender, EventArgs e) { _bbsRepo = RepositoryFactory.CreateBbsRepo(); //取得頁面資料 model = WebUtils.ViewModelMapping <BbsViewModel>(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; //if (!Check_Null()) //{ // return; //} try { if (String.IsNullOrWhiteSpace(Request["BbsID"])) { BatchFileUpload1(File_Photo); BatchFileUpload2(File_Up1); _bbsRepo.CreateData(model); successRdUrl = @"bbs_contentList.aspx?orderField=CreateDate&descending=True"; responseMessage = "新增成功!"; } else { string filepath1 = string.Empty; if (File_Photo.Visible == false && Button_DelFILE1.Visible == true) { filepath1 = _bbsRepo.Find_Photo(model.bbs_id.ToString()); } else if (!string.IsNullOrEmpty(File_Photo.PostedFile.FileName)) { BatchFileUpload1(File_Photo); filepath1 = File_Photo.FileName; } model.PhotoName = filepath1; string filepath2 = string.Empty; if (File_Up1.Visible == false && Button_DelFILE2.Visible == true) { filepath2 = _bbsRepo.Find_Url(model.bbs_id.ToString()); } else if (!string.IsNullOrEmpty(File_Up1.PostedFile.FileName)) { BatchFileUpload2(File_Up1); filepath2 = File_Up1.FileName; } model.UpName = filepath2; _bbsRepo.EditData(model); successRdUrl = @"bbs_contentList.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); } }