/// <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");
     }
 }
Example #2
0
        /// <summary>
        /// 获取所有新闻
        /// </summary>
        /// <param name="context"></param>
        private void GetAllNewList(HttpContext context, int typeId, string strWhere, int page)
        {
            //初始化置顶数据
            if (page == 1)
            {
                var bll  = new BLL.CCOM.News();
                var list = bll.GetModelList("News_top=1");
                for (int i = 0; i < list.Count; i++)
                {
                    if (list[i].News_date != null)
                    {
                        DateTime date = Convert.ToDateTime(list[i].News_date);
                        if (list[i].News_top_time != null)
                        {
                            if (date.AddDays((double)list[i].News_top_time) < DateTime.Now)
                            {
                                var model = bll.GetModel(list[i].News_id);
                                model.News_top      = false;
                                model.News_top_time = 0;
                                bll.Update(model);
                            }
                        }
                        else
                        {
                            //若为空,默认为3天
                            if (date.AddDays(3.0) < DateTime.Now)
                            {
                                var model = bll.GetModel(list[i].News_id);
                                model.News_top      = false;
                                model.News_top_time = 0;
                                bll.Update(model);
                            }
                        }
                    }
                }
            }
            int       start_index = pageSize * (page - 1) + 1;
            int       end_index   = pageSize * page;
            DataTable dt          = new BLL.CCOM.News().GetListByPage(strWhere, "News_top DESC ,News_date DESC ", start_index, end_index).Tables[0];
            string    json        = ToJson(dt);

            context.Response.Write(json);
        }
        /// <summary>
        /// 置顶
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lbtTop_Click(object sender, EventArgs e)
        {
            var bll  = new BLL.CCOM.News();
            var lbtn = sender as LinkButton;

            if (lbtn != null)
            {
                int  news_id = Int32.Parse(DESEncrypt.Decrypt(lbtn.ToolTip.ToString()));
                bool isTop   = false;
                bool result  = true;
                try
                {
                    var model = bll.GetModel(news_id);
                    if (model.News_top != null && !(bool)model.News_top)
                    {
                        isTop          = false;
                        model.News_top = true;
                        DateTime date      = Convert.ToDateTime(model.News_date);
                        TimeSpan time_span = DateTime.Now - date;
                        int      day       = time_span.Days;
                        model.News_top_time = day + 3;
                        bll.Update(model);
                    }
                    else
                    {
                        isTop               = true;
                        model.News_top      = false;
                        model.News_top_time = 0;
                        bll.Update(model);
                    }
                    result = true;
                }
                catch
                {
                    result = false;
                }
                //string keywords = MyRequest.GetQueryString("keywords");
                int page = MyRequest.GetQueryInt("page", 1);
                if (result == true)
                {
                    JscriptMsg(isTop ? "取消置顶成功!" : "置顶成功!", Utils.CombUrlTxt("News_list_manager.aspx", "keywords={0}&page={1}&fun_id={2}",
                                                                             keywords, page.ToString(), DESEncrypt.Encrypt(this.fun_id)), "Success");
                }
                else
                {
                    JscriptMsg(isTop ? "取消置顶失败!" : "置顶失败!", Utils.CombUrlTxt("News_list_manager.aspx", "keywords={0}&page={1}&fun_id={2}",
                                                                             keywords, page.ToString(), DESEncrypt.Encrypt(this.fun_id)), "Error");
                }
            }
        }
        /// <summary>
        /// 初始化资讯
        /// </summary>
        /// <param name="typeId"></param>
        protected void InitialPage(int page)
        {
            //更新置顶数据
            var bll  = new BLL.CCOM.News();
            var list = bll.GetModelList("News_top=1");

            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].News_date != null)
                {
                    DateTime date = Convert.ToDateTime(list[i].News_date);
                    if (list[i].News_top_time != null)
                    {
                        if (date.AddDays((double)list[i].News_top_time) < DateTime.Now)
                        {
                            var model = bll.GetModel(list[i].News_id);
                            model.News_top      = false;
                            model.News_top_time = 0;
                            bll.Update(model);
                        }
                    }
                    else
                    {
                        //若为空,默认为3天
                        if (date.AddDays(3.0) < DateTime.Now)
                        {
                            var model = bll.GetModel(list[i].News_id);
                            model.News_top      = false;
                            model.News_top_time = 0;
                            bll.Update(model);
                        }
                    }
                }
            }
            int start_index = 1;
            int end_index   = 10;

            DataTable dt = bll.GetListByPage("", "News_top DESC ,News_date DESC ", start_index, end_index).Tables[0];

            if (dt != null && dt.Rows.Count > 0)
            {
                string li = string.Empty;
                foreach (DataRow dr in dt.Rows)
                {
                    bool top = false;
                    try
                    {
                        top = Convert.ToBoolean(dr["News_top"]);
                    }
                    catch
                    {
                        top = false;
                    }
                    finally
                    {
                        DateTime date = Convert.ToDateTime(dr["News_date"]);
                        string   time = date.ToString("yyyy/MM/dd");
                        if (top)
                        {
                            li += "<li class=\"notice-li\">" + "<a href=\"" +
                                  dr["News_URL"] + "\"  target=\"_blank\">" + "<img src=\"/images/news/news_logo2.png\"  class=\"img_logo\"/>" + "<span style=\"color:red;\">[置顶] </span>" +
                                  dr["News_title"] + "</a>" + "<span class=\"date\">" +
                                  time + "</span>" + "</li>";
                        }
                        else
                        {
                            li += "<li class=\"notice-li\">" + "<a href=\"" +
                                  dr["News_URL"] + "\"  target=\"_blank\">" + "<img src=\"/images/news/news_logo2.png\" class=\"img_logo\"/>" +
                                  dr["News_title"] + "</a>" + "<span class=\"date\">" +
                                  time + "</span>" + "</li>";
                        }
                    }
                }
                this.news_list.InnerHtml = li;
            }
            int newsNum = bll.GetRecordCount("");
            int pageNum = 0;

            if (newsNum % 10 == 0)
            {
                pageNum = newsNum / 10;
            }
            else
            {
                pageNum = newsNum / 10 + 1;
            }
            this.page_num.Value = pageNum + "";
        }
        /// <summary>
        /// 绑定资讯内容
        /// </summary>
        private void bindNewsData()
        {
            //更新置顶数据
            var bll  = new BLL.CCOM.News();
            var list = bll.GetModelList("News_top=1");

            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].News_date != null)
                {
                    DateTime date = Convert.ToDateTime(list[i].News_date);
                    if (list[i].News_top_time != null)
                    {
                        if (date.AddDays((double)list[i].News_top_time) < DateTime.Now)
                        {
                            var model = bll.GetModel(list[i].News_id);
                            model.News_top      = false;
                            model.News_top_time = 0;
                            bll.Update(model);
                        }
                    }
                    else
                    {
                        //若为空,默认为3天
                        if (date.AddDays(3.0) < DateTime.Now)
                        {
                            var model = bll.GetModel(list[i].News_id);
                            model.News_top      = false;
                            model.News_top_time = 0;
                            bll.Update(model);
                        }
                    }
                }
            }


            string strWhere = string.Empty;
            int    pageSize = GetPageSize(15); //每页数量
            int    page     = MyRequest.GetQueryInt("page", 1);

            keywords = MyRequest.GetQueryString("keywords");
            string news_type_id = MyRequest.GetQueryString("news_type_id");

            if (news_type_id != null && news_type_id.Length > 0)
            {
                string news_type = DESEncrypt.Decrypt(news_type_id);
                if (news_type != "0")
                {
                    strWhere += " News_type_id=" + news_type;
                }
            }
            if (keywords != null && keywords.Length > 0)
            {
                if (strWhere != "")
                {
                    strWhere = strWhere + " and News_title like '%" + keywords + "%' ";
                }
                else
                {
                    strWhere = " News_title like '%" + keywords + "%' ";
                }
            }
            int start_index = pageSize * (page - 1) + 1;
            int end_index   = pageSize * page;


            //计算数量
            int totalCount = bll.GetRecordCount("");

            //绑定当页

            this.rptList.DataSource = bll.GetListByPage(strWhere, " News_date DESC ", start_index, end_index);
            this.rptList.DataBind();

            //for (int i = 0; i < rptList.Items.Count; i++)
            //{
            //    LinkButton lbt = (LinkButton)rptList.Items[i].FindControl("lbtDelete");
            //    HiddenField hide = (HiddenField)rptList.Items[i].FindControl("hideCreatorId");
            //    int CreatorId = int.Parse(hide.Value);
            //    if(CreatorId==GetAdminInfo_CCOM().User_id)
            //    {

            //    }
            //}
            //绑定页码
            this.txtPageNum.Text = pageSize.ToString();
            string pageUrl = Utils.CombUrlTxt("News_list_manager.aspx", "keywords={0}&page={1}&fun_id={2}", keywords, "__id__", DESEncrypt.Encrypt(this.fun_id));

            this.PageContent.InnerHtml = Utils.OutPageList(pageSize, page, totalCount, pageUrl, 8, true);
        }
        /// <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");
            }
        }