FormRssShow.cs
上传用户:xtyqhl
上传日期:2022-06-07
资源大小:212k
文件大小:4k
源码类别:

Windows Mobile

开发平台:

Windows_Unix

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.IO;
  9. using _3ESoft.WindowsMobile.Process;
  10. namespace _3ESoft.WindowsMobile.RSS
  11. {
  12.     public partial class FormRssShow : Form
  13.     {
  14.         /// <summary>
  15.         /// 当前RSS对象
  16.         /// </summary>
  17.         RssNews CurrRssNews;
  18.         RssNews PreRssNews;
  19.         RssNews NextRssNews;
  20.         /// <summary>
  21.         /// 当前频道所有News列表,全局的
  22.         /// </summary>
  23.         public List<RssNews> NewsList { get; set; }
  24.         bool IsNavigated = false;
  25.         public FormRssShow(RssNews _CurrRssNews)
  26.         {
  27.             InitializeComponent();
  28.             CurrRssNews = _CurrRssNews;
  29.         }
  30.         private void FormRssShow_Load(object sender, EventArgs e)
  31.         {
  32.             PreRssAndNextRss();
  33.             GetDocumentText();
  34.             //IsNavigated = true;
  35.             
  36.         }
  37.         /// <summary>
  38.         /// 构建Html文档
  39.         /// </summary>
  40.         private void GetDocumentText()
  41.         {
  42.             StreamReader reader = new StreamReader(Global.AppRssStylePath() + "Style1.htm");
  43.             string News = reader.ReadToEnd();
  44.             News = News.Replace("#TITLE#", CurrRssNews.Title);
  45.             News = News.Replace("#lblAuthor#", "作者");
  46.             News = News.Replace("#Author#", CurrRssNews.Author);
  47.             News = News.Replace("#PubDate#", CurrRssNews.PubDate);
  48.             News = News.Replace("#Description#", CurrRssNews.Description);
  49.             News = News.Replace("#LINK#", CurrRssNews.Link);
  50.             News = News.Replace("#READ#", "在线阅读...");
  51.             News = News.Replace("#PreRSS#", PreRssNews !=null?"阅读上一篇":"");
  52.             News = News.Replace("#NextRSS#", NextRssNews != null ? "阅读下一篇" : "");
  53.             CurrRssNews.IsRead = true;
  54.             RssBrowser.DocumentText = News;
  55.           
  56.         }
  57.         private void RssBrowser_Navigating(object sender, WebBrowserNavigatingEventArgs e)
  58.         {
  59.             string strUrl = e.Url.ToString();
  60.             if (strUrl.ToUpper().EndsWith("&3ESOFT"))
  61.             {
  62.                 //e.Cancel = true;
  63.                 if (strUrl.IndexOf("previous") > 0)
  64.                 {
  65.                     CurrRssNews = PreRssNews;
  66.                 }
  67.                 else if (strUrl.IndexOf("next") > 0)
  68.                 {
  69.                     CurrRssNews = NextRssNews;
  70.                 }
  71.                 PreRssAndNextRss();
  72.                 GetDocumentText();
  73.                 //IsNavigated = false;
  74.             }
  75.             //非向DocumentText赋值产生,非制定的连结,则用新IE打开
  76.             else if (e.Url != new Uri("about:blank"))
  77.             {
  78.                 e.Cancel = true;
  79.                 MobileProcess.CreateProcess("iexplore.exe", e.Url.ToString(), null);
  80.             }
  81.         }
  82.         /// <summary>
  83.         /// 生成上一篇,下一篇
  84.         /// </summary>
  85.         private void PreRssAndNextRss()
  86.         {
  87.             for (int i = 0; i < NewsList.Count; i++)
  88.             {
  89.                 if (CurrRssNews == NewsList[i])
  90.                 {
  91.                     
  92.                     if (i == 0)
  93.                     {
  94.                         PreRssNews = null;
  95.                         NextRssNews = NewsList[i + 1];
  96.                     }
  97.                     else if (i == NewsList.Count-1)
  98.                     {
  99.                         PreRssNews = NewsList[i - 1];
  100.                         NextRssNews = null;
  101.                     }
  102.                     else
  103.                     {
  104.                         PreRssNews = NewsList[i - 1];
  105.                         NextRssNews = NewsList[i + 1];
  106.                     }
  107.                 }
  108.             }
  109.            
  110.         }
  111.         private void RssBrowser_Validating(object sender, CancelEventArgs e)
  112.         {
  113.             e.Cancel = true;
  114.         }
  115.         private void RssBrowser_Navigated(object sender, WebBrowserNavigatedEventArgs e)
  116.         {
  117.             //if (!IsNavigated)
  118.             //{
  119.             //    GetDocumentText();
  120.             //    IsNavigated = true;
  121.             //}
  122.         }
  123.     }
  124. }