FormChannel.cs
资源名称:MobileRss.rar [点击查看]
上传用户:xtyqhl
上传日期:2022-06-07
资源大小:212k
文件大小:6k
源码类别:
Windows Mobile
开发平台:
Windows_Unix
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using System.Xml;
- namespace _3ESoft.WindowsMobile.RSS
- {
- public partial class FormChannel : Form
- {
- RssType opType = RssType.Channel;
- bool isNew = true;
- /// <summary>
- /// 要编辑的ChannelName
- /// </summary>
- public string OldChannelName { get; set; }
- /// <summary>
- /// 要编辑的Rss节点Opml对象
- /// </summary>
- public Opml oldOpml { get; set; }
- public FormChannel(RssType type, bool _isNew)
- {
- InitializeComponent();
- opType = type;
- isNew = _isNew;
- if (opType == RssType.Channel)
- {
- pChannel.Dock = DockStyle.Fill;
- pChannel.BringToFront();
- if (isNew)
- this.Text = "新建频道分类";
- else
- this.Text = "频道分类重命名";
- }
- else
- {
- pRss.Dock = DockStyle.Fill;
- pRss.BringToFront();
- if (isNew)
- this.Text = "新建频道";
- else
- this.Text = "频道编辑";
- }
- }
- private void miSave_Click(object sender, EventArgs e)
- {
- if (opType == RssType.Channel)
- {
- if (isNew)
- {
- if (!OpmlHelper.ChannelAdd(txtChannelName.Text))
- {
- MessageBox.Show("添加类别失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
- return;
- }
- }
- else
- {
- if (!OpmlHelper.ChannelReName(OldChannelName, txtChannelName.Text))
- {
- MessageBox.Show("类别修改失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
- return;
- }
- }
- }
- else if (opType == RssType.Rss)
- {
- if (cbChannels.Text.Trim() == "" || txtRssTitle.Text.Trim() == "")
- {
- MessageBox.Show("类别和标题都不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
- return;
- }
- Opml opml = new Opml() { XmlUrl = txtRssUrl.Text, Text = txtRssTitle.Text, Type = RssType.Rss };
- if (isNew)
- {
- if (!OpmlHelper.RSSAdd(cbChannels.Text, opml))
- {
- MessageBox.Show("添加频道失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
- return;
- }
- }
- else
- {
- if (!OpmlHelper.RSSEdit(OldChannelName, cbChannels.Text, oldOpml, opml))
- {
- MessageBox.Show("编辑频道失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
- return;
- }
- }
- }
- else
- {
- MessageBox.Show("类别不对!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
- return;
- }
- MessageBox.Show("操作成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
- this.Close();
- }
- private void miCancel_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- private void btnGetRssTitle_Click(object sender, EventArgs e)
- {
- Cursor.Current = Cursors.WaitCursor;
- Cursor.Show();
- XmlDocument XmlRSS = new XmlDocument();
- try
- {
- XmlRSS.Load(txtRssUrl.Text);
- XmlNode ChannelNode;
- ChannelNode = XmlRSS.SelectSingleNode("/rss/channel");
- if (ChannelNode["title"] != null)
- txtRssTitle.Text = ChannelNode["title"].InnerText;
- else
- MessageBox.Show("没有找到名称,RSS源出错!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
- }
- catch
- {
- MessageBox.Show("没有找到RSS源,连结失败。请检查Rss的URL!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
- }
- Cursor.Current = Cursors.Default;
- }
- private void FormChannel_Load(object sender, EventArgs e)
- {
- Cursor.Current = Cursors.WaitCursor;
- Cursor.Show();
- Application.DoEvents();
- List<OpmlChannel> oChannelList = OpmlHelper.GetChannelList();
- if (oChannelList != null)
- {
- cbChannels.DataSource = oChannelList;
- cbChannels.DisplayMember = "Title";
- cbChannels.ValueMember = "ID";
- }
- Cursor.Current = Cursors.Default;
- }
- }
- }