Exemplo n.º 1
0
        ///Method to assign artwork to artist
        public void AssignArtworkToArtist(List <Artist> artistx, List <Artwork> art)
        {
            // set up the lists as arrays so we can search through them
            Artist[]  arrayofArtist  = artistx.ToArray();
            Artwork[] arrayofArtwork = art.ToArray();

            /// Search through the arrays
            for (int i = 0; i < arrayofArtist.Length; i++)
            {
                for (int t = 0; t < arrayofArtwork.Length; t++)
                {
                    /// Matches the artist ID with the Artist ID in the artwork array
                    if (arrayofArtist[i].ArtistID == arrayofArtwork[t].HoldArtistID)
                    {
                        /// Assigns the new artwork to the artist
                        arrayofArtist[i].ArtistArtwork.Add(arrayofArtwork[t]);
                    }
                }
            }
            /// Return artist array back into a list
            artistx = arrayofArtist.ToList();

            // Save the assigned artwork
            Savexml.SaveData(artistx, "ArtistList.xml");
        }
Exemplo n.º 2
0
        private void Save_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Savexml x = new Savexml();

                // Loads artist information

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


                /// Creates a artist instance
                var artist = new Artist();
                // Sets variable values
                artist.ThisArtistName   = ArtistName.Text;
                artist.thisArtistAddres = ArtistAddress.Text;

                // Adds the artist instance into artistlist
                ArtistList.Add(artist);
                for (int i = 0; i < ArtistList.Count(); i++)
                {
                    foreach (var artistx in ArtistList)
                    {
                        //set ID
                        if (ArtistList.Count() == 1)
                        {
                            artist.ThisArtistID = ArtistList.Count();
                        }
                        else
                        {
                            artist.ThisArtistID = ArtistList.Count();
                        }
                    }
                }

                /// Save artist Information
                Savexml.SaveData(ArtistList, "ArtistList.xml");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Edit the artist's Address /// </summary>
        /// <param name="artist"></param> A collection of artist
        /// <param name="ID"></param>
        /// <param name="changeAddress"></param>
        public void editArtist(List <Artist> artist, int ID, string changeAddress)
        {
            /// Change Artist list into a array for searching
            Artist[] ArtistInstance = artist.ToArray();

            /// Search through the array with a loop
            for (int i = 0; i < ArtistInstance.Length; i++)
            {
                /// Matches the Artist ID with the one provided
                if (ID == ArtistInstance[i].ArtistID)
                {
                    /// Sets the new address
                    ArtistInstance[i].Address = changeAddress;
                }
            }
            /// Return array into artist List
            artist = ArtistInstance.ToList();

            /// Save changes to the artist's Address
            Savexml.SaveData(artist, "ArtistList.xml");
        }