Beispiel #1
0
        private void podcastNew_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(urlInput.Text))
            {
                if (Validation.IfCorrectURL(urlInput.Text))
                {
                    string selectedCategory = categorySelect.Text;

                    if (!string.IsNullOrWhiteSpace(updateFreqSelect.Text) || !string.IsNullOrWhiteSpace(selectedCategory))
                    {
                        podcasts.Add(new Podcast(urlInput.Text, podcastName.Text, int.Parse(updateFreqSelect.Text), selectedCategory));
                    }

                    urlInput.Text    = "";
                    podcastName.Text = "";

                    OtherSerializer serializer = new OtherSerializer();
                    serializer.Serialize(podcasts);
                    podcastList.Items.Clear();
                    foreach (Podcast podcast in podcasts)
                    {
                        int    numberOfEpisodes = podcast.NumberOfEpisodes;
                        string name             = podcast.Name;
                        string category         = podcast.Category;
                        int    freq             = podcast.UpdateFreq;

                        podcastList.Items.Add($"{numberOfEpisodes}, {name}, {freq}, {category}");
                    }
                }
            }
            DisplayPodcasts();
        }
Beispiel #2
0
        private void categoryRemove_Click(object sender, EventArgs e)
        {
            if (categories.SelectedItem != null)
            {
                // Hämtar ut den valda kategorin som användaren väljer
                string selectedCat = categories.SelectedItem.ToString();

                // Variabler med information samt valmöjlighet
                string            message = "Are you sure you want to delete this category? ";
                string            caption = "Message from the program";
                MessageBoxButtons buttons = MessageBoxButtons.YesNo;
                DialogResult      result;

                // För att visa en MessageBox samt raderar vald kategori med LINQ
                result = MessageBox.Show(message, caption, buttons);
                if (result == System.Windows.Forms.DialogResult.Yes)
                {
                    podcasts.RemoveAll(x => x.Category == selectedCat);

                    OtherSerializer serializer = new OtherSerializer();
                    serializer.Serialize(podcasts);

                    categoryList.Remove(selectedCat);
                    DisplayCategories();
                    DisplayPodcasts();
                }
            }
        }
Beispiel #3
0
        private void podcastRemove_Click(object sender, EventArgs e)
        {
            podcasts.Remove(selectedPodcast);
            OtherSerializer serializer = new OtherSerializer();

            serializer.Serialize(podcasts);
            DisplayPodcasts();
        }
Beispiel #4
0
        private void podcastSave_Click(object sender, EventArgs e)
        {
            OtherSerializer serializer = new OtherSerializer();

            if (urlInput.Text != null || podcastName != null || categorySelect.Text != null)
            {
                selectedPodcast.Url        = urlInput.Text;
                selectedPodcast.Name       = podcastName.Text;
                selectedPodcast.UpdateFreq = int.Parse(updateFreqSelect.Text);
                selectedPodcast.Category   = categorySelect.Text;
            }

            serializer.Serialize(podcasts);
            podcastList.Items.Clear();
            DisplayPodcasts();
        }
Beispiel #5
0
        protected void CreateListOfPodcasts()
        {
            string currentDir = Directory.GetCurrentDirectory();
            string filePath   = @"\podcastListData.xml";

            if (File.Exists(currentDir + filePath))
            {
                OtherSerializer serializer  = new OtherSerializer();
                List <Podcast>  podcastList = serializer.DeserializeList();

                podcasts.AddRange(podcastList);

                DisplayPodcasts();

                foreach (Podcast podcast in podcasts)
                {
                    categoryList.Add(podcast.Category);
                }
            }
        }
Beispiel #6
0
        private void categorySave_Click(object sender, EventArgs e)
        {
            OtherSerializer serializer = new OtherSerializer();
            string          oldCatName = categories.SelectedItem.ToString();
            string          newCatName = categoryInput.Text;

            foreach (Podcast podcast in podcasts)
            {
                if (podcast.Category.Equals(oldCatName))
                {
                    podcast.Category = newCatName;
                }
            }

            serializer.Serialize(podcasts);

            categoryList.Clear();
            podcasts.Clear();

            CreateListOfPodcasts();
            DisplayPodcasts();
            DisplayCategories();
        }