private void addButton_Click(object sender, EventArgs e) { if (nameTextBox.Text == "") { Notifications.ShowError("Please give the series a name.", "No name given"); } else if (imdbIdTextBox.Text == "") { Notifications.ShowError("Please give a valid IMDB ID of the series or search by name from the field above.", "No IMDB ID given"); } else if (lastViewedEpisodeTextBox.Text == "") { Notifications.ShowError("Please give the last episode you watched from this series.", "No last viewed episode given"); } else { try { Convert.ToInt32(imdbIdTextBox.Text); } catch { Notifications.ShowError("The IMDB ID can only contain numbers. Please check the given value.", "Invalid IMDB ID"); return; } if (!Episode.IsValidEpisodeString(lastViewedEpisodeTextBox.Text)) { Notifications.ShowError("Format of the given last viewed episode is invalid. Please give a valid value, eg. S05E13", "Invalid last viewed episode"); return; } addSeries(); Context.Notifications.ShowComingSeries(true); } }
void editLastViewedLabel(object sender) { TableLayoutPanel seriesTable = (TableLayoutPanel)Controls.Find("seriesTable", true)[0]; try { Label currLastViewedLabel = (Label)sender; int id = Convert.ToInt32(currLastViewedLabel.Name.Split('_')[1]); string text = currLastViewedLabel.Text; seriesTable.Controls.Remove(currLastViewedLabel); TextBox newTextBox = Context.Controls.CreateTextBox("lastViewedBox_" + id, text); newTextBox.KeyDown += newTextBox_KeyDown; newTextBox.LostFocus += newTextBox_LostFocus; seriesTable.Controls.Add(newTextBox, 2, id + 1); newTextBox.Focus(); } catch { TextBox currLastViewedTextBox = new TextBox(); foreach (Control currControl in seriesTable.Controls) { if (currControl.GetType() == typeof(TextBox)) { currLastViewedTextBox = (TextBox)currControl; } } int id = Convert.ToInt32(currLastViewedTextBox.Name.Split('_')[1]); string text = currLastViewedTextBox.Text; if (!Episode.IsValidEpisodeString(text)) { Variables.IsAddFormOpened = true; Notifications.ShowError("The format of the given episode number is incorrect. Please give a correct one.", "Invalid episode number"); return; } seriesTable.Controls.Remove(currLastViewedTextBox); Label newLabel = Context.Controls.CreateLabel("lastViewed_" + id, text, false); newLabel.Cursor = Cursors.Hand; newLabel.Click += lastViewedLabel_Click; seriesTable.Controls.Add(newLabel, 2, id + 1); Internal.Variables.SeriesList[id].LastViewed = new Episode(text); Context.IO.WriteSeries(); Control currLastEpLabel = Controls.Find("lastEp_" + id, true)[0]; if (Internal.Variables.SeriesList[id].LastEpisode.SeasonNumber > Internal.Variables.SeriesList[id].LastViewed.SeasonNumber || (Internal.Variables.SeriesList[id].LastEpisode.SeasonNumber == Internal.Variables.SeriesList[id].LastViewed.SeasonNumber && Internal.Variables.SeriesList[id].LastEpisode.EpisodeNumber > Internal.Variables.SeriesList[id].LastViewed.EpisodeNumber)) { currLastEpLabel.Font = new Font("Microsoft Sans Serif", 8.25F, FontStyle.Bold, GraphicsUnit.Point, 238); } else if (Internal.Variables.SeriesList[id].LastEpisode.SeasonNumber < Internal.Variables.SeriesList[id].LastViewed.SeasonNumber || (Internal.Variables.SeriesList[id].LastEpisode.SeasonNumber == Internal.Variables.SeriesList[id].LastViewed.SeasonNumber && Internal.Variables.SeriesList[id].LastEpisode.EpisodeNumber < Internal.Variables.SeriesList[id].LastViewed.EpisodeNumber)) { Deactivate -= Form1_Deactivate; MessageBox.Show(this, "The number of the last viewed episode has to be smaller than the one of the newest episode.", "Invalid episode number", MessageBoxButtons.OK, MessageBoxIcon.Error); Show(); Deactivate += Form1_Deactivate; editLastViewedLabel(newLabel); } else { currLastEpLabel.Font = new Font("Microsoft Sans Serif", 8.25F, FontStyle.Regular, GraphicsUnit.Point, 238); } } }