Exemplo n.º 1
0
        override protected void Save(object sender, RoutedEventArgs e)
        {
            if (XMLParser.IsEntityPresent(XMLParser.EventXDocument.Handle, name_text.Text) && !Editing)
            {
                System.Windows.Forms.MessageBox.Show("This event already exists, please try again.");
            }
            else
            {
                if (!XMLParser.IsTextValid(name_text.Text) || !XMLParser.IsTextValid(description_text.Text))
                {
                    required_text.Foreground = Brushes.Red;
                }
                else
                {
                    if (Editing)
                    {
                        XElement eventReference = (from c in XMLParser.EventXDocument.Handle.Root.Descendants("event")
                                                   where c.Element("name").Value.Equals(name_text.Text)
                                                   select c).First();

                        eventReference.Element("location").Value    = PrepareText(location_combo_box.Text);
                        eventReference.Element("unit_date").Value   = PrepareText(event_unit_date_number.Text);
                        eventReference.Element("date").Value        = PrepareText(event_date_number.Text);
                        eventReference.Element("description").Value = PrepareText(description_text.Text);
                    }
                    else
                    {
                        XElement newEvent = new XElement("event",
                                                         new XElement("name", PrepareText(name_text.Text)),
                                                         new XElement("location", PrepareText(location_combo_box.Text)),
                                                         new XElement("unit_date", PrepareText(event_unit_date_number.Text)),
                                                         new XElement("date", PrepareText(event_date_number.Text)),
                                                         new XElement("description", PrepareText(description_text.Text)),
                                                         new XElement("participants"),
                                                         new XElement("order_key", EventOrdering.GetNewOrderKey()));

                        string temp = newEvent.ToString();

                        XMLParser.EventXDocument.Handle.Root.Add(newEvent);
                    }

                    XMLParser.EventXDocument.Save();

                    Update();
                    Close();
                }
            }
        }
Exemplo n.º 2
0
        override protected void Save(object sender, RoutedEventArgs e)
        {
            string focusEvent       = focusCombo.Text;
            string beforeEvent      = event_one_combo.Text;
            string afterEvent       = event_two_combo.Text;
            int    eventOneOrderKey = 0;
            int    eventTwoOrderKey = 0;

            XElement focusEventOrderKey = (from c in XMLParser.EventXDocument.Handle.Root.Descendants("event")
                                           where c.Element("name").Value.Equals(focusEvent)
                                           select c.Element("order_key")).First();

            bool beforeEventValid = XMLParser.IsTextValid(beforeEvent);
            bool afterEventValid  = XMLParser.IsTextValid(afterEvent);
            bool SaveAndClose     = true;

            if (beforeEventValid)
            {
                eventOneOrderKey = (from c in XMLParser.EventXDocument.Handle.Root.Descendants("event")
                                    where c.Element("name").Value.Equals(beforeEvent)
                                    select int.Parse(c.Element("order_key").Value)).First();
            }
            if (afterEventValid)
            {
                eventTwoOrderKey = (from c in XMLParser.EventXDocument.Handle.Root.Descendants("event")
                                    where c.Element("name").Value.Equals(afterEvent)
                                    select int.Parse(c.Element("order_key").Value)).First();
            }

            if (beforeEventValid || afterEventValid)
            {
                if (beforeEventValid && !afterEventValid)
                {
                    if (int.Parse(focusEventOrderKey.Value) <= eventOneOrderKey)
                    {
                        focusEventOrderKey.Value = EventOrdering.GetKeyAfter(eventOneOrderKey).ToString();
                    }
                    else
                    {
                        System.Windows.Forms.MessageBox.Show("The event already lies in the order specified");
                    }
                }
                else if (!beforeEventValid && afterEventValid)
                {
                    if (int.Parse(focusEventOrderKey.Value) >= eventTwoOrderKey)
                    {
                        focusEventOrderKey.Value = EventOrdering.GetKeyBefore(eventTwoOrderKey).ToString();
                    }
                    else
                    {
                        System.Windows.Forms.MessageBox.Show("The event already lies in the order specified");
                    }
                }

                else if (beforeEventValid && afterEventValid)
                {
                    if (eventOneOrderKey > eventTwoOrderKey)
                    {
                        //invalid order
                        System.Windows.Forms.MessageBox.Show("The first event must come before the second event");
                        SaveAndClose = false;
                    }
                    else if (eventOneOrderKey == eventTwoOrderKey)
                    {
                        focusEventOrderKey.Value = eventOneOrderKey.ToString();
                    }
                    else
                    {
                        focusEventOrderKey.Value = EventOrdering.GetKeyBetween(eventOneOrderKey, eventTwoOrderKey).ToString();
                    }
                }
                if (SaveAndClose)
                {
                    XMLParser.EventXDocument.Save();
                    Close();
                }
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("Please select at least one relationship.");
            }
        }
Exemplo n.º 3
0
 public XMLParser(string folderPath)
 {
     FolderPath = folderPath;
     UpdateXDocuments();
     EventOrdering.Initialize();
 }