Advertisement
parabola949

Untitled

Nov 24th, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.05 KB | None | 0 0
  1. namespace Finalproject
  2.    
  3. {
  4.  
  5.  
  6.     public partial class Form1 : Form
  7.     {
  8.         ArrayList _holdThis = new ArrayList(), _tempList = new ArrayList();
  9.         int _year = 0, indextodelete;// = Convert.ToInt32(textBox3.Text);
  10.         string _time = "", _fileName= "", _title = "";
  11.  
  12.         public Form1()
  13.         {
  14.             InitializeComponent();
  15.         }
  16.  
  17.         private void button1_Click(object sender, EventArgs e)
  18.         {//read button
  19.            
  20.             string title = ""; // = textBox2.Text;
  21.             int year = 0;// = Convert.ToInt32(textBox3.Text);
  22.             string time = "";// = textBox4.Text;
  23.             string line;
  24.             string[] values;
  25.             if (!File.Exists(_fileName))
  26.             {
  27.                 MessageBox.Show(@"Incorrect file path.");
  28.                 return;
  29.             }
  30.             using (var sr = new StreamReader(fileName)){
  31.                
  32.             try{
  33.                 while ((line = sr.ReadLine()) != null)
  34.                 {
  35.                    
  36.                         values = line.Split(',');
  37.                        
  38.                         title = values[0].Replace('|',',');
  39.                         year = Convert.ToInt32(values[1]);
  40.                         time = values[2];
  41.                         _holdThis.Add(new Movie(title, year, time));  //do this here.  No reason to intialize variable a (memory handling)
  42.                 }
  43.             }
  44.             catch (ArgumentException e)
  45.             {
  46.                 MessageBox.Show(e.Message);
  47.             }
  48.             catch (IOException i)
  49.             {
  50.                 MessageBox.Show(i.Message);
  51.             }
  52.             finally
  53.             {
  54.                 values = null;
  55.                 line = null;
  56.             }
  57.  
  58.             foreach (Movie item in _holdThis)
  59.             {
  60.                 listBox1.Items.Add(item.movietitle);
  61.                 listBox2.Items.Add(item.movieyear);
  62.                 listBox3.Items.Add(item.movieruntime);
  63.             }
  64.  
  65.         }
  66.  
  67.         private void textBox1_TextChanged(object sender, EventArgs e)
  68.         {
  69.             _fileName = textBox1.Text;
  70.         }
  71.  
  72.         private void textBox2_TextChanged(object sender, EventArgs e)
  73.         {
  74.  
  75.         }
  76.  
  77.         private void textBox3_TextChanged(object sender, EventArgs e)
  78.         {
  79.  
  80.         }
  81.  
  82.         private void textBox4_TextChanged(object sender, EventArgs e)
  83.         {
  84.  
  85.         }
  86.  
  87.         private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
  88.         {
  89.  
  90.         }
  91.  
  92.         private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
  93.         {
  94.  
  95.         }
  96.  
  97.         private void listBox3_SelectedIndexChanged(object sender, EventArgs e)
  98.         {
  99.  
  100.         }
  101.  
  102.         private void button2_Click(object sender, EventArgs e)
  103.         {
  104.             //btnAdd
  105.             string title = textBox2.Text;
  106.            
  107.             int year =0;
  108.             if (!Int32.TryParse(textBox3.Text, out year))
  109.             {
  110.                 MessageBox.Show("Please enter the year as a numeric value");
  111.                 return;
  112.             }
  113.             string time = textBox4.Text;
  114.             _holdThis.Add(new Movie(title, year, time));
  115.  
  116.             listBox1.Items.Add(title);
  117.             listBox2.Items.Add(year);
  118.             listBox3.Items.Add(time);
  119.            
  120.  
  121.             textBox2.Clear();
  122.             textBox3.Clear();
  123.             textBox4.Clear();
  124.  
  125.  
  126.  
  127.  
  128.         }
  129.  
  130.         private void button3_Click(object sender, EventArgs e)
  131.         {
  132.             //btnRemove
  133.             string selection = (string)listBox1.SelectedItem;
  134.             int index = listBox1.SelectedIndex;
  135.             _holdThis.RemoveAt(index)
  136.             listBox1.Items.RemoveAt(index);
  137.             listBox2.Items.RemoveAt(index);
  138.             listBox3.Items.RemoveAt(index);
  139.         }
  140.  
  141.         private void button4_Click(object sender, EventArgs e)
  142.         {
  143.             using (var stream = new StreamWriter(_fileName))
  144.             {
  145.                 foreach (Movie item in Holdthis)
  146.                 {
  147.                     stream.WriteLine(item.movietitle.Replace(',','|') + ","+ item.movieyear + "," + item.movieruntime);
  148.                 }
  149.                 stream.Flush();
  150.                 stream.Close();
  151.             }
  152.  
  153.        
  154.         }
  155.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement