/// <summary> /// 初始化修改页面 /// </summary> /// <param name="newsId">新闻id</param> private void ShowInfo(int newsId) { BLL.CCOM.News bll = new BLL.CCOM.News(); Model.CCOM.News model = bll.GetModel(newsId); if (model != null) { this.txtTitle.Text = model.News_title; //this.hidNewsType.Value = model.News_type_id.ToString(); this.txtReleaseTime.Text = model.News_date.ToString(); this.hidEditorCnt.Value = model.News_content; if (model.News_top != null) { this.optTop.Checked = (bool)model.News_top; this.txtTopTime.Text = model.News_top_time.ToString(); //this.trTop.Style.Add("display", ""); } List <Model.CCOM.News_attach> attach_model = new BLL.CCOM.News_attach().GetModelList(" News_id=" + newsId); if (attach_model != null && attach_model.Count > 0) { rptAttach.DataSource = attach_model; rptAttach.DataBind(); } } else { JscriptMsg("资讯不存在或已被删除!", "back", "Error"); } }
private int DoAdd() { var model = new Model.CCOM.News(); model.News_title = this.txtTitle.Text.Trim(); model.News_URL = "/AdminMetro/index.aspx"; model.News_creator_id = (int)GetAdminInfo_CCOM().User_id; if (this.txtReleaseTime.Text.Trim() != null && this.txtReleaseTime.Text.Trim().Length > 0) { model.News_date = Convert.ToDateTime(this.txtReleaseTime.Text.Trim()); } else { model.News_date = DateTime.Now; } model.News_readnumber = 1; model.News_type_id = int.Parse(DESEncrypt.Decrypt(this.hidNewsType.Value)); model.News_content = this.hidEditorCnt.Value.Replace("'", ""); model.News_top = false; if (this.optTop.Checked) { model.News_top = true; string time = this.txtTopTime.Text.Trim(); if (time != null && time.Length > 0) { int last_time = int.Parse(time); model.News_top_time = last_time; } else { model.News_top_time = 3;//默认置顶3天 } } Int32 newsId = 0; newsId = new BLL.CCOM.News().Add(model); if (newsId > 0) { #region ====================附件 //保存附件 string hidFileList = Request.Params["hidFileName"]; if (!string.IsNullOrEmpty(hidFileList)) { string[] fileListArr = hidFileList.Split(','); //var list = new List<Model.CCOM.News_attach>(); for (int i = 0; i < fileListArr.Length; i++) { string[] fileArr = fileListArr[i].Split('|'); if (fileArr.Length == 3) { int attach_id = Int32.Parse(fileArr[0]); String toFilePath = DataDic.News_Attach_Path + DateTime.Now.Ticks.ToString() + i.ToString() + FileOperate.GetPostfixStr(fileArr[2]); try { FileOperate.FileMove(Server.MapPath(fileArr[2]), Server.MapPath(toFilePath)); //上传附件至文件服务器 UI.UpLoad.UploadFileThread(toFilePath); } catch (Exception ex) { toFilePath = fileArr[2]; } Model.CCOM.News_attach model_attach = new Model.CCOM.News_attach(); model_attach.News_id = newsId; model_attach.News_attach_name = fileArr[1]; model_attach.News_attach_address = toFilePath; new BLL.CCOM.News_attach().Add(model_attach); } } } #endregion //修改URL Model.CCOM.News model1 = new BLL.CCOM.News().GetModel(newsId); model1.News_URL = "/AdminMetro/CCOM/notification/ViewNews.aspx?id=" + DESEncrypt.Encrypt(newsId.ToString()); new BLL.CCOM.News().Update(model1); //生成静态页 NewsHtml.CreateHtml(newsId, false); } return(newsId); }
/// <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"); } }