private void okButton_Click(object sender, EventArgs e) { string startDate; string currentDate; if (tagBox.Text == "") { MessageBox.Show("The campaign must have a tag.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (nameBox.Text == "") { MessageBox.Show("The campaign must have a name.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (currentCalendar.CampaignList.Find(x => x.Tag == tagBox.Text) != null && campaignToAdd == null) // added check for 'if editing existing campaign, allow tag if it already exists { // (without this, to edit a campaign you would need to change the tag) MessageBox.Show("A campaign with this tag already exists.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (validDateBoxes()) { startDate = startM.Text + startD.Text + startY.Text; currentDate = currM.Text + currD.Text + currY.Text; if (campaignToAdd == null) { campaignToAdd = new Campaign(nameBox.Text, tagBox.Text, startDate, currentDate); currentCalendar.AddCampaign(campaignToAdd); } else { campaignToAdd.Name = nameBox.Text; campaignToAdd.setCurrentDate(currentDate); campaignToAdd.setStartDate(startDate); campaignToAdd.Tag = tagBox.Text; } Cviewer.UpdateTree(); this.Close(); } else { return; } }
public static Calendar ReadInFile(System.IO.StreamReader sr) { CalendarType calendarType = new CalendarType(sr); Calendar loadedCalendar = new Calendar(calendarType); int numOfGenNotes; if (Int32.TryParse(sr.ReadLine(), out numOfGenNotes)) { for (int i = 0; i < numOfGenNotes; i++) { loadedCalendar.AddNote(ReadInNote(sr)); } int numOfCampaigns; if (Int32.TryParse(sr.ReadLine(), out numOfCampaigns)) { for (int i = 0; i < numOfCampaigns; i++) { Campaign loadedCampaign = new Campaign(); loadedCampaign.Name = sr.ReadLine(); loadedCampaign.Tag = sr.ReadLine(); loadedCampaign.CurrentDate = sr.ReadLine(); int numOfTimers = Int32.Parse(sr.ReadLine()); for (int j = 0; j < numOfTimers; j++) { string timerMessage = sr.ReadLine(); bool trackTimer = Convert.ToBoolean(sr.ReadLine()); string timerDate = sr.ReadLine(); loadedCampaign.addTimer(new Timer(timerDate, trackTimer, timerMessage)); } int numOfNotes = Int32.Parse(sr.ReadLine()); for (int j = 0; j < numOfNotes; j++) { loadedCampaign.addNote(ReadInNote(sr)); } loadedCalendar.AddCampaign(loadedCampaign); } } } return(loadedCalendar); }