//单个删除 protected void lbtSingleDelete_Click(object sender, EventArgs e) { var lbtn = sender as LinkButton; BLL.CCOM.News_type bll = new BLL.CCOM.News_type(); BLL.CCOM.News news_bll = new BLL.CCOM.News(); if (lbtn != null) { bool result = false; int newsTypeId = Int32.Parse(DESEncrypt.Decrypt(lbtn.ToolTip.ToString())); if (newsTypeId > 0) { Model.CCOM.News_type model = bll.GetModel(newsTypeId); if (model.News_type_creator_id == GetAdminInfo_CCOM().User_id) { news_bll.Delete(" News_type_id=" + newsTypeId); result = bll.Delete(newsTypeId); } int page = MyRequest.GetQueryInt("page", 1); if (result) { JscriptMsg("删除成功!", Utils.CombUrlTxt("News_type_manage.aspx", "&keywords={0}&page={1}&fun_id={2}", keywords, page.ToString(), DESEncrypt.Encrypt(this.fun_id)), "Success"); } } } }
/// <summary> /// 单个删除 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void lbtSingleDelete_Click(object sender, EventArgs e) { BLL.CCOM.News bll = new BLL.CCOM.News(); BLL.CCOM.News_attach bll1 = new BLL.CCOM.News_attach(); var lbtn = sender as LinkButton; if (lbtn != null) { int news_id = Int32.Parse(DESEncrypt.Decrypt(lbtn.ToolTip.ToString())); if (news_id > 0) { Model.CCOM.News model = bll.GetModel(news_id); bool result = false; if (model != null) { if (model.News_creator_id == GetAdminInfo_CCOM().User_id) { //删除附件 var list = bll1.GetModelList(" News_id=" + news_id); if (list != null && list.Count > 0) { for (int j = 0; j < list.Count; j++) { string path = list[j].News_attach_address; if (File.Exists(Server.MapPath(path))) { FileInfo fi = new FileInfo(path); if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1) { fi.Attributes = FileAttributes.Normal; } File.Delete(Server.MapPath(path)); } bll1.Delete(list[j].News_attach_id); } } //删除静态页 String name = NewsHtml.GetWebNewsPath(news_id); if (File.Exists(Server.MapPath(name))) { FileInfo fi = new FileInfo(name); if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1) { fi.Attributes = FileAttributes.Normal; } string path_name = Server.MapPath(name); File.Delete(Server.MapPath(name)); } result = bll.Delete(model.News_id); } } string keywords = MyRequest.GetQueryString("keywords"); int page = MyRequest.GetQueryInt("page", 1); if (result == true) { JscriptMsg("删除成功!", Utils.CombUrlTxt("News_list_manager.aspx", "&keywords={0}&page={1}&fun_id={2}", keywords, page.ToString(), get_fun_id("CCOM/notification/News_list_manager.aspx")), "Success"); } else { JscriptMsg("删除失败!", Utils.CombUrlTxt("News_list_manager.aspx", "keywords={0}&page={1}&fun_id={2}", keywords, page.ToString(), get_fun_id("CCOM/notification/News_list_manager.aspx")), "Error"); } } } }
/// <summary> /// 批量删除 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnDelete_Click(object sender, EventArgs e) { BLL.CCOM.News bll = new BLL.CCOM.News(); BLL.CCOM.News_attach bll1 = new BLL.CCOM.News_attach(); int count = 0; bool result = false; for (int i = 0; i < this.rptList.Items.Count; i++) { System.Web.UI.WebControls.CheckBox cb = (System.Web.UI.WebControls.CheckBox)rptList.Items[i].FindControl("chkId"); if (!cb.Checked) { continue; } else { int newsId = Convert.ToInt32(((HiddenField)rptList.Items[i].FindControl("hidId")).Value); if (newsId > 0) { Model.CCOM.News model = bll.GetModel(newsId); if (model.News_creator_id == GetAdminInfo_CCOM().User_id) { //删除附件 var list = bll1.GetModelList(" News_id=" + newsId); if (list != null && list.Count > 0) { for (int j = 0; j < list.Count; j++) { string path = list[j].News_attach_address; if (File.Exists(Server.MapPath(path))) { FileInfo fi = new FileInfo(path); if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1) { fi.Attributes = FileAttributes.Normal; } File.Delete(Server.MapPath(path)); } bll1.Delete(list[j].News_attach_id); } } //删除静态页 String name = NewsHtml.GetWebNewsPath(newsId); if (File.Exists(Server.MapPath(name))) { FileInfo fi = new FileInfo(name); if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1) { fi.Attributes = FileAttributes.Normal; } string path_name = Server.MapPath(name); File.Delete(Server.MapPath(name)); } //删除记录 result = bll.Delete(model.News_id); } if (result) { count++; } } } } if (count < 1) { JscriptMsg("请您选择需要删除的新闻!", "", "Error"); return; } string keywords = MyRequest.GetQueryString("keywords"); int page = MyRequest.GetQueryInt("page", 1); if (result == true) { JscriptMsg("批量删除成功!", Utils.CombUrlTxt("News_list_manager.aspx", "&keywords={0}&page={1}&fun_id={2}", keywords, page.ToString(), DESEncrypt.Encrypt(this.fun_id)), "Success"); } else { JscriptMsg("批量删除失败!", Utils.CombUrlTxt("News_list_manager.aspx", "keywords={0}&page={1}&fun_id={2}", keywords, page.ToString(), DESEncrypt.Encrypt(this.fun_id)), "Error"); } }