public static void LoadList(Sections section, SettingsForm settingsForm, ListView listView) { try { listView.Items.Clear(); using (StreamReader loadFile = new StreamReader(loadPath)) { string line; while ((line = loadFile.ReadLine()) != null) { if (section == Sections.Movie) { MovieModel formattedLine = DataFormatController.ExistedMovieDataFormatter(line); string[] row = { formattedLine.Name, formattedLine.Genre }; var listViewItem = new ListViewItem(row); listView.Items.Add(listViewItem); } if (section == Sections.Serie) { SerieModel formattedLine = DataFormatController.ExistedSerieDataFormatter(line); string[] row = { formattedLine.Name, formattedLine.Genre }; var listViewItem = new ListViewItem(row); listView.Items.Add(listViewItem); } if (section == Sections.Book) { BookModel formattedLine = DataFormatController.ExistedBookDataFormatter(line); string[] row = { formattedLine.Name, formattedLine.Author, formattedLine.Genre }; var listViewItem = new ListViewItem(row); listView.Items.Add(listViewItem); } } } } catch (FileNotFoundException) { NotFoundExceptions(section, settingsForm); } catch (DirectoryNotFoundException) { NotFoundExceptions(section, settingsForm); } catch (System.ArgumentException) { } }
public static void SaveList(bool showMessage, Button saveButton, Sections section, ListView listView) { StreamWriter saveFile = new StreamWriter(savePath); foreach (ListViewItem item in listView.Items) { if (section == Sections.Movie) { MovieModel movieData = new MovieModel(item.Text, item.SubItems[1].Text); string formattedData = DataFormatController.NewMovieDataFormatter(movieData); saveFile.WriteLine(formattedData); } if (section == Sections.Serie) { SerieModel serieData = new SerieModel(item.Text, item.SubItems[1].Text); string formattedData = DataFormatController.NewSerieDataFormatter(serieData); saveFile.WriteLine(formattedData); } if (section == Sections.Book) { BookModel bookData = new BookModel(item.Text, item.SubItems[1].Text, item.SubItems[2].Text); string formattedData = DataFormatController.NewBookDataFormatter(bookData); saveFile.WriteLine(formattedData); } } saveFile.Close(); if (showMessage) { MessageBox.Show(section + "list saved!"); showMessage = false; saveButton.Enabled = false; saveButton.BackColor = Colors.OptionButtonsDeactiveColor; } }