コード例 #1
0
        private void ShowNews(int newsId)
        {
            String name = NewsHtml.GetWebNewsPath(newsId);

            NewsHtml.CreateWebNewsHtml(newsId + "", Server.MapPath(name));
            if (!System.IO.File.Exists(Server.MapPath(name)))
            {
                Response.Redirect("/home/news/template/news_404.html");
            }
            else
            {
                NewsHtml.UpdateNewsReadNum(newsId);
                Response.Redirect(name);
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        /// <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);
            }
        }
コード例 #4
0
        /// <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");
                    }
                }
            }
        }
コード例 #5
0
        /// <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");
            }
        }