Ejemplo n.º 1
0
        /// <summary>
        /// Verfies the category information is valid, and creates a new category if it is.</summary>
        private void SaveCategoryEditButton_Click(object sender, EventArgs e)
        {
            // check for valid input
            if (ValidateCategoryModify())
            {
                if (currentCategory == null)
                {
                    // TODO: create a new category
                    CalendarCategory cat = new CalendarCategory()
                    {
                        Name   = nameField.Text,
                        Symbol = (Shape)Enum.Parse(typeof(Shape), symbolDropDown.SelectedItem.ToString()),
                        Colour = Color.FromName(colorDropDown.SelectedItem.ToString())
                    };
                    eventCategories.Add(cat.Name, cat);
                }
                else
                {
                    // check if it's only a change in symbol of colour
                    CalendarCategory cat;
                    if (eventCategories.TryGetValue(nameField.Text, out cat))
                    {
                        // simply update the symbol and colour
                        cat.Symbol = (Shape)Enum.Parse(typeof(Shape), symbolDropDown.SelectedItem.ToString());
                        cat.Colour = Color.FromName(colorDropDown.SelectedItem.ToString());
                    }
                    else
                    {
                        // otherwise,
                        if (eventCategories.TryGetValue(currentCategory.Name, out cat))
                        {
                            // set all event under the old category to use its new name
                            foreach (CalendarEvent ev in cat.Events)
                            {
                                ev.Category = nameField.Text;
                            }

                            // remove the  category from the dictionary
                            eventCategories.Remove(currentCategory.Name);

                            // add back the category under its new name
                            eventCategories.Add(nameField.Text, new CalendarCategory()
                            {
                                Name   = nameField.Text,
                                Symbol = (Shape)Enum.Parse(typeof(Shape), symbolDropDown.SelectedItem.ToString()),
                                Colour = Color.FromName(colorDropDown.SelectedItem.ToString())
                            });
                        }
                    }
                }

                // refresh the calendar
                RefreshCalendar();

                // switch view back to events list
                eventsDisplayPanel.Visible  = true;
                eventModifyPanel.Visible    = false;
                categoryModifyPanel.Visible = false;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Shows a confirmation before allowing the user to delete the selected category.</summary>
        private void DeleteCategoryMenuItem_Click(object sender, EventArgs e)
        {
            // get the selected category
            TreeNode parentNode = (((sender as ToolStripMenuItem).Owner as ContextMenuStrip).SourceControl as TreeView).SelectedNode;

            currentCategory = parentNode.Tag as CalendarCategory;

            // create a string with category data
            string checkString = currentCategory.Name + "\r\n"
                                 + "Symbol: " + currentCategory.Colour.ToKnownColor().ToString() + " " + currentCategory.Symbol.ToString() + "\r\n"
                                 + "Events:\r\n";

            currentCategory.Events.Sort(new SortEventsByDate());
            if (currentCategory.Events.Count > 5)
            {
                for (int i = 0; i < 5; i++)
                {
                    checkString += "- " + currentCategory.Events[i].Label;
                    checkString += " (" + currentCategory.Events[i].StartingTime.ToString("MMM dd h:mmtt");
                    checkString += " - " + currentCategory.Events[i].EndingTime.ToString("MMM dd h:mmtt") + ")\r\n";
                }
                checkString += string.Format("... and {0} more.", currentCategory.Events.Count - 5);
            }
            else
            {
                foreach (CalendarEvent ev in currentCategory.Events)
                {
                    checkString += "- " + ev.Label;
                    checkString += " (" + ev.StartingTime.ToString("MMM dd h:mmtt");
                    checkString += " - " + ev.EndingTime.ToString("MMM dd h:mmtt") + ")\r\n";
                }
            }
            checkString += "\r\n\r\nNote: Events will be recategorized to Uncategorized";

            // show a confirmation dialog to user before deleting event
            DialogResult check = MessageBox.Show("Are you sure you wish to delete this category?\r\n\r\n" + checkString, "Delete Category", MessageBoxButtons.YesNo);

            if (check == DialogResult.Yes)
            {
                // delete the category
                eventCategories.Remove(currentCategory.Name);
                foreach (CalendarEvent ev in currentCategory.Events)
                {
                    ev.Category = "Uncategorized";
                }

                // refresh the form
                RefreshCalendar();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Cancels the modification of an event.</summary>
        private void CreateCategoryButton_Click(object sender, EventArgs e)
        {
            currentCategory = null;

            // ensure previous inputs are cleared
            ClearCategoryModify();

            // set title of panel
            categoryModifyLabel.Text = "Create Category";

            // switch view back to events list
            categoryModifyPanel.Visible = true;
            eventsDisplayPanel.Visible  = false;
            eventModifyPanel.Visible    = false;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Takes the user to the category modification panel for the selected category.</summary>
        private void ModifyCategoryMenuItem_Click(object sender, EventArgs e)
        {
            // get the selected category
            TreeNode parentNode = (((sender as ToolStripMenuItem).Owner as ContextMenuStrip).SourceControl as TreeView).SelectedNode;

            currentCategory = parentNode.Tag as CalendarCategory;

            // ensure previous inputs are cleared
            ClearCategoryModify();

            // set title of panel
            categoryModifyLabel.Text = "Modify Category";

            // fill in event details in controls
            nameField.Text = currentCategory.Name;
            symbolDropDown.SelectedIndex = symbolDropDown.FindStringExact(currentCategory.Symbol.ToString());
            colorDropDown.SelectedIndex  = colorDropDown.FindStringExact(currentCategory.Colour.ToKnownColor().ToString());

            // switch view to category modification
            categoryModifyPanel.Visible = true;
            eventsDisplayPanel.Visible  = false;
            eventModifyPanel.Visible    = false;
        }