Beispiel #1
0
        override protected void Save(object sender, RoutedEventArgs e)
        {
            //strings used to determine how the two characters relate in XML terms
            string ancestorTag           = "children";
            string descendantTag         = "child";
            string relationship          = relationship_combo.Text;
            string oppositeAncestorTag   = "parents";
            string oppositeDescendantTag = "parent";

            if (!XMLParser.IsTextValid(focus_character_combo.Text) || !XMLParser.IsTextValid(relationship_combo.Text) || !XMLParser.IsTextValid(character_two_combo.Text))
            {
                required_text.Foreground = Brushes.Red;
            }

            else
            {
                if (relationship.Equals(IsParentOf))
                {
                    ancestorTag           = "parents";
                    descendantTag         = "parent";
                    oppositeAncestorTag   = "children";
                    oppositeDescendantTag = "child";
                }
                else if (relationship.Equals(WasMarriedTo))
                {
                    ancestorTag           = "marriages";
                    descendantTag         = "wasmarriedto";
                    oppositeAncestorTag   = ancestorTag;
                    oppositeDescendantTag = descendantTag;
                }
                else if (relationship.Equals(IsMarriedTo))
                {
                    ancestorTag           = "marriages";
                    descendantTag         = "ismarriedto";
                    oppositeAncestorTag   = ancestorTag;
                    oppositeDescendantTag = descendantTag;
                }

                if (IsRelationshipPresent(FocusCharacter, oppositeAncestorTag, oppositeDescendantTag, character_two_combo.Text))
                {
                    System.Windows.Forms.MessageBox.Show("This relationship already exists, please try again.");
                }
                else
                {
                    XElement characterOneReference = (from c in XMLParser.CharacterXDocument.Handle.Root.Descendants("character")
                                                      where c.Element("name").Value.Equals(FocusCharacter)
                                                      select c).First();
                    XElement characterTwoReference = (from c in XMLParser.CharacterXDocument.Handle.Root.Descendants("character")
                                                      where c.Element("name").Value.Equals(character_two_combo.Text)
                                                      select c).First();

                    XElement newRelationship = new XElement(oppositeDescendantTag, character_two_combo.Text);

                    characterOneReference.Element(oppositeAncestorTag).Add(newRelationship);

                    newRelationship = new XElement(descendantTag, FocusCharacter);

                    characterTwoReference.Element(ancestorTag).Add(newRelationship);

                    XMLParser.CharacterXDocument.Save();

                    if (MessageBox.Show($"Would you like to create another relationship?", "Create Another Relationship", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
                    {
                        Close();
                    }
                }
            }
        }
Beispiel #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.");
            }
        }
 override public void Update(XDocumentInformation x = null)
 {
     XMLParser.FillComboboxWithNames(XMLParser.CharacterXDocument.Handle, ref character_combo, FocusEvent);
 }
Beispiel #4
0
 override public void Update(XDocumentInformation x = null)
 {
     XMLParser.FillComboboxWithNames(XMLParser.EventXDocument.Handle, ref focusCombo);
     event_one_combo.Items.Clear();
     event_two_combo.Items.Clear();
 }