예제 #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();
                }
            }
        }
예제 #2
0
        override protected void Save(object sender, RoutedEventArgs e)
        {
            if (XMLParser.IsEntityPresent(XMLParser.CharacterXDocument.Handle, name_text.Text) && !Editing)
            {
                System.Windows.Forms.MessageBox.Show("This character already exists, please try again.");
            }
            else
            {
                if (!XMLParser.IsTextValid(name_text.Text))
                {
                    required_text.Foreground = Brushes.Red;
                }
                else
                {
                    if (Editing)
                    {
                        XElement characterReference = (from c in XMLParser.CharacterXDocument.Handle.Root.Descendants("character")
                                                       where c.Element("name").Value.Equals(name_text.Text)
                                                       select c).First();

                        characterReference.Element("gender").Value      = PrepareText(gender_combo_box.Text);
                        characterReference.Element("description").Value = PrepareText(description_text.Text);
                    }
                    else
                    {
                        //adding a new xelement if it is not present
                        XElement newCharacter = new XElement("character",
                                                             new XElement("name", PrepareText(name_text.Text)),
                                                             new XElement("gender", PrepareText(gender_combo_box.Text)),
                                                             new XElement("description", PrepareText(description_text.Text)),
                                                             new XElement("parents", ""),
                                                             new XElement("children", ""),
                                                             new XElement("marriages", ""));

                        string temp = newCharacter.ToString();

                        XMLParser.CharacterXDocument.Handle.Root.Add(newCharacter);
                    }

                    XMLParser.CharacterXDocument.Save();

                    Update();
                    Close();
                }
            }
        }
예제 #3
0
        override protected void Save(object sender, RoutedEventArgs e)
        {
            if (XMLParser.IsEntityPresent(XMLParser.LocationXDocument.Handle, name_text.Text) && !Editing)
            {
                System.Windows.Forms.MessageBox.Show("This location already exists, please try again.");
            }
            else
            {
                if (!XMLParser.IsTextValid(name_text.Text) || !XMLParser.IsTextValid(type_combobox.Text))
                {
                    required_text.Foreground = Brushes.Red;
                }
                else
                {
                    if (Editing)
                    {
                        XElement locationReference = (from c in XMLParser.LocationXDocument.Handle.Root.Descendants("location")
                                                      where c.Element("name").Value.Equals(name_text.Text)
                                                      select c).First();

                        locationReference.Element("type").Value        = PrepareText(type_combobox.Text);
                        locationReference.Element("subtype").Value     = PrepareText(subtype_combobox.Text);
                        locationReference.Element("description").Value = PrepareText(description_text.Text);
                    }
                    else
                    {
                        XElement newLocation = new XElement("location",
                                                            new XElement("name", PrepareText(name_text.Text)),
                                                            new XElement("type", PrepareText(type_combobox.Text)),
                                                            new XElement("subtype", PrepareText(subtype_combobox.Text)),
                                                            new XElement("description", PrepareText(description_text.Text)));

                        string temp = newLocation.ToString();

                        XMLParser.LocationXDocument.Handle.Root.Add(newLocation);
                    }

                    XMLParser.LocationXDocument.Save();

                    Update();
                    Close();
                }
            }
        }