Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.96 KB | None | 0 0
  1. namespace Labb_3_1
  2. {
  3. /// <summary>
  4. /// Laboration 3.1
  5. /// Kurs: 1ik203
  6. /// Av: Martin Nilsson och Peter Heimbrand
  7. /// Datum: 2011-02-22
  8. /// </summary>
  9. public partial class Form1 : Form
  10. {
  11. List<Film> Filmtps = new List<Film>();
  12. Film namlos;
  13.  
  14. public Form1()
  15. {
  16. InitializeComponent();
  17. }
  18.  
  19.  
  20. private void button2_Click(object sender, EventArgs e)
  21. {
  22.  
  23. for (int i = 0; i < Filmtps.Count; i++)
  24. {
  25. listBox1.Items.Add(Filmtps[i].Filmtitel);
  26. listBox1.Items.Add(Filmtps[i].Huvudkaraktar);
  27. listBox1.Items.Add(Filmtps[i].Speltid);
  28. listBox1.Items.Add(Filmtps[i].Genre);
  29. listBox1.Items.Add(Filmtps[i].Medietyp);
  30. listBox1.Items.Add(Filmtps[i].Kommentarer);
  31. listBox1.Items.Add("----------");
  32. }
  33.  
  34.  
  35. }
  36.  
  37. private void button1_Click_1(object sender, EventArgs e)
  38. {
  39. namlos = new Film();
  40. namlos.Filmtitel = Convert.ToString(textBox5.Text);
  41. namlos.Huvudkaraktar = Convert.ToString(textBox4.Text);
  42. namlos.Speltid = Convert.ToInt32(textBox3.Text);
  43. namlos.Genre = Convert.ToString(textBox2.Text);
  44. namlos.Medietyp = Convert.ToString(textBox1.Text);
  45. namlos.Kommentarer = Convert.ToString(textBox6.Text);
  46. Filmtps.Add(namlos);
  47. }
  48.  
  49. private void textBox6_TextChanged(object sender, EventArgs e)
  50. {
  51.  
  52. }
  53.  
  54. private void Form1_FormClosing(object sender, FormClosingEventArgs e)
  55. {
  56. IFormatter posten = new BinaryFormatter();
  57. FileStream spara = new FileStream("Filmtps.dat", FileMode.OpenOrCreate, FileAccess.Write);
  58. posten.Serialize(spara, Filmtps);
  59. spara.Close();
  60.  
  61. }
  62.  
  63. private void Form1_Load(object sender, EventArgs e)
  64. {
  65.  
  66. IFormatter posten = new BinaryFormatter();
  67. try
  68. {
  69. FileStream hamta = new FileStream("Filmtps.dat", FileMode.OpenOrCreate, FileAccess.Read);
  70. Filmtps = posten.Deserialize(hamta) as List<Film>;
  71. hamta.Close();
  72. }
  73. catch (Exception ex) { MessageBox.Show(ex.Message); }
  74.  
  75. }
  76.  
  77. private void button3_Click(object sender, EventArgs e)
  78. {
  79. listBox1.Items.Clear();
  80. bool _harHittatFilm = false;
  81. for (int i = 0; i < Filmtps.Count; i++)
  82. {
  83. if (textBox7.Text == Filmtps[i].Filmtitel)
  84. {
  85. _harHittatFilm = true;
  86. }
  87. if (_harHittatFilm)
  88. {
  89. listBox1.Items.Add("Filmtitel:" + Filmtps[i].Filmtitel);
  90. listBox1.Items.Add("Genre:" + Filmtps[i].Genre);
  91. listBox1.Items.Add("Huvudkaraktär." + Filmtps[i].Huvudkaraktar);
  92. listBox1.Items.Add("Speltid:" + Filmtps[i].Speltid);
  93. listBox1.Items.Add("Mediatyp:" + Filmtps[i].Medietyp);
  94. listBox1.Items.Add("Kommentarer:" + Filmtps[i].Kommentarer);
  95. }
  96. else
  97. {
  98. MessageBox.Show("Filmen kunde inte hittas, lägg till den eller sök på en annan!");
  99. }
  100. }
  101.  
  102. }
  103.  
  104. private void button4_Click(object sender, EventArgs e)
  105. {
  106. MessageBox.Show("Använd knappen Lägg till för att lägga till en film, skriv in datan som du har. Vill du se hela listan tryck på Visa filmer, Vill du söka på en film i databasen skriv in filmtitlen och tryck Söka Filmer. Nu är du fullärd bra va");
  107. }
  108.  
  109. private void button5_Click(object sender, EventArgs e)
  110. {
  111. MessageBox.Show("Filmdatabas v1.3 2011-02-22 av: h4x0r och l1ll3n");
  112. }
  113.  
  114. }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement