protected void egvAttachments_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            ArticleAttachment attachment = e.Row.DataItem as ArticleAttachment;
            Image             picture    = e.Row.FindControl("imgPicture") as Image;

            if (picture != null)
            {
                if (attachment.IsRemote)
                {
                    picture.ImageUrl = attachment.FileName;
                }
                else
                {
                    picture.ImageUrl = attachment.GetDefaultImageUrl((int)picture.Width.Value, (int)picture.Height.Value);
                }
            }

            HyperLink hyName = e.Row.FindControl("hlName") as HyperLink;
            if (hyName != null)
            {
                hyName.Text        = attachment.Name;
                hyName.NavigateUrl = "#";
            }
        }
    }
Example #2
0
 protected void dlArticle_ItemDataBound(object sender, DataListItemEventArgs e)
 {
     if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
     {
         Image image = e.Item.FindControl("imgArticle") as Image;
         if (image != null)
         {
             Article article = e.Item.DataItem as Article;
             //image.ImageUrl = GlobalSettings.RelativeWebRoot + article.GetDefaultImageUrl(100, 100);
             if (article != null)
             {
                 // 获取附件
                 ArticleAttachment attachment = ArticleAttachments.GetAttachment(article.Image);
                 if (attachment != null)
                 {
                     if (attachment.IsRemote)
                     {
                         image.ImageUrl = attachment.FileName;
                     }
                     else
                     {
                         image.ImageUrl = attachment.GetDefaultImageUrl(100, 100);
                     }
                     image.Visible = true;
                 }
                 else
                 {
                     image.Visible = false;
                 }
             }
             else
             {
                 image.Visible = false;
             }
         }
         //Literal ltPrice = e.Item.FindControl("ltPrice") as Literal;
         //if (ltPrice != null)
         //{
         //    decimal? price = null;
         //    if (!User.Identity.IsAuthenticated)
         //    {
         //        price = ArticlePrices.GetPriceDefault(article.ID);
         //    }
         //    else
         //    {
         //        price = ArticlePrices.GetPriceDefault(article.ID);
         //    }
         //    ltPrice.Text = (price == null ? "需询价" : price.Value.ToString("c"));
         //}
     }
 }
 protected void repArticles_ItemDataBound(object sender, RepeaterItemEventArgs e)
 {
     if (e.Item.Controls.Count > 1)
     {
         Image image = e.Item.Controls[1] as Image;
         if (image != null)
         {
             Article article = e.Item.DataItem as Article;
             if (article != null)
             {
                 // 获取附件
                 ArticleAttachment attachment = ArticleAttachments.GetAttachment(article.Image);
                 if (attachment != null)
                 {
                     if (attachment.IsRemote)
                     {
                         image.ImageUrl = attachment.FileName;
                     }
                     else
                     {
                         image.ImageUrl = attachment.GetDefaultImageUrl(100, 100);
                     }
                     image.Visible = true;
                 }
                 else
                 {
                     image.Visible = false;
                 }
             }
             else
             {
                 image.Visible = false;
             }
         }
     }
 }
Example #4
0
    void WritePics()
    {
        AttachmentQuery          aq    = new AttachmentQuery();
        List <ArticleAttachment> items = ArticleAttachments.GetAttachments(aq).Records;

        if (items != null && items.Count > 0)
        {
            StringBuilder sb = new StringBuilder();
            foreach (ArticleAttachment a in items)
            {
                if (a.IsRemote)
                {
                    sb.Append("item" + a.ID.ToString() + ":'" + a.FileName + "',");
                }
                else
                {
                    sb.Append("item" + a.ID.ToString() + ":'" + a.GetDefaultImageUrl(40, 40) + "',");
                }
            }
            ArticleAttachment aa = items[0];
            imgTitleImg.ImageUrl = (aa.IsRemote ? aa.FileName : aa.GetDefaultImageUrl(40, 40));
            base.ExecuteJs("var titlePics = {" + sb.ToString().Remove(sb.ToString().Length - 1) + "};", true);
        }
    }
Example #5
0
    private void BindData()
    {
        string articleIDStr = Request.QueryString["id"];

        if (!string.IsNullOrEmpty(articleIDStr))
        {
            int articleID;
            if (int.TryParse(HHOnline.Framework.GlobalSettings.Decrypt(articleIDStr), out articleID))
            {
                // 增加点击率
                //ArticleManager.IncreaseHitTimes(articleID);
                BaseViews views = ViewsFactory.GetViews(typeof(ArticleViews));
                views.AddViewCount(articleID);

                Article article = ArticleManager.GetArticle(articleID);
                if (article != null)
                {
                    lblAbstract.InnerHtml = article.Abstract;
                    lblAuthor.Text        = string.IsNullOrEmpty(article.Author) ? "匿名" : article.Author;
                    lblDate.Text          = article.Date.HasValue ? article.Date.Value.ToString() : DateTime.Now.ToString();
                    lblHitTimes.Text      = article.HitTimes.ToString();
                    lblTitle.Text         = article.Title;
                    lblSubTitle.Text      = article.SubTitle;
                    lblKeywords.Text      = string.IsNullOrEmpty(article.Keywords) ? "无" : article.Keywords;

                    // 获取所有产品
                    ProductQuery pq = new ProductQuery();
                    pq.HasPublished = true;
                    List <Product>         products = Products.GetProductList(pq);
                    List <ReplaceKeyValue> rkvs     = new List <ReplaceKeyValue>();

                    foreach (Product item in products)
                    {
                        ReplaceKeyValue rkv = new ReplaceKeyValue();
                        rkv.Key   = item.ProductName;
                        rkv.Value = "<a style='color: blue; text-decoration:underline;' href=\"view.aspx?product-product&ID=" + HHOnline.Framework.GlobalSettings.Encrypt(item.ProductID.ToString()) + "\">" + item.ProductName + "</a>";
                        rkvs.Add(rkv);
                    }

                    FastReplace fr = new FastReplace(rkvs.ToArray());
                    lblContent.InnerHtml = fr.ReplaceAll(article.Content);

                    // 查找分类
                    ArticleCategory ac = ArticleManager.GetArticleCategory(article.Category);
                    if (ac != null)
                    {
                        btnCategory.Text          = ac.Name;
                        btnCategory.OnClientClick = "window.location.href='view.aspx?news-newslist&cate=" + HHOnline.Framework.GlobalSettings.Encrypt(ac.ID.ToString()) + "';return false;";
                    }

                    if (!string.IsNullOrEmpty(article.CopyFrom))
                    {
                        lblCopyForm.Text    = "文章来源: " + article.CopyFrom;
                        lblCopyForm.Visible = true;
                    }
                    else
                    {
                        lblCopyForm.Visible = false;
                    }

                    // 获取附件
                    ArticleAttachment attachment = ArticleAttachments.GetAttachment(article.Image);
                    if (attachment != null)
                    {
                        if (attachment.IsRemote)
                        {
                            imgAttachment.ImageUrl = attachment.FileName;
                        }
                        else
                        {
                            imgAttachment.ImageUrl = attachment.GetDefaultImageUrl(100, 100);
                        }
                        imgAttachment.Visible = true;
                    }
                    else
                    {
                        imgAttachment.Visible = false;
                    }

                    this.ShortTitle = article.Title;
                }
                else
                {
                    imgAttachment.Visible = false;
                }
            }
            this.SetTitle();
        }
    }