示例#1
0
        /// <summary>
        /// Builds the link from an object
        /// </summary>
        /// <param name="_newsDetailsRow"></param>
        public void BuildLink(Object articleObject)
        {
            if (articleObject == null)
            {
                return;
            }

            SqlDataReader  thisArticle     = articleObject as SqlDataReader;
            NewsDetailView _articleDetails = null;

            if (thisArticle == null)
            {
                object obj = DataBinder.Eval(articleObject, "NewsId");
                if (obj != null)
                {
                    ArticleId = (int)obj;
                }

                if (ArticleId == null)
                {
                    return;
                }

                _articleDetails = articleObject as NewsDetailView;

                if (_articleDetails == null)
                {
                    _articleDetails = new NewsDetailView
                    {
                        NewsId         = ArticleId.Value,
                        Title          = DataBinder.Eval(articleObject, "Title").ToString(),
                        NewsFile       = DataBinder.Eval(articleObject, "NewsFile").ToString(),
                        TypeName       = DataBinder.Eval(articleObject, "TypeName").ToString(),
                        TypeUniqueName = DataBinder.Eval(articleObject, "TypeUniqueName").ToString(),
                        UniqueName     = DataBinder.Eval(articleObject, "UniqueName").ToString()
                    };
                    DateTime?newsDate = DataBinder.Eval(articleObject, "NewsDate") as DateTime?;
                    if (newsDate != null)
                    {
                        _articleDetails.NewsDate = newsDate.Value;
                    }
                }
            }
            else
            {
                ArticleId = (int)thisArticle["NewsId"];

                _articleDetails = new NewsDetailView
                {
                    NewsId         = ArticleId.Value,
                    Title          = thisArticle["Title"].ToString(),
                    NewsFile       = thisArticle["NewsFile"].ToString(),
                    NewsDate       = (DateTime)thisArticle["NewsDate"],
                    TypeName       = thisArticle["TypeName"].ToString(),
                    TypeUniqueName = thisArticle["TypeUniqueName"].ToString(),
                    UniqueName     = thisArticle["UniqueName"].ToString()
                };
            }
            BuildLink(_articleDetails);
        }
示例#2
0
        /// <summary>
        /// Builds the link and content for a news link.
        /// </summary>
        /// <param name="_newsDetails"></param>
        public void BuildLink(NewsDetailView _newsDetails)
        {
            string text = _newsDetails.Title;

            if (_newsDetails.Status == 0)
            {
                this.Attributes["class"] = this.Attributes["class"] + " disabled";
            }

            switch (Type)
            {
            case NewsLinkType.Auto:
                if (!String.IsNullOrEmpty(_newsDetails.NewsFile))
                {
                    goto case NewsLinkType.DirectFileLink;
                }
                goto default;

            case NewsLinkType.DirectFileLink:
                if (string.IsNullOrEmpty(_newsDetails.NewsFile))
                {
                    goto default;
                }
                this.HRef = string.Format("{2}/{0}/{1}",
                                          Folders.NewsFile,
                                          _newsDetails.NewsFile,
                                          WebContext.Root
                                          );
                this.Target = "_blank";
                break;

            case NewsLinkType.DownloadFile:
                if (string.IsNullOrEmpty(_newsDetails.NewsFile))
                {
                    goto default;
                }
                this.HRef = string.Format("{1}/download-file.axd?file={0}&type=News",
                                          _newsDetails.NewsFile,
                                          WebContext.Root
                                          );
                break;

            case NewsLinkType.ArchiveByDate:
                text      = string.Format("{0:MMMM}, {0:yyyy}", _newsDetails.NewsDate);
                this.HRef = string.Format("{3}/{0}/{1:yyyy}/{1:MM}{2}",
                                          Path == null ? "archives" : Path,
                                          _newsDetails.NewsDate,
                                          LinkExtension,
                                          WebContext.Root
                                          );
                break;

            case NewsLinkType.ArchiveByType:
                text      = _newsDetails.TypeName;
                this.HRef = string.Format("{3}/{0}{1}{2}",
                                          Path == null ? "article-categories" : Path,
                                          _newsDetails.TypeUniqueName,
                                          LinkExtension,
                                          WebContext.Root
                                          );
                break;

            case NewsLinkType.ArticleID:
                if (IncludeNewsTypePath)
                {
                    this.HRef = string.Format("{4}/{0}{1}/{2}{3}",
                                              Path == null ? "" : Path + "/",
                                              _newsDetails.TypeUniqueName,
                                              _newsDetails.NewsId,
                                              LinkExtension,
                                              WebContext.Root
                                              );
                }
                else
                {
                    this.HRef = string.Format("{3}/{0}{1}{2}",
                                              Path == null ? "" : Path + "/",
                                              _newsDetails.NewsId,
                                              LinkExtension,
                                              WebContext.Root
                                              );
                }
                break;

            case NewsLinkType.Article:
            default:
                if (_newsDetails.UniqueName.IndexOf("http://") == 0)
                {
                    this.HRef   = _newsDetails.UniqueName;
                    this.Target = "_blank";
                }
                else
                {
                    if (IncludeNewsTypePath)
                    {
                        this.HRef = string.Format("{4}/{0}{1}/{2}{3}",
                                                  Path == null ? "" : Path + "/",
                                                  _newsDetails.TypeUniqueName,
                                                  _newsDetails.UniqueName,
                                                  LinkExtension,
                                                  WebContext.Root
                                                  );
                    }
                    else
                    {
                        this.HRef = string.Format("{3}/{0}{1}{2}",
                                                  Path == null ? "" : Path + "/",
                                                  _newsDetails.UniqueName,
                                                  LinkExtension,
                                                  WebContext.Root
                                                  );
                    }
                }
                break;
            }
            if (this.Controls.Count == 0)
            {
                this.InnerHtml = string.Format(Format, text);
            }
        }