/// <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");
     }
 }
        protected int GetNewsAttachNum(string newsId)
        {
            var list = new BLL.CCOM.News_attach().GetModelList(" News_id=" + newsId);

            if (list != null)
            {
                return(list.Count);
            }
            return(0);
        }
Exemplo n.º 3
0
        public static void CreateWebNewsHtml(String newsId, String fileName, bool checkExists)
        {
            if ((!checkExists) || (!System.IO.File.Exists(fileName)))
            {
                var news = new BLL.CCOM.News().GetModel(Int32.Parse(newsId));
                if (news != null)
                {
                    // 读取模板文件
                    string temp    = HttpContext.Current.Server.MapPath("news_temp.html");
                    String newsStr = FileOperate.ReadFile(temp);
                    newsStr = newsStr.Replace("titlexxx", news.News_title);
                    StringBuilder sb         = new StringBuilder();
                    int           creator_id = news.News_creator_id;
                    string        realname   = new BLL.CCOM.User_information().GetModel(creator_id).User_realname;
                    if (realname != "请填写真实姓名")
                    {
                        sb.Append("<span>发布者:").Append(realname).Append("</span>");
                    }

                    sb.Append("&nbsp;&nbsp;");
                    sb.Append(news.News_date);
                    //sb.Append("&nbsp;&nbsp;").Append("阅读次数:").Append(news.NI_ReadNum);
                    newsStr = newsStr.Replace("desxxx", sb.ToString());
                    String content = HttpContext.Current.Server.HtmlDecode(news.News_content);

                    newsStr = newsStr.Replace("contentxxx", content);
                    sb.Clear();
                    //var newsAttach = new BLL.news.News_NewsInfo().GetModel(Int64.Parse(newsId)).NewsAttach;
                    string strWhere   = " News_id=" + newsId;
                    var    newsAttach = new BLL.CCOM.News_attach().GetModelList(strWhere);
                    if (newsAttach != null && newsAttach.Count > 0)
                    {
                        sb.Append("<p class='attachTitle'>附件:</p>");
                        var itemCnt = 1;
                        foreach (var item in newsAttach)
                        {
                            sb.Append("<p class='attachItem'>(").Append(itemCnt).Append(")&nbsp;<a href='")
                            .Append("/home/news/Attach.aspx?id=").Append(DESEncrypt.Encrypt(item.News_attach_id.ToString()))
                            .Append("&address=").Append(HttpUtility.UrlEncode(item.News_attach_address))
                            .Append("&name=").Append(HttpUtility.UrlEncode(item.News_attach_name))
                            .Append("' target='_blank' >")
                            .Append(item.News_attach_name)
                            .Append("</a>")
                            .Append(OnlineViewHelper.GetOnlineViewWrapLink(item.News_attach_address, item.News_attach_name))
                            .Append("</p>");
                            itemCnt++;
                        }
                    }
                    newsStr = newsStr.Replace("attachxxx", sb.ToString());
                    ////写文件
                    FileOperate.WriteNewFile(fileName, newsStr);
                }
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="_id">资讯ID</param>
        /// <returns></returns>
        private bool DoEdit(int _id)
        {
            #region =====================================附件
            string hidFileList = Request.Params["hidFileName"];
            string strWhere    = " News_id=" + _id;
            var    news_attach = new BLL.CCOM.News_attach().GetModelList(strWhere);
            if (!string.IsNullOrEmpty(hidFileList))
            {
                string[] fileListArr = hidFileList.Split(',');
                //附件发生变化,重新上传(从无到有,数目发生变化,内容发生变化)
                if (news_attach != null && news_attach.Count > 0 && news_attach.Count != fileListArr.Length || this.attachChange.Value == "1" || news_attach.Count == 0)
                {
                    var bll = new BLL.CCOM.News_attach();
                    for (int i = 0; i < news_attach.Count; i++)
                    {
                        string str = " News_attach_id=" + news_attach[i].News_attach_id;
                        bll.Delete(str);
                    }

                    for (int i = 0; i < fileListArr.Length; i++)
                    {
                        string[] fileArr = fileListArr[i].Split('|');
                        if (fileArr.Length == 3)
                        {
                            long   attach_id  = Int64.Parse(fileArr[0]);
                            String toFilePath = DataDic.News_Attach_Path + DateTime.Now.Ticks.ToString() + i.ToString() +
                                                FileOperate.GetPostfixStr(fileArr[2]);
                            //新增文件
                            if (attach_id == 0)
                            {
                                try
                                {
                                    FileOperate.FileMove(Server.MapPath(fileArr[2]),
                                                         Server.MapPath(toFilePath));
                                    //上传附件至文件服务器
                                    UI.UpLoad.UploadFileThread(toFilePath);
                                }
                                catch
                                {
                                    toFilePath = fileArr[2];
                                }
                            }
                            else
                            {
                                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);
                        }
                    }
                }
            }
            else
            {
                //从有到无,删除数据库数据
                if (news_attach != null && news_attach.Count > 0)
                {
                    var bll = new BLL.CCOM.News_attach();
                    for (int i = 0; i < news_attach.Count; i++)
                    {
                        string str = " News_attach_id=" + news_attach[i].News_attach_id;
                        bll.Delete(str);
                    }
                }
            }
            #endregion
            //var model = new Model.CCOM.News();
            var model = new BLL.CCOM.News().GetModel(_id);
            model.News_title = this.txtTitle.Text.Trim();
            if (this.txtReleaseTime.Text.Trim() != null && this.txtReleaseTime.Text.Trim().Length > 0)
            {
                model.News_date = Convert.ToDateTime(this.txtReleaseTime.Text.Trim());
            }
            model.News_last_editor = (int)GetAdminInfo_CCOM().User_id;
            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天
                }
            }

            if (new BLL.CCOM.News().Update(model))
            {
                NewsHtml.CreateHtml(_id, false);
                return(true);
            }
            else
            {
                return(false);
            }
        }
        /// <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");
            }
        }