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

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.Xml;
  9. namespace _3ESoft.WindowsMobile.RSS
  10. {
  11.     public partial class FormChannel : Form
  12.     {
  13.         RssType opType = RssType.Channel;
  14.         bool isNew = true;
  15.         /// <summary>
  16.         /// 要编辑的ChannelName
  17.         /// </summary>
  18.         public string OldChannelName { get; set; }
  19.         /// <summary>
  20.         /// 要编辑的Rss节点Opml对象
  21.         /// </summary>
  22.         public Opml oldOpml { get; set; }
  23.         public FormChannel(RssType type, bool _isNew)
  24.         {
  25.             InitializeComponent();
  26.             opType = type;
  27.             isNew = _isNew;
  28.             if (opType == RssType.Channel)
  29.             {
  30.                 pChannel.Dock = DockStyle.Fill;
  31.                 pChannel.BringToFront();
  32.                 if (isNew)
  33.                     this.Text = "新建频道分类";
  34.                 else
  35.                     this.Text = "频道分类重命名";
  36.             }
  37.             else
  38.             {
  39.                 pRss.Dock = DockStyle.Fill;
  40.                 pRss.BringToFront();
  41.                 if (isNew)
  42.                     this.Text = "新建频道";
  43.                 else
  44.                     this.Text = "频道编辑";
  45.             }
  46.         }
  47.         private void miSave_Click(object sender, EventArgs e)
  48.         {
  49.             if (opType == RssType.Channel)
  50.             {
  51.                 if (isNew)
  52.                 {
  53.                     if (!OpmlHelper.ChannelAdd(txtChannelName.Text))
  54.                     {
  55.                         MessageBox.Show("添加类别失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
  56.                         return;
  57.                     }
  58.                 }
  59.                 else
  60.                 {
  61.                     if (!OpmlHelper.ChannelReName(OldChannelName, txtChannelName.Text))
  62.                     {
  63.                         MessageBox.Show("类别修改失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
  64.                         return;
  65.                     }
  66.                 }
  67.             }
  68.             else if (opType == RssType.Rss)
  69.             {
  70.                 if (cbChannels.Text.Trim() == "" || txtRssTitle.Text.Trim() == "")
  71.                 {
  72.                     MessageBox.Show("类别和标题都不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
  73.                     return;
  74.                 }
  75.                 Opml opml = new Opml() { XmlUrl = txtRssUrl.Text, Text = txtRssTitle.Text, Type = RssType.Rss };
  76.                 if (isNew)
  77.                 {
  78.                     if (!OpmlHelper.RSSAdd(cbChannels.Text, opml))
  79.                     {
  80.                         MessageBox.Show("添加频道失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
  81.                         return;
  82.                     }
  83.                 }
  84.                 else
  85.                 {
  86.                     if (!OpmlHelper.RSSEdit(OldChannelName, cbChannels.Text, oldOpml, opml))
  87.                     {
  88.                         MessageBox.Show("编辑频道失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
  89.                         return;
  90.                     }
  91.                 }
  92.             }
  93.             else
  94.             {
  95.                 MessageBox.Show("类别不对!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
  96.                 return;
  97.             }
  98.             MessageBox.Show("操作成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
  99.                 this.Close();
  100.         }
  101.         private void miCancel_Click(object sender, EventArgs e)
  102.         {
  103.             this.Close();
  104.         }
  105.         private void btnGetRssTitle_Click(object sender, EventArgs e)
  106.         {
  107.             Cursor.Current = Cursors.WaitCursor;
  108.             Cursor.Show();
  109.              XmlDocument XmlRSS = new XmlDocument();
  110.              try
  111.              {
  112.                  XmlRSS.Load(txtRssUrl.Text);
  113.                  XmlNode ChannelNode;
  114.                  ChannelNode = XmlRSS.SelectSingleNode("/rss/channel");
  115.                  if (ChannelNode["title"] != null)
  116.                      txtRssTitle.Text = ChannelNode["title"].InnerText;
  117.                  else
  118.                      MessageBox.Show("没有找到名称,RSS源出错!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
  119.              }
  120.              catch
  121.              {
  122.                  MessageBox.Show("没有找到RSS源,连结失败。请检查Rss的URL!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); 
  123.              }
  124.              Cursor.Current = Cursors.Default;
  125.         }
  126.         private void FormChannel_Load(object sender, EventArgs e)
  127.         {
  128.             Cursor.Current = Cursors.WaitCursor;
  129.             Cursor.Show();
  130.             Application.DoEvents();
  131.             List<OpmlChannel> oChannelList = OpmlHelper.GetChannelList();
  132.             if (oChannelList != null)
  133.             {
  134.                 cbChannels.DataSource = oChannelList;
  135.                 cbChannels.DisplayMember = "Title";
  136.                 cbChannels.ValueMember = "ID";
  137.             }
  138.             Cursor.Current = Cursors.Default;
  139.         }
  140.     }
  141. }