Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Finalproject
- {
- public partial class Form1 : Form
- {
- ArrayList _holdThis = new ArrayList(), _tempList = new ArrayList();
- int _year = 0, indextodelete;// = Convert.ToInt32(textBox3.Text);
- string _time = "", _fileName= "", _title = "";
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {//read button
- string title = ""; // = textBox2.Text;
- int year = 0;// = Convert.ToInt32(textBox3.Text);
- string time = "";// = textBox4.Text;
- string line;
- string[] values;
- if (!File.Exists(_fileName))
- {
- MessageBox.Show(@"Incorrect file path.");
- return;
- }
- using (var sr = new StreamReader(fileName)){
- try{
- while ((line = sr.ReadLine()) != null)
- {
- values = line.Split(',');
- title = values[0].Replace('|',',');
- year = Convert.ToInt32(values[1]);
- time = values[2];
- _holdThis.Add(new Movie(title, year, time)); //do this here. No reason to intialize variable a (memory handling)
- }
- }
- catch (ArgumentException e)
- {
- MessageBox.Show(e.Message);
- }
- catch (IOException i)
- {
- MessageBox.Show(i.Message);
- }
- finally
- {
- values = null;
- line = null;
- }
- foreach (Movie item in _holdThis)
- {
- listBox1.Items.Add(item.movietitle);
- listBox2.Items.Add(item.movieyear);
- listBox3.Items.Add(item.movieruntime);
- }
- }
- private void textBox1_TextChanged(object sender, EventArgs e)
- {
- _fileName = textBox1.Text;
- }
- private void textBox2_TextChanged(object sender, EventArgs e)
- {
- }
- private void textBox3_TextChanged(object sender, EventArgs e)
- {
- }
- private void textBox4_TextChanged(object sender, EventArgs e)
- {
- }
- private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
- {
- }
- private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
- {
- }
- private void listBox3_SelectedIndexChanged(object sender, EventArgs e)
- {
- }
- private void button2_Click(object sender, EventArgs e)
- {
- //btnAdd
- string title = textBox2.Text;
- int year =0;
- if (!Int32.TryParse(textBox3.Text, out year))
- {
- MessageBox.Show("Please enter the year as a numeric value");
- return;
- }
- string time = textBox4.Text;
- _holdThis.Add(new Movie(title, year, time));
- listBox1.Items.Add(title);
- listBox2.Items.Add(year);
- listBox3.Items.Add(time);
- textBox2.Clear();
- textBox3.Clear();
- textBox4.Clear();
- }
- private void button3_Click(object sender, EventArgs e)
- {
- //btnRemove
- string selection = (string)listBox1.SelectedItem;
- int index = listBox1.SelectedIndex;
- _holdThis.RemoveAt(index)
- listBox1.Items.RemoveAt(index);
- listBox2.Items.RemoveAt(index);
- listBox3.Items.RemoveAt(index);
- }
- private void button4_Click(object sender, EventArgs e)
- {
- using (var stream = new StreamWriter(_fileName))
- {
- foreach (Movie item in Holdthis)
- {
- stream.WriteLine(item.movietitle.Replace(',','|') + ","+ item.movieyear + "," + item.movieruntime);
- }
- stream.Flush();
- stream.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement