private void AddMovie(Movie entry) { movies.Add(entry); movieTitlesListBox.Items.Add(entry.Title); movieYearListBox.Items.Add(entry.Date); movieRuntimeListBox.Items.Add(entry.Runtime); }
private void addMovieButton_Click(object sender, EventArgs e) { string title = titleTxtBox.Text; int date = Convert.ToInt32(yearTxtBox.Text); string runtime = runtimeTxtBox.Text; Movie entry = new Movie(title, date, runtime); AddMovie(entry); titleTxtBox.Clear(); yearTxtBox.Clear(); runtimeTxtBox.Clear(); }
private void readDataButton_Click(object sender, EventArgs e) { string fileName = filePathTxtBox.Text.Trim(); string line; bool finished = false; string[] lineValue; StreamReader sr = new StreamReader(fileName); try { //Clear items from list boxes and movie arraylist if items are present and read data button is pressed if(movieTitlesListBox.Items.Count > 0) { movieTitlesListBox.Items.Clear(); movieYearListBox.Items.Clear(); movieRuntimeListBox.Items.Clear(); movies.Clear(); } while(!(finished)) { line = sr.ReadLine(); if (line != null) { lineValue = line.Split(','); Movie entry = new Movie(lineValue[0], Convert.ToInt32(lineValue[1]), lineValue[2]); AddMovie(entry); } else finished = true; } } catch(FileNotFoundException fnf) { MessageBox.Show("File Not Found {0}", fnf.Message); } catch(DirectoryNotFoundException dnf) { MessageBox.Show("File Path Not Found {0}", dnf.Message); } catch(Exception ex) { MessageBox.Show(ex.Message); } finally { sr.Close(); } }