Beispiel #1
0
        private void btnGetCategoryInfo_Click(object sender, EventArgs e)
        {
            if (Validering.isComboBoxEmpty(cmbCategories))
            {
                string getInfo = cmbCategories.GetItemText(cmbCategories.SelectedItem);

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

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

                foreach (XmlNode item
                         in dom.DocumentElement.SelectNodes("Categories"))
                {
                    var name = item.SelectSingleNode("Name");

                    string stringName = name.InnerText;

                    if (stringName == getInfo)
                    {
                        tbNewName.Text = stringName;
                    }
                }
            }
        }
Beispiel #2
0
        private void btnChangeCategory_Click(object sender, EventArgs e)
        {
            if (Validering.isComboBoxEmpty(cmbCategories))
            {
                string getInfo = cmbCategories.GetItemText(cmbCategories.SelectedItem);

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

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

                foreach (XmlNode item
                         in dom.DocumentElement.SelectNodes("Categories"))
                {
                    var    name       = item.SelectSingleNode("Name");
                    string stringName = name.InnerText;
                    if (getInfo == stringName)
                    {
                        XmlNode nameNode = item.SelectSingleNode("Name");
                        nameNode.InnerText = tbNewName.Text;
                        MessageBox.Show("Kategorinamnet är ändrat.");
                    }
                }
                dom.Save("categories.xml");
            }
        }
Beispiel #3
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();
            }
        }
        private void btnDeleteFeed_Click(object sender, EventArgs e)
        {
            if (Validering.isComboBoxEmpty(cmbChoseFeed))
            {
                string getFeed = cmbChoseFeed.GetItemText(cmbChoseFeed.SelectedItem);

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

                XmlDocument doc = new XmlDocument();
                doc.LoadXml(xml);

                foreach (XmlNode node in doc.SelectNodes("//Podcast//name"))
                {
                    if (node.InnerText == getFeed)
                    {
                        XmlNode parents = node.ParentNode;
                        parents.ParentNode.RemoveChild(parents);
                        doc.Save("podcasts.xml");
                        MessageBox.Show("Feed är borttagen.");
                    }
                }
            }
        }
        private void Remove_Click(object sender, EventArgs e)
        {
            if (Validering.isComboBoxEmpty(cmbCategoryRemove))
            {
                string getFeed = cmbCategoryRemove.GetItemText(cmbCategoryRemove.SelectedItem);

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

                XmlDocument catDoc = new XmlDocument();

                catDoc.LoadXml(categoryXml);


                foreach (XmlNode node in catDoc.SelectNodes("//Categories//Name"))
                {
                    if (node.InnerText == getFeed)
                    {
                        XmlNode parents = node.ParentNode;
                        parents.ParentNode.RemoveChild(parents);
                        catDoc.Save("categories.xml");
                        MessageBox.Show("Kategori är borttagen.");
                    }
                }
            }
        }
        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();
            }
        }