Пример #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            int    Code;
            string strCode = Request["Code"];
            Int32.TryParse(strCode, out Code);
            if (Code != 0)
            {
                BOLNews NewsBOL = new BOLNews();
                //PageTools1.ItemCode = Code;
                //PageTools1.HCEntityCode = 1;
                vNewsDetail CurNews = NewsBOL.GetNewsByCode(Code);
                if (CurNews == null)
                {
                    msgText.MessageTextMode = AKP.Web.Controls.Common.MessageMode.Error;
                    msgText.Text            = "No news found.";
                    pnlShowNews.Visible     = false;
                    return;
                }

                strNewsCode = CurNews.Code.ToString();
                Tools.SetLink("lnkCanonical", "https://www.khabardaan.ir/" + "/News/" + CurNews.Code + ".html");

                Tools.SetMeta("keywords", CurNews.Title);
                Tools.SetMeta("description", CurNews.Title);
                Tools.SetMeta("twittercard", CurNews.Title);
                Tools.SetMeta("twittertitle", CurNews.Title);
                Tools.SetMeta("twitterdescription", CurNews.Title);
                Tools.SetMeta("ogtitle", CurNews.Title);
                Tools.SetMeta("ogurl", "https://www.khabardaan.ir/" + "/News/" + CurNews.Code + "_" + Tools.ReplaceSpaceWithUnderline(CurNews.Title) + ".html");
                Tools.SetMeta("twitterimagesrc", "");
                if (!string.IsNullOrEmpty(CurNews.PicName))
                {
                    Tools.SetMeta("ogimage", "https://static.parset.com/Files/News/" + CurNews.PicName);
                }
                Tools.SetMeta("ogdescription", CurNews.Title);


                //NewsBOL.UpdateViewCount(Code);
                lblViewTitle.Text = CurNews.Title;
                Page.Title        = CurNews.Title + " - خبردان";
                ReqUtils Utils     = new ReqUtils();
                string   FullStory = CurNews.Contents;
                FullStory = Utils.RemoveTags(FullStory);

                FullStory = Tools.FormatString(FullStory);
                FullStory = Tools.ShowBriefText(FullStory, 3000) + "...";

                FullStory = FullStory.Replace("<img ", "<img class=\"img-responsive\" ");

                //if (FullStory.IndexOf("<br />") == -1)
                //{
                //    if(FullStory.IndexOf("<img ") == -1)
                //        lblViewContents.Text = GenParagraph(FullStory);
                //    else
                //        lblViewContents.Text = CorrectEnters(FullStory);
                //}
                //else
                //    lblViewContents.Text = FullStory;


                DataTable dtNewsImages = new Converter <NewsImages>().ToDataTable(NewsBOL.GetNewsImages(CurNews.Code));

                lblViewContents.Text = GenParagraph(FullStory, dtNewsImages);

                DateTimeMethods dtm = new DateTimeMethods();
                lblViewNewsDate.Text = Tools.ChangeEnc(dtm.GetPersianDate((DateTime)CurNews.NewsDate));
                if (!string.IsNullOrEmpty(CurNews.PicName))
                {
                    imgPicName.ImageUrl = CurNews.ImgUrl;// "https://www.khabardaan.ir/Files/News/" + CurNews.PicName;
                    imgPicName.ToolTip  = CurNews.Title;
                }
                else
                {
                    pnlPic.Visible = false;
                }
                RelatedNews1.NewsCode = Code.ToString();
                KeywordList1.NewsCode = Code.ToString();

                lblViewCount.Text        = Tools.ChangeEnc(NewsBOL.GetVisitCount(CurNews.Code));
                hplViewResourceName.Text = CurNews.Name;
                hplMoreFull.NavigateUrl  = hplViewResourceName.NavigateUrl = CurNews.Url;
                //"https://www.khabardaan.ir/N" + CurNews.Code + "_" + Tools.ReplaceSpaceWithUnderline(CurNews.Title) + ".html";
                lblViewCode.Text = CurNews.Code.ToString();

                string strNewsHour = CurNews.NewsDate.Value.Hour.ToString();
                if (strNewsHour.Length == 1)
                {
                    strNewsHour = "0" + strNewsHour;
                }
                string strNewsMinute = CurNews.NewsDate.Value.Minute.ToString();
                if (strNewsMinute.Length == 1)
                {
                    strNewsMinute = "0" + strNewsMinute;
                }

                lblViewNewsTime.Text = Tools.ChangeEnc(strNewsHour + ":" + strNewsMinute);

                News3Col1.LoadPicNews();

                //rptNewsImages.DataSource = NewsBOL.GetNewsImages(CurNews.Code);
                //rptNewsImages.DataBind();

                //rptImages.DataSource = NewsBOL.GetSmallRelatedNews(CurNews.Code, 20, 1);
                //rptImages.DataBind();


                //int CatCode = (int)CurNews.CatCode;
                //switch (CatCode)
                //{
                //    case 1:
                //        {
                //            lblCatTitle.Text = "اجتماعي ";
                //            break;
                //        }
                //    case 2:
                //        {
                //            lblCatTitle.Text = "اقتصادي";
                //            break;
                //        }
                //    case 3:
                //        {
                //            lblCatTitle.Text = "سياسي";
                //            break;
                //        }
                //    case 4:
                //        {
                //            lblCatTitle.Text = "ورزشي";
                //            break;
                //        }
                //    case 5:
                //        {
                //            lblCatTitle.Text = "علمي";
                //            break;
                //        }
                //    case 6:
                //        {
                //            lblCatTitle.Text = "فرهنگي";
                //            break;
                //        }
                //    case 7:
                //        {
                //            lblCatTitle.Text = "ادب و هنر";
                //            break;
                //        }
                //    case 8:
                //        {
                //            lblCatTitle.Text = "بين‌الملل";
                //            break;
                //        }
                //    case 9:
                //        {
                //            lblCatTitle.Text = "حوادث";
                //            break;
                //        }
                //    default:
                //        break;
                //}
                //lblCatTitle.Text = "آخرین خبرهای  " + lblCatTitle.Text ;

                //NewsList1.ShowPager = false;
                //NewsList1.ShowNewsByCatCode((int)CurNews.CatCode, null);


                if (Request.UserAgent == "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" ||
                    Request.UserAgent == "Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)" ||
                    Request.UserAgent == "msnbot/2.0b (+http://search.msn.com/msnbot.htm)._" ||
                    Request.UserAgent == "Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)" ||
                    Request.UserAgent == "Mozilla/5.0 (en-us) AppleWebKit/525.13 (KHTML, like Gecko; Google Web Preview) Version/3.1 Safari/525.13" ||
                    Request.UserAgent == "Mozilla/5.0 (compatible; MJ12bot/v1.3.3; http://www.majestic12.co.uk/bot.php?+)" ||
                    Request.UserAgent == "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)" ||
                    Request.UserAgent == "Mozilla/5.0 (compatible; MJ12bot/v1.4.3; http://www.majestic12.co.uk/bot.php?+)" ||
                    Request.UserAgent == "Sogou web spider/4.0(+http://www.sogou.com/docs/help/webmasters.htm#07)"
                    )
                {
                }
                else
                {
                    NewsBOL.IncrementVisitCount(Code);
                }
                //if (FullStory.Length < 100)
                //{
                //    Response.Redirect(CurNews.Url);
                //    return;
                //}

                //SmallAdsList1.ShowAdsByNewsCode(Code);


                //dtlRelatedPicNews.DataSource = NewsBOL.GetRelatedPicNews(Code);
                //dtlRelatedPicNews.DataBind();

                //ProductsDataContext pdc = new ProductsDataContext();
                //vRandPayeganGood CurRandBanner = pdc.vRandPayeganGoods.SingleOrDefault();
                //if (CurRandBanner != null)
                //{
                //    hplPBanner.ImageUrl = CurRandBanner.strHBannerURL.Trim();
                //    hplPBanner.NavigateUrl = "http://forosh.biz/Detail.aspx?q=" + CurRandBanner.strGoodCode.Trim() + "&s=9144";
                //}
                //CurRandBanner = pdc.vRandPayeganGoods.SingleOrDefault();
                //if (CurRandBanner != null)
                //{
                //    hplPBanner2.ImageUrl = CurRandBanner.strHBannerURL.Trim();
                //    hplPBanner2.NavigateUrl = "http://forosh.biz/Detail.aspx?q=" + CurRandBanner.strGoodCode.Trim() + "&s=9144";
                //}
            }
        }
        catch (Exception err)
        {
            BOLErrorLogs ErrorLogsBOL = new BOLErrorLogs();
            ErrorLogsBOL.Insert(err.Message, DateTime.Now, Request.Url.AbsolutePath, "ShowNews::Load");
        }
    }