Ejemplo n.º 1
0
        private void btnChangeCategory_Click(object sender, EventArgs e)
        {
            if (Validering.EmptyTextField(tbChangeFeedUrl) && Validering.IsUrlCorrect(tbChangeFeedUrl) &&
                Validering.EmptyTextField(tbChangeFeedName) && Validering.EmptyTextField(tbChangeFeedInterval) &&
                Validering.EmptyInterval(tbChangeFeedInterval) &&
                Validering.isComboBoxEmpty(cmbChangeCategory))
            {
                string getInfo = cmbChooseFeed.GetItemText(cmbChooseFeed.SelectedItem);

                var xml = "";
                using (var client = new System.Net.WebClient())
                {
                    client.Encoding = Encoding.UTF8;
                    xml             = client.DownloadString("podcasts.xml");
                }

                var dom = new XmlDocument();
                dom.LoadXml(xml);

                foreach (XmlNode item
                         in dom.DocumentElement.SelectNodes("Podcast"))
                {
                    var    name       = item.SelectSingleNode("name");
                    string stringName = name.InnerText;
                    if (getInfo == stringName)
                    {
                        XmlNode urlNode      = item.SelectSingleNode("url");
                        XmlNode nameNode     = item.SelectSingleNode("name");
                        XmlNode intervalNode = item.SelectSingleNode("interval");
                        XmlNode categoryNode = item.SelectSingleNode("category");

                        urlNode.InnerText  = tbChangeFeedUrl.Text;
                        nameNode.InnerText = tbChangeFeedName.Text;
                        string intervalNumber                    = tbChangeFeedInterval.Text;
                        int    intIntervalNumber                 = Convert.ToInt32(intervalNumber);
                        int    multiplicatedIntervalNumber       = intIntervalNumber * 60000;
                        string stringMultiplicatedIntervalNumber = Convert.ToString(multiplicatedIntervalNumber);
                        intervalNode.InnerText = stringMultiplicatedIntervalNumber;
                        categoryNode.InnerText = cmbChangeCategory.Text;
                        MessageBox.Show("Feed ändrad!");
                    }
                }
                dom.Save("podcasts.xml");
                LoadBox();
            }
        }
Ejemplo n.º 2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (Validering.EmptyTextField(tbUrl) && Validering.IsUrlCorrect(tbUrl) && Validering.EmptyTextField(tbName) && Validering.EmptyTextField(tbInterval) && Validering.EmptyInterval(tbInterval) &&
                Validering.isComboBoxEmpty(cmbCategory))
            {
                string url      = tbUrl.Text;
                string name     = tbName.Text;
                int    interval = Convert.ToInt32(tbInterval.Text);
                string category = cmbCategory.SelectedItem.ToString();



                Podcast podcast = AddNewPodcast(url, name, interval, category);
                podcasts.Add(podcast);


                using (var stream = new StreamWriter("podcasts.xml")) // Skapar XML filen.
                {
                    serializer.Serialize(stream, podcasts);
                }

                MessageBox.Show("Feed added.");
                ClearListBox();
            }
        }