示例#1
0
        /// <summary>
        /// Change the price of the artwork
        /// </summary>
        /// <param name="artwork"></param> A collection of artwork
        /// <param name="ID"></param> Artwork ID
        /// <param name="newPrice"></param> The new price of the artwork
        public void changeArtworkPrice(List <Artwork> artwork, int ID, decimal newPrice)
        {
            // Changes collection of artwork into a array

            Artwork[] artworks = artwork.ToArray();

            // Loop through the array
            for (int i = 0; i < artworks.Length; i++)
            {
                /// Matches the artwork ID with the ID provided
                if (artworks[i].ThisArtworkID == ID)
                {
                    /// Changes price of the artwork
                    artworks[i].ThisArtworkPrice = newPrice;
                }
            }
            /// Changes array back into a list
            artwork = artworks.ToList();

            Savexml.SaveArtworkData(artworks, "ArtworkList.xml");
        }
        private void SaveArtwork(object sender, RoutedEventArgs e)
        {
            try
            {
                /// Load the artwork list
                if (File.Exists("ArtworkList.xml"))
                {
                    XmlSerializer deserializer = new XmlSerializer(typeof(List <Artwork>));
                    StreamReader  textReader   = new StreamReader("ArtworkList.xml");
                    ArtworkList = (List <Artwork>)deserializer.Deserialize(textReader);
                    textReader.Close();
                }

                /// User input of the artist ID
                int ArtistID = int.Parse(ArtistID1textBOX.Text);

                /// Sends artistlist to array
                Artist[] artistx = ArtistList.ToArray();
                var      array   = artistx;
                var      artwork = new Artwork();


                var artistt = ArtistList.Any(p => p.ThisArtistID == ArtistID);
                artwork.HoldArtistID           = ArtistID;
                artwork.ThisArtworkDescription = DescriptionTextBox.Text;
                artwork.ThisArtworkPrice       = decimal.Parse(PriceTextBox.Text);
                ArtworkList.Add(artwork);
                /// Search through list
                for (int i = 0; i < ArtworkList.Count(); i++)
                {
                    foreach (var Artwork in ArtworkList)
                    {
                        /// sets the ID value
                        if (ArtworkList.Count() == 1)
                        {
                            Artwork.ThisArtworkID = ArtworkList.Count();
                        }
                        else
                        {
                            artwork.ThisArtworkID = ArtworkList.Count() - 1;
                        }
                    }
                }

                /// Save artwork Data
                Savexml.SaveArtworkData(ArtworkList, "ArtworkList.xml");

                ///assign to the artist


                if (File.Exists("ArtistList.xml"))
                {
                    XmlSerializer deserializer = new XmlSerializer(typeof(List <Artist>));
                    TextReader    textReader   = new StreamReader("ArtistList.xml");
                    ArtistList = (List <Artist>)deserializer.Deserialize(textReader);
                    textReader.Close();
                }


                Artist a = new Artist();
                a.AssignArtworkToArtist(ArtistList, ArtworkList);
            }



            catch (Exception ex)
            {
                MessageBox.Show("Artist ID and price are numbers");
            }
        }