Пример #1
0
        private void BindTags()
        {
            this.Title = "Tags列表";
            EyouSoft.BLL.NewsStructure.TagKeyInfo           TagKeyInfoBll = new EyouSoft.BLL.NewsStructure.TagKeyInfo();
            IList <EyouSoft.Model.NewsStructure.TagKeyInfo> list          = TagKeyInfoBll.GetAllTag();

            if (list != null && list.Count > 0)
            {
                int i = 1;
                foreach (var item in list)
                {
                    html += string.Format("<a class=\"tagc{0}\" href=\"{1}\">{2}</a>", i++ % 2 == 0 ? 1 : 2, EyouSoft.Common.URLREWRITE.Infomation.GetOtherListUrl(item.Id), item.ItemName);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 初始化资讯列表
        /// </summary>
        private void InitNewsList(int typeId)
        {
            lsNews = new List <EyouSoft.Model.NewsStructure.NewsModel>();

            //如果是关键字列表
            if (Request["TagId"] != null)
            {
                string tagName = string.Empty;
                EyouSoft.BLL.NewsStructure.TagKeyInfo   tagBll   = new EyouSoft.BLL.NewsStructure.TagKeyInfo();
                EyouSoft.Model.NewsStructure.TagKeyInfo tagModel = tagBll.GetModel(int.Parse(Request["TagId"].ToString()), EyouSoft.Model.NewsStructure.ItemCategory.Tag);

                if (tagModel != null)
                {
                    tagName = tagModel.ItemName;
                }

                this.Page.Title = string.Format(EyouSoft.Common.PageTitle.Information_List_Title, tagName + "-相关内容");

                //cateName = tagName == "" ? "行业资讯":tagName;
                cateName = "行业资讯";
                EyouSoft.Model.NewsStructure.SearchOrderInfo queryModel = new EyouSoft.Model.NewsStructure.SearchOrderInfo();
                queryModel.Tag = typeId;
                lsNews         = bll.GetList(pageSize, pageIndex, ref recordCount, queryModel);
            }
            else
            {
                //type<0表示是大类
                if (typeId < 0)
                {
                    queryModel          = new EyouSoft.Model.NewsStructure.SearchOrderInfo();
                    queryModel.Category = (EyouSoft.Model.NewsStructure.NewsCategory)(-typeId);
                    lsNews          = bll.GetList(pageSize, pageIndex, ref recordCount, queryModel);
                    cateName        = queryModel.Category.ToString();
                    this.Page.Title = string.Format(EyouSoft.Common.PageTitle.Information_List_Title, cateName);
                }
                else
                {
                    cateName        = newTypeBll.GetCategoryById(typeId) == null ? "" : ((EyouSoft.Model.NewsStructure.NewsCategory)newTypeBll.GetCategoryById(typeId)).ToString();
                    this.Page.Title = cateName;
                    className       = newTypeBll.GetNewsTypeName(typeId).ToString();
                    this.Page.Title = string.Format(EyouSoft.Common.PageTitle.Information_List_Title, className);

                    queryModel      = new EyouSoft.Model.NewsStructure.SearchOrderInfo();
                    queryModel.Type = typeId;
                    lsNews          = bll.GetList(pageSize, pageIndex, ref recordCount, queryModel);
                }
            }

            AddMetaTag("keywords", string.Format(EyouSoft.Common.PageTitle.Information_List_Keywords, cateName == "" ? className : cateName));
            AddMetaTag("description", string.Format(EyouSoft.Common.PageTitle.Information_List_Des, cateName == "" ? className : cateName));

            //如果有数据
            if (lsNews != null && lsNews.Count > 0)
            {
                rptNewsList.DataSource = lsNews;
                rptNewsList.DataBind();

                BindPage();
                BindUpPage();
            }
        }
Пример #3
0
        public void Databind()
        {
            //要显示关键字(1),还是Tag(2)
            string keyOrTags = EyouSoft.Common.Utils.GetQueryStringValue("keyOrTags");
            //关键字Tag标题
            string keyOrTagsTitle = EyouSoft.Common.Utils.GetQueryStringValue("keyOrTagsTitle");
            //是否要异步请求数据
            bool isAjax = Convert.ToBoolean(EyouSoft.Common.Utils.GetQueryStringValue("isAjax"));

            EyouSoft.BLL.NewsStructure.TagKeyInfo           tagKeyInfoBLL = new EyouSoft.BLL.NewsStructure.TagKeyInfo();
            IList <EyouSoft.Model.NewsStructure.TagKeyInfo> list          = new List <EyouSoft.Model.NewsStructure.TagKeyInfo>();

            System.Text.StringBuilder str = new System.Text.StringBuilder();
            //是关键字
            if (keyOrTags == "1")
            {
                if (!string.IsNullOrEmpty(keyOrTagsTitle))
                {
                    list = tagKeyInfoBLL.GetAllKeyWord(keyOrTagsTitle);
                }
                else
                {
                    list = tagKeyInfoBLL.GetAllKeyWord();
                }
            }
            //Tag
            else if (keyOrTags == "2")
            {
                if (!string.IsNullOrEmpty(keyOrTagsTitle))
                {
                    list = tagKeyInfoBLL.GetAllTag(keyOrTagsTitle);
                }
                else
                {
                    list = tagKeyInfoBLL.GetAllTag();
                }
            }
            if (list != null)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    //每行显示8列,奇数列显示颜色:white,偶数列显示颜色:#f3f7ff
                    if (i % 8 == 0)
                    {
                        str.AppendFormat("<tr bgcolor=\"{0}\">", ((i / 8)) % 2 == 0 ? "#f3f7ff" : "white");
                    }
                    str.AppendFormat("<td><input id=\"{0}\" name=\"selKey\" type=\"checkbox\" /><label for=\"{0}\">{1}</label></td>", list[i].Id, list[i].ItemName);
                    if (i + 1 % 10 == 0 && i > 0)
                    {
                        str.Append("</tr>");
                    }
                }
            }
            //是否异步请求
            if (isAjax)
            {
                Response.Clear();
                Response.Write(str);
                Response.End();
            }
            list          = null;
            tagKeyInfoBLL = null;
            Html          = str.ToString();
        }
Пример #4
0
        /// <summary>
        /// 内容添加关键字
        /// </summary>
        private void ContentAddKeys()
        {
            //计数器,一篇文章最多加5个关键字
            int i = 0;
            //每篇文章加关键字的最大数量
            int count = 5;
            //开始查找位置
            int startIndex = 0;
            //每隔40个字符加一个关键字
            int step = 40;

            //已处理过的关键字
            System.Collections.Hashtable KeyEd = new System.Collections.Hashtable();
            Hashtable replay = new Hashtable();

            EyouSoft.BLL.NewsStructure.TagKeyInfo TagKeyInfoBll = new EyouSoft.BLL.NewsStructure.TagKeyInfo();
            //得到所有的关键字
            IList <EyouSoft.Model.NewsStructure.TagKeyInfo> list = TagKeyInfoBll.GetAllKeyWord();
            //得到内容中的所有关键字
            IList <EyouSoft.Model.NewsStructure.TagKeyInfo> AllKeyListInContent = new List <EyouSoft.Model.NewsStructure.TagKeyInfo>();
            //用指定的字符串实例化StringBuilder
            StringBuilder strBuilder = null;
            //在加关键字之前先删除以前的关键字链接
            string reg      = "";
            string NewsKeys = txtNewsKeys.Value.Trim() + ' ' + txtNewsKey.Value.Trim();

            if (!string.IsNullOrEmpty(NewsKeys.Trim(' ')))
            {
                reg = NewsKeys.Trim(' ').Replace(' ', '|');
            }
            if (!string.IsNullOrEmpty(reg))
            {
                reg = reg.TrimEnd('|');
                List <string> list2 = parseHref(Content, reg);
                if (list2 != null && list != null)
                {
                    foreach (string str in list2)
                    {
                        foreach (EyouSoft.Model.NewsStructure.TagKeyInfo item in list)
                        {
                            if (str == item.ItemName)
                            {
                                AllKeyListInContent.Add(item);
                                string attrReg = string.Format("(?<==\"[^=<>]*?){0}(?=[^=<>]*?\")", item.ItemName);
                                string linkReg = string.Format("(?<=<a[\\s\\S]*?>[\\s\\S]*?){0}(?=[\\s\\S]*?</a>)", item.ItemName);
                                string randStr = GenerateRandomString(item.ItemName.Length);
                                while (replay.ContainsKey(randStr))
                                {
                                    randStr = GenerateRandomString(item.ItemName.Length);
                                }
                                if (!replay.ContainsValue(item.ItemName))
                                {
                                    Content = System.Text.RegularExpressions.Regex.Replace(Content, attrReg, randStr);
                                    Content = System.Text.RegularExpressions.Regex.Replace(Content, linkReg, randStr);
                                    replay.Add(randStr, item.ItemName);
                                }
                                break;
                            }
                        }
                    }
                }
            }

            strBuilder = new StringBuilder(Content);
            //在加关键字之前先删除以前的关键字链接
            if (list != null)
            {
                foreach (EyouSoft.Model.NewsStructure.TagKeyInfo item in list)
                {
                    string        temp     = string.Empty;
                    List <string> templist = parseHref(Content, string.Format("<a[^>]*?>{0}</a>", item.ItemName));
                    if (templist != null && templist.Count > 0)
                    {
                        temp = templist[0];
                    }
                    if (!string.IsNullOrEmpty(temp))
                    {
                        strBuilder = strBuilder.Replace(temp, item.ItemName);
                    }
                }
            }
            int length = 0;

            if (AllKeyListInContent != null)
            {
                foreach (EyouSoft.Model.NewsStructure.TagKeyInfo item in AllKeyListInContent)
                {
                    //如果替换大于等于最大次数,则跳出
                    if (i >= count || startIndex > strBuilder.Length)
                    {
                        break;
                    }
                    //开始替换的位置
                    int index = strBuilder.ToString().IndexOf(item.ItemName, startIndex);
                    if (index == -1 && startIndex >= strBuilder.Length)
                    {
                        break;
                    }
                    ;
                    if ((index - length) < step && length > 0)
                    {
                        //下次查找位置的开始
                        startIndex += item.ItemName.Length;
                        continue;
                    }
                    if (index > -1)
                    {
                        //要替换成的字符串
                        string newString = string.Format("<a InnerLinkId=\"{0}\" {3} href=\"{1}\">{2}</a>", item.Id, item.ItemUrl == "" ? "javascript:" : item.ItemUrl, item.ItemName, string.IsNullOrEmpty(item.ItemUrl) ? "" : "target=\"blank\"");
                        //替换的字符串
                        string oldString = item.ItemName;
                        //判断是否存在相应的关键字
                        if (!KeyEd.ContainsKey(item.ItemName))
                        {
                            //替换指定开始位置到指定长度内的所有字符串
                            strBuilder.Replace(oldString, newString, index, item.ItemName.Length);
                            //将已处理的关键字存入哈希表,避免重复替换
                            KeyEd.Add(item.ItemName, item.Id);
                            //计数器加1
                            i++;
                            length = index + newString.Length;
                            //下次查找位置的开始
                            startIndex = length;
                        }
                        else
                        {
                            //下次查找位置的开始
                            startIndex = index;
                        }
                    }
                }
            }
            System.Collections.IDictionaryEnumerator enumerator1 = replay.GetEnumerator();
            while (enumerator1.MoveNext())
            {
                string key   = enumerator1.Key.ToString();
                string valeu = enumerator1.Value.ToString();
                strBuilder.Replace(key, valeu);
            }
            Content = strBuilder.ToString();
        }