I have to make a playlist where I can add a song title, the artist and the duration. I may not add the same song twice ( title, artist, and duration the same) and when i try to add a song with the same title and artist, but with a different duration, I have to keep the one with the longest duration.
This is my code I have now:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnAdd_Click(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(txtTitle.Text) || String.IsNullOrEmpty(txtArtist.Text) || String.IsNullOrEmpty(txtDuration.Text) || System.Text.RegularExpressions.Regex.IsMatch(txtDurationr.Text, "[^0-9]"))
{
MessageBox.Show("No valid entry");
}
else
{
String title = Convert.ToString(txtTitle.Text);
String artist = Convert.ToString(txtArtist.Text);
double duration = Convert.ToDouble(txtDuration.Text);
if (listBox.Items.Contains(txtTitle.Text) && listBox.Items.Contains(txtArtist.Text) && listBox.Items.Contains(txtDuration.Text))
{
MessageBox.Show("This already exists");
}
else
{
listBox.Items.Add("Title: " + title + ", Artist: " + artist + ", Duration: " + duration);
}
}
}
private void btnReset_Click(object sender, EventArgs e)
{
listBox.Items.Clear();
}
}
The thing i did to check for duplication's doesn't work, and I have no idea how I could do the thing when i have the same title and artist but different duration.
But the check for the duplication's is the most important
Thanks in advance