Example #1
0
        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);
        }
Example #2
0
        private void okButton_Click(object sender, EventArgs e)
        {
            Campaign notesCampaign;

            if (alertAll.Checked == false && AlertCampaign.Checked == false && noAlert.Checked == false)
            {
                MessageBox.Show("Choose a visibilty level.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (month.Text == "" || day.Text == "" || year.Text == "")
            {
                MessageBox.Show("Please enter a valid date.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (editNoteBox.Text == "")
            {
                MessageBox.Show("The note must have some content.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (campaignSelector.SelectedItem == null && generalBox.Checked)
            {
                notesCampaign = null;
            }

            else if (campaignSelector.SelectedItem == null && generalBox.Checked == false)
            {
                MessageBox.Show("Please select an associated campaign.\nIf it is a general note, check the general box.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else
            {
                notesCampaign = currentCalendar.CampaignList.Find(x => x.Tag == campaignSelector.SelectedItem.ToString());
            }


            if (editNote.Campaign == null)
            {
                currentCalendar.deleteNote(editNote);
            }
            else
            {
                editNote.Campaign.deleteNote(editNote);
            }

            AlertScope importance = AlertScope.dontAlert;

            if (alertAll.Checked)
            {
                importance = AlertScope.global;
            }
            else if (AlertCampaign.Checked)
            {
                importance = AlertScope.campaign;
            }
            else if (noAlert.Checked)
            {
                importance = AlertScope.dontAlert;
            }

            currentCalendar.AddNote(new Note(textBoxToDate(), importance, editNoteBox.Text, notesCampaign));

            this.Close();
        }