Exemple #1
0
 public MainWindow()
 {
     collection = new Kolekcja();
     reader     = new XMLReader();
     writer     = new XMLWriter();
     transform  = new XSLTransformation();
     schema     = new XMLSchema();
     InitializeComponent();
 }
Exemple #2
0
 public EditWindow(Gra game, Kolekcja coll, MainWindow win)
 {
     this.win        = win;
     this.collection = coll;
     this.game       = game;
     InitializeComponent();
     title_txt.Text      = game.Title;
     dev_txt.Text        = game.Dev;
     relese_txt.Text     = game.ReleseDate;
     publisher_txt.Text  = game.Publisher;
     price_txt.Text      = game.Price;
     production_txt.Text = game.Madedate;
     id_txt.Text         = game.Id;
     genre_txt.Text      = game.Genere;
 }
Exemple #3
0
        //https://www.youtube.com/watch?v=M4aXKPN0nK0

        public void Read(string file, Kolekcja collection)
        {
            this.file = file;
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(file);
            foreach (XmlNode mainNode in xmlDoc.DocumentElement)
            {
                foreach (XmlNode ulubione in mainNode.ChildNodes)
                {
                    foreach (XmlNode node in ulubione.ChildNodes)
                    {
                        if (node.Name == "gra")
                        {
                            string id         = node.Attributes[0].InnerText;
                            string genere     = node.Attributes[1].InnerText;
                            string title      = node.ChildNodes[0].InnerText;
                            string dev        = node.ChildNodes[1].InnerText;
                            string releseDate = node.ChildNodes[2].InnerText;
                            string publisher  = node.ChildNodes[3].Attributes[0].InnerText;
                            string price      = node.ChildNodes[4].InnerText;
                            string madedate   = node.ChildNodes[5].InnerText;

                            collection.AddGame(id, title, genere, dev, releseDate, publisher, price, madedate);

                            /*foreach (XmlNode child in node.ChildNodes)
                             * {
                             * }*/
                        }
                    }
                    if (ulubione.Name == "d")
                    {
                        string id       = ulubione.Attributes[0].InnerText;
                        string name     = ulubione.ChildNodes[0].InnerText;
                        string city     = ulubione.ChildNodes[1].InnerText;
                        string street   = ulubione.ChildNodes[2].InnerText;
                        string streetnr = ulubione.ChildNodes[2].Attributes[0].InnerText;
                        string postal   = ulubione.ChildNodes[3].InnerText;
                        string phone    = ulubione.ChildNodes[4].InnerText;
                        string kier     = ulubione.ChildNodes[4].Attributes[0].InnerText;

                        collection.AddPublisher(id, name, city, street, streetnr, postal, phone, kier);
                    }
                }
            }
        }
Exemple #4
0
        private void read_btn_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();

            fileDialog.Filter = "XML files (*.xml)|*.xml|All files (*.*)|*.*";
            if (fileDialog.ShowDialog() == true)
            {
                collection = new Kolekcja();
                string file = fileDialog.FileName;
                reader.Read(file, collection);
                //listBox.ItemsSource = collection.Games;
                //listBox.DisplayMemberPath = "Title";
                writer.originalFile = file;

                /*foreach(Gra game in collection.Games)
                 * {
                 *  ListBoxItem itm = new ListBoxItem();
                 *  itm.Content = game.Title;
                 *  listBox.Items.Add(itm);
                 * }*/
                UpdateCollection();
            }
        }
Exemple #5
0
        public void Write(string file, Kolekcja collection)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(originalFile);

            int numOfGames = 0;

            foreach (XmlNode mainNode in doc.DocumentElement)
            {
                foreach (XmlNode ulubione in mainNode.ChildNodes)
                {
                    foreach (XmlNode node in ulubione.ChildNodes)
                    {
                        if (node.Name == "gra")
                        {
                            if (numOfGames < collection.Games.Count)
                            {
                                Gra game = collection.Games[numOfGames];

                                /*string id = node.Attributes[0].InnerText;
                                 * string genere = node.Attributes[1].InnerText;
                                 * string title = node.ChildNodes[0].InnerText;
                                 * string dev = node.ChildNodes[1].InnerText;
                                 * string releseDate = node.ChildNodes[2].InnerText;
                                 * string publisher = node.ChildNodes[3].Attributes[0].InnerText;
                                 * string price = node.ChildNodes[4].InnerText;
                                 * string madedate = node.ChildNodes[5].InnerText;*/
                                node.Attributes[0].InnerText = game.Id;
                                node.Attributes[1].InnerText = game.Genere;
                                node.ChildNodes[0].InnerText = game.Title;
                                node.ChildNodes[1].InnerText = game.Dev;
                                node.ChildNodes[2].InnerText = game.ReleseDate;
                                node.ChildNodes[3].Attributes[0].InnerText = game.Publisher;
                                node.ChildNodes[4].InnerText = game.Price;
                                node.ChildNodes[5].InnerText = game.Madedate;
                            }
                            else
                            {
                                node.RemoveAll();
                                node.ParentNode.RemoveChild(node);
                            }
                            numOfGames++;
                        }
                    }
                }
            }

            if (collection.Games.Count < numOfGames)
            {
            }
            else if (collection.Games.Count > numOfGames)
            {
                while (collection.Games.Count != numOfGames)
                {
                    Gra          game     = collection.Games[numOfGames];
                    XmlElement   ulubione = doc.CreateElement("ulubione");
                    XmlElement   newGame  = doc.CreateElement("gra");
                    XmlAttribute newID    = doc.CreateAttribute("id");
                    newID.InnerText = game.Id;
                    XmlAttribute newGen = doc.CreateAttribute("gatunek");
                    newGen.InnerText = game.Genere;
                    newGame.Attributes.Append(newID);
                    newGame.Attributes.Append(newGen);
                    XmlElement title = doc.CreateElement("tytuł");
                    title.InnerText = game.Title;
                    newGame.AppendChild(title);
                    XmlElement dev = doc.CreateElement("twórcy");
                    dev.InnerText = game.Dev;
                    newGame.AppendChild(dev);
                    XmlElement relese = doc.CreateElement("data_premiery");
                    relese.InnerText = game.ReleseDate;
                    newGame.AppendChild(relese);
                    XmlElement   publisher = doc.CreateElement("dystrybutor");
                    XmlAttribute idref     = doc.CreateAttribute("idref");
                    idref.InnerText = game.Publisher;
                    publisher.Attributes.Append(idref);
                    newGame.AppendChild(publisher);
                    XmlElement   price  = doc.CreateElement("cena");
                    XmlAttribute waluta = doc.CreateAttribute("waluta");
                    waluta.InnerText = "PLN";
                    price.Attributes.Append(waluta);
                    price.InnerText = game.Price;
                    newGame.AppendChild(price);
                    XmlElement prod = doc.CreateElement("rok_produkcji");
                    prod.InnerText = game.Madedate;
                    newGame.AppendChild(prod);
                    ulubione.AppendChild(newGame);
                    doc.DocumentElement.ChildNodes[1].AppendChild(ulubione);

                    numOfGames++;
                }
            }

            doc.Save(file);
        }