-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form2.cs
66 lines (64 loc) · 5.01 KB
/
Form2.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp9
{
public partial class Form2 : Form
{
List<song> fav; //A list of song type variables (From song.cs class), fav.
public Form2(List<song> top10) //Form2 initialize along with a list of song type variables (From song.cs class), top10.
{
InitializeComponent(); //Initialize components.
fav = new List<song>(); //fav, is a list of song type variables (From song.cs class).
fav = top10; //Lists of song type variables (From song.cs class), fav equals to top10 initially.
}
private void Form2_Load(object sender, EventArgs e) //Form2_Load void.
{
try //A try method.
{
if (fav.Count() <= 10) //If fav.Count is less than/equals to 10, then:
{
for (int i = 0; i < fav.Count(); i++) //A for loop statement.
{
StreamWriter sw = new StreamWriter("tmp.txt", true); //A StreamWriter variable, sw for tmp.txt file.
{
sw.Write("SONG : " + fav[i].Song + " ARTIST : " + fav[i].Artist + //StreamWriter variable, sw writes to tmp.txt file,
" ALBUM : " + fav[i].Album + " YEAR : " + fav[i].Year + //song's name, song's artist, song's publish year,
" GENDER : " + fav[i].Gender + " CLICKS : " + fav[i].Fame //song's gender category and song's clicks (plays),
+ Environment.NewLine); //which all are provided from song.cs class.
}
sw.Close(); //StreamWriter variable, sw closes.
}
}
else //Else (If fav.Count is over 10) then:
{
for (int i = 0; i < 10; i++) //A for loop statement (with 10 loops).
{
StreamWriter sw = new StreamWriter("tmp.txt", true); //A StreamWriter variable, sw for tmp.txt file.
{
sw.Write("SONG : " + fav[i].Song + " ARTIST : " + fav[i].Artist + //StreamWriter variable, sw writes to tmp.txt file,
" ALBUM : " + fav[i].Album + " YEAR : " + fav[i].Year + //song's name, song's artist, song's publish year,
" GENDER : " + fav[i].Gender + " CLICKS : " + fav[i].Fame //song's gender category and song's clicks (plays),
+ Environment.NewLine); //which all are provided from song.cs class.
}
sw.Close(); //StreamWriter variable, sw closes.
}
}
richTextBox1.LoadFile("tmp.txt", RichTextBoxStreamType.PlainText); //richTextBox1 loads tmp.txt file.
File.Delete("tmp.txt"); //Deletes tmp.txt file.
}
catch //Exception.
{
MessageBox.Show("THERE ARE NO SONGS"); //Exception message appears.
this.Close(); //Closes the Application (Form2).
}
}
}
}